MainViewController.m 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071
  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.p_alert = nil;
  726. self.categoryViewController.p_available = nil;
  727. self.categoryViewController.p_price = nil;
  728. self.categoryViewController.p_QTY = nil;
  729. [self.categoryViewController reload_container_getdata:true];
  730. [self.categoryViewController showCategory];
  731. if([self.current_VC isKindOfClass:[CategoryViewController class]])
  732. return;
  733. [self flipFromViewController:self.current_VC toViewController:self.categoryViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  734. [[self navigationController] setNavigationBarHidden:YES animated:NO];
  735. // self.is_home = false;
  736. // self.current_vc = VC_CATEGORY;
  737. // [self.homeViewController willMoveToParentViewController:nil]; //1
  738. // [self.homeViewController.view removeFromSuperview]; //2
  739. // [self.homeViewController removeFromParentViewController]; //3
  740. //
  741. // [self.container addSubview:self.cagegoryViewController.view]; //2
  742. // [self.cagegoryViewController didMoveToParentViewController:self];
  743. }
  744. - (IBAction)switchToHome:(UIButton *)sender {
  745. [self switchToHome];
  746. // self.current_vc = VC_HOME;
  747. // self.is_home = true;
  748. //
  749. // [self.cagegoryViewController willMoveToParentViewController:nil]; //1
  750. // [self.cagegoryViewController.view removeFromSuperview]; //2
  751. // [self.cagegoryViewController removeFromParentViewController]; //3
  752. //
  753. // [self.container addSubview:self.homeViewController.view]; //2
  754. // [self.homeViewController didMoveToParentViewController:self];
  755. }
  756. -(void)switchToHome
  757. {
  758. if([self.current_VC isKindOfClass:[HomeViewController class]])
  759. return;
  760. [self flipFromViewController:self.current_VC toViewController:self.homeViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  761. }
  762. -(void) switchToPreviousVC
  763. {
  764. if(self.previous_VC==nil)
  765. return;
  766. if([self.current_VC isKindOfClass:[self.previous_VC class]])
  767. return;
  768. [self flipFromViewController:self.current_VC toViewController:self.previous_VC withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  769. }
  770. - (IBAction)switchToCart:(UIButton *)sender {
  771. [self switchToCart];
  772. // self.current_vc = VC_HOME;
  773. }
  774. -(void) switchToCart
  775. {
  776. if([self.current_VC isKindOfClass:[CartViewController class]])
  777. return;
  778. UIApplication * app = [UIApplication sharedApplication];
  779. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  780. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  781. if(appDelegate.bLogin==false)
  782. {
  783. LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  784. // loginvc.delegate = self;
  785. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  786. loginvc.returnValue = ^(bool blogin){
  787. // UIApplication * app = [UIApplication sharedApplication];
  788. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  789. if(blogin)
  790. {
  791. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  792. {
  793. [self checklogin:false];
  794. if(appDelegate.can_create_order)
  795. {
  796. NSString* msg =@"Do you want to switch to a pending order or a new order?";
  797. if(appDelegate.contact_id.length>0)
  798. {
  799. msg = [msg stringByAppendingString:@"\n\nCustomer:"];
  800. msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
  801. }
  802. 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];
  803. // alert.
  804. [alert show];
  805. }
  806. else
  807. {
  808. 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];
  809. // alert.
  810. [alert show];
  811. }
  812. }
  813. else
  814. {
  815. [self checklogin:true];
  816. self.previous_VC = self.current_VC;
  817. [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  818. }
  819. }
  820. // self.offset = 0;
  821. // [self.content_data removeAllObjects];
  822. // [self loadpage];
  823. //
  824. // [[self navigationController] setNavigationBarHidden:YES animated:NO];
  825. };
  826. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  827. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  828. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  829. [self presentViewController:navi animated:YES completion:^{
  830. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  831. NSLog(@"LoginViewController present.........");
  832. // self.btop = false;
  833. // <#code#>
  834. }];
  835. }
  836. else
  837. {
  838. if(appDelegate.user_type==USER_ROLE_EMPLOYEE&&/*appDelegate.contact_id==nil&&*/appDelegate.order_code==nil)
  839. {
  840. [self checklogin:false];
  841. if(appDelegate.can_create_order)
  842. {
  843. NSString* msg =@"Do you want to switch to a pending order or a new order?";
  844. if(appDelegate.contact_id.length>0)
  845. {
  846. msg = [msg stringByAppendingString:@"\n\nCustomer:"];
  847. msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
  848. }
  849. 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];
  850. // alert.
  851. [alert show];
  852. }
  853. else
  854. {
  855. 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];
  856. // alert.
  857. [alert show];
  858. }
  859. }
  860. else
  861. {
  862. self.previous_VC = self.current_VC;
  863. [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  864. }
  865. }
  866. }
  867. -(void) switchToOrder
  868. {
  869. if([self.current_VC isKindOfClass:[OrderListViewController class]])
  870. return;
  871. UIApplication * app = [UIApplication sharedApplication];
  872. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  873. if(appDelegate.bLogin==false)
  874. {
  875. LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  876. // loginvc.delegate = self;
  877. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  878. loginvc.returnValue = ^(bool blogin){
  879. if(blogin)
  880. {
  881. [self checklogin:true];
  882. [self flipFromViewController:self.current_VC toViewController:self.orderViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  883. }
  884. };
  885. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  886. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  887. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  888. [self presentViewController:navi animated:YES completion:^{
  889. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  890. NSLog(@"LoginViewController present.........");
  891. // self.btop = false;
  892. // <#code#>
  893. }];
  894. }
  895. else
  896. [self flipFromViewController:self.current_VC toViewController:self.orderViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  897. }
  898. - (IBAction)switchToOrder:(id)sender {
  899. [self switchToOrder];
  900. //self.orderViewController =[ self.storyboard instantiateViewControllerWithIdentifier:@"OrderListViewController"];
  901. }
  902. #pragma mark - CategoryMenuDelegate
  903. -(void)SelectCategory:(NSString *)category
  904. {
  905. [self switchToCagegory:category];
  906. }
  907. - (IBAction)showCategoryMenu:(id)sender {
  908. RAViewController * categorymenuVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"RAViewController"];
  909. // categorymenuVC.rootViewController = self;
  910. categorymenuVC.CateMenu_delegate = self;
  911. // categorymenuVC.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  912. // [self presentViewController:categorymenuVC animated:YES completion:^{
  913. //
  914. // NSLog(@"login.........");
  915. // // <#code#>
  916. // }];
  917. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:categorymenuVC] ;
  918. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  919. [self presentViewController:navi animated:YES completion:^{
  920. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  921. NSLog(@"bundle present.........");
  922. // self.btop = false;
  923. // <#code#>
  924. }];
  925. // if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
  926. // categorymenuVC.providesPresentationContextTransitionStyle = YES;
  927. // categorymenuVC.definesPresentationContext = YES;
  928. // categorymenuVC.modalPresentationStyle = UIModalPresentationFormSheet;
  929. // [self presentViewController:categorymenuVC animated:YES completion:nil];
  930. // } else {
  931. // categorymenuVC.modalPresentationStyle = UIModalPresentationFormSheet;
  932. // [self presentViewController:categorymenuVC animated:NO completion:nil];
  933. //// self.view.window.rootViewController.modalPresentationStyle = UIModalPresentationFullScreen;
  934. // }
  935. UIApplication * app = [UIApplication sharedApplication];
  936. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  937. if(appDelegate.categoryMenu == nil)
  938. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  939. NSDictionary* category=[iSalesNetwork request_Cagegory];
  940. dispatch_async(dispatch_get_main_queue(), ^{
  941. if([[category valueForKey:@"result"] intValue]==2)
  942. {
  943. appDelegate.categoryMenu = category;
  944. [categorymenuVC SetMenu:appDelegate.categoryMenu ];
  945. }
  946. else
  947. if([[category valueForKey:@"result"] intValue]==RESULT_NET_ERROR)
  948. {
  949. [categorymenuVC SetMenu:nil ];
  950. }
  951. else
  952. {
  953. [RAUtils message_alert:[category valueForKey:@"err_msg"] title:@"Load Category Menu" controller:self] ;
  954. }
  955. });
  956. });
  957. else
  958. [categorymenuVC SetMenu:appDelegate.categoryMenu];
  959. }
  960. -(NSString*) categoryString:(NSString*) categoryid node:(NSDictionary*) json level:(int) level;
  961. {
  962. //NSString* idString = [NSString stringWithFormat:@"%d",categoryid];
  963. NSString* categoryString =@">";
  964. int count = [[json valueForKey:@"count"] intValue];
  965. for(int i=0;i<count;i++)
  966. {
  967. NSDictionary * category_json = [json objectForKey:[NSString stringWithFormat:@"category_%d",i]];
  968. NSString* cid = [category_json valueForKey:@"id"] ;
  969. // NSString* ttt =[categoryid substringToIndex:2+level*2];
  970. // NSString * qqq =[cid substringToIndex:2+level*2];
  971. // NSString *ds1=[categoryid substringToIndex:3+level*3];
  972. // NSString*ds2 = [cid substringToIndex:3+level*3];
  973. if([[categoryid substringToIndex:3+level*3] isEqualToString: [cid substringToIndex:3+level*3]])
  974. {
  975. //categoryString = [categoryString stringByAppendingString:@">"];
  976. categoryString =[categoryString stringByAppendingString: [category_json valueForKey:@"title" ] ];
  977. categoryString = [categoryString stringByAppendingString:[ self categoryString:categoryid node:category_json level:level+1]];
  978. break;
  979. }
  980. }
  981. return categoryString;
  982. }
  983. - (void)didReceiveMemoryWarning
  984. {
  985. [super didReceiveMemoryWarning];
  986. // Dispose of any resources that can be recreated.
  987. }
  988. - (IBAction)openMenu:(UIButton *)sender {
  989. [self showMenu];
  990. // [((RootContainerViewController *)self.parentViewController) showMenu];
  991. // SideMenuViewController *sideMenuController = [self.storyboard instantiateViewControllerWithIdentifier:@"SideMenuViewController"];
  992. // if (sideMenuController) {
  993. // //[sideMenuController openMenu];
  994. // [UIView animateWithDuration:1.0 animations:^{ sideMenuController.view.alpha = 1.0;
  995. // self.view.alpha = 0.0; }];
  996. // }
  997. }
  998. - (UIImage*)screen_shot
  999. {
  1000. // CGRect r = self.view.frame;
  1001. // CGRect r1 = self.view.bounds;
  1002. // double width,height;
  1003. //
  1004. // UIInterfaceOrientation orientation =[UIApplication sharedApplication].statusBarOrientation;
  1005. // ;
  1006. // if(orientation == UIDeviceOrientationLandscapeLeft ||orientation == UIDeviceOrientationLandscapeRight)
  1007. // {
  1008. // width = self.view.frame.size.width>self.view.frame.size.height? self.view.frame.size.width:self.view.frame.size.height;
  1009. // height =self.view.frame.size.width<self.view.frame.size.height? self.view.frame.size.width:self.view.frame.size.height;
  1010. // }
  1011. // else
  1012. // {
  1013. // width = self.view.frame.size.width<self.view.frame.size.height? self.view.frame.size.width:self.view.frame.size.height;
  1014. // height =self.view.frame.size.width>self.view.frame.size.height? self.view.frame.size.width:self.view.frame.size.height;
  1015. // }
  1016. UIGraphicsBeginImageContext(CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height));
  1017. [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
  1018. UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
  1019. UIGraphicsEndImageContext();
  1020. return viewImage;
  1021. }
  1022. - (IBAction)onhideMenuClick:(id)sender {
  1023. [self hideMenu];
  1024. self.backgroundButton.hidden=true;
  1025. self.openMenuButton.hidden = false;
  1026. self.sideMenu.hidden = true;
  1027. }
  1028. - (void)hideMenu
  1029. {
  1030. CGRect frame ;
  1031. frame.origin.x = -300;
  1032. frame.origin.y = 0;
  1033. frame.size.height = self.view.bounds.size.height;
  1034. frame.size.width = 364;
  1035. self.sideMenu.frame=frame;
  1036. self.sideMenu.hidden = true;
  1037. self.blurView.alpha = 0;
  1038. [self.menuButton setImage:[UIImage imageNamed:@"menu_open"] forState:UIControlStateNormal];
  1039. self.menuShown = false;
  1040. self.backgroundButton.hidden=true;
  1041. self.openMenuButton.hidden = false;
  1042. }
  1043. - (void)showMenu
  1044. {
  1045. [self.sideMenuTable reloadData];
  1046. UIImage* imgsource = [self screen_shot];
  1047. self.blurView.alpha = 0;
  1048. UIImage* imgBlur =[self applyBlurWithRadius:5 sourceImage:imgsource tintColor:[UIColor colorWithWhite:0.2 alpha:0.73] saturationDeltaFactor:1.8 maskImage:nil];
  1049. self.blurView.image = imgBlur;
  1050. // self.blurView.hidden = imgBlur;
  1051. // [self.sideMenu becomeFirstResponder];
  1052. self.sideMenu.hidden = false;
  1053. self.backgroundButton.hidden=false;
  1054. CGRect frame ;
  1055. frame.origin.x = 0;
  1056. frame.origin.y = 0;
  1057. frame.size.height = self.view.bounds.size.height;
  1058. frame.size.width = 364;
  1059. // [UIView animateWithDuration:1.0 animations:^{ self.sideMenu.frame=frame;
  1060. // self.blurView.alpha = 1;
  1061. // [self.menuButton setImage:[UIImage imageNamed:@"menu"] forState:UIControlStateNormal];
  1062. //
  1063. // }];
  1064. [UIView animateWithDuration:0.5 animations:^{ self.sideMenu.frame=frame;
  1065. self.blurView.alpha = 1;
  1066. }
  1067. completion:^(BOOL finished) {
  1068. [self.menuButton setImage:[UIImage imageNamed:@"menu"] forState:UIControlStateNormal];
  1069. }];
  1070. // UIImage* img= [UIImage imageNamed:@"menu"];
  1071. // self.menuButton.imageView.image = nil;
  1072. self.menuShown = true;
  1073. }
  1074. -(void)initMenuItems
  1075. {
  1076. UIApplication * app = [UIApplication sharedApplication];
  1077. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1078. self.sideMenuItems = [[NSMutableArray alloc] init];
  1079. NSMutableDictionary* map = [[NSMutableDictionary alloc] init];
  1080. if(appDelegate.user!=nil)
  1081. {
  1082. [map setValue:@"Wishlist" forKey:@"title"];
  1083. [map setValue:@"rect_market_news" forKey:@"img"];
  1084. [self.sideMenuItems addObject:map.copy];
  1085. }
  1086. // if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  1087. {
  1088. [map setValue:@"Cam Scan" forKey:@"title"];
  1089. [map setValue:@"rect_contact_list" forKey:@"img"];
  1090. [self.sideMenuItems addObject:map.copy];
  1091. }
  1092. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  1093. {
  1094. // [map setValue:@"Contact" forKey:@"title"];
  1095. // [map setValue:@"rect_contact_list" forKey:@"img"];
  1096. // [self.sideMenuItems addObject:map.copy];
  1097. [map setValue:@"Portfolio" forKey:@"title"];
  1098. [map setValue:@"rect_market_news" forKey:@"img"];
  1099. [self.sideMenuItems addObject:map.copy];
  1100. [map setValue:@"View Portfolios" forKey:@"title"];
  1101. [map setValue:@"rect_pdf_list" forKey:@"img"];
  1102. [self.sideMenuItems addObject:map.copy];
  1103. }
  1104. if(appDelegate.can_show_price)
  1105. {
  1106. if(appDelegate.price_hidden)
  1107. [map setValue:@"Show Price" forKey:@"title"];
  1108. else
  1109. [map setValue:@"Hide Price" forKey:@"title"];
  1110. [map setValue:@"rect_announcements" forKey:@"img"];
  1111. [self.sideMenuItems addObject:map.copy];
  1112. }
  1113. // [map setValue:@"Contact" forKey:@"title"];
  1114. // [map setValue:@"rect_market_news" forKey:@"img"];
  1115. // [self.sideMenuItems addObject:map.copy];
  1116. [map setValue:@"Cache" forKey:@"title"];
  1117. [map setValue:@"rect_announcements" forKey:@"img"];
  1118. [self.sideMenuItems addObject:map.copy];
  1119. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  1120. // [map setValue:@"Message" forKey:@"title"];
  1121. // [map setValue:@"rect_search_history" forKey:@"img"];
  1122. // [self.sideMenuItems addObject:map.copy];
  1123. //
  1124. [map setValue:@"Scanner Setting" forKey:@"title"];
  1125. [map setValue:@"rect_change_password" forKey:@"img"];
  1126. [self.sideMenuItems addObject:map.copy];
  1127. // if(appDelegate.user!=nil)
  1128. // {
  1129. // [map setValue:@"Offline data" forKey:@"title"];
  1130. // [map setValue:@"rect_market_news" forKey:@"img"];
  1131. // [self.sideMenuItems addObject:map.copy];
  1132. //
  1133. //
  1134. //
  1135. // }
  1136. [map setValue:@"About" forKey:@"title"];
  1137. [map setValue:@"rect_change_password" forKey:@"img"];
  1138. [self.sideMenuItems addObject:map.copy];
  1139. [self.sideMenuTable reloadData];
  1140. //
  1141. }
  1142. - (UIImage *)applyBlurWithRadius:(CGFloat)blurRadius sourceImage:(UIImage*)sourceImage tintColor:(UIColor *)tintColor saturationDeltaFactor:(CGFloat)saturationDeltaFactor maskImage:(UIImage *)maskImage
  1143. {
  1144. // Check pre-conditions.
  1145. if (sourceImage.size.width < 1 || sourceImage.size.height < 1) {
  1146. NSLog (@"*** error: invalid size: (%.2f x %.2f). Both dimensions must be >= 1: %@", sourceImage.size.width, sourceImage.size.height, self);
  1147. return nil;
  1148. }
  1149. if (!sourceImage.CGImage) {
  1150. NSLog (@"*** error: image must be backed by a CGImage: %@", self);
  1151. return nil;
  1152. }
  1153. if (maskImage && !maskImage.CGImage) {
  1154. NSLog (@"*** error: maskImage must be backed by a CGImage: %@", maskImage);
  1155. return nil;
  1156. }
  1157. CGRect imageRect = { CGPointZero, sourceImage.size };
  1158. UIImage *effectImage = sourceImage;
  1159. BOOL hasBlur = blurRadius > __FLT_EPSILON__;
  1160. BOOL hasSaturationChange = fabs(saturationDeltaFactor - 1.) > __FLT_EPSILON__;
  1161. if (hasBlur || hasSaturationChange) {
  1162. UIGraphicsBeginImageContextWithOptions(sourceImage.size, NO, [[UIScreen mainScreen] scale]);
  1163. CGContextRef effectInContext = UIGraphicsGetCurrentContext();
  1164. CGContextScaleCTM(effectInContext, 1.0, -1.0);
  1165. CGContextTranslateCTM(effectInContext, 0, -sourceImage.size.height);
  1166. CGContextDrawImage(effectInContext, imageRect, sourceImage.CGImage);
  1167. vImage_Buffer effectInBuffer;
  1168. effectInBuffer.data = CGBitmapContextGetData(effectInContext);
  1169. effectInBuffer.width = CGBitmapContextGetWidth(effectInContext);
  1170. effectInBuffer.height = CGBitmapContextGetHeight(effectInContext);
  1171. effectInBuffer.rowBytes = CGBitmapContextGetBytesPerRow(effectInContext);
  1172. UIGraphicsBeginImageContextWithOptions(sourceImage.size, NO, [[UIScreen mainScreen] scale]);
  1173. CGContextRef effectOutContext = UIGraphicsGetCurrentContext();
  1174. vImage_Buffer effectOutBuffer;
  1175. effectOutBuffer.data = CGBitmapContextGetData(effectOutContext);
  1176. effectOutBuffer.width = CGBitmapContextGetWidth(effectOutContext);
  1177. effectOutBuffer.height = CGBitmapContextGetHeight(effectOutContext);
  1178. effectOutBuffer.rowBytes = CGBitmapContextGetBytesPerRow(effectOutContext);
  1179. if (hasBlur) {
  1180. // A description of how to compute the box kernel width from the Gaussian
  1181. // radius (aka standard deviation) appears in the SVG spec:
  1182. // http://www.w3.org/TR/SVG/filters.html#feGaussianBlurElement
  1183. //
  1184. // For larger values of 's' (s >= 2.0), an approximation can be used: Three
  1185. // successive box-blurs build a piece-wise quadratic convolution kernel, which
  1186. // approximates the Gaussian kernel to within roughly 3%.
  1187. //
  1188. // let d = floor(s * 3*sqrt(2*pi)/4 + 0.5)
  1189. //
  1190. // ... if d is odd, use three box-blurs of size 'd', centered on the output pixel.
  1191. //
  1192. CGFloat inputRadius = blurRadius * [[UIScreen mainScreen] scale];
  1193. NSUInteger radius = floor(inputRadius * 3. * sqrt(2 * M_PI) / 4 + 0.5);
  1194. if (radius % 2 != 1) {
  1195. radius += 1; // force radius to be odd so that the three box-blur methodology works.
  1196. }
  1197. vImageBoxConvolve_ARGB8888(&effectInBuffer, &effectOutBuffer, NULL, 0, 0, (unsigned int)radius, (unsigned int)radius, 0, kvImageEdgeExtend);
  1198. vImageBoxConvolve_ARGB8888(&effectOutBuffer, &effectInBuffer, NULL, 0, 0, (unsigned int)radius, (unsigned int)radius, 0, kvImageEdgeExtend);
  1199. vImageBoxConvolve_ARGB8888(&effectInBuffer, &effectOutBuffer, NULL, 0, 0, (unsigned int)radius, (unsigned int)radius, 0, kvImageEdgeExtend);
  1200. }
  1201. BOOL effectImageBuffersAreSwapped = NO;
  1202. if (hasSaturationChange) {
  1203. CGFloat s = saturationDeltaFactor;
  1204. CGFloat floatingPointSaturationMatrix[] = {
  1205. 0.0722 + 0.9278 * s, 0.0722 - 0.0722 * s, 0.0722 - 0.0722 * s, 0,
  1206. 0.7152 - 0.7152 * s, 0.7152 + 0.2848 * s, 0.7152 - 0.7152 * s, 0,
  1207. 0.2126 - 0.2126 * s, 0.2126 - 0.2126 * s, 0.2126 + 0.7873 * s, 0,
  1208. 0, 0, 0, 1,
  1209. };
  1210. const int32_t divisor = 256;
  1211. NSUInteger matrixSize = sizeof(floatingPointSaturationMatrix)/sizeof(floatingPointSaturationMatrix[0]);
  1212. int16_t saturationMatrix[matrixSize];
  1213. for (NSUInteger i = 0; i < matrixSize; ++i) {
  1214. saturationMatrix[i] = (int16_t)roundf(floatingPointSaturationMatrix[i] * divisor);
  1215. }
  1216. if (hasBlur) {
  1217. vImageMatrixMultiply_ARGB8888(&effectOutBuffer, &effectInBuffer, saturationMatrix, divisor, NULL, NULL, kvImageNoFlags);
  1218. effectImageBuffersAreSwapped = YES;
  1219. }
  1220. else {
  1221. vImageMatrixMultiply_ARGB8888(&effectInBuffer, &effectOutBuffer, saturationMatrix, divisor, NULL, NULL, kvImageNoFlags);
  1222. }
  1223. }
  1224. if (!effectImageBuffersAreSwapped)
  1225. effectImage = UIGraphicsGetImageFromCurrentImageContext();
  1226. UIGraphicsEndImageContext();
  1227. if (effectImageBuffersAreSwapped)
  1228. effectImage = UIGraphicsGetImageFromCurrentImageContext();
  1229. UIGraphicsEndImageContext();
  1230. }
  1231. // Set up output context.
  1232. UIGraphicsBeginImageContextWithOptions(sourceImage.size, NO, [[UIScreen mainScreen] scale]);
  1233. CGContextRef outputContext = UIGraphicsGetCurrentContext();
  1234. CGContextScaleCTM(outputContext, 1.0, -1.0);
  1235. CGContextTranslateCTM(outputContext, 0, -sourceImage.size.height);
  1236. // Draw base image.
  1237. CGContextDrawImage(outputContext, imageRect, sourceImage.CGImage);
  1238. // Draw effect image.
  1239. if (hasBlur) {
  1240. CGContextSaveGState(outputContext);
  1241. if (maskImage) {
  1242. CGContextClipToMask(outputContext, imageRect, maskImage.CGImage);
  1243. }
  1244. CGContextDrawImage(outputContext, imageRect, effectImage.CGImage);
  1245. CGContextRestoreGState(outputContext);
  1246. }
  1247. // Add in color tint.
  1248. if (tintColor) {
  1249. CGContextSaveGState(outputContext);
  1250. CGContextSetFillColorWithColor(outputContext, tintColor.CGColor);
  1251. CGContextFillRect(outputContext, imageRect);
  1252. CGContextRestoreGState(outputContext);
  1253. }
  1254. // Output image is ready.
  1255. UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext();
  1256. UIGraphicsEndImageContext();
  1257. return outputImage;
  1258. }
  1259. //- (IBAction)openMenu:(UIButton *)sender {
  1260. //}
  1261. #pragma mark - Table view data source
  1262. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  1263. {
  1264. return 1;
  1265. }
  1266. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  1267. {
  1268. return self.sideMenuItems.count;
  1269. }
  1270. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  1271. {
  1272. UIApplication * app = [UIApplication sharedApplication];
  1273. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1274. NSString *CellIdentifier = @"SideMenuItem";
  1275. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1276. NSString* title = [self.sideMenuItems[indexPath.row] valueForKey:@"title"];
  1277. cell.backgroundColor = [UIColor clearColor];
  1278. // [cell.backgroundColor:[UIColor clearColor]];
  1279. // UIImageView* iv= [[UIImageView alloc] initWithImage:];
  1280. cell.textLabel.text = title;
  1281. cell.detailTextLabel.textColor =[UIColor redColor];
  1282. if([title isEqualToString:@"Wishlist"]&&appDelegate.wish_count>0)
  1283. cell.detailTextLabel.text = [NSString stringWithFormat:@"%ld",appDelegate.wish_count];
  1284. else if([title isEqualToString:@"Portfolio"]&&appDelegate.port_count>0)
  1285. cell.detailTextLabel.text = [NSString stringWithFormat:@"%ld",appDelegate.port_count];
  1286. else
  1287. {
  1288. cell.detailTextLabel.text =nil;
  1289. }
  1290. // cell.imageView.image = [UIImage imageNamed:[self.toolsinfo[indexPath.row] valueForKey:@"img"]];
  1291. return cell;
  1292. }
  1293. #pragma mark - Table view delegate
  1294. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  1295. {
  1296. NSString* title = [self.sideMenuItems[indexPath.row] valueForKey:@"title"];
  1297. if([title isEqualToString:@"Cache"])
  1298. {
  1299. CacheViewController * settingvc=[ self.storyboard instantiateViewControllerWithIdentifier:@"CacheViewController"];
  1300. PopupNavigationController * navi=[[PopupNavigationController alloc] initWithRootViewController:settingvc];
  1301. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1302. [self presentViewController:navi animated:YES completion:^{
  1303. //NSLog(@"login.........");
  1304. // <#code#>
  1305. }];
  1306. }
  1307. else if([title isEqualToString:@"Scanner Setting"])
  1308. {
  1309. UIApplication * app = [UIApplication sharedApplication];
  1310. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1311. UIViewController* active_vc = appDelegate.active_controller;
  1312. ScannerSettingViewController * gunVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"ScannerSettingViewController"];
  1313. // loginvc.delegate = self;
  1314. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1315. appDelegate.active_controller = gunVC;
  1316. gunVC.onDismissVC = ^(){
  1317. appDelegate.active_controller = active_vc;
  1318. };
  1319. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:gunVC] ;
  1320. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1321. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  1322. [self presentViewController:navi animated:YES completion:^{
  1323. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1324. NSLog(@"about present.........");
  1325. // self.btop = false;
  1326. // <#code#>
  1327. }];
  1328. }
  1329. else if([title isEqualToString:@"Offline data"])
  1330. {
  1331. [iSalesDB testdata];
  1332. }
  1333. else if([title isEqualToString:@"About"])
  1334. {
  1335. AboutViewController * aboutVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"AboutViewController"];
  1336. // loginvc.delegate = self;
  1337. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1338. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:aboutVC] ;
  1339. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1340. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  1341. [self presentViewController:navi animated:YES completion:^{
  1342. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1343. NSLog(@"about present.........");
  1344. // self.btop = false;
  1345. // <#code#>
  1346. }];
  1347. }
  1348. else if([title isEqualToString:@"Wishlist"])
  1349. {
  1350. [self hideMenu];
  1351. [self switchtowishlist];
  1352. }
  1353. else if([title isEqualToString:@"Show Price"])
  1354. {
  1355. UIApplication * app = [UIApplication sharedApplication];
  1356. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1357. [appDelegate set_priceHidden:false];
  1358. //appDelegate.price_hidden = false;
  1359. //[self.sideMenuTable reloadData];
  1360. [self initMenuItems];
  1361. [self hideMenu];
  1362. // if([self.current_VC isKindOfClass:[WatchListViewController class]])
  1363. // return;
  1364. // [self flipFromViewController:self.current_VC toViewController:self.watchListViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1365. }
  1366. else if([title isEqualToString:@"Hide Price"])
  1367. {
  1368. UIApplication * app = [UIApplication sharedApplication];
  1369. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1370. [appDelegate set_priceHidden:true];
  1371. // appDelegate.price_hidden = true;
  1372. [self initMenuItems];
  1373. // [self.sideMenuTable reloadData];
  1374. [self hideMenu];
  1375. // if([self.current_VC isKindOfClass:[WatchListViewController class]])
  1376. // return;
  1377. // [self flipFromViewController:self.current_VC toViewController:self.watchListViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1378. }
  1379. else if([title isEqualToString:@"Portfolio"])
  1380. {
  1381. [self hideMenu];
  1382. if([self.current_VC isKindOfClass:[PortfolioViewController class]])
  1383. return;
  1384. [self flipFromViewController:self.current_VC toViewController:self.portfolioViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1385. }
  1386. else if([title isEqualToString:@"View Portfolios"])
  1387. {
  1388. [self hideMenu];
  1389. if([self.current_VC isKindOfClass:[PDFListViewController class]])
  1390. return;
  1391. [self flipFromViewController:self.current_VC toViewController:self.pdfListViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1392. }
  1393. else if([title isEqualToString:@"Contact"])
  1394. {
  1395. // UITableViewCell* cell =(UITableViewCell*) sender.superview.superview;
  1396. //
  1397. // NSIndexPath * indexPath = [self.detailTable indexPathForCell:cell];
  1398. //
  1399. // if(indexPath.section!=1)
  1400. // return ;
  1401. // // NSLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
  1402. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1403. //
  1404. // NSString* product_id = [item_json valueForKey:@"product_id"];
  1405. [self hideMenu];
  1406. [self switchtocontact];
  1407. }
  1408. else if([title isEqualToString:@"Cam Scan"])
  1409. {
  1410. // UITableViewCell* cell =(UITableViewCell*) sender.superview.superview;
  1411. //
  1412. // NSIndexPath * indexPath = [self.detailTable indexPathForCell:cell];
  1413. //
  1414. // if(indexPath.section!=1)
  1415. // return ;
  1416. // // NSLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
  1417. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1418. //
  1419. // NSString* product_id = [item_json valueForKey:@"product_id"];
  1420. [self hideMenu];
  1421. //
  1422. // [self switchtocontact];
  1423. ScannerViewController * scannerVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"ScannerViewController"];
  1424. [self.navigationController pushViewController:scannerVC animated:true];
  1425. }
  1426. }
  1427. #pragma mark - UIAlertViewDelegate
  1428. // Called when a button is clicked. The view will be automatically dismissed after this call returns
  1429. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  1430. {
  1431. UIApplication * app = [UIApplication sharedApplication];
  1432. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1433. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  1434. if(buttonIndex==alertView.cancelButtonIndex)
  1435. {
  1436. }
  1437. else if(buttonIndex==1)
  1438. {
  1439. //open exist
  1440. OrderListViewController* ovc =[ self.storyboard instantiateViewControllerWithIdentifier:@"OrderListViewController"];
  1441. ovc.showNavibar = true;
  1442. ovc.selectOrder = ^(NSMutableDictionary* order_detail){
  1443. if(appDelegate.order_code==nil)
  1444. {
  1445. [self neworderforCart];
  1446. }
  1447. else
  1448. {
  1449. self.previous_VC = self.current_VC;
  1450. [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1451. [self checklogin:true];
  1452. }
  1453. };
  1454. ovc.init_style = OL_OPEN;
  1455. ovc.onCancel = ^(){
  1456. [self checklogin:true];
  1457. };
  1458. [self.navigationController pushViewController:ovc animated:true];
  1459. }
  1460. else
  1461. {
  1462. //create new;
  1463. if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  1464. {
  1465. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  1466. cvc.showNavibar = true;
  1467. cvc.contact_type = @"Sales_Order_Customer";
  1468. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1469. appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  1470. appDelegate.customerInfo = value;
  1471. if(appDelegate.order_code==nil)
  1472. [self neworderforCart];
  1473. };
  1474. cvc.onCancel = ^(){
  1475. [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"" controller:self];
  1476. };
  1477. cvc.onReset = ^(){
  1478. [self checklogin:true];
  1479. };
  1480. [self.navigationController pushViewController:cvc animated:true];
  1481. }
  1482. else
  1483. {
  1484. [self neworderforCart];
  1485. }
  1486. }
  1487. }
  1488. -(void) neworderforCart
  1489. {
  1490. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Create Order"];
  1491. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1492. NSDictionary* return_json = [iSalesNetwork new_Order];
  1493. dispatch_async(dispatch_get_main_queue(), ^{
  1494. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  1495. if([[return_json valueForKey:@"result"] intValue]==2)
  1496. {
  1497. int result=[[return_json valueForKey:@"result"] intValue];
  1498. if(result==2)
  1499. {
  1500. //successed.
  1501. NSString* order_code = [return_json valueForKey:@"orderCode"];
  1502. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1503. appDelegate.order_code = order_code;
  1504. self.previous_VC = self.current_VC;
  1505. [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1506. }
  1507. }
  1508. else
  1509. {
  1510. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
  1511. }
  1512. });
  1513. });
  1514. }
  1515. @end