MainViewController.m 100 KB

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