Просмотр исходного кода

修改offline_itemsearch、offline_category方法中count值的查询

Pen Li 9 лет назад
Родитель
Сommit
9d63130254

BIN
RedAnt ERP Mobile/RedAnt ERP Mobile.xcworkspace/xcuserdata/macmini1.xcuserdatad/UserInterfaceState.xcuserstate


+ 18 - 7
RedAnt ERP Mobile/common/Functions/offline/OLDataProvider.m

@@ -3395,7 +3395,8 @@
     sqlite3 *db = [iSalesDB get_db];
     [iSalesDB AddExFunction:db];
     
-    int count = [iSalesDB get_recordcount:db table:@"model" where:[NSString stringWithFormat:@"category like'%%#%@#%%'",category]];
+    int count;
+    NSString *where = [NSString stringWithFormat:@"category like'%%#%@#%%'",category];
     
     
     NSString *sqlQuery = [NSString stringWithFormat:@"select m.name,m.description,m.product_id,w._id,m.closeout from model m left join wishlist w on m.product_id=w.product_id where m.category like'%%#%@#%%' order by m.name limit %d offset %d ;",category,limit, offset];
@@ -3441,8 +3442,8 @@
         
         // best seller
         [self check:params[@"bestseller"] valueKey:@"best_seller" inDictionary:filter];
-        NSString *best_seller = @"m.name asc";
-        NSString *order_best_seller = @"";
+        NSString *best_seller = @"";
+        NSString *order_best_seller = @"m.name asc";
         if ([params[@"bestseller"] isEqualToString:@"Yes"]) {
             best_seller = @"and best_seller > 0";
             order_best_seller = @"m.best_seller desc";
@@ -3495,9 +3496,13 @@
         // where bestseller > 0 order by bestseller desc
         // sql query: alert     availability(int)   best_seller(int)    price    qty
        sqlQuery = [NSString stringWithFormat:@"select m.name,m.description,m.product_id,w._id,m.closeout from (select name,description,product_id,closeout,best_seller from model where %@ %@ %@ %@ %@ %@) m left join wishlist w on m.product_id=w.product_id order by %@ limit %d offset %d;",cateWhere,best_seller,alert,available_condition,qty,price,order_best_seller,limit,offset];
+        
+        where =[NSString stringWithFormat:@"%@ %@ %@ %@ %@ %@",cateWhere,best_seller,alert,available_condition,qty,price];
+        
     }
     
-   
+   count = [iSalesDB get_recordcount:db table:@"model" where:where];
+    
     if (!appDelegate.user) {
         [filter setValue:@{@"count" : @(0)} forKey:@"price"];
     }
@@ -3505,6 +3510,7 @@
     [ret setValue:filter forKey:@"filter"];
     
     DebugLog(@"offline_category sql:%@",sqlQuery);
+    
     sqlite3_stmt * statement;
     [ret setValue:@"2" forKey:@"result"];
     [ret setValue:[NSString stringWithFormat:@"%d",count] forKey:@"item_total_count"];
@@ -3633,6 +3639,8 @@
     sqlite3 *db = [iSalesDB get_db];
     [iSalesDB AddExFunction:db];
     
+#warning count 在filter情况下不能使用get_recordcount:table:where:
+    int count;
     
     NSString *sqlQuery = nil;
     sqlQuery=[NSString stringWithFormat:@"select m.name,m.description,m.product_id,w._id,m.closeout from model m left join wishlist w on m.product_id=w.product_id where %@ order by %@ limit %d offset %d ;",where,orderby,limit, offset];
@@ -3773,12 +3781,15 @@
         // sql query: alert     availability(int)   best_seller(int)    price    qty
         sqlQuery = [NSString stringWithFormat:@"select m.name,m.description,m.product_id,w._id,m.closeout from (select name,description,product_id,closeout,best_seller from model where %@ %@ %@ %@ %@ %@) m left join wishlist w on m.product_id=w.product_id order by %@ limit %d offset %d;",cateWhere,best_seller,alert,available_condition,qty,price,order_best_seller,limit,offset];
         
+        // count
+        where =[NSString stringWithFormat:@"%@ %@ %@ %@ %@ %@",cateWhere,best_seller,alert,available_condition,qty,price];
         
-        where = cateWhere;
     }
+    where = [where stringByReplacingOccurrencesOfString:@"m." withString:@""];
     
-    // where == nil 在filterSearch时
-    int count = [iSalesDB get_recordcount:db table:@"model" where:where];
+    count = [iSalesDB get_recordcount:db table:@"model" where:where];
+    
+
     
     
     if (!appDelegate.user) {