Ray Zhang 9 лет назад
Родитель
Сommit
ff3273556c

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


+ 46 - 30
RedAnt ERP Mobile/RedAnt ERP Mobile.xcworkspace/xcuserdata/Ray.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@@ -106,12 +106,12 @@
             ignoreCount = "0"
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             continueAfterRunningActions = "No"
             filePath = "common/Functions/offline/OLDataProvider.m"
             filePath = "common/Functions/offline/OLDataProvider.m"
-            timestampString = "494386106.525467"
+            timestampString = "494839298.810392"
             startingColumnNumber = "9223372036854775807"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "4688"
-            endingLineNumber = "4688"
-            landmarkName = "+offline_saveNewContact:"
+            startingLineNumber = "4699"
+            endingLineNumber = "4699"
+            landmarkName = "+offline_saveContact:update:isCustomer:"
             landmarkType = "5">
             landmarkType = "5">
          </BreakpointContent>
          </BreakpointContent>
       </BreakpointProxy>
       </BreakpointProxy>
@@ -122,11 +122,11 @@
             ignoreCount = "0"
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             continueAfterRunningActions = "No"
             filePath = "common/Functions/offline/OLDataProvider.m"
             filePath = "common/Functions/offline/OLDataProvider.m"
-            timestampString = "494386106.525467"
+            timestampString = "494839298.810392"
             startingColumnNumber = "9223372036854775807"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "4909"
-            endingLineNumber = "4909"
+            startingLineNumber = "4920"
+            endingLineNumber = "4920"
             landmarkName = "+offline_editContact:"
             landmarkName = "+offline_editContact:"
             landmarkType = "5">
             landmarkType = "5">
          </BreakpointContent>
          </BreakpointContent>
@@ -143,7 +143,7 @@
             endingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
             startingLineNumber = "791"
             startingLineNumber = "791"
             endingLineNumber = "791"
             endingLineNumber = "791"
-            landmarkName = "+offline_notimpl"
+            landmarkName = "+offline_wishlist:"
             landmarkType = "5">
             landmarkType = "5">
          </BreakpointContent>
          </BreakpointContent>
       </BreakpointProxy>
       </BreakpointProxy>
@@ -191,7 +191,7 @@
             endingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
             startingLineNumber = "2027"
             startingLineNumber = "2027"
             endingLineNumber = "2027"
             endingLineNumber = "2027"
-            landmarkName = "+offline_add2cart:"
+            landmarkName = "+offline_editorder:"
             landmarkType = "5">
             landmarkType = "5">
          </BreakpointContent>
          </BreakpointContent>
       </BreakpointProxy>
       </BreakpointProxy>
@@ -223,7 +223,7 @@
             endingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
             startingLineNumber = "2016"
             startingLineNumber = "2016"
             endingLineNumber = "2016"
             endingLineNumber = "2016"
-            landmarkName = "+offline_editorder:"
+            landmarkName = "+offline_createorder:"
             landmarkType = "5">
             landmarkType = "5">
          </BreakpointContent>
          </BreakpointContent>
       </BreakpointProxy>
       </BreakpointProxy>
@@ -234,12 +234,12 @@
             ignoreCount = "0"
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             continueAfterRunningActions = "No"
             filePath = "common/Functions/offline/OLDataProvider.m"
             filePath = "common/Functions/offline/OLDataProvider.m"
-            timestampString = "494386106.525467"
+            timestampString = "494839298.810392"
             startingColumnNumber = "9223372036854775807"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "8128"
-            endingLineNumber = "8128"
-            landmarkName = "+offline_placeorder:"
+            startingLineNumber = "8139"
+            endingLineNumber = "8139"
+            landmarkName = "+paymentInfoDic:db:"
             landmarkType = "5">
             landmarkType = "5">
          </BreakpointContent>
          </BreakpointContent>
       </BreakpointProxy>
       </BreakpointProxy>
@@ -250,11 +250,11 @@
             ignoreCount = "0"
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             continueAfterRunningActions = "No"
             filePath = "common/Functions/offline/OLDataProvider.m"
             filePath = "common/Functions/offline/OLDataProvider.m"
-            timestampString = "494386106.525467"
+            timestampString = "494839298.810392"
             startingColumnNumber = "9223372036854775807"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "5812"
-            endingLineNumber = "5812"
+            startingLineNumber = "5823"
+            endingLineNumber = "5823"
             landmarkName = "+offline_orderdetail:"
             landmarkName = "+offline_orderdetail:"
             landmarkType = "5">
             landmarkType = "5">
          </BreakpointContent>
          </BreakpointContent>
@@ -266,11 +266,11 @@
             ignoreCount = "0"
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             continueAfterRunningActions = "No"
             filePath = "iSales-NPD/AppDelegate.m"
             filePath = "iSales-NPD/AppDelegate.m"
-            timestampString = "494585029.093343"
+            timestampString = "494838480.772555"
             startingColumnNumber = "9223372036854775807"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "1040"
-            endingLineNumber = "1040"
+            startingLineNumber = "1048"
+            endingLineNumber = "1048"
             landmarkName = "-check_offline:useInternalAddress:parentvc:"
             landmarkName = "-check_offline:useInternalAddress:parentvc:"
             landmarkType = "5">
             landmarkType = "5">
          </BreakpointContent>
          </BreakpointContent>
@@ -310,7 +310,7 @@
       <BreakpointProxy
       <BreakpointProxy
          BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
          BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
          <BreakpointContent
          <BreakpointContent
-            shouldBeEnabled = "No"
+            shouldBeEnabled = "Yes"
             ignoreCount = "0"
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             continueAfterRunningActions = "No"
             filePath = "iSales-NPD/AppDelegate.m"
             filePath = "iSales-NPD/AppDelegate.m"
@@ -330,11 +330,11 @@
             ignoreCount = "0"
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             continueAfterRunningActions = "No"
             filePath = "iSales-NPD/AppDelegate.m"
             filePath = "iSales-NPD/AppDelegate.m"
-            timestampString = "494585029.093343"
+            timestampString = "494838480.772555"
             startingColumnNumber = "9223372036854775807"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "996"
-            endingLineNumber = "996"
+            startingLineNumber = "1004"
+            endingLineNumber = "1004"
             landmarkName = "-check_offline:useInternalAddress:parentvc:"
             landmarkName = "-check_offline:useInternalAddress:parentvc:"
             landmarkType = "5">
             landmarkType = "5">
          </BreakpointContent>
          </BreakpointContent>
@@ -346,11 +346,11 @@
             ignoreCount = "0"
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             continueAfterRunningActions = "No"
             filePath = "iSales-NPD/AppDelegate.m"
             filePath = "iSales-NPD/AppDelegate.m"
-            timestampString = "494585029.093343"
+            timestampString = "494838480.772555"
             startingColumnNumber = "9223372036854775807"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "991"
-            endingLineNumber = "991"
+            startingLineNumber = "999"
+            endingLineNumber = "999"
             landmarkName = "-check_offline:useInternalAddress:parentvc:"
             landmarkName = "-check_offline:useInternalAddress:parentvc:"
             landmarkType = "5">
             landmarkType = "5">
          </BreakpointContent>
          </BreakpointContent>
@@ -378,11 +378,11 @@
             ignoreCount = "0"
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             continueAfterRunningActions = "No"
             filePath = "iSales-NPD/AppDelegate.m"
             filePath = "iSales-NPD/AppDelegate.m"
-            timestampString = "494585029.093343"
+            timestampString = "494838480.772555"
             startingColumnNumber = "9223372036854775807"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "999"
