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

删除文件iSalesDB+JKDB 并将jk_query: completion:方法写到iSales文件中

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

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


+ 105 - 78
RedAnt ERP Mobile/common/Functions/offline/OLDataProvider.m

@@ -11,7 +11,6 @@
 #import "RAUtils.h"
 #import "RAUtils.h"
 #import "AESCrypt.h"
 #import "AESCrypt.h"
 #import "AppDelegate.h"
 #import "AppDelegate.h"
-#import "iSalesDB+JKDB.h"
 
 
 
 
 @interface OLDataProvider ()
 @interface OLDataProvider ()
@@ -2658,6 +2657,7 @@
 #pragma mark - Jack
 #pragma mark - Jack
 
 
 #pragma mark create new contact
 #pragma mark create new contact
+
 + (NSDictionary *)offline_getAllCountryDefault:(NSString *)countryCode {
 + (NSDictionary *)offline_getAllCountryDefault:(NSString *)countryCode {
     //    "val_227" : {
     //    "val_227" : {
     //        "check" : 1,
     //        "check" : 1,
@@ -2669,101 +2669,127 @@
         countryCode = @"US";
         countryCode = @"US";
     }
     }
     
     
-    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
-    sqlite3 *db = [iSalesDB get_db];
-    
-    const char *sqlQuery = "select _id,name,code,countrycode_id from offline_country;";
-    sqlite3_stmt * statement;
-    
-    if (sqlite3_prepare_v2(db, sqlQuery, -1, &statement, nil) == SQLITE_OK) {
-        
-        long count = 0;
-        while (sqlite3_step(statement) == SQLITE_ROW) {
-            char *name = (char *) sqlite3_column_text(statement, 1); // 全称
-            char *code = (char *) sqlite3_column_text(statement, 2); // 缩写
-            int code_id = sqlite3_column_int(statement, 3); // id
-            
-            NSMutableDictionary *countryDic = [NSMutableDictionary dictionaryWithCapacity:2];
-            [countryDic setValue:[NSString stringWithFormat:@"%s",name] forKey:@"value"];
-            [countryDic setValue:[NSString stringWithFormat:@"%d",code_id] forKey:@"value_id"];
-            [countryDic setValue:[NSNumber numberWithInt:0] forKey:@"check"];
-            
-            if ([countryCode isEqualToString:[NSString stringWithUTF8String:code]]) {
-                [countryDic setValue:[NSNumber numberWithInt:1] forKey:@"check"];
-            }
-            
-            NSString *key = [NSString stringWithFormat:@"val_%ld",count++];
-            [dic setValue:countryDic forKey:key];
+//    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
+//    sqlite3 *db = [iSalesDB get_db];
+//    
+//    const char *sqlQuery = "select _id,name,code,countrycode_id from offline_country;";
+//    sqlite3_stmt * statement;
+//    
+//    if (sqlite3_prepare_v2(db, sqlQuery, -1, &statement, nil) == SQLITE_OK) {
+//        
+//        long count = 0;
+//        while (sqlite3_step(statement) == SQLITE_ROW) {
+//            char *name = (char *) sqlite3_column_text(statement, 1); // 全称
+//            char *code = (char *) sqlite3_column_text(statement, 2); // 缩写
+//            int code_id = sqlite3_column_int(statement, 3); // id
+//            
+//            NSMutableDictionary *countryDic = [NSMutableDictionary dictionaryWithCapacity:2];
+//            [countryDic setValue:[NSString stringWithFormat:@"%s",name] forKey:@"value"];
+//            [countryDic setValue:[NSString stringWithFormat:@"%d",code_id] forKey:@"value_id"];
+//            [countryDic setValue:[NSNumber numberWithInt:0] forKey:@"check"];
+//            
+//            if ([countryCode isEqualToString:[NSString stringWithUTF8String:code]]) {
+//                [countryDic setValue:[NSNumber numberWithInt:1] forKey:@"check"];
+//            }
+//            
+//            NSString *key = [NSString stringWithFormat:@"val_%ld",count++];
+//            [dic setValue:countryDic forKey:key];
+//        }
+//        
+//        sqlite3_finalize(statement);
+//    }
+//    
+//    sqlite3_close(db);
+//    [dic setValue:[NSNumber numberWithInt:dic.allKeys.count] forKey:@"count"];
+//    return dic;
+
+    NSMutableDictionary *ret = [[iSalesDB jk_query:@"select _id,name,code,countrycode_id from offline_country;" completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container,long *count) {
+        char *name = (char *) sqlite3_column_text(stmt, 1); // 全称
+        char *code = (char *) sqlite3_column_text(stmt, 2); // 缩写
+        int code_id = sqlite3_column_int(stmt, 3); // id
+
+        NSMutableDictionary *countryDic = [NSMutableDictionary dictionaryWithCapacity:2];
+        [countryDic setValue:[NSString stringWithFormat:@"%s",name] forKey:@"value"];
+        [countryDic setValue:[NSString stringWithFormat:@"%d",code_id] forKey:@"value_id"];
+        [countryDic setValue:[NSNumber numberWithInt:0] forKey:@"check"];
+
+        if ([countryCode isEqualToString:[NSString stringWithUTF8String:code]]) {
+            [countryDic setValue:[NSNumber numberWithInt:1] forKey:@"check"];
         }
         }
-        
-        sqlite3_finalize(statement);
-    }
     
     
-    sqlite3_close(db);
-    [dic setValue:[NSNumber numberWithInt:dic.allKeys.count] forKey:@"count"];
-    return dic;
+        long n = *count;
+        *count = n + 1;
+        NSString *key = [NSString stringWithFormat:@"val_%ld",n];
+        [container setValue:countryDic forKey:key];
+    }] mutableCopy];
     
     
-//    NSDictionary *ret = [iSalesDB jk_query:@"select _id,name,code,countrycode_id from offline_country;" completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container,long *count) {
-//        char *name = (char *) sqlite3_column_text(stmt, 1); // 全称
-//        char *code = (char *) sqlite3_column_text(stmt, 2); // 缩写
-//        int code_id = sqlite3_column_int(stmt, 3); // id
-//
-//        NSMutableDictionary *countryDic = [NSMutableDictionary dictionaryWithCapacity:2];
-//        [countryDic setValue:[NSString stringWithFormat:@"%s",name] forKey:@"value"];
-//        [countryDic setValue:[NSString stringWithFormat:@"%d",code_id] forKey:@"value_id"];
-//        [countryDic setValue:[NSNumber numberWithInt:0] forKey:@"check"];
-//
-//        if ([countryCode isEqualToString:[NSString stringWithUTF8String:code]]) {
-//            [countryDic setValue:[NSNumber numberWithInt:1] forKey:@"check"];
-//        }
-//    
-//        long n = *count;
-//        *count = n + 1;
-//        NSString *key = [NSString stringWithFormat:@"val_%ld",n];
-//        [container setValue:countryDic forKey:key];
-//    }];
-//    
-//    return [ret copy];
+    [ret setValue:[NSNumber numberWithInt:ret.allKeys.count] forKey:@"count"];
+    return ret;
 }
 }
 
 
 + (NSDictionary *)offline_getStateByCountryCode:(NSString *)countryCode checkedState:(NSString *)state_code{
 + (NSDictionary *)offline_getStateByCountryCode:(NSString *)countryCode checkedState:(NSString *)state_code{
     
     
-    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
-    
-    sqlite3 *db = [iSalesDB get_db];
+//    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
+//    
+//    sqlite3 *db = [iSalesDB get_db];
+//    
+//    NSString *sqlQuery = [NSString stringWithFormat:@"select _id,name,code,country_code from offline_state where country_code = '%@';",countryCode];
+//    
+//    //    NSString *sqlQuery = [NSString stringWithFormat:@"select * from offline_state"];
+//    DebugLog(@"query state:%@",sqlQuery);
+//    
+//    sqlite3_stmt * statement;
+//    
+//    if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK) {
+//        int i = 0;
+//        while (sqlite3_step(statement) == SQLITE_ROW) {
+//            char *name = (char *) sqlite3_column_text(statement, 1); // value
+//            char *code = (char *) sqlite3_column_text(statement, 2); // value_id
+//            
+//            NSMutableDictionary *stateDic = [NSMutableDictionary dictionaryWithCapacity:2];
+//            [stateDic setValue:[NSString stringWithUTF8String:name] forKey:@"value"];
+//            [stateDic setValue:[NSString stringWithUTF8String:code] forKey:@"value_id"];
+//            [stateDic setValue:[NSNumber numberWithInt:0] forKey:@"check"];
+//            
+//            if (state_code && [[NSString stringWithUTF8String:code] isEqualToString:state_code]) {
+//                [stateDic setValue:[NSNumber numberWithInt:1] forKey:@"check"];
+//            }
+//            
+//            NSString *key = [NSString stringWithFormat:@"val_%d",i++];
+//            [dic setValue:stateDic forKey:key];
+//        }
+//        
+//        sqlite3_finalize(statement);
+//    }
+//    
+//    sqlite3_close(db);
+//    [dic setValue:[NSNumber numberWithInt:dic.allKeys.count] forKey:@"count"];
+//    return dic;
     
     
     NSString *sqlQuery = [NSString stringWithFormat:@"select _id,name,code,country_code from offline_state where country_code = '%@';",countryCode];
     NSString *sqlQuery = [NSString stringWithFormat:@"select _id,name,code,country_code from offline_state where country_code = '%@';",countryCode];
     
     
-    //    NSString *sqlQuery = [NSString stringWithFormat:@"select * from offline_state"];
-    DebugLog(@"query state:%@",sqlQuery);
-    
-    sqlite3_stmt * statement;
-    
-    if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK) {
-        int i = 0;
-        while (sqlite3_step(statement) == SQLITE_ROW) {
-            char *name = (char *) sqlite3_column_text(statement, 1); // value
-            char *code = (char *) sqlite3_column_text(statement, 2); // value_id
-            
+    NSMutableDictionary *ret = [[iSalesDB jk_query:sqlQuery completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
+        
+        char *name = (char *) sqlite3_column_text(stmt, 1); // value
+            char *code = (char *) sqlite3_column_text(stmt, 2); // value_id
+
             NSMutableDictionary *stateDic = [NSMutableDictionary dictionaryWithCapacity:2];
             NSMutableDictionary *stateDic = [NSMutableDictionary dictionaryWithCapacity:2];
             [stateDic setValue:[NSString stringWithUTF8String:name] forKey:@"value"];
             [stateDic setValue:[NSString stringWithUTF8String:name] forKey:@"value"];
             [stateDic setValue:[NSString stringWithUTF8String:code] forKey:@"value_id"];
             [stateDic setValue:[NSString stringWithUTF8String:code] forKey:@"value_id"];
             [stateDic setValue:[NSNumber numberWithInt:0] forKey:@"check"];
             [stateDic setValue:[NSNumber numberWithInt:0] forKey:@"check"];
-            
+
             if (state_code && [[NSString stringWithUTF8String:code] isEqualToString:state_code]) {
             if (state_code && [[NSString stringWithUTF8String:code] isEqualToString:state_code]) {
                 [stateDic setValue:[NSNumber numberWithInt:1] forKey:@"check"];
                 [stateDic setValue:[NSNumber numberWithInt:1] forKey:@"check"];
             }
             }
-            
-            NSString *key = [NSString stringWithFormat:@"val_%d",i++];
-            [dic setValue:stateDic forKey:key];
-        }
+
+            NSString *key = [NSString stringWithFormat:@"val_%ld",(*count)++];
+            [container setValue:stateDic forKey:key];
         
         
-        sqlite3_finalize(statement);
-    }
+    }] mutableCopy];
     
     
-    sqlite3_close(db);
-    [dic setValue:[NSNumber numberWithInt:dic.allKeys.count] forKey:@"count"];
-    return dic;
+    [ret setValue:[NSNumber numberWithInt:ret.allKeys.count] forKey:@"count"];
+    
+    return ret;
 }
 }
 
 
 + (NSDictionary *)offline_getStateByCountryCodeId:(NSString *)codeId checkedState:(NSString *)stateCode {
 + (NSDictionary *)offline_getStateByCountryCodeId:(NSString *)codeId checkedState:(NSString *)stateCode {
@@ -3179,7 +3205,8 @@
     
     
     NSString *sql = [NSString stringWithFormat:@"insert into offline_contact (company_name,addr_1,addr_2,addr_3,addr_4,country,state,city,zipcode,first_name,last_name,phone,fax,email,notes,price_type,sales_rep,img_0,img_1,img_2,editable,contact_id) values ('%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@',1,'%@')",companyName,addr1,addr2,addr3,addr4,country,state,city,zipcode,fistName,lastName,phone,fax,email,notes,price,salesRep,img_0,img_1,img_2,contact_id];
     NSString *sql = [NSString stringWithFormat:@"insert into offline_contact (company_name,addr_1,addr_2,addr_3,addr_4,country,state,city,zipcode,first_name,last_name,phone,fax,email,notes,price_type,sales_rep,img_0,img_1,img_2,editable,contact_id) values ('%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@',1,'%@')",companyName,addr1,addr2,addr3,addr4,country,state,city,zipcode,fistName,lastName,phone,fax,email,notes,price,salesRep,img_0,img_1,img_2,contact_id];
     
     
-    int result = [iSalesDB jk_execSql:sql withDatabase:YES];
+//    int result = [iSalesDB jk_execSql:sql withDatabase:YES];
+    int result = [iSalesDB execSql:sql] == SQLITE_OK ? RESULT_TRUE : RESULT_FALSE;
     
     
     NSString *retStr = [NSString stringWithFormat:@"{\"result\":%d,\"min_ver\":\"160409\",\"mode\":\"Regular Mode\"}",result];
     NSString *retStr = [NSString stringWithFormat:@"{\"result\":%d,\"min_ver\":\"160409\",\"mode\":\"Regular Mode\"}",result];
     
     

+ 10 - 0
RedAnt ERP Mobile/common/data_provider/iSalesDB.h

@@ -10,6 +10,10 @@
 #import "const.h"
 #import "const.h"
 #import <sqlite3.h>  
 #import <sqlite3.h>  
 #import "config.h"
 #import "config.h"
+
+typedef void(^queryBlock)(sqlite3_stmt *stmt,NSMutableDictionary *container,long *count);
+
+
 @interface iSalesDB : NSObject
 @interface iSalesDB : NSObject
 //+(void)testdata;
 //+(void)testdata;
 + (int) initializeDb;
 + (int) initializeDb;
@@ -36,4 +40,10 @@
 
 
 + (sqlite3*) get_db_at:(NSString* )path;
 + (sqlite3*) get_db_at:(NSString* )path;
 +(int) AddExFunction:(sqlite3 *) db;
 +(int) AddExFunction:(sqlite3 *) db;
+
+#pragma mark - JK
+
++ (NSDictionary *)jk_query:(NSString *)sql completion:(queryBlock)block;
+
+
 @end
 @end

+ 23 - 0
RedAnt ERP Mobile/common/data_provider/iSalesDB.m

@@ -867,5 +867,28 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
     
     
 }
 }
 
 
