Ray Zhang vor 10 Jahren
Ursprung
Commit
309a879cd3

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

@@ -50,7 +50,9 @@
 #define AP_MESSAGE_NEW				 5
 #define AP_MESSAGE_NONE					 6
 
-
+#define OFFLINE_MODE true
+#define OFFLINE_IMG_TYPE_CATEGORY 0
+#define OFFLINE_IMG_TYPE_DETAIL 1
 
 #define RESULT_FALSE 0
 #define RESULT_TRUE		 2

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

@@ -11,6 +11,7 @@
 #import <sqlite3.h>  
 #import "config.h"
 @interface iSalesDB : NSObject
++(void)testdata;
 + (BOOL) initializeDb;
 +(void)execSql:(NSString *)sql db:(sqlite3 *)db;
 +(void)execSql:(NSString *)sql;

+ 188 - 26
RedAnt ERP Mobile/common/data_provider/iSalesDB.m

@@ -10,6 +10,164 @@
 #import "AppDelegate.h"
 @implementation iSalesDB
 
+
++(void)testdata
+{
+    
+    //---------------- init db --------------------
+    //    NSString* date;
+    //    NSDateFormatter* formatter = [[NSDateFormatter alloc]init];
+    //    [formatter setDateFormat:@"YYYY-MM-dd-hh-mm-ss"];
+    //    date = [formatter stringFromDate:[NSDate date]];
+    //
+    //    NSString* dbname=[NSString stringWithFormat:@"%@.db",date];
+    //
+    //    DebugLog (@"initializeDB");
+    //
+    //    //   NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
+    //    NSString *documents = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];//[paths objectAtIndex:0];
+    //    NSString *database_path = [documents stringByAppendingPathComponent:dbname];
+    //
+    //
+    //    // move db file from document to cache ;
+    //    //   NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
+    //    NSString *documentFolderPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] ;//[searchPaths objectAtIndex: 0];
+    //    NSString* dbFilePath = [documentFolderPath stringByAppendingPathComponent:dbname];
+    //    if ([[NSFileManager defaultManager] fileExistsAtPath: dbFilePath])
+    //    {
+    //        [[NSFileManager defaultManager] moveItemAtPath:dbFilePath toPath:database_path error:nil];
+    //
+    //    }
+    //    // end move;
+    //
+    
+    
+    
+    
+    sqlite3 *db = [iSalesDB get_db];
+    
+    NSString* drop_model =@"DROP TABLE IF EXISTS MODEL;";
+    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;";
+    
+    
+    [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];
+    
+    
+    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);";
+    
+    
+    
+    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_category=@"CREATE TABLE IF NOT EXISTS category ( _id INTEGER PRIMARY KEY, code VARCHAR(20),name 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));
+    //        [self execSql:create_actions_info db:db];
+    //        [self execSql:create_fields_info db:db];
+    //        [self execSql:create_search_history db:db];
+    //        [self execSql:create_push_message db:db];
+    //        [self execSql:create_favorites db:db];
+    //        [self execSql:create_history db:db];
+    //        [self execSql:create_location db:db];
+    [iSalesDB execSql:create_model db:db];
+    
+    [iSalesDB execSql:create_image db:db];
+    
+    [iSalesDB execSql:create_image_price db:db];
+    [iSalesDB execSql:create_category db:db];
+    //   [self execSql:create_model_category db:db];
+    
+    //        if( ![self checkForField:@"search_history" field:@"level" db:db])
+    //        {
+    //            NSString* alter_search_history = @"ALTER TABLE search_history ADD level INTEGER";
+    //            [self execSql:alter_search_history db:db];
+    //        }
+    //        NSTimeInterval time=[[NSDate date] timeIntervalSince1970];
+    //        double t = time-2592000;      //NSTimeInterval返回的是double类型
+    //        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
+    //        [formatter setDateFormat:@"yyyy-MM-dd"];
+    //
+    //        NSString*timestr=[formatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:t]];
+    //
+    //    //    [self execSql:[NSString stringWithFormat:@"delete from search_history where h_time<%@",timestr ] db:db];
+    //        [self execSql:@"delete from search_history where julianday('now', 'localtime')-julianday(h_time, 'localtime')>30" db:db];
+    //  int ret=sqlite3_close(db);
+    
+    
+    DebugLog (@"bottom of initializeDb");
+    
+    
+    NSString* IMS_S=@"http://113.28.30.235:80/site//u/NPD/20150715/3857_1455_s.jpg";
+    //NSString* IMS_M=@"http://113.28.30.235:80/site//u/NPD/20150715/3857_1455_m.jpg";
+    NSString* IMS_L=@"http://113.28.30.235:80/site//u/NPD/20150715/3857_1455_l.jpg";
+    
+    //----------------- fill data -------------------
+    NSString* img_url1 = IMS_S;
+    //   NSString* img_url2 = IMS_M;
+    NSString* img_url3 = IMS_L;
+    
+    CFAbsoluteTime start = CFAbsoluteTimeGetCurrent();
+    [iSalesDB execSql:@"begin" db:db];
+    //   NSString* exec = @"";
+    for(int i=0;i<1000;i++)
+    {
+        
+        int category = arc4random() % 4;
+        NSString* sql = [NSString stringWithFormat:@"insert into model(ETA,property_display,property_field,selector_display,isnew,selector_field,fashion,stockUom,name,description,product_id,color,legcolor,availability,incoming_stock,demension,seat_height,meterial,box_dim,volume,weight,model_set,load_ability,default_category,category,fabric_content,assembling,made_in,special_remarks) values('07/13/2016','Leg Color','legcolor','Color',1,'color','108526-48-BS%d',1,'108526-48-BS%d','Charlotte Fabric Counter Stool Brushed Smoke Legs, Putty%d',%d,'red color%d','white color%d',15%d,25%d,'20.00\"w  22.00\"d  39.00\"h%d','26.0\"h','Solid Birch Wood%d','20.50\"w  23.00\"d  40.00\"h',10.91%d,23.00%d,'Sold in quantities of 1','Load ability%d','%d','%d','77%% Polyester, 15%% Cotton, 8%% Linen', 'Fully Assembled;%d','China%d','Special Remarks%d');",i,i,i,i,i,i,i,i,i,i,i,i,i,category,category,i,i,i];
+        
+        
+        NSString* sql_1=[NSString stringWithFormat:@"insert into model_price (product_id,price,type) values(%d,12.%d,0);",i,i%100];
+        NSString* sql_2=[NSString stringWithFormat:@"insert into model_price (product_id,price,type) values(%d,12.%d,1);",i,i%100];
+        NSString* sql_3=[NSString stringWithFormat:@"insert into model_price (product_id,price,type) values(%d,12.%d,2);",i,i%100];
+        
+        
+        
+        NSString* sql_4=[NSString stringWithFormat:@"insert into model_image(product_id,type,url) values(%d,0,'%@')",i,img_url1];
+        NSString* sql_5=[NSString stringWithFormat:@"insert into model_image(product_id,type,url) values(%d,1,'%@')",i,img_url3];
+        
+        //        exec=[exec stringByAppendingString:sql];
+        //
+        //        exec=[exec stringByAppendingString:sql_1];
+        //        exec=[exec stringByAppendingString:sql_2];
+        //        exec=[exec stringByAppendingString:sql_3];
+        
+        
+        [iSalesDB execSql:sql db:db];
+        
+        [iSalesDB execSql:sql_1 db:db];
+        [iSalesDB execSql:sql_2 db:db];
+        [iSalesDB execSql:sql_3 db:db];
+        [iSalesDB execSql:sql_4 db:db];
+        [iSalesDB execSql:sql_5 db:db];
+        
+    }
+    //    [iSalesDB execSql:exec db:db];
+    
+    [iSalesDB execSql:@"update model set category='#001003#;' where category='0'" db:db];
+    [iSalesDB execSql:@"update model set category='#001001#;' where category='1'" db:db];
+    [iSalesDB execSql:@"update model set category='#001002#;' where category='2'" db:db];
+    [iSalesDB execSql:@"update model set category='#001003#;' where category='3'" db:db];
+    [iSalesDB execSql:@"commit" db:db];
+    sqlite3_close(db);
+    
+    CFAbsoluteTime end = CFAbsoluteTimeGetCurrent();
+    
+    //  ((double)(begintime-endtime))/(1000*1000);
+    NSLog(@"time cost: %0.3f", end - start);
+    
+    
+    
+    
+    
+    
+}
 + (sqlite3*) get_db
 {
     sqlite3* db = nil;
@@ -18,6 +176,7 @@
     NSString *documents = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];//[paths objectAtIndex:0];
     NSString *database_path = [documents stringByAppendingPathComponent:DBNAME];
     
