MainViewController.m 72 KB

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