MainViewController.m 79 KB

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