+    DebugLog(@"DB path:%@",database_path);
     if (sqlite3_open([database_path UTF8String], &db) != SQLITE_OK) {
         
         DebugLog(@"sqlite3_open failed. msg:%s",sqlite3_errmsg(db));
@@ -40,7 +199,7 @@
     keyWord = [keyWord stringByReplacingOccurrencesOfString:@"_" withString:@"/_"];
     keyWord = [keyWord stringByReplacingOccurrencesOfString:@"(" withString:@"/("];
     keyWord = [keyWord stringByReplacingOccurrencesOfString:@")" withString:@"/)"];
-
+    
     
     return keyWord;
 }
@@ -76,17 +235,17 @@
     }
     NSString *save_path = [pdf_cache stringByAppendingPathComponent:filename];
     
-      NSError *error = [[NSError alloc] init];
+    NSError *error = [[NSError alloc] init];
     
     bool bsuccess=[fileManager copyItemAtPath:temp_path toPath:save_path error:&error];
     
-   
+    
     
     if(bsuccess)
         DebugLog(@"PDF SAVE SUCCESS,%@",filename);
     else
         DebugLog(@"PDF SAVE FAILED,%@",filename);
-  
+    
 }
 + (void) cache_img: (NSData*) imgData :(NSString*) name
 {
@@ -110,15 +269,15 @@
         bool bsuccess=[fileManager createDirectoryAtPath:img_cache withIntermediateDirectories:YES attributes:nil error:&error];
         
         if(!bsuccess)
-                        DebugLog(@"Create cache folder failed");
+            DebugLog(@"Create cache folder failed");
         
-//        if(bsuccess)
-//        {
-//            sqlite3 *db = [self get_db];
-//            
-//            [self execSql:[NSString stringWithFormat:@"insert into img_cache(name) values('%@')",name] db:db];
-//            sqlite3_close(db);
-//        }
+        //        if(bsuccess)
+        //        {
+        //            sqlite3 *db = [self get_db];
+        //
+        //            [self execSql:[NSString stringWithFormat:@"insert into img_cache(name) values('%@')",name] db:db];
+        //            sqlite3_close(db);
+        //        }
     }
     NSString *filePath = [img_cache stringByAppendingPathComponent:name];
     bool bsuccess=[imgData writeToFile:filePath atomically:YES];
