MainViewController.m 72 KB

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