MainViewController.m 102 KB

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