MainViewController.m 89 KB

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