MainViewController.m 136 KB

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