MainViewController.m 93 KB

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