Răsfoiți Sursa

增加方法:item_image: db: 查询item的image,同时修改,offline_search:、 offline_itemsearch:、offline_category方法中查询语句 增加is_active = 1判断

Pen Li 9 ani în urmă
părinte
comite
529e76902f

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


+ 62 - 13
RedAnt ERP Mobile/common/Functions/offline/OLDataProvider.m

@@ -642,7 +642,7 @@
     if(product_id==nil && model_name)
         sqlQuery = [NSString stringWithFormat:@"select i.url from product m LEFT join model_image i on m.product_id = i.product_id  where m.name=%@ order by i.default_img desc, i._id asc limit 1;",model_name];// select i.url from model m LEFT join model_image i on m.product_id = i.product_id  where m.name=%@ order by i.default_img desc, i._id asc limit 1;
     else if (product_id)
-        sqlQuery = [NSString stringWithFormat:@"select i.url from product m LEFT join model_image i on m.product_id = i.product_id  where m.item_id=%@ order by i.default_img desc, i._id asc limit 1;",product_id];// select i.url from model m
+        sqlQuery = [NSString stringWithFormat:@"select i.url from product m LEFT join model_image i on m.product_id = i.product_id  where m.product_id=%@ order by i.default_img desc, i._id asc limit 1;",product_id];// select i.url from model m
     
     sqlite3_stmt * statement;
     
@@ -1070,15 +1070,15 @@
     
     sqlite3 *db = [iSalesDB get_db];
     
-    int count = [iSalesDB get_recordcount:db table:@"product" where:[NSString stringWithFormat:@"lower(name) like'%%%@%%' or lower(description) like'%%%@%%'",keyword,keyword]];
+    int count = [iSalesDB get_recordcount:db table:@"product" where:[NSString stringWithFormat:@"(lower(name) like'%%%@%%' or lower(description) like'%%%@%%') and is_active = 1",keyword,keyword]];
     
     
     NSString *sqlQuery = nil;
     if(exactMatch )
-        sqlQuery=[NSString stringWithFormat:@"select m.name,m.description,m.product_id,w._id,m.closeout from product m left join wishlist w on m.product_id=w.product_id where lower(name) like'%@%%' order by m.name limit %d offset %d ;",keyword,limit, offset]; // 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 lower(name) like'%@%%' order by m.name limit %d offset %d ;
+        sqlQuery=[NSString stringWithFormat:@"select m.name,m.description,m.product_id,w._id,m.closeout from product m left join wishlist w on m.product_id=w.product_id where lower(name) like'%@%%' and m.is_active = 1 order by m.name limit %d offset %d ;",keyword,limit, offset]; // 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 lower(name) like'%@%%' order by m.name limit %d offset %d ;
     else
 
-        sqlQuery=[NSString stringWithFormat:@"select m.name,m.description,m.product_id,w._id,m.closeout from product m left join wishlist w on m.product_id=w.product_id where lower(name) like'%%%@%%' or lower(description) like'%%%@%%' order by m.name limit %d offset %d ;",keyword,keyword,limit, offset];// 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 lower(name) like'%%%@%%' or
+        sqlQuery=[NSString stringWithFormat:@"select m.name,m.description,m.product_id,w._id,m.closeout from product m left join wishlist w on m.product_id=w.product_id where (lower(name) like'%%%@%%' or lower(description) like'%%%@%%') and m.is_active = 1 order by m.name limit %d offset %d ;",keyword,keyword,limit, offset];// 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 lower(name) like'%%%@%%' or
     
     DebugLog(@"offline_search sql:%@",sqlQuery);
     sqlite3_stmt * statement;
@@ -1754,7 +1754,8 @@
             double weight=[bsubtotaljson[@"weight"] doubleValue];
             int carton=[bsubtotaljson[@"carton"] intValue];
             
-            itemjson[@"img_url"]= [self model_category_img:[NSString stringWithFormat:@"%@",[NSNumber numberWithInt:item_id]] model_name:nil db:db];
+//            itemjson[@"img_url"]= [self model_category_img:[NSString stringWithFormat:@"%@",[NSNumber numberWithInt:item_id]] model_name:nil db:db];
+            itemjson[@"img_url"] = [self item_image:[NSString stringWithFormat:@"%@",[NSNumber numberWithInt:item_id]] db:db];
             itemjson[@"model"]=nsname;
             itemjson[@"cuft"]=[NSNumber numberWithDouble:cuft];
             itemjson[@"weight"]=[NSNumber numberWithDouble:weight];
