Ray Zhang il y a 10 ans
Parent
commit
c574ac4bcd

+ 3 - 0
RedAnt ERP Mobile/common/RAUtils.h

@@ -32,4 +32,7 @@
 +(UIImage*)img_compress:(UIImage*)image kbsize:(float) size;
 +(NSString* )current_date;
 +(NSMutableArray*)dictionary2array:(NSDictionary*)json count_fields:(NSString*) count_fields item_mark:(NSString*) item_mark items_mark:(NSString* )items_mark;
+
+
++(NSString*) arr2string:(NSArray *) arr separator:(NSString*)separator;
 @end

+ 11 - 0
RedAnt ERP Mobile/common/RAUtils.m

@@ -282,6 +282,17 @@
 //    [info setValue:[[UIDevice currentDevice] name] forKey:@"name"];
 //    [info setValue:[[UIDevice currentDevice] name] forKey:@"name"];
     
+}
++(NSString*) arr2string:(NSArray *) arr separator:(NSString*)separator
+{
+    
+    NSMutableArray * marr = [arr mutableCopy];
+    for (NSString* item in marr) {
+        if(item.length==0)
+            [marr removeObject:item];
+    }
+    NSString * ret = [marr componentsJoinedByString:@","];
+    return ret;
 }
 +(NSString*) dict2string:(NSDictionary*) dict
 {

+ 1 - 1
RedAnt ERP Mobile/common/const.h

@@ -50,7 +50,7 @@
 #define AP_MESSAGE_NEW				 5
 #define AP_MESSAGE_NONE					 6
 
-#define OFFLINE_MODE true
+#define OFFLINE_MODE false
 #define OFFLINE_IMG_TYPE_CATEGORY 0
 #define OFFLINE_IMG_TYPE_DETAIL 1
 

+ 62 - 5
RedAnt ERP Mobile/common/data_provider/iSalesDB.m

@@ -50,13 +50,22 @@
     NSString* drop_IMAGE =@"DROP TABLE IF EXISTS model_image;";
     NSString* drop_image_price =@"DROP TABLE IF EXISTS model_price;";
     NSString* drop_category =@"DROP TABLE IF EXISTS category;";
+    NSString* drop_login =@"DROP TABLE IF EXISTS offline_login;";
+    NSString* drop_cart =@"DROP TABLE IF EXISTS offline_cart;";
+    NSString* drop_wish =@"DROP TABLE IF EXISTS offline_wishlist;";
+     NSString* drop_contact =@"DROP TABLE IF EXISTS offline_contact;";
+    NSString* drop_contact_image =@"DROP TABLE IF EXISTS contact_image;";
     
     
     [iSalesDB execSql:drop_model db:db];
     [iSalesDB execSql:drop_IMAGE db:db];
     [iSalesDB execSql:drop_image_price db:db];
     [iSalesDB execSql:drop_category db:db];
-    
+    [iSalesDB execSql:drop_login db:db];
+    [iSalesDB execSql:drop_cart db:db];
+    [iSalesDB execSql:drop_wish db:db];
+    [iSalesDB execSql:drop_contact db:db];
+    [iSalesDB execSql:drop_contact_image db:db];
     
     NSString* create_model=@"CREATE TABLE IF NOT EXISTS model ( _id INTEGER PRIMARY KEY, name VARCHAR(20), description VARCHAR(20), product_id INTEGER, color VARCHAR(20), legcolor VARCHAR(20) ,availability INTEGER,  incoming_stock INTEGER , demension VARCHAR(20), seat_height VARCHAR(20), meterial VARCHAR(20), box_dim VARCHAR(20), volume VARCHAR(20), weight VARCHAR(20), model_set VARCHAR(20), load_ability VARCHAR(20),default_category VARCHAR(20), category VARCHAR(100),fabric_content VARCHAR(20), assembling VARCHAR(20), made_in VARCHAR(20), special_remarks VARCHAR(20),stockUom integer,fashion VARCHAR(20), isnew integer,property_field VARCHAR(20),property_display VARCHAR(20),selector_field VARCHAR(20),selector_display VARCHAR(20),ETA DATE);";
     
@@ -64,8 +73,21 @@
     
     NSString* create_image=@"CREATE TABLE IF NOT EXISTS model_image ( _id INTEGER PRIMARY KEY, name VARCHAR(20), url VARCHAR(256), type integer, product_id INTEGER);";
     
-    NSString* create_image_price=@"CREATE TABLE IF NOT EXISTS model_price ( _id INTEGER PRIMARY KEY, product_id INTEGER,price float , type integer);";
+    NSString* create_model_price=@"CREATE TABLE IF NOT EXISTS model_price ( _id INTEGER PRIMARY KEY, product_id INTEGER,price float , type integer);";
     NSString* create_category=@"CREATE TABLE IF NOT EXISTS category ( _id INTEGER PRIMARY KEY, code VARCHAR(20),name VARCHAR(20));";
+    
+    NSString* create_offline_login=@"CREATE TABLE IF NOT EXISTS offline_login ( _id INTEGER PRIMARY KEY, username VARCHAR(40),password VARCHAR(40), can_show_price integer ,can_see_price integer,contact_id VARCHAR(20),user_type integer,can_cancel_order integer,can_set_cart_price integer,can_create_portfolio integer, can_delete_order integer,can_submit_order integer,can_set_tearsheet_price integer,can_create_order integer, mode VARCHAR(20));";
+    
+    
+    
+    NSString* create_offline_cart=@"CREATE TABLE IF NOT EXISTS offline_cart ( _id INTEGER PRIMARY KEY, product_id INTEGER,price float , discount float , so_no VARCHAR(40));";
+    NSString* create_offline_wish=@"CREATE TABLE IF NOT EXISTS offline_wishlist ( _id INTEGER PRIMARY KEY, product_id INTEGER);";
+    
+    NSString* create_offline_contact=@"CREATE TABLE IF NOT EXISTS offline_contact ( _id INTEGER PRIMARY KEY, country VARCHAR(40),company_name VARCHAR(40),contact_id VARCHAR(20),addr_1 text, addr_2 text , addr_3 text, addr_4 text, zipcode varchar(20),state  VARCHAR(40), city VARCHAR(40), first_name VARCHAR(40) ,last_name  VARCHAR(40),phone VARCHAR(40),fax VARCHAR(40),email VARCHAR(40),notes text, price_type  VARCHAR(40), sales_rep VARCHAR(40), type VARCHAR(40),create_time timestamp,editable integer,contact_name VARCHAR(40) , addr text);";
+    
+    NSString* create_contact_image=@"CREATE TABLE IF NOT EXISTS contact_image ( _id INTEGER PRIMARY KEY, name VARCHAR(20), url VARCHAR(256),  contact_id VARCHAR(20));";
+    
+    
     //   NSString* create_model_category=@"CREATE TABLE IF NOT EXISTS model_category ( _id INTEGER PRIMARY KEY, product_id INTEGER,code VARCHAR(20));";
     
     //        CREATE TABLE users (_id integer PRIMARY KEY,name varchar(20),pass varchar(20));
@@ -80,8 +102,21 @@
     
     [iSalesDB execSql:create_image db:db];
     
-    [iSalesDB execSql:create_image_price db:db];
+    [iSalesDB execSql:create_model_price db:db];
     [iSalesDB execSql:create_category db:db];
+    
+    [iSalesDB execSql:create_offline_login db:db];
+    
+    [iSalesDB execSql:create_offline_cart db:db];
+    [iSalesDB execSql:create_offline_wish db:db];
+    
+    
+    [iSalesDB execSql:create_offline_contact db:db];
+    
+    [iSalesDB execSql:create_contact_image db:db];
+    
+    NSString * insert_user_queeniey=@"insert into offline_login(can_show_price,can_see_price,contact_id,user_type,can_cancel_order,can_set_cart_price,can_create_portfolio,can_delete_order,can_submit_order,can_set_tearsheet_price,can_create_order,mode,username,password) values(1,1,'NPD',1,1,1,1,1,1,1,1,'Regualar Mode','QueenieY','lj0EPk2Th9zZCVwrcskZOA==')";
+     [iSalesDB execSql:insert_user_queeniey db:db];
     //   [self execSql:create_model_category db:db];
     
     //        if( ![self checkForField:@"search_history" field:@"level" db:db])
@@ -368,10 +403,22 @@
         
         NSString* create_image=@"CREATE TABLE IF NOT EXISTS model_image ( _id INTEGER PRIMARY KEY, name VARCHAR(20), url VARCHAR(256), type integer, product_id INTEGER);";
         
-        NSString* create_image_price=@"CREATE TABLE IF NOT EXISTS model_price ( _id INTEGER PRIMARY KEY, product_id INTEGER,price float , type integer);";
+        NSString* create_model_price=@"CREATE TABLE IF NOT EXISTS model_price ( _id INTEGER PRIMARY KEY, product_id INTEGER,price float , type integer, price_name varchar(30));";
         NSString* create_category=@"CREATE TABLE IF NOT EXISTS category ( _id INTEGER PRIMARY KEY, code VARCHAR(20),name VARCHAR(20));";
         NSString* create_offline_setting=@"CREATE TABLE IF NOT EXISTS offline_setting ( _id INTEGER PRIMARY KEY, name VARCHAR(20),value VARCHAR(40));";
         
+        
+        NSString* create_offline_login=@"CREATE TABLE IF NOT EXISTS offline_login ( _id INTEGER PRIMARY KEY, username VARCHAR(40),password VARCHAR(40), can_show_price integer ,can_see_price integer,contact_id VARCHAR(20),user_type integer,can_cancel_order integer,can_set_cart_price integer,can_create_portfolio integer, can_delete_order integer,can_submit_order integer,can_set_tearsheet_price integer,can_create_order integer, mode VARCHAR(20));";
+        
+        
+        
+        NSString* create_offline_cart=@"CREATE TABLE IF NOT EXISTS offline_cart ( _id INTEGER PRIMARY KEY, product_id INTEGER,price float , discount float , so_no VARCHAR(40));";
+        NSString* create_offline_wish=@"CREATE TABLE IF NOT EXISTS offline_wishlist ( _id INTEGER PRIMARY KEY, product_id INTEGER);";
+        
+        
+        NSString* create_offline_contact=@"CREATE TABLE IF NOT EXISTS offline_contact ( _id INTEGER PRIMARY KEY, country VARCHAR(40),company_name VARCHAR(40),contact_id VARCHAR(20),addr_1 text, addr_2 text , addr_3 text, addr_4 text, zipcode varchar(20),state  VARCHAR(40), city VARCHAR(40), first_name VARCHAR(40) ,last_name  VARCHAR(40),phone VARCHAR(40),fax VARCHAR(40),email VARCHAR(40),notes text, price_type  VARCHAR(40), sales_rep VARCHAR(40), type VARCHAR(40),create_time timestamp,editable integer,contact_name VARCHAR(40) , addr text);";
+        
+        NSString* create_contact_image=@"CREATE TABLE IF NOT EXISTS contact_image ( _id INTEGER PRIMARY KEY, name VARCHAR(20), url VARCHAR(256),  contact_id VARCHAR(20));";
         //        CREATE TABLE users (_id integer PRIMARY KEY,name varchar(20),pass varchar(20));
         //        [self execSql:create_actions_info db:db];
         //        [self execSql:create_fields_info db:db];
@@ -384,10 +431,20 @@
         
         [self execSql:create_image db:db];
         
-        [self execSql:create_image_price db:db];
+        [self execSql:create_model_price db:db];
         [self execSql:create_category db:db];
         [self execSql:create_offline_setting db:db];
         
+        [self execSql:create_offline_login db:db];
+        
+        [self execSql:create_offline_cart db:db];
+        
+        [self execSql:create_offline_wish db:db];
+        
+        [self execSql:create_offline_contact db:db];
+        
+        [self execSql:create_contact_image db:db];
+        
         //        if( ![self checkForField:@"search_history" field:@"level" db:db])
         //        {
         //            NSString* alter_search_history = @"ALTER TABLE search_history ADD level INTEGER";

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

@@ -2058,8 +2058,20 @@ repeat:{
 #else
     [params setValue:@"false" forKey:@"is_debug"];
 #endif
-    NSData* json=[self get_json:URL_UPDATE_AUTH parameters:params];
-    if(json==nil)
+    
+    NSData* json= nil;
+    if(appDelegate.offline_mode)
+    {
+        json= [NSJSONSerialization dataWithJSONObject:[OLDataProvider offline_login:params] options:kNilOptions error:nil];
+        
+    }
+    else
+    {
+        json =[self get_json:URL_UPDATE_AUTH parameters:params];
+
+    }
+    
+        if(json==nil)
         return RESULT_NET_ERROR;
     
 

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

@@ -11,6 +11,8 @@
 @interface OLDataProvider : NSObject
 +(NSDictionary*) offline_category :(NSMutableDictionary *) params;
 +(NSDictionary*) offline_model :(NSMutableDictionary *) params;
++(NSDictionary*) offline_login :(NSMutableDictionary *) params;
++(NSDictionary*) offline_contactlist :(NSMutableDictionary *) params;
 //+(NSDictionary*) model_img :(int)product_id;
 //+(NSDictionary*) model_property :(int)product_id field:(NSString*) value ;
 @end

+ 348 - 65
RedAnt ERP Mobile/iSales-NPD/OLDataProvider.m

@@ -9,6 +9,10 @@
 #import "OLDataProvider.h"
 #import "iSalesDB.h"
 #import "RAUtils.h"
+#import "AESCrypt.h"
+#import "AppDelegate.h"
+
+
 @interface OLDataProvider ()
 
 @end
@@ -17,23 +21,8 @@
 +(NSDictionary*) offline_model :(NSMutableDictionary *) params
 {
     
-    //    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:[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"];
+
+    
     
     
     
@@ -76,7 +65,7 @@
         {
             NSMutableDictionary* item = [[NSMutableDictionary alloc] init];
             
-
+            
             char *name = (char*)sqlite3_column_text(statement, 0);
             if(name==nil)
                 name="";
@@ -94,17 +83,17 @@
             char *color = (char*)sqlite3_column_text(statement, 3);
             if(color==nil)
                 color="";
-//            NSString *nscolor = [[NSString alloc]initWithUTF8String:color];
-//            
-//            char *legcolor = (char*)sqlite3_column_text(statement, 4);
-//            if(legcolor==nil)
-//                legcolor="";
-//            NSString *nslegcolor = [[NSString alloc]initWithUTF8String:legcolor];
-//            
-//            
+            //            NSString *nscolor = [[NSString alloc]initWithUTF8String:color];
+            //
+            //            char *legcolor = (char*)sqlite3_column_text(statement, 4);
+            //            if(legcolor==nil)
+            //                legcolor="";
+            //            NSString *nslegcolor = [[NSString alloc]initWithUTF8String:legcolor];
+            //
+            //
             int availability = sqlite3_column_int(statement, 5);
-//            
-//            int incoming_stock = sqlite3_column_int(statement, 6);
+            //
+            //            int incoming_stock = sqlite3_column_int(statement, 6);
             
             
             char *demension = (char*)sqlite3_column_text(statement, 7);
@@ -185,10 +174,10 @@
                 fashion="";
             NSString *nsfashion = [[NSString alloc]initWithUTF8String:fashion];
             
-//            char *fashion_selector = (char*)sqlite3_column_text(statement, 22);
-//            if(fashion_selector==nil)
-//                fashion_selector="";
-//            NSString *nsfashion_selector = [[NSString alloc]initWithUTF8String:fashion_selector];
+            //            char *fashion_selector = (char*)sqlite3_column_text(statement, 22);
+            //            if(fashion_selector==nil)
+            //                fashion_selector="";
+            //            NSString *nsfashion_selector = [[NSString alloc]initWithUTF8String:fashion_selector];
             
             char *property_field = (char*)sqlite3_column_text(statement, 22);
             if(property_field==nil)
@@ -263,30 +252,15 @@
     
     
     sqlite3_close(db);
-     DebugLog(@"data string: %@",[RAUtils dict2string:ret] );
+    DebugLog(@"data string: %@",[RAUtils dict2string:ret] );
     
     return ret;
 }
 +(NSDictionary*) offline_category :(NSMutableDictionary *) params
 {
     
-//    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:[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"];
+
+    
     
     
     
@@ -315,8 +289,8 @@
     sqlite3_stmt * statement;
     [ret setValue:@"2" forKey:@"result"];
     [ret setValue:[NSString stringWithFormat:@"%d",count] forKey:@"item_total_count"];
-     NSMutableDictionary* items = [[NSMutableDictionary alloc] init];
-//    int count=0;
+    NSMutableDictionary* items = [[NSMutableDictionary alloc] init];
+    //    int count=0;
     if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
     {
         
@@ -324,7 +298,7 @@
         while (sqlite3_step(statement) == SQLITE_ROW)
         {
             NSMutableDictionary* item = [[NSMutableDictionary alloc] init];
-           
+            
             //            char *name = (char*)sqlite3_column_text(statement, 1);
             //            NSString *nsNameStr = [[NSString alloc]initWithUTF8String:name];
             
@@ -335,9 +309,9 @@
             NSString *nsdescription = [[NSString alloc]initWithUTF8String:description];
             
             
-
+            
             int product_id = sqlite3_column_int(statement, 2);
-
+            
             
             char *url = (char*)sqlite3_column_text(statement, 3);
             if(url==nil)
@@ -364,6 +338,315 @@
     
     
     
+    DebugLog(@"data string: %@",[RAUtils dict2string:ret] );
+    
+    return ret;
+}
++(NSDictionary*) offline_login :(NSMutableDictionary *) params
+{
+    
+    
+    
+    NSString* user = [params valueForKey:@"user"];
+    
+    NSString* password = [params valueForKey:@"password"];
+    
+    
+    
+    NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
+    
+    
+    
+    
+    
+    
+    sqlite3 *db = [iSalesDB get_db];
+    
+    
+    
+    
+    
+    NSString *sqlQuery = [NSString stringWithFormat:@"select can_show_price,can_see_price,contact_id,user_type,can_cancel_order,can_set_cart_price,can_create_portfolio,can_delete_order,can_submit_order,can_set_tearsheet_price,can_create_order,mode,username from offline_login where lower(username)='%@' and password='%@'",user.lowercaseString ,[AESCrypt encrypt:password password:@"usai"]];
+    
+    
+
+    
+    DebugLog(@"offline_login sql:%@",sqlQuery);
+    sqlite3_stmt * statement;
+    
+    
+    [ret setValue:[NSNumber numberWithInt:AP_USER_NOT_AUTH ] forKey:@"result"];
+    
+    
+    if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
+    {
+        
+        
+        if (sqlite3_step(statement) == SQLITE_ROW)
+        {
+            
+            [ret setValue:[NSNumber numberWithInt:AP_USER_AUTH ] forKey:@"result"];
+            NSMutableDictionary* header = [[NSMutableDictionary alloc] init];
+            
+            
+            
+            int can_show_price = sqlite3_column_int(statement, 0);
+            int can_see_price = sqlite3_column_int(statement, 1);
+            
+            char *contact_id = (char*)sqlite3_column_text(statement, 2);
+            if(contact_id==nil)
+                contact_id="";
+            NSString *nscontact_id= [[NSString alloc]initWithUTF8String:contact_id];
+            
+            int user_type = sqlite3_column_int(statement, 3);
+            
+            int can_cancel_order = sqlite3_column_int(statement, 4);
+            int can_set_cart_price = sqlite3_column_int(statement, 5);
+            int can_create_portfolio = sqlite3_column_int(statement, 6);
+            int can_delete_order = sqlite3_column_int(statement, 7);
+            int can_submit_order = sqlite3_column_int(statement, 8);
+            int can_set_tearsheet_price = sqlite3_column_int(statement, 9);
+            int can_create_order = sqlite3_column_int(statement, 10);
+            
+            
+            char *mode = (char*)sqlite3_column_text(statement, 11);
+            if(mode==nil)
+                mode="";
+            NSString *nsmode= [[NSString alloc]initWithUTF8String:mode];
+            
+            
+            char *username = (char*)sqlite3_column_text(statement, 12);
+            if(username==nil)
+                username="";
+            NSString *nsusername= [[NSString alloc]initWithUTF8String:username];
+            
+            
+            [header setValue:[NSNumber numberWithBool:can_show_price]   forKey:@"can_show_price"];
+            [header setValue:[NSNumber numberWithBool:can_see_price]   forKey:@"can_see_price"];
+            [header setValue:nscontact_id   forKey:@"contact_id"];
+            [header setValue:[NSNumber numberWithBool:user_type]   forKey:@"user_type"];
+            [header setValue:[NSNumber numberWithBool:can_cancel_order]   forKey:@"can_cancel_order"];
+            [header setValue:[NSNumber numberWithBool:can_set_cart_price]   forKey:@"can_set_cart_price"];
+            [header setValue:[NSNumber numberWithBool:can_create_portfolio]   forKey:@"can_create_portfolio"];
+            [header setValue:[NSNumber numberWithBool:can_delete_order]   forKey:@"can_delete_order"];
+            [header setValue:[NSNumber numberWithBool:can_submit_order]   forKey:@"can_submit_order"];
+            [header setValue:[NSNumber numberWithBool:can_set_tearsheet_price]   forKey:@"can_set_tearsheet_price"];
+            [header setValue:[NSNumber numberWithBool:can_create_order]   forKey:@"can_create_order"];
+            
+            [header setValue:nsusername   forKey:@"username"];
+            
+            
+            [ret setObject:header forKey:@"header"];
+            [ret setValue:nsmode   forKey:@"mode"];
+            
+            
+        }
+        
+        
+        
+        sqlite3_finalize(statement);
+    }
+    
+    
+    
+    sqlite3_close(db);
+    
+    
+    
+    
+    DebugLog(@"data string: %@",[RAUtils dict2string:ret] );
+    
+    return ret;
+}
++(NSDictionary*) offline_contactlist :(NSMutableDictionary *) params
+{
+    
+    
+    
+    
+    
+    NSString* contactType = [params valueForKey:@"contactType"];
+    
+    NSString* keyword = [params valueForKey:@"keyword"];
+    
+    
+    // advanced search
+    
+     NSString* contact_name = [params valueForKey:@"contact_name"];
+     NSString* customer_phone = [params valueForKey:@"customer_phone"];
+     NSString* customer_fax = [params valueForKey:@"customer_fax"];
+     NSString* customer_zipcode = [params valueForKey:@"customer_zipcode"];
+     NSString* sales_rep = [params valueForKey:@"sales_rep"];
+     NSString* customer_state = [params valueForKey:@"customer_state"];
+     NSString* customer_name = [params valueForKey:@"customer_name"];
+     NSString* customer_country = [params valueForKey:@"customer_country"];
+     NSString* customer_cid = [params valueForKey:@"customer_cid"];
+     NSString* customer_city = [params valueForKey:@"customer_city"];
+     NSString* customer_address = [params valueForKey:@"customer_address"];
+     NSString* customer_email = [params valueForKey:@"customer_email"];
+    
+    
+    int limit = [[params valueForKey:@"limit"] intValue];
+    int offset = [[params valueForKey:@"offset"] intValue];
+    
+    
+    NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
+    
+    
+    
+    
+    
+    
+    sqlite3 *db = [iSalesDB get_db];
+    
+    
+    
+    int count =0;
+    
+    
+    
+    NSString *sqlQuery = nil;
+    
+    if(keyword.length==0)
+    {
+        sqlQuery=[NSString stringWithFormat:@"select editable,company_name,country,addr,zipcode,state,city,contact_name,phone,contact_id from offline_contact where contactType='%@' order by create_time limit %d offset %d",contactType , limit, offset];
+        count=[iSalesDB get_recordcount:db table:@"offline_contact" where:[NSString stringWithFormat:@"contactType='%@'",contactType]];
+    }
+    else
+    {
+        keyword = keyword.lowercaseString;
+        sqlQuery=[NSString stringWithFormat:@"select editable,company_name,country,addr,zipcode,state,city,contact_name,phone,contact_id from offline_contact where contactType='%@' and (lower(contact_id ) like'%@' or lower(company_name) like'%@') order by create_time limit %d offset %d",contactType , keyword,keyword,limit, offset];
+    
+        count=[iSalesDB get_recordcount:db table:@"offline_contact" where:[NSString stringWithFormat:@"contactType='%@' and (lower(contact_id ) like'%@' or lower(company_name) like'%@')",contactType,keyword,keyword]];
+    }
+    
+    
+    DebugLog(@"offline_contactlist sql:%@",sqlQuery);
+    sqlite3_stmt * statement;
+    
+    
+    [ret setValue:@"2" forKey:@"result"];
+    [ret setValue:[NSNumber numberWithInt:count ]  forKey:@"total"];
+    
+    
+    if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
+    {
+        
+        int i = 0;
+        while (sqlite3_step(statement) == SQLITE_ROW)
+        {
+            
+            [ret setValue:[NSNumber numberWithInt:AP_USER_AUTH ] forKey:@"result"];
+            
+            NSMutableDictionary* item = [[NSMutableDictionary alloc] init];
+            
+   
+            int editable  = sqlite3_column_int(statement, 0);
+
+            
+            char *company_name = (char*)sqlite3_column_text(statement, 1);
+            NSString *nscompany_name =nil;
+            if(company_name==nil)
+                nscompany_name=@"";
+            else
+                nscompany_name=[NSString stringWithFormat:@"<b>%@</b>", [[NSString alloc]initWithUTF8String:company_name] ];
+            
+            
+            char *country = (char*)sqlite3_column_text(statement, 2);
+            if(country==nil)
+                country="";
+            NSString *nscountry= [[NSString alloc]initWithUTF8String:country];
+            
+            
+            char *addr = (char*)sqlite3_column_text(statement, 3);
+            if(addr==nil)
+                addr="";
+            NSString *nsaddr= [[NSString alloc]initWithUTF8String:addr];
+            
+            
+            char *zipcode = (char*)sqlite3_column_text(statement, 4);
+            if(zipcode==nil)
+                zipcode="";
+            NSString *nszipcode= [[NSString alloc]initWithUTF8String:zipcode];
+            
+            
+            char *state = (char*)sqlite3_column_text(statement, 5);
+            if(state==nil)
+                state="";
+            NSString *nsstate= [[NSString alloc]initWithUTF8String:state];
+            
+            char *city = (char*)sqlite3_column_text(statement, 6);
+            if(city==nil)
+                city="";
+            NSString *nscity= [[NSString alloc]initWithUTF8String:city];
+            
+            char *contact_name = (char*)sqlite3_column_text(statement, 7);
+            NSString *nscontact_name = nil;
+            if(contact_name==nil)
+                nscontact_name=@"";
+            else
+                nscontact_name= [[NSString alloc]initWithUTF8String:contact_name];
+            
+            char *phone = (char*)sqlite3_column_text(statement, 8);
+            NSString *nsphone = nil;
+            if(phone==nil)
+                nsphone=@"";
+            else
+                nsphone= [NSString stringWithFormat:@"TEL:%@",[[NSString alloc]initWithUTF8String:phone]];
+            
+            
+            char *contact_id = (char*)sqlite3_column_text(statement, 9);
+            if(contact_id==nil)
+                contact_id="";
+            NSString *nscontact_id= [[NSString alloc]initWithUTF8String:contact_id];
+            
+
+            
+            NSMutableArray* arr_addr = [[NSMutableArray alloc] init];
+            
+            
+            [arr_addr addObject:nscompany_name];
+            [arr_addr addObject:nscontact_name];
+            [arr_addr addObject:@"<br>"];
+            
+            [arr_addr addObject:nsaddr];
+            [arr_addr addObject:nszipcode];
+            [arr_addr addObject:nscity];
+            [arr_addr addObject:nsstate];
+            [arr_addr addObject:nscountry];
+            [arr_addr addObject:nsphone];
+            
+            
+            NSString * name = [RAUtils arr2string:arr_addr separator:@","];
+            
+            
+          
+            [item setValue:name   forKey:@"name"];
+             [item setValue:nscontact_id   forKey:@"contact_id"];
+            
+            [ret setObject:item forKey:[NSString stringWithFormat:@"item_%d",i]];
+            i++;
+           
+            
+            
+        }
+        UIApplication * app = [UIApplication sharedApplication];
+        AppDelegate *appDelegate = (AppDelegate *)[app delegate];
+         [ret setValue:appDelegate.mode   forKey:@"mode"];
+         [ret setValue:[NSNumber numberWithInt:i ]    forKey:@"count"];
+        
+        
+        
+        sqlite3_finalize(statement);
+    }
+    
+    
+    
+    sqlite3_close(db);
+    
+    
+    
+    
     DebugLog(@"data string: %@",[RAUtils dict2string:ret] );
     
     return ret;
@@ -383,7 +666,7 @@
     
     sqlite3 *db = [iSalesDB get_db];
     
-  //  int count = [iSalesDB get_recordcount:db table:@"model" where:[NSString stringWithFormat:@"category like'#%%%@%%#'",category]];
+    //  int count = [iSalesDB get_recordcount:db table:@"model" where:[NSString stringWithFormat:@"category like'#%%%@%%#'",category]];
     
     
     NSString *sqlQuery = [NSString stringWithFormat:@"select m.name,m.product_id,i.url from model m LEFT join model_image i on m.product_id = i.product_id where m.category like'%%#%@#%%' and isnew=1 and i.type = %d order by m.name ;",category,OFFLINE_IMG_TYPE_CATEGORY];
@@ -437,7 +720,7 @@
     
     
     return ret;
-
+    
     
 }
 +(NSDictionary*) model_kvItem:(NSString*) key value:(NSString*)value
@@ -557,7 +840,7 @@
             
             NSMutableDictionary* params=[[NSMutableDictionary alloc] init];
             [params setValue:@"2" forKey:@"count"];
-             NSMutableDictionary* param0=[[NSMutableDictionary alloc] init];
+            NSMutableDictionary* param0=[[NSMutableDictionary alloc] init];
             [param0 setValue:[NSNumber numberWithInt:product_id ] forKey:@"val"];
             [param0 setValue:@"product_id" forKey:@"name"];
             
@@ -613,10 +896,10 @@
         
         if (sqlite3_step(statement) == SQLITE_ROW)
         {
-           char *url = (char*)sqlite3_column_text(statement, 0);
+            char *url = (char*)sqlite3_column_text(statement, 0);
             if(url==nil)
                 url="";
-             ret = [[NSString alloc]initWithUTF8String:url];
+            ret = [[NSString alloc]initWithUTF8String:url];
             
             
             
@@ -645,8 +928,8 @@
     
     NSString *sqlQuery = [NSString stringWithFormat:@"select url from model_image where product_id=%d and type=%d;",product_id,OFFLINE_IMG_TYPE_DETAIL];
     sqlite3_stmt * statement;
-  
-   
+    
+    
     if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
     {
         
@@ -663,11 +946,11 @@
                 url="";
             NSString *nsurl = [[NSString alloc]initWithUTF8String:url];
             
-           
+            
             
             [item setValue:nsurl forKey:@"s"];
             [item setValue:nsurl forKey:@"l"];
-           
+            
             
             [ret setObject:item forKey:[NSString stringWithFormat:@"img_%d",i]];
             i++;
@@ -678,7 +961,7 @@
         
         sqlite3_finalize(statement);
     }
- 
+    
     
     
     sqlite3_close(db);