MainViewController.m 158 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146
  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. NSLog(@"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. NSLog(@"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. // NSLog(@"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. [RANetwork request_logout:^(NSMutableDictionary *result) {
  693. NSMutableDictionary* return_json =result;
  694. [waitalert dismissViewControllerAnimated:YES completion:^{
  695. if([[return_json valueForKey:@"result"] intValue]==2)
  696. {
  697. // [self hideMenu];
  698. // [self switchToHome:nil];
  699. [appDelegate Logout];
  700. [self checklogin :false];
  701. if(showlogin)
  702. {
  703. LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  704. loginvc.returnValue = ^(bool blogin){
  705. [self checklogin :true];
  706. };
  707. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  708. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  709. [self presentViewController:navi animated:YES completion:^{
  710. DebugLog(@"login present.........");
  711. }];
  712. }
  713. }
  714. else
  715. {
  716. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Sign Out" controller:self] ;
  717. }
  718. }];
  719. }];
  720. }];
  721. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  722. //
  723. // NSDictionary* return_json = [RANetwork logout];
  724. //
  725. // dispatch_async(dispatch_get_main_queue(), ^{
  726. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  727. //
  728. //
  729. // if([[return_json valueForKey:@"result"] intValue]==2)
  730. // {
  731. //// [self hideMenu];
  732. //// [self switchToHome:nil];
  733. // [appDelegate Logout];
  734. // [self checklogin :false];
  735. // if(showlogin)
  736. // {
  737. // LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  738. // loginvc.returnValue = ^(bool blogin){
  739. //
  740. // [self checklogin :true];
  741. //
  742. // };
  743. //
  744. // UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  745. //
  746. //
  747. //
  748. //
  749. //
  750. //
  751. // navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  752. // [self presentViewController:navi animated:YES completion:^{
  753. //
  754. // DebugLog(@"login present.........");
  755. //
  756. // }];
  757. // }
  758. // }
  759. // else
  760. // {
  761. // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Sign Out" controller:self] ;
  762. // }
  763. //
  764. //
  765. //
  766. //
  767. // });
  768. // });
  769. }
  770. else
  771. {
  772. LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  773. loginvc.returnValue = ^(bool blogin){
  774. [self checklogin :true];
  775. };
  776. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  777. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  778. [self presentViewController:navi animated:YES completion:^{
  779. DebugLog(@"login present.........");
  780. }];
  781. }
  782. }
  783. - (IBAction)onUserListClick:(id)sender {
  784. UIApplication * app = [UIApplication sharedApplication];
  785. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  786. if(!appDelegate.bLogin)
  787. return;
  788. UserListViewController * vc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"UserListViewController"];
  789. vc.returnValue = ^(bool blogin){
  790. if(blogin==false)
  791. {
  792. LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  793. loginvc.returnValue = ^(bool blogin){
  794. [self checklogin :true];
  795. };
  796. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  797. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  798. [self presentViewController:navi animated:YES completion:^{
  799. DebugLog(@"login present.........");
  800. }];
  801. }
  802. };
  803. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  804. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  805. [self presentViewController:navi animated:YES completion:^{
  806. DebugLog(@"login present.........");
  807. }];
  808. }
  809. - (IBAction)OnLoginClick:(UIButton *)sender {
  810. [self Loginout:true];
  811. }
  812. - (IBAction)onScanClick:(id)sender {
  813. ScannerViewController * scannerVC =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ScannerViewController"];
  814. // LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  815. // ScanOrderScanModelViewController *scanresult = [[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanOrderScanModelViewController"];
  816. ScanOrderModelListViewController* scanresult = [[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanOrderModelListViewController"];
  817. scannerVC.resultvc = scanresult;
  818. [self.navigationController pushViewController:scannerVC animated:true];
  819. }
  820. - (IBAction)switchToSearch:(UIButton *)sender {
  821. [self clearSelected];
  822. self.btnsearch.selected = true;
  823. if([self.current_VC isKindOfClass:[ScanSearchViewController class]])
  824. return;
  825. [self flipFromViewController:self.current_VC toViewController:self.scansearchViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  826. }
  827. //- (IBAction)switchToList:(UIButton *)sender {
  828. // [self switchtowishlist];
  829. //}
  830. - (IBAction)switchToList:(UIButton *)sender {
  831. [self clearSelected];
  832. self.btnlist.selected = true;
  833. [self switchtowishlist];
  834. }
  835. -(void)switchtowishlist
  836. {
  837. if([self.current_VC isKindOfClass:[ScanHistoryViewController class]])
  838. return;
  839. // if([self.current_VC isKindOfClass:[OrderListViewController class]])
  840. // return;
  841. // UIApplication * app = [UIApplication sharedApplication];
  842. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  843. // if(appDelegate.bLogin==false)
  844. // {
  845. // LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  846. // // loginvc.delegate = self;
  847. // // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  848. //
  849. // loginvc.returnValue = ^(bool blogin){
  850. //
  851. //
  852. // if(blogin)
  853. // {
  854. // [self checklogin:true];
  855. //
  856. //
  857. // [self flipFromViewController:self.current_VC toViewController:self.watchListViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  858. // }
  859. //
  860. //
  861. // };
  862. //
  863. // UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  864. //
  865. //
  866. //
  867. //
  868. //
  869. // // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  870. //
  871. // navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  872. // [self presentViewController:navi animated:YES completion:^{
  873. //
  874. // // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  875. //
  876. // DebugLog(@"LoginViewController present.........");
  877. //
  878. // // self.btop = false;
  879. // // <#code#>
  880. // }];
  881. // }
  882. // else
  883. [self flipFromViewController:self.current_VC toViewController:self.scanHistoryViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  884. }
  885. - (IBAction)switchToContact:(UIButton *)sender {
  886. [self switchtocontact];
  887. }
  888. -(void)switchtocontact
  889. {
  890. if([self.current_VC isKindOfClass:[ContactListViewController class]])
  891. return;
  892. UIApplication * app = [UIApplication sharedApplication];
  893. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  894. if(appDelegate.bLogin==false)
  895. {
  896. LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  897. // loginvc.delegate = self;
  898. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  899. loginvc.returnValue = ^(bool blogin){
  900. if(blogin)
  901. {
  902. [self checklogin:true];
  903. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  904. {
  905. [self flipFromViewController:self.current_VC toViewController:self.contactListViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  906. }
  907. else
  908. {
  909. [RAUtils message_alert:@"Customer Login does not support this feature." title:@"Contact List" controller:self] ;
  910. }
  911. }
  912. };
  913. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  914. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  915. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  916. [self presentViewController:navi animated:YES completion:^{
  917. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  918. DebugLog(@"LoginViewController present.........");
  919. // self.btop = false;
  920. // <#code#>
  921. }];
  922. }
  923. else
  924. [self flipFromViewController:self.current_VC toViewController:self.contactListViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  925. }
  926. - (void) reload
  927. {
  928. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  929. return;
  930. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  931. //
  932. //
  933. // NSDictionary* category=[RANetwork request_Cagegory];
  934. //
  935. // dispatch_async(dispatch_get_main_queue(), ^{
  936. //
  937. // if([[category valueForKey:@"result"] intValue]==2)
  938. // {
  939. // appDelegate.categoryMenu = category;
  940. // }
  941. // else
  942. // {
  943. // // [RAUtils error_alert:[category valueForKey:@"err_msg"]] ;
  944. // }
  945. //
  946. // });
  947. // });
  948. }
  949. -(void) scanTempsave
  950. {
  951. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  952. // RASingleton.sharedInstance.scan_temp_code
  953. NSString *orderdir =[OLDataProvider getScanPath];
  954. // appDelegate.order_code = RASingleton.sharedInstance.scan_temp_code;
  955. // [OLDataProvider moveScanTemp2Order];
  956. // NSString *orderdir = [OLDataProvider getScanPath];
  957. NSString* userdir = [OLDataProvider getUserPath];
  958. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  959. // [RAUtils dicttofile:orderPath dict:self.content_data_download];
  960. // NSString* order_code = RASingleton.sharedInstance.scan_temp_code;
  961. //
  962. // int section_count = [self.content_data_download[@"section_count"] intValue];
  963. //
  964. // for(int i=0;i<section_count;i++)
  965. // {
  966. // NSMutableDictionary* section = [self.content_data_download[[NSString stringWithFormat:@"section_%d",i]] mutableCopy];
  967. // NSString* title = section[@"title"];
  968. //
  969. // if([title isEqualToString:@"Customer"])
  970. // {
  971. // // 订单信息会写customer info
  972. //
  973. // int scount = [section[@"count"] intValue];
  974. // for(int j=0;j<scount;j++)
  975. // {
  976. // NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  977. // NSString * name = item[@"name"];
  978. //
  979. //
  980. // if(item[@"value"]!=nil )
  981. // appDelegate.customerInfo[name]=item[@"value"];
  982. //
  983. //
  984. // }
  985. //
  986. //
  987. //
  988. // }
  989. //
  990. // NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  991. //
  992. //
  993. //
  994. // [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  995. // orderdir = [OLDataProvider getScanOrderPath];
  996. NSString *cartpath = [orderdir stringByAppendingPathComponent:@"cart.json"];
  997. RASingleton.sharedInstance.scan_cart[@"price_type"] = @(RASingleton.sharedInstance.price_type);
  998. [RAUtils dicttofile:cartpath dict:RASingleton.sharedInstance.scan_cart];
  999. NSMutableDictionary* orderlist = [OLDataProvider getScanOrderList];
  1000. // NSString *orderlistPath = [userdir stringByAppendingPathComponent:@"orderlist.json"];
  1001. //
  1002. //
  1003. // if (![[NSFileManager defaultManager] fileExistsAtPath:orderlistPath]) {
  1004. //
  1005. //
  1006. // orderlist = [NSMutableDictionary new];
  1007. //
  1008. //// [orderlist addObject:appDelegate.order_code];
  1009. //// [RAUtils dicttofile:orderlistPath dict:orderlist];
  1010. //
  1011. // }
  1012. // else
  1013. // {
  1014. // orderlist=[[RAUtils dictfromfile:orderlistPath] mutableCopy];
  1015. //
  1016. //// [orderlist insertObject:appDelegate.order_code atIndex:0];
  1017. //
  1018. //// [RAUtils dicttofile:orderlistPath dict:orderlist];
  1019. // }
  1020. float p =0;
  1021. float s =0;
  1022. NSDictionary* price_group = [RADataProvider get_price_group:appDelegate.price_group];
  1023. int order_qty=0;
  1024. for(int j=0;j<[RASingleton.sharedInstance.scan_cart[@"section_0"][@"count"] intValue];j++)
  1025. {
  1026. NSDictionary* cartitem =RASingleton.sharedInstance.scan_cart[@"section_0"][[NSString stringWithFormat:@"item_%d",j]];
  1027. p+=[cartitem[@"unit_price"] doubleValue]*[cartitem[@"count"]intValue] * (1-[cartitem[@"discount"]doubleValue]/100.0);
  1028. int mcount = [cartitem[@"count"] intValue];
  1029. order_qty+=mcount;
  1030. double msurcharge =0;
  1031. // remove net price
  1032. // if(RASingleton.sharedInstance.price_type==1)
  1033. // {
  1034. // if([cartitem[@"special_price"] boolValue])
  1035. // {
  1036. // msurcharge=([cartitem[price_group[@"price_3"][@"name"]] doubleValue]-[cartitem[price_group[@"price_2"][@"name"]] doubleValue])*mcount*(1-[cartitem[@"discount"]doubleValue]/100.0);
  1037. // }
  1038. // else
  1039. // {
  1040. // msurcharge=([cartitem[price_group[@"price_3"][@"name"]] doubleValue]-[cartitem[price_group[@"price_1"][@"name"]] doubleValue])*mcount*(1-[cartitem[@"discount"]doubleValue]/100.0);
  1041. // }
  1042. // }
  1043. s+=msurcharge;
  1044. }
  1045. NSMutableDictionary* orderitem = [NSMutableDictionary new];
  1046. orderitem[@"create_by"] = appDelegate.user;
  1047. orderitem[@"price"] = [RAConvertor currencyNumber:p+s];//[NSString stringWithFormat:@"%.2f",p+s];
  1048. orderitem[@"model_count"] =[ NSString stringWithFormat:@"%d",order_qty];
  1049. // orderitem[@"price"] = upparams[@"totalPrice"];
  1050. // NSString*
  1051. orderitem[@"customer_name"] = appDelegate.customerInfo[@"customer_contact"];
  1052. orderitem[@"purchase_time"] = [RAUtils current_date_time];
  1053. orderitem[@"order_status"] = @"Saved Order";
  1054. orderitem[@"order_code"] = appDelegate.order_code;
  1055. NSMutableDictionary* section =RASingleton.sharedInstance.scan_cart[@"section_0"];
  1056. // orderitem[@"model_count"] =[ NSString stringWithFormat:@"%d",order_qty];//RASingleton.sharedInstance.scan_cart[@"section_0"][@"count"] ];
  1057. int count = [orderlist[@"count"] intValue];
  1058. NSMutableDictionary* newlist = [NSMutableDictionary new];
  1059. newlist[@"item_0"]=orderitem;
  1060. int newcount = 1;
  1061. for(int i=0;i<count;i++)
  1062. {
  1063. NSMutableDictionary* item = orderlist[[NSString stringWithFormat:@"item_%d",i]];
  1064. if([item[@"order_code"] isEqualToString: appDelegate.order_code ])
  1065. continue;
  1066. else
  1067. {
  1068. newlist[[NSString stringWithFormat:@"item_%d",newcount]] = item;
  1069. newcount++;
  1070. }
  1071. }
  1072. newlist[@"count"] = @(newcount);
  1073. [OLDataProvider saveScanOrderList:newlist];
  1074. // [RAUtils dicttofile:orderlistPath dict:newlist];
  1075. #ifdef RA_NOTIFICATION
  1076. [ActiveViewController Notify:@"CartViewController,ScanOrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1077. #else
  1078. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1079. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  1080. #endif
  1081. }
  1082. - (IBAction)onUserButtonClick:(id)sender {
  1083. DebugLog(@"header view login");
  1084. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1085. if( appDelegate.user ==nil /*|| [appDelegate.user isEqualToString:@"GUEST"]*/)
  1086. {
  1087. // appDelegate.user = nil;
  1088. // appDelegate.password = nil;
  1089. LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  1090. // loginvc.delegate = self;
  1091. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1092. loginvc.returnValue = ^(bool blogin){
  1093. [self checklogin:true];
  1094. };
  1095. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  1096. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1097. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1098. [self presentViewController:navi animated:YES completion:^{
  1099. // <#code#>
  1100. }];
  1101. }
  1102. else
  1103. {
  1104. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Sign Out" message:@"" preferredStyle:UIAlertControllerStyleAlert];
  1105. UIAlertAction *action_1 = [UIAlertAction actionWithTitle:@"Sign Out" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  1106. //open exist
  1107. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1108. // int cc=[RASingleton.sharedInstance.scan_cart[@"section_0"][@"count"] intValue];
  1109. bool issaved = [OLDataProvider isSavedScanOrder:appDelegate.order_code];
  1110. if(/*appDelegate.order_code == nil*/!issaved && [RASingleton.sharedInstance.scan_cart[@"section_0"][@"count"] intValue]>0)
  1111. {
  1112. UIAlertController *alertController1 = [UIAlertController alertControllerWithTitle:@"Save Cart?" message:@"" preferredStyle:UIAlertControllerStyleAlert];
  1113. UIAlertAction *action_1 = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  1114. [self scanTempsave];
  1115. [OLDataProvider scanCloseOrder];
  1116. [appDelegate Logout];
  1117. // appDelegate.cart_count = 0;//[[jsobj :@"cart_count"] intValue];
  1118. // appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  1119. // appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  1120. //
  1121. // [appDelegate update_count_mark];
  1122. //
  1123. //
  1124. // appDelegate.can_show_price =false;
  1125. // appDelegate.can_see_price =false;
  1126. // appDelegate.can_create_portfolio =false;
  1127. // appDelegate.can_create_order =false;
  1128. //
  1129. //
  1130. // appDelegate.can_cancel_order =false;
  1131. // appDelegate.can_set_cart_price =false;
  1132. // appDelegate.can_delete_order =false;
  1133. // appDelegate.can_submit_order =false;
  1134. // appDelegate.can_set_tearsheet_price =false;
  1135. // appDelegate.can_update_contact_info = false;
  1136. //
  1137. // appDelegate.save_order_logout = false;
  1138. // appDelegate.submit_order_logout = false;
  1139. // appDelegate.alert_sold_in_quantities = false;
  1140. //
  1141. // appDelegate.ipad_perm =nil ;
  1142. // appDelegate.user_type = USER_ROLE_UNKNOWN;
  1143. // appDelegate.OrderFilter= nil;
  1144. // [appDelegate SetSo:nil];
  1145. // [appDelegate set_main_button_panel];
  1146. #ifdef RA_NOTIFICATION
  1147. [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
  1148. #endif
  1149. // [appDelegate Logout];
  1150. }];
  1151. UIAlertAction *action_2 = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  1152. //create new;
  1153. [OLDataProvider scanCloseOrder];
  1154. [appDelegate Logout];
  1155. // appDelegate.cart_count = 0;//[[jsobj :@"cart_count"] intValue];
  1156. // appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  1157. // appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  1158. //
  1159. // [appDelegate update_count_mark];
  1160. //
  1161. //
  1162. // appDelegate.can_show_price =false;
  1163. // appDelegate.can_see_price =false;
  1164. // appDelegate.can_create_portfolio =false;
  1165. // appDelegate.can_create_order =false;
  1166. //
  1167. //
  1168. // appDelegate.can_cancel_order =false;
  1169. // appDelegate.can_set_cart_price =false;
  1170. // appDelegate.can_delete_order =false;
  1171. // appDelegate.can_submit_order =false;
  1172. // appDelegate.can_set_tearsheet_price =false;
  1173. // appDelegate.can_update_contact_info = false;
  1174. //
  1175. // appDelegate.save_order_logout = false;
  1176. // appDelegate.submit_order_logout = false;
  1177. // appDelegate.alert_sold_in_quantities = false;
  1178. //
  1179. // appDelegate.ipad_perm =nil ;
  1180. // appDelegate.user_type = USER_ROLE_UNKNOWN;
  1181. // appDelegate.OrderFilter= nil;
  1182. // [appDelegate SetSo:nil];
  1183. // [appDelegate set_main_button_panel];
  1184. #ifdef RA_NOTIFICATION
  1185. [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
  1186. #endif
  1187. // [appDelegate Logout];
  1188. }];
  1189. [alertController1 addAction:action_1];
  1190. [alertController1 addAction:action_2];
  1191. [self presentViewController:alertController1 animated:YES completion:nil];
  1192. return;
  1193. }
  1194. [OLDataProvider scanCloseOrder];
  1195. [appDelegate Logout];
  1196. // appDelegate.cart_count = 0;//[[jsobj :@"cart_count"] intValue];
  1197. // appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  1198. // appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  1199. //
  1200. // [appDelegate update_count_mark];
  1201. //
  1202. //
  1203. // appDelegate.can_show_price =false;
  1204. // appDelegate.can_see_price =false;
  1205. // appDelegate.can_create_portfolio =false;
  1206. // appDelegate.can_create_order =false;
  1207. //
  1208. //
  1209. // appDelegate.can_cancel_order =false;
  1210. // appDelegate.can_set_cart_price =false;
  1211. // appDelegate.can_delete_order =false;
  1212. // appDelegate.can_submit_order =false;
  1213. // appDelegate.can_set_tearsheet_price =false;
  1214. // appDelegate.can_update_contact_info = false;
  1215. //
  1216. // appDelegate.save_order_logout = false;
  1217. // appDelegate.submit_order_logout = false;
  1218. // appDelegate.alert_sold_in_quantities = false;
  1219. //
  1220. // appDelegate.ipad_perm =nil ;
  1221. // appDelegate.user_type = USER_ROLE_UNKNOWN;
  1222. // appDelegate.OrderFilter= nil;
  1223. // [appDelegate SetSo:nil];
  1224. //
  1225. // [appDelegate set_main_button_panel];
  1226. #ifdef RA_NOTIFICATION
  1227. [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
  1228. #endif
  1229. // [appDelegate Logout];
  1230. }];
  1231. UIAlertAction *action_2 = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  1232. //create new;
  1233. }];
  1234. [alertController addAction:action_1];
  1235. [alertController addAction:action_2];
  1236. [self presentViewController:alertController animated:YES completion:nil];
  1237. }
  1238. }
  1239. #pragma mark - LoginViewControllerDelegate
  1240. -(void)LoginViewControllerDidLogin:(LoginViewController *)viewController
  1241. {
  1242. [viewController dismissViewControllerAnimated:YES completion:^{
  1243. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1244. self.sideMenu_UserName.text =appDelegate.user;
  1245. [self.btn_sideMenu_UserName setTitle:appDelegate.user forState:UIControlStateNormal];
  1246. [self.btnLogin setTitle:@"Sign out" forState:UIControlStateNormal];
  1247. [RANetwork LoadImage:appDelegate.user_icon into:self.user_head ];
  1248. // if(/*appDelegate.user_type==USER_ROLE_EMPLOYEE*/true)
  1249. // self.btnContact.hidden = NO;
  1250. // else
  1251. // self.btnContact.hidden = YES;
  1252. NSDictionary * customerinfo=appDelegate.customerInfo;
  1253. NSString * contact=nil;
  1254. NSString * customer=nil;
  1255. if(customerinfo==nil)
  1256. {
  1257. contact=@"Select Contact";
  1258. [self.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  1259. }
  1260. else
  1261. {
  1262. contact=[customerinfo valueForKey:@"customer_contact"];
  1263. customer=[customerinfo valueForKey:@"customer_name"];
  1264. if(contact==nil||contact.length==0)
  1265. {
  1266. contact=@"No Name";
  1267. [self.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  1268. }
  1269. else
  1270. {
  1271. [self.btnContact setTitleColor:UIColorFromRGB(0x009900) forState:UIControlStateNormal];
  1272. }
  1273. }
  1274. NSMutableArray* arr_contact = [[NSMutableArray alloc] init];
  1275. if(contact.length>0)
  1276. [arr_contact addObject:contact];
  1277. if(customer.length>0)
  1278. [arr_contact addObject:customer];
  1279. NSString *contact_string = [arr_contact componentsJoinedByString:@" @"];
  1280. [self.btnContact setTitle:contact_string forState:UIControlStateNormal];
  1281. // [self.buttonUser setTitle:appDelegate.user forState:UIControlStateNormal];
  1282. [self reload];
  1283. }];
  1284. }
  1285. - (void) flipFromViewController:(UIViewController*) fromController
  1286. toViewController:(UIViewController*) toController
  1287. withDirection:(UIViewAnimationOptions) direction
  1288. {
  1289. toController.view.frame = self.container.bounds; // 1
  1290. // UIViewAutoresizingFlexibleLeftMargin = 1 << 0,
  1291. // UIViewAutoresizingFlexibleWidth = 1 << 1,
  1292. // UIViewAutoresizingFlexibleRightMargin = 1 << 2,
  1293. // UIViewAutoresizingFlexibleTopMargin = 1 << 3,
  1294. // UIViewAutoresizingFlexibleHeight = 1 << 4,
  1295. // UIViewAutoresizingFlexibleBottomMargin = 1 << 5
  1296. toController.view.autoresizingMask = UIViewAutoresizingFlexibleHeight |UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin;
  1297. NSLog(@"MAIN VIEWCONTROLLER CHILD COUNT %lu",(unsigned long)self.childViewControllers.count);
  1298. [self addChildViewController:toController]; //
  1299. [fromController willMoveToParentViewController:nil]; //
  1300. [self transitionFromViewController:fromController
  1301. toViewController:toController
  1302. duration:0.0
  1303. options:direction | UIViewAnimationOptionCurveEaseIn
  1304. animations:nil
  1305. completion:^(BOOL finished) {
  1306. [toController didMoveToParentViewController:self]; // 2
  1307. [fromController removeFromParentViewController]; // 3
  1308. self.current_VC = toController;
  1309. // if([fromController isKindOfClass:[HomeViewController class]])
  1310. // {
  1311. // // [[NSNotificationCenter defaultCenter] postNotificationName:CYCLESCROLL_STOPTIMMER object:nil];
  1312. // // self.homeViewController = nil;
  1313. //
  1314. // }
  1315. }];
  1316. }
  1317. -(void)topicViewSelected:(int) type _id: (int) _id
  1318. {
  1319. // [self switchToCagegory:nil];
  1320. // if(type==0)
  1321. // {
  1322. // // [self.categoryViewController showDetailat:_id];
  1323. // }
  1324. // else
  1325. // {
  1326. // [self.categoryViewController showCategory];
  1327. //
  1328. // }
  1329. }
  1330. -(void)categoryMenuSelected:(NSString*)_id
  1331. {
  1332. [self switchToCagegory:_id];
  1333. // [self.categoryViewController showCategory];
  1334. }
  1335. //- (void)switchToItemSearch:(NSString* )coverttype {
  1336. //
  1337. //
  1338. // self.itemSearchViewController.default_filter = nil;
  1339. // self.itemSearchViewController.covertype = coverttype;
  1340. // self.itemSearchViewController.saved_covertype = coverttype;
  1341. //
  1342. //
  1343. //
  1344. // self.itemSearchViewController.p_available = nil;
  1345. // self.itemSearchViewController.p_price = nil;
  1346. // self.itemSearchViewController.p_QTY = nil;
  1347. // self.itemSearchViewController.p_bestseller = nil;
  1348. //#ifdef RA_NOTIFICATION
  1349. // [ActiveViewController Notify:@"ItemSearchViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1350. //#else
  1351. // [self.itemSearchViewController reload_container_getdata:true];
  1352. //#endif
  1353. //
  1354. // if([self.current_VC isKindOfClass:[ItemSearchViewController class]])
  1355. //
  1356. // return;
  1357. // [self flipFromViewController:self.current_VC toViewController:self.itemSearchViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1358. //
  1359. // [[self navigationController] setNavigationBarHidden:YES animated:NO];
  1360. //
  1361. //
  1362. // // self.is_home = false;
  1363. // // self.current_vc = VC_CATEGORY;
  1364. // // [self.homeViewController willMoveToParentViewController:nil]; //1
  1365. // // [self.homeViewController.view removeFromSuperview]; //2
  1366. // // [self.homeViewController removeFromParentViewController]; //3
  1367. // //
  1368. // // [self.container addSubview:self.cagegoryViewController.view]; //2
  1369. // // [self.cagegoryViewController didMoveToParentViewController:self];
  1370. //}
  1371. //- (void)switchToCagegory:(NSString* )categoryid {
  1372. // // NSString* ttt =[@"Category" stringByAppendingString:[self categoryString:categoryid node:self.categoryMenu level:0]];
  1373. //
  1374. //
  1375. // UIApplication * app = [UIApplication sharedApplication];
  1376. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1377. // #if defined(BUILD_UWAVER)
  1378. // self.categoryViewController.categoryString = [@"Collections" stringByAppendingString:[self categoryString:categoryid node:appDelegate.categoryMenu level:0]];
  1379. //#else
  1380. // self.categoryViewController.categoryString = [@"Category" stringByAppendingString:[self categoryString:categoryid node:appDelegate.categoryMenu level:0]];
  1381. //#endif
  1382. //
  1383. // self.categoryViewController.cagegoryLabel.text =self.categoryViewController.categoryString;
  1384. // self.categoryViewController.categoryid = categoryid ;
  1385. // self.categoryViewController.loadall=false;
  1386. //// self.categoryViewController.collectionview
  1387. // self.categoryViewController.p_alert = nil;
  1388. // self.categoryViewController.p_available = nil;
  1389. // self.categoryViewController.p_price = nil;
  1390. // self.categoryViewController.p_QTY = nil;
  1391. // self.categoryViewController.p_bestseller = nil;
  1392. //
  1393. // self.categoryViewController.modelname = nil;
  1394. // self.categoryViewController.modeldescrip = nil;
  1395. //#ifdef RA_NOTIFICATION
  1396. // [ActiveViewController Notify:@"CategoryViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1397. //#else
  1398. // [self.categoryViewController reload_container_getdata:true];
  1399. //#endif
  1400. //
  1401. // [self.categoryViewController showCategory];
  1402. // if([self.current_VC isKindOfClass:[CategoryViewController class]])
  1403. //
  1404. // return;
  1405. // [self flipFromViewController:self.current_VC toViewController:self.categoryViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1406. //
  1407. // [[self navigationController] setNavigationBarHidden:YES animated:NO];
  1408. //
  1409. //
  1410. // // self.is_home = false;
  1411. // // self.current_vc = VC_CATEGORY;
  1412. // // [self.homeViewController willMoveToParentViewController:nil]; //1
  1413. // // [self.homeViewController.view removeFromSuperview]; //2
  1414. // // [self.homeViewController removeFromParentViewController]; //3
  1415. // //
  1416. // // [self.container addSubview:self.cagegoryViewController.view]; //2
  1417. // // [self.cagegoryViewController didMoveToParentViewController:self];
  1418. //}
  1419. - (IBAction)switchToHome:(UIButton *)sender {
  1420. [self clearSelected];
  1421. [self switchToHome];
  1422. // self.current_vc = VC_HOME;
  1423. // self.is_home = true;
  1424. //
  1425. // [self.cagegoryViewController willMoveToParentViewController:nil]; //1
  1426. // [self.cagegoryViewController.view removeFromSuperview]; //2
  1427. // [self.cagegoryViewController removeFromParentViewController]; //3
  1428. //
  1429. // [self.container addSubview:self.homeViewController.view]; //2
  1430. // [self.homeViewController didMoveToParentViewController:self];
  1431. }
  1432. -(void)switchToHome
  1433. {
  1434. [self clearSelected];
  1435. if([self.current_VC isKindOfClass:[ScanHomeViewController class]])
  1436. return;
  1437. if(self.homeViewController == nil)
  1438. {
  1439. self.homeViewController =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanHomeViewController"];
  1440. self.homeViewController.view.frame = self.container.bounds;
  1441. }
  1442. [self flipFromViewController:self.current_VC toViewController:self.homeViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1443. }
  1444. -(void) switchToPreviousVC
  1445. {
  1446. if(self.previous_VC==nil)
  1447. return;
  1448. if([self.current_VC isKindOfClass:[self.previous_VC class]])
  1449. return;
  1450. [self flipFromViewController:self.current_VC toViewController:self.previous_VC withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1451. }
  1452. - (IBAction)switchToCart:(UIButton *)sender {
  1453. // [self.btncart setBackgroundColor:UIColor.whiteColor];
  1454. // [self.btncart setTintColor:UIColor.clearColor];
  1455. // UIColor *color0=[self.btncart titleColorForState:UIControlStateNormal];
  1456. // UIColor *color1=[self.btncart titleColorForState:UIControlStateSelected];
  1457. [self switchToCart];
  1458. // self.current_vc = VC_HOME;
  1459. }
  1460. -(void) switchToCart
  1461. {
  1462. if([self.current_VC isKindOfClass:[CartViewController class]])
  1463. return;
  1464. [self clearSelected];
  1465. self.btncart.selected = true;
  1466. //
  1467. //
  1468. // UIApplication * app = [UIApplication sharedApplication];
  1469. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1470. // // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  1471. // if(appDelegate.bLogin==false&& !RASingleton.sharedInstance.enable_OfflineOrder)
  1472. // {
  1473. //
  1474. // LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  1475. // // loginvc.delegate = self;
  1476. // // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1477. //
  1478. // loginvc.returnValue = ^(bool blogin){
  1479. //
  1480. //
  1481. // // UIApplication * app = [UIApplication sharedApplication];
  1482. // // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1483. //
  1484. //
  1485. //
  1486. //
  1487. // if(blogin)
  1488. // {
  1489. // if(/*appDelegate.user_type==USER_ROLE_EMPLOYEE*/true)
  1490. // {
  1491. //
  1492. // [self checklogin:false];
  1493. // if(appDelegate.can_create_order)
  1494. // {
  1495. //
  1496. // NSString* msg =@"";
  1497. // if(appDelegate.contact_id.length>0)
  1498. // {
  1499. // msg = [msg stringByAppendingString:@"\n\nCustomer:"];
  1500. // msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
  1501. //
  1502. // }
  1503. //
  1504. // UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Switch To Cart" message:msg preferredStyle:UIAlertControllerStyleAlert];
  1505. //
  1506. // UIAlertAction *action_1 = [UIAlertAction actionWithTitle:@"Check for saved order" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  1507. // //open exist
  1508. //
  1509. // ScanOrderListViewController* ovc =[ [UIStoryboard storyboardWithName:@"ERP_Mobile_Order" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanOrderListViewController"];
  1510. // ovc.showNavibar = true;
  1511. // ovc.selectOrder = ^(NSMutableDictionary* order_detail){
  1512. // if(appDelegate.order_code==nil)
  1513. // {
  1514. // [self neworderforCart];
  1515. // }
  1516. // else
  1517. // {
  1518. // self.previous_VC = self.current_VC;
  1519. // [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1520. //
  1521. // [self checklogin:true];
  1522. //
  1523. // }
  1524. //
  1525. // };
  1526. //// ovc.init_style = OL_OPEN;
  1527. // ovc.onCancel = ^(){
  1528. //
  1529. // [self checklogin:true];
  1530. //
  1531. // };
  1532. // ovc.title = @"SAVED ORDER";
  1533. // [self.navigationController pushViewController:ovc animated:true];
  1534. // }];
  1535. // UIAlertAction *action_2 = [UIAlertAction actionWithTitle:@"Create new order" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1536. // //create new;
  1537. //
  1538. // if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  1539. // {
  1540. //
  1541. // ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  1542. // cvc.showNavibar = true;
  1543. // cvc.contact_type = @"Sales_Order_Customer";
  1544. // cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1545. //
  1546. // appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  1547. // appDelegate.customerInfo = value;
  1548. //
  1549. //
  1550. // if(appDelegate.order_code==nil)
  1551. // [self neworderforCart];
  1552. //
  1553. //
  1554. // };
  1555. //
  1556. // cvc.onCancel = ^(){
  1557. //
  1558. // [RAUtils message_alert:@"Cannot create order without customer infomation." title:@"" controller:self];
  1559. //
  1560. //
  1561. //
  1562. // };
  1563. // cvc.onReset = ^(){
  1564. // [self checklogin:true];
  1565. // };
  1566. //
  1567. // [self.navigationController pushViewController:cvc animated:true];
  1568. // }
  1569. // else
  1570. // {
  1571. // [self neworderforCart];
  1572. // }
  1573. //
  1574. // }];
  1575. // UIAlertAction *action_3 = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  1576. //
  1577. //
  1578. //
  1579. // }];
  1580. //
  1581. // [alertController addAction:action_1];
  1582. // [alertController addAction:action_2];
  1583. // [alertController addAction:action_3];
  1584. //
  1585. //
  1586. // [self presentViewController:alertController animated:YES completion:nil];
  1587. //// 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];
  1588. ////
  1589. ////
  1590. ////
  1591. //// // alert.
  1592. //// [alert show];
  1593. // }
  1594. // else
  1595. // {
  1596. //
  1597. // UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Switch To Cart" message:@"Do you want to switch to a pending order?" preferredStyle:UIAlertControllerStyleAlert];
  1598. //
  1599. //
  1600. // UIAlertAction *action_2 = [UIAlertAction actionWithTitle:@"Check for saved order" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1601. // //open exist
  1602. //
  1603. // ScanOrderListViewController* ovc =[ [UIStoryboard storyboardWithName:@"ERP_Mobile_Order" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanOrderListViewController"];
  1604. // ovc.showNavibar = true;
  1605. // ovc.selectOrder = ^(NSMutableDictionary* order_detail){
  1606. // if(appDelegate.order_code==nil)
  1607. // {
  1608. // [self neworderforCart];
  1609. // }
  1610. // else
  1611. // {
  1612. // self.previous_VC = self.current_VC;
  1613. // [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1614. //
  1615. // [self checklogin:true];
  1616. //
  1617. // }
  1618. //
  1619. // };
  1620. //// ovc.init_style = OL_OPEN;
  1621. // ovc.onCancel = ^(){
  1622. //
  1623. // [self checklogin:true];
  1624. //
  1625. // };
  1626. // ovc.title = @"SAVED ORDER";
  1627. // [self.navigationController pushViewController:ovc animated:true];
  1628. // }];
  1629. // UIAlertAction *action_3 = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  1630. //
  1631. //
  1632. //
  1633. // }];
  1634. //
  1635. //
  1636. // [alertController addAction:action_2];
  1637. // [alertController addAction:action_3];
  1638. //
  1639. //
  1640. // [self presentViewController:alertController animated:YES completion:nil];
  1641. //
  1642. //
  1643. //// 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];
  1644. ////
  1645. //// // alert.
  1646. //// [alert show];
  1647. // }
  1648. // }
  1649. //// else
  1650. //// {
  1651. //// [self checklogin:true];
  1652. //// self.previous_VC = self.current_VC;
  1653. //// [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1654. //// }
  1655. // }
  1656. //
  1657. // // self.offset = 0;
  1658. // // [self.content_data removeAllObjects];
  1659. // // [self loadpage];
  1660. // //
  1661. // // [[self navigationController] setNavigationBarHidden:YES animated:NO];
  1662. //
  1663. // };
  1664. //
  1665. // UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  1666. //
  1667. //
  1668. //
  1669. //
  1670. //
  1671. // // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1672. //
  1673. // navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  1674. // [self presentViewController:navi animated:YES completion:^{
  1675. //
  1676. // // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1677. //
  1678. // DebugLog(@"LoginViewController present.........");
  1679. //
  1680. // // self.btop = false;
  1681. // // <#code#>
  1682. // }];
  1683. // }
  1684. // else
  1685. // {
  1686. //// if(/*appDelegate.user_type==USER_ROLE_EMPLOYEE&&/*appDelegate.contact_id==nil&&*/appDelegate.order_code==nil)
  1687. // if(appDelegate.order_code==nil)
  1688. // {
  1689. //// [self checklogin:false];
  1690. // if(appDelegate.can_create_order)
  1691. // {
  1692. // NSString* msg =@"";
  1693. // if(appDelegate.contact_id.length>0)
  1694. // {
  1695. // msg = [msg stringByAppendingString:@"\n\nCustomer:"];
  1696. // msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
  1697. //
  1698. // }
  1699. //
  1700. // UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Switch To Cart" message:msg preferredStyle:UIAlertControllerStyleAlert];
  1701. //
  1702. // UIAlertAction *action_1 = [UIAlertAction actionWithTitle:@"Check for saved order" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  1703. // //open exist
  1704. //
  1705. // ScanOrderListViewController* ovc =[ [UIStoryboard storyboardWithName:@"ERP_Mobile_Order" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanOrderListViewController"];
  1706. // ovc.showNavibar = true;
  1707. // ovc.selectOrder = ^(NSMutableDictionary* order_detail){
  1708. // if(appDelegate.order_code==nil)
  1709. // {
  1710. // [self neworderforCart];
  1711. // }
  1712. // else
  1713. // {
  1714. // self.previous_VC = self.current_VC;
  1715. // [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1716. //
  1717. // [self checklogin:true];
  1718. //
  1719. // }
  1720. //
  1721. // };
  1722. //// ovc.init_style = OL_OPEN;
  1723. // ovc.onCancel = ^(){
  1724. //
  1725. // [self checklogin:true];
  1726. //
  1727. // };
  1728. // ovc.title = @"SAVED ORDER";
  1729. // [self.navigationController pushViewController:ovc animated:true];
  1730. // }];
  1731. // UIAlertAction *action_2 = [UIAlertAction actionWithTitle:@"Create new order" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1732. // //create new;
  1733. //
  1734. // if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  1735. // {
  1736. //
  1737. // ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  1738. // cvc.showNavibar = true;
  1739. // cvc.contact_type = @"Sales_Order_Customer";
  1740. // cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1741. //
  1742. // appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  1743. // appDelegate.customerInfo = value;
  1744. //
  1745. //
  1746. // if(appDelegate.order_code==nil)
  1747. // [self neworderforCart];
  1748. //
  1749. //
  1750. // };
  1751. //
  1752. // cvc.onCancel = ^(){
  1753. //
  1754. // [RAUtils message_alert:@"Cannot create order without customer infomation." title:@"" controller:self];
  1755. //
  1756. //
  1757. //
  1758. // };
  1759. // cvc.onReset = ^(){
  1760. // [self checklogin:true];
  1761. // };
  1762. //
  1763. // [self.navigationController pushViewController:cvc animated:true];
  1764. // }
  1765. // else
  1766. // {
  1767. // [self neworderforCart];
  1768. // }
  1769. //
  1770. // }];
  1771. // UIAlertAction *action_3 = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  1772. //
  1773. //
  1774. //
  1775. // }];
  1776. //
  1777. // [alertController addAction:action_1];
  1778. // [alertController addAction:action_2];
  1779. // [alertController addAction:action_3];
  1780. //
  1781. //
  1782. // [self presentViewController:alertController animated:YES completion:nil];
  1783. //
  1784. //
  1785. //// 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];
  1786. ////
  1787. //// // alert.
  1788. //// [alert show];
  1789. // }
  1790. // else
  1791. // {
  1792. // UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Switch To Cart" message:@"Do you want to switch to a pending order?" preferredStyle:UIAlertControllerStyleAlert];
  1793. //
  1794. //
  1795. // UIAlertAction *action_2 = [UIAlertAction actionWithTitle:@"Switch to pending order" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1796. // //open exist
  1797. //
  1798. // ScanOrderListViewController* ovc =[ [UIStoryboard storyboardWithName:@"ERP_Mobile_Order" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanOrderListViewController"];
  1799. // ovc.showNavibar = true;
  1800. // ovc.selectOrder = ^(NSMutableDictionary* order_detail){
  1801. // if(appDelegate.order_code==nil)
  1802. // {
  1803. // [self neworderforCart];
  1804. // }
  1805. // else
  1806. // {
  1807. // self.previous_VC = self.current_VC;
  1808. // [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1809. //
  1810. // [self checklogin:true];
  1811. //
  1812. // }
  1813. //
  1814. // };
  1815. //// ovc.init_style = OL_OPEN;
  1816. // ovc.onCancel = ^(){
  1817. //
  1818. // [self checklogin:true];
  1819. //
  1820. // };
  1821. // ovc.title = @"SAVED ORDER";
  1822. // [self.navigationController pushViewController:ovc animated:true];
  1823. // }];
  1824. // UIAlertAction *action_3 = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  1825. //
  1826. //
  1827. //
  1828. // }];
  1829. //
  1830. //
  1831. // [alertController addAction:action_2];
  1832. // [alertController addAction:action_3];
  1833. //
  1834. //
  1835. // [self presentViewController:alertController animated:YES completion:nil];
  1836. //
  1837. //// 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];
  1838. ////
  1839. //// // alert.
  1840. //// [alert show];
  1841. // }
  1842. // }
  1843. // else
  1844. // {
  1845. //
  1846. // self.previous_VC = self.current_VC;
  1847. // [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1848. //
  1849. //
  1850. //
  1851. // }
  1852. // }
  1853. //
  1854. self.previous_VC = self.current_VC;
  1855. [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1856. }
  1857. -(void) switchToOrder
  1858. {
  1859. [self clearSelected];
  1860. self.btnorder.selected = true;
  1861. if([self.current_VC isKindOfClass:[ScanOrderListViewController class]])
  1862. return;
  1863. UIApplication * app = [UIApplication sharedApplication];
  1864. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1865. [self flipFromViewController:self.current_VC toViewController:self.scanorderViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1866. }
  1867. - (IBAction)switchToOrder:(id)sender {
  1868. [self switchToOrder];
  1869. }
  1870. #pragma mark - CategoryMenuDelegate
  1871. -(void)SelectCategory:(NSString *)category
  1872. {
  1873. [self switchToCagegory:category];
  1874. }
  1875. -(NSString*) categoryString:(NSString*) categoryid node:(NSDictionary*) json level:(int) level;
  1876. {
  1877. if(categoryid.length==0)
  1878. return @">All Products>";
  1879. //NSString* idString = [NSString stringWithFormat:@"%d",categoryid];
  1880. NSString* categoryString =@">";
  1881. int count = [[json valueForKey:@"count"] intValue];
  1882. for(int i=0;i<count;i++)
  1883. {
  1884. NSDictionary * category_json = [json objectForKey:[NSString stringWithFormat:@"category_%d",i]];
  1885. NSString* cid = [category_json valueForKey:@"id"] ;
  1886. // NSString* ttt =[categoryid substringToIndex:2+level*2];
  1887. // NSString * qqq =[cid substringToIndex:2+level*2];
  1888. // NSString *ds1=[categoryid substringToIndex:3+level*3];
  1889. // NSString*ds2 = [cid substringToIndex:3+level*3];
  1890. if(cid.length<3+level*3)
  1891. continue;
  1892. if(categoryid.length<3+level*3)
  1893. continue;
  1894. if([[categoryid substringToIndex:3+level*3] isEqualToString: [cid substringToIndex:3+level*3]])
  1895. {
  1896. //categoryString = [categoryString stringByAppendingString:@">"];
  1897. categoryString =[categoryString stringByAppendingString: [category_json valueForKey:@"title" ] ];
  1898. categoryString = [categoryString stringByAppendingString:[ self categoryString:categoryid node:category_json level:level+1]];
  1899. break;
  1900. }
  1901. }
  1902. return categoryString;
  1903. }
  1904. - (void)didReceiveMemoryWarning
  1905. {
  1906. [super didReceiveMemoryWarning];
  1907. // Dispose of any resources that can be recreated.
  1908. }
  1909. - (IBAction)openMenu:(UIButton *)sender {
  1910. [self showMenu];
  1911. }
  1912. - (UIImage*)screen_shot
  1913. {
  1914. // CGRect r = self.view.frame;
  1915. // CGRect r1 = self.view.bounds;
  1916. // double width,height;
  1917. //
  1918. // UIInterfaceOrientation orientation =[UIApplication sharedApplication].statusBarOrientation;
  1919. // ;
  1920. // if(orientation == UIDeviceOrientationLandscapeLeft ||orientation == UIDeviceOrientationLandscapeRight)
  1921. // {
  1922. // width = self.view.frame.size.width>self.view.frame.size.height? self.view.frame.size.width:self.view.frame.size.height;
  1923. // height =self.view.frame.size.width<self.view.frame.size.height? self.view.frame.size.width:self.view.frame.size.height;
  1924. // }
  1925. // else
  1926. // {
  1927. // width = self.view.frame.size.width<self.view.frame.size.height? self.view.frame.size.width:self.view.frame.size.height;
  1928. // height =self.view.frame.size.width>self.view.frame.size.height? self.view.frame.size.width:self.view.frame.size.height;
  1929. // }
  1930. UIGraphicsBeginImageContext(CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height));
  1931. [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
  1932. UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
  1933. UIGraphicsEndImageContext();
  1934. return viewImage;
  1935. }
  1936. - (IBAction)onhideMenuClick:(id)sender {
  1937. [self hideMenu];
  1938. self.backgroundButton.hidden=true;
  1939. self.openMenuButton.hidden = false;
  1940. self.sideMenu.hidden = true;
  1941. }
  1942. - (void)hideMenu
  1943. {
  1944. CGRect frame ;
  1945. frame.origin.x = -300;
  1946. frame.origin.y = 0;
  1947. frame.size.height = self.view.bounds.size.height;
  1948. frame.size.width = 364;
  1949. self.sideMenu.frame=frame;
  1950. self.sideMenu.hidden = true;
  1951. self.blurView.alpha = 0;
  1952. [self.menuButton setImage:[UIImage imageNamed:@"menu_open"] forState:UIControlStateNormal];
  1953. self.menuShown = false;
  1954. self.backgroundButton.hidden=true;
  1955. self.openMenuButton.hidden = false;
  1956. }
  1957. - (void)showMenu
  1958. {
  1959. [self.sideMenuTable reloadData];
  1960. UIImage* imgsource = [self screen_shot];
  1961. self.blurView.alpha = 0;
  1962. UIImage* imgBlur =[self applyBlurWithRadius:5 sourceImage:imgsource tintColor:[UIColor colorWithWhite:0.2 alpha:0.73] saturationDeltaFactor:1.8 maskImage:nil];
  1963. self.blurView.image = imgBlur;
  1964. // self.blurView.hidden = imgBlur;
  1965. // [self.sideMenu becomeFirstResponder];
  1966. self.sideMenu.hidden = false;
  1967. self.backgroundButton.hidden=false;
  1968. CGRect frame ;
  1969. frame.origin.x = 0;
  1970. frame.origin.y = 0;
  1971. frame.size.height = self.view.bounds.size.height;
  1972. frame.size.width = 364;
  1973. // [UIView animateWithDuration:1.0 animations:^{ self.sideMenu.frame=frame;
  1974. // self.blurView.alpha = 1;
  1975. // [self.menuButton setImage:[UIImage imageNamed:@"menu"] forState:UIControlStateNormal];
  1976. //
  1977. // }];
  1978. [UIView animateWithDuration:0.5 animations:^{ self.sideMenu.frame=frame;
  1979. self.blurView.alpha = 1;
  1980. }
  1981. completion:^(BOOL finished) {
  1982. [self.menuButton setImage:[UIImage imageNamed:@"menu"] forState:UIControlStateNormal];
  1983. }];
  1984. // UIImage* img= [UIImage imageNamed:@"menu"];
  1985. // self.menuButton.imageView.image = nil;
  1986. self.menuShown = true;
  1987. }
  1988. -(void)initMenuItems
  1989. {
  1990. UIApplication * app = [UIApplication sharedApplication];
  1991. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1992. self.sideMenuItems = [[NSMutableArray alloc] init];
  1993. NSMutableDictionary* map = [[NSMutableDictionary alloc] init];
  1994. if(appDelegate.user!=nil)
  1995. {
  1996. [map setValue:@"Wish List" forKey:@"title"];
  1997. [map setValue:@"rect_market_news" forKey:@"img"];
  1998. [self.sideMenuItems addObject:map.copy];
  1999. }
  2000. #if !defined(BUILD_HOMER) && !defined(BUILD_GATIT)
  2001. //#ifndef BUILD_HOMER //homer 要求去掉cam scan 2017/12/20
  2002. // if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  2003. {
  2004. [map setValue:@"Cam Scan" forKey:@"title"];
  2005. [map setValue:@"rect_contact_list" forKey:@"img"];
  2006. [self.sideMenuItems addObject:map.copy];
  2007. }
  2008. #endif
  2009. if(appDelegate.user_type==USER_ROLE_EMPLOYEE || (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeCustomer))
  2010. {
  2011. // [map setValue:@"Contact" forKey:@"title"];
  2012. // [map setValue:@"rect_contact_list" forKey:@"img"];
  2013. // [self.sideMenuItems addObject:map.copy];
  2014. //#ifdef BUILD_UWAVER
  2015. // [map setValue:@"Hang Tag" forKey:@"title"];
  2016. //#else
  2017. [map setValue:@"Portfolio" forKey:@"title"];
  2018. //#endif
  2019. [map setValue:@"rect_market_news" forKey:@"img"];
  2020. [self.sideMenuItems addObject:map.copy];
  2021. //#ifdef BUILD_UWAVER
  2022. // [map setValue:@"View Hang Tags" forKey:@"title"];
  2023. //#else
  2024. [map setValue:@"View Portfolios" forKey:@"title"];
  2025. //#endif
  2026. [map setValue:@"rect_pdf_list" forKey:@"img"];
  2027. [self.sideMenuItems addObject:map.copy];
  2028. }
  2029. if(appDelegate.can_show_price)
  2030. {
  2031. if(appDelegate.price_hidden)
  2032. [map setValue:@"Show Price" forKey:@"title"];
  2033. else
  2034. [map setValue:@"Hide Price" forKey:@"title"];
  2035. [map setValue:@"rect_announcements" forKey:@"img"];
  2036. [self.sideMenuItems addObject:map.copy];
  2037. }
  2038. // [map setValue:@"Contact" forKey:@"title"];
  2039. // [map setValue:@"rect_market_news" forKey:@"img"];
  2040. // [self.sideMenuItems addObject:map.copy];
  2041. // [map setValue:@"Cache" forKey:@"title"];
  2042. // [map setValue:@"rect_announcements" forKey:@"img"];
  2043. //[self.sideMenuItems addObject:map.copy];
  2044. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  2045. // [map setValue:@"Message" forKey:@"title"];
  2046. // [map setValue:@"rect_search_history" forKey:@"img"];
  2047. // [self.sideMenuItems addObject:map.copy];
  2048. //
  2049. #if defined(BUILD_NPD)
  2050. [map setValue:@"Scanner Setting" forKey:@"title"];
  2051. [map setValue:@"rect_change_password" forKey:@"img"];
  2052. [self.sideMenuItems addObject:map.copy];
  2053. # endif
  2054. #if defined(SCANNER_ORDER)
  2055. [map setValue:@"Scanner Order" forKey:@"title"];
  2056. [map setValue:@"rect_change_password" forKey:@"img"];
  2057. [self.sideMenuItems addObject:map.copy];
  2058. # endif
  2059. #if defined(BUILD_NPD)|| defined (BUILD_CONTRAST)
  2060. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  2061. {
  2062. [map setValue:@"Offline Setting" forKey:@"title"];
  2063. [map setValue:@"rect_market_news" forKey:@"img"];
  2064. [self.sideMenuItems addObject:map.copy];
  2065. }
  2066. #endif
  2067. if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore ) {
  2068. [map setValue:@"Price Setting" forKey:@"title"];
  2069. // [map setValue:@"rect_market_news" forKey:@"img"];
  2070. [self.sideMenuItems addObject:map.copy];
  2071. }
  2072. if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore ) {
  2073. if ([RASingleton sharedInstance].global_lock) {
  2074. [map setValue:@"Unlock" forKey:@"title"];
  2075. } else {
  2076. [map setValue:@"Lock" forKey:@"title"];
  2077. }
  2078. [self.sideMenuItems addObject:map.copy];
  2079. }
  2080. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  2081. /*
  2082. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  2083. {
  2084. [map setValue:@"Offline Setting" forKey:@"title"];
  2085. [map setValue:@"rect_market_news" forKey:@"img"];
  2086. [self.sideMenuItems addObject:map.copy];
  2087. }
  2088. */
  2089. // if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER) {
  2090. // [map setValue:@"Price Setting" forKey:@"title"];
  2091. // // [map setValue:@"rect_market_news" forKey:@"img"];
  2092. // [self.sideMenuItems addObject:map.copy];
  2093. // }
  2094. if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore ) {
  2095. if ([Singleton sharedInstance].global_lock) {
  2096. [map setValue:@"Unlock" forKey:@"title"];
  2097. } else {
  2098. [map setValue:@"Lock" forKey:@"title"];
  2099. }
  2100. [self.sideMenuItems addObject:map.copy];
  2101. }
  2102. # endif
  2103. #ifdef DEBUG
  2104. // if([[appDelegate.user lowercaseString] isEqualToString:@"larryl"]||[[appDelegate.user lowercaseString] isEqualToString:@"arpithat"])
  2105. {
  2106. // [map setValue:@"Contact" forKey:@"title"];
  2107. // [map setValue:@"rect_contact_list" forKey:@"img"];
  2108. // [self.sideMenuItems addObject:map.copy];
  2109. [map setValue:@"Function Test" forKey:@"title"];
  2110. [map setValue:@"rect_market_news" forKey:@"img"];
  2111. [self.sideMenuItems addObject:map.copy];
  2112. }
  2113. #endif
  2114. [map setValue:@"Privacy Policy" forKey:@"title"];
  2115. [map setValue:@"rect_change_password" forKey:@"img"];
  2116. [self.sideMenuItems addObject:map.copy];
  2117. [map setValue:@"About us" forKey:@"title"];
  2118. [map setValue:@"rect_change_password" forKey:@"img"];
  2119. [self.sideMenuItems addObject:map.copy];
  2120. #ifdef BUILD_HMLG
  2121. [map setValue:@"Homelegance Website" forKey:@"title"];
  2122. [map setValue:@"rect_change_password" forKey:@"img"];
  2123. [self.sideMenuItems addObject:map.copy];
  2124. #endif
  2125. #if defined(BUILD_NPD)
  2126. [map setValue:@"BLOG" forKey:@"title"];
  2127. [map setValue:@"rect_change_password" forKey:@"img"];
  2128. [self.sideMenuItems addObject:map.copy];
  2129. [map setValue:[NSString stringWithFormat:@"%@ Website",COMPANY_SHORT_NAME] forKey:@"title"];
  2130. [map setValue:@"rect_change_password" forKey:@"img"];
  2131. [self.sideMenuItems addObject:map.copy];
  2132. [map setValue:[NSString stringWithFormat:@"%@ Policy",COMPANY_SHORT_NAME] forKey:@"title"];
  2133. [map setValue:@"rect_change_password" forKey:@"img"];
  2134. [self.sideMenuItems addObject:map.copy];
  2135. [map setValue:@"Simplified Buying Program" forKey:@"title"];
  2136. [map setValue:@"rect_change_password" forKey:@"img"];
  2137. [self.sideMenuItems addObject:map.copy];
  2138. #endif
  2139. #ifdef BUILD_USAI
  2140. // [map setValue:@"BLOG" forKey:@"title"];
  2141. // [map setValue:@"rect_change_password" forKey:@"img"];
  2142. // [self.sideMenuItems addObject:map.copy];
  2143. [map setValue:@"USAI Website" forKey:@"title"];
  2144. [map setValue:@"rect_change_password" forKey:@"img"];
  2145. [self.sideMenuItems addObject:map.copy];
  2146. #endif
  2147. #ifdef BUILD_HOMER
  2148. /*
  2149. [map setValue:@"BLOG" forKey:@"title"];
  2150. [map setValue:@"rect_change_password" forKey:@"img"];
  2151. [self.sideMenuItems addObject:map.copy];
  2152. */
  2153. [map setValue:@"HOMER Website" forKey:@"title"];
  2154. [map setValue:@"rect_change_password" forKey:@"img"];
  2155. [self.sideMenuItems addObject:map.copy];
  2156. #endif
  2157. #ifdef BUILD_GATIT
  2158. [map setValue:@"TITAN Website" forKey:@"title"];
  2159. [map setValue:@"rect_change_password" forKey:@"img"];
  2160. [self.sideMenuItems addObject:map.copy];
  2161. # endif
  2162. [self.sideMenuTable reloadData];
  2163. //
  2164. }
  2165. - (UIImage *)applyBlurWithRadius:(CGFloat)blurRadius sourceImage:(UIImage*)sourceImage tintColor:(UIColor *)tintColor saturationDeltaFactor:(CGFloat)saturationDeltaFactor maskImage:(UIImage *)maskImage
  2166. {
  2167. // Check pre-conditions.
  2168. if (sourceImage.size.width < 1 || sourceImage.size.height < 1) {
  2169. DebugLog (@"*** error: invalid size: (%.2f x %.2f). Both dimensions must be >= 1: %@", sourceImage.size.width, sourceImage.size.height, self);
  2170. return nil;
  2171. }
  2172. if (!sourceImage.CGImage) {
  2173. DebugLog (@"*** error: image must be backed by a CGImage: %@", self);
  2174. return nil;
  2175. }
  2176. if (maskImage && !maskImage.CGImage) {
  2177. DebugLog (@"*** error: maskImage must be backed by a CGImage: %@", maskImage);
  2178. return nil;
  2179. }
  2180. CGRect imageRect = { CGPointZero, sourceImage.size };
  2181. UIImage *effectImage = sourceImage;
  2182. BOOL hasBlur = blurRadius > __FLT_EPSILON__;
  2183. BOOL hasSaturationChange = fabs(saturationDeltaFactor - 1.) > __FLT_EPSILON__;
  2184. if (hasBlur || hasSaturationChange) {
  2185. UIGraphicsBeginImageContextWithOptions(sourceImage.size, NO, [[UIScreen mainScreen] scale]);
  2186. CGContextRef effectInContext = UIGraphicsGetCurrentContext();
  2187. CGContextScaleCTM(effectInContext, 1.0, -1.0);
  2188. CGContextTranslateCTM(effectInContext, 0, -sourceImage.size.height);
  2189. CGContextDrawImage(effectInContext, imageRect, sourceImage.CGImage);
  2190. vImage_Buffer effectInBuffer;
  2191. effectInBuffer.data = CGBitmapContextGetData(effectInContext);
  2192. effectInBuffer.width = CGBitmapContextGetWidth(effectInContext);
  2193. effectInBuffer.height = CGBitmapContextGetHeight(effectInContext);
  2194. effectInBuffer.rowBytes = CGBitmapContextGetBytesPerRow(effectInContext);
  2195. UIGraphicsBeginImageContextWithOptions(sourceImage.size, NO, [[UIScreen mainScreen] scale]);
  2196. CGContextRef effectOutContext = UIGraphicsGetCurrentContext();
  2197. vImage_Buffer effectOutBuffer;
  2198. effectOutBuffer.data = CGBitmapContextGetData(effectOutContext);
  2199. effectOutBuffer.width = CGBitmapContextGetWidth(effectOutContext);
  2200. effectOutBuffer.height = CGBitmapContextGetHeight(effectOutContext);
  2201. effectOutBuffer.rowBytes = CGBitmapContextGetBytesPerRow(effectOutContext);
  2202. if (hasBlur) {
  2203. // A description of how to compute the box kernel width from the Gaussian
  2204. // radius (aka standard deviation) appears in the SVG spec:
  2205. // http://www.w3.org/TR/SVG/filters.html#feGaussianBlurElement
  2206. //
  2207. // For larger values of 's' (s >= 2.0), an approximation can be used: Three
  2208. // successive box-blurs build a piece-wise quadratic convolution kernel, which
  2209. // approximates the Gaussian kernel to within roughly 3%.
  2210. //
  2211. // let d = floor(s * 3*sqrt(2*pi)/4 + 0.5)
  2212. //
  2213. // ... if d is odd, use three box-blurs of size 'd', centered on the output pixel.
  2214. //
  2215. CGFloat inputRadius = blurRadius * [[UIScreen mainScreen] scale];
  2216. NSUInteger radius = floor(inputRadius * 3. * sqrt(2 * M_PI) / 4 + 0.5);
  2217. if (radius % 2 != 1) {
  2218. radius += 1; // force radius to be odd so that the three box-blur methodology works.
  2219. }
  2220. vImageBoxConvolve_ARGB8888(&effectInBuffer, &effectOutBuffer, NULL, 0, 0, (unsigned int)radius, (unsigned int)radius, 0, kvImageEdgeExtend);
  2221. vImageBoxConvolve_ARGB8888(&effectOutBuffer, &effectInBuffer, NULL, 0, 0, (unsigned int)radius, (unsigned int)radius, 0, kvImageEdgeExtend);
  2222. vImageBoxConvolve_ARGB8888(&effectInBuffer, &effectOutBuffer, NULL, 0, 0, (unsigned int)radius, (unsigned int)radius, 0, kvImageEdgeExtend);
  2223. }
  2224. BOOL effectImageBuffersAreSwapped = NO;
  2225. if (hasSaturationChange) {
  2226. CGFloat s = saturationDeltaFactor;
  2227. CGFloat floatingPointSaturationMatrix[] = {
  2228. 0.0722 + 0.9278 * s, 0.0722 - 0.0722 * s, 0.0722 - 0.0722 * s, 0,
  2229. 0.7152 - 0.7152 * s, 0.7152 + 0.2848 * s, 0.7152 - 0.7152 * s, 0,
  2230. 0.2126 - 0.2126 * s, 0.2126 - 0.2126 * s, 0.2126 + 0.7873 * s, 0,
  2231. 0, 0, 0, 1,
  2232. };
  2233. const int32_t divisor = 256;
  2234. NSUInteger matrixSize = sizeof(floatingPointSaturationMatrix)/sizeof(floatingPointSaturationMatrix[0]);
  2235. int16_t saturationMatrix[matrixSize];
  2236. for (NSUInteger i = 0; i < matrixSize; ++i) {
  2237. saturationMatrix[i] = (int16_t)roundf(floatingPointSaturationMatrix[i] * divisor);
  2238. }
  2239. if (hasBlur) {
  2240. vImageMatrixMultiply_ARGB8888(&effectOutBuffer, &effectInBuffer, saturationMatrix, divisor, NULL, NULL, kvImageNoFlags);
  2241. effectImageBuffersAreSwapped = YES;
  2242. }
  2243. else {
  2244. vImageMatrixMultiply_ARGB8888(&effectInBuffer, &effectOutBuffer, saturationMatrix, divisor, NULL, NULL, kvImageNoFlags);
  2245. }
  2246. }
  2247. if (!effectImageBuffersAreSwapped)
  2248. effectImage = UIGraphicsGetImageFromCurrentImageContext();
  2249. UIGraphicsEndImageContext();
  2250. if (effectImageBuffersAreSwapped)
  2251. effectImage = UIGraphicsGetImageFromCurrentImageContext();
  2252. UIGraphicsEndImageContext();
  2253. }
  2254. // Set up output context.
  2255. UIGraphicsBeginImageContextWithOptions(sourceImage.size, NO, [[UIScreen mainScreen] scale]);
  2256. CGContextRef outputContext = UIGraphicsGetCurrentContext();
  2257. CGContextScaleCTM(outputContext, 1.0, -1.0);
  2258. CGContextTranslateCTM(outputContext, 0, -sourceImage.size.height);
  2259. // Draw base image.
  2260. CGContextDrawImage(outputContext, imageRect, sourceImage.CGImage);
  2261. // Draw effect image.
  2262. if (hasBlur) {
  2263. CGContextSaveGState(outputContext);
  2264. if (maskImage) {
  2265. CGContextClipToMask(outputContext, imageRect, maskImage.CGImage);
  2266. }
  2267. CGContextDrawImage(outputContext, imageRect, effectImage.CGImage);
  2268. CGContextRestoreGState(outputContext);
  2269. }
  2270. // Add in color tint.
  2271. if (tintColor) {
  2272. CGContextSaveGState(outputContext);
  2273. CGContextSetFillColorWithColor(outputContext, tintColor.CGColor);
  2274. CGContextFillRect(outputContext, imageRect);
  2275. CGContextRestoreGState(outputContext);
  2276. }
  2277. // Output image is ready.
  2278. UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext();
  2279. UIGraphicsEndImageContext();
  2280. return outputImage;
  2281. }
  2282. //- (IBAction)openMenu:(UIButton *)sender {
  2283. //}
  2284. #pragma mark - Table view data source
  2285. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  2286. {
  2287. return 1;
  2288. }
  2289. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  2290. {
  2291. return self.sideMenuItems.count;
  2292. }
  2293. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  2294. {
  2295. UIApplication * app = [UIApplication sharedApplication];
  2296. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  2297. NSString *CellIdentifier = @"SideMenuItem";
  2298. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2299. NSString* title = [self.sideMenuItems[indexPath.row] valueForKey:@"title"];
  2300. cell.backgroundColor = [UIColor clearColor];
  2301. // [cell.backgroundColor:[UIColor clearColor]];
  2302. // UIImageView* iv= [[UIImageView alloc] initWithImage:];
  2303. cell.textLabel.text = title;
  2304. cell.detailTextLabel.textColor =[UIColor redColor];
  2305. if([title isEqualToString:@"Wish List"]&&appDelegate.wish_count>0)
  2306. cell.detailTextLabel.text = [NSString stringWithFormat:@"%ld",appDelegate.wish_count];
  2307. else if(([title isEqualToString:@"Portfolio"] || [title isEqualToString:@"Hang Tag"])&&appDelegate.port_count>0)
  2308. cell.detailTextLabel.text = [NSString stringWithFormat:@"%ld",appDelegate.port_count];
  2309. else
  2310. {
  2311. cell.detailTextLabel.text =nil;
  2312. }
  2313. // cell.imageView.image = [UIImage imageNamed:[self.toolsinfo[indexPath.row] valueForKey:@"img"]];
  2314. return cell;
  2315. }
  2316. #ifdef SCANNER_ORDER
  2317. //#pragma mark - Offline Order
  2318. //-(void) CreateOfflineOrder
  2319. //{
  2320. //
  2321. // RASingleton.sharedInstance.enable_OfflineOrder = true;
  2322. //
  2323. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2324. // __block MainViewController *brself= self;
  2325. // if(appDelegate.contact_id.length<=0)
  2326. // {
  2327. //
  2328. // UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"New Offline Order" message:nil preferredStyle:UIAlertControllerStyleAlert];
  2329. // UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"With Offline Contact" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  2330. //
  2331. //// if(appDelegate.order_code && appDelegate.order_code.length>0)
  2332. //// {
  2333. //// [RAUtils message_alert:@"Please close current order and try again." title:@"" controller:self];
  2334. //// }
  2335. //// NSLog(@"new click");
  2336. //
  2337. // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  2338. //
  2339. //// NSString *path = [[NSBundle mainBundle] pathForResource:@"editContact.json" ofType:nil];
  2340. //
  2341. // CustomerEditViewController * cuseditVC = [[CustomerEditViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  2342. // cuseditVC.bnewcustomer=true;
  2343. // cuseditVC.bolocustomer = true;
  2344. // cuseditVC.url_type = URL_LOCAL;
  2345. // cuseditVC.request_url=URL_SO_NEW_CONTACT;
  2346. //
  2347. // cuseditVC.params = params;
  2348. //
  2349. // cuseditVC.returnValue=^(NSMutableDictionary* value)
  2350. // {
  2351. // if(value==nil)
  2352. // {
  2353. // [RAUtils message_alert:@"Cannot create order without customer infomation." title:@"" controller:self];
  2354. // }
  2355. // else
  2356. // {
  2357. // NSString* contact_id=[[NSUUID new] UUIDString];
  2358. //
  2359. //
  2360. //
  2361. //
  2362. //
  2363. //
  2364. // value [@"customer_cid"] = contact_id;
  2365. // appDelegate.contact_id=contact_id;
  2366. // appDelegate.customerInfo = value;
  2367. // [brself refreshContactDisplay];
  2368. // [self newoloorder];
  2369. //// [brself switchToCart:nil];
  2370. //
  2371. // }
  2372. // };
  2373. //
  2374. //
  2375. // // cuseditVC.delegate=self;
  2376. // //
  2377. // // if(checked.count==count)
  2378. // // {
  2379. // // orderinfoVC.have_tail = true
  2380. // // }
  2381. //
  2382. // [[self navigationController] setNavigationBarHidden:NO animated:NO];
  2383. // [self.navigationController pushViewController:cuseditVC animated:false];
  2384. //
  2385. //// [self dismissViewControllerAnimated:NO completion:^{
  2386. ////// [(UINavigationController*)[self parentViewController] pushViewController:cuseditVC animated:false];;
  2387. ////// [[self navigationController] setNavigationBarHidden:NO animated:NO];
  2388. ////
  2389. ////// [self pushViewController:cuseditVC animated:false];
  2390. //// }];
  2391. //
  2392. //// [[self navigationController] setNavigationBarHidden:NO animated:NO];
  2393. //// [self.navigationController pushViewController:cuseditVC animated:false];
  2394. //
  2395. //
  2396. // }];
  2397. //
  2398. // UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"With Online Contact" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  2399. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2400. //
  2401. // if(appDelegate.order_code && appDelegate.order_code.length>0)
  2402. // {
  2403. // // appDelegate.order_code= nil;
  2404. // // [appDelegate SetSo:nil];
  2405. //
  2406. //
  2407. // // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  2408. // ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  2409. // cvc.showNavibar = true;
  2410. // cvc.contact_type = @"Sales_Order_Customer";
  2411. // cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  2412. //
  2413. // appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  2414. // appDelegate.customerInfo = value;
  2415. //
  2416. //// self.norefresh = true;
  2417. // [self newoloorder];
  2418. //
  2419. //
  2420. //
  2421. // // [main_vc checklogin:true];
  2422. // // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  2423. //
  2424. // //
  2425. // // if(self.returnValue)
  2426. // // self.returnValue(value);
  2427. // };
  2428. //
  2429. // cvc.onCancel = ^(){
  2430. //// self.norefresh = true;
  2431. // if(appDelegate.customerInfo==nil)
  2432. // {
  2433. // [RAUtils message_alert:@"Cannot create order without customer infomation." title:@"" controller:self];
  2434. // }
  2435. // else
  2436. // {
  2437. // [self newoloorder];
  2438. // }
  2439. // // [main_vc checklogin:true];
  2440. // };
  2441. // cvc.onReset = ^(){
  2442. // // [main_vc checklogin:true];
  2443. // };
  2444. //
  2445. // [self.navigationController pushViewController:cvc animated:true];
  2446. //
  2447. //
  2448. //
  2449. // }
  2450. // else
  2451. // {
  2452. // //create new;
  2453. //
  2454. // if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  2455. // {
  2456. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  2457. // ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  2458. // cvc.showNavibar = true;
  2459. // cvc.contact_type = @"Sales_Order_Customer";
  2460. // cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  2461. //
  2462. // appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  2463. // appDelegate.customerInfo = value;
  2464. //
  2465. //
  2466. // if(appDelegate.order_code==nil)
  2467. // [self newoloorder];
  2468. //
  2469. // // [main_vc checklogin:true];
  2470. // // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  2471. //
  2472. // //
  2473. // // if(self.returnValue)
  2474. // // self.returnValue(value);
  2475. // };
  2476. //
  2477. // cvc.onCancel = ^(){
  2478. //
  2479. // [RAUtils message_alert:@"Cannot create order without customer infomation." title:@"" controller:self];
  2480. //
  2481. //
  2482. //
  2483. // };
  2484. // cvc.onReset = ^(){
  2485. // [main_vc checklogin:true];
  2486. // };
  2487. //
  2488. // [self.navigationController pushViewController:cvc animated:true];
  2489. // }
  2490. // else
  2491. // {
  2492. // [self newoloorder];
  2493. // }
  2494. // }
  2495. //
  2496. // }];
  2497. //
  2498. // UIAlertAction *alertCancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  2499. //
  2500. // }];
  2501. //
  2502. // [alertControl addAction:actionOne];
  2503. //
  2504. // [alertControl addAction:alertthree];
  2505. // [alertControl addAction:alertCancel];
  2506. //
  2507. // [self presentViewController:alertControl animated:YES completion:nil];
  2508. // }
  2509. // else
  2510. // {
  2511. // [self newoloorder];
  2512. // }
  2513. //}
  2514. -(void) scanLogin
  2515. {
  2516. [self onUserButtonClick:nil];
  2517. }
  2518. -(void) initAppDelegate
  2519. {
  2520. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2521. // appDelegate.user_type = USER_ROLE_EMPLOYEE;
  2522. // appDelegate.can_set_cart_price = true;
  2523. // appDelegate.can_see_price = true;
  2524. // appDelegate.can_set_cart_price = true;
  2525. // appDelegate.can_show_price = true;
  2526. // appDelegate.can_cancel_order = true;
  2527. // appDelegate.can_create_order=true;
  2528. // appDelegate.can_delete_order = true;
  2529. // appDelegate.can_submit_order = true;
  2530. // appDelegate.bLogin = true;
  2531. // RASingleton.sharedInstance.permissions_edit_order = true;
  2532. RASingleton.sharedInstance.price_type = 1;
  2533. // [OLDataProvider createScanTempFolder];
  2534. NSDictionary *addressDic = [[NSUserDefaults standardUserDefaults] valueForKey:@"ScanAddress"] ;
  2535. if (addressDic) {
  2536. // NSUInteger selectedIndex = [[addressDic objectForKey:@"selectedIndex"] integerValue];
  2537. // if (selectedIndex == 1) {
  2538. // self.address = [addressDic objectForKey:@"serverAddress"];
  2539. // }
  2540. // if (selectedIndex == 2) {
  2541. // self.address = [addressDic objectForKey:@"serverAddress"];
  2542. // }
  2543. appDelegate.address = [addressDic objectForKey:@"serverAddress"];
  2544. // [OLDataProvider guestLogin];
  2545. NSMutableDictionary* guestjson=[OLDataProvider loadScanTemplate:@"guest.json"];
  2546. if(!guestjson)
  2547. {
  2548. dispatch_async(dispatch_get_main_queue(), ^{
  2549. [RADataProvider updateTemplate:self];
  2550. });
  2551. }
  2552. else
  2553. dispatch_async(dispatch_get_main_queue(), ^{
  2554. [self onUserButtonClick:nil];
  2555. });
  2556. }
  2557. else
  2558. {
  2559. // return;
  2560. SetupServerViewController * servervc =[[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"SetupServerViewController"];
  2561. servervc.returnValue = ^{
  2562. NSDictionary *addressDic = [[NSUserDefaults standardUserDefaults] valueForKey:@"ScanAddress"];
  2563. if (addressDic) {
  2564. self.labelServer.text = [addressDic objectForKey:@"show_name"];
  2565. }
  2566. dispatch_async(dispatch_get_main_queue(), ^{
  2567. [RADataProvider updateTemplate:self];
  2568. });
  2569. };
  2570. [self.navigationController pushViewController:servervc animated:true];
  2571. }
  2572. [RADataProvider default_price_group];
  2573. }
  2574. //-(void) newoloorder
  2575. //{
  2576. // NSString* order_code = [[NSUUID new] UUIDString];
  2577. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2578. // appDelegate.order_code = order_code;
  2579. //
  2580. // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_CART ofType:@"json" ]];
  2581. // RASingleton.sharedInstance.scan_cart=[[RAConvertor data2dict:json] mutableCopy];
  2582. //
  2583. //
  2584. //// __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Create Order" completion:^{
  2585. //// [RANetwork request_create_order:^(NSMutableDictionary *result) {
  2586. //// NSMutableDictionary* return_json =result;
  2587. ////
  2588. //// [waitalert dismissViewControllerAnimated:YES completion:^{
  2589. //// if([[return_json valueForKey:@"result"] intValue]==2)
  2590. //// {
  2591. //// int result=[[return_json valueForKey:@"result"] intValue];
  2592. //// if(result==2)
  2593. //// {
  2594. //// //successed.
  2595. ////
  2596. //// NSString* order_code = [return_json valueForKey:@"orderCode"];
  2597. //// AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2598. //// appDelegate.order_code = order_code;
  2599. //// appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
  2600. ////
  2601. ////
  2602. //// #ifdef RA_NOTIFICATION
  2603. //// [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2604. //// #else
  2605. //// MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  2606. //// [main_vc reloadCart:true immediately:false];
  2607. //// #endif
  2608. ////
  2609. ////// [self ReloadData];
  2610. ////
  2611. ////
  2612. //// // [self performSelector:@selector(loadpage) withObject:nil afterDelay:1];
  2613. //// // [self loadpage];
  2614. ////
  2615. ////
  2616. //// // if(self.shopCartBlock!=nil)
  2617. //// // {
  2618. //// // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  2619. //// //
  2620. //// //
  2621. //// // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  2622. //// // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  2623. //// // iv.image = img;
  2624. //// // // [self.contentView addSubview:iv];
  2625. //// // self.shopCartBlock(iv);
  2626. //// //
  2627. //// // }
  2628. ////
  2629. //// }
  2630. //// }
  2631. //// else
  2632. //// {
  2633. //// [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Create Order" controller:self] ;
  2634. //// }
  2635. //// }];
  2636. //// // [waitalert dismissViewControllerAnimated:YES completion:nil];
  2637. ////
  2638. ////
  2639. ////
  2640. ////
  2641. ////
  2642. ////
  2643. ////
  2644. ////
  2645. //// }];
  2646. ////
  2647. //// }];
  2648. //
  2649. //// dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2650. ////
  2651. //// NSDictionary* return_json = [RANetwork new_Order];
  2652. ////
  2653. //// dispatch_async(dispatch_get_main_queue(), ^{
  2654. //// [waitalert dismissViewControllerAnimated:YES completion:nil];
  2655. ////
  2656. ////
  2657. //// if([[return_json valueForKey:@"result"] intValue]==2)
  2658. //// {
  2659. //// int result=[[return_json valueForKey:@"result"] intValue];
  2660. //// if(result==2)
  2661. //// {
  2662. //// //successed.
  2663. ////
  2664. //// NSString* order_code = [return_json valueForKey:@"orderCode"];
  2665. //// AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2666. //// appDelegate.order_code = order_code;
  2667. //// appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
  2668. ////
  2669. ////
  2670. ////#ifdef RA_NOTIFICATION
  2671. //// [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2672. ////#else
  2673. //// MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  2674. //// [main_vc reloadCart:true immediately:false];
  2675. ////#endif
  2676. ////
  2677. //// [self ReloadData];
  2678. ////
  2679. ////
  2680. //// // [self performSelector:@selector(loadpage) withObject:nil afterDelay:1];
  2681. //// // [self loadpage];
  2682. ////
  2683. ////
  2684. //// // if(self.shopCartBlock!=nil)
  2685. //// // {
  2686. //// // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  2687. //// //
  2688. //// //
  2689. //// // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  2690. //// // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  2691. //// // iv.image = img;
  2692. //// // // [self.contentView addSubview:iv];
  2693. //// // self.shopCartBlock(iv);
  2694. //// //
  2695. //// // }
  2696. ////
  2697. //// }
  2698. //// }
  2699. //// else
  2700. //// {
  2701. //// [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Create Order" controller:self] ;
  2702. //// }
  2703. ////
  2704. ////
  2705. ////
  2706. ////
  2707. //// });
  2708. //// });
  2709. //}
  2710. #endif
  2711. #pragma mark - Table view delegate
  2712. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  2713. {
  2714. NSString* title = [self.sideMenuItems[indexPath.row] valueForKey:@"title"];
  2715. if([title isEqualToString:@"Cache"])
  2716. {
  2717. CacheViewController * settingvc=[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"CacheViewController"];
  2718. PopupNavigationController * navi=[[PopupNavigationController alloc] initWithRootViewController:settingvc];
  2719. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  2720. [self presentViewController:navi animated:YES completion:^{
  2721. //DebugLog(@"login.........");
  2722. // <#code#>
  2723. }];
  2724. }
  2725. #ifdef SCANNER_ORDER
  2726. // else if([title isEqualToString:@"Scanner Order"])
  2727. // {
  2728. //
  2729. // OLOSettingViewController * offlineVC =[ [UIStoryboard storyboardWithName:@"OLM" bundle:nil] instantiateViewControllerWithIdentifier:@"OLOSettingViewController"];
  2730. // offlineVC.returnValue=^(int type){
  2731. // if(type == OOC_CREATE_ORDER){
  2732. // [self CreateOfflineOrder];
  2733. // }
  2734. // };
  2735. // // loginvc.delegate = self;
  2736. // // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  2737. // // appDelegate.active_controller = gunVC;
  2738. //// gunVC.onDismissVC = ^(){
  2739. //// appDelegate.active_controller = active_vc;
  2740. //// };
  2741. // UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:offlineVC] ;
  2742. //
  2743. //
  2744. //
  2745. //
  2746. //
  2747. // // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  2748. //
  2749. // navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  2750. // [self presentViewController:navi animated:YES completion:^{
  2751. //
  2752. // // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  2753. //
  2754. // DebugLog(@"about present.........");
  2755. //
  2756. // // self.btop = false;
  2757. // // <#code#>
  2758. // }];
  2759. //
  2760. // }
  2761. #endif
  2762. else if([title isEqualToString:@"Scanner Setting"])
  2763. {
  2764. //
  2765. #ifndef RA_NOTIFICATION
  2766. UIApplication * app = [UIApplication sharedApplication];
  2767. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  2768. UIViewController* active_vc = appDelegate.active_controller;
  2769. ScannerSettingViewController * gunVC =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ScannerSettingViewController"];
  2770. appDelegate.active_controller = gunVC;
  2771. gunVC.onDismissVC = ^(){
  2772. appDelegate.active_controller = active_vc;
  2773. };
  2774. #else
  2775. ScannerSettingViewController * gunVC =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ScannerSettingViewController"];
  2776. #endif
  2777. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:gunVC] ;
  2778. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  2779. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  2780. [self presentViewController:navi animated:YES completion:^{
  2781. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  2782. DebugLog(@"about present.........");
  2783. // self.btop = false;
  2784. // <#code#>
  2785. }];
  2786. }
  2787. else if([title isEqualToString:@"Offline Setting"])
  2788. {
  2789. // UIApplication * app = [UIApplication sharedApplication];
  2790. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  2791. //UIViewController* active_vc = appDelegate.active_controller;
  2792. OfflineSettingViewController * offlineVC =[ [UIStoryboard storyboardWithName:@"OLM" bundle:nil] instantiateViewControllerWithIdentifier:@"OfflineSettingViewController"];
  2793. // loginvc.delegate = self;
  2794. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  2795. // appDelegate.active_controller = gunVC;
  2796. // gunVC.onDismissVC = ^(){
  2797. // appDelegate.active_controller = active_vc;
  2798. // };
  2799. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:offlineVC] ;
  2800. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  2801. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  2802. [self presentViewController:navi animated:YES completion:^{
  2803. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  2804. DebugLog(@"about present.........");
  2805. // self.btop = false;
  2806. // <#code#>
  2807. }];
  2808. // [iSalesDB testdata];
  2809. }
  2810. else if([title isEqualToString:@"Function Test"])
  2811. {
  2812. // NSString* url = @"https://shopla.homelegance.com/";
  2813. //
  2814. //
  2815. // NSString* title = @"NPD";
  2816. // UIApplication * app = [UIApplication sharedApplication];
  2817. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  2818. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  2819. //
  2820. //
  2821. FunctionTestViewController *ViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"FunctionTestViewController"];
  2822. // ViewController.url = url;
  2823. // ViewController.title = title;
  2824. [self.navigationController pushViewController:ViewController animated:YES];
  2825. }
  2826. else if ([title isEqualToString:@"BLOG"]) {
  2827. NSString* url = URL_BLOG;
  2828. #ifdef BUILD_HOMER
  2829. NSString* title = @"HOMER BLOG";
  2830. #endif
  2831. #ifdef BUILD_GATIT
  2832. NSString* title = @"TITAN BLOG";
  2833. #endif
  2834. #ifdef BUILD_NPD
  2835. NSString* title = @"NPD BLOG";
  2836. #endif
  2837. #ifdef BUILD_USAI
  2838. NSString* title = @"USAI BLOG";
  2839. #endif
  2840. #ifdef BUILD_CONTRAST
  2841. NSString* title = @"CONTRAST BLOG";
  2842. #endif
  2843. title = [NSString stringWithFormat:@"%@ BLOG",COMPANY_SHORT_NAME];
  2844. WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  2845. ViewController.url = url;
  2846. ViewController.title = title;
  2847. [self.navigationController pushViewController:ViewController animated:YES];
  2848. }
  2849. else if([title isEqualToString:@"NPD Website"])
  2850. {
  2851. NSString* url = @"https://www.newpacificdirect.com";//@"https://shopla.homelegance.com/general.htm?websiteId=1";//
  2852. NSString* title = @"NPD";
  2853. // UIApplication * app = [UIApplication sharedApplication];
  2854. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  2855. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  2856. //
  2857. //
  2858. WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  2859. ViewController.url = url;
  2860. ViewController.title = title;
  2861. [self.navigationController pushViewController:ViewController animated:YES];
  2862. }
  2863. else if([title isEqualToString:@"USAI Website"])
  2864. {
  2865. NSString* url = @"http://www.united-us.net/";//@"https://shopla.homelegance.com/general.htm?websiteId=1";//
  2866. NSString* title = @"USAI";
  2867. // UIApplication * app = [UIApplication sharedApplication];
  2868. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  2869. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  2870. //
  2871. //
  2872. WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  2873. ViewController.url = url;
  2874. ViewController.title = title;
  2875. [self.navigationController pushViewController:ViewController animated:YES];
  2876. }
  2877. else if([title isEqualToString:@"Homelegance Website"])
  2878. {
  2879. NSString* url = @"http://207.140.24.83";//@"https://shopla.homelegance.com/general.htm?websiteId=1";//
  2880. NSString* title = @"Homelegance";
  2881. // UIApplication * app = [UIApplication sharedApplication];
  2882. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  2883. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  2884. //
  2885. //
  2886. WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  2887. ViewController.url = url;
  2888. ViewController.title = title;
  2889. [self.navigationController pushViewController:ViewController animated:YES];
  2890. }
  2891. else if([title isEqualToString:@"HOMER Website"])
  2892. {
  2893. NSString* url = COMPANY_WEB;
  2894. NSString* title = @"HOMER";
  2895. WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  2896. ViewController.url = url;
  2897. ViewController.title = title;
  2898. [self.navigationController pushViewController:ViewController animated:YES];
  2899. }
  2900. else if([title isEqualToString:@"TITAN Website"])
  2901. {
  2902. NSString* url = COMPANY_WEB;
  2903. NSString* title = @"TITAN";
  2904. WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  2905. ViewController.url = url;
  2906. ViewController.title = title;
  2907. [self.navigationController pushViewController:ViewController animated:YES];
  2908. }
  2909. else if([title isEqualToString:@"NPD Policy"])
  2910. {
  2911. NSString* url = URL_NPD_POLICY;//@"https://shopla.homelegance.com/general.htm?websiteId=1";//
  2912. NSString* title = @"NPD Policy";
  2913. // UIApplication * app = [UIApplication sharedApplication];
  2914. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  2915. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  2916. //
  2917. //
  2918. WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  2919. ViewController.url = url;
  2920. ViewController.title = title;
  2921. [self.navigationController pushViewController:ViewController animated:YES];
  2922. }
  2923. else if([title isEqualToString:@"USAI Policy"])
  2924. {
  2925. NSString* url = URL_NPD_POLICY;
  2926. NSString* title = @"USAI Policy";
  2927. WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  2928. ViewController.url = url;
  2929. ViewController.title = title;
  2930. [self.navigationController pushViewController:ViewController animated:YES];
  2931. }
  2932. else if([title isEqualToString:@"HOMER Policy"])
  2933. {
  2934. NSString* url = URL_NPD_POLICY;
  2935. NSString* title = @"HOMER Policy";
  2936. WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  2937. ViewController.url = url;
  2938. ViewController.title = title;
  2939. [self.navigationController pushViewController:ViewController animated:YES];
  2940. }
  2941. else if([title isEqualToString:@"Simplified Buying Program"])
  2942. {
  2943. SimplifiedBuyingProgramViewController *ViewController = [[UIStoryboard storyboardWithName:@"NPD_Mobile" bundle:nil] instantiateViewControllerWithIdentifier:@"SimplifiedBuyingProgramViewController"];
  2944. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:ViewController] ;
  2945. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  2946. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  2947. [self presentViewController:navi animated:YES completion:^{
  2948. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  2949. DebugLog(@"about present.........");
  2950. // self.btop = false;
  2951. // <#code#>
  2952. }];
  2953. }
  2954. else if ([title isEqualToString:@"Privacy Policy"]) {
  2955. NSString* url = URL_PRIVACY;
  2956. NSString* title = @"Privacy Policy";
  2957. WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  2958. ViewController.url = url;
  2959. ViewController.title = title;
  2960. [self.navigationController pushViewController:ViewController animated:YES];
  2961. }
  2962. else if([title isEqualToString:@"About us"])
  2963. {
  2964. AboutViewController * aboutVC =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"AboutViewController"];
  2965. // loginvc.delegate = self;
  2966. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  2967. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:aboutVC] ;
  2968. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  2969. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  2970. [self presentViewController:navi animated:YES completion:^{
  2971. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  2972. DebugLog(@"about present.........");
  2973. // self.btop = false;
  2974. // <#code#>
  2975. }];
  2976. }
  2977. // else if([title isEqualToString:@"Wish List"])
  2978. // {
  2979. // [self hideMenu];
  2980. // [self switchtowishlist];
  2981. // }
  2982. else if([title isEqualToString:@"Show Price"])
  2983. {
  2984. UIApplication * app = [UIApplication sharedApplication];
  2985. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  2986. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore && [RASingleton sharedInstance].global_lock) {
  2987. JKLockController *lockVC = [[JKLockController alloc] init];
  2988. [lockVC setPasswordKey:[NSString stringWithFormat:@"%@_password",appDelegate.user]];
  2989. __weak typeof(self) weakself = self;
  2990. lockVC.authoReturn = ^(BOOL failure) {
  2991. if (weakself) {
  2992. __strong typeof(weakself) strongself = weakself;
  2993. [appDelegate set_priceHidden:false];
  2994. [strongself initMenuItems];
  2995. [strongself hideMenu];
  2996. }
  2997. };
  2998. [self.navigationController pushViewController:lockVC animated:YES];
  2999. } else {
  3000. [appDelegate set_priceHidden:false];
  3001. [self initMenuItems];
  3002. [self hideMenu];
  3003. }
  3004. }
  3005. else if([title isEqualToString:@"Hide Price"])
  3006. {
  3007. UIApplication * app = [UIApplication sharedApplication];
  3008. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  3009. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore && [RASingleton sharedInstance].global_lock) {
  3010. JKLockController *lockVC = [[JKLockController alloc] init];
  3011. [lockVC setPasswordKey:[NSString stringWithFormat:@"%@_password",appDelegate.user]];
  3012. __weak typeof(self) weakself = self;
  3013. lockVC.authoReturn = ^(BOOL failure) {
  3014. if (weakself) {
  3015. __strong typeof(weakself) strongself = weakself;
  3016. [appDelegate set_priceHidden:true];
  3017. [strongself initMenuItems];
  3018. [strongself hideMenu];
  3019. }
  3020. };
  3021. [self.navigationController pushViewController:lockVC animated:YES];
  3022. } else {
  3023. [appDelegate set_priceHidden:true];
  3024. [self initMenuItems];
  3025. [self hideMenu];
  3026. }
  3027. }
  3028. // else if([title isEqualToString:@"Portfolio"] || [title isEqualToString:@"Hang Tag"])
  3029. // {
  3030. // [self hideMenu];
  3031. // if([self.current_VC isKindOfClass:[PortfolioViewController class]])
  3032. // return;
  3033. // [self flipFromViewController:self.current_VC toViewController:self.portfolioViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  3034. // }
  3035. // else if([title isEqualToString:@"View Portfolios"] || [title isEqualToString:@"View Hang Tags"])
  3036. // {
  3037. // [self hideMenu];
  3038. // if([self.current_VC isKindOfClass:[PortfolioListViewController class]])
  3039. // return;
  3040. // [self flipFromViewController:self.current_VC toViewController:self.pdfListViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  3041. // }
  3042. else if([title isEqualToString:@"Contact"])
  3043. {
  3044. // UITableViewCell* cell =(UITableViewCell*) sender.superview.superview;
  3045. //
  3046. // NSIndexPath * indexPath = [self.detailTable indexPathForCell:cell];
  3047. //
  3048. // if(indexPath.section!=1)
  3049. // return ;
  3050. // // DebugLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
  3051. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  3052. //
  3053. // NSString* product_id = [item_json valueForKey:@"product_id"];
  3054. [self hideMenu];
  3055. [self switchtocontact];
  3056. }
  3057. else if([title isEqualToString:@"Cam Scan"])
  3058. {
  3059. // UITableViewCell* cell =(UITableViewCell*) sender.superview.superview;
  3060. //
  3061. // NSIndexPath * indexPath = [self.detailTable indexPathForCell:cell];
  3062. //
  3063. // if(indexPath.section!=1)
  3064. // return ;
  3065. // // DebugLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
  3066. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  3067. //
  3068. // NSString* product_id = [item_json valueForKey:@"product_id"];
  3069. [self hideMenu];
  3070. //
  3071. // [self switchtocontact];
  3072. ScannerViewController * scannerVC =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ScannerViewController"];
  3073. [self.navigationController pushViewController:scannerVC animated:true];
  3074. } else if ([title isEqualToString:@"Price Setting"]) {
  3075. UIApplication * app = [UIApplication sharedApplication];
  3076. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  3077. if ([RASingleton sharedInstance].global_lock) {
  3078. JKLockController *lockVC = [[JKLockController alloc] init];
  3079. [lockVC setPasswordKey:[NSString stringWithFormat:@"%@_password",appDelegate.user]];
  3080. __weak typeof(self) weakself = self;
  3081. lockVC.authoReturn = ^(BOOL failure) {
  3082. if (weakself) {
  3083. __strong typeof(weakself) strongself = weakself;
  3084. PriceSettingViewController *priceSettingVC =[ [UIStoryboard storyboardWithName:@"CUL" bundle:nil] instantiateViewControllerWithIdentifier:@"PriceSettingViewController"];
  3085. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:priceSettingVC] ;
  3086. navi.navigationBar.translucent = NO;
  3087. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  3088. [strongself presentViewController:navi animated:YES completion:^{
  3089. }];
  3090. }
  3091. };
  3092. [self.navigationController pushViewController:lockVC animated:YES];
  3093. } else {
  3094. PriceSettingViewController *priceSettingVC =[ [UIStoryboard storyboardWithName:@"CUL" bundle:nil] instantiateViewControllerWithIdentifier:@"PriceSettingViewController"];
  3095. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:priceSettingVC] ;
  3096. navi.navigationBar.translucent = NO;
  3097. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  3098. [self presentViewController:navi animated:YES completion:^{
  3099. }];
  3100. }
  3101. } else if ([title isEqualToString:@"Lock"] || [title isEqualToString:@"Unlock"]) {
  3102. UIApplication * app = [UIApplication sharedApplication];
  3103. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  3104. JKLockController *lockVC = [[JKLockController alloc] init];
  3105. [lockVC setPasswordKey:[NSString stringWithFormat:@"%@_password",appDelegate.user]];
  3106. __weak typeof(self) weakself = self;
  3107. lockVC.authoReturn = ^(BOOL failure) {
  3108. if (weakself) {
  3109. __strong typeof(weakself) strongself = weakself;
  3110. [RASingleton sharedInstance].global_lock = ![RASingleton sharedInstance].global_lock;
  3111. [strongself initMenuItems];
  3112. [strongself hideMenu];
  3113. }
  3114. };
  3115. [self.navigationController pushViewController:lockVC animated:YES];
  3116. }
  3117. }
  3118. //#pragma mark - UIAlertViewDelegate
  3119. //// Called when a button is clicked. The view will be automatically dismissed after this call returns
  3120. //- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  3121. //{
  3122. // UIApplication * app = [UIApplication sharedApplication];
  3123. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  3124. //
  3125. //
  3126. //
  3127. // // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  3128. // if(buttonIndex==alertView.cancelButtonIndex)
  3129. // {
  3130. //
  3131. //
  3132. //
  3133. // }
  3134. // else if(buttonIndex==1)
  3135. // {
  3136. // //open exist
  3137. //
  3138. // OrderListViewController* ovc =[ [UIStoryboard storyboardWithName:@"ERP_Mobile_Order" bundle:nil] instantiateViewControllerWithIdentifier:@"OrderListViewController"];
  3139. // ovc.showNavibar = true;
  3140. // ovc.selectOrder = ^(NSMutableDictionary* order_detail){
  3141. // if(appDelegate.order_code==nil)
  3142. // {
  3143. // [self neworderforCart];
  3144. // }
  3145. // else
  3146. // {
  3147. // self.previous_VC = self.current_VC;
  3148. // [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  3149. //
  3150. // [self checklogin:true];
  3151. //
  3152. // }
  3153. //
  3154. // };
  3155. // ovc.init_style = OL_OPEN;
  3156. // ovc.onCancel = ^(){
  3157. //
  3158. // [self checklogin:true];
  3159. //
  3160. // };
  3161. // ovc.title = @"SAVED ORDER";
  3162. // [self.navigationController pushViewController:ovc animated:true];
  3163. // }
  3164. // else
  3165. // {
  3166. // //create new;
  3167. //
  3168. // if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  3169. // {
  3170. //
  3171. // ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  3172. // cvc.showNavibar = true;
  3173. // cvc.contact_type = @"Sales_Order_Customer";
  3174. // cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  3175. //
  3176. // appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  3177. // appDelegate.customerInfo = value;
  3178. //
  3179. //
  3180. // if(appDelegate.order_code==nil)
  3181. // [self neworderforCart];
  3182. //
  3183. //
  3184. // };
  3185. //
  3186. // cvc.onCancel = ^(){
  3187. //
  3188. // [RAUtils message_alert:@"Cannot create order without customer infomation." title:@"" controller:self];
  3189. //
  3190. //
  3191. //
  3192. // };
  3193. // cvc.onReset = ^(){
  3194. // [self checklogin:true];
  3195. // };
  3196. //
  3197. // [self.navigationController pushViewController:cvc animated:true];
  3198. // }
  3199. // else
  3200. // {
  3201. // [self neworderforCart];
  3202. // }
  3203. //
  3204. // }
  3205. //}
  3206. -(void) neworderforCart
  3207. {
  3208. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Create Order" completion:^{
  3209. [RANetwork request_create_order:^(NSMutableDictionary *result) {
  3210. NSMutableDictionary* return_json = result;
  3211. [waitalert dismissViewControllerAnimated:YES completion:^{
  3212. if([[return_json valueForKey:@"result"] intValue]==2)
  3213. {
  3214. int result=[[return_json valueForKey:@"result"] intValue];
  3215. if(result==2)
  3216. {
  3217. //successed.
  3218. NSString* order_code = [return_json valueForKey:@"orderCode"];
  3219. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3220. appDelegate.order_code = order_code;
  3221. appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
  3222. self.previous_VC = self.current_VC;
  3223. [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  3224. #ifdef RA_NOTIFICATION
  3225. [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  3226. #else
  3227. [self reloadCart:true immediately:false];
  3228. [self reloadOrder:true immediately:false];
  3229. #endif
  3230. }
  3231. }
  3232. else
  3233. {
  3234. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
  3235. }
  3236. }];
  3237. }];
  3238. }];
  3239. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  3240. //
  3241. // NSDictionary* return_json = [RANetwork new_Order];
  3242. //
  3243. // dispatch_async(dispatch_get_main_queue(), ^{
  3244. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  3245. //
  3246. //
  3247. // if([[return_json valueForKey:@"result"] intValue]==2)
  3248. // {
  3249. // int result=[[return_json valueForKey:@"result"] intValue];
  3250. // if(result==2)
  3251. // {
  3252. // //successed.
  3253. //
  3254. // NSString* order_code = [return_json valueForKey:@"orderCode"];
  3255. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3256. // appDelegate.order_code = order_code;
  3257. // appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
  3258. //
  3259. // self.previous_VC = self.current_VC;
  3260. // [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  3261. //
  3262. //
  3263. //#ifdef RA_NOTIFICATION
  3264. // [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  3265. //#else
  3266. // [self reloadCart:true immediately:false];
  3267. // [self reloadOrder:true immediately:false];
  3268. //#endif
  3269. //
  3270. //
  3271. // }
  3272. // }
  3273. // else
  3274. // {
  3275. // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
  3276. // }
  3277. //
  3278. //
  3279. //
  3280. //
  3281. // });
  3282. // });
  3283. }
  3284. - (void)showPriceAuth:(NSInteger)from {
  3285. }
  3286. @end