-            endingLineNumber = "999"
+            startingLineNumber = "1007"
+            endingLineNumber = "1007"
             landmarkName = "-check_offline:useInternalAddress:parentvc:"
             landmarkName = "-check_offline:useInternalAddress:parentvc:"
             landmarkType = "5">
             landmarkType = "5">
          </BreakpointContent>
          </BreakpointContent>
@@ -403,5 +403,21 @@
             landmarkType = "5">
             landmarkType = "5">
          </BreakpointContent>
          </BreakpointContent>
       </BreakpointProxy>
       </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            shouldBeEnabled = "Yes"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "iSales-NPD/AppDelegate.m"
+            timestampString = "494585833.476943"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "850"
+            endingLineNumber = "850"
+            landmarkName = "-upload_offline:useInternalAddress:orderid:"
+            landmarkType = "5">
+         </BreakpointContent>
+      </BreakpointProxy>
    </Breakpoints>
    </Breakpoints>
 </Bucket>
 </Bucket>

+ 5 - 0
RedAnt ERP Mobile/common/Functions/offline/OLDataProvider.h

@@ -12,6 +12,11 @@
 +(NSDictionary*) offline_category :(NSMutableDictionary *) params;
 +(NSDictionary*) offline_category :(NSMutableDictionary *) params;
 +(NSDictionary*) offline_search :(NSMutableDictionary *) params;
 +(NSDictionary*) offline_search :(NSMutableDictionary *) params;
 +(NSDictionary*) offline_itemsearch :(NSMutableDictionary *) params;
 +(NSDictionary*) offline_itemsearch :(NSMutableDictionary *) params;
+
++(NSData*) offline_categoryaddall :(NSMutableDictionary *) params;
++(NSData*) offline_searchaddall :(NSMutableDictionary *) params;
++(NSData*) offline_itemsearchaddall :(NSMutableDictionary *) params;
+
 +(NSDictionary*) offline_model :(NSMutableDictionary *) params;
 +(NSDictionary*) offline_model :(NSMutableDictionary *) params;
 
 
 
 

+ 12 - 1
RedAnt ERP Mobile/common/Functions/offline/OLDataProvider.m

@@ -3447,7 +3447,18 @@
     
     
     return ret;
     return ret;
 }
 }
-
++(NSData*) offline_categoryaddall :(NSMutableDictionary *) params
+{
+    return [RAUtils dict2data:[self offline_notimpl]];
+}
++(NSData*) offline_searchaddall :(NSMutableDictionary *) params
+{
+    return [RAUtils dict2data:[self offline_notimpl]];
+}
++(NSData*) offline_itemsearchaddall :(NSMutableDictionary *) params
+{
+    return [RAUtils dict2data:[self offline_notimpl]];
+}
 #pragma mark - Jack
 #pragma mark - Jack
 #warning 做SQL操作时转义!!
 #warning 做SQL操作时转义!!
 
 

+ 9 - 0
RedAnt ERP Mobile/common/data_provider/iSalesNetwork.h

@@ -107,6 +107,15 @@
 +(NSDictionary*)direct_save_TearSheet:(NSString*) request_url name:(NSString*)name delete:(NSString* )ids note:(NSString* )saveNote;
 +(NSDictionary*)direct_save_TearSheet:(NSString*) request_url name:(NSString*)name delete:(NSString* )ids note:(NSString* )saveNote;
 
 
 
 
++(NSDictionary*)Category_addall: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword  offset:(long) offset limit:(long) limit alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip orderCode:(NSString*) orderCode;
+//+(NSDictionary*)category_addall2wish: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword  offset:(long) offset limit:(long) limit alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip;
+//+(NSDictionary*)category_addall2portfolio: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword  offset:(long) offset limit:(long) limit alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip;
+
++(NSDictionary*)Search_addall:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull orderCode:(NSString*) orderCode  addTo:(NSString*) addTo;
+
++(NSDictionary*)ItemSearch_addall:(long ) offset limit :(long)limit covertype:(NSString* ) covertype ctgid:(NSString*)ctgid modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller orderCode:(NSString*) orderCode addTo:(NSString*) addTo;
+
+
 //+(NSDictionary*)category_LoadMore: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword offset:(int)offset;
 //+(NSDictionary*)category_LoadMore: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword offset:(int)offset;
 //+(NSData*)fake_json:(NSString*) url;
 //+(NSData*)fake_json:(NSString*) url;
 //+(NSDictionary*)request_ItemDetail: (NSString* ) item_id category_id:(NSString*) category_id price_template:(int) price_template customid:(int) customid;
 //+(NSDictionary*)request_ItemDetail: (NSString* ) item_id category_id:(NSString*) category_id price_template:(int) price_template customid:(int) customid;

+ 268 - 2
RedAnt ERP Mobile/common/data_provider/iSalesNetwork.m

@@ -2436,6 +2436,167 @@ repeat:
 //    return jsobj;
 //    return jsobj;
 //
 //
 //}
 //}
