MainViewController.m 120 KB

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