MainViewController.m 91 KB

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