MainViewController.m 140 KB

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