+#pragma mark - JK
+
++ (NSDictionary *)jk_query:(NSString *)sql completion:(queryBlock)block {
+    
+    __block NSMutableDictionary *dic = [NSMutableDictionary dictionary];
+    
+    sqlite3 *db = [iSalesDB get_db];
+    NSString *sqlQuery = sql;
+    sqlite3_stmt * statement;
+    
+    if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK) {
+        long count = 0;
+        while (sqlite3_step(statement) == SQLITE_ROW) {
+            block(statement,dic,&count);
+        }
+        
+        sqlite3_finalize(statement);
+    }
+    sqlite3_close(db);
+    
+    
+    return [dic copy];
+}
 
 
 @end
 @end

+ 0 - 6
RedAnt ERP Mobile/iSales-NPD.xcodeproj/project.pbxproj

@@ -8,7 +8,6 @@
 
 
 /* Begin PBXBuildFile section */
 /* Begin PBXBuildFile section */
 		423A4ADC1D503A53005ECE4A /* createContact.json in Resources */ = {isa = PBXBuildFile; fileRef = 423A4ADB1D503A53005ECE4A /* createContact.json */; };
 		423A4ADC1D503A53005ECE4A /* createContact.json in Resources */ = {isa = PBXBuildFile; fileRef = 423A4ADB1D503A53005ECE4A /* createContact.json */; };
