MainViewController.m 91 KB

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