MainViewController.m 100 KB

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