-		4265A1D91D51C86600B3B43B /* iSalesDB+JKDB.m in Sources */ = {isa = PBXBuildFile; fileRef = 4265A1D81D51C86600B3B43B /* iSalesDB+JKDB.m */; };
 		710274251CC606C4009FD219 /* UserListViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 710274241CC606C4009FD219 /* UserListViewController.m */; };
 		710274251CC606C4009FD219 /* UserListViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 710274241CC606C4009FD219 /* UserListViewController.m */; };
 		7111E5721C76C557004763B3 /* customer_info_template_edit.json in Resources */ = {isa = PBXBuildFile; fileRef = 7111E5711C76C557004763B3 /* customer_info_template_edit.json */; };
 		7111E5721C76C557004763B3 /* customer_info_template_edit.json in Resources */ = {isa = PBXBuildFile; fileRef = 7111E5711C76C557004763B3 /* customer_info_template_edit.json */; };
 		71131F921CA1372300DBF6E2 /* SimplifiedBuyingProgramViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 71131F911CA1372300DBF6E2 /* SimplifiedBuyingProgramViewController.m */; };
 		71131F921CA1372300DBF6E2 /* SimplifiedBuyingProgramViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 71131F911CA1372300DBF6E2 /* SimplifiedBuyingProgramViewController.m */; };