++(NSDictionary*)Category_addall: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword  offset:(long) offset limit:(long) limit alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip orderCode:(NSString*) orderCode addTo:(NSString*) addTo
+
+{
+    
+    
+    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+    
+    
+    NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
+    
+    if(appDelegate.user!=nil)
+        [params setValue:appDelegate.user forKey:@"user"];
+    if(appDelegate.contact_id!=nil)
+        [params setValue:appDelegate.contact_id forKey:@"contactId"];
+    if(appDelegate.password!=nil)
+        [params setValue:appDelegate.password forKey:@"password"];
+    if(appDelegate.order_code!=nil)
+        [params setValue:appDelegate.order_code forKey:@"orderCode"];
+    
+    [params setValue:addTo forKey:@"addTo"];
+    [params setValue:orderCode forKey:@"orderCode"];
+    [params setValue:alert forKey:@"alert"];
+    [params setValue:qty forKey:@"sold_by_qty"];
+    [params setValue:available forKey:@"available"];
+    [params setValue:price forKey:@"price"];
+    [params setValue:bestseller forKey:@"bestseller"];
+    [params setValue:modelname forKey:@"modelName"];
+    [params setValue:modeldescrip forKey:@"modelDescription"];
+    
+    [params setValue:[NSString stringWithFormat:@"%d",price_template]  forKey:@"price_template"];
+    [params setValue:[NSString stringWithFormat:@"%d",customid]  forKey:@"custom_id"];
+    [params setValue:category  forKey:@"category"];
+    [params setValue:[NSString stringWithFormat:@"%d",sort_by]  forKey:@"sort_by"];
+    [params setValue:[NSString stringWithFormat:@"%d",sort_by]  forKey:@"sort_by"];
+    [params setValue:[NSString stringWithFormat:@"%ld",limit]  forKey:@"limit"];
+    [params setValue:[NSString stringWithFormat:@"%ld",offset]  forKey:@"offset"];
+    [params setValue:filter forKey:@"filter"];
+    [params setValue:keyword forKey:@"keyword"];
+    
+    NSData* json= nil;
+    
+    if(appDelegate.offline_mode)
+    {
+        json= [OLDataProvider offline_categoryaddall:params];
+    }
+    else
+    {
+    if(![self IsNetworkAvailable])
+        return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
+    
+    json=[self get_json:URL_CATEGORYADDALL parameters:params];
+    }
+    if(json==nil)
+        return nil;
+    NSError *error=nil;
+    NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
+    return jsobj;
+    
+}
+//+(NSDictionary*)category_addall2portfolio: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword  offset:(long) offset limit:(long) limit alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip
+//{
+//    
+//    
+//    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+//    
+//    
+//    NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
+//    
+//    if(appDelegate.user!=nil)
+//        [params setValue:appDelegate.user forKey:@"user"];
+//    if(appDelegate.contact_id!=nil)
+//        [params setValue:appDelegate.contact_id forKey:@"contactId"];
+//    if(appDelegate.password!=nil)
+//        [params setValue:appDelegate.password forKey:@"password"];
+//    if(appDelegate.order_code!=nil)
+//        [params setValue:appDelegate.order_code forKey:@"orderCode"];
+//    
+//    [params setValue:alert forKey:@"alert"];
+//    [params setValue:qty forKey:@"sold_by_qty"];
+//    [params setValue:available forKey:@"available"];
+//    [params setValue:price forKey:@"price"];
+//    [params setValue:bestseller forKey:@"bestseller"];
+//    [params setValue:modelname forKey:@"modelName"];
+//    [params setValue:modeldescrip forKey:@"modelDescription"];
+//    
+//    [params setValue:[NSString stringWithFormat:@"%d",price_template]  forKey:@"price_template"];
+//    [params setValue:[NSString stringWithFormat:@"%d",customid]  forKey:@"custom_id"];
+//    [params setValue:category  forKey:@"category"];
+//    [params setValue:[NSString stringWithFormat:@"%d",sort_by]  forKey:@"sort_by"];
+//    [params setValue:[NSString stringWithFormat:@"%d",sort_by]  forKey:@"sort_by"];
+//    [params setValue:[NSString stringWithFormat:@"%ld",limit]  forKey:@"limit"];
+//    [params setValue:[NSString stringWithFormat:@"%ld",offset]  forKey:@"offset"];
+//    [params setValue:filter forKey:@"filter"];
+//    [params setValue:keyword forKey:@"keyword"];
+//    
+//    
+//    
+//    if(appDelegate.offline_mode)
+//        return [OLDataProvider offline_category:params];
+//    if(![self IsNetworkAvailable])
+//        return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
+//    
+//    NSData* json=[self get_json:URL_ADDALL2PORTFOLIO parameters:params];
+//    if(json==nil)
+//        return nil;
+//    NSError *error=nil;
+//    NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
+//    return jsobj;
+//    
+//}
+//+(NSDictionary*)category_addall2wish: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword  offset:(long) offset limit:(long) limit alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip
+//{
+//    
+//    
+//    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+//    
+//    
+//    NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
+//    
+//    if(appDelegate.user!=nil)
+//        [params setValue:appDelegate.user forKey:@"user"];
+//    if(appDelegate.contact_id!=nil)
+//        [params setValue:appDelegate.contact_id forKey:@"contactId"];
+//    if(appDelegate.password!=nil)
+//        [params setValue:appDelegate.password forKey:@"password"];
+//    if(appDelegate.order_code!=nil)
+//        [params setValue:appDelegate.order_code forKey:@"orderCode"];
+//    
+//    [params setValue:alert forKey:@"alert"];
+//    [params setValue:qty forKey:@"sold_by_qty"];
+//    [params setValue:available forKey:@"available"];
+//    [params setValue:price forKey:@"price"];
+//    [params setValue:bestseller forKey:@"bestseller"];
+//    [params setValue:modelname forKey:@"modelName"];
+//    [params setValue:modeldescrip forKey:@"modelDescription"];
+//    
+//    [params setValue:[NSString stringWithFormat:@"%d",price_template]  forKey:@"price_template"];
+//    [params setValue:[NSString stringWithFormat:@"%d",customid]  forKey:@"custom_id"];
+//    [params setValue:category  forKey:@"category"];
+//    [params setValue:[NSString stringWithFormat:@"%d",sort_by]  forKey:@"sort_by"];
+//    [params setValue:[NSString stringWithFormat:@"%d",sort_by]  forKey:@"sort_by"];
+//    [params setValue:[NSString stringWithFormat:@"%ld",limit]  forKey:@"limit"];
+//    [params setValue:[NSString stringWithFormat:@"%ld",offset]  forKey:@"offset"];
+//    [params setValue:filter forKey:@"filter"];
+//    [params setValue:keyword forKey:@"keyword"];
+//    
+//    
+//    
+//    if(appDelegate.offline_mode)
+//        return [OLDataProvider offline_category:params];
+//    if(![self IsNetworkAvailable])
+//        return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
+//    
+//    NSData* json=[self get_json:URL_ADDALL2WISH parameters:params];
+//    if(json==nil)
+//        return nil;
+//    NSError *error=nil;
+//    NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
+//    return jsobj;
+//    
+//}
 +(NSDictionary*)Category: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword  offset:(long) offset limit:(long) limit alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip
 +(NSDictionary*)Category: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword  offset:(long) offset limit:(long) limit alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip
 {
 {
     
     
@@ -2487,7 +2648,56 @@ repeat:
     return jsobj;
     return jsobj;
     
     
 }
 }
-
++(NSDictionary*)Search_addall:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull orderCode:(NSString*) orderCode  addTo:(NSString*) addTo
+{
+    
+    
+    
+    
+    NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
+    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+    if(appDelegate.user!=nil)
+        [params setValue:appDelegate.user forKey:@"user"];
+    if(appDelegate.contact_id!=nil)
+        [params setValue:appDelegate.contact_id forKey:@"contactId"];
+    if(appDelegate.password!=nil)
+        [params setValue:appDelegate.password forKey:@"password"];
+    if(appDelegate.order_code!=nil)
+        [params setValue:appDelegate.order_code forKey:@"orderCode"];
+    //    [params setValue:[NSString stringWithFormat:@"%d",price_template]  forKey:@"price_template"];
+    //    [params setValue:[NSString stringWithFormat:@"%d",customid]  forKey:@"custom_id"];
+    //    [params setValue:[NSString stringWithFormat:@"%@",category]  forKey:@"category"];
+    //    [params setValue:[NSString stringWithFormat:@"%d",sort_by]  forKey:@"sort_by"];
+    //    [params setValue:filter forKey:@"filter"];
+    [params setValue:keywords forKey:@"keyword"];
+    [params setValue:addTo forKey:@"addTo"];
+    
+    [params setValue:orderCode forKey:@"orderCode"];
+    [params setValue:[NSString stringWithFormat:@"%ld",limit]  forKey:@"limit"];
+    [params setValue:[NSString stringWithFormat:@"%ld",offset]  forKey:@"offset"];
+    if(matchfull)
+        [params setValue:@"true"  forKey:@"exactMatch"];
+    else
+        [params setValue:@"false"  forKey:@"exactMatch"];
+    
+    NSData* json=nil;
+    if(appDelegate.offline_mode)
+    {
+        json=[OLDataProvider offline_searchaddall:params];
+    }
+    else
+    {
+    if(![self IsNetworkAvailable])
+        return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
+    
+    json=[self get_json:URL_SEARCHADDALL parameters:params];
+    }
+    if(json==nil)
+        return nil;
+    NSError *error=nil;
+    NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
+    return jsobj;
+}
 +(NSDictionary*)Search:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull
 +(NSDictionary*)Search:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull
 {
 {
     
     
@@ -2531,7 +2741,63 @@ repeat:
     NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
     NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
     return jsobj;
     return jsobj;
 }
 }
