Przeglądaj źródła

为iSalesDB增加分类:iSalesDB+JKDB,实现新建联系人保存方法offline_saveNewContact:。

Pen Li 9 lat temu
rodzic
commit
02ba770115

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


+ 170 - 4
RedAnt ERP Mobile/common/Functions/offline/OLDataProvider.m

@@ -11,6 +11,7 @@
 #import "RAUtils.h"
 #import "AESCrypt.h"
 #import "AppDelegate.h"
+#import "iSalesDB+JKDB.h"
 
 
 @interface OLDataProvider ()
@@ -2701,6 +2702,28 @@
     sqlite3_close(db);
     [dic setValue:[NSNumber numberWithInt:dic.allKeys.count] forKey:@"count"];
     return dic;
+    
+//    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];
 }
 
 + (NSDictionary *)offline_getStateByCountryCode:(NSString *)countryCode checkedState:(NSString *)state_code{
@@ -2935,10 +2958,7 @@
 {
     return nil;
 }
-+(NSData *) offline_saveNewContact:(NSMutableDictionary *) params
-{
-    return nil;
-}
+
 + (NSData *)offline_createContact:(NSMutableDictionary *)params {
     
     NSString *path = [[NSBundle mainBundle] pathForResource:@"createContact.json" ofType:nil];
@@ -3020,5 +3040,151 @@
     return [RAUtils dict2data:ret];
 }
 
+#pragma mark save new contact
+
++ (NSString *)countryNameByCountryCodeId:(NSString *)codeId {
+    
+    NSString *name = nil;
+    
+    sqlite3 *db = [iSalesDB get_db];
+    NSString *sqlQuery = [NSString stringWithFormat:@"select name from offline_country where countrycode_id = %@",codeId];
+    sqlite3_stmt * statement;
+    
+    if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK) {
+        while (sqlite3_step(statement) == SQLITE_ROW) {
+            char *value = (char *)sqlite3_column_text(statement, 0);
+            name = [NSString stringWithUTF8String:value];
+        }
+        
+        sqlite3_finalize(statement);
+    }
+    sqlite3_close(db);
+    
+    return name;
+}
+
++ (NSString *)priceNameByPriceId:(NSString *)priceId {
+    
+    NSString *ret = nil;
+    
+    sqlite3 *db = [iSalesDB get_db];
+    NSString *sqlQuery = [NSString stringWithFormat:@"select name from price where order_by = %@;",priceId];
+    sqlite3_stmt * statement;
+    
+    if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK) {
+        while (sqlite3_step(statement) == SQLITE_ROW) {
+            char *name = (char *)sqlite3_column_text(statement, 0);
+            ret = [NSString stringWithUTF8String:name];
+        }
+        
+        sqlite3_finalize(statement);
+    }
+    sqlite3_close(db);
+
+    return ret;
+}
+
++ (NSString *)salesRepCodeById:(NSString *)_id {
+    
+    NSString *ret = nil;
+    
+    sqlite3 *db = [iSalesDB get_db];
+    NSString *sqlQuery = [NSString stringWithFormat:@"select code from offline_salesrep where salesrep_id = %@",_id];
+    sqlite3_stmt * statement;
+    
+    if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK) {
+        while (sqlite3_step(statement) == SQLITE_ROW) {
+            char *rep = (char *)sqlite3_column_text(statement, 0);
+            ret = [NSString stringWithUTF8String:rep];
+        }
+        
+        sqlite3_finalize(statement);
+    }
+    sqlite3_close(db);
+
+    
+    return ret;
+}
+
++(NSData *) offline_saveNewContact:(NSMutableDictionary *) params
+{
+//    {
+//
+//        password = 123456;
+//        "price_name" = 0;
+//        "sales_rep" = 121;
+
+//    }
+
+    NSLog(@"%@",params);
+    NSString *companyName = [params objectForKey:@"company"];
+    if (companyName) {
+        companyName = [AESCrypt fastencrypt:companyName];
+    }
+    
+    NSString *addr1 = [params objectForKey:@"address"];
+    if (addr1) {
+        addr1 = [AESCrypt fastencrypt:addr1];
+    }
+    NSString *addr2 = [params objectForKey:@"address2"];
+    if (addr2) {
+        addr2 = [AESCrypt fastencrypt:addr2];
+    }
+    NSString *addr3 = [params objectForKey:@"address_3"];
+    if (addr3) {
+        addr3 = [AESCrypt fastencrypt:addr3];
+    }
+    NSString *addr4 = [params objectForKey:@"address_4"];
+    if (addr4) {
+        addr4 = [AESCrypt fastencrypt:addr4];
+    }
+    
+    NSString *country = [params objectForKey:@"country"];
+    if (country) {
+        country = [self countryNameByCountryCodeId:country];
+    }
+    NSString *state = [params objectForKey:@"state"];
+    NSString *city = [params objectForKey:@"city"];
+    NSString *zipcode = [params objectForKey:@"zipcode"];
+    
+    NSString *fistName = [params objectForKey:@"firstname"];
+    NSString *lastName = [params objectForKey:@"lastname"];
+    
+    NSString *phone = [params objectForKey:@"phone"];
+    if (phone) {
+        phone = [AESCrypt fastencrypt:phone];
+    }
+    
+    NSString *fax = [params objectForKey:@"fax"];
+    NSString *email = [params objectForKey:@"email"];
+    
+    NSString *notes = [params objectForKey:@"contact_notes"];
+    
+    NSString *price = [params objectForKey:@"price_name"];
+    if (price) {
+        price = [self priceNameByPriceId:price];
+    }
+    NSString *salesRep = [params objectForKey:@"sales_rep"];
+    if (salesRep) {
+        salesRep = [self salesRepCodeById:salesRep];
+    }
+    
+    NSString *img = [params objectForKey:@"business_card"];
+    NSArray *array = [img componentsSeparatedByString:@","];
+    NSString *img_0 = array[0];
+    NSString *img_1 = array[1];
+    NSString *img_2 = array[2];
+    
+    NSString *contact_id = [NSUUID UUID].UUIDString;
+    
+    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];
+    
+    NSString *retStr = [NSString stringWithFormat:@"{\"result\":%d,\"min_ver\":\"160409\",\"mode\":\"Regular Mode\"}",result];
+    
+    return [retStr dataUsingEncoding:NSUTF8StringEncoding];
+}
+
 
 @end

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