@@ -190,8 +189,6 @@
 
 
 /* Begin PBXFileReference section */
 /* Begin PBXFileReference section */
 		423A4ADB1D503A53005ECE4A /* createContact.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = createContact.json; sourceTree = "<group>"; };
 		423A4ADB1D503A53005ECE4A /* createContact.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = createContact.json; sourceTree = "<group>"; };
-		4265A1D71D51C86600B3B43B /* iSalesDB+JKDB.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "iSalesDB+JKDB.h"; sourceTree = "<group>"; };
-		4265A1D81D51C86600B3B43B /* iSalesDB+JKDB.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "iSalesDB+JKDB.m"; sourceTree = "<group>"; };
 		56528CA8B8A71F67C2EE5366 /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = "<group>"; };
 		56528CA8B8A71F67C2EE5366 /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = "<group>"; };
 		6C826876B24EFB83AC94A464 /* Pods.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.release.xcconfig; path = "Pods/Target Support Files/Pods/Pods.release.xcconfig"; sourceTree = "<group>"; };
 		6C826876B24EFB83AC94A464 /* Pods.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.release.xcconfig; path = "Pods/Target Support Files/Pods/Pods.release.xcconfig"; sourceTree = "<group>"; };
 		710274231CC606C4009FD219 /* UserListViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UserListViewController.h; path = common/Functions/sidemenu/UserListViewController.h; sourceTree = SOURCE_ROOT; };
 		710274231CC606C4009FD219 /* UserListViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UserListViewController.h; path = common/Functions/sidemenu/UserListViewController.h; sourceTree = SOURCE_ROOT; };
@@ -800,8 +797,6 @@
 				71BF06F91D2F3CAC00981938 /* OLDataProvider.h */,
 				71BF06F91D2F3CAC00981938 /* OLDataProvider.h */,
 				71BF06FA1D2F3CAC00981938 /* OLDataProvider.m */,
 				71BF06FA1D2F3CAC00981938 /* OLDataProvider.m */,
 				423A4ADB1D503A53005ECE4A /* createContact.json */,
 				423A4ADB1D503A53005ECE4A /* createContact.json */,