-
++(NSDictionary*)ItemSearch_addall:(long ) offset limit :(long)limit covertype:(NSString* ) covertype ctgid:(NSString*)ctgid modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller orderCode:(NSString*) orderCode addTo:(NSString*) addTo
+{
+    
+    // for debug
+    //    return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
+    //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
+    
+    NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
+    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+    if(appDelegate.user!=nil)
+        [params setValue:appDelegate.user forKey:@"user"];
+    if(appDelegate.contact_id!=nil)
+        [params setValue:appDelegate.contact_id forKey:@"contactId"];
+    if(appDelegate.password!=nil)
+        [params setValue:appDelegate.password forKey:@"password"];
+    if(appDelegate.order_code!=nil)
+        [params setValue:appDelegate.order_code forKey:@"orderCode"];
+    
+        [params setValue:addTo forKey:@"addTo"];
+    
+    [params setValue:orderCode forKey:@"orderCode"];
+    
+    //    [params setValue:[NSString stringWithFormat:@"%d",price_template]  forKey:@"price_template"];
+    //    [params setValue:[NSString stringWithFormat:@"%d",customid]  forKey:@"custom_id"];
+    //    [params setValue:[NSString stringWithFormat:@"%@",category]  forKey:@"category"];
+    //    [params setValue:[NSString stringWithFormat:@"%d",sort_by]  forKey:@"sort_by"];
+    //    [params setValue:filter forKey:@"filter"];
+    [params setValue:covertype forKey:@"covertype"];
+    [params setValue:ctgid forKey:@"ctgId"];
+    [params setValue:modelname forKey:@"modelName"];
+    [params setValue:modeldescrip forKey:@"modelDescription"];
+    [params setValue:alert forKey:@"alert"];
+    [params setValue:qty forKey:@"sold_by_qty"];
+    [params setValue:available forKey:@"available"];
+    [params setValue:price forKey:@"price"];
+    [params setValue:bestseller forKey:@"bestseller"];
+    
+    [params setValue:[NSString stringWithFormat:@"%ld",limit]  forKey:@"limit"];
+    [params setValue:[NSString stringWithFormat:@"%ld",offset]  forKey:@"offset"];
+    NSData* json = nil;
+    
+    if(appDelegate.offline_mode)
+    {
+        json= [OLDataProvider offline_itemsearchaddall:params];
+    }
+    else
+    {
+    if(![self IsNetworkAvailable])
+        return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
+     json=[self get_json:URL_ITEMSEARCHADDALL parameters:params];
+    }
+    if(json==nil)
+        return nil;
+    NSError *error=nil;
+    NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
+    return jsobj;
+}
 +(NSDictionary*)ItemSearch:(long ) offset limit :(long)limit covertype:(NSString* ) covertype ctgid:(NSString*)ctgid modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller
 +(NSDictionary*)ItemSearch:(long ) offset limit :(long)limit covertype:(NSString* ) covertype ctgid:(NSString*)ctgid modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller
 {
 {
     
     

+ 291 - 278
RedAnt ERP Mobile/iSales-NPD/AppDelegate.m

@@ -437,7 +437,7 @@
     NSString *cachefolder = [paths objectAtIndex:0];
     NSString *cachefolder = [paths objectAtIndex:0];
     
     
     NSString *upfolder = [cachefolder stringByAppendingPathComponent:@"upload_data"];
     NSString *upfolder = [cachefolder stringByAppendingPathComponent:@"upload_data"];
- //   upfolder = [upfolder stringByAppendingPathComponent:serial];
+    //   upfolder = [upfolder stringByAppendingPathComponent:serial];
     
     
     NSFileManager* fileManager = [NSFileManager defaultManager];
     NSFileManager* fileManager = [NSFileManager defaultManager];
     BOOL bdir=YES;
     BOOL bdir=YES;
@@ -459,7 +459,7 @@
     //    }
     //    }
     
     
     
     
-
+    
     
     
     
     
     //    NSString* order_filter_source_path =[[NSBundle mainBundle]  pathForResource:@"status_filter_cadedate" ofType:@"json" ];
     //    NSString* order_filter_source_path =[[NSBundle mainBundle]  pathForResource:@"status_filter_cadedate" ofType:@"json" ];
@@ -553,8 +553,8 @@
     }
     }
     
     
     
     
-//    [self test_descrypt];
-//    [self test_descrypt1];
+    //    [self test_descrypt];
+    //    [self test_descrypt1];
     //UILabel * appearanceLabel = [UILabel appearanceWhenContainedIn:uialertcontroller.class, nil];
     //UILabel * appearanceLabel = [UILabel appearanceWhenContainedIn:uialertcontroller.class, nil];
     //  [appearanceLabel setAppearanceFont:[UIFont boldSystemFontOfSize:10]]; //for example
     //  [appearanceLabel setAppearanceFont:[UIFont boldSystemFontOfSize:10]]; //for example
     return YES;
     return YES;
@@ -562,79 +562,79 @@
 //-(void)test_descrypt
 //-(void)test_descrypt
 //{
 //{
 //    sqlite3 *db = [iSalesDB get_db];
 //    sqlite3 *db = [iSalesDB get_db];
-//    
+//
 //   int result= [iSalesDB AddExFunction:db];
 //   int result= [iSalesDB AddExFunction:db];
-//    
+//
 //    NSString *sqlQuery = [NSString stringWithFormat:@"select decrypt(company_name) from offline_contact;"];
 //    NSString *sqlQuery = [NSString stringWithFormat:@"select decrypt(company_name) from offline_contact;"];
 //    sqlite3_stmt * statement;
 //    sqlite3_stmt * statement;
-//    
-//    
+//
+//
 //    if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
 //    if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
 //    {
 //    {
-//        
-//        
+//
+//
 //        while (sqlite3_step(statement) == SQLITE_ROW)
 //        while (sqlite3_step(statement) == SQLITE_ROW)
 //        {
 //        {
-//           
-//            
+//
+//
 //            char *url = (char*)sqlite3_column_text(statement, 0);
 //            char *url = (char*)sqlite3_column_text(statement, 0);
 //            if(url==nil)
 //            if(url==nil)
 //                url="";
 //                url="";
 //            NSString *nsurl = [[NSString alloc]initWithUTF8String:url];
 //            NSString *nsurl = [[NSString alloc]initWithUTF8String:url];
 //            NSLog(nsurl);
 //            NSLog(nsurl);
-//            
-//            
-//           
-//            
+//
+//
+//
+//
 //        }
 //        }
 //      //  [ret setValue:[NSString stringWithFormat:@"%d",i] forKey:@"img_count"];
 //      //  [ret setValue:[NSString stringWithFormat:@"%d",i] forKey:@"img_count"];
-//        
-//        
+//
+//
 //        sqlite3_finalize(statement);
 //        sqlite3_finalize(statement);
 //    }
 //    }
-//    
+//
 //    [iSalesDB close_db:db];
 //    [iSalesDB close_db:db];
 //}
 //}
 //
 //
 //-(void)test_descrypt1
 //-(void)test_descrypt1
 //{
 //{
 //    sqlite3 *db = [iSalesDB get_db];
 //    sqlite3 *db = [iSalesDB get_db];
-//    
+//
 //    int result= [iSalesDB AddExFunction:db];
 //    int result= [iSalesDB AddExFunction:db];
-//    
+//
 //    NSString* sqlindex= @"CREATE INDEX hijk ON offline_contact (lower(company_name));";
 //    NSString* sqlindex= @"CREATE INDEX hijk ON offline_contact (lower(company_name));";
-//    
+//
 //    [iSalesDB execSql:sqlindex];
 //    [iSalesDB execSql:sqlindex];
