Преглед изворни кода

160919
Add offline data dirty check.

Ray Zhang пре 9 година
родитељ
комит
b612d269f4

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


+ 63 - 47
RedAnt ERP Mobile/RedAnt ERP Mobile.xcworkspace/xcuserdata/Ray.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@@ -122,11 +122,11 @@
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "iSales-NPD/AppDelegate.m"
-            timestampString = "495880482.155263"
+            timestampString = "495965830.940569"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "1678"
-            endingLineNumber = "1678"
+            startingLineNumber = "1680"
+            endingLineNumber = "1680"
             landmarkName = "-download_offline:checkdiskspace:"
             landmarkType = "5">
          </BreakpointContent>
@@ -138,11 +138,11 @@
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "iSales-NPD/AppDelegate.m"
-            timestampString = "495880482.155263"
+            timestampString = "495965423.823355"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "1318"
-            endingLineNumber = "1318"
+            startingLineNumber = "1319"
+            endingLineNumber = "1319"
             landmarkName = "-check_offline:useInternalAddress:parentvc:"
             landmarkType = "5">
          </BreakpointContent>
@@ -378,11 +378,11 @@
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "iSales-NPD/AppDelegate.m"
-            timestampString = "495880482.155263"
+            timestampString = "495965423.823355"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "1351"
-            endingLineNumber = "1351"
+            startingLineNumber = "1352"
+            endingLineNumber = "1352"
             landmarkName = "-check_offline:useInternalAddress:parentvc:"
             landmarkType = "5">
          </BreakpointContent>
@@ -442,11 +442,11 @@
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "iSales-NPD/AppDelegate.m"
-            timestampString = "495880482.155263"
+            timestampString = "495965830.940569"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "1993"
-            endingLineNumber = "1993"
+            startingLineNumber = "1995"
+            endingLineNumber = "1995"
             landmarkName = "-connectionDidFinishLoading:"
             landmarkType = "5">
          </BreakpointContent>
@@ -458,11 +458,11 @@
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "iSales-NPD/AppDelegate.m"
-            timestampString = "495880482.155263"
+            timestampString = "495965830.940569"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "1980"
-            endingLineNumber = "1980"
+            startingLineNumber = "1982"
+            endingLineNumber = "1982"
             landmarkName = "-connectionDidFinishLoading:"
             landmarkType = "5">
          </BreakpointContent>
@@ -474,11 +474,11 @@
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "iSales-NPD/AppDelegate.m"
-            timestampString = "495880482.155263"
+            timestampString = "495965423.823355"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "1305"
-            endingLineNumber = "1305"
+            startingLineNumber = "1306"
+            endingLineNumber = "1306"
             landmarkName = "-download_offline:useInternalAddress:"
             landmarkType = "5">
          </BreakpointContent>
@@ -506,11 +506,11 @@
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "iSales-NPD/AppDelegate.m"
-            timestampString = "495879102.454128"
+            timestampString = "495965423.823355"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "1137"
-            endingLineNumber = "1137"
+            startingLineNumber = "1138"
+            endingLineNumber = "1138"
             landmarkName = "-upload_offline:useInternalAddress:orderid:"
             landmarkType = "5">
          </BreakpointContent>
@@ -586,11 +586,11 @@
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "iSales-NPD/AppDelegate.m"
-            timestampString = "495947392.153313"
+            timestampString = "495965423.823355"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "1109"
-            endingLineNumber = "1109"
+            startingLineNumber = "1110"
+            endingLineNumber = "1110"
             landmarkName = "-upload_offline:useInternalAddress:orderid:"
             landmarkType = "5">
          </BreakpointContent>
@@ -602,11 +602,11 @@
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "iSales-NPD/AppDelegate.m"
-            timestampString = "495947396.34807"
+            timestampString = "495965423.823355"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "1110"
-            endingLineNumber = "1110"
+            startingLineNumber = "1111"
+            endingLineNumber = "1111"
             landmarkName = "-upload_offline:useInternalAddress:orderid:"
             landmarkType = "5">
          </BreakpointContent>
@@ -618,11 +618,11 @@
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "iSales-NPD/AppDelegate.m"
-            timestampString = "495947400.847702"
+            timestampString = "495965423.823355"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "1125"
-            endingLineNumber = "1125"
+            startingLineNumber = "1126"
+            endingLineNumber = "1126"
             landmarkName = "-upload_offline:useInternalAddress:orderid:"
             landmarkType = "5">
          </BreakpointContent>
