MainViewController.m 99 KB

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