MainViewController.m 77 KB

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