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

完成离线新建联系人的数据提供方法offline_createContact:

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

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


+ 5 - 0
RedAnt ERP Mobile/RedAnt ERP Mobile.xcworkspace/xcuserdata/macmini1.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Bucket
+   type = "0"
+   version = "2.0">
+</Bucket>

+ 74 - 10
RedAnt ERP Mobile/common/Functions/offline/OLDataProvider.m

@@ -2603,15 +2603,16 @@
     if (sqlite3_prepare_v2(db, sqlQuery, -1, &statement, nil) == SQLITE_OK) {
         
         while (sqlite3_step(statement) == SQLITE_ROW) {
-            char *name = (char *) sqlite3_column_text(statement, 1);
-            char *code = (char *) sqlite3_column_text(statement, 2);
+            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 stringWithUTF8String:name] forKey:@"value"];
             [countryDic setValue:[NSString stringWithUTF8String:code] forKey:@"value_id"];
             [countryDic setValue:[NSNumber numberWithInt:0] forKey:@"check"];
             
-            NSString *key = [NSString stringWithFormat:@"val_%d",[[NSString stringWithUTF8String:code] integerValue] - 1];
+            NSString *key = [NSString stringWithFormat:@"val_%d",code_id - 1];
             [dic setValue:countryDic forKey:key];
         }
         
@@ -2629,7 +2630,8 @@
     
     sqlite3 *db = [iSalesDB get_db];
     
-    NSString *sqlQuery = [NSString stringWithFormat:@"select * from offline_state where country_code = %@;",countryCode];
+    NSString *sqlQuery = [NSString stringWithFormat:@"select * from offline_state;"];
+    // select * from offline_state where country_code = %d;",[countryCode integerValue]
     sqlite3_stmt * statement;
     
     if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK) {
@@ -2672,6 +2674,12 @@
             [priceDic setValue:[NSString stringWithUTF8String:name] forKey:@"value"];
             [priceDic setValue:[NSNumber numberWithInt:type] forKey:@"value_id"];
             NSString *key = [NSString stringWithFormat:@"val_%d",orderBy];
+            [priceDic setValue:[NSNumber numberWithInt:0] forKey:@"check"];
+            
+            if (orderBy == 0) {
+                [priceDic setValue:[NSNumber numberWithInt:1] forKey:@"check"];
+            }
+            
             [dic setValue:priceDic forKey:key];
         }
         
@@ -2685,6 +2693,48 @@
     return dic;
 }
 
++ (NSDictionary *)offline_getSalesRep {
+    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
+    
+    sqlite3 *db = [iSalesDB get_db];
+    NSString *sqlQuery = [NSString stringWithFormat:@"select * from offline_salesrep;"];
+    sqlite3_stmt * statement;
+    
+    if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK) {
+        while (sqlite3_step(statement) == SQLITE_ROW) {
+            // 1 name 2 code 3 salesrep_id
+            char *name = (char *)sqlite3_column_text(statement, 1);
+            char *code = (char *)sqlite3_column_text(statement, 2);
+            int salesrep_id = sqlite3_column_int(statement, 3);
+            int _id = sqlite3_column_int(statement, 0);
+//
+//            "val_0" : {
+//                "value" : "BBSC - BARBARA BORROUGHS",
+//                "value_id" : 121
+//            },
+            NSMutableDictionary *repDic = [NSMutableDictionary dictionary];
+            [repDic setValue:[NSString stringWithFormat:@"%s - %s",code,name] forKey:@"value"];
+            [repDic setValue:[NSNumber numberWithInt:salesrep_id] forKey:@"value_id"];
+            [dic setValue:repDic forKey:[NSString stringWithFormat:@"val_%d",_id - 1]];
+        }
+        
+        sqlite3_finalize(statement);
+    }
+    sqlite3_close(db);
+    
+    [dic setValue:[NSNumber numberWithInt:dic.allKeys.count] forKey:@"count"];
+    
+    return dic;
+}
+
++ (void)setValue:(id)value forItemKey:(NSString *)itemKey valueKey:(NSString *)valueKey inDictionary:(NSMutableDictionary *)dic{
+    
+    NSMutableDictionary *item = [[dic objectForKey:itemKey] mutableCopy];
+    [item setValue:value forKey:valueKey];
+    
+    [dic setValue:item forKey:itemKey];
+}
+
 + (NSData *)offline_createContact:(NSMutableDictionary *)params {
     
     NSString *path = [[NSBundle mainBundle] pathForResource:@"createContact.json" ofType:nil];
@@ -2710,20 +2760,34 @@
     NSMutableDictionary *country = [allCountry objectForKey:key];
     [country setValue:[NSNumber numberWithInt:1] forKey:@"check"];
     
-    NSDictionary *section_0 = [ret objectForKey:@"section_0"];
-    NSDictionary *item_country = [section_0 objectForKey:@"item_5"];
-    [item_country setValue:allCountry forKey:@"cadedate"];
+    NSMutableDictionary *section_0 = [[ret objectForKey:@"section_0"] mutableCopy];
+//    NSDictionary *item_country = [section_0 objectForKey:@"item_5"];
+//    [item_country setValue:allCountry forKey:@"cadedate"];
+    
+    [self setValue:allCountry forItemKey:@"item_5" valueKey:@"cadedate" inDictionary:section_0];
     
     // state
     NSDictionary *allState = [self offline_getStateByCountryCode:countryCode];
-    NSMutableDictionary *item_state = [section_0 objectForKey:@"item_11"];
-    [item_state setValue:allState forKey:@"cadedate"];
+//    NSMutableDictionary *item_state = [section_0 objectForKey:@"item_11"];
+//    [item_state setValue:allState forKey:@"cadedate"];
     
-    // price type
+    [self setValue:allState forItemKey:@"item_11" valueKey:@"cadedate" inDictionary:section_0];
     
+    // price type
+    NSDictionary *priceDic = [self offline_getPrice];
+//    NSDictionary *item_price = [section_0 objectForKey:@"item_2"];
+//    [item_price setValue:priceDic forKey:@"cadedate"];
     
+    [self setValue:priceDic forItemKey:@"item_2" valueKey:@"cadedate" inDictionary:section_0];
+
     // Sales Rep
+    NSDictionary *repDic = [self offline_getSalesRep];
+//    NSDictionary *item_rep = [section_0 objectForKey:@"item_17"];
+//    [item_rep setValue:repDic forKey:@"cadedate"];
+    
+    [self setValue:repDic forItemKey:@"item_17" valueKey:@"cadedate" inDictionary:section_0];
     
+    [ret setValue:section_0 forKey:@"section_0"];
     return [RAUtils dict2data:ret];
 }