MainViewController.m 88 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442
  1. //
  2. // ViewController.m
  3. // RedAnt ERP Suite
  4. //
  5. // Created by Ray on 14-5-19.
  6. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "MainViewController.h"
  9. //#import "SideMenuViewController.h"
  10. //#import "RootContainerViewController.h"
  11. #import <Accelerate/Accelerate.h>
  12. #import "PopupNavigationController.h"
  13. //#import "CommonGridViewController.h"
  14. #import "CacheViewController.h"
  15. #import "ScannerViewController.h"
  16. #import "ContactListViewController.h"
  17. #import "RAUtils.h"
  18. #import "AboutViewController.h"
  19. #import "ScannerSettingViewController.h"
  20. #import "ActiveViewController.h"
  21. #import "WebViewController.h"
  22. #import "FunctionTestViewController.h"
  23. #import "SimplifiedBuyingProgramViewController.h"
  24. #import "UserListViewController.h"
  25. #import "OfflineSettingViewController.h"
  26. #import "DefaultAppearance.h"
  27. #import "PriceSettingViewController.h"
  28. #import "JKLockController.h"
  29. @interface MainViewController ()
  30. @end
  31. @implementation MainViewController
  32. -(void) logoutDocuments
  33. {
  34. [self.pdfListViewController logout];
  35. }
  36. -(void) logoutCart
  37. {
  38. [self.cartViewController logout];
  39. }
  40. -(void) logoutWish
  41. {
  42. [self.watchListViewController logout];
  43. }
  44. -(void) logoutPortfolio
  45. {
  46. [self.portfolioViewController logout];
  47. }
  48. -(void) logoutOrder
  49. {
  50. [self.orderViewController logout];
  51. }
  52. -(void) logoutContact
  53. {
  54. [self.contactListViewController logout];
  55. }
  56. -(void) logoutCategory
  57. {
  58. [self.categoryViewController logout];
  59. }
  60. -(void) reloadCategory:(BOOL) update_data immediately:(bool)immediately
  61. {
  62. if(immediately)
  63. [ self.categoryViewController reload_container_getdata:update_data];
  64. else
  65. {
  66. if(update_data&&self.categoryViewController.refresh_type<=REFRESH_DATA)
  67. self.categoryViewController.refresh_type = REFRESH_DATA;
  68. else if(self.categoryViewController.refresh_type<=REFRESH_VIEW)
  69. self.categoryViewController.refresh_type = REFRESH_VIEW;
  70. }
  71. }
  72. -(void) reloadDocuments:(BOOL) update_data immediately:(bool)immediately
  73. {
  74. if(immediately)
  75. [ self.pdfListViewController reload_container_getdata:update_data];
  76. else
  77. {
  78. if(update_data&&self.pdfListViewController.refresh_type<=REFRESH_DATA)
  79. self.pdfListViewController.refresh_type = REFRESH_DATA;
  80. else if(self.pdfListViewController.refresh_type<=REFRESH_VIEW)
  81. self.pdfListViewController.refresh_type = REFRESH_VIEW;
  82. }
  83. //[self.pdfListViewController reload_container_getdata:update_data];
  84. }
  85. -(void) reloadCart:(BOOL) update_data immediately:(bool)immediately
  86. {
  87. if(immediately)
  88. [ self.cartViewController reload_container_getdata:update_data];
  89. else
  90. {
  91. if(update_data&&self.cartViewController.refresh_type<=REFRESH_DATA)
  92. self.cartViewController.refresh_type = REFRESH_DATA;
  93. else if(self.cartViewController.refresh_type<=REFRESH_VIEW)
  94. self.cartViewController.refresh_type = REFRESH_VIEW;
  95. }
  96. // [self.cartViewController reload_container_getdata:update_data];
  97. }
  98. -(void) reloadWish:(BOOL) update_data immediately:(bool)immediately
  99. {
  100. if(immediately)
  101. [ self.watchListViewController reload_container_getdata:update_data];
  102. else
  103. {
  104. if(update_data&&self.watchListViewController.refresh_type<=REFRESH_DATA)
  105. self.watchListViewController.refresh_type = REFRESH_DATA;
  106. else if(self.watchListViewController.refresh_type<=REFRESH_VIEW)
  107. self.watchListViewController.refresh_type = REFRESH_VIEW;
  108. }
  109. // [self.watchListViewController reload_container_getdata:update_data];
  110. }
  111. -(void) reloadPortfolio:(BOOL) update_data immediately:(bool)immediately
  112. {
  113. if(immediately)
  114. [ self.portfolioViewController reload_container_getdata:update_data];
  115. else
  116. {
  117. if(update_data&&self.portfolioViewController.refresh_type<=REFRESH_DATA)
  118. self.portfolioViewController.refresh_type = REFRESH_DATA;
  119. else if(self.portfolioViewController.refresh_type<=REFRESH_VIEW)
  120. self.portfolioViewController.refresh_type = REFRESH_VIEW;
  121. }
  122. // [self.portfolioViewController reload_container_getdata:update_data];
  123. }
  124. -(void) reloadOrder:(BOOL) update_data immediately:(bool)immediately
  125. {
  126. if(immediately)
  127. [ self.orderViewController reload_container_getdata:update_data];
  128. else
  129. {
  130. if(update_data&&self.orderViewController.refresh_type<=REFRESH_DATA)
  131. self.orderViewController.refresh_type = REFRESH_DATA;
  132. else if(self.orderViewController.refresh_type<=REFRESH_VIEW)
  133. self.orderViewController.refresh_type = REFRESH_VIEW;
  134. }
  135. // [self.orderViewController reload_container_getdata:update_data];
  136. }
  137. -(void) reloadContact:(BOOL) update_data immediately:(bool)immediately
  138. {
  139. //[self.con reload_container];
  140. if(immediately)
  141. [ self.contactListViewController reload_container_getdata:update_data];
  142. else
  143. {
  144. if(update_data&&self.contactListViewController.refresh_type<=REFRESH_DATA)
  145. self.contactListViewController.refresh_type = REFRESH_DATA;
  146. else if(self.contactListViewController.refresh_type<=REFRESH_VIEW)
  147. self.contactListViewController.refresh_type = REFRESH_VIEW;
  148. }
  149. }
  150. -(void)viewWillLayoutSubviews
  151. {
  152. self.headerView.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.headerView.bounds].CGPath;
  153. }
  154. -(void) viewWillAppear:(BOOL)animated
  155. {
  156. // [self.label_ccount.layer setMasksToBounds:YES];
  157. UIApplication * app = [UIApplication sharedApplication];
  158. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  159. // self.labelContact.text=appDelegate.contact_name;
  160. NSString * contact =[appDelegate.customerInfo valueForKey:@"customer_contact"];
  161. NSString * customer=[appDelegate.customerInfo valueForKey:@"customer_name"];
  162. NSDictionary * customerinfo=appDelegate.customerInfo;
  163. if(customerinfo==nil)
  164. {
  165. contact=@"Select Contact";
  166. [self.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  167. }
  168. // if(contact==nil||contact.length==0)
  169. // {
  170. // contact=@"No Name";
  171. // [self.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  172. // }
  173. else
  174. {
  175. if(contact==nil||contact.length==0)
  176. {
  177. contact=@"No Name";
  178. [self.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  179. }
  180. else
  181. {
  182. [self.btnContact setTitleColor:UIColorFromRGB(0x009900) forState:UIControlStateNormal];
  183. }
  184. }
  185. NSMutableArray* arr_contact = [[NSMutableArray alloc] init];
  186. if(contact.length>0)
  187. [arr_contact addObject:contact];
  188. if(customer.length>0)
  189. [arr_contact addObject:customer];
  190. NSString *contact_string = [arr_contact componentsJoinedByString:@" @"];
  191. [self.btnContact setTitle:contact_string forState:UIControlStateNormal];
  192. [[self navigationController] setNavigationBarHidden:YES animated:NO];
  193. }
  194. - (void) checklogin:(bool) reloadCurrentVC
  195. {
  196. [self initMenuItems];
  197. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  198. self.sideMenu_UserName.text =appDelegate.user;
  199. [self.btn_sideMenu_UserName setTitle:appDelegate.user forState:UIControlStateNormal];
  200. if(appDelegate.bLogin)
  201. [self.btnLogin setTitle:@"Sign out" forState:UIControlStateNormal];
  202. else
  203. [self.btnLogin setTitle:@"Sign in" forState:UIControlStateNormal];
  204. [iSalesNetwork LoadImage:appDelegate.user_icon into:self.user_head ];
  205. if(/*appDelegate.user_type==USER_ROLE_EMPLOYEE*/true)
  206. self.btnContact.hidden = NO;
  207. else
  208. self.btnContact.hidden = YES;
  209. NSDictionary * customerinfo=appDelegate.customerInfo;
  210. NSString * contact=nil;
  211. NSString * customer=nil;
  212. if(customerinfo==nil)
  213. {
  214. contact=@"Select Contact";
  215. [self.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  216. }
  217. else
  218. {
  219. contact=[customerinfo valueForKey:@"customer_contact"];
  220. customer=[customerinfo valueForKey:@"customer_name"];
  221. if(contact==nil||contact.length==0)
  222. {
  223. contact=@"No Name";
  224. [self.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  225. }
  226. else
  227. {
  228. [self.btnContact setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
  229. }
  230. }
  231. NSMutableArray* arr_contact = [[NSMutableArray alloc] init];
  232. if(contact.length>0)
  233. [arr_contact addObject:contact];
  234. if(customer.length>0)
  235. [arr_contact addObject:customer];
  236. NSString *contact_string = [arr_contact componentsJoinedByString:@" @"];
  237. [self.btnContact setTitle:contact_string forState:UIControlStateNormal];
  238. // if(appDelegate.bLogin)
  239. // [self.buttonUser setTitle:appDelegate.user forState:UIControlStateNormal];
  240. // else
  241. // [self.buttonUser setTitle:@"Sign in" forState:UIControlStateNormal];
  242. [self reloadDocuments:true immediately:false];
  243. [self reloadCart:true immediately:false];
  244. [self reloadWish:true immediately:false];
  245. [self reloadPortfolio:true immediately:false];
  246. [self reloadOrder:true immediately:false];
  247. [self reloadContact:true immediately:false];
  248. [self reloadCategory:true immediately:false];
  249. ActiveViewController* lrvc = (ActiveViewController*)appDelegate.active_controller;
  250. if(reloadCurrentVC)
  251. {
  252. if(lrvc!=nil)
  253. [ lrvc refresh_on_login];
  254. }
  255. else
  256. {
  257. if(lrvc.refresh_type<=REFRESH_DATA)
  258. lrvc.refresh_type = REFRESH_DATA;
  259. else if(lrvc.refresh_type<=REFRESH_VIEW)
  260. lrvc.refresh_type = REFRESH_VIEW;
  261. }
  262. // [self reload];
  263. }
  264. - (IBAction)onContactClick:(id)sender {
  265. UIApplication * app = [UIApplication sharedApplication];
  266. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  267. NSString* contactid=appDelegate.contact_id ;
  268. if(contactid==nil)
  269. {
  270. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  271. cvc.update_order = true;
  272. cvc.edit_icon = true;
  273. cvc.assig_icon = true;
  274. cvc.reset_icon = false;
  275. cvc.showNavibar = true;
  276. cvc.contact_type = @"Sales_Order_Customer";
  277. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  278. [self.navigationController popViewControllerAnimated:false];
  279. appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  280. appDelegate.customerInfo = value;
  281. // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  282. //
  283. // if(self.returnValue)
  284. // self.returnValue(value);
  285. };
  286. [self.navigationController pushViewController:cvc animated:true];
  287. }
  288. else
  289. {
  290. CustomerInfoViewController * vc =[ self.storyboard instantiateViewControllerWithIdentifier:@"CustomerInfoViewController"];
  291. vc.url_type = URL_LOCAL;
  292. // if(appDelegate.order_code.length>0)
  293. {
  294. vc.edit_icon = false;
  295. vc.assig_icon = true;
  296. vc.reset_icon = true;
  297. vc.request_url=LOCAL_URL_CUSTOMER_INFO_EDIT;
  298. }
  299. // else
  300. // {
  301. // vc.edit_icon = false;
  302. // vc.assig_icon = false;
  303. // vc.reset_icon = true;
  304. // vc.request_url=LOCAL_URL_CUSTOMER_INFO_EDITOR;
  305. // }
  306. // NSDictionary* dd=appDelegate.customerInfo;;
  307. vc.data_init = appDelegate.customerInfo;
  308. vc.update_order = true;
  309. vc.contactId=contactid;
  310. // vc.delegate = self;
  311. vc.returnValue = ^(NSMutableDictionary* value){
  312. appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  313. appDelegate.customerInfo = value;
  314. };
  315. [self.navigationController pushViewController:vc animated:true];
  316. }
  317. }
  318. - (void)viewDidLoad
  319. {
  320. [super viewDidLoad];
  321. self.automaticallyAdjustsScrollViewInsets = NO;
  322. NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultColor" valuename:@"labelcolor"];
  323. if(value==nil)
  324. value=@"";
  325. unsigned long frontcolor = strtoul([value UTF8String],0,16);
  326. [self.labelSo setTextColor:UIColorFromRGB(frontcolor)];
  327. float vx =[[DefaultAppearance get_noneappearance_value:@"MainLogo" valuename:@"x"] floatValue];
  328. float vy =[[DefaultAppearance get_noneappearance_value:@"MainLogo" valuename:@"y"] floatValue];
  329. float vwidth =[[DefaultAppearance get_noneappearance_value:@"MainLogo" valuename:@"width"] floatValue];
  330. float vheight =[[DefaultAppearance get_noneappearance_value:@"MainLogo" valuename:@"height"] floatValue];
  331. self.btn_LogoHome.frame = CGRectMake(vx, vy, vwidth, vheight);
  332. float mvx =[[DefaultAppearance get_noneappearance_value:@"ModePos" valuename:@"x"] floatValue];
  333. float mvy =[[DefaultAppearance get_noneappearance_value:@"ModePos" valuename:@"y"] floatValue];
  334. float mvwidth =[[DefaultAppearance get_noneappearance_value:@"ModePos" valuename:@"width"] floatValue];
  335. float mvheight =[[DefaultAppearance get_noneappearance_value:@"ModePos" valuename:@"height"] floatValue];
  336. self.labelMode.frame = CGRectMake(mvx, mvy, mvwidth, mvheight);
  337. self.label_ccount.layer.cornerRadius=10.5;
  338. self.label_ccount.layer.masksToBounds=true;
  339. self.label_wcount.layer.cornerRadius=10.5;
  340. self.label_wcount.layer.masksToBounds=true;
  341. self.label_cccount.layer.cornerRadius=10.5;
  342. self.label_cccount.layer.masksToBounds=true;
  343. self.label_cwcount.layer.cornerRadius=10.5;
  344. self.label_cwcount.layer.masksToBounds=true;
  345. self.employee_bp.hidden = false;
  346. self.customer_bp.hidden = true;
  347. UIApplication * app = [UIApplication sharedApplication];
  348. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  349. appDelegate.main_vc = self;
  350. [appDelegate update_count_mark];
  351. NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  352. NSString* build =[infoDict objectForKey:@"CFBundleVersion"];
  353. NSString* version =[infoDict objectForKey:@"CFBundleShortVersionString"];
  354. #ifdef BUILD_HMLG
  355. NSString* versionNum = [NSString stringWithFormat:@"HMLG %@ Build %@",version,build];
  356. #else
  357. NSString* versionNum = [NSString stringWithFormat:@"npd %@ Build %@",version,build];
  358. #endif
  359. [self initMenuItems];
  360. self.homeViewController =[ self.storyboard instantiateViewControllerWithIdentifier:@"HomeViewController"];
  361. self.categoryViewController =[ self.storyboard instantiateViewControllerWithIdentifier:@"CategoryViewController"];
  362. self.cartViewController =[ self.storyboard instantiateViewControllerWithIdentifier:@"CartViewController"];
  363. self.orderViewController =[ self.storyboard instantiateViewControllerWithIdentifier:@"OrderListViewController"];
  364. self.contactListViewController =[ self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController"];
  365. self.contactListViewController.contact_type = @"Sales_Order_Customer";
  366. self.contactListViewController.edit_icon = true;
  367. self.contactListViewController.assig_icon = true;
  368. self.contactListViewController.reset_icon = false;
  369. self.contactListViewController.ui_type = CONTACT_LIST;
  370. __block MainViewController *brself= self;
  371. self.contactListViewController.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  372. appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  373. appDelegate.customerInfo = value;
  374. [brself switchToCart:nil];
  375. // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  376. //
  377. // if(self.returnValue)
  378. // self.returnValue(value);
  379. };
  380. //Capturing strongly warring;
  381. self.orderViewController.selectOrder=^(NSMutableDictionary* order_detail){
  382. //main view 下打开order
  383. //Capturing strongly warring;
  384. __block MainViewController *brbrself= brself;
  385. brself.cartViewController.onFinishLoad=^()
  386. {
  387. [brbrself.cartViewController placeOrder];
  388. brbrself.cartViewController.onFinishLoad=nil;
  389. };
  390. [brself switchToCart:nil];
  391. };
  392. self.watchListViewController =[ self.storyboard instantiateViewControllerWithIdentifier:@"WatchListViewController"];
  393. self.portfolioViewController =[ self.storyboard instantiateViewControllerWithIdentifier:@"PortfolioViewController"];
  394. self.pdfListViewController =[ self.storyboard instantiateViewControllerWithIdentifier:@"PDFListViewController"];
  395. self.itemSearchViewController=[ self.storyboard instantiateViewControllerWithIdentifier:@"ItemSearchViewController"];
  396. self.searchViewController=[ self.storyboard instantiateViewControllerWithIdentifier:@"SearchViewController"];
  397. [self addChildViewController:self.homeViewController]; //1
  398. self.homeViewController.view.frame = self.container.bounds;
  399. [self.container addSubview:self.homeViewController.view]; //2
  400. [self.homeViewController didMoveToParentViewController:self];
  401. self.current_VC = self.homeViewController;
  402. // self.is_home = true;
  403. // [UIBezierPath bezierPathWithRect:self.headerView.bounds].CGPath;
  404. self.headerView.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.headerView.bounds].CGPath;
  405. self.headerView.layer.masksToBounds = false;
  406. //添加四个边阴影
  407. self.headerView.layer.shadowColor = [UIColor blackColor].CGColor;
  408. self.headerView.layer.shadowOffset = CGSizeMake(0, 0);
  409. self.headerView.layer.shadowOpacity = 0.5;
  410. self.headerView.layer.shadowRadius = 2.0;
  411. self.labelVer.text=versionNum;
  412. // UIApplication * app = [UIApplication sharedApplication];
  413. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  414. if(appDelegate.categoryMenu==nil)
  415. {
  416. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  417. NSDictionary* category=[iSalesNetwork request_Cagegory];
  418. dispatch_async(dispatch_get_main_queue(), ^{
  419. if([[category valueForKey:@"result"] intValue]==2)
  420. {
  421. appDelegate.categoryMenu = category;
  422. }
  423. else
  424. {
  425. // [RAUtils error_alert:[category valueForKey:@"err_msg"] title:@"Failed to load category."] ;
  426. }
  427. // self.categoryViewController.categoryMenu = category;
  428. });
  429. });
  430. }
  431. // Do any additional setup after loading the view, typically from a nib.
  432. }
  433. - (IBAction)onmenuButtonClicked:(id)sender {
  434. self.openMenuButton.hidden = true;
  435. self.sideMenu.hidden = false;
  436. [self showMenu];
  437. }
  438. - (IBAction)switchMenu:(UIButton *)sender {
  439. // if(self.menuShown==true)
  440. [self hideMenu];
  441. self.openMenuButton.hidden = false;
  442. self.sideMenu.hidden = true;
  443. // else
  444. // [self showMenu];
  445. }
  446. -(void) Loginout:(bool)showlogin
  447. {
  448. UIApplication * app = [UIApplication sharedApplication];
  449. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  450. if(appDelegate.bLogin)
  451. {
  452. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Sign out"];
  453. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  454. NSDictionary* return_json = [iSalesNetwork logout];
  455. dispatch_async(dispatch_get_main_queue(), ^{
  456. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  457. if([[return_json valueForKey:@"result"] intValue]==2)
  458. {
  459. // [self hideMenu];
  460. // [self switchToHome:nil];
  461. [appDelegate Logout];
  462. if(showlogin)
  463. {
  464. LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  465. loginvc.returnValue = ^(bool blogin){
  466. [self checklogin :true];
  467. };
  468. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  469. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  470. [self presentViewController:navi animated:YES completion:^{
  471. NSLog(@"login present.........");
  472. }];
  473. }
  474. }
  475. else
  476. {
  477. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Sign Out" controller:self] ;
  478. }
  479. });
  480. });
  481. }
  482. else
  483. {
  484. LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  485. loginvc.returnValue = ^(bool blogin){
  486. [self checklogin :true];
  487. };
  488. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  489. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  490. [self presentViewController:navi animated:YES completion:^{
  491. NSLog(@"login present.........");
  492. }];
  493. }
  494. }
  495. - (IBAction)onUserListClick:(id)sender {
  496. UIApplication * app = [UIApplication sharedApplication];
  497. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  498. if(!appDelegate.bLogin)
  499. return;
  500. UserListViewController * vc =[ self.storyboard instantiateViewControllerWithIdentifier:@"UserListViewController"];
  501. vc.returnValue = ^(bool blogin){
  502. if(blogin==false)
  503. {
  504. LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  505. loginvc.returnValue = ^(bool blogin){
  506. [self checklogin :true];
  507. };
  508. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  509. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  510. [self presentViewController:navi animated:YES completion:^{
  511. NSLog(@"login present.........");
  512. }];
  513. }
  514. };
  515. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  516. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  517. [self presentViewController:navi animated:YES completion:^{
  518. NSLog(@"login present.........");
  519. }];
  520. }
  521. - (IBAction)OnLoginClick:(UIButton *)sender {
  522. [self Loginout:true];
  523. }
  524. - (IBAction)onScanClick:(id)sender {
  525. ScannerViewController * scannerVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"ScannerViewController"];
  526. [self.navigationController pushViewController:scannerVC animated:true];
  527. }
  528. - (IBAction)switchToSearch:(UIButton *)sender {
  529. if([self.current_VC isKindOfClass:[SearchViewController class]])
  530. return;
  531. [self flipFromViewController:self.current_VC toViewController:self.searchViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  532. }
  533. - (IBAction)switchToWishlist:(UIButton *)sender {
  534. [self switchtowishlist];
  535. }
  536. -(void)switchtowishlist
  537. {
  538. if([self.current_VC isKindOfClass:[WatchListViewController class]])
  539. return;
  540. // if([self.current_VC isKindOfClass:[OrderListViewController class]])
  541. // return;
  542. UIApplication * app = [UIApplication sharedApplication];
  543. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  544. if(appDelegate.bLogin==false)
  545. {
  546. LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  547. // loginvc.delegate = self;
  548. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  549. loginvc.returnValue = ^(bool blogin){
  550. if(blogin)
  551. {
  552. [self checklogin:true];
  553. [self flipFromViewController:self.current_VC toViewController:self.watchListViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  554. }
  555. };
  556. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  557. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  558. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  559. [self presentViewController:navi animated:YES completion:^{
  560. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  561. NSLog(@"LoginViewController present.........");
  562. // self.btop = false;
  563. // <#code#>
  564. }];
  565. }
  566. else
  567. [self flipFromViewController:self.current_VC toViewController:self.watchListViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  568. }
  569. - (IBAction)switchToContact:(UIButton *)sender {
  570. [self switchtocontact];
  571. }
  572. -(void)switchtocontact
  573. {
  574. if([self.current_VC isKindOfClass:[ContactListViewController class]])
  575. return;
  576. UIApplication * app = [UIApplication sharedApplication];
  577. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  578. if(appDelegate.bLogin==false)
  579. {
  580. LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  581. // loginvc.delegate = self;
  582. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  583. loginvc.returnValue = ^(bool blogin){
  584. if(blogin)
  585. {
  586. [self checklogin:true];
  587. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  588. {
  589. [self flipFromViewController:self.current_VC toViewController:self.contactListViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  590. }
  591. else
  592. {
  593. [RAUtils message_alert:@"Customer Login does not support this feature." title:@"Contact List" controller:self] ;
  594. }
  595. }
  596. };
  597. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  598. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  599. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  600. [self presentViewController:navi animated:YES completion:^{
  601. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  602. NSLog(@"LoginViewController present.........");
  603. // self.btop = false;
  604. // <#code#>
  605. }];
  606. }
  607. else
  608. [self flipFromViewController:self.current_VC toViewController:self.contactListViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  609. //
  610. // UIApplication * app = [UIApplication sharedApplication];
  611. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  612. // ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  613. // cvc.update_order = true;
  614. // cvc.contact_type = @"Sales_Order_Customer";
  615. // cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  616. //
  617. // appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  618. // appDelegate.customerInfo = value;
  619. //
  620. // // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  621. //
  622. // //
  623. // // if(self.returnValue)
  624. // // self.returnValue(value);
  625. // };
  626. // [self.navigationController pushViewController:cvc animated:true];
  627. }
  628. - (void) reload
  629. {
  630. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  631. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  632. NSDictionary* category=[iSalesNetwork request_Cagegory];
  633. dispatch_async(dispatch_get_main_queue(), ^{
  634. if([[category valueForKey:@"result"] intValue]==2)
  635. {
  636. appDelegate.categoryMenu = category;
  637. }
  638. else
  639. {
  640. // [RAUtils error_alert:[category valueForKey:@"err_msg"]] ;
  641. }
  642. });
  643. });
  644. }
  645. - (IBAction)onUserButtonClick:(id)sender {
  646. NSLog(@"header view login");
  647. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  648. if( appDelegate.user ==nil)
  649. {
  650. LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  651. // loginvc.delegate = self;
  652. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  653. loginvc.returnValue = ^(bool blogin){
  654. [self checklogin:true];
  655. };
  656. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  657. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  658. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  659. [self presentViewController:navi animated:YES completion:^{
  660. // <#code#>
  661. }];
  662. // LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  663. // loginvc.delegate = self;
  664. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  665. // [self presentViewController:loginvc animated:YES completion:^{
  666. //
  667. // NSLog(@"login.........");
  668. // // <#code#>
  669. // }];
  670. }
  671. }
  672. #pragma mark - LoginViewControllerDelegate
  673. -(void)LoginViewControllerDidLogin:(LoginViewController *)viewController
  674. {
  675. [viewController dismissViewControllerAnimated:YES completion:nil];
  676. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  677. self.sideMenu_UserName.text =appDelegate.user;
  678. [self.btn_sideMenu_UserName setTitle:appDelegate.user forState:UIControlStateNormal];
  679. [self.btnLogin setTitle:@"Sign out" forState:UIControlStateNormal];
  680. [iSalesNetwork LoadImage:appDelegate.user_icon into:self.user_head ];
  681. if(/*appDelegate.user_type==USER_ROLE_EMPLOYEE*/true)
  682. self.btnContact.hidden = NO;
  683. else
  684. self.btnContact.hidden = YES;
  685. NSDictionary * customerinfo=appDelegate.customerInfo;
  686. NSString * contact=nil;
  687. NSString * customer=nil;
  688. if(customerinfo==nil)
  689. {
  690. contact=@"Select Contact";
  691. [self.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  692. }
  693. else
  694. {
  695. contact=[customerinfo valueForKey:@"customer_contact"];
  696. customer=[customerinfo valueForKey:@"customer_name"];
  697. if(contact==nil||contact.length==0)
  698. {
  699. contact=@"No Name";
  700. [self.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  701. }
  702. else
  703. {
  704. [self.btnContact setTitleColor:UIColorFromRGB(0x009900) forState:UIControlStateNormal];
  705. }
  706. }
  707. NSMutableArray* arr_contact = [[NSMutableArray alloc] init];
  708. if(contact.length>0)
  709. [arr_contact addObject:contact];
  710. if(customer.length>0)
  711. [arr_contact addObject:customer];
  712. NSString *contact_string = [arr_contact componentsJoinedByString:@" @"];
  713. [self.btnContact setTitle:contact_string forState:UIControlStateNormal];
  714. // [self.buttonUser setTitle:appDelegate.user forState:UIControlStateNormal];
  715. [self reload];
  716. }
  717. - (void) flipFromViewController:(UIViewController*) fromController
  718. toViewController:(UIViewController*) toController
  719. withDirection:(UIViewAnimationOptions) direction
  720. {
  721. toController.view.frame = self.container.bounds; // 1
  722. // UIViewAutoresizingFlexibleLeftMargin = 1 << 0,
  723. // UIViewAutoresizingFlexibleWidth = 1 << 1,
  724. // UIViewAutoresizingFlexibleRightMargin = 1 << 2,
  725. // UIViewAutoresizingFlexibleTopMargin = 1 << 3,
  726. // UIViewAutoresizingFlexibleHeight = 1 << 4,
  727. // UIViewAutoresizingFlexibleBottomMargin = 1 << 5
  728. toController.view.autoresizingMask = UIViewAutoresizingFlexibleHeight |UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin;
  729. [self addChildViewController:toController]; //
  730. [fromController willMoveToParentViewController:nil]; //
  731. [self transitionFromViewController:fromController
  732. toViewController:toController
  733. duration:0.2
  734. options:direction | UIViewAnimationOptionCurveEaseIn
  735. animations:nil
  736. completion:^(BOOL finished) {
  737. [toController didMoveToParentViewController:self]; // 2
  738. [fromController removeFromParentViewController]; // 3
  739. self.current_VC = toController;
  740. }];
  741. }
  742. -(void)topicViewSelected:(int) type _id: (int) _id
  743. {
  744. [self switchToCagegory:nil];
  745. if(type==0)
  746. {
  747. // [self.categoryViewController showDetailat:_id];
  748. }
  749. else
  750. {
  751. [self.categoryViewController showCategory];
  752. }
  753. }
  754. -(void)categoryMenuSelected:(NSString*)_id
  755. {
  756. [self switchToCagegory:_id];
  757. // [self.categoryViewController showCategory];
  758. }
  759. - (void)switchToItemSearch:(NSString* )coverttype {
  760. // NSString* ttt =[@"Category" stringByAppendingString:[self categoryString:categoryid node:self.categoryMenu level:0]];
  761. // UIApplication * app = [UIApplication sharedApplication];
  762. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  763. self.itemSearchViewController.default_filter = nil;
  764. self.itemSearchViewController.covertype = coverttype;
  765. self.itemSearchViewController.saved_covertype = coverttype;
  766. self.categoryViewController.p_available = nil;
  767. self.categoryViewController.p_price = nil;
  768. self.categoryViewController.p_QTY = nil;
  769. self.categoryViewController.p_bestseller = nil;
  770. [self.itemSearchViewController reload_container_getdata:true];
  771. // .categoryString = [@"Category" stringByAppendingString:[self categoryString:categoryid node:appDelegate.categoryMenu level:0]];
  772. // self.categoryViewController.cagegoryLabel.text =self.categoryViewController.categoryString;
  773. // // NSString* sss =[@"Category" stringByAppendingString:[self categoryString:categoryid node:appDelegate.categoryMenu level:0]];
  774. // self.categoryViewController.categoryid = categoryid ;
  775. // [self.itemSearchViewController reload];
  776. // [self.itemSearchViewController showCategory];
  777. if([self.current_VC isKindOfClass:[ItemSearchViewController class]])
  778. return;
  779. [self flipFromViewController:self.current_VC toViewController:self.itemSearchViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  780. [[self navigationController] setNavigationBarHidden:YES animated:NO];
  781. // self.is_home = false;
  782. // self.current_vc = VC_CATEGORY;
  783. // [self.homeViewController willMoveToParentViewController:nil]; //1
  784. // [self.homeViewController.view removeFromSuperview]; //2
  785. // [self.homeViewController removeFromParentViewController]; //3
  786. //
  787. // [self.container addSubview:self.cagegoryViewController.view]; //2
  788. // [self.cagegoryViewController didMoveToParentViewController:self];
  789. }
  790. - (void)switchToCagegory:(NSString* )categoryid {
  791. // NSString* ttt =[@"Category" stringByAppendingString:[self categoryString:categoryid node:self.categoryMenu level:0]];
  792. UIApplication * app = [UIApplication sharedApplication];
  793. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  794. NSString* aaa =[@"Category" stringByAppendingString:[self categoryString:categoryid node:appDelegate.categoryMenu level:0]];;
  795. self.categoryViewController.categoryString = [@"Category" stringByAppendingString:[self categoryString:categoryid node:appDelegate.categoryMenu level:0]];
  796. self.categoryViewController.cagegoryLabel.text =self.categoryViewController.categoryString;
  797. // NSString* sss =[@"Category" stringByAppendingString:[self categoryString:categoryid node:appDelegate.categoryMenu level:0]];
  798. self.categoryViewController.categoryid = categoryid ;
  799. self.categoryViewController.loadall=false;
  800. // self.categoryViewController.collectionview
  801. self.categoryViewController.p_alert = nil;
  802. self.categoryViewController.p_available = nil;
  803. self.categoryViewController.p_price = nil;
  804. self.categoryViewController.p_QTY = nil;
  805. self.categoryViewController.p_bestseller = nil;
  806. self.categoryViewController.modelname = nil;
  807. self.categoryViewController.modeldescrip = nil;
  808. [self.categoryViewController reload_container_getdata:true];
  809. [self.categoryViewController showCategory];
  810. if([self.current_VC isKindOfClass:[CategoryViewController class]])
  811. return;
  812. [self flipFromViewController:self.current_VC toViewController:self.categoryViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  813. [[self navigationController] setNavigationBarHidden:YES animated:NO];
  814. // self.is_home = false;
  815. // self.current_vc = VC_CATEGORY;
  816. // [self.homeViewController willMoveToParentViewController:nil]; //1
  817. // [self.homeViewController.view removeFromSuperview]; //2
  818. // [self.homeViewController removeFromParentViewController]; //3
  819. //
  820. // [self.container addSubview:self.cagegoryViewController.view]; //2
  821. // [self.cagegoryViewController didMoveToParentViewController:self];
  822. }
  823. - (IBAction)switchToHome:(UIButton *)sender {
  824. [self switchToHome];
  825. // self.current_vc = VC_HOME;
  826. // self.is_home = true;
  827. //
  828. // [self.cagegoryViewController willMoveToParentViewController:nil]; //1
  829. // [self.cagegoryViewController.view removeFromSuperview]; //2
  830. // [self.cagegoryViewController removeFromParentViewController]; //3
  831. //
  832. // [self.container addSubview:self.homeViewController.view]; //2
  833. // [self.homeViewController didMoveToParentViewController:self];
  834. }
  835. -(void)switchToHome
  836. {
  837. if([self.current_VC isKindOfClass:[HomeViewController class]])
  838. return;
  839. [self flipFromViewController:self.current_VC toViewController:self.homeViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  840. }
  841. -(void) switchToPreviousVC
  842. {
  843. if(self.previous_VC==nil)
  844. return;
  845. if([self.current_VC isKindOfClass:[self.previous_VC class]])
  846. return;
  847. [self flipFromViewController:self.current_VC toViewController:self.previous_VC withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  848. }
  849. - (IBAction)switchToCart:(UIButton *)sender {
  850. [self switchToCart];
  851. // self.current_vc = VC_HOME;
  852. }
  853. -(void) switchToCart
  854. {
  855. if([self.current_VC isKindOfClass:[CartViewController class]])
  856. return;
  857. UIApplication * app = [UIApplication sharedApplication];
  858. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  859. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  860. if(appDelegate.bLogin==false)
  861. {
  862. LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  863. // loginvc.delegate = self;
  864. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  865. loginvc.returnValue = ^(bool blogin){
  866. // UIApplication * app = [UIApplication sharedApplication];
  867. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  868. if(blogin)
  869. {
  870. if(/*appDelegate.user_type==USER_ROLE_EMPLOYEE*/true)
  871. {
  872. [self checklogin:false];
  873. if(appDelegate.can_create_order)
  874. {
  875. NSString* msg =@"";
  876. if(appDelegate.contact_id.length>0)
  877. {
  878. msg = [msg stringByAppendingString:@"\n\nCustomer:"];
  879. msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
  880. }
  881. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Switch To Cart", nil) message:msg delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Check for saved order", nil),NSLocalizedString(@"Create new order", nil), nil];
  882. // alert.
  883. [alert show];
  884. }
  885. else
  886. {
  887. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Switch To Cart", nil) message:NSLocalizedString(@"Do you want to switch to a pending order?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Check for saved order", nil), nil];
  888. // alert.
  889. [alert show];
  890. }
  891. }
  892. else
  893. {
  894. [self checklogin:true];
  895. self.previous_VC = self.current_VC;
  896. [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  897. }
  898. }
  899. // self.offset = 0;
  900. // [self.content_data removeAllObjects];
  901. // [self loadpage];
  902. //
  903. // [[self navigationController] setNavigationBarHidden:YES animated:NO];
  904. };
  905. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  906. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  907. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  908. [self presentViewController:navi animated:YES completion:^{
  909. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  910. NSLog(@"LoginViewController present.........");
  911. // self.btop = false;
  912. // <#code#>
  913. }];
  914. }
  915. else
  916. {
  917. if(/*appDelegate.user_type==USER_ROLE_EMPLOYEE&&/*appDelegate.contact_id==nil&&*/appDelegate.order_code==nil)
  918. {
  919. [self checklogin:false];
  920. if(appDelegate.can_create_order)
  921. {
  922. NSString* msg =@"";
  923. if(appDelegate.contact_id.length>0)
  924. {
  925. msg = [msg stringByAppendingString:@"\n\nCustomer:"];
  926. msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
  927. }
  928. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Switch to cart", nil) message:msg delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Check for saved order", nil),NSLocalizedString(@"Create new order", nil), nil];
  929. // alert.
  930. [alert show];
  931. }
  932. else
  933. {
  934. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Switch to cart", nil) message:NSLocalizedString(@"Do you want to Switch to a pending order?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Switcht to pending order", nil), nil];
  935. // alert.
  936. [alert show];
  937. }
  938. }
  939. else
  940. {
  941. self.previous_VC = self.current_VC;
  942. [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  943. }
  944. }
  945. }
  946. -(void) switchToOrder
  947. {
  948. if([self.current_VC isKindOfClass:[OrderListViewController class]])
  949. return;
  950. UIApplication * app = [UIApplication sharedApplication];
  951. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  952. if(appDelegate.bLogin==false)
  953. {
  954. LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  955. // loginvc.delegate = self;
  956. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  957. loginvc.returnValue = ^(bool blogin){
  958. if(blogin)
  959. {
  960. [self checklogin:true];
  961. [self flipFromViewController:self.current_VC toViewController:self.orderViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  962. }
  963. };
  964. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  965. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  966. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  967. [self presentViewController:navi animated:YES completion:^{
  968. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  969. NSLog(@"LoginViewController present.........");
  970. // self.btop = false;
  971. // <#code#>
  972. }];
  973. }
  974. else
  975. [self flipFromViewController:self.current_VC toViewController:self.orderViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  976. }
  977. - (IBAction)switchToOrder:(id)sender {
  978. [self switchToOrder];
  979. //self.orderViewController =[ self.storyboard instantiateViewControllerWithIdentifier:@"OrderListViewController"];
  980. }
  981. #pragma mark - CategoryMenuDelegate
  982. -(void)SelectCategory:(NSString *)category
  983. {
  984. [self switchToCagegory:category];
  985. }
  986. - (IBAction)showCategoryMenu:(id)sender {
  987. RAViewController * categorymenuVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"RAViewController"];
  988. // categorymenuVC.rootViewController = self;
  989. categorymenuVC.CateMenu_delegate = self;
  990. // categorymenuVC.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  991. // [self presentViewController:categorymenuVC animated:YES completion:^{
  992. //
  993. // NSLog(@"login.........");
  994. // // <#code#>
  995. // }];
  996. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:categorymenuVC] ;
  997. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  998. [self presentViewController:navi animated:YES completion:^{
  999. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1000. NSLog(@"bundle present.........");
  1001. // self.btop = false;
  1002. // <#code#>
  1003. }];
  1004. // if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
  1005. // categorymenuVC.providesPresentationContextTransitionStyle = YES;
  1006. // categorymenuVC.definesPresentationContext = YES;
  1007. // categorymenuVC.modalPresentationStyle = UIModalPresentationFormSheet;
  1008. // [self presentViewController:categorymenuVC animated:YES completion:nil];
  1009. // } else {
  1010. // categorymenuVC.modalPresentationStyle = UIModalPresentationFormSheet;
  1011. // [self presentViewController:categorymenuVC animated:NO completion:nil];
  1012. //// self.view.window.rootViewController.modalPresentationStyle = UIModalPresentationFullScreen;
  1013. // }
  1014. UIApplication * app = [UIApplication sharedApplication];
  1015. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1016. if(appDelegate.categoryMenu == nil)
  1017. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1018. NSDictionary* category=[iSalesNetwork request_Cagegory];
  1019. dispatch_async(dispatch_get_main_queue(), ^{
  1020. if([[category valueForKey:@"result"] intValue]==2)
  1021. {
  1022. appDelegate.categoryMenu = category;
  1023. [categorymenuVC SetMenu:appDelegate.categoryMenu ];
  1024. }
  1025. else
  1026. if([[category valueForKey:@"result"] intValue]==RESULT_NET_ERROR)
  1027. {
  1028. [categorymenuVC SetMenu:nil ];
  1029. }
  1030. else
  1031. {
  1032. [RAUtils message_alert:[category valueForKey:@"err_msg"] title:@"Load Category Menu" controller:self] ;
  1033. }
  1034. });
  1035. });
  1036. else
  1037. [categorymenuVC SetMenu:appDelegate.categoryMenu];
  1038. }
  1039. -(NSString*) categoryString:(NSString*) categoryid node:(NSDictionary*) json level:(int) level;
  1040. {
  1041. if(categoryid.length==0)
  1042. return @">All Products>";
  1043. //NSString* idString = [NSString stringWithFormat:@"%d",categoryid];
  1044. NSString* categoryString =@">";
  1045. int count = [[json valueForKey:@"count"] intValue];
  1046. for(int i=0;i<count;i++)
  1047. {
  1048. NSDictionary * category_json = [json objectForKey:[NSString stringWithFormat:@"category_%d",i]];
  1049. NSString* cid = [category_json valueForKey:@"id"] ;
  1050. // NSString* ttt =[categoryid substringToIndex:2+level*2];
  1051. // NSString * qqq =[cid substringToIndex:2+level*2];
  1052. // NSString *ds1=[categoryid substringToIndex:3+level*3];
  1053. // NSString*ds2 = [cid substringToIndex:3+level*3];
  1054. if(cid.length<3+level*3)
  1055. continue;
  1056. if(categoryid.length<3+level*3)
  1057. continue;
  1058. if([[categoryid substringToIndex:3+level*3] isEqualToString: [cid substringToIndex:3+level*3]])
  1059. {
  1060. //categoryString = [categoryString stringByAppendingString:@">"];
  1061. categoryString =[categoryString stringByAppendingString: [category_json valueForKey:@"title" ] ];
  1062. categoryString = [categoryString stringByAppendingString:[ self categoryString:categoryid node:category_json level:level+1]];
  1063. break;
  1064. }
  1065. }
  1066. return categoryString;
  1067. }
  1068. - (void)didReceiveMemoryWarning
  1069. {
  1070. [super didReceiveMemoryWarning];
  1071. // Dispose of any resources that can be recreated.
  1072. }
  1073. - (IBAction)openMenu:(UIButton *)sender {
  1074. [self showMenu];
  1075. // [((RootContainerViewController *)self.parentViewController) showMenu];
  1076. // SideMenuViewController *sideMenuController = [self.storyboard instantiateViewControllerWithIdentifier:@"SideMenuViewController"];
  1077. // if (sideMenuController) {
  1078. // //[sideMenuController openMenu];
  1079. // [UIView animateWithDuration:1.0 animations:^{ sideMenuController.view.alpha = 1.0;
  1080. // self.view.alpha = 0.0; }];
  1081. // }
  1082. }
  1083. - (UIImage*)screen_shot
  1084. {
  1085. // CGRect r = self.view.frame;
  1086. // CGRect r1 = self.view.bounds;
  1087. // double width,height;
  1088. //
  1089. // UIInterfaceOrientation orientation =[UIApplication sharedApplication].statusBarOrientation;
  1090. // ;
  1091. // if(orientation == UIDeviceOrientationLandscapeLeft ||orientation == UIDeviceOrientationLandscapeRight)
  1092. // {
  1093. // width = self.view.frame.size.width>self.view.frame.size.height? self.view.frame.size.width:self.view.frame.size.height;
  1094. // height =self.view.frame.size.width<self.view.frame.size.height? self.view.frame.size.width:self.view.frame.size.height;
  1095. // }
  1096. // else
  1097. // {
  1098. // width = self.view.frame.size.width<self.view.frame.size.height? self.view.frame.size.width:self.view.frame.size.height;
  1099. // height =self.view.frame.size.width>self.view.frame.size.height? self.view.frame.size.width:self.view.frame.size.height;
  1100. // }
  1101. UIGraphicsBeginImageContext(CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height));
  1102. [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
  1103. UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
  1104. UIGraphicsEndImageContext();
  1105. return viewImage;
  1106. }
  1107. - (IBAction)onhideMenuClick:(id)sender {
  1108. [self hideMenu];
  1109. self.backgroundButton.hidden=true;
  1110. self.openMenuButton.hidden = false;
  1111. self.sideMenu.hidden = true;
  1112. }
  1113. - (void)hideMenu
  1114. {
  1115. CGRect frame ;
  1116. frame.origin.x = -300;
  1117. frame.origin.y = 0;
  1118. frame.size.height = self.view.bounds.size.height;
  1119. frame.size.width = 364;
  1120. self.sideMenu.frame=frame;
  1121. self.sideMenu.hidden = true;
  1122. self.blurView.alpha = 0;
  1123. [self.menuButton setImage:[UIImage imageNamed:@"menu_open"] forState:UIControlStateNormal];
  1124. self.menuShown = false;
  1125. self.backgroundButton.hidden=true;
  1126. self.openMenuButton.hidden = false;
  1127. }
  1128. - (void)showMenu
  1129. {
  1130. [self.sideMenuTable reloadData];
  1131. UIImage* imgsource = [self screen_shot];
  1132. self.blurView.alpha = 0;
  1133. UIImage* imgBlur =[self applyBlurWithRadius:5 sourceImage:imgsource tintColor:[UIColor colorWithWhite:0.2 alpha:0.73] saturationDeltaFactor:1.8 maskImage:nil];
  1134. self.blurView.image = imgBlur;
  1135. // self.blurView.hidden = imgBlur;
  1136. // [self.sideMenu becomeFirstResponder];
  1137. self.sideMenu.hidden = false;
  1138. self.backgroundButton.hidden=false;
  1139. CGRect frame ;
  1140. frame.origin.x = 0;
  1141. frame.origin.y = 0;
  1142. frame.size.height = self.view.bounds.size.height;
  1143. frame.size.width = 364;
  1144. // [UIView animateWithDuration:1.0 animations:^{ self.sideMenu.frame=frame;
  1145. // self.blurView.alpha = 1;
  1146. // [self.menuButton setImage:[UIImage imageNamed:@"menu"] forState:UIControlStateNormal];
  1147. //
  1148. // }];
  1149. [UIView animateWithDuration:0.5 animations:^{ self.sideMenu.frame=frame;
  1150. self.blurView.alpha = 1;
  1151. }
  1152. completion:^(BOOL finished) {
  1153. [self.menuButton setImage:[UIImage imageNamed:@"menu"] forState:UIControlStateNormal];
  1154. }];
  1155. // UIImage* img= [UIImage imageNamed:@"menu"];
  1156. // self.menuButton.imageView.image = nil;
  1157. self.menuShown = true;
  1158. }
  1159. -(void)initMenuItems
  1160. {
  1161. UIApplication * app = [UIApplication sharedApplication];
  1162. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1163. self.sideMenuItems = [[NSMutableArray alloc] init];
  1164. NSMutableDictionary* map = [[NSMutableDictionary alloc] init];
  1165. if(appDelegate.user!=nil)
  1166. {
  1167. [map setValue:@"Wish List" forKey:@"title"];
  1168. [map setValue:@"rect_market_news" forKey:@"img"];
  1169. [self.sideMenuItems addObject:map.copy];
  1170. }
  1171. // if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  1172. {
  1173. [map setValue:@"Cam Scan" forKey:@"title"];
  1174. [map setValue:@"rect_contact_list" forKey:@"img"];
  1175. [self.sideMenuItems addObject:map.copy];
  1176. }
  1177. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  1178. {
  1179. // [map setValue:@"Contact" forKey:@"title"];
  1180. // [map setValue:@"rect_contact_list" forKey:@"img"];
  1181. // [self.sideMenuItems addObject:map.copy];
  1182. [map setValue:@"Portfolio" forKey:@"title"];
  1183. [map setValue:@"rect_market_news" forKey:@"img"];
  1184. [self.sideMenuItems addObject:map.copy];
  1185. [map setValue:@"View Portfolios" forKey:@"title"];
  1186. [map setValue:@"rect_pdf_list" forKey:@"img"];
  1187. [self.sideMenuItems addObject:map.copy];
  1188. }
  1189. if(appDelegate.can_show_price)
  1190. {
  1191. if(appDelegate.price_hidden)
  1192. [map setValue:@"Show Price" forKey:@"title"];
  1193. else
  1194. [map setValue:@"Hide Price" forKey:@"title"];
  1195. [map setValue:@"rect_announcements" forKey:@"img"];
  1196. [self.sideMenuItems addObject:map.copy];
  1197. }
  1198. // [map setValue:@"Contact" forKey:@"title"];
  1199. // [map setValue:@"rect_market_news" forKey:@"img"];
  1200. // [self.sideMenuItems addObject:map.copy];
  1201. [map setValue:@"Cache" forKey:@"title"];
  1202. [map setValue:@"rect_announcements" forKey:@"img"];
  1203. [self.sideMenuItems addObject:map.copy];
  1204. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  1205. // [map setValue:@"Message" forKey:@"title"];
  1206. // [map setValue:@"rect_search_history" forKey:@"img"];
  1207. // [self.sideMenuItems addObject:map.copy];
  1208. //
  1209. [map setValue:@"Scanner Setting" forKey:@"title"];
  1210. [map setValue:@"rect_change_password" forKey:@"img"];
  1211. [self.sideMenuItems addObject:map.copy];
  1212. #ifdef BUILD_NPD
  1213. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  1214. {
  1215. [map setValue:@"Offline Setting" forKey:@"title"];
  1216. [map setValue:@"rect_market_news" forKey:@"img"];
  1217. [self.sideMenuItems addObject:map.copy];
  1218. }
  1219. if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER) {
  1220. [map setValue:@"Price Setting" forKey:@"title"];
  1221. // [map setValue:@"rect_market_news" forKey:@"img"];
  1222. [self.sideMenuItems addObject:map.copy];
  1223. }
  1224. # endif
  1225. // if([[appDelegate.user lowercaseString] isEqualToString:@"larryl"]||[[appDelegate.user lowercaseString] isEqualToString:@"arpithat"])
  1226. // {
  1227. // // [map setValue:@"Contact" forKey:@"title"];
  1228. // // [map setValue:@"rect_contact_list" forKey:@"img"];
  1229. // // [self.sideMenuItems addObject:map.copy];
  1230. //
  1231. //
  1232. // [map setValue:@"Function Test" forKey:@"title"];
  1233. // [map setValue:@"rect_market_news" forKey:@"img"];
  1234. // [self.sideMenuItems addObject:map.copy];
  1235. //
  1236. //
  1237. // }
  1238. //
  1239. [map setValue:@"About us" forKey:@"title"];
  1240. [map setValue:@"rect_change_password" forKey:@"img"];
  1241. [self.sideMenuItems addObject:map.copy];
  1242. #ifdef BUILD_HMLG
  1243. [map setValue:@"Homelegance Website" forKey:@"title"];
  1244. [map setValue:@"rect_change_password" forKey:@"img"];
  1245. [self.sideMenuItems addObject:map.copy];
  1246. #endif
  1247. #ifdef BUILD_NPD
  1248. [map setValue:@"NPD Website" forKey:@"title"];
  1249. [map setValue:@"rect_change_password" forKey:@"img"];
  1250. [self.sideMenuItems addObject:map.copy];
  1251. [map setValue:@"NPD Policy" forKey:@"title"];
  1252. [map setValue:@"rect_change_password" forKey:@"img"];
  1253. [self.sideMenuItems addObject:map.copy];
  1254. [map setValue:@"Simplified Buying Program" forKey:@"title"];
  1255. [map setValue:@"rect_change_password" forKey:@"img"];
  1256. [self.sideMenuItems addObject:map.copy];
  1257. #endif
  1258. [self.sideMenuTable reloadData];
  1259. //
  1260. }
  1261. - (UIImage *)applyBlurWithRadius:(CGFloat)blurRadius sourceImage:(UIImage*)sourceImage tintColor:(UIColor *)tintColor saturationDeltaFactor:(CGFloat)saturationDeltaFactor maskImage:(UIImage *)maskImage
  1262. {
  1263. // Check pre-conditions.
  1264. if (sourceImage.size.width < 1 || sourceImage.size.height < 1) {
  1265. NSLog (@"*** error: invalid size: (%.2f x %.2f). Both dimensions must be >= 1: %@", sourceImage.size.width, sourceImage.size.height, self);
  1266. return nil;
  1267. }
  1268. if (!sourceImage.CGImage) {
  1269. NSLog (@"*** error: image must be backed by a CGImage: %@", self);
  1270. return nil;
  1271. }
  1272. if (maskImage && !maskImage.CGImage) {
  1273. NSLog (@"*** error: maskImage must be backed by a CGImage: %@", maskImage);
  1274. return nil;
  1275. }
  1276. CGRect imageRect = { CGPointZero, sourceImage.size };
  1277. UIImage *effectImage = sourceImage;
  1278. BOOL hasBlur = blurRadius > __FLT_EPSILON__;
  1279. BOOL hasSaturationChange = fabs(saturationDeltaFactor - 1.) > __FLT_EPSILON__;
  1280. if (hasBlur || hasSaturationChange) {
  1281. UIGraphicsBeginImageContextWithOptions(sourceImage.size, NO, [[UIScreen mainScreen] scale]);
  1282. CGContextRef effectInContext = UIGraphicsGetCurrentContext();
  1283. CGContextScaleCTM(effectInContext, 1.0, -1.0);
  1284. CGContextTranslateCTM(effectInContext, 0, -sourceImage.size.height);
  1285. CGContextDrawImage(effectInContext, imageRect, sourceImage.CGImage);
  1286. vImage_Buffer effectInBuffer;
  1287. effectInBuffer.data = CGBitmapContextGetData(effectInContext);
  1288. effectInBuffer.width = CGBitmapContextGetWidth(effectInContext);
  1289. effectInBuffer.height = CGBitmapContextGetHeight(effectInContext);
  1290. effectInBuffer.rowBytes = CGBitmapContextGetBytesPerRow(effectInContext);
  1291. UIGraphicsBeginImageContextWithOptions(sourceImage.size, NO, [[UIScreen mainScreen] scale]);
  1292. CGContextRef effectOutContext = UIGraphicsGetCurrentContext();
  1293. vImage_Buffer effectOutBuffer;
  1294. effectOutBuffer.data = CGBitmapContextGetData(effectOutContext);
  1295. effectOutBuffer.width = CGBitmapContextGetWidth(effectOutContext);
  1296. effectOutBuffer.height = CGBitmapContextGetHeight(effectOutContext);
  1297. effectOutBuffer.rowBytes = CGBitmapContextGetBytesPerRow(effectOutContext);
  1298. if (hasBlur) {
  1299. // A description of how to compute the box kernel width from the Gaussian
  1300. // radius (aka standard deviation) appears in the SVG spec:
  1301. // http://www.w3.org/TR/SVG/filters.html#feGaussianBlurElement
  1302. //
  1303. // For larger values of 's' (s >= 2.0), an approximation can be used: Three
  1304. // successive box-blurs build a piece-wise quadratic convolution kernel, which
  1305. // approximates the Gaussian kernel to within roughly 3%.
  1306. //
  1307. // let d = floor(s * 3*sqrt(2*pi)/4 + 0.5)
  1308. //
  1309. // ... if d is odd, use three box-blurs of size 'd', centered on the output pixel.
  1310. //
  1311. CGFloat inputRadius = blurRadius * [[UIScreen mainScreen] scale];
  1312. NSUInteger radius = floor(inputRadius * 3. * sqrt(2 * M_PI) / 4 + 0.5);
  1313. if (radius % 2 != 1) {
  1314. radius += 1; // force radius to be odd so that the three box-blur methodology works.
  1315. }
  1316. vImageBoxConvolve_ARGB8888(&effectInBuffer, &effectOutBuffer, NULL, 0, 0, (unsigned int)radius, (unsigned int)radius, 0, kvImageEdgeExtend);
  1317. vImageBoxConvolve_ARGB8888(&effectOutBuffer, &effectInBuffer, NULL, 0, 0, (unsigned int)radius, (unsigned int)radius, 0, kvImageEdgeExtend);
  1318. vImageBoxConvolve_ARGB8888(&effectInBuffer, &effectOutBuffer, NULL, 0, 0, (unsigned int)radius, (unsigned int)radius, 0, kvImageEdgeExtend);
  1319. }
  1320. BOOL effectImageBuffersAreSwapped = NO;
  1321. if (hasSaturationChange) {
  1322. CGFloat s = saturationDeltaFactor;
  1323. CGFloat floatingPointSaturationMatrix[] = {
  1324. 0.0722 + 0.9278 * s, 0.0722 - 0.0722 * s, 0.0722 - 0.0722 * s, 0,
  1325. 0.7152 - 0.7152 * s, 0.7152 + 0.2848 * s, 0.7152 - 0.7152 * s, 0,
  1326. 0.2126 - 0.2126 * s, 0.2126 - 0.2126 * s, 0.2126 + 0.7873 * s, 0,
  1327. 0, 0, 0, 1,
  1328. };
  1329. const int32_t divisor = 256;
  1330. NSUInteger matrixSize = sizeof(floatingPointSaturationMatrix)/sizeof(floatingPointSaturationMatrix[0]);
  1331. int16_t saturationMatrix[matrixSize];
  1332. for (NSUInteger i = 0; i < matrixSize; ++i) {
  1333. saturationMatrix[i] = (int16_t)roundf(floatingPointSaturationMatrix[i] * divisor);
  1334. }
  1335. if (hasBlur) {
  1336. vImageMatrixMultiply_ARGB8888(&effectOutBuffer, &effectInBuffer, saturationMatrix, divisor, NULL, NULL, kvImageNoFlags);
  1337. effectImageBuffersAreSwapped = YES;
  1338. }
  1339. else {
  1340. vImageMatrixMultiply_ARGB8888(&effectInBuffer, &effectOutBuffer, saturationMatrix, divisor, NULL, NULL, kvImageNoFlags);
  1341. }
  1342. }
  1343. if (!effectImageBuffersAreSwapped)
  1344. effectImage = UIGraphicsGetImageFromCurrentImageContext();
  1345. UIGraphicsEndImageContext();
  1346. if (effectImageBuffersAreSwapped)
  1347. effectImage = UIGraphicsGetImageFromCurrentImageContext();
  1348. UIGraphicsEndImageContext();
  1349. }
  1350. // Set up output context.
  1351. UIGraphicsBeginImageContextWithOptions(sourceImage.size, NO, [[UIScreen mainScreen] scale]);
  1352. CGContextRef outputContext = UIGraphicsGetCurrentContext();
  1353. CGContextScaleCTM(outputContext, 1.0, -1.0);
  1354. CGContextTranslateCTM(outputContext, 0, -sourceImage.size.height);
  1355. // Draw base image.
  1356. CGContextDrawImage(outputContext, imageRect, sourceImage.CGImage);
  1357. // Draw effect image.
  1358. if (hasBlur) {
  1359. CGContextSaveGState(outputContext);
  1360. if (maskImage) {
  1361. CGContextClipToMask(outputContext, imageRect, maskImage.CGImage);
  1362. }
  1363. CGContextDrawImage(outputContext, imageRect, effectImage.CGImage);
  1364. CGContextRestoreGState(outputContext);
  1365. }
  1366. // Add in color tint.
  1367. if (tintColor) {
  1368. CGContextSaveGState(outputContext);
  1369. CGContextSetFillColorWithColor(outputContext, tintColor.CGColor);
  1370. CGContextFillRect(outputContext, imageRect);
  1371. CGContextRestoreGState(outputContext);
  1372. }
  1373. // Output image is ready.
  1374. UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext();
  1375. UIGraphicsEndImageContext();
  1376. return outputImage;
  1377. }
  1378. //- (IBAction)openMenu:(UIButton *)sender {
  1379. //}
  1380. #pragma mark - Table view data source
  1381. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  1382. {
  1383. return 1;
  1384. }
  1385. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  1386. {
  1387. return self.sideMenuItems.count;
  1388. }
  1389. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  1390. {
  1391. UIApplication * app = [UIApplication sharedApplication];
  1392. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1393. NSString *CellIdentifier = @"SideMenuItem";
  1394. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1395. NSString* title = [self.sideMenuItems[indexPath.row] valueForKey:@"title"];
  1396. cell.backgroundColor = [UIColor clearColor];
  1397. // [cell.backgroundColor:[UIColor clearColor]];
  1398. // UIImageView* iv= [[UIImageView alloc] initWithImage:];
  1399. cell.textLabel.text = title;
  1400. cell.detailTextLabel.textColor =[UIColor redColor];
  1401. if([title isEqualToString:@"Wish List"]&&appDelegate.wish_count>0)
  1402. cell.detailTextLabel.text = [NSString stringWithFormat:@"%ld",appDelegate.wish_count];
  1403. else if([title isEqualToString:@"Portfolio"]&&appDelegate.port_count>0)
  1404. cell.detailTextLabel.text = [NSString stringWithFormat:@"%ld",appDelegate.port_count];
  1405. else
  1406. {
  1407. cell.detailTextLabel.text =nil;
  1408. }
  1409. // cell.imageView.image = [UIImage imageNamed:[self.toolsinfo[indexPath.row] valueForKey:@"img"]];
  1410. return cell;
  1411. }
  1412. #pragma mark - Table view delegate
  1413. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  1414. {
  1415. NSString* title = [self.sideMenuItems[indexPath.row] valueForKey:@"title"];
  1416. if([title isEqualToString:@"Cache"])
  1417. {
  1418. CacheViewController * settingvc=[ self.storyboard instantiateViewControllerWithIdentifier:@"CacheViewController"];
  1419. PopupNavigationController * navi=[[PopupNavigationController alloc] initWithRootViewController:settingvc];
  1420. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1421. [self presentViewController:navi animated:YES completion:^{
  1422. //NSLog(@"login.........");
  1423. // <#code#>
  1424. }];
  1425. }
  1426. else if([title isEqualToString:@"Scanner Setting"])
  1427. {
  1428. UIApplication * app = [UIApplication sharedApplication];
  1429. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1430. UIViewController* active_vc = appDelegate.active_controller;
  1431. ScannerSettingViewController * gunVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"ScannerSettingViewController"];
  1432. // loginvc.delegate = self;
  1433. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1434. appDelegate.active_controller = gunVC;
  1435. gunVC.onDismissVC = ^(){
  1436. appDelegate.active_controller = active_vc;
  1437. };
  1438. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:gunVC] ;
  1439. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1440. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  1441. [self presentViewController:navi animated:YES completion:^{
  1442. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1443. NSLog(@"about present.........");
  1444. // self.btop = false;
  1445. // <#code#>
  1446. }];
  1447. }
  1448. else if([title isEqualToString:@"Offline Setting"])
  1449. {
  1450. UIApplication * app = [UIApplication sharedApplication];
  1451. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1452. //UIViewController* active_vc = appDelegate.active_controller;
  1453. OfflineSettingViewController * offlineVC =[ [UIStoryboard storyboardWithName:@"OLM" bundle:nil] instantiateViewControllerWithIdentifier:@"OfflineSettingViewController"];
  1454. // loginvc.delegate = self;
  1455. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1456. // appDelegate.active_controller = gunVC;
  1457. // gunVC.onDismissVC = ^(){
  1458. // appDelegate.active_controller = active_vc;
  1459. // };
  1460. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:offlineVC] ;
  1461. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1462. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  1463. [self presentViewController:navi animated:YES completion:^{
  1464. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1465. NSLog(@"about present.........");
  1466. // self.btop = false;
  1467. // <#code#>
  1468. }];
  1469. // [iSalesDB testdata];
  1470. }
  1471. else if([title isEqualToString:@"Function Test"])
  1472. {
  1473. // NSString* url = @"https://www.newpacificdirect.com";
  1474. //
  1475. //
  1476. // NSString* title = @"NPD";
  1477. // UIApplication * app = [UIApplication sharedApplication];
  1478. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1479. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  1480. //
  1481. //
  1482. FunctionTestViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"FunctionTestViewController"];
  1483. // ViewController.url = url;
  1484. // ViewController.title = title;
  1485. [self.navigationController pushViewController:ViewController animated:YES];
  1486. }
  1487. else if([title isEqualToString:@"NPD Website"])
  1488. {
  1489. NSString* url = @"https://www.newpacificdirect.com";//@"https://www.newpacificdirect.com/general.htm?websiteId=1";//
  1490. NSString* title = @"NPD";
  1491. // UIApplication * app = [UIApplication sharedApplication];
  1492. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1493. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  1494. //
  1495. //
  1496. WebViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"WebViewController"];
  1497. ViewController.url = url;
  1498. ViewController.title = title;
  1499. [self.navigationController pushViewController:ViewController animated:YES];
  1500. }
  1501. else if([title isEqualToString:@"Homelegance Website"])
  1502. {
  1503. NSString* url = @"http://207.140.24.83";//@"https://www.newpacificdirect.com/general.htm?websiteId=1";//
  1504. NSString* title = @"Homelegance";
  1505. // UIApplication * app = [UIApplication sharedApplication];
  1506. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1507. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  1508. //
  1509. //
  1510. WebViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"WebViewController"];
  1511. ViewController.url = url;
  1512. ViewController.title = title;
  1513. [self.navigationController pushViewController:ViewController animated:YES];
  1514. }
  1515. else if([title isEqualToString:@"NPD Policy"])
  1516. {
  1517. NSString* url = URL_NPD_POLICY;//@"https://www.newpacificdirect.com/general.htm?websiteId=1";//
  1518. NSString* title = @"NPD Policy";
  1519. // UIApplication * app = [UIApplication sharedApplication];
  1520. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1521. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  1522. //
  1523. //
  1524. WebViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"WebViewController"];
  1525. ViewController.url = url;
  1526. ViewController.title = title;
  1527. [self.navigationController pushViewController:ViewController animated:YES];
  1528. }
  1529. else if([title isEqualToString:@"Simplified Buying Program"])
  1530. {
  1531. SimplifiedBuyingProgramViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"SimplifiedBuyingProgramViewController"];
  1532. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:ViewController] ;
  1533. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1534. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  1535. [self presentViewController:navi animated:YES completion:^{
  1536. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1537. NSLog(@"about present.........");
  1538. // self.btop = false;
  1539. // <#code#>
  1540. }];
  1541. }
  1542. else if([title isEqualToString:@"About us"])
  1543. {
  1544. AboutViewController * aboutVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"AboutViewController"];
  1545. // loginvc.delegate = self;
  1546. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1547. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:aboutVC] ;
  1548. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1549. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  1550. [self presentViewController:navi animated:YES completion:^{
  1551. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1552. NSLog(@"about present.........");
  1553. // self.btop = false;
  1554. // <#code#>
  1555. }];
  1556. }
  1557. else if([title isEqualToString:@"Wish List"])
  1558. {
  1559. [self hideMenu];
  1560. [self switchtowishlist];
  1561. }
  1562. else if([title isEqualToString:@"Show Price"])
  1563. {
  1564. UIApplication * app = [UIApplication sharedApplication];
  1565. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1566. JKLockController *lockVC = [[JKLockController alloc] init];
  1567. [lockVC setPasswordKey:[NSString stringWithFormat:@"%@_password",appDelegate.user]];
  1568. __weak typeof(self) weakself = self;
  1569. lockVC.authoReturn = ^(BOOL failure) {
  1570. if (weakself) {
  1571. __strong typeof(weakself) strongself = weakself;
  1572. [appDelegate set_priceHidden:false];
  1573. [strongself initMenuItems];
  1574. [strongself hideMenu];
  1575. }
  1576. };
  1577. [self.navigationController pushViewController:lockVC animated:YES];
  1578. }
  1579. else if([title isEqualToString:@"Hide Price"])
  1580. {
  1581. UIApplication * app = [UIApplication sharedApplication];
  1582. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1583. JKLockController *lockVC = [[JKLockController alloc] init];
  1584. [lockVC setPasswordKey:[NSString stringWithFormat:@"%@_password",appDelegate.user]];
  1585. __weak typeof(self) weakself = self;
  1586. lockVC.authoReturn = ^(BOOL failure) {
  1587. if (weakself) {
  1588. __strong typeof(weakself) strongself = weakself;
  1589. [appDelegate set_priceHidden:true];
  1590. [strongself initMenuItems];
  1591. [strongself hideMenu];
  1592. }
  1593. };
  1594. [self.navigationController pushViewController:lockVC animated:YES];
  1595. }
  1596. else if([title isEqualToString:@"Portfolio"])
  1597. {
  1598. [self hideMenu];
  1599. if([self.current_VC isKindOfClass:[PortfolioViewController class]])
  1600. return;
  1601. [self flipFromViewController:self.current_VC toViewController:self.portfolioViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1602. }
  1603. else if([title isEqualToString:@"View Portfolios"])
  1604. {
  1605. [self hideMenu];
  1606. if([self.current_VC isKindOfClass:[PDFListViewController class]])
  1607. return;
  1608. [self flipFromViewController:self.current_VC toViewController:self.pdfListViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1609. }
  1610. else if([title isEqualToString:@"Contact"])
  1611. {
  1612. // UITableViewCell* cell =(UITableViewCell*) sender.superview.superview;
  1613. //
  1614. // NSIndexPath * indexPath = [self.detailTable indexPathForCell:cell];
  1615. //
  1616. // if(indexPath.section!=1)
  1617. // return ;
  1618. // // NSLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
  1619. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1620. //
  1621. // NSString* product_id = [item_json valueForKey:@"product_id"];
  1622. [self hideMenu];
  1623. [self switchtocontact];
  1624. }
  1625. else if([title isEqualToString:@"Cam Scan"])
  1626. {
  1627. // UITableViewCell* cell =(UITableViewCell*) sender.superview.superview;
  1628. //
  1629. // NSIndexPath * indexPath = [self.detailTable indexPathForCell:cell];
  1630. //
  1631. // if(indexPath.section!=1)
  1632. // return ;
  1633. // // NSLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
  1634. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1635. //
  1636. // NSString* product_id = [item_json valueForKey:@"product_id"];
  1637. [self hideMenu];
  1638. //
  1639. // [self switchtocontact];
  1640. ScannerViewController * scannerVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"ScannerViewController"];
  1641. [self.navigationController pushViewController:scannerVC animated:true];
  1642. } else if ([title isEqualToString:@"Price Setting"]) {
  1643. UIApplication * app = [UIApplication sharedApplication];
  1644. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1645. JKLockController *lockVC = [[JKLockController alloc] init];
  1646. [lockVC setPasswordKey:[NSString stringWithFormat:@"%@_password",appDelegate.user]];
  1647. __weak typeof(self) weakself = self;
  1648. lockVC.authoReturn = ^(BOOL failure) {
  1649. if (weakself) {
  1650. __strong typeof(weakself) strongself = weakself;
  1651. PriceSettingViewController *priceSettingVC =[ [UIStoryboard storyboardWithName:@"CUL" bundle:nil] instantiateViewControllerWithIdentifier:@"PriceSettingViewController"];
  1652. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:priceSettingVC] ;
  1653. navi.navigationBar.translucent = NO;
  1654. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  1655. [strongself presentViewController:navi animated:YES completion:^{
  1656. }];
  1657. }
  1658. };
  1659. [self.navigationController pushViewController:lockVC animated:YES];
  1660. }
  1661. }
  1662. #pragma mark - UIAlertViewDelegate
  1663. // Called when a button is clicked. The view will be automatically dismissed after this call returns
  1664. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  1665. {
  1666. UIApplication * app = [UIApplication sharedApplication];
  1667. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1668. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  1669. if(buttonIndex==alertView.cancelButtonIndex)
  1670. {
  1671. }
  1672. else if(buttonIndex==1)
  1673. {
  1674. //open exist
  1675. OrderListViewController* ovc =[ self.storyboard instantiateViewControllerWithIdentifier:@"OrderListViewController"];
  1676. ovc.showNavibar = true;
  1677. ovc.selectOrder = ^(NSMutableDictionary* order_detail){
  1678. if(appDelegate.order_code==nil)
  1679. {
  1680. [self neworderforCart];
  1681. }
  1682. else
  1683. {
  1684. self.previous_VC = self.current_VC;
  1685. [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1686. [self checklogin:true];
  1687. }
  1688. };
  1689. ovc.init_style = OL_OPEN;
  1690. ovc.onCancel = ^(){
  1691. [self checklogin:true];
  1692. };
  1693. [self.navigationController pushViewController:ovc animated:true];
  1694. }
  1695. else
  1696. {
  1697. //create new;
  1698. if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  1699. {
  1700. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  1701. cvc.showNavibar = true;
  1702. cvc.contact_type = @"Sales_Order_Customer";
  1703. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1704. appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  1705. appDelegate.customerInfo = value;
  1706. if(appDelegate.order_code==nil)
  1707. [self neworderforCart];
  1708. };
  1709. cvc.onCancel = ^(){
  1710. [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"" controller:self];
  1711. };
  1712. cvc.onReset = ^(){
  1713. [self checklogin:true];
  1714. };
  1715. [self.navigationController pushViewController:cvc animated:true];
  1716. }
  1717. else
  1718. {
  1719. [self neworderforCart];
  1720. }
  1721. }
  1722. }
  1723. -(void) neworderforCart
  1724. {
  1725. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Create Order"];
  1726. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1727. NSDictionary* return_json = [iSalesNetwork new_Order];
  1728. dispatch_async(dispatch_get_main_queue(), ^{
  1729. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  1730. if([[return_json valueForKey:@"result"] intValue]==2)
  1731. {
  1732. int result=[[return_json valueForKey:@"result"] intValue];
  1733. if(result==2)
  1734. {
  1735. //successed.
  1736. NSString* order_code = [return_json valueForKey:@"orderCode"];
  1737. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1738. appDelegate.order_code = order_code;
  1739. appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
  1740. self.previous_VC = self.current_VC;
  1741. [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1742. }
  1743. }
  1744. else
  1745. {
  1746. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
  1747. }
  1748. });
  1749. });
  1750. }
  1751. - (void)showPriceAuth:(NSInteger)from {
  1752. }
  1753. @end