@@ -634,11 +634,11 @@
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "iSales-NPD/AppDelegate.m"
-            timestampString = "495947410.163821"
+            timestampString = "495965423.823355"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "1139"
-            endingLineNumber = "1139"
+            startingLineNumber = "1140"
+            endingLineNumber = "1140"
             landmarkName = "-upload_offline:useInternalAddress:orderid:"
             landmarkType = "5">
          </BreakpointContent>
@@ -682,11 +682,11 @@
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "common/data_provider/iSalesDB.m"
-            timestampString = "495963927.215656"
+            timestampString = "495965423.823355"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "693"
-            endingLineNumber = "693"
+            startingLineNumber = "696"
+            endingLineNumber = "696"
             landmarkName = "+initializeDb"
             landmarkType = "5">
          </BreakpointContent>
@@ -694,15 +694,15 @@
       <BreakpointProxy
          BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
          <BreakpointContent
-            shouldBeEnabled = "Yes"
+            shouldBeEnabled = "No"
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "common/data_provider/iSalesDB.m"
-            timestampString = "495963932.025825"
+            timestampString = "495965830.940569"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "734"
-            endingLineNumber = "734"
+            startingLineNumber = "738"
+            endingLineNumber = "738"
             landmarkName = "+initializeDb"
             landmarkType = "5">
          </BreakpointContent>
@@ -710,15 +710,15 @@
       <BreakpointProxy
          BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
          <BreakpointContent
-            shouldBeEnabled = "Yes"
+            shouldBeEnabled = "No"
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "common/data_provider/iSalesDB.m"
-            timestampString = "495963935.571955"
+            timestampString = "495965423.823355"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "43"
-            endingLineNumber = "43"
+            startingLineNumber = "44"
+            endingLineNumber = "44"
             landmarkName = "offline_dirty()"
             landmarkType = "7">
          </BreakpointContent>
@@ -730,14 +730,30 @@
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "common/data_provider/iSalesDB.m"
-            timestampString = "495964098.161058"
+            timestampString = "495965423.823355"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "50"
-            endingLineNumber = "50"
+            startingLineNumber = "53"
+            endingLineNumber = "53"
             landmarkName = "encryptfield()"
             landmarkType = "7">
          </BreakpointContent>
       </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            shouldBeEnabled = "No"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "common/Functions/MainViewController.m"
+            timestampString = "495967628.976102"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "232"
+            endingLineNumber = "232"
+            landmarkName = "-checklogin:"
+            landmarkType = "5">
+         </BreakpointContent>
+      </BreakpointProxy>
    </Breakpoints>
 </Bucket>

+ 92 - 6
RedAnt ERP Mobile/common/Functions/sidemenu/LoginViewController.m

@@ -12,6 +12,8 @@
 #import "UILabel+FontAppearance.h"
 #import "OLDataProvider.h"
 #import "NotificationNameCenter.h"
+#import "OfflineSettingViewController.h"
+#import "MainViewController.h"
 
 
 @interface LoginViewController ()
@@ -123,7 +125,7 @@
                 {
                     btn.selected = !btn.selected;
                     
-                    [RAUtils alert_view:@"Detective incomplete sync, please finish sync first." title:@"Incomplete sync"];
+                    [RAUtils alert_view:@"Detected incomplete sync, please finish sync first." title:@"Incomplete sync"];
                 }
                 else
                 {
@@ -205,7 +207,7 @@
     {
         self.checkOfflineMode.selected = !self.checkOfflineMode.selected;
         
-        [RAUtils alert_view:@"Detective incomplete sync, please finish sync first." title:@"Incomplete sync"];
+        [RAUtils alert_view:@"Detected incomplete sync, please finish sync first." title:@"Incomplete sync"];
         return;
     }
     
@@ -285,15 +287,99 @@
                 }
                 [defaults synchronize];
                 
