| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478 |
- //
- // OLDataProvider.m
- // iSales-NPD
- //
- // Created by Ray on 2/2/16.
- // Copyright © 2016 United Software Applications, Inc. All rights reserved.
- //
- #import "OLDataProvider.h"
- #import "iSalesDB.h"
- #import "RAUtils.h"
- #import "AESCrypt.h"
- #import "AppDelegate.h"
- @interface OLDataProvider ()
- @end
- @implementation OLDataProvider
- +(bool) check_offlinedata
- {
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- sqlite3 *db = [iSalesDB get_db];
- NSString * where=@"1=1";
- // if(appDelegate.user!=nil)
- // where=[NSString stringWithFormat:@"lower(username)='%@'",appDelegate.user.lowercaseString];
- int count = [iSalesDB get_recordcount:db table:@"offline_login" where:where];
- if(count==0)
- {
- return false;
- }
- return true;
- //
- sqlite3_close(db);
- }
- +(NSDictionary*) offline_deletewishlist :(NSMutableDictionary *) params
- {
-
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
-
- NSMutableDictionary* ret=[[NSMutableDictionary alloc]init];
- sqlite3 *db = [iSalesDB get_db];
- NSString* collectId=params[@"collectId"];
-
-
-
-
- NSString* sqlQuery = [NSString stringWithFormat:@"delete from wishlist where _id in (%@);",collectId];
- [iSalesDB execSql:sqlQuery];
- int count=[iSalesDB get_recordcount:db table:@"wishlist" where:@"1=1"];
- sqlite3_close(db);
-
- appDelegate.wish_count =count;
-
- [appDelegate update_count_mark];
- ret[@"result"]= [NSNumber numberWithInt:2];
- return ret;
- }
- +(NSDictionary*) offline_add2wishlist :(NSMutableDictionary *) params
- {
-
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
-
- NSMutableDictionary* ret=[[NSMutableDictionary alloc]init];
- sqlite3 *db = [iSalesDB get_db];
- NSString* product_id=params[@"product_id"];
-
-
- NSArray* arr=[RAUtils string2arr:product_id separator:@","];
-
-
- for(int i=0;i<arr.count;i++)
- {
- NSString* where=[NSString stringWithFormat:@"product_id=%@",arr[i]];
- int count=[iSalesDB get_recordcount:db table:@"wishlist" where:where];
- if(count==0)
- {
- NSString* sqlQuery = [NSString stringWithFormat:@"insert into wishlist(product_id) values('%@');",arr[i]];
- [iSalesDB execSql:sqlQuery];
- }
- }
- int count=[iSalesDB get_recordcount:db table:@"wishlist" where:@"1=1"];
- sqlite3_close(db);
-
- appDelegate.wish_count =count;
-
- [appDelegate update_count_mark];
- ret[@"result"]= [NSNumber numberWithInt:2];
- return ret;
- //
- //return ret;
- }
- +(NSDictionary*) offline_wishlist :(NSMutableDictionary *) params
- {
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
-
-
-
- NSString* user = appDelegate.user;
-
- sqlite3 *db = [iSalesDB get_db];
-
- NSString* sqlQuery = @"select w.product_id,m.name||'\n'||m.description,w._id from wishlist as w left join model as m on w.product_id=m.product_id order by w.create_time;";
- sqlite3_stmt * statement;
-
-
- NSMutableDictionary* ret=[[NSMutableDictionary alloc]init];
- int count=0;
-
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
- {
-
-
- while (sqlite3_step(statement) == SQLITE_ROW)
- {
-
-
-
- NSMutableDictionary* item=[[NSMutableDictionary alloc]init];
-
- int product_id = sqlite3_column_double(statement, 0);
-
-
-
-
-
- char *description = (char*)sqlite3_column_text(statement, 1);
- if(description==nil)
- description= "";
- NSString *nsdescription= [[NSString alloc]initWithUTF8String:description];
-
- int item_id = sqlite3_column_double(statement, 2);
-
-
- NSString *nsurl=[self model_category_img:[NSString stringWithFormat:@"%@",[NSNumber numberWithInt:product_id]] model_name:nil];
-
- // char *url = (char*)sqlite3_column_text(statement, 3);
- // if(url==nil)
- // url="";
- // NSString *nsurl = [[NSString alloc]initWithUTF8String:url];
-
-
-
- item[@"product_id"]= [NSString stringWithFormat:@"%d",product_id];
- item[@"item_id"]= [NSString stringWithFormat:@"%d",item_id];
- item[@"description"]= nsdescription;
- item[@"img"]= nsurl;
-
-
-
- ret[[NSString stringWithFormat:@"item_%d",count]]= item;
- count++;
-
- }
-
- ret[@"count"]= [NSNumber numberWithInt:count];
- ret[@"total_count"]= [NSNumber numberWithInt:count];
- // ret[@"wish_count"]= [NSNumber numberWithInt:count];
- ret[@"result"]= [NSNumber numberWithInt:2];
-
-
- appDelegate.wish_count =count;
-
- [appDelegate update_count_mark];
- sqlite3_finalize(statement);
-
-
-
-
- }
-
- sqlite3_close(db);
-
- return ret;
- }
- +(NSDictionary*) offline_notimpl
- {
-
- NSMutableDictionary* ret=[[NSMutableDictionary alloc]init];
- ret[@"result"]=@"8";
- ret[@"err_msg"]=@"offline mode does not support this function.";
- return ret;
- }
- +(NSDictionary*) offline_home
- {
-
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
- NSString *cachefolder = [paths objectAtIndex:0];
- NSString *img_cache = [cachefolder stringByAppendingPathComponent:@"offline_data/home.json"];
-
-
- NSData* json =nil;
- json=[NSData dataWithContentsOfFile:img_cache];
- NSError *error=nil;
- NSMutableDictionary* menu = [[NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
-
- return menu;
- }
- +(NSDictionary*) offline_category_menu
- {
-
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
- NSString *cachefolder = [paths objectAtIndex:0];
- NSString *img_cache = [cachefolder stringByAppendingPathComponent:@"offline_data/category_menu.json"];
-
-
- NSData* json =nil;
- json=[NSData dataWithContentsOfFile:img_cache];
- NSError *error=nil;
- NSMutableDictionary* menu = [[NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
-
- return menu;
- }
- +(NSDictionary*) offline_commoneditor_partialrefresh :(NSMutableDictionary *) params
- {
- NSString* offline_command=params[@"offline_Command"];
- NSDictionary* ret=nil;
- if([offline_command isEqualToString:@"model_NIYMAL"])
- {
- NSString* category = params[@"category"];
- ret = [self refresh_model_NIYMAL:category];
- }
- return ret;
- }
- +(NSDictionary*) refresh_model_NIYMAL :(NSString *) category
- {
-
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
-
-
- [ret setValue:@"2" forKey:@"result"];
- [ret setValue:@"Regular Mode" forKey:@"mode"];
- NSMutableDictionary* detail1_section = [[self model_NIYMAL:category] mutableCopy];
-
- [ret setObject:detail1_section forKey:@"detail_1"];
- return ret;
- }
- +(NSMutableDictionary*) get_model_all_price:(NSString*) contact_id product_id:(int) product_id
- {
-
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
-
- // NSArray* arr1 = [self get_user_all_price_type];
- NSArray* arr2 = [self get_contact_default_price_type:contact_id];
-
- // NSSet *set1 = [NSSet setWithArray:arr1];
- // NSMutableSet *set2 = [[NSSet setWithArray:arr2] mutableCopy];
-
- // if(appDelegate.contact_id==nil)
- // set2=[set1 mutableCopy];
- // else
- // [set2 intersectsSet:set1];
-
-
- // NSArray *retarr = [set2 allObjects];
-
- NSString* whereprice=[RAUtils arr2string:arr2 separator:@"," trim:true brackets:@"'"];
-
-
- sqlite3 *db = [iSalesDB get_db];
-
- NSString* sqlQuery = nil;
- if(appDelegate.contact_id==nil)
- sqlQuery=[NSString stringWithFormat:@"select a.name,b.price from price as a left join model_price as b on a.name=b.price_name and b.product_id=%d order by a.order_by;",product_id];
- else
- sqlQuery=[NSString stringWithFormat:@"select a.name,b.price from price as a left join model_price as b on a.name=b.price_name and b.product_id=%d and b.price_name in(%@) order by a.order_by;",product_id,whereprice];
- sqlite3_stmt * statement;
-
-
- NSMutableDictionary* ret=[[NSMutableDictionary alloc]init];
- int count=0;
-
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
- {
-
-
- while (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];
-
- // double price = sqlite3_column_double(statement, 1);
-
- // char *isnull = (char*)sqlite3_column_text(statement, 1);
- // if(isnull==nil)
- // item[nsname]= @"No Price";
- // else
- // item[nsname]= [NSString stringWithFormat:@"%.2f",price];
-
- char *price = (char*)sqlite3_column_text(statement, 1);
- if(price!=nil)
- {
- NSString* nsprice = [[NSString alloc]initWithUTF8String:price];
- nsprice=[AESCrypt fastdecrypt:nsprice];
- if(nsprice.length>0)
- {
- double dp= [nsprice doubleValue];
- item[nsname]= [NSString stringWithFormat:@"%.2f",dp];
- }
- }
- else
- {
- item[nsname]= @"No Price";
- }
-
-
- // item[nsname]= nsprice;
-
- ret[[NSString stringWithFormat:@"item_%d",count]]= item;
- count++;
-
- }
-
- ret[@"count"]= [NSNumber numberWithInt:count];
-
-
-
- sqlite3_finalize(statement);
-
-
-
-
- }
-
- sqlite3_close(db);
-
- return ret;
- }
- +(NSNumber*) get_model_default_price:(NSString*) contact_id product_id:(int) product_id
- {
- NSArray* arr1 = [self get_user_all_price_type];
- NSArray* arr2 = [self get_contact_default_price_type:contact_id];
-
- // NSSet *set1 = [NSSet setWithArray:arr1];
- // NSMutableSet *set2 = [[NSSet setWithArray:arr2] mutableCopy];
- // [set2 intersectsSet:set1];
- //
- //
- // NSArray *retarr = [set2 allObjects];
-
- NSString* whereprice=nil;
- if(contact_id==nil)
- whereprice=[RAUtils arr2string:arr1 separator:@"," trim:true brackets:@"'"];
- else
- whereprice=[RAUtils arr2string:arr2 separator:@"," trim:true brackets:@"'"];
-
-
- sqlite3 *db = [iSalesDB get_db];
-
- NSString* sqlQuery = [NSString stringWithFormat:@"select price from model_price where product_id='%d' and price_name in(%@);",product_id,whereprice];
- sqlite3_stmt * statement;
-
-
- NSNumber* ret = nil;
- double dprice=DBL_MAX;
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
- {
-
-
- while (sqlite3_step(statement) == SQLITE_ROW)
- {
-
- // double val = sqlite3_column_double(statement, 0);
- char *price = (char*)sqlite3_column_text(statement, 0);
- if(price!=nil)
- {
- NSString* nsprice = [[NSString alloc]initWithUTF8String:price];
- nsprice=[AESCrypt fastdecrypt:nsprice];
- if(nsprice.length>0)
- {
- double dp= [nsprice doubleValue];
- if(dp<dprice)
- dprice=dp;
- }
- }
- }
-
-
-
-
- sqlite3_finalize(statement);
-
-
-
-
- }
-
- sqlite3_close(db);
-
- if(dprice==DBL_MAX)
- ret= nil;
- else
- ret= [NSNumber numberWithDouble:dprice];
- return ret;
- }
- +(NSArray*) get_user_all_price_type
- {
-
- NSArray* ret=nil;
-
- sqlite3 *db = [iSalesDB get_db];
- // no customer assigned , use login user contact_id
-
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- NSString* sqlQuery = [NSString stringWithFormat:@"select price from offline_login where username='%@';",appDelegate.user];
- sqlite3_stmt * statement;
-
-
-
-
- // int count=0;
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
- {
-
-
- if (sqlite3_step(statement) == SQLITE_ROW)
- {
-
- char *val = (char*)sqlite3_column_text(statement, 0);
- if(val==nil)
- val="";
- NSString* price = [[NSString alloc]initWithUTF8String:val];
-
- ret=[RAUtils string2arr:price separator:OFFLINE_ARRAY_SEPARATOR];
-
- }
-
-
-
-
- sqlite3_finalize(statement);
-
-
-
-
- }
-
- sqlite3_close(db);
-
- return ret;
-
-
-
- }
- +(NSArray*) get_contact_default_price_type:(NSString*) contact_id
- {
-
- sqlite3 *db = [iSalesDB get_db];
- if(contact_id==nil)
- {
- // no customer assigned , use login user contact_id
-
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- NSString* sqlQuery = [NSString stringWithFormat:@"select contact_id from offline_login where username='%@';",appDelegate.user];
- sqlite3_stmt * statement;
-
-
-
-
- // int count=0;
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
- {
-
-
- if (sqlite3_step(statement) == SQLITE_ROW)
- {
-
- char *val = (char*)sqlite3_column_text(statement, 0);
- if(val==nil)
- val="";
- contact_id = [[NSString alloc]initWithUTF8String:val];
-
-
-
- }
-
-
-
-
- sqlite3_finalize(statement);
-
-
-
-
- }
-
- if(contact_id.length<=0)
- {
- sqlite3_close(db);
- return nil;
- }
-
- }
-
- NSString* sqlQuery = [NSString stringWithFormat:@"select price_type from offline_contact where contact_id='%@';",contact_id];
- sqlite3_stmt * statement;
-
-
-
- NSArray* ret=nil;
- // int count=0;
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
- {
-
-
- if (sqlite3_step(statement) == SQLITE_ROW)
- {
-
- char *price_type = (char*)sqlite3_column_text(statement, 0);
- if(price_type==nil)
- price_type="";
- NSString *nsprice_type = [[NSString alloc]initWithUTF8String:price_type];
- if(nsprice_type.length>0)
- ret=[RAUtils string2arr:nsprice_type separator:OFFLINE_ARRAY_SEPARATOR];
- else
- ret=nil;
-
-
- }
-
-
-
-
- sqlite3_finalize(statement);
- }
-
- sqlite3_close(db);
-
- return ret;
-
-
- }
- +(NSString*) model_category_img :(NSString *) product_id model_name:(NSString *) model_name
- {
-
-
- NSString* ret= nil;
-
-
- sqlite3 *db = [iSalesDB get_db];
-
-
- NSString *sqlQuery = nil;
- //select url,type from model_image where product_id=%d and type=1 order by default_img desc , _id asc limit 1;",product_id
-
- if(product_id==nil)
- sqlQuery = [NSString stringWithFormat:@"select i.url from model m LEFT join model_image i on m.product_id = i.product_id where m.name=%@ order by i.default_img desc, i._id asc limit 1;",model_name];
- else
- sqlQuery = [NSString stringWithFormat:@"select i.url from model m LEFT join model_image i on m.product_id = i.product_id where m.product_id=%@ order by i.default_img desc, i._id asc limit 1;",product_id];
-
- sqlite3_stmt * statement;
-
- // int count=0;
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
- {
-
-
- if (sqlite3_step(statement) == SQLITE_ROW)
- {
-
-
- char *imgurl = (char*)sqlite3_column_text(statement, 0);
- if(imgurl==nil)
- imgurl="";
- NSString *nsimgurl = [[NSString alloc]initWithUTF8String:imgurl];
-
-
- ret=nsimgurl;
-
-
- }
-
- sqlite3_finalize(statement);
- }
- else
- {
- [ret setValue:@"8" forKey:@"result"];
- }
-
-
-
- sqlite3_close(db);
- DebugLog(@"data string: %@",ret );
-
-
- return ret;
- }
- +(NSString*) model_default_category :(NSString *) product_id model_name:(NSString *) model_name
- {
-
-
- NSString* ret= nil;
-
-
- sqlite3 *db = [iSalesDB get_db];
-
-
- NSString *sqlQuery = nil;
-
- if(product_id==nil)
- sqlQuery = [NSString stringWithFormat:@"select default_category from model where name='%@';",model_name];
- else
- sqlQuery = [NSString stringWithFormat:@"select default_category from model where product_id=%@;",product_id];
-
- sqlite3_stmt * statement;
-
- // int count=0;
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
- {
-
-
- if (sqlite3_step(statement) == SQLITE_ROW)
- {
-
-
- char *default_category = (char*)sqlite3_column_text(statement, 0);
- if(default_category==nil)
- default_category="";
- NSString *nsdefault_category = [[NSString alloc]initWithUTF8String:default_category];
- nsdefault_category=[nsdefault_category stringByReplacingOccurrencesOfString:@"%#" withString:@""];
- nsdefault_category=[nsdefault_category stringByReplacingOccurrencesOfString:@"#%" withString:@""];
-
- ret=nsdefault_category;
-
-
- }
-
- sqlite3_finalize(statement);
- }
- else
- {
- [ret setValue:@"8" forKey:@"result"];
- }
-
-
-
- sqlite3_close(db);
- DebugLog(@"data string: %@",ret );
-
-
- return ret;
- }
- +(NSDictionary*) offline_model :(NSMutableDictionary *) params
- {
-
-
-
-
-
-
- NSString* model_name = [params valueForKey:@"product_name"];
-
- NSString* product_id = [params valueForKey:@"product_id"];
-
- NSString* category = [params valueForKey:@"category"];
-
-
- if(category==nil)
- category = [self model_default_category:product_id model_name:model_name];
-
- 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,material,box_dim,volume,weight,model_set,load_ability,default_category,fabric_content,assembling,made_in,special_remarks,stockUom,product_group,selector_field,property_field,packaging from model where name='%@';",model_name];
- else
- sqlQuery = [NSString stringWithFormat:@"select name,description,product_id,color,legcolor,availability,incoming_stock,demension,seat_height,material,box_dim,volume,weight,model_set,load_ability,default_category,fabric_content,assembling,made_in,special_remarks,stockUom,product_group,selector_field,property_field,packaging from model where product_id=%@;",product_id];
-
- sqlite3_stmt * statement;
- [ret setValue:@"2" forKey:@"result"];
- [ret setValue:@"3" 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 *material = (char*)sqlite3_column_text(statement, 9);
- if(material==nil)
- material="";
- NSString *nsmaterial = [[NSString alloc]initWithUTF8String:material];
-
- 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 *product_group = (char*)sqlite3_column_text(statement, 21);
- if(product_group==nil)
- product_group="";
- NSString *nsproduct_group = [[NSString alloc]initWithUTF8String:product_group];
-
- // char *fashion_selector = (char*)sqlite3_column_text(statement, 22);
- // if(fashion_selector==nil)
- // fashion_selector="";
- // NSString *nsfashion_selector = [[NSString alloc]initWithUTF8String:fashion_selector];
-
- char *selector_field = (char*)sqlite3_column_text(statement, 22);
- if(selector_field==nil)
- selector_field="";
- NSString *nsselector_field = [[NSString alloc]initWithUTF8String:selector_field];
-
- char *property_field = (char*)sqlite3_column_text(statement, 23);
- if(property_field==nil)
- property_field="";
- NSString *nsproperty_field = [[NSString alloc]initWithUTF8String:property_field];
-
-
-
- char *packaging = (char*)sqlite3_column_text(statement, 24);
- if(packaging==nil)
- packaging="";
- NSString *nspackaging = [[NSString alloc]initWithUTF8String:packaging];
-
- [ret setValue:[NSString stringWithFormat:@"%d",product_id] forKey:@"product_id"];
-
- NSMutableDictionary* img_section = [[NSMutableDictionary alloc] init];
-
- NSString* model_s_img = [self model_category_img:[NSString stringWithFormat:@"%d",product_id] model_name:model_name];
-
- [img_section setValue:model_s_img forKey:@"model_s_img"];
- [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:nsproduct_group field:nsselector_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"];
-
- AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
-
-
- NSString* Price=nil;
- if(appDelegate.bLogin==false)
- Price=@"Must Sign in.";
- else
- {
- NSNumber* price= [self get_model_default_price:appDelegate.contact_id product_id:product_id];
- if(price==nil)
- Price=@"No Price.";
- else
- Price=[NSString stringWithFormat:@"%.2f",price.floatValue];
- }
-
- [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:nsmaterial] 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 setObject:[self model_kvItem:@"Packaging" value:nspackaging] forKey:[NSString stringWithFormat:@"item_%d",detail0_item_count++]];
-
-
- NSDictionary* pricejson=[self get_model_all_price:appDelegate.contact_id product_id:product_id];
- for(int l=0;l<[pricejson[@"count"] intValue];l++)
- {
- NSDictionary* price_item = pricejson[[NSString stringWithFormat:@"item_%d",l]];
- [detail0_section setObject:[self model_kvItem:price_item.allKeys[0] value:price_item.allValues[0]] 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"];
- // [detail1_section setValue:@"New Items You May Also Like" forKey:@"title"];
- // [detail1_section setValue:@"model_NIYMAL" forKey:@"data_interface"];
- // [detail1_section setValue:@"true" forKey:@"single_row"];
- // [detail1_section setValue:@"true" forKey:@"partial_refresh"];
- [ret setObject:detail1_section forKey:@"detail_1"];
-
-
-
-
- NSMutableDictionary* detail2_section = [[NSMutableDictionary alloc]init];
- [detail2_section setValue:@"detail" forKey:@"target"];
- [detail2_section setValue:@"popup" forKey:@"action"];
- [detail2_section setValue:@"content" forKey:@"type"];
- [detail2_section setValue:@"Recently Viewed" forKey:@"title"];
- [detail2_section setValue:@"true" forKey:@"single_row"];
- [detail2_section setValue:@"local" forKey:@"data"];
- [ret setObject:detail2_section forKey:@"detail_2"];
- }
-
-
-
-
- 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
- {
- NSString* orderCode = [params valueForKey:@"orderCode"];
-
- NSString* category = [params valueForKey:@"category"];
-
- int limit = [[params valueForKey:@"limit"] intValue];
- int offset = [[params valueForKey:@"offset"] intValue];
-
- 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.description,m.product_id,w._id,m.closeout from model m left join wishlist w on m.product_id=w.product_id where m.category like'%%#%@#%%' order by m.name limit %d offset %d ;",category,limit, offset];
-
- 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];
-
- 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 *url = (char*)sqlite3_column_text(statement, 3);
- // if(url==nil)
- // url="";
- // NSString *nsurl = [[NSString alloc]initWithUTF8String:url];
-
- int wid = sqlite3_column_int(statement, 3);
- int closeout = sqlite3_column_int(statement, 4);
-
- NSMutableDictionary* imgjson=[self category_img:product_id];
-
- if(wid==0)
- [item setValue:@"false" forKey:@"wish_exists"];
- else
- [item setValue:@"true" forKey:@"wish_exists"];
-
- if(closeout==0)
- [item setValue:@"false" forKey:@"is_closeout"];
- else
- [item setValue:@"true" forKey:@"is_closeout"];
-
- [item addEntriesFromDictionary:imgjson];
-
-
- // [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*) offline_search:(NSMutableDictionary *) params
- {
-
-
-
-
-
-
- NSString* orderCode = [params valueForKey:@"orderCode"];
-
- NSString* keyword = [params valueForKey:@"keyword"];
- keyword=keyword.lowercaseString;
-
- bool exactMatch = [[params valueForKey:@"exactMatch"] boolValue];
-
-
- int limit = [[params valueForKey:@"limit"] intValue];
- int offset = [[params valueForKey:@"offset"] intValue];
-
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
-
-
-
-
-
-
- sqlite3 *db = [iSalesDB get_db];
-
- int count = [iSalesDB get_recordcount:db table:@"model" where:[NSString stringWithFormat:@"lower(name) like'%%%@%%' or lower(description) like'%%%@%%'",keyword,keyword]];
-
-
- NSString *sqlQuery = nil;
- if(exactMatch )
- sqlQuery=[NSString stringWithFormat:@"select m.name,m.description,m.product_id,w._id,m.closeout from model m left join wishlist w on m.product_id=w.product_id where lower(name) like'%@%%' order by m.name limit %d offset %d ;",keyword,limit, offset];
- else
- sqlQuery=[NSString stringWithFormat:@"select m.name,m.description,m.product_id,w._id,m.closeout from model m left join wishlist w on m.product_id=w.product_id where lower(name) like'%%%@%%' or lower(description) like'%%%@%%' order by m.name limit %d offset %d ;",keyword,keyword,limit, offset];
-
- DebugLog(@"offline_search 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];
-
- char *name = (char*)sqlite3_column_text(statement, 0);
- NSString *nsname = [[NSString alloc]initWithUTF8String:name];
-
- char *description = (char*)sqlite3_column_text(statement, 1);
- 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)
- // url="";
- // NSString *nsurl = [[NSString alloc]initWithUTF8String:url];
-
- int wid = sqlite3_column_int(statement, 3);
- int closeout = sqlite3_column_int(statement, 4);
-
- NSMutableDictionary* imgjson=[self category_img:product_id];
-
- if(wid==0)
- [item setValue:@"false" forKey:@"wish_exists"];
- else
- [item setValue:@"true" forKey:@"wish_exists"];
-
- if(closeout==0)
- [item setValue:@"false" forKey:@"is_closeout"];
- else
- [item setValue:@"true" forKey:@"is_closeout"];
-
- [item addEntriesFromDictionary:imgjson];
-
-
- // [item setValue:nsurl forKey:@"img"];
- [item setValue:nsname forKey:@"fash_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*) offline_itemsearch:(NSMutableDictionary *) params
- {
-
-
-
- // [params setValue:covertype forKey:@"covertype"];
- // [params setValue:ctgid forKey:@"ctgId"];
- // [params setValue:modelname forKey:@"modelName"];
- // [params setValue:modeldescrip forKey:@"modelDescription"];
- // [params setValue:alert forKey:@"alert"];
- // [params setValue:qty forKey:@"sold_by_qty"];
- // [params setValue:available forKey:@"available"];
- // [params setValue:price forKey:@"price"];
- // [params setValue:bestseller forKey:@"bestseller"];
-
- NSString* orderCode = [params valueForKey:@"orderCode"];
- int covertype = [[params valueForKey:@"covertype"] intValue];
-
- NSString* where= nil;
- NSString* orderby= @"m.name";
- switch (covertype) {
- case 0:
- {
- where=@"m.category like'%%#005#%%'";
- break;
- }
- case 1:
- {
- where=@"m.alert like '%QS%'";
- break;
- }
- case 2:
- {
- where=@"m.availability>0";
- break;
- }
- case 3:
- {
- where=@"m.best_seller>0";
- orderby=@"m.best_seller desc";
- break;
- }
- default:
- where=@"1=1";
- break;
- }
- // NSString* keyword = [params valueForKey:@"keyword"];
-
- // bool exactMatch = [[params valueForKey:@"exactMatch"] boolValue];
-
-
- int limit = [[params valueForKey:@"limit"] intValue];
- int offset = [[params valueForKey:@"offset"] intValue];
-
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
-
-
-
-
-
-
- sqlite3 *db = [iSalesDB get_db];
-
- int count = [iSalesDB get_recordcount:db table:@"model" where:where];
-
-
- NSString *sqlQuery = nil;
- sqlQuery=[NSString stringWithFormat:@"select m.name,m.description,m.product_id,w._id,m.closeout from model m left join wishlist w on m.product_id=w.product_id where %@ order by %@ limit %d offset %d ;",where,orderby,limit, offset];
-
- DebugLog(@"offline_itemsearch 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];
-
- char *name = (char*)sqlite3_column_text(statement, 0);
- NSString *nsname = [[NSString alloc]initWithUTF8String:name];
-
- char *description = (char*)sqlite3_column_text(statement, 1);
- 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)
- // url="";
- // NSString *nsurl = [[NSString alloc]initWithUTF8String:url];
-
- int wid = sqlite3_column_int(statement, 3);
- int closeout = sqlite3_column_int(statement, 4);
-
- NSMutableDictionary* imgjson=[self category_img:product_id];
-
- if(wid==0)
- [item setValue:@"false" forKey:@"wish_exists"];
- else
- [item setValue:@"true" forKey:@"wish_exists"];
-
- if(closeout==0)
- [item setValue:@"false" forKey:@"is_closeout"];
- else
- [item setValue:@"true" forKey:@"is_closeout"];
-
- [item addEntriesFromDictionary:imgjson];
-
-
- // [item setValue:nsurl forKey:@"img"];
- [item setValue:nsname forKey:@"fash_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*) offline_logout :(NSMutableDictionary *) params
- {
-
-
- //
- // NSString* user = [params valueForKey:@"user"];
- //
- // NSString* password = [params valueForKey:@"password"];
-
-
-
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
-
- ret[@"result"]=[NSNumber numberWithInt:2 ];
-
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
-
- appDelegate.cart_count = 0;//[[jsobj valueForKey:@"cart_count"] intValue];
- appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
- appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
-
- [appDelegate update_count_mark];
-
-
- appDelegate.can_show_price =false;
- appDelegate.can_see_price =false;
- appDelegate.can_create_portfolio =false;
- appDelegate.can_create_order =false;
-
-
- appDelegate.can_cancel_order =false;
- appDelegate.can_set_cart_price =false;
- appDelegate.can_delete_order =false;
- appDelegate.can_submit_order =false;
- appDelegate.can_set_tearsheet_price =false;
- appDelegate.can_update_contact_info = false;
-
- appDelegate.save_order_logout = false;
- appDelegate.submit_order_logout = false;
- appDelegate.alert_sold_in_quantities = false;
-
- appDelegate.ipad_perm =nil ;
- appDelegate.user_type = USER_ROLE_UNKNOWN;
- appDelegate.OrderFilter= nil;
- [appDelegate SetSo:nil];
- [appDelegate set_main_button_panel];
-
-
- // 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_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_contactinfo :(NSMutableDictionary *) params
- {
- NSString* contactId = [params valueForKey:@"contactId"];
-
-
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
-
-
-
-
-
-
- sqlite3 *db = [iSalesDB get_db];
-
-
-
-
-
- NSString *sqlQuery = nil;
-
-
- {
- sqlQuery=[NSString stringWithFormat:@"select editable,company_name,country,addr,zipcode,state,city,contact_name,phone,contact_id,addr_1,addr_2,addr_3,addr_4,first_name,last_name,fax,email,img_0,img_1,img_2,price_type,notes,sales_rep from offline_contact where contact_id='%@'",contactId];
-
- }
-
-
- DebugLog(@"offline_contactlist sql:%@",sqlQuery);
- sqlite3_stmt * statement;
-
-
- [ret setValue:@"2" forKey:@"result"];
-
-
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
- {
-
- //int i = 0;
- if (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 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 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];
-
- char *addr_1 = (char*)sqlite3_column_text(statement, 10);
- if(addr_1==nil)
- addr_1="";
- NSString *nsaddr_1= [[NSString alloc]initWithUTF8String:addr_1];
-
- char *addr_2 = (char*)sqlite3_column_text(statement, 11);
- if(addr_2==nil)
- addr_2="";
- NSString *nsaddr_2= [[NSString alloc]initWithUTF8String:addr_2];
-
-
- char *addr_3 = (char*)sqlite3_column_text(statement, 12);
- if(addr_3==nil)
- addr_3="";
- NSString *nsaddr_3= [[NSString alloc]initWithUTF8String:addr_3];
-
-
- char *addr_4 = (char*)sqlite3_column_text(statement, 13);
- if(addr_4==nil)
- addr_4="";
- NSString *nsaddr_4= [[NSString alloc]initWithUTF8String:addr_4];
-
-
- char *first_name = (char*)sqlite3_column_text(statement, 14);
- if(first_name==nil)
- first_name="";
- NSString *nsfirst_name= [[NSString alloc]initWithUTF8String:first_name];
-
-
- char *last_name = (char*)sqlite3_column_text(statement, 15);
- if(last_name==nil)
- last_name="";
- NSString *nslast_name= [[NSString alloc]initWithUTF8String:last_name];
-
- char *fax = (char*)sqlite3_column_text(statement, 16);
- NSString *nsfax = nil;
- if(fax==nil)
- nsfax=@"";
- else
- nsfax= [[NSString alloc]initWithUTF8String:fax];
-
- char *email = (char*)sqlite3_column_text(statement, 17);
- NSString *nsemail = nil;
- if(email==nil)
- nsemail=@"";
- else
- nsemail= [[NSString alloc]initWithUTF8String:email];
-
- char *img_0 = (char*)sqlite3_column_text(statement, 18);
- NSString *nsimg_0 = nil;
- if(img_0==nil)
- nsimg_0=@"";
- else
- nsimg_0= [[NSString alloc]initWithUTF8String:img_0];
-
- char *img_1 = (char*)sqlite3_column_text(statement, 19);
- NSString *nsimg_1 = nil;
- if(img_1==nil)
- nsimg_1=@"";
- else
- nsimg_1= [[NSString alloc]initWithUTF8String:img_1];
-
- char *img_2 = (char*)sqlite3_column_text(statement, 20);
- NSString *nsimg_2 = nil;
- if(img_2==nil)
- nsimg_2=@"";
- else
- nsimg_2= [[NSString alloc]initWithUTF8String:img_2];
-
- char *price_type = (char*)sqlite3_column_text(statement, 21);
- NSString *nsprice_type = nil;
- if(price_type==nil)
- nsprice_type=@"";
- else
- nsprice_type= [[NSString alloc]initWithUTF8String:price_type];
-
-
- char *notes = (char*)sqlite3_column_text(statement, 22);
- NSString *nsnotes = nil;
- if(notes==nil)
- nsnotes=@"";
- else
- nsnotes= [[NSString alloc]initWithUTF8String:notes];
-
-
- char *salesrep = (char*)sqlite3_column_text(statement, 23);
- NSString *nssalesrep = nil;
- if(salesrep==nil)
- nssalesrep=@"";
- else
- nssalesrep= [[NSString alloc]initWithUTF8String:salesrep];
-
-
- {
- // decrypt
-
- nscompany_name=[AESCrypt fastdecrypt:nscompany_name];
-
- // nscompany_name=[NSString stringWithFormat:@"<b>%@</b>",nscompany_name];
-
- nsphone=[AESCrypt fastdecrypt:nsphone];
- // nsphone=[NSString stringWithFormat:@"TEL:%@",nsphone];
-
- nsaddr_1=[AESCrypt fastdecrypt:nsaddr_1];
- // nsaddr_1=[NSString stringWithFormat:@"TEL:%@",nsphone];
-
- }
-
- NSMutableArray* arr_name= [[NSMutableArray alloc] init];
-
- [arr_name addObject:nsfirst_name];
- [arr_name addObject:nslast_name];
-
- NSString *nscontact_name=[RAUtils arr2string:arr_name separator:@" " trim:true];
-
-
- NSMutableArray* arr_ext= [[NSMutableArray alloc] init];
-
- [arr_ext addObject:nsaddr_1];
- [arr_ext addObject:nsaddr_2];
- [arr_ext addObject:nsaddr_3];
- [arr_ext addObject:nsaddr_4];
- [arr_ext addObject:@"\r\n"];
-
- [arr_ext addObject:nscity];
- [arr_ext addObject:nsstate];
- [arr_ext addObject:nszipcode];
- [arr_ext addObject:nscountry];
-
- NSString *nsext=[RAUtils arr2string:arr_ext separator:@", " trim:true];
-
-
- nsext=[nsext stringByReplacingOccurrencesOfString:@", \r\n," withString:@"\r\n"];
-
-
- [item setValue:nsimg_2 forKey:@"business_card_2"];
- [item setValue:nsimg_0 forKey:@"business_card_0"];
- [item setValue:nscountry forKey:@"customer_country"];
- [item setValue:nsphone forKey:@"customer_phone"];
- [item setValue:nsimg_1 forKey:@"business_card_1"];
- [item setValue:nscompany_name forKey:@"customer_name"];
- [item setValue:nsprice_type forKey:@"customer_price_type"];
- [item setValue:nsfirst_name forKey:@"customer_first_name"];
- [item setValue:nsext forKey:@"customer_contact_ext"];
- [item setValue:nszipcode forKey:@"customer_zipcode"];
- [item setValue:nsaddr_1 forKey:@"customer_address1"];
- [item setValue:nsaddr_2 forKey:@"customer_address2"];
- [item setValue:nsaddr_3 forKey:@"customer_address3"];
- [item setValue:nsaddr_4 forKey:@"customer_address4"];
- [item setValue:nsnotes forKey:@"customer_contact_notes"];
- [item setValue:nslast_name forKey:@"customer_last_name"];
- [item setValue:nscity forKey:@"customer_city"];
- [item setValue:nsstate forKey:@"customer_state"];
- [item setValue:nssalesrep forKey:@"customer_sales_rep"];
- [item setValue:contactId forKey:@"customer_cid"];
- [item setValue:nscontact_name forKey:@"customer_contact"];
- [item setValue:nsfax forKey:@"customer_fax"];
- [item setValue:nsemail forKey:@"customer_email"];
-
-
-
- [ret setObject:item forKey:@"customerInfo"];
- // i++;
-
-
-
- }
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- [ret setValue:appDelegate.mode forKey:@"mode"];
- [ret setValue:[NSNumber numberWithInt:1 ] forKey:@"count"];
-
-
-
- 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 result= [iSalesDB AddExFunction: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,addr_1,addr_2,addr_3,addr_4,first_name,last_name,fax,email from offline_contact where %@=1 order by create_time limit %d offset %d",contactType , limit, offset];
- count=[iSalesDB get_recordcount:db table:@"offline_contact" where:[NSString stringWithFormat:@"%@='1",contactType]];
- }
- else
- {
- // NSString* encrypt_keyword= [AESCrypt fastencrypt:keyword];
-
- keyword = keyword.lowercaseString;
-
-
- sqlQuery=[NSString stringWithFormat:@"select editable,company_name,country,addr,zipcode,state,city,contact_name,phone,contact_id,addr_1,addr_2,addr_3,addr_4,first_name,last_name,fax,email from offline_contact where %@=1 and (lower(contact_id ) like'%%%@%%' or lower(decrypt(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:@"%@=1 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 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 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];
-
- char *addr_1 = (char*)sqlite3_column_text(statement, 10);
- if(addr_1==nil)
- addr_1="";
- NSString *nsaddr_1= [[NSString alloc]initWithUTF8String:addr_1];
-
- char *addr_2 = (char*)sqlite3_column_text(statement, 11);
- if(addr_2==nil)
- addr_2="";
- NSString *nsaddr_2= [[NSString alloc]initWithUTF8String:addr_2];
-
-
- char *addr_3 = (char*)sqlite3_column_text(statement, 12);
- if(addr_3==nil)
- addr_3="";
- NSString *nsaddr_3= [[NSString alloc]initWithUTF8String:addr_3];
-
-
- char *addr_4 = (char*)sqlite3_column_text(statement, 13);
- if(addr_4==nil)
- addr_4="";
- NSString *nsaddr_4= [[NSString alloc]initWithUTF8String:addr_4];
-
-
- char *first_name = (char*)sqlite3_column_text(statement, 14);
- if(first_name==nil)
- first_name="";
- NSString *nsfirst_name= [[NSString alloc]initWithUTF8String:first_name];
-
-
- char *last_name = (char*)sqlite3_column_text(statement, 15);
- if(last_name==nil)
- last_name="";
- NSString *nslast_name= [[NSString alloc]initWithUTF8String:last_name];
-
- char *fax = (char*)sqlite3_column_text(statement, 16);
- NSString *nsfax = nil;
- if(fax==nil)
- nsfax=@"";
- else
- nsfax= [NSString stringWithFormat:@"FAX:%@",[[NSString alloc]initWithUTF8String:fax]];
-
- char *email = (char*)sqlite3_column_text(statement, 17);
- NSString *nsemail = nil;
- if(email==nil)
- nsemail=@"";
- else
- nsemail= [NSString stringWithFormat:@"EMAIL:%@",[[NSString alloc]initWithUTF8String:email]];
-
-
-
- NSMutableArray* arr_name= [[NSMutableArray alloc] init];
-
- [arr_name addObject:nsfirst_name];
- [arr_name addObject:nslast_name];
-
- NSString *nscontact_name=[RAUtils arr2string:arr_name separator:@" " trim:true];
-
- NSMutableArray* arr_addr = [[NSMutableArray alloc] init];
-
- {
- // decrypt
-
- nscompany_name=[AESCrypt fastdecrypt:nscompany_name];
-
- nscompany_name=[NSString stringWithFormat:@"<b>%@</b>",nscompany_name];
-
- nsphone=[AESCrypt fastdecrypt:nsphone];
- nsphone=[NSString stringWithFormat:@"TEL:%@",nsphone];
-
- nsaddr_1=[AESCrypt fastdecrypt:nsaddr_1];
- // nsaddr_1=[NSString stringWithFormat:@"TEL:%@",nsphone];
-
- }
-
-
- [arr_addr addObject:nscompany_name];
- [arr_addr addObject:nscontact_name];
- [arr_addr addObject:@"<br>"];
-
- [arr_addr addObject:nsaddr_1];
- [arr_addr addObject:nsaddr_2];
- [arr_addr addObject:nsaddr_3];
- [arr_addr addObject:nsaddr_4];
- //[arr_addr addObject:nsaddr];
- [arr_addr addObject:nszipcode];
- [arr_addr addObject:nscity];
- [arr_addr addObject:nsstate];
- [arr_addr addObject:nscountry];
- [arr_addr addObject:@"<br>"];
- [arr_addr addObject:nsphone];
- [arr_addr addObject:nsfax];
- [arr_addr addObject:nsemail];
-
- NSString * name = [RAUtils arr2string:arr_addr separator:@", " trim:true];
-
- name=[name stringByReplacingOccurrencesOfString:@", <br>," withString:@"<br>"];
-
-
- [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;
- }
- +(NSDictionary*) model_NIYMAL:(NSString*) category
- {
- // MODEL DETAIL NEW ITEM YOU MAY ALSO LIKE
-
-
- category = [category substringToIndex:3];
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
-
- NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
-
- params[@"category"]= category;
-
- ret[@"params"]= params;
- [ret setValue:@"detail" forKey:@"target"];
- [ret setValue:@"popup" forKey:@"action"];
- [ret setValue:@"content" forKey:@"type"];
- [ret setValue:@"New Items You May Also Like" forKey:@"title"];
- [ret setValue:@"model_NIYMAL" forKey:@"data_interface"];
- [ret setValue:@"true" forKey:@"single_row"];
- [ret setValue:@"true" forKey:@"partial_refresh"];
-
- 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,random() as aa from model m LEFT join model_image i on m.product_id = i.product_id where m.category like'%%#%@#%%' and m.category like'%%#005#%%' and i.default_img = %d order by aa limit 10 ;",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];
-
-
-
-
- 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);
-
-
- 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*)product_group 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 product_group='%@' order by name;",field,product_group];
- 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 model_category_img:[NSNumber numberWithInt:product_id].stringValue model_name:nil];//[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;
- }
- +(NSMutableDictionary*) category_img :(int)product_id
- {
- // model 在 category search 显示的图片。
- NSMutableDictionary* ret =[[NSMutableDictionary alloc]init];
-
-
-
- sqlite3 *db = [iSalesDB get_db];
-
-
- NSString *sqlQuery = [NSString stringWithFormat:@"select url,type from model_image where product_id=%d and type<2 order by default_img desc , _id asc limit 2;",product_id];
- sqlite3_stmt * statement;
-
-
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
- {
-
-
- while (sqlite3_step(statement) == SQLITE_ROW)
- {
- char *url = (char*)sqlite3_column_text(statement, 0);
- if(url==nil)
- url="";
- int type = sqlite3_column_int(statement, 1);
- if(type==0)
- [ret setValue:[[NSString alloc]initWithUTF8String:url] forKey:@"img"];
- else
- [ret setValue:[[NSString alloc]initWithUTF8String:url] forKey:@"img_big"];
-
- }
-
-
-
- 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=1;",product_id];
- 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;
- }
- @end
|