MainViewController.m 141 KB

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