@@ -171,20 +330,20 @@
     //    sqlite3_finalize(statement);
     
     
-   // sqlite3_close(db);
+    // sqlite3_close(db);
     return data;
     
 }
 + (BOOL) initializeDb {
     DebugLog (@"initializeDB");
     
- //   NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
+    //   NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
     NSString *documents = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];//[paths objectAtIndex:0];
     NSString *database_path = [documents stringByAppendingPathComponent:DBNAME];
     
     
     // move db file from document to cache ;
- //   NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
+    //   NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
     NSString *documentFolderPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] ;//[searchPaths objectAtIndex: 0];
     NSString* dbFilePath = [documentFolderPath stringByAppendingPathComponent:DBNAME];
     if ([[NSFileManager defaultManager] fileExistsAtPath: dbFilePath])
@@ -203,7 +362,7 @@
     {
         sqlite3 *db = [self get_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));";
+        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 ,ETA DATE, 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));";
         
         
         
@@ -211,7 +370,7 @@
         
         NSString* create_image_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_model_category=@"CREATE TABLE IF NOT EXISTS model_category ( _id INTEGER PRIMARY KEY, product_id INTEGER,code VARCHAR(20));";
+        NSString* create_offline_setting=@"CREATE TABLE IF NOT EXISTS offline_setting ( _id INTEGER PRIMARY KEY, name VARCHAR(20),value VARCHAR(40));";
         
         //        CREATE TABLE users (_id integer PRIMARY KEY,name varchar(20),pass varchar(20));
         //        [self execSql:create_actions_info db:db];
@@ -227,7 +386,7 @@
         
         [self execSql:create_image_price db:db];
         [self execSql:create_category db:db];
-        [self execSql:create_model_category db:db];
+        [self execSql:create_offline_setting db:db];
         
         //        if( ![self checkForField:@"search_history" field:@"level" db:db])
         //        {
@@ -258,7 +417,7 @@
         
         DebugLog(@"sqlite3_exec failed msg:%s",sqlite3_errmsg(db));
         DebugLog(@"sqlite3_exec failed sql:%@",sql);
-       // sqlite3_close(db);
+        // sqlite3_close(db);
         
     }
 }
@@ -269,12 +428,12 @@
     [json setValue:@"1" forKey:@"result"];
     NSString *sqlQuery =nil;
     if(keywords.length>0)
-    sqlQuery=[NSString stringWithFormat: @"SELECT _id,name,file_name,send_to,create_params,c_id,c_name,o_id,pdf_type,create_time FROM pdf_cache where  lower(name) like '%%%@%%' order by create_time desc limit %d offset %d",keywords,limit,offset];
+        sqlQuery=[NSString stringWithFormat: @"SELECT _id,name,file_name,send_to,create_params,c_id,c_name,o_id,pdf_type,create_time FROM pdf_cache where  lower(name) like '%%%@%%' order by create_time desc limit %d offset %d",keywords,limit,offset];
     
     else
         sqlQuery=[NSString stringWithFormat: @"SELECT _id,name,file_name,send_to,create_params,c_id,c_name,o_id,pdf_type,create_time FROM pdf_cache order by create_time desc limit %d offset %d",limit,offset];
     
-   sqlite3_stmt * statement;
+    sqlite3_stmt * statement;
     int count = 0;
     if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
     {
@@ -311,7 +470,7 @@
             
         }
         [json setValue:[NSString stringWithFormat:@"%d",count] forKey:@"count"];
-         [json setValue:@"2" forKey:@"result"];
+        [json setValue:@"2" forKey:@"result"];
     }
     
     sqlite3_close(db);
