MainViewController.m 103 KB

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