MainViewController.m 99 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747
  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. [RANetwork 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. //#endif
  361. //#if defined(BUILD_NPD) || defined(BUILD_USAI)
  362. // NSString* versionNum = [NSString stringWithFormat:@"npd %@ Build %@",version,build];
  363. //#endif
  364. //#ifdef BUILD_HOMER
  365. NSString* versionNum = [NSString stringWithFormat:@"%@ %@ Build %@",COMPANY_SHORT_NAME,version,build];
  366. //#endif
  367. [self initMenuItems];
  368. self.homeViewController =[ self.storyboard instantiateViewControllerWithIdentifier:@"HomeViewController"];
  369. self.categoryViewController =[ self.storyboard instantiateViewControllerWithIdentifier:@"CategoryViewController"];
  370. self.cartViewController =[ self.storyboard instantiateViewControllerWithIdentifier:@"CartViewController"];
  371. self.orderViewController =[ self.storyboard instantiateViewControllerWithIdentifier:@"OrderListViewController"];
  372. self.contactListViewController =[ self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController"];
  373. self.contactListViewController.contact_type = @"Sales_Order_Customer";
  374. self.contactListViewController.edit_icon = true;
  375. self.contactListViewController.assig_icon = true;
  376. self.contactListViewController.reset_icon = false;
  377. self.contactListViewController.ui_type = CONTACT_LIST;
  378. __block MainViewController *brself= self;
  379. self.contactListViewController.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  380. appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  381. appDelegate.customerInfo = value;
  382. [brself switchToCart:nil];
  383. // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  384. //
  385. // if(self.returnValue)
  386. // self.returnValue(value);
  387. };
  388. //Capturing strongly warring;
  389. self.orderViewController.selectOrder=^(NSMutableDictionary* order_detail){
  390. //main view 下打开order
  391. //Capturing strongly warring;
  392. __block MainViewController *brbrself= brself;
  393. brself.cartViewController.onFinishLoad=^()
  394. {
  395. [brbrself.cartViewController placeOrder];
  396. brbrself.cartViewController.onFinishLoad=nil;
  397. };
  398. [brself switchToCart:nil];
  399. };
  400. self.watchListViewController =[ self.storyboard instantiateViewControllerWithIdentifier:@"WatchListViewController"];
  401. self.portfolioViewController =[ self.storyboard instantiateViewControllerWithIdentifier:@"PortfolioViewController"];
  402. self.pdfListViewController =[ self.storyboard instantiateViewControllerWithIdentifier:@"PDFListViewController"];
  403. self.itemSearchViewController=[ self.storyboard instantiateViewControllerWithIdentifier:@"ItemSearchViewController"];
  404. self.searchViewController=[ self.storyboard instantiateViewControllerWithIdentifier:@"SearchViewController"];
  405. [self addChildViewController:self.homeViewController]; //1
  406. self.homeViewController.view.frame = self.container.bounds;
  407. [self.container addSubview:self.homeViewController.view]; //2
  408. [self.homeViewController didMoveToParentViewController:self];
  409. self.current_VC = self.homeViewController;
  410. // self.is_home = true;
  411. // [UIBezierPath bezierPathWithRect:self.headerView.bounds].CGPath;
  412. self.headerView.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.headerView.bounds].CGPath;
  413. self.headerView.layer.masksToBounds = false;
  414. //添加四个边阴影
  415. self.headerView.layer.shadowColor = [UIColor blackColor].CGColor;
  416. self.headerView.layer.shadowOffset = CGSizeMake(0, 0);
  417. self.headerView.layer.shadowOpacity = 0.5;
  418. self.headerView.layer.shadowRadius = 2.0;
  419. self.labelVer.text=versionNum;
  420. // UIApplication * app = [UIApplication sharedApplication];
  421. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  422. if(appDelegate.categoryMenu==nil)
  423. {
  424. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  425. NSDictionary* category=[RANetwork request_Cagegory];
  426. dispatch_async(dispatch_get_main_queue(), ^{
  427. if([[category valueForKey:@"result"] intValue]==2)
  428. {
  429. appDelegate.categoryMenu = category;
  430. }
  431. else
  432. {
  433. // [RAUtils error_alert:[category valueForKey:@"err_msg"] title:@"Failed to load category."] ;
  434. }
  435. // self.categoryViewController.categoryMenu = category;
  436. });
  437. });
  438. }
  439. // Do any additional setup after loading the view, typically from a nib.
  440. }
  441. - (IBAction)onmenuButtonClicked:(id)sender {
  442. self.openMenuButton.hidden = true;
  443. self.sideMenu.hidden = false;
  444. [self showMenu];
  445. }
  446. - (IBAction)switchMenu:(UIButton *)sender {
  447. // if(self.menuShown==true)
  448. [self hideMenu];
  449. self.openMenuButton.hidden = false;
  450. self.sideMenu.hidden = true;
  451. // else
  452. // [self showMenu];
  453. }
  454. -(void) Loginout:(bool)showlogin
  455. {
  456. UIApplication * app = [UIApplication sharedApplication];
  457. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  458. if(appDelegate.bLogin)
  459. {
  460. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Sign out"];
  461. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  462. NSDictionary* return_json = [RANetwork logout];
  463. dispatch_async(dispatch_get_main_queue(), ^{
  464. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  465. if([[return_json valueForKey:@"result"] intValue]==2)
  466. {
  467. // [self hideMenu];
  468. // [self switchToHome:nil];
  469. [appDelegate Logout];
  470. [self checklogin :false];
  471. if(showlogin)
  472. {
  473. LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  474. loginvc.returnValue = ^(bool blogin){
  475. [self checklogin :true];
  476. };
  477. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  478. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  479. [self presentViewController:navi animated:YES completion:^{
  480. DebugLog(@"login present.........");
  481. }];
  482. }
  483. }
  484. else
  485. {
  486. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Sign Out" controller:self] ;
  487. }
  488. });
  489. });
  490. }
  491. else
  492. {
  493. LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  494. loginvc.returnValue = ^(bool blogin){
  495. [self checklogin :true];
  496. };
  497. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  498. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  499. [self presentViewController:navi animated:YES completion:^{
  500. DebugLog(@"login present.........");
  501. }];
  502. }
  503. }
  504. - (IBAction)onUserListClick:(id)sender {
  505. UIApplication * app = [UIApplication sharedApplication];
  506. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  507. if(!appDelegate.bLogin)
  508. return;
  509. UserListViewController * vc =[ self.storyboard instantiateViewControllerWithIdentifier:@"UserListViewController"];
  510. vc.returnValue = ^(bool blogin){
  511. if(blogin==false)
  512. {
  513. LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  514. loginvc.returnValue = ^(bool blogin){
  515. [self checklogin :true];
  516. };
  517. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  518. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  519. [self presentViewController:navi animated:YES completion:^{
  520. DebugLog(@"login present.........");
  521. }];
  522. }
  523. };
  524. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  525. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  526. [self presentViewController:navi animated:YES completion:^{
  527. DebugLog(@"login present.........");
  528. }];
  529. }
  530. - (IBAction)OnLoginClick:(UIButton *)sender {
  531. [self Loginout:true];
  532. }
  533. - (IBAction)onScanClick:(id)sender {
  534. ScannerViewController * scannerVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"ScannerViewController"];
  535. [self.navigationController pushViewController:scannerVC animated:true];
  536. }
  537. - (IBAction)switchToSearch:(UIButton *)sender {
  538. if([self.current_VC isKindOfClass:[SearchViewController class]])
  539. return;
  540. [self flipFromViewController:self.current_VC toViewController:self.searchViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  541. }
  542. - (IBAction)switchToWishlist:(UIButton *)sender {
  543. [self switchtowishlist];
  544. }
  545. -(void)switchtowishlist
  546. {
  547. if([self.current_VC isKindOfClass:[WatchListViewController class]])
  548. return;
  549. // if([self.current_VC isKindOfClass:[OrderListViewController class]])
  550. // return;
  551. UIApplication * app = [UIApplication sharedApplication];
  552. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  553. if(appDelegate.bLogin==false)
  554. {
  555. LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  556. // loginvc.delegate = self;
  557. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  558. loginvc.returnValue = ^(bool blogin){
  559. if(blogin)
  560. {
  561. [self checklogin:true];
  562. [self flipFromViewController:self.current_VC toViewController:self.watchListViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  563. }
  564. };
  565. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  566. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  567. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  568. [self presentViewController:navi animated:YES completion:^{
  569. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  570. DebugLog(@"LoginViewController present.........");
  571. // self.btop = false;
  572. // <#code#>
  573. }];
  574. }
  575. else
  576. [self flipFromViewController:self.current_VC toViewController:self.watchListViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  577. }
  578. - (IBAction)switchToContact:(UIButton *)sender {
  579. [self switchtocontact];
  580. }
  581. -(void)switchtocontact
  582. {
  583. if([self.current_VC isKindOfClass:[ContactListViewController class]])
  584. return;
  585. UIApplication * app = [UIApplication sharedApplication];
  586. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  587. if(appDelegate.bLogin==false)
  588. {
  589. LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  590. // loginvc.delegate = self;
  591. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  592. loginvc.returnValue = ^(bool blogin){
  593. if(blogin)
  594. {
  595. [self checklogin:true];
  596. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  597. {
  598. [self flipFromViewController:self.current_VC toViewController:self.contactListViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  599. }
  600. else
  601. {
  602. [RAUtils message_alert:@"Customer Login does not support this feature." title:@"Contact List" controller:self] ;
  603. }
  604. }
  605. };
  606. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  607. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  608. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  609. [self presentViewController:navi animated:YES completion:^{
  610. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  611. DebugLog(@"LoginViewController present.........");
  612. // self.btop = false;
  613. // <#code#>
  614. }];
  615. }
  616. else
  617. [self flipFromViewController:self.current_VC toViewController:self.contactListViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  618. //
  619. // UIApplication * app = [UIApplication sharedApplication];
  620. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  621. // ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  622. // cvc.update_order = true;
  623. // cvc.contact_type = @"Sales_Order_Customer";
  624. // cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  625. //
  626. // appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  627. // appDelegate.customerInfo = value;
  628. //
  629. // // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  630. //
  631. // //
  632. // // if(self.returnValue)
  633. // // self.returnValue(value);
  634. // };
  635. // [self.navigationController pushViewController:cvc animated:true];
  636. }
  637. - (void) reload
  638. {
  639. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  640. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  641. NSDictionary* category=[RANetwork request_Cagegory];
  642. dispatch_async(dispatch_get_main_queue(), ^{
  643. if([[category valueForKey:@"result"] intValue]==2)
  644. {
  645. appDelegate.categoryMenu = category;
  646. }
  647. else
  648. {
  649. // [RAUtils error_alert:[category valueForKey:@"err_msg"]] ;
  650. }
  651. });
  652. });
  653. }
  654. - (IBAction)onUserButtonClick:(id)sender {
  655. DebugLog(@"header view login");
  656. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  657. if( appDelegate.user ==nil)
  658. {
  659. LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  660. // loginvc.delegate = self;
  661. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  662. loginvc.returnValue = ^(bool blogin){
  663. [self checklogin:true];
  664. };
  665. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  666. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  667. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  668. [self presentViewController:navi animated:YES completion:^{
  669. // <#code#>
  670. }];
  671. // LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  672. // loginvc.delegate = self;
  673. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  674. // [self presentViewController:loginvc animated:YES completion:^{
  675. //
  676. // DebugLog(@"login.........");
  677. // // <#code#>
  678. // }];
  679. }
  680. }
  681. #pragma mark - LoginViewControllerDelegate
  682. -(void)LoginViewControllerDidLogin:(LoginViewController *)viewController
  683. {
  684. [viewController dismissViewControllerAnimated:YES completion:nil];
  685. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  686. self.sideMenu_UserName.text =appDelegate.user;
  687. [self.btn_sideMenu_UserName setTitle:appDelegate.user forState:UIControlStateNormal];
  688. [self.btnLogin setTitle:@"Sign out" forState:UIControlStateNormal];
  689. [RANetwork LoadImage:appDelegate.user_icon into:self.user_head ];
  690. if(/*appDelegate.user_type==USER_ROLE_EMPLOYEE*/true)
  691. self.btnContact.hidden = NO;
  692. else
  693. self.btnContact.hidden = YES;
  694. NSDictionary * customerinfo=appDelegate.customerInfo;
  695. NSString * contact=nil;
  696. NSString * customer=nil;
  697. if(customerinfo==nil)
  698. {
  699. contact=@"Select Contact";
  700. [self.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  701. }
  702. else
  703. {
  704. contact=[customerinfo valueForKey:@"customer_contact"];
  705. customer=[customerinfo valueForKey:@"customer_name"];
  706. if(contact==nil||contact.length==0)
  707. {
  708. contact=@"No Name";
  709. [self.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  710. }
  711. else
  712. {
  713. [self.btnContact setTitleColor:UIColorFromRGB(0x009900) forState:UIControlStateNormal];
  714. }
  715. }
  716. NSMutableArray* arr_contact = [[NSMutableArray alloc] init];
  717. if(contact.length>0)
  718. [arr_contact addObject:contact];
  719. if(customer.length>0)
  720. [arr_contact addObject:customer];
  721. NSString *contact_string = [arr_contact componentsJoinedByString:@" @"];
  722. [self.btnContact setTitle:contact_string forState:UIControlStateNormal];
  723. // [self.buttonUser setTitle:appDelegate.user forState:UIControlStateNormal];
  724. [self reload];
  725. }
  726. - (void) flipFromViewController:(UIViewController*) fromController
  727. toViewController:(UIViewController*) toController
  728. withDirection:(UIViewAnimationOptions) direction
  729. {
  730. toController.view.frame = self.container.bounds; // 1
  731. // UIViewAutoresizingFlexibleLeftMargin = 1 << 0,
  732. // UIViewAutoresizingFlexibleWidth = 1 << 1,
  733. // UIViewAutoresizingFlexibleRightMargin = 1 << 2,
  734. // UIViewAutoresizingFlexibleTopMargin = 1 << 3,
  735. // UIViewAutoresizingFlexibleHeight = 1 << 4,
  736. // UIViewAutoresizingFlexibleBottomMargin = 1 << 5
  737. toController.view.autoresizingMask = UIViewAutoresizingFlexibleHeight |UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin;
  738. NSLog(@"MAIN VIEWCONTROLLER CHILD COUNT %lu",(unsigned long)self.childViewControllers.count);
  739. [self addChildViewController:toController]; //
  740. [fromController willMoveToParentViewController:nil]; //
  741. [self transitionFromViewController:fromController
  742. toViewController:toController
  743. duration:0.0
  744. options:direction | UIViewAnimationOptionCurveEaseIn
  745. animations:nil
  746. completion:^(BOOL finished) {
  747. [toController didMoveToParentViewController:self]; // 2
  748. [fromController removeFromParentViewController]; // 3
  749. self.current_VC = toController;
  750. if([fromController isKindOfClass:[HomeViewController class]])
  751. {
  752. // [[NSNotificationCenter defaultCenter] postNotificationName:CYCLESCROLL_STOPTIMMER object:nil];
  753. // self.homeViewController = nil;
  754. }
  755. }];
  756. }
  757. -(void)topicViewSelected:(int) type _id: (int) _id
  758. {
  759. [self switchToCagegory:nil];
  760. if(type==0)
  761. {
  762. // [self.categoryViewController showDetailat:_id];
  763. }
  764. else
  765. {
  766. [self.categoryViewController showCategory];
  767. }
  768. }
  769. -(void)categoryMenuSelected:(NSString*)_id
  770. {
  771. [self switchToCagegory:_id];
  772. // [self.categoryViewController showCategory];
  773. }
  774. - (void)switchToItemSearch:(NSString* )coverttype {
  775. // NSString* ttt =[@"Category" stringByAppendingString:[self categoryString:categoryid node:self.categoryMenu level:0]];
  776. // UIApplication * app = [UIApplication sharedApplication];
  777. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  778. self.itemSearchViewController.default_filter = nil;
  779. self.itemSearchViewController.covertype = coverttype;
  780. self.itemSearchViewController.saved_covertype = coverttype;
  781. // self.categoryViewController.p_available = nil;
  782. // self.categoryViewController.p_price = nil;
  783. // self.categoryViewController.p_QTY = nil;
  784. // self.categoryViewController.p_bestseller = nil;
  785. // [self.itemSearchViewController reload_container_getdata:true];
  786. self.itemSearchViewController.p_available = nil;
  787. self.itemSearchViewController.p_price = nil;
  788. self.itemSearchViewController.p_QTY = nil;
  789. self.itemSearchViewController.p_bestseller = nil;
  790. [self.itemSearchViewController reload_container_getdata:true];
  791. // .categoryString = [@"Category" stringByAppendingString:[self categoryString:categoryid node:appDelegate.categoryMenu level:0]];
  792. // self.categoryViewController.cagegoryLabel.text =self.categoryViewController.categoryString;
  793. // // NSString* sss =[@"Category" stringByAppendingString:[self categoryString:categoryid node:appDelegate.categoryMenu level:0]];
  794. // self.categoryViewController.categoryid = categoryid ;
  795. // [self.itemSearchViewController reload];
  796. // [self.itemSearchViewController showCategory];
  797. if([self.current_VC isKindOfClass:[ItemSearchViewController class]])
  798. return;
  799. [self flipFromViewController:self.current_VC toViewController:self.itemSearchViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  800. [[self navigationController] setNavigationBarHidden:YES animated:NO];
  801. // self.is_home = false;
  802. // self.current_vc = VC_CATEGORY;
  803. // [self.homeViewController willMoveToParentViewController:nil]; //1
  804. // [self.homeViewController.view removeFromSuperview]; //2
  805. // [self.homeViewController removeFromParentViewController]; //3
  806. //
  807. // [self.container addSubview:self.cagegoryViewController.view]; //2
  808. // [self.cagegoryViewController didMoveToParentViewController:self];
  809. }
  810. - (void)switchToCagegory:(NSString* )categoryid {
  811. // NSString* ttt =[@"Category" stringByAppendingString:[self categoryString:categoryid node:self.categoryMenu level:0]];
  812. UIApplication * app = [UIApplication sharedApplication];
  813. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  814. // NSString* aaa =[@"Category" stringByAppendingString:[self categoryString:categoryid node:appDelegate.categoryMenu level:0]];;
  815. self.categoryViewController.categoryString = [@"Category" stringByAppendingString:[self categoryString:categoryid node:appDelegate.categoryMenu level:0]];
  816. self.categoryViewController.cagegoryLabel.text =self.categoryViewController.categoryString;
  817. // NSString* sss =[@"Category" stringByAppendingString:[self categoryString:categoryid node:appDelegate.categoryMenu level:0]];
  818. self.categoryViewController.categoryid = categoryid ;
  819. self.categoryViewController.loadall=false;
  820. // self.categoryViewController.collectionview
  821. self.categoryViewController.p_alert = nil;
  822. self.categoryViewController.p_available = nil;
  823. self.categoryViewController.p_price = nil;
  824. self.categoryViewController.p_QTY = nil;
  825. self.categoryViewController.p_bestseller = nil;
  826. self.categoryViewController.modelname = nil;
  827. self.categoryViewController.modeldescrip = nil;
  828. [self.categoryViewController reload_container_getdata:true];
  829. [self.categoryViewController showCategory];
  830. if([self.current_VC isKindOfClass:[CategoryViewController class]])
  831. return;
  832. [self flipFromViewController:self.current_VC toViewController:self.categoryViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  833. [[self navigationController] setNavigationBarHidden:YES animated:NO];
  834. // self.is_home = false;
  835. // self.current_vc = VC_CATEGORY;
  836. // [self.homeViewController willMoveToParentViewController:nil]; //1
  837. // [self.homeViewController.view removeFromSuperview]; //2
  838. // [self.homeViewController removeFromParentViewController]; //3
  839. //
  840. // [self.container addSubview:self.cagegoryViewController.view]; //2
  841. // [self.cagegoryViewController didMoveToParentViewController:self];
  842. }
  843. - (IBAction)switchToHome:(UIButton *)sender {
  844. [self switchToHome];
  845. // self.current_vc = VC_HOME;
  846. // self.is_home = true;
  847. //
  848. // [self.cagegoryViewController willMoveToParentViewController:nil]; //1
  849. // [self.cagegoryViewController.view removeFromSuperview]; //2
  850. // [self.cagegoryViewController removeFromParentViewController]; //3
  851. //
  852. // [self.container addSubview:self.homeViewController.view]; //2
  853. // [self.homeViewController didMoveToParentViewController:self];
  854. }
  855. -(void)switchToHome
  856. {
  857. if([self.current_VC isKindOfClass:[HomeViewController class]])
  858. return;
  859. if(self.homeViewController == nil)
  860. {
  861. self.homeViewController =[ self.storyboard instantiateViewControllerWithIdentifier:@"HomeViewController"];
  862. self.homeViewController.view.frame = self.container.bounds;
  863. }
  864. [self flipFromViewController:self.current_VC toViewController:self.homeViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  865. }
  866. -(void) switchToPreviousVC
  867. {
  868. if(self.previous_VC==nil)
  869. return;
  870. if([self.current_VC isKindOfClass:[self.previous_VC class]])
  871. return;
  872. [self flipFromViewController:self.current_VC toViewController:self.previous_VC withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  873. }
  874. - (IBAction)switchToCart:(UIButton *)sender {
  875. [self switchToCart];
  876. // self.current_vc = VC_HOME;
  877. }
  878. -(void) switchToCart
  879. {
  880. if([self.current_VC isKindOfClass:[CartViewController class]])
  881. return;
  882. UIApplication * app = [UIApplication sharedApplication];
  883. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  884. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  885. if(appDelegate.bLogin==false)
  886. {
  887. LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  888. // loginvc.delegate = self;
  889. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  890. loginvc.returnValue = ^(bool blogin){
  891. // UIApplication * app = [UIApplication sharedApplication];
  892. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  893. if(blogin)
  894. {
  895. if(/*appDelegate.user_type==USER_ROLE_EMPLOYEE*/true)
  896. {
  897. [self checklogin:false];
  898. if(appDelegate.can_create_order)
  899. {
  900. NSString* msg =@"";
  901. if(appDelegate.contact_id.length>0)
  902. {
  903. msg = [msg stringByAppendingString:@"\n\nCustomer:"];
  904. msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
  905. }
  906. 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];
  907. // alert.
  908. [alert show];
  909. }
  910. else
  911. {
  912. 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];
  913. // alert.
  914. [alert show];
  915. }
  916. }
  917. else
  918. {
  919. [self checklogin:true];
  920. self.previous_VC = self.current_VC;
  921. [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  922. }
  923. }
  924. // self.offset = 0;
  925. // [self.content_data removeAllObjects];
  926. // [self loadpage];
  927. //
  928. // [[self navigationController] setNavigationBarHidden:YES animated:NO];
  929. };
  930. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  931. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  932. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  933. [self presentViewController:navi animated:YES completion:^{
  934. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  935. DebugLog(@"LoginViewController present.........");
  936. // self.btop = false;
  937. // <#code#>
  938. }];
  939. }
  940. else
  941. {
  942. if(/*appDelegate.user_type==USER_ROLE_EMPLOYEE&&/*appDelegate.contact_id==nil&&*/appDelegate.order_code==nil)
  943. {
  944. [self checklogin:false];
  945. if(appDelegate.can_create_order)
  946. {
  947. NSString* msg =@"";
  948. if(appDelegate.contact_id.length>0)
  949. {
  950. msg = [msg stringByAppendingString:@"\n\nCustomer:"];
  951. msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
  952. }
  953. 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];
  954. // alert.
  955. [alert show];
  956. }
  957. else
  958. {
  959. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Switch to cart", nil) message:NSLocalizedString(@"Do you want to Switch to a pending order?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Switch to pending order", nil), nil];
  960. // alert.
  961. [alert show];
  962. }
  963. }
  964. else
  965. {
  966. self.previous_VC = self.current_VC;
  967. [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  968. }
  969. }
  970. }
  971. -(void) switchToOrder
  972. {
  973. if([self.current_VC isKindOfClass:[OrderListViewController class]])
  974. return;
  975. UIApplication * app = [UIApplication sharedApplication];
  976. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  977. if(appDelegate.bLogin==false)
  978. {
  979. LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  980. // loginvc.delegate = self;
  981. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  982. loginvc.returnValue = ^(bool blogin){
  983. if(blogin)
  984. {
  985. [self checklogin:true];
  986. [self flipFromViewController:self.current_VC toViewController:self.orderViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  987. }
  988. };
  989. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  990. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  991. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  992. [self presentViewController:navi animated:YES completion:^{
  993. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  994. DebugLog(@"LoginViewController present.........");
  995. // self.btop = false;
  996. // <#code#>
  997. }];
  998. }
  999. else
  1000. [self flipFromViewController:self.current_VC toViewController:self.orderViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1001. }
  1002. - (IBAction)switchToOrder:(id)sender {
  1003. [self switchToOrder];
  1004. //self.orderViewController =[ self.storyboard instantiateViewControllerWithIdentifier:@"OrderListViewController"];
  1005. }
  1006. #pragma mark - CategoryMenuDelegate
  1007. -(void)SelectCategory:(NSString *)category
  1008. {
  1009. [self switchToCagegory:category];
  1010. }
  1011. - (IBAction)showCategoryMenu:(id)sender {
  1012. RAViewController * categorymenuVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"RAViewController"];
  1013. // categorymenuVC.rootViewController = self;
  1014. categorymenuVC.CateMenu_delegate = self;
  1015. // categorymenuVC.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1016. // [self presentViewController:categorymenuVC animated:YES completion:^{
  1017. //
  1018. // DebugLog(@"login.........");
  1019. // // <#code#>
  1020. // }];
  1021. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:categorymenuVC] ;
  1022. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  1023. [self presentViewController:navi animated:YES completion:^{
  1024. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1025. DebugLog(@"bundle present.........");
  1026. // self.btop = false;
  1027. // <#code#>
  1028. }];
  1029. // if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
  1030. // categorymenuVC.providesPresentationContextTransitionStyle = YES;
  1031. // categorymenuVC.definesPresentationContext = YES;
  1032. // categorymenuVC.modalPresentationStyle = UIModalPresentationFormSheet;
  1033. // [self presentViewController:categorymenuVC animated:YES completion:nil];
  1034. // } else {
  1035. // categorymenuVC.modalPresentationStyle = UIModalPresentationFormSheet;
  1036. // [self presentViewController:categorymenuVC animated:NO completion:nil];
  1037. //// self.view.window.rootViewController.modalPresentationStyle = UIModalPresentationFullScreen;
  1038. // }
  1039. UIApplication * app = [UIApplication sharedApplication];
  1040. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1041. if(appDelegate.categoryMenu == nil)
  1042. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1043. NSDictionary* category=[RANetwork request_Cagegory];
  1044. dispatch_async(dispatch_get_main_queue(), ^{
  1045. if([[category valueForKey:@"result"] intValue]==2)
  1046. {
  1047. appDelegate.categoryMenu = category;
  1048. [categorymenuVC SetMenu:appDelegate.categoryMenu ];
  1049. }
  1050. else
  1051. if([[category valueForKey:@"result"] intValue]==RESULT_NET_ERROR)
  1052. {
  1053. [categorymenuVC SetMenu:nil ];
  1054. }
  1055. else
  1056. {
  1057. [RAUtils message_alert:[category valueForKey:@"err_msg"] title:@"Load Category Menu" controller:self] ;
  1058. }
  1059. });
  1060. });
  1061. else
  1062. [categorymenuVC SetMenu:appDelegate.categoryMenu];
  1063. }
  1064. -(NSString*) categoryString:(NSString*) categoryid node:(NSDictionary*) json level:(int) level;
  1065. {
  1066. if(categoryid.length==0)
  1067. return @">All Products>";
  1068. //NSString* idString = [NSString stringWithFormat:@"%d",categoryid];
  1069. NSString* categoryString =@">";
  1070. int count = [[json valueForKey:@"count"] intValue];
  1071. for(int i=0;i<count;i++)
  1072. {
  1073. NSDictionary * category_json = [json objectForKey:[NSString stringWithFormat:@"category_%d",i]];
  1074. NSString* cid = [category_json valueForKey:@"id"] ;
  1075. // NSString* ttt =[categoryid substringToIndex:2+level*2];
  1076. // NSString * qqq =[cid substringToIndex:2+level*2];
  1077. // NSString *ds1=[categoryid substringToIndex:3+level*3];
  1078. // NSString*ds2 = [cid substringToIndex:3+level*3];
  1079. if(cid.length<3+level*3)
  1080. continue;
  1081. if(categoryid.length<3+level*3)
  1082. continue;
  1083. if([[categoryid substringToIndex:3+level*3] isEqualToString: [cid substringToIndex:3+level*3]])
  1084. {
  1085. //categoryString = [categoryString stringByAppendingString:@">"];
  1086. categoryString =[categoryString stringByAppendingString: [category_json valueForKey:@"title" ] ];
  1087. categoryString = [categoryString stringByAppendingString:[ self categoryString:categoryid node:category_json level:level+1]];
  1088. break;
  1089. }
  1090. }
  1091. return categoryString;
  1092. }
  1093. - (void)didReceiveMemoryWarning
  1094. {
  1095. [super didReceiveMemoryWarning];
  1096. // Dispose of any resources that can be recreated.
  1097. }
  1098. - (IBAction)openMenu:(UIButton *)sender {
  1099. [self showMenu];
  1100. // [((RootContainerViewController *)self.parentViewController) showMenu];
  1101. // SideMenuViewController *sideMenuController = [self.storyboard instantiateViewControllerWithIdentifier:@"SideMenuViewController"];
  1102. // if (sideMenuController) {
  1103. // //[sideMenuController openMenu];
  1104. // [UIView animateWithDuration:1.0 animations:^{ sideMenuController.view.alpha = 1.0;
  1105. // self.view.alpha = 0.0; }];
  1106. // }
  1107. }
  1108. - (UIImage*)screen_shot
  1109. {
  1110. // CGRect r = self.view.frame;
  1111. // CGRect r1 = self.view.bounds;
  1112. // double width,height;
  1113. //
  1114. // UIInterfaceOrientation orientation =[UIApplication sharedApplication].statusBarOrientation;
  1115. // ;
  1116. // if(orientation == UIDeviceOrientationLandscapeLeft ||orientation == UIDeviceOrientationLandscapeRight)
  1117. // {
  1118. // width = self.view.frame.size.width>self.view.frame.size.height? self.view.frame.size.width:self.view.frame.size.height;
  1119. // height =self.view.frame.size.width<self.view.frame.size.height? self.view.frame.size.width:self.view.frame.size.height;
  1120. // }
  1121. // else
  1122. // {
  1123. // width = self.view.frame.size.width<self.view.frame.size.height? self.view.frame.size.width:self.view.frame.size.height;
  1124. // height =self.view.frame.size.width>self.view.frame.size.height? self.view.frame.size.width:self.view.frame.size.height;
  1125. // }
  1126. UIGraphicsBeginImageContext(CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height));
  1127. [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
  1128. UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
  1129. UIGraphicsEndImageContext();
  1130. return viewImage;
  1131. }
  1132. - (IBAction)onhideMenuClick:(id)sender {
  1133. [self hideMenu];
  1134. self.backgroundButton.hidden=true;
  1135. self.openMenuButton.hidden = false;
  1136. self.sideMenu.hidden = true;
  1137. }
  1138. - (void)hideMenu
  1139. {
  1140. CGRect frame ;
  1141. frame.origin.x = -300;
  1142. frame.origin.y = 0;
  1143. frame.size.height = self.view.bounds.size.height;
  1144. frame.size.width = 364;
  1145. self.sideMenu.frame=frame;
  1146. self.sideMenu.hidden = true;
  1147. self.blurView.alpha = 0;
  1148. [self.menuButton setImage:[UIImage imageNamed:@"menu_open"] forState:UIControlStateNormal];
  1149. self.menuShown = false;
  1150. self.backgroundButton.hidden=true;
  1151. self.openMenuButton.hidden = false;
  1152. }
  1153. - (void)showMenu
  1154. {
  1155. [self.sideMenuTable reloadData];
  1156. UIImage* imgsource = [self screen_shot];
  1157. self.blurView.alpha = 0;
  1158. UIImage* imgBlur =[self applyBlurWithRadius:5 sourceImage:imgsource tintColor:[UIColor colorWithWhite:0.2 alpha:0.73] saturationDeltaFactor:1.8 maskImage:nil];
  1159. self.blurView.image = imgBlur;
  1160. // self.blurView.hidden = imgBlur;
  1161. // [self.sideMenu becomeFirstResponder];
  1162. self.sideMenu.hidden = false;
  1163. self.backgroundButton.hidden=false;
  1164. CGRect frame ;
  1165. frame.origin.x = 0;
  1166. frame.origin.y = 0;
  1167. frame.size.height = self.view.bounds.size.height;
  1168. frame.size.width = 364;
  1169. // [UIView animateWithDuration:1.0 animations:^{ self.sideMenu.frame=frame;
  1170. // self.blurView.alpha = 1;
  1171. // [self.menuButton setImage:[UIImage imageNamed:@"menu"] forState:UIControlStateNormal];
  1172. //
  1173. // }];
  1174. [UIView animateWithDuration:0.5 animations:^{ self.sideMenu.frame=frame;
  1175. self.blurView.alpha = 1;
  1176. }
  1177. completion:^(BOOL finished) {
  1178. [self.menuButton setImage:[UIImage imageNamed:@"menu"] forState:UIControlStateNormal];
  1179. }];
  1180. // UIImage* img= [UIImage imageNamed:@"menu"];
  1181. // self.menuButton.imageView.image = nil;
  1182. self.menuShown = true;
  1183. }
  1184. -(void)initMenuItems
  1185. {
  1186. UIApplication * app = [UIApplication sharedApplication];
  1187. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1188. self.sideMenuItems = [[NSMutableArray alloc] init];
  1189. NSMutableDictionary* map = [[NSMutableDictionary alloc] init];
  1190. if(appDelegate.user!=nil)
  1191. {
  1192. [map setValue:@"Wish List" forKey:@"title"];
  1193. [map setValue:@"rect_market_news" forKey:@"img"];
  1194. [self.sideMenuItems addObject:map.copy];
  1195. }
  1196. #if !defined(BUILD_HOMER) && !defined(BUILD_GATIT)
  1197. //#ifndef BUILD_HOMER //homer 要求去掉cam scan 2017/12/20
  1198. // if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  1199. {
  1200. [map setValue:@"Cam Scan" forKey:@"title"];
  1201. [map setValue:@"rect_contact_list" forKey:@"img"];
  1202. [self.sideMenuItems addObject:map.copy];
  1203. }
  1204. #endif
  1205. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  1206. {
  1207. // [map setValue:@"Contact" forKey:@"title"];
  1208. // [map setValue:@"rect_contact_list" forKey:@"img"];
  1209. // [self.sideMenuItems addObject:map.copy];
  1210. [map setValue:@"Portfolio" forKey:@"title"];
  1211. [map setValue:@"rect_market_news" forKey:@"img"];
  1212. [self.sideMenuItems addObject:map.copy];
  1213. [map setValue:@"View Portfolios" forKey:@"title"];
  1214. [map setValue:@"rect_pdf_list" forKey:@"img"];
  1215. [self.sideMenuItems addObject:map.copy];
  1216. }
  1217. if(appDelegate.can_show_price)
  1218. {
  1219. if(appDelegate.price_hidden)
  1220. [map setValue:@"Show Price" forKey:@"title"];
  1221. else
  1222. [map setValue:@"Hide Price" forKey:@"title"];
  1223. [map setValue:@"rect_announcements" forKey:@"img"];
  1224. [self.sideMenuItems addObject:map.copy];
  1225. }
  1226. // [map setValue:@"Contact" forKey:@"title"];
  1227. // [map setValue:@"rect_market_news" forKey:@"img"];
  1228. // [self.sideMenuItems addObject:map.copy];
  1229. // [map setValue:@"Cache" forKey:@"title"];
  1230. // [map setValue:@"rect_announcements" forKey:@"img"];
  1231. //[self.sideMenuItems addObject:map.copy];
  1232. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  1233. // [map setValue:@"Message" forKey:@"title"];
  1234. // [map setValue:@"rect_search_history" forKey:@"img"];
  1235. // [self.sideMenuItems addObject:map.copy];
  1236. //
  1237. #if defined(BUILD_NPD) || defined(BUILD_USAI)
  1238. [map setValue:@"Scanner Setting" forKey:@"title"];
  1239. [map setValue:@"rect_change_password" forKey:@"img"];
  1240. [self.sideMenuItems addObject:map.copy];
  1241. #ifdef BUILD_NPD
  1242. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  1243. {
  1244. [map setValue:@"Offline Setting" forKey:@"title"];
  1245. [map setValue:@"rect_market_news" forKey:@"img"];
  1246. [self.sideMenuItems addObject:map.copy];
  1247. }
  1248. #endif
  1249. if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER) {
  1250. [map setValue:@"Price Setting" forKey:@"title"];
  1251. // [map setValue:@"rect_market_news" forKey:@"img"];
  1252. [self.sideMenuItems addObject:map.copy];
  1253. }
  1254. if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER) {
  1255. if ([Singleton sharedInstance].global_lock) {
  1256. [map setValue:@"Unlock" forKey:@"title"];
  1257. } else {
  1258. [map setValue:@"Lock" forKey:@"title"];
  1259. }
  1260. [self.sideMenuItems addObject:map.copy];
  1261. }
  1262. # endif
  1263. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  1264. /*
  1265. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  1266. {
  1267. [map setValue:@"Offline Setting" forKey:@"title"];
  1268. [map setValue:@"rect_market_news" forKey:@"img"];
  1269. [self.sideMenuItems addObject:map.copy];
  1270. }
  1271. */
  1272. // if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER) {
  1273. // [map setValue:@"Price Setting" forKey:@"title"];
  1274. // // [map setValue:@"rect_market_news" forKey:@"img"];
  1275. // [self.sideMenuItems addObject:map.copy];
  1276. // }
  1277. if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER) {
  1278. if ([Singleton sharedInstance].global_lock) {
  1279. [map setValue:@"Unlock" forKey:@"title"];
  1280. } else {
  1281. [map setValue:@"Lock" forKey:@"title"];
  1282. }
  1283. [self.sideMenuItems addObject:map.copy];
  1284. }
  1285. # endif
  1286. // if([[appDelegate.user lowercaseString] isEqualToString:@"larryl"]||[[appDelegate.user lowercaseString] isEqualToString:@"arpithat"])
  1287. // {
  1288. // // [map setValue:@"Contact" forKey:@"title"];
  1289. // // [map setValue:@"rect_contact_list" forKey:@"img"];
  1290. // // [self.sideMenuItems addObject:map.copy];
  1291. //
  1292. //
  1293. // [map setValue:@"Function Test" forKey:@"title"];
  1294. // [map setValue:@"rect_market_news" forKey:@"img"];
  1295. // [self.sideMenuItems addObject:map.copy];
  1296. //
  1297. //
  1298. // }
  1299. //
  1300. [map setValue:@"About us" forKey:@"title"];
  1301. [map setValue:@"rect_change_password" forKey:@"img"];
  1302. [self.sideMenuItems addObject:map.copy];
  1303. #ifdef BUILD_HMLG
  1304. [map setValue:@"Homelegance Website" forKey:@"title"];
  1305. [map setValue:@"rect_change_password" forKey:@"img"];
  1306. [self.sideMenuItems addObject:map.copy];
  1307. #endif
  1308. #ifdef BUILD_NPD
  1309. [map setValue:@"BLOG" forKey:@"title"];
  1310. [map setValue:@"rect_change_password" forKey:@"img"];
  1311. [self.sideMenuItems addObject:map.copy];
  1312. [map setValue:[NSString stringWithFormat:@"%@ Website",COMPANY_SHORT_NAME] forKey:@"title"];
  1313. [map setValue:@"rect_change_password" forKey:@"img"];
  1314. [self.sideMenuItems addObject:map.copy];
  1315. [map setValue:[NSString stringWithFormat:@"%@ Policy",COMPANY_SHORT_NAME] forKey:@"title"];
  1316. [map setValue:@"rect_change_password" forKey:@"img"];
  1317. [self.sideMenuItems addObject:map.copy];
  1318. [map setValue:@"Simplified Buying Program" forKey:@"title"];
  1319. [map setValue:@"rect_change_password" forKey:@"img"];
  1320. [self.sideMenuItems addObject:map.copy];
  1321. #endif
  1322. #ifdef BUILD_USAI
  1323. // [map setValue:@"BLOG" forKey:@"title"];
  1324. // [map setValue:@"rect_change_password" forKey:@"img"];
  1325. // [self.sideMenuItems addObject:map.copy];
  1326. [map setValue:@"USAI Website" forKey:@"title"];
  1327. [map setValue:@"rect_change_password" forKey:@"img"];
  1328. [self.sideMenuItems addObject:map.copy];
  1329. // [map setValue:@"USAI Policy" forKey:@"title"];
  1330. // [map setValue:@"rect_change_password" forKey:@"img"];
  1331. // [self.sideMenuItems addObject:map.copy];
  1332. // [map setValue:@"Simplified Buying Program" forKey:@"title"];
  1333. // [map setValue:@"rect_change_password" forKey:@"img"];
  1334. // [self.sideMenuItems addObject:map.copy];
  1335. #endif
  1336. #ifdef BUILD_HOMER
  1337. /*
  1338. [map setValue:@"BLOG" forKey:@"title"];
  1339. [map setValue:@"rect_change_password" forKey:@"img"];
  1340. [self.sideMenuItems addObject:map.copy];
  1341. */
  1342. [map setValue:@"HOMER Website" forKey:@"title"];
  1343. [map setValue:@"rect_change_password" forKey:@"img"];
  1344. [self.sideMenuItems addObject:map.copy];
  1345. /*
  1346. [map setValue:@"HOMER Policy" forKey:@"title"];
  1347. [map setValue:@"rect_change_password" forKey:@"img"];
  1348. [self.sideMenuItems addObject:map.copy];
  1349. [map setValue:@"Simplified Buying Program" forKey:@"title"];
  1350. [map setValue:@"rect_change_password" forKey:@"img"];
  1351. [self.sideMenuItems addObject:map.copy];
  1352. */
  1353. #endif
  1354. #ifdef BUILD_GATIT
  1355. [map setValue:@"TITAN Website" forKey:@"title"];
  1356. [map setValue:@"rect_change_password" forKey:@"img"];
  1357. [self.sideMenuItems addObject:map.copy];
  1358. # endif
  1359. [self.sideMenuTable reloadData];
  1360. //
  1361. }
  1362. - (UIImage *)applyBlurWithRadius:(CGFloat)blurRadius sourceImage:(UIImage*)sourceImage tintColor:(UIColor *)tintColor saturationDeltaFactor:(CGFloat)saturationDeltaFactor maskImage:(UIImage *)maskImage
  1363. {
  1364. // Check pre-conditions.
  1365. if (sourceImage.size.width < 1 || sourceImage.size.height < 1) {
  1366. DebugLog (@"*** error: invalid size: (%.2f x %.2f). Both dimensions must be >= 1: %@", sourceImage.size.width, sourceImage.size.height, self);
  1367. return nil;
  1368. }
  1369. if (!sourceImage.CGImage) {
  1370. DebugLog (@"*** error: image must be backed by a CGImage: %@", self);
  1371. return nil;
  1372. }
  1373. if (maskImage && !maskImage.CGImage) {
  1374. DebugLog (@"*** error: maskImage must be backed by a CGImage: %@", maskImage);
  1375. return nil;
  1376. }
  1377. CGRect imageRect = { CGPointZero, sourceImage.size };
  1378. UIImage *effectImage = sourceImage;
  1379. BOOL hasBlur = blurRadius > __FLT_EPSILON__;
  1380. BOOL hasSaturationChange = fabs(saturationDeltaFactor - 1.) > __FLT_EPSILON__;
  1381. if (hasBlur || hasSaturationChange) {
  1382. UIGraphicsBeginImageContextWithOptions(sourceImage.size, NO, [[UIScreen mainScreen] scale]);
  1383. CGContextRef effectInContext = UIGraphicsGetCurrentContext();
  1384. CGContextScaleCTM(effectInContext, 1.0, -1.0);
  1385. CGContextTranslateCTM(effectInContext, 0, -sourceImage.size.height);
  1386. CGContextDrawImage(effectInContext, imageRect, sourceImage.CGImage);
  1387. vImage_Buffer effectInBuffer;
  1388. effectInBuffer.data = CGBitmapContextGetData(effectInContext);
  1389. effectInBuffer.width = CGBitmapContextGetWidth(effectInContext);
  1390. effectInBuffer.height = CGBitmapContextGetHeight(effectInContext);
  1391. effectInBuffer.rowBytes = CGBitmapContextGetBytesPerRow(effectInContext);
  1392. UIGraphicsBeginImageContextWithOptions(sourceImage.size, NO, [[UIScreen mainScreen] scale]);
  1393. CGContextRef effectOutContext = UIGraphicsGetCurrentContext();
  1394. vImage_Buffer effectOutBuffer;
  1395. effectOutBuffer.data = CGBitmapContextGetData(effectOutContext);
  1396. effectOutBuffer.width = CGBitmapContextGetWidth(effectOutContext);
  1397. effectOutBuffer.height = CGBitmapContextGetHeight(effectOutContext);
  1398. effectOutBuffer.rowBytes = CGBitmapContextGetBytesPerRow(effectOutContext);
  1399. if (hasBlur) {
  1400. // A description of how to compute the box kernel width from the Gaussian
  1401. // radius (aka standard deviation) appears in the SVG spec:
  1402. // http://www.w3.org/TR/SVG/filters.html#feGaussianBlurElement
  1403. //
  1404. // For larger values of 's' (s >= 2.0), an approximation can be used: Three
  1405. // successive box-blurs build a piece-wise quadratic convolution kernel, which
  1406. // approximates the Gaussian kernel to within roughly 3%.
  1407. //
  1408. // let d = floor(s * 3*sqrt(2*pi)/4 + 0.5)
  1409. //
  1410. // ... if d is odd, use three box-blurs of size 'd', centered on the output pixel.
  1411. //
  1412. CGFloat inputRadius = blurRadius * [[UIScreen mainScreen] scale];
  1413. NSUInteger radius = floor(inputRadius * 3. * sqrt(2 * M_PI) / 4 + 0.5);
  1414. if (radius % 2 != 1) {
  1415. radius += 1; // force radius to be odd so that the three box-blur methodology works.
  1416. }
  1417. vImageBoxConvolve_ARGB8888(&effectInBuffer, &effectOutBuffer, NULL, 0, 0, (unsigned int)radius, (unsigned int)radius, 0, kvImageEdgeExtend);
  1418. vImageBoxConvolve_ARGB8888(&effectOutBuffer, &effectInBuffer, NULL, 0, 0, (unsigned int)radius, (unsigned int)radius, 0, kvImageEdgeExtend);
  1419. vImageBoxConvolve_ARGB8888(&effectInBuffer, &effectOutBuffer, NULL, 0, 0, (unsigned int)radius, (unsigned int)radius, 0, kvImageEdgeExtend);
  1420. }
  1421. BOOL effectImageBuffersAreSwapped = NO;
  1422. if (hasSaturationChange) {
  1423. CGFloat s = saturationDeltaFactor;
  1424. CGFloat floatingPointSaturationMatrix[] = {
  1425. 0.0722 + 0.9278 * s, 0.0722 - 0.0722 * s, 0.0722 - 0.0722 * s, 0,
  1426. 0.7152 - 0.7152 * s, 0.7152 + 0.2848 * s, 0.7152 - 0.7152 * s, 0,
  1427. 0.2126 - 0.2126 * s, 0.2126 - 0.2126 * s, 0.2126 + 0.7873 * s, 0,
  1428. 0, 0, 0, 1,
  1429. };
  1430. const int32_t divisor = 256;
  1431. NSUInteger matrixSize = sizeof(floatingPointSaturationMatrix)/sizeof(floatingPointSaturationMatrix[0]);
  1432. int16_t saturationMatrix[matrixSize];
  1433. for (NSUInteger i = 0; i < matrixSize; ++i) {
  1434. saturationMatrix[i] = (int16_t)roundf(floatingPointSaturationMatrix[i] * divisor);
  1435. }
  1436. if (hasBlur) {
  1437. vImageMatrixMultiply_ARGB8888(&effectOutBuffer, &effectInBuffer, saturationMatrix, divisor, NULL, NULL, kvImageNoFlags);
  1438. effectImageBuffersAreSwapped = YES;
  1439. }
  1440. else {
  1441. vImageMatrixMultiply_ARGB8888(&effectInBuffer, &effectOutBuffer, saturationMatrix, divisor, NULL, NULL, kvImageNoFlags);
  1442. }
  1443. }
  1444. if (!effectImageBuffersAreSwapped)
  1445. effectImage = UIGraphicsGetImageFromCurrentImageContext();
  1446. UIGraphicsEndImageContext();
  1447. if (effectImageBuffersAreSwapped)
  1448. effectImage = UIGraphicsGetImageFromCurrentImageContext();
  1449. UIGraphicsEndImageContext();
  1450. }
  1451. // Set up output context.
  1452. UIGraphicsBeginImageContextWithOptions(sourceImage.size, NO, [[UIScreen mainScreen] scale]);
  1453. CGContextRef outputContext = UIGraphicsGetCurrentContext();
  1454. CGContextScaleCTM(outputContext, 1.0, -1.0);
  1455. CGContextTranslateCTM(outputContext, 0, -sourceImage.size.height);
  1456. // Draw base image.
  1457. CGContextDrawImage(outputContext, imageRect, sourceImage.CGImage);
  1458. // Draw effect image.
  1459. if (hasBlur) {
  1460. CGContextSaveGState(outputContext);
  1461. if (maskImage) {
  1462. CGContextClipToMask(outputContext, imageRect, maskImage.CGImage);
  1463. }
  1464. CGContextDrawImage(outputContext, imageRect, effectImage.CGImage);
  1465. CGContextRestoreGState(outputContext);
  1466. }
  1467. // Add in color tint.
  1468. if (tintColor) {
  1469. CGContextSaveGState(outputContext);
  1470. CGContextSetFillColorWithColor(outputContext, tintColor.CGColor);
  1471. CGContextFillRect(outputContext, imageRect);
  1472. CGContextRestoreGState(outputContext);
  1473. }
  1474. // Output image is ready.
  1475. UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext();
  1476. UIGraphicsEndImageContext();
  1477. return outputImage;
  1478. }
  1479. //- (IBAction)openMenu:(UIButton *)sender {
  1480. //}
  1481. #pragma mark - Table view data source
  1482. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  1483. {
  1484. return 1;
  1485. }
  1486. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  1487. {
  1488. return self.sideMenuItems.count;
  1489. }
  1490. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  1491. {
  1492. UIApplication * app = [UIApplication sharedApplication];
  1493. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1494. NSString *CellIdentifier = @"SideMenuItem";
  1495. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1496. NSString* title = [self.sideMenuItems[indexPath.row] valueForKey:@"title"];
  1497. cell.backgroundColor = [UIColor clearColor];
  1498. // [cell.backgroundColor:[UIColor clearColor]];
  1499. // UIImageView* iv= [[UIImageView alloc] initWithImage:];
  1500. cell.textLabel.text = title;
  1501. cell.detailTextLabel.textColor =[UIColor redColor];
  1502. if([title isEqualToString:@"Wish List"]&&appDelegate.wish_count>0)
  1503. cell.detailTextLabel.text = [NSString stringWithFormat:@"%ld",appDelegate.wish_count];
  1504. else if([title isEqualToString:@"Portfolio"]&&appDelegate.port_count>0)
  1505. cell.detailTextLabel.text = [NSString stringWithFormat:@"%ld",appDelegate.port_count];
  1506. else
  1507. {
  1508. cell.detailTextLabel.text =nil;
  1509. }
  1510. // cell.imageView.image = [UIImage imageNamed:[self.toolsinfo[indexPath.row] valueForKey:@"img"]];
  1511. return cell;
  1512. }
  1513. #pragma mark - Table view delegate
  1514. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  1515. {
  1516. NSString* title = [self.sideMenuItems[indexPath.row] valueForKey:@"title"];
  1517. if([title isEqualToString:@"Cache"])
  1518. {
  1519. CacheViewController * settingvc=[ self.storyboard instantiateViewControllerWithIdentifier:@"CacheViewController"];
  1520. PopupNavigationController * navi=[[PopupNavigationController alloc] initWithRootViewController:settingvc];
  1521. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1522. [self presentViewController:navi animated:YES completion:^{
  1523. //DebugLog(@"login.........");
  1524. // <#code#>
  1525. }];
  1526. }
  1527. else if([title isEqualToString:@"Scanner Setting"])
  1528. {
  1529. UIApplication * app = [UIApplication sharedApplication];
  1530. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1531. UIViewController* active_vc = appDelegate.active_controller;
  1532. ScannerSettingViewController * gunVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"ScannerSettingViewController"];
  1533. // loginvc.delegate = self;
  1534. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1535. appDelegate.active_controller = gunVC;
  1536. gunVC.onDismissVC = ^(){
  1537. appDelegate.active_controller = active_vc;
  1538. };
  1539. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:gunVC] ;
  1540. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1541. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  1542. [self presentViewController:navi animated:YES completion:^{
  1543. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1544. DebugLog(@"about present.........");
  1545. // self.btop = false;
  1546. // <#code#>
  1547. }];
  1548. }
  1549. else if([title isEqualToString:@"Offline Setting"])
  1550. {
  1551. UIApplication * app = [UIApplication sharedApplication];
  1552. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1553. //UIViewController* active_vc = appDelegate.active_controller;
  1554. OfflineSettingViewController * offlineVC =[ [UIStoryboard storyboardWithName:@"OLM" bundle:nil] instantiateViewControllerWithIdentifier:@"OfflineSettingViewController"];
  1555. // loginvc.delegate = self;
  1556. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1557. // appDelegate.active_controller = gunVC;
  1558. // gunVC.onDismissVC = ^(){
  1559. // appDelegate.active_controller = active_vc;
  1560. // };
  1561. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:offlineVC] ;
  1562. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1563. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  1564. [self presentViewController:navi animated:YES completion:^{
  1565. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1566. DebugLog(@"about present.........");
  1567. // self.btop = false;
  1568. // <#code#>
  1569. }];
  1570. // [iSalesDB testdata];
  1571. }
  1572. else if([title isEqualToString:@"Function Test"])
  1573. {
  1574. // NSString* url = @"https://shopla.homelegance.com/";
  1575. //
  1576. //
  1577. // NSString* title = @"NPD";
  1578. // UIApplication * app = [UIApplication sharedApplication];
  1579. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1580. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  1581. //
  1582. //
  1583. FunctionTestViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"FunctionTestViewController"];
  1584. // ViewController.url = url;
  1585. // ViewController.title = title;
  1586. [self.navigationController pushViewController:ViewController animated:YES];
  1587. }
  1588. else if ([title isEqualToString:@"BLOG"]) {
  1589. NSString* url = URL_BLOG;
  1590. #ifdef BUILD_HOMER
  1591. NSString* title = @"HOMER BLOG";
  1592. #endif
  1593. #ifdef BUILD_GATIT
  1594. NSString* title = @"TITAN BLOG";
  1595. #endif
  1596. #ifdef BUILD_NPD
  1597. NSString* title = @"NPD BLOG";
  1598. #endif
  1599. #ifdef BUILD_USAI
  1600. NSString* title = @"USAI BLOG";
  1601. #endif
  1602. title = [NSString stringWithFormat:@"%@ BLOG",COMPANY_SHORT_NAME];
  1603. WebViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"WebViewController"];
  1604. ViewController.url = url;
  1605. ViewController.title = title;
  1606. [self.navigationController pushViewController:ViewController animated:YES];
  1607. }
  1608. else if([title isEqualToString:@"NPD Website"])
  1609. {
  1610. NSString* url = @"https://www.newpacificdirect.com";//@"https://shopla.homelegance.com/general.htm?websiteId=1";//
  1611. NSString* title = @"NPD";
  1612. // UIApplication * app = [UIApplication sharedApplication];
  1613. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1614. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  1615. //
  1616. //
  1617. WebViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"WebViewController"];
  1618. ViewController.url = url;
  1619. ViewController.title = title;
  1620. [self.navigationController pushViewController:ViewController animated:YES];
  1621. }
  1622. else if([title isEqualToString:@"USAI Website"])
  1623. {
  1624. NSString* url = @"http://www.united-us.net/";//@"https://shopla.homelegance.com/general.htm?websiteId=1";//
  1625. NSString* title = @"USAI";
  1626. // UIApplication * app = [UIApplication sharedApplication];
  1627. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1628. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  1629. //
  1630. //
  1631. WebViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"WebViewController"];
  1632. ViewController.url = url;
  1633. ViewController.title = title;
  1634. [self.navigationController pushViewController:ViewController animated:YES];
  1635. }
  1636. else if([title isEqualToString:@"Homelegance Website"])
  1637. {
  1638. NSString* url = @"http://207.140.24.83";//@"https://shopla.homelegance.com/general.htm?websiteId=1";//
  1639. NSString* title = @"Homelegance";
  1640. // UIApplication * app = [UIApplication sharedApplication];
  1641. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1642. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  1643. //
  1644. //
  1645. WebViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"WebViewController"];
  1646. ViewController.url = url;
  1647. ViewController.title = title;
  1648. [self.navigationController pushViewController:ViewController animated:YES];
  1649. }
  1650. else if([title isEqualToString:@"HOMER Website"])
  1651. {
  1652. NSString* url = COMPANY_WEB;
  1653. NSString* title = @"HOMER";
  1654. WebViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"WebViewController"];
  1655. ViewController.url = url;
  1656. ViewController.title = title;
  1657. [self.navigationController pushViewController:ViewController animated:YES];
  1658. }
  1659. else if([title isEqualToString:@"TITAN Website"])
  1660. {
  1661. NSString* url = COMPANY_WEB;
  1662. NSString* title = @"TITAN";
  1663. WebViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"WebViewController"];
  1664. ViewController.url = url;
  1665. ViewController.title = title;
  1666. [self.navigationController pushViewController:ViewController animated:YES];
  1667. }
  1668. else if([title isEqualToString:@"NPD Policy"])
  1669. {
  1670. NSString* url = URL_NPD_POLICY;//@"https://shopla.homelegance.com/general.htm?websiteId=1";//
  1671. NSString* title = @"NPD Policy";
  1672. // UIApplication * app = [UIApplication sharedApplication];
  1673. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1674. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  1675. //
  1676. //
  1677. WebViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"WebViewController"];
  1678. ViewController.url = url;
  1679. ViewController.title = title;
  1680. [self.navigationController pushViewController:ViewController animated:YES];
  1681. }
  1682. else if([title isEqualToString:@"USAI Policy"])
  1683. {
  1684. NSString* url = URL_NPD_POLICY;
  1685. NSString* title = @"USAI Policy";
  1686. WebViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"WebViewController"];
  1687. ViewController.url = url;
  1688. ViewController.title = title;
  1689. [self.navigationController pushViewController:ViewController animated:YES];
  1690. }
  1691. else if([title isEqualToString:@"HOMER Policy"])
  1692. {
  1693. NSString* url = URL_NPD_POLICY;
  1694. NSString* title = @"HOMER Policy";
  1695. WebViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"WebViewController"];
  1696. ViewController.url = url;
  1697. ViewController.title = title;
  1698. [self.navigationController pushViewController:ViewController animated:YES];
  1699. }
  1700. else if([title isEqualToString:@"Simplified Buying Program"])
  1701. {
  1702. SimplifiedBuyingProgramViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"SimplifiedBuyingProgramViewController"];
  1703. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:ViewController] ;
  1704. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1705. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  1706. [self presentViewController:navi animated:YES completion:^{
  1707. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1708. DebugLog(@"about present.........");
  1709. // self.btop = false;
  1710. // <#code#>
  1711. }];
  1712. }
  1713. else if([title isEqualToString:@"About us"])
  1714. {
  1715. AboutViewController * aboutVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"AboutViewController"];
  1716. // loginvc.delegate = self;
  1717. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1718. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:aboutVC] ;
  1719. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1720. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  1721. [self presentViewController:navi animated:YES completion:^{
  1722. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1723. DebugLog(@"about present.........");
  1724. // self.btop = false;
  1725. // <#code#>
  1726. }];
  1727. }
  1728. else if([title isEqualToString:@"Wish List"])
  1729. {
  1730. [self hideMenu];
  1731. [self switchtowishlist];
  1732. }
  1733. else if([title isEqualToString:@"Show Price"])
  1734. {
  1735. UIApplication * app = [UIApplication sharedApplication];
  1736. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1737. if (appDelegate.user_type == USER_ROLE_CUSTOMER && [Singleton sharedInstance].global_lock) {
  1738. JKLockController *lockVC = [[JKLockController alloc] init];
  1739. [lockVC setPasswordKey:[NSString stringWithFormat:@"%@_password",appDelegate.user]];
  1740. __weak typeof(self) weakself = self;
  1741. lockVC.authoReturn = ^(BOOL failure) {
  1742. if (weakself) {
  1743. __strong typeof(weakself) strongself = weakself;
  1744. [appDelegate set_priceHidden:false];
  1745. [strongself initMenuItems];
  1746. [strongself hideMenu];
  1747. }
  1748. };
  1749. [self.navigationController pushViewController:lockVC animated:YES];
  1750. } else {
  1751. [appDelegate set_priceHidden:false];
  1752. [self initMenuItems];
  1753. [self hideMenu];
  1754. }
  1755. }
  1756. else if([title isEqualToString:@"Hide Price"])
  1757. {
  1758. UIApplication * app = [UIApplication sharedApplication];
  1759. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1760. if (appDelegate.user_type == USER_ROLE_CUSTOMER && [Singleton sharedInstance].global_lock) {
  1761. JKLockController *lockVC = [[JKLockController alloc] init];
  1762. [lockVC setPasswordKey:[NSString stringWithFormat:@"%@_password",appDelegate.user]];
  1763. __weak typeof(self) weakself = self;
  1764. lockVC.authoReturn = ^(BOOL failure) {
  1765. if (weakself) {
  1766. __strong typeof(weakself) strongself = weakself;
  1767. [appDelegate set_priceHidden:true];
  1768. [strongself initMenuItems];
  1769. [strongself hideMenu];
  1770. }
  1771. };
  1772. [self.navigationController pushViewController:lockVC animated:YES];
  1773. } else {
  1774. [appDelegate set_priceHidden:true];
  1775. [self initMenuItems];
  1776. [self hideMenu];
  1777. }
  1778. }
  1779. else if([title isEqualToString:@"Portfolio"])
  1780. {
  1781. [self hideMenu];
  1782. if([self.current_VC isKindOfClass:[PortfolioViewController class]])
  1783. return;
  1784. [self flipFromViewController:self.current_VC toViewController:self.portfolioViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1785. }
  1786. else if([title isEqualToString:@"View Portfolios"])
  1787. {
  1788. [self hideMenu];
  1789. if([self.current_VC isKindOfClass:[PDFListViewController class]])
  1790. return;
  1791. [self flipFromViewController:self.current_VC toViewController:self.pdfListViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1792. }
  1793. else if([title isEqualToString:@"Contact"])
  1794. {
  1795. // UITableViewCell* cell =(UITableViewCell*) sender.superview.superview;
  1796. //
  1797. // NSIndexPath * indexPath = [self.detailTable indexPathForCell:cell];
  1798. //
  1799. // if(indexPath.section!=1)
  1800. // return ;
  1801. // // DebugLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
  1802. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1803. //
  1804. // NSString* product_id = [item_json valueForKey:@"product_id"];
  1805. [self hideMenu];
  1806. [self switchtocontact];
  1807. }
  1808. else if([title isEqualToString:@"Cam Scan"])
  1809. {
  1810. // UITableViewCell* cell =(UITableViewCell*) sender.superview.superview;
  1811. //
  1812. // NSIndexPath * indexPath = [self.detailTable indexPathForCell:cell];
  1813. //
  1814. // if(indexPath.section!=1)
  1815. // return ;
  1816. // // DebugLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
  1817. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1818. //
  1819. // NSString* product_id = [item_json valueForKey:@"product_id"];
  1820. [self hideMenu];
  1821. //
  1822. // [self switchtocontact];
  1823. ScannerViewController * scannerVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"ScannerViewController"];
  1824. [self.navigationController pushViewController:scannerVC animated:true];
  1825. } else if ([title isEqualToString:@"Price Setting"]) {
  1826. UIApplication * app = [UIApplication sharedApplication];
  1827. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1828. if ([Singleton sharedInstance].global_lock) {
  1829. JKLockController *lockVC = [[JKLockController alloc] init];
  1830. [lockVC setPasswordKey:[NSString stringWithFormat:@"%@_password",appDelegate.user]];
  1831. __weak typeof(self) weakself = self;
  1832. lockVC.authoReturn = ^(BOOL failure) {
  1833. if (weakself) {
  1834. __strong typeof(weakself) strongself = weakself;
  1835. PriceSettingViewController *priceSettingVC =[ [UIStoryboard storyboardWithName:@"CUL" bundle:nil] instantiateViewControllerWithIdentifier:@"PriceSettingViewController"];
  1836. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:priceSettingVC] ;
  1837. navi.navigationBar.translucent = NO;
  1838. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  1839. [strongself presentViewController:navi animated:YES completion:^{
  1840. }];
  1841. }
  1842. };
  1843. [self.navigationController pushViewController:lockVC animated:YES];
  1844. } else {
  1845. PriceSettingViewController *priceSettingVC =[ [UIStoryboard storyboardWithName:@"CUL" bundle:nil] instantiateViewControllerWithIdentifier:@"PriceSettingViewController"];
  1846. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:priceSettingVC] ;
  1847. navi.navigationBar.translucent = NO;
  1848. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  1849. [self presentViewController:navi animated:YES completion:^{
  1850. }];
  1851. }
  1852. } else if ([title isEqualToString:@"Lock"] || [title isEqualToString:@"Unlock"]) {
  1853. UIApplication * app = [UIApplication sharedApplication];
  1854. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1855. JKLockController *lockVC = [[JKLockController alloc] init];
  1856. [lockVC setPasswordKey:[NSString stringWithFormat:@"%@_password",appDelegate.user]];
  1857. __weak typeof(self) weakself = self;
  1858. lockVC.authoReturn = ^(BOOL failure) {
  1859. if (weakself) {
  1860. __strong typeof(weakself) strongself = weakself;
  1861. [Singleton sharedInstance].global_lock = ![Singleton sharedInstance].global_lock;
  1862. [strongself initMenuItems];
  1863. [strongself hideMenu];
  1864. }
  1865. };
  1866. [self.navigationController pushViewController:lockVC animated:YES];
  1867. }
  1868. }
  1869. #pragma mark - UIAlertViewDelegate
  1870. // Called when a button is clicked. The view will be automatically dismissed after this call returns
  1871. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  1872. {
  1873. UIApplication * app = [UIApplication sharedApplication];
  1874. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1875. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  1876. if(buttonIndex==alertView.cancelButtonIndex)
  1877. {
  1878. }
  1879. else if(buttonIndex==1)
  1880. {
  1881. //open exist
  1882. OrderListViewController* ovc =[ self.storyboard instantiateViewControllerWithIdentifier:@"OrderListViewController"];
  1883. ovc.showNavibar = true;
  1884. ovc.selectOrder = ^(NSMutableDictionary* order_detail){
  1885. if(appDelegate.order_code==nil)
  1886. {
  1887. [self neworderforCart];
  1888. }
  1889. else
  1890. {
  1891. self.previous_VC = self.current_VC;
  1892. [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1893. [self checklogin:true];
  1894. }
  1895. };
  1896. ovc.init_style = OL_OPEN;
  1897. ovc.onCancel = ^(){
  1898. [self checklogin:true];
  1899. };
  1900. ovc.title = @"SAVED ORDER";
  1901. [self.navigationController pushViewController:ovc animated:true];
  1902. }
  1903. else
  1904. {
  1905. //create new;
  1906. if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  1907. {
  1908. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  1909. cvc.showNavibar = true;
  1910. cvc.contact_type = @"Sales_Order_Customer";
  1911. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1912. appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  1913. appDelegate.customerInfo = value;
  1914. if(appDelegate.order_code==nil)
  1915. [self neworderforCart];
  1916. };
  1917. cvc.onCancel = ^(){
  1918. [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"" controller:self];
  1919. };
  1920. cvc.onReset = ^(){
  1921. [self checklogin:true];
  1922. };
  1923. [self.navigationController pushViewController:cvc animated:true];
  1924. }
  1925. else
  1926. {
  1927. [self neworderforCart];
  1928. }
  1929. }
  1930. }
  1931. -(void) neworderforCart
  1932. {
  1933. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Create Order"];
  1934. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1935. NSDictionary* return_json = [RANetwork new_Order];
  1936. dispatch_async(dispatch_get_main_queue(), ^{
  1937. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  1938. if([[return_json valueForKey:@"result"] intValue]==2)
  1939. {
  1940. int result=[[return_json valueForKey:@"result"] intValue];
  1941. if(result==2)
  1942. {
  1943. //successed.
  1944. NSString* order_code = [return_json valueForKey:@"orderCode"];
  1945. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1946. appDelegate.order_code = order_code;
  1947. appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
  1948. self.previous_VC = self.current_VC;
  1949. [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1950. [self reloadCart:true immediately:false];
  1951. }
  1952. }
  1953. else
  1954. {
  1955. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
  1956. }
  1957. });
  1958. });
  1959. }
  1960. - (void)showPriceAuth:(NSInteger)from {
  1961. }
  1962. @end