-				4265A1D71D51C86600B3B43B /* iSalesDB+JKDB.h */,
-				4265A1D81D51C86600B3B43B /* iSalesDB+JKDB.m */,
 			);
 			);
 			name = utils;
 			name = utils;
 			sourceTree = "<group>";
 			sourceTree = "<group>";
@@ -1421,7 +1416,6 @@
 				7162A5DD1C5876E300AB630E /* PopupNavigationController.m in Sources */,
 				7162A5DD1C5876E300AB630E /* PopupNavigationController.m in Sources */,
 				7162A59E1C58733400AB630E /* OrderListTableViewCell.m in Sources */,
 				7162A59E1C58733400AB630E /* OrderListTableViewCell.m in Sources */,
 				71DF746A1C575E7900F2789C /* SRMonthPicker.m in Sources */,
 				71DF746A1C575E7900F2789C /* SRMonthPicker.m in Sources */,
-				4265A1D91D51C86600B3B43B /* iSalesDB+JKDB.m in Sources */,
 				714B1F401C7BF74100539193 /* OrderDetailSignatureCell.m in Sources */,
 				714B1F401C7BF74100539193 /* OrderDetailSignatureCell.m in Sources */,
 				71DF745D1C575E7900F2789C /* CommonEditorCellEnum.m in Sources */,
 				71DF745D1C575E7900F2789C /* CommonEditorCellEnum.m in Sources */,
 				7141DD521C57459B00F7DF59 /* qrinput.c in Sources */,
 				7141DD521C57459B00F7DF59 /* qrinput.c in Sources */,