-////    
+////
 ////    NSString *sqlQuery = [NSString stringWithFormat:@"select decrypt(company_name) from offline_contact;"];
 ////    NSString *sqlQuery = [NSString stringWithFormat:@"select decrypt(company_name) from offline_contact;"];
 ////    sqlite3_stmt * statement;
 ////    sqlite3_stmt * statement;
-////    
-////    
-////    
+////
+////
+////
 ////    if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
 ////    if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
 ////    {
 ////    {
-////        
-////        
+////
+////
 ////        while (sqlite3_step(statement) == SQLITE_ROW)
 ////        while (sqlite3_step(statement) == SQLITE_ROW)
 ////        {
 ////        {
-////            
-////            
+////
+////
 ////            char *url = (char*)sqlite3_column_text(statement, 0);
 ////            char *url = (char*)sqlite3_column_text(statement, 0);
 ////            if(url==nil)
 ////            if(url==nil)
 ////                url="";
 ////                url="";
 ////            NSString *nsurl = [[NSString alloc]initWithUTF8String:url];
 ////            NSString *nsurl = [[NSString alloc]initWithUTF8String:url];
 ////            NSLog(nsurl);
 ////            NSLog(nsurl);
-////            
-////            
-////            
-////            
+////
+////
+////
+////
 ////        }
 ////        }
 ////        //  [ret setValue:[NSString stringWithFormat:@"%d",i] forKey:@"img_count"];
 ////        //  [ret setValue:[NSString stringWithFormat:@"%d",i] forKey:@"img_count"];
-////        
-////        
+////
+////
 ////        sqlite3_finalize(statement);
 ////        sqlite3_finalize(statement);
 ////    }
 ////    }
-//    
+//
 //    [iSalesDB close_db:db];
 //    [iSalesDB close_db:db];
 //}
 //}
 
 
@@ -774,7 +774,7 @@
 {
 {
     [self add_downloadlog:@"Begin sync, please wait."];
     [self add_downloadlog:@"Begin sync, please wait."];
     [self add_downloadlog:@"Prepare upload data."];
     [self add_downloadlog:@"Prepare upload data."];
- //   NSArray* arr_order=[OLDataProvider enumOfflineOrder];
+    //   NSArray* arr_order=[OLDataProvider enumOfflineOrder];
     NSDictionary* upjson=[OLDataProvider prepareUpload:arr_order];
     NSDictionary* upjson=[OLDataProvider prepareUpload:arr_order];
     
     
     NSString* upfile=upjson[@"file"];
     NSString* upfile=upjson[@"file"];
@@ -853,10 +853,15 @@
                     [iSalesDB execSql:@"delete from wishlist"];
                     [iSalesDB execSql:@"delete from wishlist"];
                     [iSalesDB execSql:[NSString stringWithFormat:@"delete from offline_order where so_id=in(%@)",so_id]];
                     [iSalesDB execSql:[NSString stringWithFormat:@"delete from offline_order where so_id=in(%@)",so_id]];
                     [iSalesDB execSql:[NSString stringWithFormat:@"delete from offline_cart where so_no=in(%@)",so_id]];
                     [iSalesDB execSql:[NSString stringWithFormat:@"delete from offline_cart where so_no=in(%@)",so_id]];
-//                    NSDictionary* contactjson= upjson[@"contact"];
-//                    NSDictionary* wishlistjson= upjson[@"wishlist"];
-//                    NSDictionary* orderjson= upjson[@"order"];
+                    //                    NSDictionary* contactjson= upjson[@"contact"];
+                    //                    NSDictionary* wishlistjson= upjson[@"wishlist"];
+                    //                    NSDictionary* orderjson= upjson[@"order"];
+                    
                     
                     
+                    NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
+                    [defaults removeObjectForKey:@"Forcedownload"];
+                    [defaults setValue:@"true" forKey:@"Forcedownload"];
+                    [defaults synchronize];
                     
                     
                     [self download_offline:ver useInternalAddress:buseinternaladdress];
                     [self download_offline:ver useInternalAddress:buseinternaladdress];
                     
                     
@@ -874,7 +879,7 @@
         
         
         
         
         
         
-
+        
         
         
         
         
         
         
@@ -883,7 +888,7 @@
     }
     }
     
     
     
     
-
+    
     return;
     return;
 }
 }
 -(void) download_offline:(NSString*) ver useInternalAddress:(bool)buseinternaladdress
 -(void) download_offline:(NSString*) ver useInternalAddress:(bool)buseinternaladdress
@@ -891,11 +896,11 @@
     if(self.downloading)
     if(self.downloading)
         return;
         return;
     
     
-         self.downloading=true;
+    self.downloading=true;
     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
         
         
         
         
-
+        
         NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
         NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
         
         
         NSString*  pvid = [defaults stringForKey:@"vid"] ;
         NSString*  pvid = [defaults stringForKey:@"vid"] ;
@@ -938,7 +943,7 @@
             count++;
             count++;
             download_json=[[iSalesNetwork  download_Offline:downSerial] mutableCopy];
             download_json=[[iSalesNetwork  download_Offline:downSerial] mutableCopy];
             
             
-
+            
             
             
             
             
         }
         }