-                [self dismissViewControllerAnimated:YES completion:nil];
-                if(self.returnValue)
-                    self.returnValue(true);
+                [self dismissViewControllerAnimated:YES completion:^{
+                    
+                    NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
+                    
+                    bool offline_dirty=[defaults boolForKey:@"OFFLINE_DIRTY"];
+                    
+                    
+                    
+                    
+                    if(offline_dirty)
+                    {
+                        
+                        UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Detected new offline data" message:@"Do you want to sync with server?" preferredStyle:UIAlertControllerStyleAlert];
+                        //block代码块取代了delegate
+                        
+                        
+                        UIAlertAction *actionTwo = [UIAlertAction actionWithTitle:@"Yes(recommoned)" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
+                            
+                            
+                            
+                            
+                            UIApplication * app = [UIApplication sharedApplication];
+                            AppDelegate *appDelegate = (AppDelegate *)[app delegate];
+                            //UIViewController* active_vc = appDelegate.active_controller;
+                            OfflineSettingViewController * offlineVC =[ [UIStoryboard storyboardWithName:@"OLM" bundle:nil] instantiateViewControllerWithIdentifier:@"OfflineSettingViewController"];
+                            //    loginvc.delegate = self;
+                            //    loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
+                            //       appDelegate.active_controller = gunVC;
+                            //        gunVC.onDismissVC = ^(){
+                            //            appDelegate.active_controller = active_vc;
+                            //        };
+                            UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:offlineVC] ;
+                            
+                            
+                            
+                            
+                            
+                            //    [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
+                            
+                            navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
+                            [appDelegate.main_vc presentViewController:navi animated:YES completion:^{
+                                
+                                
+                                    MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
+                                
+                                [main_vc checklogin:true];
+                                //        navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
+                                
+                                NSLog(@"about present.........");
+                                
+                                //   self.btop = false;
+                                //  <#code#>
+                            }];
+                            
+                            
+                            
+                            
+                        }];
+                        
+                        UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
+                            
+                            if(self.returnValue)
+                                self.returnValue(true);
+                            [[NSNotificationCenter defaultCenter] postNotificationName:LoginOK_HandleUrgencyFile_Notification object:nil];
+                            
+                        }];
+                        
+                        [alertControl addAction:actionTwo];
+                        [alertControl addAction:alertthree];
+                        
+                        
+                        
+                        [appDelegate.main_vc presentViewController:alertControl animated:YES completion:nil];
+                        
+                        
+                        
+                        
+                    }
+                    else
+                    {
+                    if(self.returnValue)
+                        self.returnValue(true);
+                    [[NSNotificationCenter defaultCenter] postNotificationName:LoginOK_HandleUrgencyFile_Notification object:nil];
+                    }
+                        }];
+
+
                 
                 //                if (self.delegate && [self.delegate respondsToSelector:@selector(LoginViewControllerDidLogin:)]) {
                 //                    [self.delegate LoginViewControllerDidLogin:self];
                 //                }
                 
