MainViewController.m 105 KB

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