MainViewController.m 92 KB

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