MainViewController.m 77 KB

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