-                [[NSNotificationCenter defaultCenter] postNotificationName:LoginOK_HandleUrgencyFile_Notification object:nil];
+                
             }
             else
             {

+ 12 - 6
RedAnt ERP Mobile/common/data_provider/iSalesDB.m

@@ -41,10 +41,13 @@ int count_dbconn;
 
 void offline_dirty(sqlite3_context *context, int argc, sqlite3_value **argv) {
     AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+    if(!appDelegate.disable_trigger)
+    {
     NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
-    [defaults removeObjectForKey:@"Need_Sync"];
-    [defaults setBool:true forKey:@"Need_Sync"];
+    [defaults removeObjectForKey:@"OFFLINE_DIRTY"];
+    [defaults setBool:true forKey:@"OFFLINE_DIRTY"];
     [defaults synchronize];
+    }
 }
 void encryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
     assert(argc == 1);
@@ -690,10 +693,10 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
     
     NSString* create_offline_salesrep=@"CREATE TABLE IF NOT EXISTS offline_salesrep ( _id INTEGER PRIMARY KEY, name text, code text,salesrep_id integer);";
     
-    NSString* create_order_trigger=@"CREATE TRIGGER  if not exists offline_order_insert after insert on offline_order BEGIN select offline_dirty(''); select encrypt('abc'); END;";
-    
-    //
-    
+    NSString* create_order_trigger=@"CREATE TRIGGER  if not exists offline_order_insert after insert on offline_order BEGIN select offline_dirty();  END;CREATE TRIGGER  if not exists offline_order_update after update on offline_order BEGIN select offline_dirty();  END;CREATE TRIGGER  if not exists offline_order_delete after delete on offline_order BEGIN select offline_dirty();  END;";
+        NSString* create_contact_trigger=@"CREATE TRIGGER  if not exists offline_contact_insert after insert on offline_contact BEGIN select offline_dirty();  END;CREATE TRIGGER  if not exists offline_contact_update after update on offline_contact BEGIN select offline_dirty();  END;CREATE TRIGGER  if not exists offline_contact_delete after delete on offline_contact BEGIN select offline_dirty();  END;";
+        NSString* create_cart_trigger=@"CREATE TRIGGER  if not exists offline_cart_insert after insert on offline_cart BEGIN select offline_dirty();  END;CREATE TRIGGER  if not exists offline_cart_update after update on offline_cart BEGIN select offline_dirty();  END;CREATE TRIGGER  if not exists offline_cart_delete after delete on offline_cart BEGIN select offline_dirty();  END;";
+        NSString* create_wishlist_trigger=@"CREATE TRIGGER  if not exists wishlist_insert after insert on wishlist BEGIN select offline_dirty();  END;CREATE TRIGGER  if not exists wishlist_update after update on wishlist BEGIN select offline_dirty();  END;CREATE TRIGGER  if not exists wishlist_delete after delete on wishlist BEGIN select offline_dirty();  END;";
     AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
     
     //if(appDelegate.offline_mode)
@@ -732,6 +735,9 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
         [self execSql:create_catalog db:db];
         [self execSql:create_errlog db:db];
         [self execSql:create_order_trigger db:db];
+        [self execSql:create_contact_trigger db:db];
+        [self execSql:create_cart_trigger db:db];
+        [self execSql:create_wishlist_trigger db:db];
         
         
         

+ 2 - 0
RedAnt ERP Mobile/iSales-NPD/AppDelegate.h

@@ -87,6 +87,8 @@
 -(void) update_count_mark;
 // downloader
 -(void) check_offline:(NSString*) ver useInternalAddress:(bool)buseinternaladdress parentvc:(UIViewController*) parent;
+@property bool disable_trigger;
+
 @property (nonatomic, strong) SyncControlPanelViewController *settingUI;
 @property (nonatomic, strong) NSFileHandle *fileHandle;
 //@property (nonatomic, assign) long long currentLength; //>>写入文件的长度

+ 8 - 4
RedAnt ERP Mobile/iSales-NPD/AppDelegate.m

@@ -716,6 +716,7 @@ void UncaughtExceptionHandler(NSException *exception) {
 
 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
 {
+    self.disable_trigger = false;
     [self initialExceptionHandler];
     [self becomeObserver];
     
@@ -1137,7 +1138,7 @@ void UncaughtExceptionHandler(NSException *exception) {
                 if([[json valueForKey:@"result"] intValue]==2)
                 {
                     [self add_downloadlog:@"Upload successful."];
-                    
+                    appDelegate.disable_trigger=true;
                     NSString* so_id=[RAUtils arr2string:arr_order separator:@"," trim:true brackets:@"'"];
                     
                     [iSalesDB execSql:@"delete from offline_contact where not sync_data is null"];
@@ -1171,7 +1172,7 @@ void UncaughtExceptionHandler(NSException *exception) {
                     //                    NSDictionary* wishlistjson= upjson[@"wishlist"];
                     //                    NSDictionary* orderjson= upjson[@"order"];
                     
-                    
+                    appDelegate.disable_trigger=false;
                     NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
                     [defaults removeObjectForKey:@"Forcedownload"];
                     [defaults setBool:true forKey:@"Forcedownload"];
@@ -1669,7 +1670,8 @@ void UncaughtExceptionHandler(NSException *exception) {
                 [defaults removeObjectForKey:@"Forcedownload"];
                 NSString * downSerial = [defaults valueForKey:@"downSerial"];
                 [defaults removeObjectForKey:@"downSerial"];
-                
+                [defaults removeObjectForKey:@"OFFLINE_DIRTY"];
+                [defaults setBool:FALSE forKey:@"OFFLINE_DIRTY"];
                 [defaults synchronize];
                 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                     
@@ -2060,6 +2062,7 @@ void UncaughtExceptionHandler(NSException *exception) {
             }
             else if([type isEqualToString:@"sql"])
             {
+                AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
                 NSString * ver = self.download_task[@"ver"];
                 NSString* tempdb=[NSString stringWithFormat:@"%@/%@",ver,DBNAME];
                 tempdb=[temp stringByAppendingPathComponent:tempdb];
@@ -2071,6 +2074,7 @@ void UncaughtExceptionHandler(NSException *exception) {
                 
                 @try {
                     char *errmsg=NULL;
+                    appDelegate.disable_trigger=true;
                     if (sqlite3_exec(tdb, "begin", NULL, NULL, &errmsg)==SQLITE_OK)
                     {
                         
@@ -2154,7 +2158,7 @@ void UncaughtExceptionHandler(NSException *exception) {
                 }
                 @finally {
                     
-                    
+                    appDelegate.disable_trigger=false;
                     sqlite3_close(tdb);
                     // [iSalesDB close_db:tdb];
                     //  [self SelectData];