@@ -987,7 +992,10 @@
 }
 }
 -(void) check_offline:(NSString*) ver useInternalAddress:(bool)buseinternaladdress parentvc:(UIViewController*) parent
 -(void) check_offline:(NSString*) ver useInternalAddress:(bool)buseinternaladdress parentvc:(UIViewController*) parent
 {
 {
- 
+    
+    
+    
+    
     NSArray* arr_order=[OLDataProvider enumOfflineOrder];
     NSArray* arr_order=[OLDataProvider enumOfflineOrder];
     if(arr_order.count>0)
     if(arr_order.count>0)
     {
     {
@@ -1038,7 +1046,7 @@
     else
     else
         [self upload_offline:ver useInternalAddress:buseinternaladdress orderid:nil];
         [self upload_offline:ver useInternalAddress:buseinternaladdress orderid:nil];
     
     
-
+    
     
     
     
     
     
     
@@ -1049,256 +1057,261 @@
 {
 {
     if(start)
     if(start)
     {
     {
-    [ [ UIApplication sharedApplication] setIdleTimerDisabled:YES ] ;
-    
-        long long size= [[self.download_task valueForKey:@"size"] longLongValue] /1024/1024;
-//        [self add_downloadlog:[NSString stringWithFormat:@"Total size %lldMB",size]];
-    long long freespace=[RAUtils freeDiskSpaceInMegaBytes];
-    long long needsize = size+500;
-    if(needsize>freespace &&checkdiskspace)
-    {
-        //size not enough.
-        NSString* space=[NSString stringWithFormat:@"Disk space not enough, need %lldMB free space at least, current free space %lldMB",needsize,freespace];
-        
-        [self add_downloadlog:space];
-        [self.settingUI onSyncFinish];
-
-        
-        return ;
-    }
-    
-    NSString* temp = NSTemporaryDirectory();
-    
-    
-    NSString * ver = self.download_task[@"ver"];
-    
-    NSString *tempfolder = [temp stringByAppendingPathComponent:ver];
-    
-    //创建版本临时目录
-    NSFileManager* fileManager = [NSFileManager defaultManager];
-    BOOL bdir=YES;
-    if(!  [fileManager fileExistsAtPath:tempfolder isDirectory:&bdir])
-    {
+        [ [ UIApplication sharedApplication] setIdleTimerDisabled:YES ] ;
         
         
-        NSError *error = nil;
-        bool bsuccess=[fileManager createDirectoryAtPath:tempfolder withIntermediateDirectories:YES attributes:nil error:&error];
+        long long size= [[self.download_task valueForKey:@"size"] longLongValue] /1024/1024;
+        //        [self add_downloadlog:[NSString stringWithFormat:@"Total size %lldMB",size]];
+        long long freespace=[RAUtils freeDiskSpaceInMegaBytes];
+        long long needsize = size+500;
+        if(needsize>freespace &&checkdiskspace)
+        {
+            //size not enough.
+            NSString* space=[NSString stringWithFormat:@"Disk space not enough, need %lldMB free space at least, current free space %lldMB",needsize,freespace];
+            
+            [self add_downloadlog:space];
+            [self.settingUI onSyncFinish];
+            
+            
+            return ;
+        }
         
         
-        if(!bsuccess)
-            DebugLog(@"Create temp folder failed");
+        NSString* temp = NSTemporaryDirectory();
         
         
-        //        if(bsuccess)
-        //        {
-        //            sqlite3 *db = [self get_db];
-        //
-        //            [self execSql:[NSString stringWithFormat:@"insert into img_cache(name) values('%@')",name] db:db];
-        //            [iSalesDB close_db:db];
-        //        }
-    }
-    
-    NSString* cachefolder=[NSString stringWithFormat:@"%@/image_cache/",ver];
-    
-    NSString *imagecache = [temp stringByAppendingPathComponent:cachefolder];
-    if(!  [fileManager fileExistsAtPath:imagecache isDirectory:&bdir])
-    {
         
         
-        NSError *error = nil;
-        bool bsuccess=[fileManager createDirectoryAtPath:imagecache withIntermediateDirectories:YES attributes:nil error:&error];
-        
-        if(!bsuccess)
-            DebugLog(@"Create cache folder failed");
+        NSString * ver = self.download_task[@"ver"];
         
         
-    }
-    
-    
-    NSString* resourcefolder=[NSString stringWithFormat:@"%@/offline_data/",ver];
-    
-    NSString *resource = [temp stringByAppendingPathComponent:resourcefolder];
-//    if(!  [fileManager fileExistsAtPath:resource isDirectory:&bdir])
-//    {
-//        
-//        NSError *error = nil;
-//        bool bsuccess=[fileManager createDirectoryAtPath:resource withIntermediateDirectories:YES attributes:nil error:&error];
-//        
-//        if(!bsuccess)
-//            DebugLog(@"Create resource folder failed");
-//        
-//    }
-    
-    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
-    NSString *documents = /*[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];*/[paths objectAtIndex:0];
-    NSString *database_path = [documents stringByAppendingPathComponent:DBNAME];
-    
-    NSString* tempdb=[NSString stringWithFormat:@"%@%@/%@",temp,ver,DBNAME];
-    //    tempdb=[documents stringByAppendingPathComponent:DBNAME];
-    NSError *error = nil;
-    bdir=NO;
-    if(!  [fileManager fileExistsAtPath:tempdb isDirectory:&bdir])
-    {
-    //    [iSalesDB execSql:@"PRAGMA journal_mode = DELETE;"];
+        NSString *tempfolder = [temp stringByAppendingPathComponent:ver];
         
         
-        if(![fileManager copyItemAtPath:database_path toPath:tempdb error:&error])
+        //创建版本临时目录
+        NSFileManager* fileManager = [NSFileManager defaultManager];
+        BOOL bdir=YES;
+        if(!  [fileManager fileExistsAtPath:tempfolder isDirectory:&bdir])
         {
         {
-            DebugLog(@"copy database failed");
+            
+            NSError *error = nil;
+            bool bsuccess=[fileManager createDirectoryAtPath:tempfolder withIntermediateDirectories:YES attributes:nil error:&error];
+            
+            if(!bsuccess)
+                DebugLog(@"Create temp folder failed");
+            
+            //        if(bsuccess)
+            //        {
+            //            sqlite3 *db = [self get_db];
+            //
+            //            [self execSql:[NSString stringWithFormat:@"insert into img_cache(name) values('%@')",name] db:db];
+            //            [iSalesDB close_db:db];
+            //        }
         }
         }
-    }
-    bdir=YES;
-    error=nil;
-    int count = [[self.download_task valueForKey:@"count"] intValue];
-    bool alldone=true;
-    bool trouble=false;
-    for (int i = 0;i<count;i++)
-    {
-        NSDictionary* itemjson = [self.download_task objectForKey:[NSString stringWithFormat:@"item_%d",i]];
-        NSString* url = [itemjson valueForKey:@"url"];
-        NSString* type = [itemjson valueForKey:@"type"];
         
         
-        NSString* status = itemjson[@"status"];
-        //bool finish = [[itemjson valueForKey:@"finish"] boolValue];
-        if(! [status isEqualToString:@"finish"])
+        NSString* cachefolder=[NSString stringWithFormat:@"%@/image_cache/",ver];
+        
+        NSString *imagecache = [temp stringByAppendingPathComponent:cachefolder];
+        if(!  [fileManager fileExistsAtPath:imagecache isDirectory:&bdir])
         {
         {
             
             
-            if([itemjson[@"retry"] intValue]<DOWNLOAD_RETRY_TIMES)
-            {
-            [self handle_download:url start:start  type:type taskid:i];
-            alldone=false;
-            break;
-            }
-            else
-            {
-                alldone=false;
-                trouble=true;
-                break;
-            }
+            NSError *error = nil;
+            bool bsuccess=[fileManager createDirectoryAtPath:imagecache withIntermediateDirectories:YES attributes:nil error:&error];
+            
+            if(!bsuccess)
+                DebugLog(@"Create cache folder failed");
+            
         }
         }
         
         
-    }
-    if(trouble)
-    {
-        [self add_downloadlog:@"offline sync got some trouble, sync canceled."];
-            dispatch_async(dispatch_get_main_queue(), ^{
-//        self.downloadlog=nil;
-        self.downloading=false;
-        });
-                [self.settingUI onSyncFinish];
-    }
-    else if(alldone)
-    {
-        
-        [self add_downloadlog:@"Finalizing download..."];
-        //全部下载完成;
-        //写入当前版本
-        
-        
-        NSDateFormatter* formatter = [[NSDateFormatter alloc]init];
-        [formatter setDateFormat:@"MM/dd/yyyy HH:mm:ss"];
-        NSString* lastsync = [formatter stringFromDate:[NSDate date]];
         
         
+        NSString* resourcefolder=[NSString stringWithFormat:@"%@/offline_data/",ver];
         
         
-        
-        NSString* ver= self.download_task[@"ver"];
-        NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
-        [defaults removeObjectForKey:@"OfflineVer"];
-        [defaults setValue:ver forKey:@"OfflineVer"];
-        [defaults removeObjectForKey:@"LastSync"];
-        [defaults setValue:lastsync forKey:@"LastSync"];
-        [defaults removeObjectForKey:@"vid"];
-        [defaults setValue:self.vid forKey:@"vid"];
-        
-        [defaults synchronize];
-        
-
+        NSString *resource = [temp stringByAppendingPathComponent:resourcefolder];
+        //    if(!  [fileManager fileExistsAtPath:resource isDirectory:&bdir])
+        //    {
+        //
+        //        NSError *error = nil;
+        //        bool bsuccess=[fileManager createDirectoryAtPath:resource withIntermediateDirectories:YES attributes:nil error:&error];
+        //
+        //        if(!bsuccess)
+        //            DebugLog(@"Create resource folder failed");
+        //
+        //    }
         
         
         NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
         NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
-        NSString *cachefolder = [paths objectAtIndex:0];
-        NSString *img_cache = [cachefolder stringByAppendingPathComponent:@"img_cache"];
-         //NSString *cached_offline_data = [cachefolder stringByAppendingPathComponent:@"offline_data"];
-
-        if(![RAUtils mergeContentsOfPath:imagecache intoPath:img_cache error:&error])
-        {
-            DebugLog(@"move image folder failed");
-            [self add_downloadlog:@"move image folder failed"];
-            trouble=true;
-        }
-        else
-        {
-            DebugLog(@"move image folder successful");
-        }
-        error=nil;
+        NSString *documents = /*[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];*/[paths objectAtIndex:0];
+        NSString *database_path = [documents stringByAppendingPathComponent:DBNAME];
         
         
-        
-        // copy temp db to cache.
-        if( [fileManager fileExistsAtPath:database_path isDirectory:&bdir])
+        NSString* tempdb=[NSString stringWithFormat:@"%@%@/%@",temp,ver,DBNAME];
+        //    tempdb=[documents stringByAppendingPathComponent:DBNAME];
+        NSError *error = nil;
+        bdir=NO;
+        if(!  [fileManager fileExistsAtPath:tempdb isDirectory:&bdir])
         {
         {
+            //    [iSalesDB execSql:@"PRAGMA journal_mode = DELETE;"];
             
             
-            if(![fileManager removeItemAtPath:database_path error:nil])
+            if(![fileManager copyItemAtPath:database_path toPath:tempdb error:&error])
             {
             {
-                DebugLog(@"delete database failed");
+                DebugLog(@"copy database failed");
             }
             }
-            else
+        }
+        bdir=YES;
+        error=nil;
+        int count = [[self.download_task valueForKey:@"count"] intValue];
+        bool alldone=true;
+        bool trouble=false;
+        for (int i = 0;i<count;i++)
+        {
+            NSDictionary* itemjson = [self.download_task objectForKey:[NSString stringWithFormat:@"item_%d",i]];
+            NSString* url = [itemjson valueForKey:@"url"];
+            NSString* type = [itemjson valueForKey:@"type"];
+            
+            NSString* status = itemjson[@"status"];
+            //bool finish = [[itemjson valueForKey:@"finish"] boolValue];
+            if(! [status isEqualToString:@"finish"])
             {
             {
-                if(![fileManager copyItemAtPath:tempdb toPath:database_path error:&error])
+                
+                if([itemjson[@"retry"] intValue]<DOWNLOAD_RETRY_TIMES)
                 {
                 {
-                    DebugLog(@"copy database failed");
-                    [self add_downloadlog:@"copy database failed"];
-                    trouble=true;
-                    
+                    [self handle_download:url start:start  type:type taskid:i];
+                    alldone=false;
+                    break;
                 }
                 }
-                else{
-                    BOOL blDele= [fileManager removeItemAtPath:tempdb error:nil];
-               //     [iSalesDB execSql:@"PRAGMA journal_mode = WAL;"];
+                else
+                {
+                    alldone=false;
+                    trouble=true;
+                    break;
                 }
                 }
             }
             }
+            
         }
         }
-        else if(![fileManager copyItemAtPath:tempdb toPath:database_path error:&error])
-        {
-            DebugLog(@"copy database failed");
-            BOOL blDele= [fileManager removeItemAtPath:tempdb error:nil];
-            [self add_downloadlog:@"copy database failed"];
-            trouble=true;
-        }
-        
-//        if(![RAUtils mergeContentsOfPath:tempdb intoPath:database_path error:&error])
-//        {
-//            DebugLog(@"move db file failed");
-//        }
-//        else
-//        {
-//            DebugLog(@"move db file successful");
-//        }
-        error=nil;
-        if(![RAUtils mergeContentsOfPath:resource intoPath:cachefolder error:&error])
-        {
-            DebugLog(@"move data folder failed");
-            [self add_downloadlog:@"move data folder failed"];
-            trouble=true;
-        }
-        else
-        {
-            DebugLog(@"move data folder successful");
-        }
-
-        
-        [ [ UIApplication sharedApplication] setIdleTimerDisabled:NO ] ;
-        
-
         if(trouble)
         if(trouble)
         {
         {
-            [self add_downloadlog:@"offline sync failed."];
-            // 尚缺更新失败还原逻辑。
+            [self add_downloadlog:@"offline sync got some trouble, sync canceled."];
+            dispatch_async(dispatch_get_main_queue(), ^{
+                //        self.downloadlog=nil;
+                self.downloading=false;
+            });
+            [self.settingUI onSyncFinish];
         }
         }
-        else
+        else if(alldone)
         {
         {
-           [self add_downloadlog:@"offline sync complete."];
+            
+            [self add_downloadlog:@"Finalizing download..."];
+            //全部下载完成;
+            //写入当前版本
+            
+            
+            NSDateFormatter* formatter = [[NSDateFormatter alloc]init];
+            [formatter setDateFormat:@"MM/dd/yyyy HH:mm:ss"];
+            NSString* lastsync = [formatter stringFromDate:[NSDate date]];
+            
+            
+            
+            NSString* ver= self.download_task[@"ver"];
+            
+            
+            
+            
+            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
+            NSString *cachefolder = [paths objectAtIndex:0];
+            NSString *img_cache = [cachefolder stringByAppendingPathComponent:@"img_cache"];
+            //NSString *cached_offline_data = [cachefolder stringByAppendingPathComponent:@"offline_data"];
+            
+            if(![RAUtils mergeContentsOfPath:imagecache intoPath:img_cache error:&error])
+            {
+                DebugLog(@"move image folder failed");
+                [self add_downloadlog:@"move image folder failed"];
+                trouble=true;
+            }
+            else
+            {
+                DebugLog(@"move image folder successful");
+            }
+            error=nil;
+            
+            
+            // copy temp db to cache.
+            if( [fileManager fileExistsAtPath:database_path isDirectory:&bdir])
+            {
+                
+                if(![fileManager removeItemAtPath:database_path error:nil])
+                {
+                    DebugLog(@"delete database failed");
+                }
+                else
+                {
+                    if(![fileManager copyItemAtPath:tempdb toPath:database_path error:&error])
+                    {
+                        DebugLog(@"copy database failed");
+                        [self add_downloadlog:@"copy database failed"];
+                        trouble=true;
+                        
+                    }
+                    else{
+                        BOOL blDele= [fileManager removeItemAtPath:tempdb error:nil];
+                        //     [iSalesDB execSql:@"PRAGMA journal_mode = WAL;"];
+                    }
+                }
+            }
+            else if(![fileManager copyItemAtPath:tempdb toPath:database_path error:&error])
+            {
+                DebugLog(@"copy database failed");
+                BOOL blDele= [fileManager removeItemAtPath:tempdb error:nil];
+                [self add_downloadlog:@"copy database failed"];
+                trouble=true;
+            }
+            
+            //        if(![RAUtils mergeContentsOfPath:tempdb intoPath:database_path error:&error])
+            //        {
+            //            DebugLog(@"move db file failed");
+            //        }
+            //        else
+            //        {
+            //            DebugLog(@"move db file successful");
+            //        }
+            error=nil;
+            if(![RAUtils mergeContentsOfPath:resource intoPath:cachefolder error:&error])
+            {
+                DebugLog(@"move data folder failed");
+                [self add_downloadlog:@"move data folder failed"];
+                trouble=true;
+            }
+            else
+            {
+                DebugLog(@"move data folder successful");
+            }
+            
+            
+            [ [ UIApplication sharedApplication] setIdleTimerDisabled:NO ] ;
+            
+            
+            if(trouble)
+            {
+                [self add_downloadlog:@"offline sync failed."];
+                // 尚缺更新失败还原逻辑。
+            }
+            else
+            {
+                [self add_downloadlog:@"offline sync complete."];
+                
+                
+                NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
+                [defaults removeObjectForKey:@"OfflineVer"];
+                [defaults setValue:ver forKey:@"OfflineVer"];
+                [defaults removeObjectForKey:@"LastSync"];
+                [defaults setValue:lastsync forKey:@"LastSync"];
+                [defaults removeObjectForKey:@"vid"];
+                [defaults setValue:self.vid forKey:@"vid"];
+                [defaults removeObjectForKey:@"Forcedownload"];
+                [defaults synchronize];
+            }
+            
+            dispatch_async(dispatch_get_main_queue(), ^{
+                //        self.downloadlog=nil;
+                self.downloading=false;
+                self.download_task=nil;
+                self.vid=nil;
+                
+                
+                [self.settingUI onSyncFinish];
+            });
         }
         }
-        
-        dispatch_async(dispatch_get_main_queue(), ^{
-//        self.downloadlog=nil;
-        self.downloading=false;
-        self.download_task=nil;
-        self.vid=nil;
-        [self.settingUI onSyncFinish];
-        });
-    }
     }
     }
     else
     else
     {
     {
@@ -1317,22 +1330,22 @@
                 if([itemjson[@"retry"] intValue]<DOWNLOAD_RETRY_TIMES)
                 if([itemjson[@"retry"] intValue]<DOWNLOAD_RETRY_TIMES)
                 {
                 {
                     [self handle_download:url start:start  type:type taskid:i];
                     [self handle_download:url start:start  type:type taskid:i];
-
+                    
                     break;
                     break;
                 }
                 }
-
+                
             }
             }
             
             
         }
         }
         dispatch_async(dispatch_get_main_queue(), ^{
         dispatch_async(dispatch_get_main_queue(), ^{
-        self.downloading=false;
+            self.downloading=false;
         });
         });
     }
     }
 }
 }
 -(void) add_downloadlog:(NSString*) newtext
 -(void) add_downloadlog:(NSString*) newtext
 {
 {
-//    if(!self.downloading)
-//        return;
+    //    if(!self.downloading)
+    //        return;
     
     
     dispatch_async(dispatch_get_main_queue(), ^{
     dispatch_async(dispatch_get_main_queue(), ^{
         NSString* date;
         NSString* date;
@@ -1398,7 +1411,7 @@
             long long freespace=[RAUtils freeDiskSpaceInMegaBytes];
             long long freespace=[RAUtils freeDiskSpaceInMegaBytes];
             if(freespace<=10)
             if(freespace<=10)
             {
             {
-                                return UNZIP_NO_SPACE;
+                return UNZIP_NO_SPACE;
             }
             }
             [zip UnzipCloseFile];
             [zip UnzipCloseFile];
             //文件损坏,删除文件重试
             //文件损坏,删除文件重试
@@ -1633,7 +1646,7 @@
                 
                 
                 NSString *imagecache = [temp stringByAppendingPathComponent:cachefolder];
                 NSString *imagecache = [temp stringByAppendingPathComponent:cachefolder];
                 
                 
-                    BOOL bdir=YES;
+                BOOL bdir=YES;
                 NSError *error = nil;
                 NSError *error = nil;
                 if(!  [[NSFileManager defaultManager] fileExistsAtPath:imagecache isDirectory:&bdir])
                 if(!  [[NSFileManager defaultManager] fileExistsAtPath:imagecache isDirectory:&bdir])
                 {
                 {
@@ -1648,7 +1661,7 @@
                 //                NSString* backupfolder=[NSString stringWithFormat:@"%@/test.xml",ver];
                 //                NSString* backupfolder=[NSString stringWithFormat:@"%@/test.xml",ver];
                 //                NSString* backup=[temp stringByAppendingPathComponent:backupfolder];
                 //                NSString* backup=[temp stringByAppendingPathComponent:backupfolder];
                 
                 
-//                NSError *error = nil;
+                //                NSError *error = nil;
                 //                NSURL* uf=[NSURL fileURLWithPath:imagecache];
                 //                NSURL* uf=[NSURL fileURLWithPath:imagecache];
                 //               if( [[NSFileManager defaultManager] replaceItemAtURL:[NSURL fileURLWithPath:imagecache]
                 //               if( [[NSFileManager defaultManager] replaceItemAtURL:[NSURL fileURLWithPath:imagecache]
                 //                               withItemAtURL:[NSURL fileURLWithPath:unZipTo]
                 //                               withItemAtURL:[NSURL fileURLWithPath:unZipTo]
@@ -1711,7 +1724,7 @@
                             sqlite3_free(errmsg);
                             sqlite3_free(errmsg);
                         }
                         }
                         
                         
-
+                        
                         
                         
                     }
                     }
                     //提交事务
                     //提交事务
@@ -1738,7 +1751,7 @@
                         
                         
                         
                         
                         
                         
-
+                        
                     }
                     }
                     else
                     else
                     {
                     {
@@ -1764,7 +1777,7 @@
                     
                     
                     
                     
                     sqlite3_close(tdb);
                     sqlite3_close(tdb);
-                   // [iSalesDB close_db:tdb];
+                    // [iSalesDB close_db:tdb];
                     //  [self SelectData];
                     //  [self SelectData];
                 }
                 }
                 
                 
@@ -1775,7 +1788,7 @@
             }
             }
             else if([type isEqualToString:@"resource"])
             else if([type isEqualToString:@"resource"])
             {
             {
-
+                
             }
             }
             int c=self.current_task+1;
             int c=self.current_task+1;
             double t=[ self.download_task[@"count"] doubleValue];
             double t=[ self.download_task[@"count"] doubleValue];