@@ -3210,6 +3211,53 @@
     return [params valueForKey:key] ? [params valueForKey:key] : @"";
 }
 
++ (NSString *)item_image:(NSString *)item_id db:(sqlite3 *)db {
+    
+    NSString* ret= nil;
+    
+    NSString *sqlQuery = nil;
+
+    sqlQuery = [NSString stringWithFormat:@"select i.url from product m LEFT join model_image i on m.product_id = i.product_id  where m.item_id=%@ order by i.default_img desc, i._id asc limit 1;",item_id];// select i.url from model m
+    
+    sqlite3_stmt * statement;
+    
+    //    int count=0;
+    if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
+    {
+        
+        
+        if (sqlite3_step(statement) == SQLITE_ROW)
+        {
+            
+            
+            char *imgurl = (char*)sqlite3_column_text(statement, 0);
+            if(imgurl==nil)
+                imgurl="";
+            NSString *nsimgurl = [[NSString alloc]initWithUTF8String:imgurl];
+            
+            
+            ret=nsimgurl;
+            
+            
+        }
+        
+        sqlite3_finalize(statement);
+    }
+    else
+    {
+        [ret setValue:@"8" forKey:@"result"];
+    }
+    
+    
+    
+    //  [iSalesDB close_db:db];
+    DebugLog(@"data string: %@",ret );
+    
+    
+    return ret;
+
+}
+
 
 #pragma mark contact list
 
@@ -4230,10 +4278,10 @@
     // [iSalesDB AddExFunction:db];
     
     int count;
-    NSString *where = [NSString stringWithFormat:@"category like'%%#%@#%%'",category];
+    NSString *where = [NSString stringWithFormat:@"category like'%%#%@#%%' and is_active = 1",category];
     
 
-    NSString *sqlQuery = [NSString stringWithFormat:@"select m.name,m.description,m.product_id,w._id,m.closeout from product 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];
+    NSString *sqlQuery = [NSString stringWithFormat:@"select m.name,m.description,m.product_id,w._id,m.closeout from product m left join wishlist w on m.product_id=w.product_id where m.category like'%%#%@#%%' and m.is_active = 1 order by m.name limit %d offset %d ;",category,limit, offset];
 
     
     //    {
@@ -4336,10 +4384,10 @@
         // 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 product 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];
+       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 product where %@ %@ %@ %@ %@ %@ and is_active = 1) 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];
+        where =[NSString stringWithFormat:@"%@ %@ %@ %@ %@ %@ and is_active = 1",cateWhere,best_seller,alert,available_condition,qty,price];
         
     }
     
@@ -4484,7 +4532,7 @@
     int count;
     
     NSString *sqlQuery = nil;
-
+    where = [where stringByAppendingString:@" and m.is_active = 1"];
     sqlQuery=[NSString stringWithFormat:@"select m.name,m.description,m.product_id,w._id,m.closeout from product m left join wishlist w on m.product_id=w.product_id where %@ order by %@ limit %d offset %d ;",where,orderby,limit, offset];
 
     
@@ -4627,11 +4675,11 @@
         // 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 product 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];
+        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 product where %@ %@ %@ %@ %@ %@ and is_active = 1) 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 =[NSString stringWithFormat:@"%@ %@ %@ %@ %@ %@ and m.is_active = 1",cateWhere,best_seller,alert,available_condition,qty,price];
         
     }
     where = [where stringByReplacingOccurrencesOfString:@"m." withString:@""];
@@ -5149,7 +5197,8 @@
             
             itemjson[@"combine"]=[self model_bundle:item_id db:db1 compute_part:false];
             
-            itemjson[@"img"]= [self model_category_img:[NSString stringWithFormat:@"%@",[NSNumber numberWithInt:item_id]] model_name:nil db:db1];
+//            itemjson[@"img"]= [self model_category_img:[NSString stringWithFormat:@"%@",[NSNumber numberWithInt:item_id]] model_name:nil db:db1];
+            itemjson[@"img"] = [self item_image:[NSString stringWithFormat:@"%@",[NSNumber numberWithInt:item_id]] db:db1];
             
             itemjson[@"Item Number"]=[NSString stringWithFormat:@"%@\n%@",nsname,nsdescription ];
             itemjson[@"note"]=nsline_note;