MainViewController.m 96 KB

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