@@ -1787,7 +1800,7 @@
         case UNZIP_NO_SPACE:
         case UNZIP_NO_SPACE:
         {
         {
             [self add_downloadlog:@"Disk space not enough."];
             [self add_downloadlog:@"Disk space not enough."];
-
+            
             break;
             break;
         }
         }
         case UNZIP_OPEN_FAILED:
         case UNZIP_OPEN_FAILED:

+ 5 - 0
RedAnt ERP Mobile/iSales-NPD/config.h

@@ -70,6 +70,11 @@
 
 
 
 
 
 
+#define  URL_CATEGORYADDALL  @"http://192.168.0.126:8080/site/isales/categoryAddAllTo.htm"
+#define  URL_SEARCHADDALL  @"http://192.168.0.126:8080/site/isales/searchAddAllTo.htm"
+#define  URL_ITEMSEARCHADDALL @"http://192.168.0.126:8080/site/isales/itemSearchAddAllTo.htm"
+
+
 #define  URL_ITEM_DETAIL  @"http://192.168.0.126:8080/site/isales/modelDetail.htm"
 #define  URL_ITEM_DETAIL  @"http://192.168.0.126:8080/site/isales/modelDetail.htm"
 
 
 #define  URL_ADD_TO_WATCHLIST  @"http://192.168.0.126:8080/site/isales/addToWishList.htm"
 #define  URL_ADD_TO_WATCHLIST  @"http://192.168.0.126:8080/site/isales/addToWishList.htm"