@@ -320,7 +479,7 @@
 +(void)execSql:(NSString *)sql
 {
     
-            sqlite3 *db = [self get_db];
+    sqlite3 *db = [self get_db];
     [self execSql:sql db:db];
     
     sqlite3_close(db);
@@ -328,7 +487,7 @@
 + (int) get_recordid:(NSString*) tablename where:(NSString*) whereclause
 {
     
-    //    [ApexMobileDB execSql: [NSString stringWithFormat: @"update fields_info set abandon = 1 where user ='%@'",user] db:db];
+    //    [iSalesDB execSql: [NSString stringWithFormat: @"update fields_info set abandon = 1 where user ='%@'",user] db:db];
     return [self get_recordid:tablename where:whereclause order:@"_id"];
 }
 + (int) get_recordcount:(sqlite3*)db table:(NSString*) tablename where:(NSString*) whereclause
@@ -337,6 +496,9 @@
     
     int ret = -1;
     NSString *sqlQuery = [NSString stringWithFormat:@"select count(0) from %@ where %@ ;",tablename,whereclause];
+    
+    
+    DebugLog(@"get_recordcount sql:%@",sqlQuery);
     sqlite3_stmt * statement;
     
     if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
@@ -355,7 +517,7 @@
         }
         sqlite3_finalize(statement);
     }
- //   sqlite3_close(db);
+    //   sqlite3_close(db);
     return ret;
 }
 + (int) get_recordid:(NSString*) tablename where:(NSString*) whereclause order:(NSString*) orderby
@@ -390,7 +552,7 @@
 
 + (int) get_recordid:(sqlite3*)db table:(NSString*) tablename where:(NSString*) whereclause
 {
-    //    [ApexMobileDB execSql: [NSString stringWithFormat: @"update fields_info set abandon = 1 where user ='%@'",user] db:db];
+    //    [iSalesDB execSql: [NSString stringWithFormat: @"update fields_info set abandon = 1 where user ='%@'",user] db:db];
     return [self get_recordid:db table:tablename where:whereclause order:@"_id"];
 }
 

+ 11 - 1
RedAnt ERP Mobile/common/data_provider/iSalesNetwork.m

@@ -8,6 +8,7 @@
 
 #import "iSalesNetwork.h"
 #import "RAUtils.h"
+#import "OLDataProvider.h"
 
 @implementation iSalesNetwork
 
