MainViewController.m 100 KB

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