@@ -8,6 +8,7 @@
 
 /* Begin PBXBuildFile section */
 		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 */; };
 		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 */; };
@@ -189,6 +190,8 @@
 
 /* Begin PBXFileReference section */
 		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>"; };
 		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; };
@@ -797,6 +800,8 @@
 				71BF06F91D2F3CAC00981938 /* OLDataProvider.h */,
 				71BF06FA1D2F3CAC00981938 /* OLDataProvider.m */,
 				423A4ADB1D503A53005ECE4A /* createContact.json */,
+				4265A1D71D51C86600B3B43B /* iSalesDB+JKDB.h */,
+				4265A1D81D51C86600B3B43B /* iSalesDB+JKDB.m */,
 			);
 			name = utils;
 			sourceTree = "<group>";
@@ -1416,6 +1421,7 @@
 				7162A5DD1C5876E300AB630E /* PopupNavigationController.m in Sources */,
 				7162A59E1C58733400AB630E /* OrderListTableViewCell.m in Sources */,
 				71DF746A1C575E7900F2789C /* SRMonthPicker.m in Sources */,
+				4265A1D91D51C86600B3B43B /* iSalesDB+JKDB.m in Sources */,
 				714B1F401C7BF74100539193 /* OrderDetailSignatureCell.m in Sources */,
 				71DF745D1C575E7900F2789C /* CommonEditorCellEnum.m in Sources */,
 				7141DD521C57459B00F7DF59 /* qrinput.c in Sources */,

+ 19 - 0
RedAnt ERP Mobile/iSales-NPD/iSalesDB+JKDB.h

@@ -0,0 +1,19 @@
+//
+//  iSalesDB+JKDB.h
+//  iSales-NPD
+//
+//  Created by Jack on 8/3/16.
+//  Copyright © 2016 United Software Applications, Inc. All rights reserved.
+//
+
+#import "iSalesDB.h"
+
+typedef void(^queryBlock)(sqlite3_stmt *stmt,NSMutableDictionary *container,long *count);
+
+@interface iSalesDB (JKDB)
+
++ (NSDictionary *)jk_query:(NSString *)sql completion:(queryBlock)block;
+
++ (int)jk_execSql:(NSString *)sql withDatabase:(BOOL)database;
+
+@end

+ 47 - 0
RedAnt ERP Mobile/iSales-NPD/iSalesDB+JKDB.m

@@ -0,0 +1,47 @@
+//
+//  iSalesDB+JKDB.m
+//  iSales-NPD
+//
+//  Created by Jack on 8/3/16.
+//  Copyright © 2016 United Software Applications, Inc. All rights reserved.
+//
+
+#import "iSalesDB+JKDB.h"
+
+@implementation iSalesDB (JKDB)
+
++ (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];
+}
+
++ (int)jk_execSql:(NSString *)sql withDatabase:(BOOL)database {
+    int flag = RESULT_TRUE;
+    if (database) {
+        sqlite3 *db = [self get_db];
+        if (sqlite3_exec(db, [sql UTF8String], NULL, NULL, nil) != SQLITE_OK) {
+            flag = RESULT_FALSE;
+        }
+    }
+    
+    return flag;
+}
+
+@end