@@ -1712,6 +1713,11 @@ repeat:{
     
     [params setValue:category_id  forKey:@"category"];
     
+    
+    if(appDelegate.offline_mode)
+        return [OLDataProvider offline_model:params];
+    
+    
     NSData* json=[self get_json:URL_ITEM_DETAIL parameters:params];
     if(json==nil)
         return nil;
@@ -1750,12 +1756,13 @@ repeat:{
 //}
 +(NSDictionary*)Category: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword  offset:(long) offset limit:(long) limit
 {
+        AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
 
     
     if(![self IsNetworkAvailable])
         return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
     NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
-    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+
     if(appDelegate.user!=nil)
         [params setValue:appDelegate.user forKey:@"user"];
     if(appDelegate.contact_id!=nil)
@@ -1775,6 +1782,9 @@ repeat:{
     [params setValue:keyword forKey:@"keyword"];
     
     
+    
+    if(appDelegate.offline_mode)
+        return [OLDataProvider offline_category:params];
     NSData* json=[self get_json:URL_CATEGORY parameters:params];
     if(json==nil)
         return nil;

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

@@ -9,6 +9,8 @@
 #import <UIKit/UIKit.h>
 
 @interface OLDataProvider : NSObject
-+(NSDictionary*) get_category :(NSMutableDictionary *) params;
-
++(NSDictionary*) offline_category :(NSMutableDictionary *) params;
++(NSDictionary*) offline_model :(NSMutableDictionary *) params;
+//+(NSDictionary*) model_img :(int)product_id;
+//+(NSDictionary*) model_property :(int)product_id field:(NSString*) value ;
 @end

+ 601 - 15
RedAnt ERP Mobile/iSales-NPD/OLDataProvider.m

@@ -8,12 +8,266 @@
 
 #import "OLDataProvider.h"
 #import "iSalesDB.h"
+#import "RAUtils.h"
 @interface OLDataProvider ()
 
 @end
 
 @implementation OLDataProvider
-+(NSDictionary*) get_category :(NSMutableDictionary *) params
++(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"];
+    
+    
+    
+    NSString* model_name = [params valueForKey:@"product_name"];
+    
+    NSString* product_id = [params valueForKey:@"product_id"];
+    
+    NSString* category = [params valueForKey:@"category"];
+    
+    
+    NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
+    
+    
+    
+    
+    
+    
+    sqlite3 *db = [iSalesDB get_db];
+    
+    int count = [iSalesDB get_recordcount:db table:@"model" where:[NSString stringWithFormat:@"category like'#%%%@%%#'",category]];
+    
+    
+    NSString *sqlQuery = nil;
+    
+    if(product_id==nil)
+        sqlQuery = [NSString stringWithFormat:@"select name,description,product_id,color,legcolor,availability,incoming_stock,demension,seat_height,meterial,box_dim,volume,weight,model_set,load_ability,default_category,fabric_content,assembling,made_in,special_remarks,stockUom,fashion,selector_field,property_field from model where name='%@';",model_name];
+    else
+        sqlQuery = [NSString stringWithFormat:@"select name,description,product_id,color,legcolor,availability,incoming_stock,demension,seat_height,meterial,box_dim,volume,weight,model_set,load_ability,default_category,fabric_content,assembling,made_in,special_remarks,stockUom,fashion,selector_field,property_field from model where product_id=%@;",product_id];
+    
+    sqlite3_stmt * statement;
+    [ret setValue:@"2" forKey:@"result"];
+    [ret setValue:@"2" forKey:@"detail_section_count"];
+    
+    //    int count=0;
+    if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
+    {
+        
+        
+        if (sqlite3_step(statement) == SQLITE_ROW)
+        {
+            NSMutableDictionary* item = [[NSMutableDictionary alloc] init];
+            
+
+            char *name = (char*)sqlite3_column_text(statement, 0);
+            if(name==nil)
+                name="";
+            NSString *nsname = [[NSString alloc]initWithUTF8String:name];
+            
+            char *description = (char*)sqlite3_column_text(statement, 1);
+            if(description==nil)
+                description="";
+            NSString *nsdescription = [[NSString alloc]initWithUTF8String:description];
+            
+            
+            int product_id = sqlite3_column_int(statement, 2);
+            
+            
+            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];
+//            
+//            
+            int availability = sqlite3_column_int(statement, 5);
+//            
+//            int incoming_stock = sqlite3_column_int(statement, 6);
+            
+            
+            char *demension = (char*)sqlite3_column_text(statement, 7);
+            if(demension==nil)
+                demension="";
+            NSString *nsdemension = [[NSString alloc]initWithUTF8String:demension];
+            
+            
+            
+            //          ,,,,,,,,,
+            
+            
+            char *seat_height = (char*)sqlite3_column_text(statement, 8);
+            if(seat_height==nil)
+                seat_height="";
+            NSString *nsseat_height = [[NSString alloc]initWithUTF8String:seat_height];
+            
+            
+            char *meterial = (char*)sqlite3_column_text(statement, 9);
+            if(meterial==nil)
+                meterial="";
+            NSString *nsmeterial = [[NSString alloc]initWithUTF8String:meterial];
+            
+            char *box_dim = (char*)sqlite3_column_text(statement, 10);
+            if(box_dim==nil)
+                box_dim="";
+            NSString *nsbox_dim = [[NSString alloc]initWithUTF8String:box_dim];
+            
+            char *volume = (char*)sqlite3_column_text(statement, 11);
+            if(volume==nil)
+                volume="";
+            NSString *nsvolume = [[NSString alloc]initWithUTF8String:volume];
+            
+            double weight = sqlite3_column_double(statement, 12);
+            
+            char *model_set = (char*)sqlite3_column_text(statement, 13);
+            if(model_set==nil)
+                model_set="";
+            NSString *nsmodel_set = [[NSString alloc]initWithUTF8String:model_set];
+            
+            char *load_ability = (char*)sqlite3_column_text(statement, 14);
+            if(load_ability==nil)
+                load_ability="";
+            NSString *nsload_ability = [[NSString alloc]initWithUTF8String:load_ability];
+            
+            char *default_category = (char*)sqlite3_column_text(statement, 15);
+            if(default_category==nil)
+                default_category="";
+            NSString *nsdefault_category = [[NSString alloc]initWithUTF8String:default_category];
+            
+            
+            char *fabric_content = (char*)sqlite3_column_text(statement, 16);
+            if(fabric_content==nil)
+                fabric_content="";
+            NSString *nsfabric_content = [[NSString alloc]initWithUTF8String:fabric_content];
+            
+            char *assembling = (char*)sqlite3_column_text(statement, 17);
+            if(assembling==nil)
+                assembling="";
+            NSString *nsassembling = [[NSString alloc]initWithUTF8String:assembling];
+            
+            char *made_in = (char*)sqlite3_column_text(statement, 18);
+            if(made_in==nil)
+                made_in="";
+            NSString *nsmade_in = [[NSString alloc]initWithUTF8String:made_in];
+            
+            
+            char *special_remarks = (char*)sqlite3_column_text(statement, 19);
+            if(special_remarks==nil)
+                special_remarks="";
+            NSString *nsspecial_remarks = [[NSString alloc]initWithUTF8String:special_remarks];
+            
+            
+            int stockUcom = sqlite3_column_double(statement, 20);
+            
+            char *fashion = (char*)sqlite3_column_text(statement, 21);
+            if(fashion==nil)
+                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 *property_field = (char*)sqlite3_column_text(statement, 22);
+            if(property_field==nil)
+                property_field="";
+            NSString *nsproperty_field = [[NSString alloc]initWithUTF8String:property_field];
+            
+            [ret setValue:[NSString stringWithFormat:@"%d",product_id] forKey:@"product_id"];
+            
+            NSMutableDictionary* img_section = [[NSMutableDictionary alloc] init];
+            [img_section setObject:[self model_img:product_id] forKey:@"images"];
+            [img_section setObject:[self model_property:product_id field:nsproperty_field] forKey:@"property"];
+            [img_section setObject:[self model_selector:nsfashion field:nsproperty_field] forKey:@"selector"];
+            NSString* Availability=nil;
+            if(availability>0)
+                Availability=[NSString stringWithFormat:@"%d",availability];
+            else
+                Availability = @"In Production";
+            
+            [img_section setValue:Availability forKey:@"Availability"];
+            [img_section setValue:[NSString stringWithFormat:@"%d",stockUcom] forKey:@"stockUom"];
+            
+            NSString* Price=@"Must Sign in.";
+            
+            [img_section setValue:Price forKey:@"price"];
+            [img_section setValue:nsname forKey:@"model_name"];
+            [img_section setValue:nsdescription forKey:@"model_descrition"];
+            
+            [ret setObject:img_section forKey:@"img_section"];
+            
+            NSMutableDictionary* detail0_section = [[NSMutableDictionary alloc] init];
+            int detail0_item_count=0;
+            
+            [detail0_section setObject:[self model_kvItem:@"Dimension" value:nsdemension] forKey:[NSString stringWithFormat:@"item_%d",detail0_item_count++]];
+            [detail0_section setObject:[self model_kvItem:@"Seat Height" value:nsseat_height] forKey:[NSString stringWithFormat:@"item_%d",detail0_item_count++]];
+            [detail0_section setObject:[self model_kvItem:@"Material" value:nsmeterial] forKey:[NSString stringWithFormat:@"item_%d",detail0_item_count++]];
+            [detail0_section setObject:[self model_kvItem:@"Box dimension" value:nsbox_dim] forKey:[NSString stringWithFormat:@"item_%d",detail0_item_count++]];
+            [detail0_section setObject:[self model_kvItem:@"Volume" value:nsvolume] forKey:[NSString stringWithFormat:@"item_%d",detail0_item_count++]];
+            [detail0_section setObject:[self model_kvItem:@"Weight" value:[NSString stringWithFormat:@"%0.2f",weight]] forKey:[NSString stringWithFormat:@"item_%d",detail0_item_count++]];
+            [detail0_section setObject:[self model_kvItem:@"Set" value:nsmodel_set] forKey:[NSString stringWithFormat:@"item_%d",detail0_item_count++]];
+            [detail0_section setObject:[self model_kvItem:@"Load ability" value:nsload_ability] forKey:[NSString stringWithFormat:@"item_%d",detail0_item_count++]];
+            [detail0_section setObject:[self model_kvItem:@"Fabric Content" value:nsfabric_content] forKey:[NSString stringWithFormat:@"item_%d",detail0_item_count++]];
+            [detail0_section setObject:[self model_kvItem:@"Assembling" value:nsassembling] forKey:[NSString stringWithFormat:@"item_%d",detail0_item_count++]];
+            [detail0_section setObject:[self model_kvItem:@"Made in" value:nsmade_in] forKey:[NSString stringWithFormat:@"item_%d",detail0_item_count++]];
+            [detail0_section setObject:[self model_kvItem:@"Special Remarks" value:nsspecial_remarks] forKey:[NSString stringWithFormat:@"item_%d",detail0_item_count++]];
+            
+            
+            [detail0_section setValue:[NSString stringWithFormat:@"%d",detail0_item_count] forKey:@"count"];
+            [detail0_section setValue:@"kv" forKey:@"type"];
+            [detail0_section setValue:@"Product Information" forKey:@"title"];
+            
+            [ret setObject:detail0_section forKey:@"detail_0"];
+            
+            
+            NSMutableDictionary* detail1_section = [[self model_NIYMAL:category] mutableCopy];
+            [detail1_section setValue:@"detail" forKey:@"target"];
+            [detail1_section setValue:@"popup" forKey:@"action"];
+            [detail1_section setValue:@"content" forKey:@"type"];
+            
+            [ret setObject:detail1_section forKey:@"detail_1"];
+        }
+        
+        
+        
+        
+        sqlite3_finalize(statement);
+    }
+    else
+    {
+        [ret setValue:@"8" forKey:@"result"];
+    }
+    NSLog(@"count:%d",count);
+    
+    
+    sqlite3_close(db);
+     DebugLog(@"data string: %@",[RAUtils dict2string:ret] );
+    
+    return ret;
+}
++(NSDictionary*) offline_category :(NSMutableDictionary *) params
 {
     
 //    if(appDelegate.user!=nil)
@@ -52,17 +306,25 @@
     
     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.description,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 i.type =%d order by m.name limit %d offset %d ;",category,OFFLINE_IMG_TYPE_CATEGORY,limit, offset];
     
-    NSString *sqlQuery = @"select m.name,m.description,m.product_id,i.name from model m LEFT join model_image i on m.product_id = i.product_id";
+    DebugLog(@"offline_category sql:%@",sqlQuery);
     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;
     if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
     {
         
+        int i=0;
         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];
             
@@ -73,22 +335,99 @@
             NSString *nsdescription = [[NSString alloc]initWithUTF8String:description];
             
             
-//            NSLog(@"product name:%@ price:%@",nsname,nsprice);
+
+            int product_id = sqlite3_column_int(statement, 2);
+
+            
+            char *url = (char*)sqlite3_column_text(statement, 3);
+            if(url==nil)
+                url="";
+            NSString *nsurl = [[NSString alloc]initWithUTF8String:url];
+            
+            [item setValue:nsurl forKey:@"img"];
+            [item setValue:nsname forKey:@"name"];
+            [item setValue:nsdescription forKey:@"description"];
+            [item setValue:[NSString stringWithFormat:@"%d",product_id] forKey:@"product_id"];
+            [items setObject:item forKey:[NSString stringWithFormat:@"item_%d",i]];
+            i++;
+            
+        }
+        [items setValue:[NSString stringWithFormat:@"%d",i] forKey:@"count"];
+        [ret setObject:items forKey:@"items"];
+        sqlite3_finalize(statement);
+    }
+    NSLog(@"count:%d",count);
+    
+    
+    sqlite3_close(db);
+    
+    
+    
+    
+    DebugLog(@"data string: %@",[RAUtils dict2string:ret] );
+    
+    return ret;
+}
++(NSDictionary*) model_NIYMAL:(NSString*) category
+{
+    // MODEL DETAIL NEW ITEM YOU MAY ALSO LIKE
+    
+    
+    
+    NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
+    
+    
+    
+    
+    
+    
+    sqlite3 *db = [iSalesDB get_db];
+    
+  //  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];
+    sqlite3_stmt * statement;
+    int count = 0;
+    [ret setValue:[NSString stringWithFormat:@"%d",count] forKey:@"count"];
+    
+    //    int count=0;
+    if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
+    {
+        
+        int i=0;
+        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];
+            
+            char *name = (char*)sqlite3_column_text(statement, 0);
+            NSString *nsname = [[NSString alloc]initWithUTF8String:name];
+            
+            
             
-            //            NSData* img_data=[ApexMobileDB load_cached_img:nsname];
-            //
-            //            if(img_data!=nil)
-            //            {
-            //
-            //                UIImage * img =[UIImage imageWithData:img_data];
-            //                self.imageView.image = img;
-            //            }
-            //
-            //            char *address = (char*)sqlite3_column_text(statement, 3);
-            //            NSString *nsAddressStr = [[NSString alloc]initWithUTF8String:address];
             
+            int product_id = sqlite3_column_int(statement, 1);
+            
+            
+            char *url = (char*)sqlite3_column_text(statement, 2);
+            if(url==nil)
+                url="";
+            NSString *nsurl = [[NSString alloc]initWithUTF8String:url];
+            
+            [item setValue:nsurl forKey:@"picture_path"];
+            [item setValue:nsname forKey:@"fash_name"];
+            [item setValue:[NSString stringWithFormat:@"%d",product_id] forKey:@"product_id"];
+            [item setValue:category forKey:@"category"];
+            [ret setObject:item forKey:[NSString stringWithFormat:@"item_%d",i]];
+            i++;
             
         }
+        [ret setValue:[NSString stringWithFormat:@"%d",i] forKey:@"count"];
+        
+        
         sqlite3_finalize(statement);
     }
     NSLog(@"count:%d",count);
