MainViewController.m 80 KB

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