MainViewController.m 75 KB

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