MainViewController.m 131 KB

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