+ (NSMutableArray *)querygoodsByIdFromLocal:(NSString *)dayFlightId{
FMDatabase *fmdb = [SADBManager sharedDB];
if (!fmdb) {
return nil;
}
NSString *query = [NSString stringWithFormat:@"select * from FlightGoods where dayFlightId= '%@'", dayFlightId];
FMResultSet *rs = [fmdb executeQuery:query];
NSMutableArray *invArray = [[NSMutableArray alloc]init];
FlightGoods *flightgoods;
while ([rs next]) {
flightgoods = [[FlightGoods alloc]init];
flightgoods.dayFlightId = [rs stringForColumn:@"dayFlightId"];
flightgoods.goodsCode = [rs stringForColumn:@"goodsCode"];
flightgoods.goodsName = [rs stringForColumn:@"goodsName"];
flightgoods.goodsUnit = [rs stringForColumn:@"goodsUnit"];
flightgoods.remarks = [rs stringForColumn:@"remarks"];
flightgoods.cabinStockNum = [[NSNumber alloc]initWithInt:[rs intForColumn:@"cabinStockNum"]];
flightgoods.loseNum = [[NSNumber alloc]initWithInt:[rs intForColumn:@"loseNum"]];
flightgoods.actualNum = [[NSNumber alloc]initWithInt:[rs intForColumn:@"actualNum"]];
flightgoods.tempActualNum = flightgoods.actualNum;
flightgoods.tempLoseNum = flightgoods.loseNum;
flightgoods.tempRemarks = flightgoods.remarks;
[invArray addObject:flightgoods];
}
return invArray;
}
+ (BOOL)updateGoodsByFlightGoods:(NSMutableArray *)flightGoodsArr{
FMDatabase *fmdb = [SADBManager sharedDB];
if (!fmdb) {
return nil;
}
[fmdb beginTransaction];
BOOL isRollBack = NO;
@try {
for (int i = 0; i<[flightGoodsArr count]; i++) {
FlightGoods * flightGoods = [flightGoodsArr objectAtIndex:i];
NSString * update = [NSString stringWithFormat:@"update FlightGoods set actualNum = '%@', loseNum = '%@',remarks = '%@' where goodsCode = '%@'",flightGoods.actualNum,flightGoods.loseNum,flightGoods.remarks,flightGoods.goodsCode];
BOOL isSuccess = [fmdb executeUpdate:update];
if (!isSuccess) {
NSLog(@"update Failure");
}
}
}
@catch (NSException *exception) {
isRollBack = YES;
[fmdb rollback];
}
@finally {
if (!isRollBack) {
[fmdb commit];
}
}
return !isRollBack;
}