MainViewController.m 80 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214
  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. @interface MainViewController ()
  25. @end
  26. @implementation MainViewController
  27. -(void) logoutDocuments
  28. {
  29. [self.pdfListViewController logout];
  30. }
  31. -(void) logoutCart
  32. {
  33. [self.cartViewController logout];
  34. }
  35. -(void) logoutWish
  36. {
  37. [self.watchListViewController logout];
  38. }
  39. -(void) logoutPortfolio
  40. {
  41. [self.portfolioViewController logout];
  42. }
  43. -(void) logoutOrder
  44. {
  45. [self.orderViewController logout];
  46. }
  47. -(void) logoutContact
  48. {
  49. [self.contactListViewController logout];
  50. }
  51. -(void) logoutCategory
  52. {
  53. [self.categoryViewController logout];
  54. }
  55. -(void) reloadCategory:(BOOL) update_data immediately:(bool)immediately
  56. {
  57. if(immediately)
  58. [ self.categoryViewController reload_container_getdata:update_data];
  59. else
  60. {
  61. if(update_data&&self.categoryViewController.refresh_type<=REFRESH_DATA)
  62. self.categoryViewController.refresh_type = REFRESH_DATA;
  63. else if(self.categoryViewController.refresh_type<=REFRESH_VIEW)
  64. self.categoryViewController.refresh_type = REFRESH_VIEW;
  65. }
  66. }
  67. -(void) reloadDocuments:(BOOL) update_data immediately:(bool)immediately
  68. {
  69. if(immediately)
  70. [ self.pdfListViewController reload_container_getdata:update_data];
  71. else
  72. {
  73. if(update_data&&self.pdfListViewController.refresh_type<=REFRESH_DATA)
  74. self.pdfListViewController.refresh_type = REFRESH_DATA;
  75. else if(self.pdfListViewController.refresh_type<=REFRESH_VIEW)
  76. self.pdfListViewController.refresh_type = REFRESH_VIEW;
  77. }
  78. //[self.pdfListViewController reload_container_getdata:update_data];
  79. }
  80. -(void) reloadCart:(BOOL) update_data immediately:(bool)immediately
  81. {
  82. if(immediately)
  83. [ self.cartViewController reload_container_getdata:update_data];
  84. else
  85. {
  86. if(update_data&&self.cartViewController.refresh_type<=REFRESH_DATA)
  87. self.cartViewController.refresh_type = REFRESH_DATA;
  88. else if(self.cartViewController.refresh_type<=REFRESH_VIEW)
  89. self.cartViewController.refresh_type = REFRESH_VIEW;
  90. }
  91. // [self.cartViewController reload_container_getdata:update_data];
  92. }
  93. -(void) reloadWish:(BOOL) update_data immediately:(bool)immediately
  94. {
  95. if(immediately)
  96. [ self.watchListViewController reload_container_getdata:update_data];
  97. else
  98. {
  99. if(update_data&&self.watchListViewController.refresh_type<=REFRESH_DATA)
  100. self.watchListViewController.refresh_type = REFRESH_DATA;
  101. else if(self.watchListViewController.refresh_type<=REFRESH_VIEW)
  102. self.watchListViewController.refresh_type = REFRESH_VIEW;
  103. }
  104. // [self.watchListViewController reload_container_getdata:update_data];
  105. }
  106. -(void) reloadPortfolio:(BOOL) update_data immediately:(bool)immediately
  107. {
  108. if(immediately)
  109. [ self.portfolioViewController reload_container_getdata:update_data];
  110. else
  111. {
  112. if(update_data&&self.portfolioViewController.refresh_type<=REFRESH_DATA)
  113. self.portfolioViewController.refresh_type = REFRESH_DATA;
  114. else if(self.portfolioViewController.refresh_type<=REFRESH_VIEW)
  115. self.portfolioViewController.refresh_type = REFRESH_VIEW;
  116. }
  117. // [self.portfolioViewController reload_container_getdata:update_data];
  118. }
  119. -(void) reloadOrder:(BOOL) update_data immediately:(bool)immediately
  120. {
  121. if(immediately)
  122. [ self.orderViewController reload_container_getdata:update_data];
  123. else
  124. {
  125. if(update_data&&self.orderViewController.refresh_type<=REFRESH_DATA)
  126. self.orderViewController.refresh_type = REFRESH_DATA;
  127. else if(self.orderViewController.refresh_type<=REFRESH_VIEW)
  128. self.orderViewController.refresh_type = REFRESH_VIEW;
  129. }
  130. // [self.orderViewController reload_container_getdata:update_data];
  131. }
  132. -(void) reloadContact:(BOOL) update_data immediately:(bool)immediately
  133. {
  134. //[self.con reload_container];
  135. if(immediately)
  136. [ self.contactListViewController reload_container_getdata:update_data];
  137. else
  138. {
  139. if(update_data&&self.contactListViewController.refresh_type<=REFRESH_DATA)
  140. self.contactListViewController.refresh_type = REFRESH_DATA;
  141. else if(self.contactListViewController.refresh_type<=REFRESH_VIEW)
  142. self.contactListViewController.refresh_type = REFRESH_VIEW;
  143. }
  144. }
  145. -(void)viewWillLayoutSubviews
  146. {
  147. self.headerView.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.headerView.bounds].CGPath;
  148. }
  149. -(void) viewWillAppear:(BOOL)animated
  150. {
  151. // [self.label_ccount.layer setMasksToBounds:YES];
  152. UIApplication * app = [UIApplication sharedApplication];
  153. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  154. // self.labelContact.text=appDelegate.contact_name;
  155. NSString * contact =[appDelegate.customerInfo valueForKey:@"customer_contact"];
  156. NSString * customer=[appDelegate.customerInfo valueForKey:@"customer_name"];
  157. if(contact==nil||contact.length==0)
  158. {
  159. contact=@"No Name";
  160. [self.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  161. }
  162. else
  163. {
  164. if(contact==nil||contact.length==0)
  165. {
  166. contact=@"No Name";
  167. [self.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  168. }
  169. else
  170. {
  171. [self.btnContact setTitleColor:UIColorFromRGB(0x009900) forState:UIControlStateNormal];
  172. }
  173. }
  174. NSMutableArray* arr_contact = [[NSMutableArray alloc] init];
  175. if(contact.length>0)
  176. [arr_contact addObject:contact];
  177. if(customer.length>0)
  178. [arr_contact addObject:customer];
  179. NSString *contact_string = [arr_contact componentsJoinedByString:@" @"];
  180. [self.btnContact setTitle:contact_string forState:UIControlStateNormal];
  181. [[self navigationController] setNavigationBarHidden:YES animated:NO];
  182. }
  183. - (void) checklogin:(bool) reloadCurrentVC
  184. {
  185. [self initMenuItems];
  186. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  187. self.sideMenu_UserName.text =appDelegate.user;
  188. if(appDelegate.bLogin)
  189. [self.btnLogin setTitle:@"Sign out" forState:UIControlStateNormal];
  190. else
  191. [self.btnLogin setTitle:@"Sign in" forState:UIControlStateNormal];
  192. [iSalesNetwork LoadImage:appDelegate.user_icon into:self.user_head ];
  193. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  194. self.btnContact.hidden = NO;
  195. else
  196. self.btnContact.hidden = YES;
  197. NSDictionary * customerinfo=appDelegate.customerInfo;
  198. NSString * contact=nil;
  199. NSString * customer=nil;
  200. if(customerinfo==nil)
  201. {
  202. contact=@"Select Contact";
  203. [self.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  204. }
  205. else
  206. {
  207. contact=[customerinfo valueForKey:@"customer_contact"];
  208. customer=[customerinfo valueForKey:@"customer_name"];
  209. if(contact==nil||contact.length==0)
  210. {
  211. contact=@"No Name";
  212. [self.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  213. }
  214. else
  215. {
  216. [self.btnContact setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
  217. }
  218. }
  219. NSMutableArray* arr_contact = [[NSMutableArray alloc] init];
  220. if(contact.length>0)
  221. [arr_contact addObject:contact];
  222. if(customer.length>0)
  223. [arr_contact addObject:customer];
  224. NSString *contact_string = [arr_contact componentsJoinedByString:@" @"];
  225. [self.btnContact setTitle:contact_string forState:UIControlStateNormal];
  226. // if(appDelegate.bLogin)
  227. // [self.buttonUser setTitle:appDelegate.user forState:UIControlStateNormal];
  228. // else
  229. // [self.buttonUser setTitle:@"Sign in" forState:UIControlStateNormal];
  230. [self reloadDocuments:true immediately:false];
  231. [self reloadCart:true immediately:false];
  232. [self reloadWish:true immediately:false];
  233. [self reloadPortfolio:true immediately:false];
  234. [self reloadOrder:true immediately:false];
  235. [self reloadContact:true immediately:false];
  236. [self reloadCategory:true immediately:false];
  237. ActiveViewController* lrvc = (ActiveViewController*)appDelegate.active_controller;
  238. if(reloadCurrentVC)
  239. {
  240. if(lrvc!=nil)
  241. [ lrvc refresh_on_login];
  242. }
  243. else
  244. {
  245. if(lrvc.refresh_type<=REFRESH_DATA)
  246. lrvc.refresh_type = REFRESH_DATA;
  247. else if(lrvc.refresh_type<=REFRESH_VIEW)
  248. lrvc.refresh_type = REFRESH_VIEW;
  249. }
  250. // [self reload];
  251. }
  252. - (IBAction)onContactClick:(id)sender {
  253. UIApplication * app = [UIApplication sharedApplication];
  254. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  255. NSString* contactid=appDelegate.contact_id ;
  256. if(contactid==nil)
  257. {
  258. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  259. cvc.update_order = true;
  260. cvc.edit_icon = true;
  261. cvc.assig_icon = true;
  262. cvc.reset_icon = false;
  263. cvc.showNavibar = true;
  264. cvc.contact_type = @"Sales_Order_Customer";
  265. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  266. appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  267. appDelegate.customerInfo = value;
  268. // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  269. //
  270. // if(self.returnValue)
  271. // self.returnValue(value);
  272. };
  273. [self.navigationController pushViewController:cvc animated:true];
  274. }
  275. else
  276. {
  277. CustomerInfoViewController * vc =[ self.storyboard instantiateViewControllerWithIdentifier:@"CustomerInfoViewController"];
  278. vc.url_type = URL_LOCAL;
  279. // if(appDelegate.order_code.length>0)
  280. {
  281. vc.edit_icon = false;
  282. vc.assig_icon = true;
  283. vc.reset_icon = true;
  284. vc.request_url=LOCAL_URL_CUSTOMER_INFO_EDIT;
  285. }
  286. // else
  287. // {
  288. // vc.edit_icon = false;
  289. // vc.assig_icon = false;
  290. // vc.reset_icon = true;
  291. // vc.request_url=LOCAL_URL_CUSTOMER_INFO_EDITOR;
  292. // }
  293. // NSDictionary* dd=appDelegate.customerInfo;;
  294. vc.data_init = appDelegate.customerInfo;
  295. vc.update_order = true;
  296. vc.contactId=contactid;
  297. // vc.delegate = self;
  298. vc.returnValue = ^(NSMutableDictionary* value){
  299. appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  300. appDelegate.customerInfo = value;
  301. };
  302. [self.navigationController pushViewController:vc animated:true];
  303. }
  304. }
  305. - (void)viewDidLoad
  306. {
  307. [super viewDidLoad];
  308. self.label_ccount.layer.cornerRadius=10.5;
  309. self.label_ccount.layer.masksToBounds=true;
  310. self.label_wcount.layer.cornerRadius=10.5;
  311. self.label_wcount.layer.masksToBounds=true;
  312. self.label_cccount.layer.cornerRadius=10.5;
  313. self.label_cccount.layer.masksToBounds=true;
  314. self.label_cwcount.layer.cornerRadius=10.5;
  315. self.label_cwcount.layer.masksToBounds=true;
  316. self.employee_bp.hidden = false;
  317. self.customer_bp.hidden = true;
  318. UIApplication * app = [UIApplication sharedApplication];
  319. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  320. appDelegate.main_vc = self;
  321. [appDelegate update_count_mark];
  322. NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  323. NSString* build =[infoDict objectForKey:@"CFBundleVersion"];
  324. NSString* version =[infoDict objectForKey:@"CFBundleShortVersionString"];
  325. NSString* versionNum = [NSString stringWithFormat:@"npd %@ Build %@",version,build];
  326. [self initMenuItems];
  327. self.homeViewController =[ self.storyboard instantiateViewControllerWithIdentifier:@"HomeViewController"];
  328. self.categoryViewController =[ self.storyboard instantiateViewControllerWithIdentifier:@"CategoryViewController"];
  329. self.cartViewController =[ self.storyboard instantiateViewControllerWithIdentifier:@"CartViewController"];
  330. self.orderViewController =[ self.storyboard instantiateViewControllerWithIdentifier:@"OrderListViewController"];
  331. self.contactListViewController =[ self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController"];
  332. self.contactListViewController.contact_type = @"Sales_Order_Customer";
  333. self.contactListViewController.edit_icon = true;
  334. self.contactListViewController.assig_icon = true;
  335. self.contactListViewController.reset_icon = false;
  336. self.contactListViewController.ui_type = CONTACT_LIST;
  337. self.contactListViewController.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  338. appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  339. appDelegate.customerInfo = value;
  340. // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  341. //
  342. // if(self.returnValue)
  343. // self.returnValue(value);
  344. };
  345. //Capturing strongly warring;
  346. __block MainViewController *brself= self;
  347. self.orderViewController.selectOrder=^(NSMutableDictionary* order_detail){
  348. //main view 下打开order
  349. //Capturing strongly warring;
  350. __block MainViewController *brbrself= brself;
  351. brself.cartViewController.onFinishLoad=^()
  352. {
  353. [brbrself.cartViewController placeOrder];
  354. brbrself.cartViewController.onFinishLoad=nil;
  355. };
  356. [brself switchToCart:nil];
  357. };
  358. self.watchListViewController =[ self.storyboard instantiateViewControllerWithIdentifier:@"WatchListViewController"];
  359. self.portfolioViewController =[ self.storyboard instantiateViewControllerWithIdentifier:@"PortfolioViewController"];
  360. self.pdfListViewController =[ self.storyboard instantiateViewControllerWithIdentifier:@"PDFListViewController"];
  361. self.itemSearchViewController=[ self.storyboard instantiateViewControllerWithIdentifier:@"ItemSearchViewController"];
  362. self.searchViewController=[ self.storyboard instantiateViewControllerWithIdentifier:@"SearchViewController"];
  363. [self addChildViewController:self.homeViewController]; //1
  364. self.homeViewController.view.frame = self.container.bounds;
  365. [self.container addSubview:self.homeViewController.view]; //2
  366. [self.homeViewController didMoveToParentViewController:self];
  367. self.current_VC = self.homeViewController;
  368. // self.is_home = true;
  369. // [UIBezierPath bezierPathWithRect:self.headerView.bounds].CGPath;
  370. self.headerView.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.headerView.bounds].CGPath;
  371. self.headerView.layer.masksToBounds = false;
  372. //添加四个边阴影
  373. self.headerView.layer.shadowColor = [UIColor blackColor].CGColor;
  374. self.headerView.layer.shadowOffset = CGSizeMake(0, 0);
  375. self.headerView.layer.shadowOpacity = 0.5;
  376. self.headerView.layer.shadowRadius = 2.0;
  377. self.labelVer.text=versionNum;
  378. // UIApplication * app = [UIApplication sharedApplication];
  379. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  380. if(appDelegate.categoryMenu==nil)
  381. {
  382. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  383. NSDictionary* category=[iSalesNetwork request_Cagegory];
  384. dispatch_async(dispatch_get_main_queue(), ^{
  385. if([[category valueForKey:@"result"] intValue]==2)
  386. {
  387. appDelegate.categoryMenu = category;
  388. }
  389. else
  390. {
  391. // [RAUtils error_alert:[category valueForKey:@"err_msg"] title:@"Failed to load category."] ;
  392. }
  393. // self.categoryViewController.categoryMenu = category;
  394. });
  395. });
  396. }
  397. // Do any additional setup after loading the view, typically from a nib.
  398. }
  399. - (IBAction)onmenuButtonClicked:(id)sender {
  400. self.openMenuButton.hidden = true;
  401. self.sideMenu.hidden = false;
  402. [self showMenu];
  403. }
  404. - (IBAction)switchMenu:(UIButton *)sender {
  405. // if(self.menuShown==true)
  406. [self hideMenu];
  407. self.openMenuButton.hidden = false;
  408. self.sideMenu.hidden = true;
  409. // else
  410. // [self showMenu];
  411. }
  412. -(void) Loginout:(bool)showlogin
  413. {
  414. UIApplication * app = [UIApplication sharedApplication];
  415. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  416. if(appDelegate.bLogin)
  417. {
  418. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Sign out"];
  419. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  420. NSDictionary* return_json = [iSalesNetwork logout];
  421. dispatch_async(dispatch_get_main_queue(), ^{
  422. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  423. if([[return_json valueForKey:@"result"] intValue]==2)
  424. {
  425. [self hideMenu];
  426. [self switchToHome:nil];
  427. [appDelegate Logout];
  428. if(showlogin)
  429. {
  430. LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  431. loginvc.returnValue = ^(bool blogin){
  432. [self checklogin :true];
  433. };
  434. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  435. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  436. [self presentViewController:navi animated:YES completion:^{
  437. NSLog(@"login present.........");
  438. }];
  439. }
  440. }
  441. else
  442. {
  443. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
  444. }
  445. });
  446. });
  447. }
  448. else
  449. {
  450. LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  451. loginvc.returnValue = ^(bool blogin){
  452. [self checklogin :true];
  453. };
  454. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  455. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  456. [self presentViewController:navi animated:YES completion:^{
  457. NSLog(@"login present.........");
  458. }];
  459. }
  460. }
  461. - (IBAction)OnLoginClick:(UIButton *)sender {
  462. [self Loginout:true];
  463. }
  464. - (IBAction)onScanClick:(id)sender {
  465. ScannerViewController * scannerVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"ScannerViewController"];
  466. [self.navigationController pushViewController:scannerVC animated:true];
  467. }
  468. - (IBAction)switchToSearch:(UIButton *)sender {
  469. if([self.current_VC isKindOfClass:[SearchViewController class]])
  470. return;
  471. [self flipFromViewController:self.current_VC toViewController:self.searchViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  472. }
  473. - (IBAction)switchToWishlist:(UIButton *)sender {
  474. [self switchtowishlist];
  475. }
  476. -(void)switchtowishlist
  477. {
  478. if([self.current_VC isKindOfClass:[WatchListViewController class]])
  479. return;
  480. // if([self.current_VC isKindOfClass:[OrderListViewController class]])
  481. // return;
  482. UIApplication * app = [UIApplication sharedApplication];
  483. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  484. if(appDelegate.bLogin==false)
  485. {
  486. LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  487. // loginvc.delegate = self;
  488. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  489. loginvc.returnValue = ^(bool blogin){
  490. if(blogin)
  491. {
  492. [self checklogin:true];
  493. [self flipFromViewController:self.current_VC toViewController:self.watchListViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  494. }
  495. };
  496. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  497. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  498. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  499. [self presentViewController:navi animated:YES completion:^{
  500. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  501. NSLog(@"LoginViewController present.........");
  502. // self.btop = false;
  503. // <#code#>
  504. }];
  505. }
  506. else
  507. [self flipFromViewController:self.current_VC toViewController:self.watchListViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  508. }
  509. - (IBAction)switchToContact:(UIButton *)sender {
  510. [self switchtocontact];
  511. }
  512. -(void)switchtocontact
  513. {
  514. if([self.current_VC isKindOfClass:[ContactListViewController class]])
  515. return;
  516. UIApplication * app = [UIApplication sharedApplication];
  517. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  518. if(appDelegate.bLogin==false)
  519. {
  520. LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  521. // loginvc.delegate = self;
  522. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  523. loginvc.returnValue = ^(bool blogin){
  524. if(blogin)
  525. {
  526. [self checklogin:true];
  527. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  528. {
  529. [self flipFromViewController:self.current_VC toViewController:self.contactListViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  530. }
  531. else
  532. {
  533. [RAUtils message_alert:@"Customer Login does not support this feature." title:@"Contact List" controller:self] ;
  534. }
  535. }
  536. };
  537. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  538. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  539. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  540. [self presentViewController:navi animated:YES completion:^{
  541. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  542. NSLog(@"LoginViewController present.........");
  543. // self.btop = false;
  544. // <#code#>
  545. }];
  546. }
  547. else
  548. [self flipFromViewController:self.current_VC toViewController:self.contactListViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  549. //
  550. // UIApplication * app = [UIApplication sharedApplication];
  551. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  552. // ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  553. // cvc.update_order = true;
  554. // cvc.contact_type = @"Sales_Order_Customer";
  555. // cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  556. //
  557. // appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  558. // appDelegate.customerInfo = value;
  559. //
  560. // // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  561. //
  562. // //
  563. // // if(self.returnValue)
  564. // // self.returnValue(value);
  565. // };
  566. // [self.navigationController pushViewController:cvc animated:true];
  567. }
  568. - (void) reload
  569. {
  570. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  571. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  572. NSDictionary* category=[iSalesNetwork request_Cagegory];
  573. dispatch_async(dispatch_get_main_queue(), ^{
  574. if([[category valueForKey:@"result"] intValue]==2)
  575. {
  576. appDelegate.categoryMenu = category;
  577. }
  578. else
  579. {
  580. // [RAUtils error_alert:[category valueForKey:@"err_msg"]] ;
  581. }
  582. });
  583. });
  584. }
  585. - (IBAction)onUserButtonClick:(id)sender {
  586. NSLog(@"header view login");
  587. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  588. if( appDelegate.user ==nil)
  589. {
  590. LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  591. // loginvc.delegate = self;
  592. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  593. loginvc.returnValue = ^(bool blogin){
  594. [self checklogin:true];
  595. };
  596. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  597. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  598. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  599. [self presentViewController:navi animated:YES completion:^{
  600. // <#code#>
  601. }];
  602. // LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  603. // loginvc.delegate = self;
  604. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  605. // [self presentViewController:loginvc animated:YES completion:^{
  606. //
  607. // NSLog(@"login.........");
  608. // // <#code#>
  609. // }];
  610. }
  611. }
  612. #pragma mark - LoginViewControllerDelegate
  613. -(void)LoginViewControllerDidLogin:(LoginViewController *)viewController
  614. {
  615. [viewController dismissViewControllerAnimated:YES completion:nil];
  616. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  617. self.sideMenu_UserName.text =appDelegate.user;
  618. [self.btnLogin setTitle:@"Sign out" forState:UIControlStateNormal];
  619. [iSalesNetwork LoadImage:appDelegate.user_icon into:self.user_head ];
  620. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  621. self.btnContact.hidden = NO;
  622. else
  623. self.btnContact.hidden = YES;
  624. NSDictionary * customerinfo=appDelegate.customerInfo;
  625. NSString * contact=nil;
  626. NSString * customer=nil;
  627. if(customerinfo==nil)
  628. {
  629. contact=@"Select Contact";
  630. [self.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  631. }
  632. else
  633. {
  634. contact=[customerinfo valueForKey:@"customer_contact"];
  635. customer=[customerinfo valueForKey:@"customer_name"];
  636. if(contact==nil||contact.length==0)
  637. {
  638. contact=@"No Name";
  639. [self.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  640. }
  641. else
  642. {
  643. [self.btnContact setTitleColor:UIColorFromRGB(0x009900) forState:UIControlStateNormal];
  644. }
  645. }
  646. NSMutableArray* arr_contact = [[NSMutableArray alloc] init];
  647. if(contact.length>0)
  648. [arr_contact addObject:contact];
  649. if(customer.length>0)
  650. [arr_contact addObject:customer];
  651. NSString *contact_string = [arr_contact componentsJoinedByString:@" @"];
  652. [self.btnContact setTitle:contact_string forState:UIControlStateNormal];
  653. // [self.buttonUser setTitle:appDelegate.user forState:UIControlStateNormal];
  654. [self reload];
  655. }
  656. - (void) flipFromViewController:(UIViewController*) fromController
  657. toViewController:(UIViewController*) toController
  658. withDirection:(UIViewAnimationOptions) direction
  659. {
  660. toController.view.frame = self.container.bounds; // 1
  661. // UIViewAutoresizingFlexibleLeftMargin = 1 << 0,
  662. // UIViewAutoresizingFlexibleWidth = 1 << 1,
  663. // UIViewAutoresizingFlexibleRightMargin = 1 << 2,
  664. // UIViewAutoresizingFlexibleTopMargin = 1 << 3,
  665. // UIViewAutoresizingFlexibleHeight = 1 << 4,
  666. // UIViewAutoresizingFlexibleBottomMargin = 1 << 5
  667. toController.view.autoresizingMask = UIViewAutoresizingFlexibleHeight |UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin;
  668. [self addChildViewController:toController]; //
  669. [fromController willMoveToParentViewController:nil]; //
  670. [self transitionFromViewController:fromController
  671. toViewController:toController
  672. duration:0.2
  673. options:direction | UIViewAnimationOptionCurveEaseIn
  674. animations:nil
  675. completion:^(BOOL finished) {
  676. [toController didMoveToParentViewController:self]; // 2
  677. [fromController removeFromParentViewController]; // 3
  678. self.current_VC = toController;
  679. }];
  680. }
  681. -(void)topicViewSelected:(int) type _id: (int) _id
  682. {
  683. [self switchToCagegory:nil];
  684. if(type==0)
  685. {
  686. // [self.categoryViewController showDetailat:_id];
  687. }
  688. else
  689. {
  690. [self.categoryViewController showCategory];
  691. }
  692. }
  693. -(void)categoryMenuSelected:(NSString*)_id
  694. {
  695. [self switchToCagegory:_id];
  696. // [self.categoryViewController showCategory];
  697. }
  698. - (void)switchToItemSearch:(NSString* )coverttype {
  699. // NSString* ttt =[@"Category" stringByAppendingString:[self categoryString:categoryid node:self.categoryMenu level:0]];
  700. // UIApplication * app = [UIApplication sharedApplication];
  701. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  702. self.itemSearchViewController.covertype = coverttype;
  703. self.itemSearchViewController.saved_covertype = coverttype;
  704. [self.itemSearchViewController reload_container_getdata:true];
  705. // .categoryString = [@"Category" stringByAppendingString:[self categoryString:categoryid node:appDelegate.categoryMenu level:0]];
  706. // self.categoryViewController.cagegoryLabel.text =self.categoryViewController.categoryString;
  707. // // NSString* sss =[@"Category" stringByAppendingString:[self categoryString:categoryid node:appDelegate.categoryMenu level:0]];
  708. // self.categoryViewController.categoryid = categoryid ;
  709. // [self.itemSearchViewController reload];
  710. // [self.itemSearchViewController showCategory];
  711. if([self.current_VC isKindOfClass:[ItemSearchViewController class]])
  712. return;
  713. [self flipFromViewController:self.current_VC toViewController:self.itemSearchViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  714. [[self navigationController] setNavigationBarHidden:YES animated:NO];
  715. // self.is_home = false;
  716. // self.current_vc = VC_CATEGORY;
  717. // [self.homeViewController willMoveToParentViewController:nil]; //1
  718. // [self.homeViewController.view removeFromSuperview]; //2
  719. // [self.homeViewController removeFromParentViewController]; //3
  720. //
  721. // [self.container addSubview:self.cagegoryViewController.view]; //2
  722. // [self.cagegoryViewController didMoveToParentViewController:self];
  723. }
  724. - (void)switchToCagegory:(NSString* )categoryid {
  725. // NSString* ttt =[@"Category" stringByAppendingString:[self categoryString:categoryid node:self.categoryMenu level:0]];
  726. UIApplication * app = [UIApplication sharedApplication];
  727. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  728. self.categoryViewController.categoryString = [@"Category" stringByAppendingString:[self categoryString:categoryid node:appDelegate.categoryMenu level:0]];
  729. self.categoryViewController.cagegoryLabel.text =self.categoryViewController.categoryString;
  730. // NSString* sss =[@"Category" stringByAppendingString:[self categoryString:categoryid node:appDelegate.categoryMenu level:0]];
  731. self.categoryViewController.categoryid = categoryid ;
  732. self.categoryViewController.p_alert = nil;
  733. self.categoryViewController.p_available = nil;
  734. self.categoryViewController.p_price = nil;
  735. self.categoryViewController.p_QTY = nil;
  736. [self.categoryViewController reload_container_getdata:true];
  737. [self.categoryViewController showCategory];
  738. if([self.current_VC isKindOfClass:[CategoryViewController class]])
  739. return;
  740. [self flipFromViewController:self.current_VC toViewController:self.categoryViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  741. [[self navigationController] setNavigationBarHidden:YES animated:NO];
  742. // self.is_home = false;
  743. // self.current_vc = VC_CATEGORY;
  744. // [self.homeViewController willMoveToParentViewController:nil]; //1
  745. // [self.homeViewController.view removeFromSuperview]; //2
  746. // [self.homeViewController removeFromParentViewController]; //3
  747. //
  748. // [self.container addSubview:self.cagegoryViewController.view]; //2
  749. // [self.cagegoryViewController didMoveToParentViewController:self];
  750. }
  751. - (IBAction)switchToHome:(UIButton *)sender {
  752. [self switchToHome];
  753. // self.current_vc = VC_HOME;
  754. // self.is_home = true;
  755. //
  756. // [self.cagegoryViewController willMoveToParentViewController:nil]; //1
  757. // [self.cagegoryViewController.view removeFromSuperview]; //2
  758. // [self.cagegoryViewController removeFromParentViewController]; //3
  759. //
  760. // [self.container addSubview:self.homeViewController.view]; //2
  761. // [self.homeViewController didMoveToParentViewController:self];
  762. }
  763. -(void)switchToHome
  764. {
  765. if([self.current_VC isKindOfClass:[HomeViewController class]])
  766. return;
  767. [self flipFromViewController:self.current_VC toViewController:self.homeViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  768. }
  769. -(void) switchToPreviousVC
  770. {
  771. if(self.previous_VC==nil)
  772. return;
  773. if([self.current_VC isKindOfClass:[self.previous_VC class]])
  774. return;
  775. [self flipFromViewController:self.current_VC toViewController:self.previous_VC withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  776. }
  777. - (IBAction)switchToCart:(UIButton *)sender {
  778. [self switchToCart];
  779. // self.current_vc = VC_HOME;
  780. }
  781. -(void) switchToCart
  782. {
  783. if([self.current_VC isKindOfClass:[CartViewController class]])
  784. return;
  785. UIApplication * app = [UIApplication sharedApplication];
  786. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  787. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  788. if(appDelegate.bLogin==false)
  789. {
  790. LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  791. // loginvc.delegate = self;
  792. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  793. loginvc.returnValue = ^(bool blogin){
  794. // UIApplication * app = [UIApplication sharedApplication];
  795. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  796. if(blogin)
  797. {
  798. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  799. {
  800. [self checklogin:false];
  801. if(appDelegate.can_create_order)
  802. {
  803. NSString* msg =@"";
  804. if(appDelegate.contact_id.length>0)
  805. {
  806. msg = [msg stringByAppendingString:@"\n\nCustomer:"];
  807. msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
  808. }
  809. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Switch To Cart", nil) message:msg delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Switch to pending order", nil),NSLocalizedString(@"Switch to new order", nil), nil];
  810. // alert.
  811. [alert show];
  812. }
  813. else
  814. {
  815. 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];
  816. // alert.
  817. [alert show];
  818. }
  819. }
  820. else
  821. {
  822. [self checklogin:true];
  823. self.previous_VC = self.current_VC;
  824. [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  825. }
  826. }
  827. // self.offset = 0;
  828. // [self.content_data removeAllObjects];
  829. // [self loadpage];
  830. //
  831. // [[self navigationController] setNavigationBarHidden:YES animated:NO];
  832. };
  833. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  834. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  835. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  836. [self presentViewController:navi animated:YES completion:^{
  837. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  838. NSLog(@"LoginViewController present.........");
  839. // self.btop = false;
  840. // <#code#>
  841. }];
  842. }
  843. else
  844. {
  845. if(appDelegate.user_type==USER_ROLE_EMPLOYEE&&/*appDelegate.contact_id==nil&&*/appDelegate.order_code==nil)
  846. {
  847. [self checklogin:false];
  848. if(appDelegate.can_create_order)
  849. {
  850. NSString* msg =@"";
  851. if(appDelegate.contact_id.length>0)
  852. {
  853. msg = [msg stringByAppendingString:@"\n\nCustomer:"];
  854. msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
  855. }
  856. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Switch to cart", nil) message:msg delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Switch to pending order", nil),NSLocalizedString(@"Switch to new order", nil), nil];
  857. // alert.
  858. [alert show];
  859. }
  860. else
  861. {
  862. 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(@"Switcht to pending order", nil), nil];
  863. // alert.
  864. [alert show];
  865. }
  866. }
  867. else
  868. {
  869. self.previous_VC = self.current_VC;
  870. [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  871. }
  872. }
  873. }
  874. -(void) switchToOrder
  875. {
  876. if([self.current_VC isKindOfClass:[OrderListViewController class]])
  877. return;
  878. UIApplication * app = [UIApplication sharedApplication];
  879. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  880. if(appDelegate.bLogin==false)
  881. {
  882. LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  883. // loginvc.delegate = self;
  884. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  885. loginvc.returnValue = ^(bool blogin){
  886. if(blogin)
  887. {
  888. [self checklogin:true];
  889. [self flipFromViewController:self.current_VC toViewController:self.orderViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  890. }
  891. };
  892. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  893. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  894. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  895. [self presentViewController:navi animated:YES completion:^{
  896. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  897. NSLog(@"LoginViewController present.........");
  898. // self.btop = false;
  899. // <#code#>
  900. }];
  901. }
  902. else
  903. [self flipFromViewController:self.current_VC toViewController:self.orderViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  904. }
  905. - (IBAction)switchToOrder:(id)sender {
  906. [self switchToOrder];
  907. //self.orderViewController =[ self.storyboard instantiateViewControllerWithIdentifier:@"OrderListViewController"];
  908. }
  909. #pragma mark - CategoryMenuDelegate
  910. -(void)SelectCategory:(NSString *)category
  911. {
  912. [self switchToCagegory:category];
  913. }
  914. - (IBAction)showCategoryMenu:(id)sender {
  915. RAViewController * categorymenuVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"RAViewController"];
  916. // categorymenuVC.rootViewController = self;
  917. categorymenuVC.CateMenu_delegate = self;
  918. // categorymenuVC.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  919. // [self presentViewController:categorymenuVC animated:YES completion:^{
  920. //
  921. // NSLog(@"login.........");
  922. // // <#code#>
  923. // }];
  924. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:categorymenuVC] ;
  925. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  926. [self presentViewController:navi animated:YES completion:^{
  927. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  928. NSLog(@"bundle present.........");
  929. // self.btop = false;
  930. // <#code#>
  931. }];
  932. // if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
  933. // categorymenuVC.providesPresentationContextTransitionStyle = YES;
  934. // categorymenuVC.definesPresentationContext = YES;
  935. // categorymenuVC.modalPresentationStyle = UIModalPresentationFormSheet;
  936. // [self presentViewController:categorymenuVC animated:YES completion:nil];
  937. // } else {
  938. // categorymenuVC.modalPresentationStyle = UIModalPresentationFormSheet;
  939. // [self presentViewController:categorymenuVC animated:NO completion:nil];
  940. //// self.view.window.rootViewController.modalPresentationStyle = UIModalPresentationFullScreen;
  941. // }
  942. UIApplication * app = [UIApplication sharedApplication];
  943. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  944. if(appDelegate.categoryMenu == nil)
  945. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  946. NSDictionary* category=[iSalesNetwork request_Cagegory];
  947. dispatch_async(dispatch_get_main_queue(), ^{
  948. if([[category valueForKey:@"result"] intValue]==2)
  949. {
  950. appDelegate.categoryMenu = category;
  951. [categorymenuVC SetMenu:appDelegate.categoryMenu ];
  952. }
  953. else
  954. if([[category valueForKey:@"result"] intValue]==RESULT_NET_ERROR)
  955. {
  956. [categorymenuVC SetMenu:nil ];
  957. }
  958. else
  959. {
  960. [RAUtils message_alert:[category valueForKey:@"err_msg"] title:@"Load Category Menu" controller:self] ;
  961. }
  962. });
  963. });
  964. else
  965. [categorymenuVC SetMenu:appDelegate.categoryMenu];
  966. }
  967. -(NSString*) categoryString:(NSString*) categoryid node:(NSDictionary*) json level:(int) level;
  968. {
  969. if(categoryid.length==0)
  970. return @">All Products>";
  971. //NSString* idString = [NSString stringWithFormat:@"%d",categoryid];
  972. NSString* categoryString =@">";
  973. int count = [[json valueForKey:@"count"] intValue];
  974. for(int i=0;i<count;i++)
  975. {
  976. NSDictionary * category_json = [json objectForKey:[NSString stringWithFormat:@"category_%d",i]];
  977. NSString* cid = [category_json valueForKey:@"id"] ;
  978. // NSString* ttt =[categoryid substringToIndex:2+level*2];
  979. // NSString * qqq =[cid substringToIndex:2+level*2];
  980. // NSString *ds1=[categoryid substringToIndex:3+level*3];
  981. // NSString*ds2 = [cid substringToIndex:3+level*3];
  982. if(cid.length<3+level*3)
  983. continue;
  984. if(categoryid.length<3+level*3)
  985. continue;
  986. if([[categoryid substringToIndex:3+level*3] isEqualToString: [cid substringToIndex:3+level*3]])
  987. {
  988. //categoryString = [categoryString stringByAppendingString:@">"];
  989. categoryString =[categoryString stringByAppendingString: [category_json valueForKey:@"title" ] ];
  990. categoryString = [categoryString stringByAppendingString:[ self categoryString:categoryid node:category_json level:level+1]];
  991. break;
  992. }
  993. }
  994. return categoryString;
  995. }
  996. - (void)didReceiveMemoryWarning
  997. {
  998. [super didReceiveMemoryWarning];
  999. // Dispose of any resources that can be recreated.
  1000. }
  1001. - (IBAction)openMenu:(UIButton *)sender {
  1002. [self showMenu];
  1003. // [((RootContainerViewController *)self.parentViewController) showMenu];
  1004. // SideMenuViewController *sideMenuController = [self.storyboard instantiateViewControllerWithIdentifier:@"SideMenuViewController"];
  1005. // if (sideMenuController) {
  1006. // //[sideMenuController openMenu];
  1007. // [UIView animateWithDuration:1.0 animations:^{ sideMenuController.view.alpha = 1.0;
  1008. // self.view.alpha = 0.0; }];
  1009. // }
  1010. }
  1011. - (UIImage*)screen_shot
  1012. {
  1013. // CGRect r = self.view.frame;
  1014. // CGRect r1 = self.view.bounds;
  1015. // double width,height;
  1016. //
  1017. // UIInterfaceOrientation orientation =[UIApplication sharedApplication].statusBarOrientation;
  1018. // ;
  1019. // if(orientation == UIDeviceOrientationLandscapeLeft ||orientation == UIDeviceOrientationLandscapeRight)
  1020. // {
  1021. // width = self.view.frame.size.width>self.view.frame.size.height? self.view.frame.size.width:self.view.frame.size.height;
  1022. // height =self.view.frame.size.width<self.view.frame.size.height? self.view.frame.size.width:self.view.frame.size.height;
  1023. // }
  1024. // else
  1025. // {
  1026. // width = self.view.frame.size.width<self.view.frame.size.height? self.view.frame.size.width:self.view.frame.size.height;
  1027. // height =self.view.frame.size.width>self.view.frame.size.height? self.view.frame.size.width:self.view.frame.size.height;
  1028. // }
  1029. UIGraphicsBeginImageContext(CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height));
  1030. [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
  1031. UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
  1032. UIGraphicsEndImageContext();
  1033. return viewImage;
  1034. }
  1035. - (IBAction)onhideMenuClick:(id)sender {
  1036. [self hideMenu];
  1037. self.backgroundButton.hidden=true;
  1038. self.openMenuButton.hidden = false;
  1039. self.sideMenu.hidden = true;
  1040. }
  1041. - (void)hideMenu
  1042. {
  1043. CGRect frame ;
  1044. frame.origin.x = -300;
  1045. frame.origin.y = 0;
  1046. frame.size.height = self.view.bounds.size.height;
  1047. frame.size.width = 364;
  1048. self.sideMenu.frame=frame;
  1049. self.sideMenu.hidden = true;
  1050. self.blurView.alpha = 0;
  1051. [self.menuButton setImage:[UIImage imageNamed:@"menu_open"] forState:UIControlStateNormal];
  1052. self.menuShown = false;
  1053. self.backgroundButton.hidden=true;
  1054. self.openMenuButton.hidden = false;
  1055. }
  1056. - (void)showMenu
  1057. {
  1058. [self.sideMenuTable reloadData];
  1059. UIImage* imgsource = [self screen_shot];
  1060. self.blurView.alpha = 0;
  1061. UIImage* imgBlur =[self applyBlurWithRadius:5 sourceImage:imgsource tintColor:[UIColor colorWithWhite:0.2 alpha:0.73] saturationDeltaFactor:1.8 maskImage:nil];
  1062. self.blurView.image = imgBlur;
  1063. // self.blurView.hidden = imgBlur;
  1064. // [self.sideMenu becomeFirstResponder];
  1065. self.sideMenu.hidden = false;
  1066. self.backgroundButton.hidden=false;
  1067. CGRect frame ;
  1068. frame.origin.x = 0;
  1069. frame.origin.y = 0;
  1070. frame.size.height = self.view.bounds.size.height;
  1071. frame.size.width = 364;
  1072. // [UIView animateWithDuration:1.0 animations:^{ self.sideMenu.frame=frame;
  1073. // self.blurView.alpha = 1;
  1074. // [self.menuButton setImage:[UIImage imageNamed:@"menu"] forState:UIControlStateNormal];
  1075. //
  1076. // }];
  1077. [UIView animateWithDuration:0.5 animations:^{ self.sideMenu.frame=frame;
  1078. self.blurView.alpha = 1;
  1079. }
  1080. completion:^(BOOL finished) {
  1081. [self.menuButton setImage:[UIImage imageNamed:@"menu"] forState:UIControlStateNormal];
  1082. }];
  1083. // UIImage* img= [UIImage imageNamed:@"menu"];
  1084. // self.menuButton.imageView.image = nil;
  1085. self.menuShown = true;
  1086. }
  1087. -(void)initMenuItems
  1088. {
  1089. UIApplication * app = [UIApplication sharedApplication];
  1090. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1091. self.sideMenuItems = [[NSMutableArray alloc] init];
  1092. NSMutableDictionary* map = [[NSMutableDictionary alloc] init];
  1093. if(appDelegate.user!=nil)
  1094. {
  1095. [map setValue:@"Wish List" forKey:@"title"];
  1096. [map setValue:@"rect_market_news" forKey:@"img"];
  1097. [self.sideMenuItems addObject:map.copy];
  1098. }
  1099. // if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  1100. {
  1101. [map setValue:@"Cam Scan" forKey:@"title"];
  1102. [map setValue:@"rect_contact_list" forKey:@"img"];
  1103. [self.sideMenuItems addObject:map.copy];
  1104. }
  1105. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  1106. {
  1107. // [map setValue:@"Contact" forKey:@"title"];
  1108. // [map setValue:@"rect_contact_list" forKey:@"img"];
  1109. // [self.sideMenuItems addObject:map.copy];
  1110. [map setValue:@"Portfolio" forKey:@"title"];
  1111. [map setValue:@"rect_market_news" forKey:@"img"];
  1112. [self.sideMenuItems addObject:map.copy];
  1113. [map setValue:@"View Portfolios" forKey:@"title"];
  1114. [map setValue:@"rect_pdf_list" forKey:@"img"];
  1115. [self.sideMenuItems addObject:map.copy];
  1116. }
  1117. if(appDelegate.can_show_price)
  1118. {
  1119. if(appDelegate.price_hidden)
  1120. [map setValue:@"Show Price" forKey:@"title"];
  1121. else
  1122. [map setValue:@"Hide Price" forKey:@"title"];
  1123. [map setValue:@"rect_announcements" forKey:@"img"];
  1124. [self.sideMenuItems addObject:map.copy];
  1125. }
  1126. // [map setValue:@"Contact" forKey:@"title"];
  1127. // [map setValue:@"rect_market_news" forKey:@"img"];
  1128. // [self.sideMenuItems addObject:map.copy];
  1129. [map setValue:@"Cache" forKey:@"title"];
  1130. [map setValue:@"rect_announcements" forKey:@"img"];
  1131. [self.sideMenuItems addObject:map.copy];
  1132. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  1133. // [map setValue:@"Message" forKey:@"title"];
  1134. // [map setValue:@"rect_search_history" forKey:@"img"];
  1135. // [self.sideMenuItems addObject:map.copy];
  1136. //
  1137. [map setValue:@"Scanner Setting" forKey:@"title"];
  1138. [map setValue:@"rect_change_password" forKey:@"img"];
  1139. [self.sideMenuItems addObject:map.copy];
  1140. // if(appDelegate.user!=nil)
  1141. // {
  1142. // [map setValue:@"Offline data" forKey:@"title"];
  1143. // [map setValue:@"rect_market_news" forKey:@"img"];
  1144. // [self.sideMenuItems addObject:map.copy];
  1145. //
  1146. //
  1147. //
  1148. // }
  1149. // if([[appDelegate.user lowercaseString] isEqualToString:@"larryl"]||[[appDelegate.user lowercaseString] isEqualToString:@"arpithat"])
  1150. // {
  1151. // // [map setValue:@"Contact" forKey:@"title"];
  1152. // // [map setValue:@"rect_contact_list" forKey:@"img"];
  1153. // // [self.sideMenuItems addObject:map.copy];
  1154. //
  1155. //
  1156. // [map setValue:@"Function Test" forKey:@"title"];
  1157. // [map setValue:@"rect_market_news" forKey:@"img"];
  1158. // [self.sideMenuItems addObject:map.copy];
  1159. //
  1160. //
  1161. // }
  1162. //
  1163. [map setValue:@"About us" forKey:@"title"];
  1164. [map setValue:@"rect_change_password" forKey:@"img"];
  1165. [self.sideMenuItems addObject:map.copy];
  1166. [map setValue:@"NPD Website" forKey:@"title"];
  1167. [map setValue:@"rect_change_password" forKey:@"img"];
  1168. [self.sideMenuItems addObject:map.copy];
  1169. [map setValue:@"NPD Policy" forKey:@"title"];
  1170. [map setValue:@"rect_change_password" forKey:@"img"];
  1171. [self.sideMenuItems addObject:map.copy];
  1172. [map setValue:@"Simplified Buying Program" forKey:@"title"];
  1173. [map setValue:@"rect_change_password" forKey:@"img"];
  1174. [self.sideMenuItems addObject:map.copy];
  1175. [self.sideMenuTable reloadData];
  1176. //
  1177. }
  1178. - (UIImage *)applyBlurWithRadius:(CGFloat)blurRadius sourceImage:(UIImage*)sourceImage tintColor:(UIColor *)tintColor saturationDeltaFactor:(CGFloat)saturationDeltaFactor maskImage:(UIImage *)maskImage
  1179. {
  1180. // Check pre-conditions.
  1181. if (sourceImage.size.width < 1 || sourceImage.size.height < 1) {
  1182. NSLog (@"*** error: invalid size: (%.2f x %.2f). Both dimensions must be >= 1: %@", sourceImage.size.width, sourceImage.size.height, self);
  1183. return nil;
  1184. }
  1185. if (!sourceImage.CGImage) {
  1186. NSLog (@"*** error: image must be backed by a CGImage: %@", self);
  1187. return nil;
  1188. }
  1189. if (maskImage && !maskImage.CGImage) {
  1190. NSLog (@"*** error: maskImage must be backed by a CGImage: %@", maskImage);
  1191. return nil;
  1192. }
  1193. CGRect imageRect = { CGPointZero, sourceImage.size };
  1194. UIImage *effectImage = sourceImage;
  1195. BOOL hasBlur = blurRadius > __FLT_EPSILON__;
  1196. BOOL hasSaturationChange = fabs(saturationDeltaFactor - 1.) > __FLT_EPSILON__;
  1197. if (hasBlur || hasSaturationChange) {
  1198. UIGraphicsBeginImageContextWithOptions(sourceImage.size, NO, [[UIScreen mainScreen] scale]);
  1199. CGContextRef effectInContext = UIGraphicsGetCurrentContext();
  1200. CGContextScaleCTM(effectInContext, 1.0, -1.0);
  1201. CGContextTranslateCTM(effectInContext, 0, -sourceImage.size.height);
  1202. CGContextDrawImage(effectInContext, imageRect, sourceImage.CGImage);
  1203. vImage_Buffer effectInBuffer;
  1204. effectInBuffer.data = CGBitmapContextGetData(effectInContext);
  1205. effectInBuffer.width = CGBitmapContextGetWidth(effectInContext);
  1206. effectInBuffer.height = CGBitmapContextGetHeight(effectInContext);
  1207. effectInBuffer.rowBytes = CGBitmapContextGetBytesPerRow(effectInContext);
  1208. UIGraphicsBeginImageContextWithOptions(sourceImage.size, NO, [[UIScreen mainScreen] scale]);
  1209. CGContextRef effectOutContext = UIGraphicsGetCurrentContext();
  1210. vImage_Buffer effectOutBuffer;
  1211. effectOutBuffer.data = CGBitmapContextGetData(effectOutContext);
  1212. effectOutBuffer.width = CGBitmapContextGetWidth(effectOutContext);
  1213. effectOutBuffer.height = CGBitmapContextGetHeight(effectOutContext);
  1214. effectOutBuffer.rowBytes = CGBitmapContextGetBytesPerRow(effectOutContext);
  1215. if (hasBlur) {
  1216. // A description of how to compute the box kernel width from the Gaussian
  1217. // radius (aka standard deviation) appears in the SVG spec:
  1218. // http://www.w3.org/TR/SVG/filters.html#feGaussianBlurElement
  1219. //
  1220. // For larger values of 's' (s >= 2.0), an approximation can be used: Three
  1221. // successive box-blurs build a piece-wise quadratic convolution kernel, which
  1222. // approximates the Gaussian kernel to within roughly 3%.
  1223. //
  1224. // let d = floor(s * 3*sqrt(2*pi)/4 + 0.5)
  1225. //
  1226. // ... if d is odd, use three box-blurs of size 'd', centered on the output pixel.
  1227. //
  1228. CGFloat inputRadius = blurRadius * [[UIScreen mainScreen] scale];
  1229. NSUInteger radius = floor(inputRadius * 3. * sqrt(2 * M_PI) / 4 + 0.5);
  1230. if (radius % 2 != 1) {
  1231. radius += 1; // force radius to be odd so that the three box-blur methodology works.
  1232. }
  1233. vImageBoxConvolve_ARGB8888(&effectInBuffer, &effectOutBuffer, NULL, 0, 0, (unsigned int)radius, (unsigned int)radius, 0, kvImageEdgeExtend);
  1234. vImageBoxConvolve_ARGB8888(&effectOutBuffer, &effectInBuffer, NULL, 0, 0, (unsigned int)radius, (unsigned int)radius, 0, kvImageEdgeExtend);
  1235. vImageBoxConvolve_ARGB8888(&effectInBuffer, &effectOutBuffer, NULL, 0, 0, (unsigned int)radius, (unsigned int)radius, 0, kvImageEdgeExtend);
  1236. }
  1237. BOOL effectImageBuffersAreSwapped = NO;
  1238. if (hasSaturationChange) {
  1239. CGFloat s = saturationDeltaFactor;
  1240. CGFloat floatingPointSaturationMatrix[] = {
  1241. 0.0722 + 0.9278 * s, 0.0722 - 0.0722 * s, 0.0722 - 0.0722 * s, 0,
  1242. 0.7152 - 0.7152 * s, 0.7152 + 0.2848 * s, 0.7152 - 0.7152 * s, 0,
  1243. 0.2126 - 0.2126 * s, 0.2126 - 0.2126 * s, 0.2126 + 0.7873 * s, 0,
  1244. 0, 0, 0, 1,
  1245. };
  1246. const int32_t divisor = 256;
  1247. NSUInteger matrixSize = sizeof(floatingPointSaturationMatrix)/sizeof(floatingPointSaturationMatrix[0]);
  1248. int16_t saturationMatrix[matrixSize];
  1249. for (NSUInteger i = 0; i < matrixSize; ++i) {
  1250. saturationMatrix[i] = (int16_t)roundf(floatingPointSaturationMatrix[i] * divisor);
  1251. }
  1252. if (hasBlur) {
  1253. vImageMatrixMultiply_ARGB8888(&effectOutBuffer, &effectInBuffer, saturationMatrix, divisor, NULL, NULL, kvImageNoFlags);
  1254. effectImageBuffersAreSwapped = YES;
  1255. }
  1256. else {
  1257. vImageMatrixMultiply_ARGB8888(&effectInBuffer, &effectOutBuffer, saturationMatrix, divisor, NULL, NULL, kvImageNoFlags);
  1258. }
  1259. }
  1260. if (!effectImageBuffersAreSwapped)
  1261. effectImage = UIGraphicsGetImageFromCurrentImageContext();
  1262. UIGraphicsEndImageContext();
  1263. if (effectImageBuffersAreSwapped)
  1264. effectImage = UIGraphicsGetImageFromCurrentImageContext();
  1265. UIGraphicsEndImageContext();
  1266. }
  1267. // Set up output context.
  1268. UIGraphicsBeginImageContextWithOptions(sourceImage.size, NO, [[UIScreen mainScreen] scale]);
  1269. CGContextRef outputContext = UIGraphicsGetCurrentContext();
  1270. CGContextScaleCTM(outputContext, 1.0, -1.0);
  1271. CGContextTranslateCTM(outputContext, 0, -sourceImage.size.height);
  1272. // Draw base image.
  1273. CGContextDrawImage(outputContext, imageRect, sourceImage.CGImage);
  1274. // Draw effect image.
  1275. if (hasBlur) {
  1276. CGContextSaveGState(outputContext);
  1277. if (maskImage) {
  1278. CGContextClipToMask(outputContext, imageRect, maskImage.CGImage);
  1279. }
  1280. CGContextDrawImage(outputContext, imageRect, effectImage.CGImage);
  1281. CGContextRestoreGState(outputContext);
  1282. }
  1283. // Add in color tint.
  1284. if (tintColor) {
  1285. CGContextSaveGState(outputContext);
  1286. CGContextSetFillColorWithColor(outputContext, tintColor.CGColor);
  1287. CGContextFillRect(outputContext, imageRect);
  1288. CGContextRestoreGState(outputContext);
  1289. }
  1290. // Output image is ready.
  1291. UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext();
  1292. UIGraphicsEndImageContext();
  1293. return outputImage;
  1294. }
  1295. //- (IBAction)openMenu:(UIButton *)sender {
  1296. //}
  1297. #pragma mark - Table view data source
  1298. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  1299. {
  1300. return 1;
  1301. }
  1302. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  1303. {
  1304. return self.sideMenuItems.count;
  1305. }
  1306. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  1307. {
  1308. UIApplication * app = [UIApplication sharedApplication];
  1309. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1310. NSString *CellIdentifier = @"SideMenuItem";
  1311. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1312. NSString* title = [self.sideMenuItems[indexPath.row] valueForKey:@"title"];
  1313. cell.backgroundColor = [UIColor clearColor];
  1314. // [cell.backgroundColor:[UIColor clearColor]];
  1315. // UIImageView* iv= [[UIImageView alloc] initWithImage:];
  1316. cell.textLabel.text = title;
  1317. cell.detailTextLabel.textColor =[UIColor redColor];
  1318. if([title isEqualToString:@"Wish List"]&&appDelegate.wish_count>0)
  1319. cell.detailTextLabel.text = [NSString stringWithFormat:@"%ld",appDelegate.wish_count];
  1320. else if([title isEqualToString:@"Portfolio"]&&appDelegate.port_count>0)
  1321. cell.detailTextLabel.text = [NSString stringWithFormat:@"%ld",appDelegate.port_count];
  1322. else
  1323. {
  1324. cell.detailTextLabel.text =nil;
  1325. }
  1326. // cell.imageView.image = [UIImage imageNamed:[self.toolsinfo[indexPath.row] valueForKey:@"img"]];
  1327. return cell;
  1328. }
  1329. #pragma mark - Table view delegate
  1330. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  1331. {
  1332. NSString* title = [self.sideMenuItems[indexPath.row] valueForKey:@"title"];
  1333. if([title isEqualToString:@"Cache"])
  1334. {
  1335. CacheViewController * settingvc=[ self.storyboard instantiateViewControllerWithIdentifier:@"CacheViewController"];
  1336. PopupNavigationController * navi=[[PopupNavigationController alloc] initWithRootViewController:settingvc];
  1337. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1338. [self presentViewController:navi animated:YES completion:^{
  1339. //NSLog(@"login.........");
  1340. // <#code#>
  1341. }];
  1342. }
  1343. else if([title isEqualToString:@"Scanner Setting"])
  1344. {
  1345. UIApplication * app = [UIApplication sharedApplication];
  1346. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1347. UIViewController* active_vc = appDelegate.active_controller;
  1348. ScannerSettingViewController * gunVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"ScannerSettingViewController"];
  1349. // loginvc.delegate = self;
  1350. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1351. appDelegate.active_controller = gunVC;
  1352. gunVC.onDismissVC = ^(){
  1353. appDelegate.active_controller = active_vc;
  1354. };
  1355. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:gunVC] ;
  1356. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1357. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  1358. [self presentViewController:navi animated:YES completion:^{
  1359. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1360. NSLog(@"about present.........");
  1361. // self.btop = false;
  1362. // <#code#>
  1363. }];
  1364. }
  1365. else if([title isEqualToString:@"Offline data"])
  1366. {
  1367. [iSalesDB testdata];
  1368. }
  1369. else if([title isEqualToString:@"Function Test"])
  1370. {
  1371. // NSString* url = @"https://www.newpacificdirect.com";
  1372. //
  1373. //
  1374. // NSString* title = @"NPD";
  1375. // UIApplication * app = [UIApplication sharedApplication];
  1376. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1377. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  1378. //
  1379. //
  1380. FunctionTestViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"FunctionTestViewController"];
  1381. // ViewController.url = url;
  1382. // ViewController.title = title;
  1383. [self.navigationController pushViewController:ViewController animated:YES];
  1384. }
  1385. else if([title isEqualToString:@"NPD Website"])
  1386. {
  1387. NSString* url = @"https://www.newpacificdirect.com";//@"https://www.newpacificdirect.com/general.htm?websiteId=1";//
  1388. NSString* title = @"NPD";
  1389. // UIApplication * app = [UIApplication sharedApplication];
  1390. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1391. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  1392. //
  1393. //
  1394. WebViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"WebViewController"];
  1395. ViewController.url = url;
  1396. ViewController.title = title;
  1397. [self.navigationController pushViewController:ViewController animated:YES];
  1398. }
  1399. else if([title isEqualToString:@"NPD Policy"])
  1400. {
  1401. NSString* url = URL_NPD_POLICY;//@"https://www.newpacificdirect.com/general.htm?websiteId=1";//
  1402. NSString* title = @"NPD Policy";
  1403. // UIApplication * app = [UIApplication sharedApplication];
  1404. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1405. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  1406. //
  1407. //
  1408. WebViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"WebViewController"];
  1409. ViewController.url = url;
  1410. ViewController.title = title;
  1411. [self.navigationController pushViewController:ViewController animated:YES];
  1412. }
  1413. else if([title isEqualToString:@"Simplified Buying Program"])
  1414. {
  1415. SimplifiedBuyingProgramViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"SimplifiedBuyingProgramViewController"];
  1416. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:ViewController] ;
  1417. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1418. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  1419. [self presentViewController:navi animated:YES completion:^{
  1420. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1421. NSLog(@"about present.........");
  1422. // self.btop = false;
  1423. // <#code#>
  1424. }];
  1425. }
  1426. else if([title isEqualToString:@"About us"])
  1427. {
  1428. AboutViewController * aboutVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"AboutViewController"];
  1429. // loginvc.delegate = self;
  1430. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1431. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:aboutVC] ;
  1432. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1433. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  1434. [self presentViewController:navi animated:YES completion:^{
  1435. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1436. NSLog(@"about present.........");
  1437. // self.btop = false;
  1438. // <#code#>
  1439. }];
  1440. }
  1441. else if([title isEqualToString:@"Wish List"])
  1442. {
  1443. [self hideMenu];
  1444. [self switchtowishlist];
  1445. }
  1446. else if([title isEqualToString:@"Show Price"])
  1447. {
  1448. UIApplication * app = [UIApplication sharedApplication];
  1449. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1450. [appDelegate set_priceHidden:false];
  1451. //appDelegate.price_hidden = false;
  1452. //[self.sideMenuTable reloadData];
  1453. [self initMenuItems];
  1454. [self hideMenu];
  1455. // if([self.current_VC isKindOfClass:[WatchListViewController class]])
  1456. // return;
  1457. // [self flipFromViewController:self.current_VC toViewController:self.watchListViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1458. }
  1459. else if([title isEqualToString:@"Hide Price"])
  1460. {
  1461. UIApplication * app = [UIApplication sharedApplication];
  1462. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1463. [appDelegate set_priceHidden:true];
  1464. // appDelegate.price_hidden = true;
  1465. [self initMenuItems];
  1466. // [self.sideMenuTable reloadData];
  1467. [self hideMenu];
  1468. // if([self.current_VC isKindOfClass:[WatchListViewController class]])
  1469. // return;
  1470. // [self flipFromViewController:self.current_VC toViewController:self.watchListViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1471. }
  1472. else if([title isEqualToString:@"Portfolio"])
  1473. {
  1474. [self hideMenu];
  1475. if([self.current_VC isKindOfClass:[PortfolioViewController class]])
  1476. return;
  1477. [self flipFromViewController:self.current_VC toViewController:self.portfolioViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1478. }
  1479. else if([title isEqualToString:@"View Portfolios"])
  1480. {
  1481. [self hideMenu];
  1482. if([self.current_VC isKindOfClass:[PDFListViewController class]])
  1483. return;
  1484. [self flipFromViewController:self.current_VC toViewController:self.pdfListViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1485. }
  1486. else if([title isEqualToString:@"Contact"])
  1487. {
  1488. // UITableViewCell* cell =(UITableViewCell*) sender.superview.superview;
  1489. //
  1490. // NSIndexPath * indexPath = [self.detailTable indexPathForCell:cell];
  1491. //
  1492. // if(indexPath.section!=1)
  1493. // return ;
  1494. // // NSLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
  1495. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1496. //
  1497. // NSString* product_id = [item_json valueForKey:@"product_id"];
  1498. [self hideMenu];
  1499. [self switchtocontact];
  1500. }
  1501. else if([title isEqualToString:@"Cam Scan"])
  1502. {
  1503. // UITableViewCell* cell =(UITableViewCell*) sender.superview.superview;
  1504. //
  1505. // NSIndexPath * indexPath = [self.detailTable indexPathForCell:cell];
  1506. //
  1507. // if(indexPath.section!=1)
  1508. // return ;
  1509. // // NSLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
  1510. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1511. //
  1512. // NSString* product_id = [item_json valueForKey:@"product_id"];
  1513. [self hideMenu];
  1514. //
  1515. // [self switchtocontact];
  1516. ScannerViewController * scannerVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"ScannerViewController"];
  1517. [self.navigationController pushViewController:scannerVC animated:true];
  1518. }
  1519. }
  1520. #pragma mark - UIAlertViewDelegate
  1521. // Called when a button is clicked. The view will be automatically dismissed after this call returns
  1522. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  1523. {
  1524. UIApplication * app = [UIApplication sharedApplication];
  1525. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1526. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  1527. if(buttonIndex==alertView.cancelButtonIndex)
  1528. {
  1529. }
  1530. else if(buttonIndex==1)
  1531. {
  1532. //open exist
  1533. OrderListViewController* ovc =[ self.storyboard instantiateViewControllerWithIdentifier:@"OrderListViewController"];
  1534. ovc.showNavibar = true;
  1535. ovc.selectOrder = ^(NSMutableDictionary* order_detail){
  1536. if(appDelegate.order_code==nil)
  1537. {
  1538. [self neworderforCart];
  1539. }
  1540. else
  1541. {
  1542. self.previous_VC = self.current_VC;
  1543. [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1544. [self checklogin:true];
  1545. }
  1546. };
  1547. ovc.init_style = OL_OPEN;
  1548. ovc.onCancel = ^(){
  1549. [self checklogin:true];
  1550. };
  1551. [self.navigationController pushViewController:ovc animated:true];
  1552. }
  1553. else
  1554. {
  1555. //create new;
  1556. if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  1557. {
  1558. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  1559. cvc.showNavibar = true;
  1560. cvc.contact_type = @"Sales_Order_Customer";
  1561. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1562. appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  1563. appDelegate.customerInfo = value;
  1564. if(appDelegate.order_code==nil)
  1565. [self neworderforCart];
  1566. };
  1567. cvc.onCancel = ^(){
  1568. [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"" controller:self];
  1569. };
  1570. cvc.onReset = ^(){
  1571. [self checklogin:true];
  1572. };
  1573. [self.navigationController pushViewController:cvc animated:true];
  1574. }
  1575. else
  1576. {
  1577. [self neworderforCart];
  1578. }
  1579. }
  1580. }
  1581. -(void) neworderforCart
  1582. {
  1583. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Create Order"];
  1584. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1585. NSDictionary* return_json = [iSalesNetwork new_Order];
  1586. dispatch_async(dispatch_get_main_queue(), ^{
  1587. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  1588. if([[return_json valueForKey:@"result"] intValue]==2)
  1589. {
  1590. int result=[[return_json valueForKey:@"result"] intValue];
  1591. if(result==2)
  1592. {
  1593. //successed.
  1594. NSString* order_code = [return_json valueForKey:@"orderCode"];
  1595. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1596. appDelegate.order_code = order_code;
  1597. self.previous_VC = self.current_VC;
  1598. [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1599. }
  1600. }
  1601. else
  1602. {
  1603. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
  1604. }
  1605. });
  1606. });
  1607. }
  1608. @end