@@ -97,6 +436,253 @@
     sqlite3_close(db);
     
     
+    return ret;
+
+    
+}
++(NSDictionary*) model_kvItem:(NSString*) key value:(NSString*)value
+{
+    NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
+    
+    [ret setValue:key forKey:@"key"];
+    [ret setValue:value forKey:@"val"];
+    return ret;
+}
++(NSDictionary*) model_property :(int)product_id field:(NSString*) field
+{
+    NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
+    
+    [ret setValue:@"0" forKey:@"img_count"];
+    
+    sqlite3 *db = [iSalesDB get_db];
+    
+    
+    
+    
+    NSString *sqlQuery = [NSString stringWithFormat:@"select %@,property_display from model where product_id=%d ;",field,product_id];
+    sqlite3_stmt * statement;
+    
+    
+    if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
+    {
+        
+        int i=0;
+        if (sqlite3_step(statement) == SQLITE_ROW)
+        {
+            NSMutableDictionary* item = [[NSMutableDictionary alloc] init];
+            
+            //            char *name = (char*)sqlite3_column_text(statement, 1);
+            //            NSString *nsNameStr = [[NSString alloc]initWithUTF8String:name];
+            
+            char *value = (char*)sqlite3_column_text(statement, 0);
+            if(value==nil)
+                value="";
+            NSString *nsvalue = [[NSString alloc]initWithUTF8String:value];
+            
+            char *key = (char*)sqlite3_column_text(statement, 1);
+            if(key==nil)
+                key="";
+            NSString *nskey = [[NSString alloc]initWithUTF8String:key];
+            
+            [item setValue:nsvalue forKey:@"val"];
+            [item setValue:nskey forKey:@"key"];
+            
+            
+            [ret setObject:item forKey:[NSString stringWithFormat:@"item_%d",i]];
+            [ret setValue:@"1" forKey:@"count"];
+            i++;
+            
+        }
+        
+        
+        
+        sqlite3_finalize(statement);
+    }
+    
+    
+    
+    sqlite3_close(db);
+    
+    return ret;
+}
++(NSDictionary*) model_selector :(NSString*)fashion field:(NSString*) field
+{
+    NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
+    
+    [ret setValue:@"0" forKey:@"count"];
+    
+    sqlite3 *db = [iSalesDB get_db];
+    
+    
+    
+    
+    NSString *sqlQuery = [NSString stringWithFormat:@"select %@,selector_display,product_id,category from model where fashion='%@'  order by name;",field,fashion];
+    sqlite3_stmt * statement;
+    
+    
+    if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
+    {
+        
+        int i=0;
+        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];
+            
+            char *value = (char*)sqlite3_column_text(statement, 0);
+            if(value==nil)
+                value="";
+            NSString *nsvalue = [[NSString alloc]initWithUTF8String:value];
+            
+            char *selector_display = (char*)sqlite3_column_text(statement, 1);
+            if(selector_display==nil)
+                selector_display="";
+            NSString *nsselector_display = [[NSString alloc]initWithUTF8String:selector_display];
+            
+            
+            int product_id = sqlite3_column_int(statement, 2);
+            
+            
+            char *category = (char*)sqlite3_column_text(statement, 3);
+            if(category==nil)
+                category="";
+            NSString *nscategory = [[NSString alloc]initWithUTF8String:category];
+            
+            NSString* url = [self category_img:product_id];
+            
+            [item setValue:nsvalue forKey:@"title"];
+            [item setValue:url forKey:@"pic_url"];
+            
+            NSMutableDictionary* params=[[NSMutableDictionary alloc] init];
+            [params setValue:@"2" forKey:@"count"];
+             NSMutableDictionary* param0=[[NSMutableDictionary alloc] init];
+            [param0 setValue:[NSNumber numberWithInt:product_id ] forKey:@"val"];
+            [param0 setValue:@"product_id" forKey:@"name"];
+            
+            
+            NSMutableDictionary* param1=[[NSMutableDictionary alloc] init];
+            [param1 setValue:nscategory forKey:@"val"];
+            [param1 setValue:@"category" forKey:@"name"];
+            
+            [params setObject:param0 forKey:@"param_0"];
+            [params setObject:param1 forKey:@"param_1"];
+            
+            
+            [item setObject:params forKey:@"params"];
+            
+            
+            
+            [ret setValue:nsselector_display forKey:@"name"];
+            
+            [ret setObject:item forKey:[NSString stringWithFormat:@"item_%d",i]];
+            i++;
+            
+        }
+        [ret setValue:[NSString stringWithFormat:@"%d",i] forKey:@"count"];
+        [ret setValue:@"switch" forKey:@"action"];
+        
+        sqlite3_finalize(statement);
+    }
+    
+    
+    
+    sqlite3_close(db);
+    
+    return ret;
+}
++(NSString*) category_img :(int)product_id
+{
+    // model 在 category search 显示的图片。
+    NSString* ret =nil;
+    
+    [ret setValue:@"0" forKey:@"img_count"];
+    
+    sqlite3 *db = [iSalesDB get_db];
+    
+    
+    
+    NSString *sqlQuery = [NSString stringWithFormat:@"select url from model_image where product_id=%d and type=%d;",product_id,OFFLINE_IMG_TYPE_CATEGORY];
+    sqlite3_stmt * statement;
+    
+    
+    if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
+    {
+        
+        
+        if (sqlite3_step(statement) == SQLITE_ROW)
+        {
+           char *url = (char*)sqlite3_column_text(statement, 0);
+            if(url==nil)
+                url="";
+             ret = [[NSString alloc]initWithUTF8String:url];
+            
+            
+            
+        }
+        
+        
+        
+        sqlite3_finalize(statement);
+    }
+    
+    
+    
+    sqlite3_close(db);
+    
+    return ret;
+}
++(NSDictionary*) model_img :(int)product_id
+{
+    NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
+    
+    [ret setValue:@"0" forKey:@"img_count"];
+    
+    sqlite3 *db = [iSalesDB get_db];
+    
+    
+    
+    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)
+    {
+        
+        int i=0;
+        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];
+            
+            char *url = (char*)sqlite3_column_text(statement, 0);
+            if(url==nil)
+                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++;
+            
+        }
+        [ret setValue:[NSString stringWithFormat:@"%d",i] forKey:@"img_count"];
+        
+        
+        sqlite3_finalize(statement);
+    }
+ 
+    
+    
+    sqlite3_close(db);
+    
     return ret;
 }