MainViewController.m 117 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176
  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 "RASingleton.h"
  30. #import "NotificationNameCenter.h"
  31. //#import "OLOSettingViewController.h"
  32. //#import "ScanHistoryViewController.h"
  33. #import "CustomerEditViewController.h"
  34. #import "ScanOrderScanModelViewController.h"
  35. #import "ScanOrderModelListViewController.h"
  36. #import "SetupServerViewController.h"
  37. //#import "ScanUserListViewController.h"
  38. @interface MainViewController ()
  39. // scan order main frame
  40. @end
  41. @implementation MainViewController
  42. -(void) logoutDocuments
  43. {
  44. // [self.pdfListViewController logout];
  45. }
  46. -(void) logoutCart
  47. {
  48. [self.cartViewController logout];
  49. RASingleton.sharedInstance.scan_cart = nil;
  50. RASingleton.sharedInstance.price_type = 1;
  51. }
  52. -(void) logoutWish
  53. {
  54. // [self.watchListViewController logout];
  55. }
  56. -(void) logoutPortfolio
  57. {
  58. // [self.portfolioViewController logout];
  59. }
  60. -(void) logoutOrder
  61. {
  62. [self.scanorderViewController logout];
  63. }
  64. -(void) logoutContact
  65. {
  66. [self.contactListViewController logout];
  67. }
  68. -(void) logoutCategory
  69. {
  70. // [self.categoryViewController logout];
  71. }
  72. - (IBAction)onScanOrderSetting:(id)sender {
  73. [self clearSelected];
  74. self.btnsetting.selected = true;
  75. if([self.current_VC isKindOfClass:[ServerSettingViewController class]])
  76. return;
  77. [self flipFromViewController:self.current_VC toViewController:self.settingViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  78. }
  79. //- (IBAction)onSelectSales:(id)sender {
  80. //
  81. //
  82. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  83. //
  84. //
  85. //
  86. // ScanUserListViewController * userVC =[ [UIStoryboard storyboardWithName:@"OLM" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanUserListViewController"];
  87. // userVC.returnValue=^(NSString* user)
  88. // {
  89. //// self.btnContact.hidden = false;
  90. // appDelegate.user = user;
  91. // [self.buttonUser setTitle:user forState:UIControlStateNormal];
  92. //
  93. // [self refreshContactDisplay];
  94. ////
  95. // };
  96. // // loginvc.delegate = self;
  97. // // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  98. //// appDelegate.active_controller = gunVC;
  99. //// gunVC.onDismissVC = ^(){
  100. //// appDelegate.active_controller = active_vc;
  101. //// };
  102. // UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:userVC] ;
  103. //
  104. //
  105. //
  106. //
  107. //
  108. // // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  109. //
  110. // navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  111. // [self presentViewController:navi animated:YES completion:^{
  112. //
  113. // // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  114. //
  115. // DebugLog(@"about present.........");
  116. //
  117. // // self.btop = false;
  118. // // <#code#>
  119. // }];
  120. //
  121. //
  122. //
  123. //
  124. // [appDelegate update_count_mark];
  125. //// appDelegate.bLogin = true;
  126. //}
  127. #ifndef RA_NOTIFICATION
  128. -(void) reloadCategory:(BOOL) update_data immediately:(bool)immediately
  129. {
  130. if(immediately)
  131. [ self.categoryViewController reload_container_getdata:update_data];
  132. else
  133. {
  134. if(update_data&&self.categoryViewController.refresh_type<=REFRESH_DATA)
  135. self.categoryViewController.refresh_type = REFRESH_DATA;
  136. else if(self.categoryViewController.refresh_type<=REFRESH_VIEW)
  137. self.categoryViewController.refresh_type = REFRESH_VIEW;
  138. }
  139. }
  140. -(void) reloadDocuments:(BOOL) update_data immediately:(bool)immediately
  141. {
  142. if(immediately)
  143. [ self.pdfListViewController reload_container_getdata:update_data];
  144. else
  145. {
  146. if(update_data&&self.pdfListViewController.refresh_type<=REFRESH_DATA)
  147. self.pdfListViewController.refresh_type = REFRESH_DATA;
  148. else if(self.pdfListViewController.refresh_type<=REFRESH_VIEW)
  149. self.pdfListViewController.refresh_type = REFRESH_VIEW;
  150. }
  151. //[self.pdfListViewController reload_container_getdata:update_data];
  152. }
  153. -(void) reloadCart:(BOOL) update_data immediately:(bool)immediately
  154. {
  155. if(immediately)
  156. [ self.cartViewController reload_container_getdata:update_data];
  157. else
  158. {
  159. if(update_data&&self.cartViewController.refresh_type<=REFRESH_DATA)
  160. self.cartViewController.refresh_type = REFRESH_DATA;
  161. else if(self.cartViewController.refresh_type<=REFRESH_VIEW)
  162. self.cartViewController.refresh_type = REFRESH_VIEW;
  163. }
  164. // [self.cartViewController reload_container_getdata:update_data];
  165. }
  166. -(void) reloadWish:(BOOL) update_data immediately:(bool)immediately
  167. {
  168. if(immediately)
  169. [ self.watchListViewController reload_container_getdata:update_data];
  170. else
  171. {
  172. if(update_data&&self.watchListViewController.refresh_type<=REFRESH_DATA)
  173. self.watchListViewController.refresh_type = REFRESH_DATA;
  174. else if(self.watchListViewController.refresh_type<=REFRESH_VIEW)
  175. self.watchListViewController.refresh_type = REFRESH_VIEW;
  176. }
  177. // [self.watchListViewController reload_container_getdata:update_data];
  178. }
  179. -(void) reloadPortfolio:(BOOL) update_data immediately:(bool)immediately
  180. {
  181. // NSMutableDictionary* dict = [NSMutableDictionary new];
  182. // dict[@"receiver"]=@[@"PortfolioViewController"];
  183. // NSString* notificationname = nil;
  184. // if(update_data)
  185. // notificationname = RA_NOTIFICATION_RELOAD_DATA;
  186. // else
  187. // notificationname = RA_NOTIFICATION_REFRESH_UI;
  188. // NSNotification *notification =[NSNotification notificationWithName:notificationname object:nil userInfo:dict];
  189. //
  190. // //通过通知中心发送通知
  191. //
  192. // [[NSNotificationCenter defaultCenter] postNotification:notification];
  193. // return;
  194. if(immediately)
  195. [ self.portfolioViewController reload_container_getdata:update_data];
  196. else
  197. {
  198. if(update_data&&self.portfolioViewController.refresh_type<=REFRESH_DATA)
  199. self.portfolioViewController.refresh_type = REFRESH_DATA;
  200. else if(self.portfolioViewController.refresh_type<=REFRESH_VIEW)
  201. self.portfolioViewController.refresh_type = REFRESH_VIEW;
  202. }
  203. // [self.portfolioViewController reload_container_getdata:update_data];
  204. }
  205. -(void) reloadOrder:(BOOL) update_data immediately:(bool)immediately
  206. {
  207. if(immediately)
  208. [ self.orderViewController reload_container_getdata:update_data];
  209. else
  210. {
  211. if(update_data&&self.orderViewController.refresh_type<=REFRESH_DATA)
  212. self.orderViewController.refresh_type = REFRESH_DATA;
  213. else if(self.orderViewController.refresh_type<=REFRESH_VIEW)
  214. self.orderViewController.refresh_type = REFRESH_VIEW;
  215. }
  216. // [self.orderViewController reload_container_getdata:update_data];
  217. }
  218. -(void) reloadContact:(BOOL) update_data immediately:(bool)immediately
  219. {
  220. //[self.con reload_container];
  221. if(immediately)
  222. [ self.contactListViewController reload_container_getdata:update_data];
  223. else
  224. {
  225. if(update_data&&self.contactListViewController.refresh_type<=REFRESH_DATA)
  226. self.contactListViewController.refresh_type = REFRESH_DATA;
  227. else if(self.contactListViewController.refresh_type<=REFRESH_VIEW)
  228. self.contactListViewController.refresh_type = REFRESH_VIEW;
  229. }
  230. }
  231. #endif
  232. -(void)viewWillLayoutSubviews
  233. {
  234. self.headerView.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.headerView.bounds].CGPath;
  235. }
  236. -(void) viewWillAppear:(BOOL)animated
  237. {
  238. [super viewWillAppear:animated];
  239. // [self.label_ccount.layer setMasksToBounds:YES];
  240. [self refreshContactDisplay];
  241. [[self navigationController] setNavigationBarHidden:YES animated:NO];
  242. }
  243. -(void) refreshContactDisplay
  244. {
  245. UIApplication * app = [UIApplication sharedApplication];
  246. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  247. // self.labelContact.text=appDelegate.contact_name;
  248. NSString * contact =[appDelegate.customerInfo valueForKey:@"customer_contact"];
  249. NSString * customer=[appDelegate.customerInfo valueForKey:@"customer_name"];
  250. NSDictionary * customerinfo=appDelegate.customerInfo;
  251. if(customerinfo==nil)
  252. {
  253. contact=@"Select Contact";
  254. [self.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  255. }
  256. // if(contact==nil||contact.length==0)
  257. // {
  258. // contact=@"No Name";
  259. // [self.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  260. // }
  261. else
  262. {
  263. if(contact==nil||contact.length==0)
  264. {
  265. contact=@"No Name";
  266. [self.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  267. }
  268. else
  269. {
  270. [self.btnContact setTitleColor:UIColorFromRGB(0x009900) forState:UIControlStateNormal];
  271. }
  272. }
  273. NSMutableArray* arr_contact = [[NSMutableArray alloc] init];
  274. if(contact.length>0)
  275. [arr_contact addObject:contact];
  276. if(customer.length>0)
  277. [arr_contact addObject:customer];
  278. NSString *contact_string = [arr_contact componentsJoinedByString:@" @"];
  279. [self.btnContact setTitle:contact_string forState:UIControlStateNormal];
  280. }
  281. - (void) checklogin:(bool) reloadCurrentVC
  282. {
  283. [self initMenuItems];
  284. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  285. self.sideMenu_UserName.text =appDelegate.user;
  286. [self.btn_sideMenu_UserName setTitle:appDelegate.user forState:UIControlStateNormal];
  287. if(appDelegate.bLogin)
  288. [self.btnLogin setTitle:@"Sign out" forState:UIControlStateNormal];
  289. else
  290. [self.btnLogin setTitle:@"Sign in" forState:UIControlStateNormal];
  291. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  292. [RANetwork LoadImage:appDelegate.user_icon into:self.user_head ];
  293. });
  294. // if(/*appDelegate.user_type==USER_ROLE_EMPLOYEE*/true)
  295. // self.btnContact.hidden = NO;
  296. // else
  297. // self.btnContact.hidden = YES;
  298. NSDictionary * customerinfo=appDelegate.customerInfo;
  299. NSString * contact=nil;
  300. NSString * customer=nil;
  301. if(customerinfo==nil)
  302. {
  303. contact=@"Select Contact";
  304. [self.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  305. }
  306. else
  307. {
  308. contact=[customerinfo valueForKey:@"customer_contact"];
  309. customer=[customerinfo valueForKey:@"customer_name"];
  310. if(contact==nil||contact.length==0)
  311. {
  312. contact=@"No Name";
  313. [self.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  314. }
  315. else
  316. {
  317. [self.btnContact setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
  318. }
  319. }
  320. // self.btnContact.hidden = !appDelegate.bLogin;// 修复登出后仍旧显示select contact
  321. NSMutableArray* arr_contact = [[NSMutableArray alloc] init];
  322. if(contact.length>0)
  323. [arr_contact addObject:contact];
  324. if(customer.length>0)
  325. [arr_contact addObject:customer];
  326. NSString *contact_string = [arr_contact componentsJoinedByString:@" @"];
  327. [self.btnContact setTitle:contact_string forState:UIControlStateNormal];
  328. // if(appDelegate.bLogin)
  329. // [self.buttonUser setTitle:appDelegate.user forState:UIControlStateNormal];
  330. // else
  331. // [self.buttonUser setTitle:@"Sign in" forState:UIControlStateNormal];
  332. #ifdef RA_NOTIFICATION
  333. [ActiveViewController Notify:@"DetailViewController,PDFListViewController,CartViewController,PortfolioViewController,WatchListViewController,OrderListViewController,OrderListViewController,ContactListViewController,CategoryViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  334. #else
  335. [self reloadDocuments:true immediately:false];
  336. [self reloadCart:true immediately:false];
  337. [self reloadPortfolio:true immediately:false];
  338. [self reloadWish:true immediately:false];
  339. [self reloadOrder:true immediately:false];
  340. [self reloadContact:true immediately:false];
  341. [self reloadCategory:true immediately:false];
  342. ActiveViewController* lrvc = (ActiveViewController*)appDelegate.active_controller;
  343. if(reloadCurrentVC)
  344. {
  345. if(lrvc!=nil)
  346. [ lrvc refresh_on_login];
  347. }
  348. else
  349. {
  350. if(lrvc.refresh_type<=REFRESH_DATA)
  351. lrvc.refresh_type = REFRESH_DATA;
  352. else if(lrvc.refresh_type<=REFRESH_VIEW)
  353. lrvc.refresh_type = REFRESH_VIEW;
  354. }
  355. #endif
  356. // [self reload];
  357. }
  358. - (IBAction)onContactClick:(id)sender {
  359. UIApplication * app = [UIApplication sharedApplication];
  360. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  361. NSString* contactid=appDelegate.contact_id ;
  362. if(contactid==nil)
  363. {
  364. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  365. CustomerEditViewController * cuseditVC = [[CustomerEditViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  366. cuseditVC.bnewcustomer=true;
  367. cuseditVC.bolocustomer = true;
  368. cuseditVC.url_type = URL_FILE;
  369. cuseditVC.request_url=[OLDataProvider scanTemplatePath:@"scan_contact.json"];;
  370. cuseditVC.params = params;
  371. cuseditVC.returnValue=^(NSMutableDictionary* value)
  372. {
  373. if(value == nil)
  374. {
  375. return; //canceled
  376. }
  377. NSString* contact_id=[[NSUUID new] UUIDString];
  378. value[@"business_card"] = value[@"customer_cid"];
  379. NSArray*arr =[RAConvertor string2arr:value[@"business_card"] separator:@","];
  380. for(int l=0;l<arr.count;l++)
  381. {
  382. value[[NSString stringWithFormat:@"business_card_%d",l]]=arr[l];
  383. }
  384. //---------------- construct customer_contact----------------------
  385. NSString* customer_first_name = [value valueForKey:@"customer_first_name"];
  386. if(customer_first_name==nil)
  387. customer_first_name=@"";
  388. NSString* customer_last_name= [value valueForKey:@"customer_last_name"];
  389. if(customer_last_name==nil)
  390. customer_last_name=@"";
  391. NSString* customer_contact = [NSString stringWithFormat:@"%@ %@",customer_first_name,customer_last_name];
  392. customer_contact=[customer_contact stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
  393. [value setValue:customer_contact forKey:@"customer_contact"];
  394. value [@"customer_cid"] = contact_id;
  395. appDelegate.contact_id=contact_id;
  396. appDelegate.customerInfo = value;
  397. };
  398. [[self navigationController] setNavigationBarHidden:NO animated:NO];
  399. [self.navigationController pushViewController:cuseditVC animated:false];
  400. }
  401. else
  402. {
  403. CustomerInfoViewController * vc = [[CustomerInfoViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  404. vc.url_type = URL_FILE;
  405. // if(appDelegate.order_code.length>0)
  406. {
  407. vc.edit_icon = false;
  408. vc.assig_icon = true;
  409. vc.reset_icon = true;
  410. vc.request_url=[OLDataProvider scanTemplatePath:@"scan_contact.json"];
  411. }
  412. // else
  413. // {
  414. // vc.edit_icon = false;
  415. // vc.assig_icon = false;
  416. // vc.reset_icon = true;
  417. // vc.request_url=LOCAL_URL_CUSTOMER_INFO_EDITOR;
  418. // }
  419. // NSDictionary* dd=appDelegate.customerInfo;;
  420. vc.data_init = appDelegate.customerInfo;
  421. vc.update_order = true;
  422. vc.contactId=contactid;
  423. // vc.delegate = self;
  424. vc.returnValue = ^(NSMutableDictionary* value){
  425. if(value==nil)
  426. {
  427. //reset
  428. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  429. {
  430. [OLDataProvider deleteScanOrder:appDelegate.order_code];
  431. [appDelegate closeOrder];
  432. //
  433. // [self prepareReturn:nil];
  434. [self.navigationController popViewControllerAnimated:true];
  435. [((MainViewController*)appDelegate.main_vc) switchToOrder];
  436. return;
  437. }
  438. }
  439. else
  440. {
  441. value[@"business_card"] = value[@"business_card"];
  442. NSArray*arr =[RAConvertor string2arr:value[@"business_card"] separator:@","];
  443. for(int l=0;l<arr.count;l++)
  444. {
  445. value[[NSString stringWithFormat:@"business_card_%d",l]]=arr[l];
  446. }
  447. //---------------- construct customer_contact----------------------
  448. NSString* customer_first_name = [value valueForKey:@"customer_first_name"];
  449. if(customer_first_name==nil)
  450. customer_first_name=@"";
  451. NSString* customer_last_name= [value valueForKey:@"customer_last_name"];
  452. if(customer_last_name==nil)
  453. customer_last_name=@"";
  454. NSString* customer_contact = [NSString stringWithFormat:@"%@ %@",customer_first_name,customer_last_name];
  455. customer_contact=[customer_contact stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
  456. [value setValue:customer_contact forKey:@"customer_contact"];
  457. value [@"customer_cid"] = appDelegate.customerInfo[@"customer_cid"];
  458. // appDelegate.contact_id=contact_id;
  459. appDelegate.customerInfo = value;
  460. }
  461. // appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  462. // appDelegate.customerInfo = value;
  463. };
  464. [self.navigationController pushViewController:vc animated:true];
  465. }
  466. }
  467. -(void) clearSelected
  468. {
  469. self.btncart.selected = false;
  470. self.btnorder.selected = false;
  471. self.btnlist.selected = false;
  472. self.btnsearch.selected = false;
  473. self.btnsetting.selected = false;
  474. }
  475. - (void)of_test
  476. {
  477. // NSString* str =@"[\"5688\",\"5808-68\",\"DINING TBL, ACACIA VNER\",\"1\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"1\",\"10.96\",\"viet\",\"vcsf\",\"42 X 68 x 30.5H\",\"234.56\"]";
  478. // NSDictionary* item = [RAConvertor string2dict:str];
  479. // NSMutableDictionary* of = [NSMutableDictionary new];
  480. // for(int i=0;i<4000;i++)
  481. // {
  482. // of[[NSString stringWithFormat:@"model_%d",i]]=item;
  483. // }
  484. //
  485. // NSString* strof=[RAConvertor dict2string:of];
  486. //
  487. //
  488. //// NSString* str2 = [AESCrypt encrypt:strof password:@"usai2010"];
  489. //// NSString * str3 = [AESCrypt decrypt:@"x6P5P+DUN+s4mYoSoipdmvaPtU1mGvGGHtoqQF3GlMg=" password:@"usai2010"];
  490. ////
  491. //// NSString * str123 = [AESCrypt decrypt:@"706dZ9zTqNPauH3j2S7MQg==" password:@"usai"];
  492. //// NSString * str333 = [AESCrypt decrypt:@"RQtrNBCGKxNq6Bk5QGkPiw==" password:@"usai2010\0\0\0\0\0\0\0\0"];
  493. //// NSString * str33 = [AESCrypt decrypt:@"0s0+JiC2ZzoDiBGQaCnT1g==" password:@"usai2010"];
  494. //
  495. //
  496. // [self sortedDictionary:of];
  497. //
  498. //// NSDictionary* test1 = of[@"model_1234"];
  499. //// NSDictionary* test2 = of[@"model_9876"];
  500. //// NSDictionary* test3 = of[@"model_4567"];
  501. //// NSDictionary* test4 = of[@"model_7654"];
  502. //
  503. // [self of_search:of keyword:@"12"];
  504. //
  505. //
  506. }
  507. /**
  508. 对字典(Key-Value)排序 区分大小写
  509. @param dict 要排序的字典
  510. */
  511. - (void)sortedDictionary:(NSDictionary *)dict{
  512. //将所有的key放进数组
  513. NSArray *allKeyArray = [dict allKeys];
  514. //序列化器对数组进行排序的block 返回值为排序后的数组
  515. NSArray *afterSortKeyArray = [allKeyArray sortedArrayUsingComparator:^NSComparisonResult(id _Nonnull obj1, id
  516. _Nonnull obj2) {
  517. /**
  518. In the compare: methods, the range argument specifies the
  519. subrange, rather than the whole, of the receiver to use in the
  520. comparison. The range is not applied to the search string. For
  521. example, [@"AB" compare:@"ABC" options:0 range:NSMakeRange(0,1)]
  522. compares "A" to "ABC", not "A" to "A", and will return
  523. NSOrderedAscending. It is an error to specify a range that is
  524. outside of the receiver's bounds, and an exception may be raised.
  525. - (NSComparisonResult)compare:(NSString *)string;
  526. compare方法的比较原理为,依次比较当前字符串的第一个字母:
  527. 如果不同,按照输出排序结果
  528. 如果相同,依次比较当前字符串的下一个字母(这里是第二个)
  529. 以此类推
  530. 排序结果
  531. NSComparisonResult resuest = [obj1 compare:obj2];为从小到大,即升序;
  532. NSComparisonResult resuest = [obj2 compare:obj1];为从大到小,即降序;
  533. 注意:compare方法是区分大小写的,即按照ASCII排序
  534. */
  535. //排序操作
  536. NSComparisonResult resuest = [obj1 compare:obj2];
  537. return resuest;
  538. }];
  539. DebugLog(@"afterSortKeyArray:%@",afterSortKeyArray);
  540. //通过排列的key值获取value
  541. NSMutableArray *valueArray = [NSMutableArray array];
  542. for (NSString *sortsing in afterSortKeyArray) {
  543. NSString *valueString = [dict objectForKey:sortsing];
  544. [valueArray addObject:valueString];
  545. }
  546. DebugLog(@"valueArray:%@",valueArray);
  547. }
  548. -(void)of_search:(NSMutableDictionary*) dict keyword:(NSString*)keyword
  549. {
  550. NSMutableArray* arr = [NSMutableArray new];
  551. NSArray* keys=[dict allKeys];
  552. for(int i=0;i<keys.count;i++)
  553. {
  554. NSString* key = keys[i];
  555. if([key containsString:keyword])
  556. {
  557. [arr addObject:dict[key]];
  558. }
  559. }
  560. }
  561. - (void)viewDidLoad
  562. {
  563. [super viewDidLoad];
  564. // NSString * str3 = [AESCrypt AES128Decrypt:@"" key:@"usai2010"];
  565. // NSString * str4 = [AESCrypt AES128Decrypt:@"" key:@"usai2010"];
  566. // NSString * str5 = [AESCrypt AES128Decrypt:@"" key:@"usai2010"];
  567. // DebugLog(@"decrypt:%@",[AESCrypt fastdecrypt:@"vafHUwfRPIUbPNVnKhLc5aAVK7sOFRztlfJVRHW7QVa/qGgm11E5UwfYWZEBTQpH"]);
  568. // [self of_test];
  569. [RADataProvider load_scan_models];
  570. [self.btncart setBackgroundImage:[UIImage imageNamed:@"btn_bg"] forState:UIControlStateSelected];
  571. [self.btnorder setBackgroundImage:[UIImage imageNamed:@"btn_bg"] forState:UIControlStateSelected];
  572. [self.btnlist setBackgroundImage:[UIImage imageNamed:@"btn_bg"] forState:UIControlStateSelected];
  573. [self.btnsearch setBackgroundImage:[UIImage imageNamed:@"btn_bg"] forState:UIControlStateSelected];
  574. [self.btnsetting setBackgroundImage:[UIImage imageNamed:@"btn_bg"] forState:UIControlStateSelected];
  575. // [self.btncart setTintColor:UIColor.whiteColor];
  576. // self.btncart.configuration.baseForegroundColor = UIColor.redColor;
  577. // [self.btncart updateConfiguration];
  578. // [self.btncart setBackgroundImage:[UIImage imageNamed:@"btn_bg"] forState:UIControlStateHighlighted];
  579. NSDictionary *addressDic = [[NSUserDefaults standardUserDefaults] valueForKey:@"ScanAddress"];
  580. if (addressDic) {
  581. self.labelServer.text = [addressDic objectForKey:@"show_name"];
  582. // NSUInteger selectedIndex = [[addressDic objectForKey:@"selectedIndex"] integerValue];
  583. // switch (selectedIndex) {
  584. // case 0:
  585. // case 1: {
  586. // [self internalCheckBtnClick:self.internalCheckBtn];
  587. // }
  588. // break;
  589. // case 2: {
  590. // [self externalCheckBtnClick:self.externalCheckBtn];
  591. // }
  592. // break;
  593. //
  594. // default:
  595. // break;
  596. // }
  597. }
  598. // self.btnContact.hidden = NO;
  599. // self.automaticallyAdjustsScrollViewInsets = NO;
  600. NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultColor" valuename:@"labelcolor"];
  601. if(value==nil)
  602. value=@"";
  603. unsigned long frontcolor = strtoul([value UTF8String],0,16);
  604. [self.labelSo setTextColor:UIColorFromRGB(frontcolor)];
  605. float vx =[[DefaultAppearance get_noneappearance_value:@"MainLogo" valuename:@"x"] floatValue];
  606. float vy =[[DefaultAppearance get_noneappearance_value:@"MainLogo" valuename:@"y"] floatValue];
  607. float vwidth =[[DefaultAppearance get_noneappearance_value:@"MainLogo" valuename:@"width"] floatValue];
  608. float vheight =[[DefaultAppearance get_noneappearance_value:@"MainLogo" valuename:@"height"] floatValue];
  609. self.btn_LogoHome.frame = CGRectMake(vx, vy, vwidth, vheight);
  610. float mvx =[[DefaultAppearance get_noneappearance_value:@"ModePos" valuename:@"x"] floatValue];
  611. float mvy =[[DefaultAppearance get_noneappearance_value:@"ModePos" valuename:@"y"] floatValue];
  612. float mvwidth =[[DefaultAppearance get_noneappearance_value:@"ModePos" valuename:@"width"] floatValue];
  613. float mvheight =[[DefaultAppearance get_noneappearance_value:@"ModePos" valuename:@"height"] floatValue];
  614. self.labelMode.frame = CGRectMake(mvx, mvy, mvwidth, mvheight);
  615. self.label_ccount.layer.cornerRadius=10.5;
  616. self.label_ccount.layer.masksToBounds=true;
  617. self.label_wcount.layer.cornerRadius=10.5;
  618. self.label_wcount.layer.masksToBounds=true;
  619. self.label_cccount.layer.cornerRadius=10.5;
  620. self.label_cccount.layer.masksToBounds=true;
  621. self.label_cwcount.layer.cornerRadius=10.5;
  622. self.label_cwcount.layer.masksToBounds=true;
  623. self.employee_bp.hidden = false;
  624. // self.customer_bp.hidden = true;
  625. UIApplication * app = [UIApplication sharedApplication];
  626. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  627. appDelegate.main_vc = self;
  628. [appDelegate update_count_mark];
  629. NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  630. NSString* build =[infoDict objectForKey:@"CFBundleVersion"];
  631. NSString* version =[infoDict objectForKey:@"CFBundleShortVersionString"];
  632. //#ifdef BUILD_HMLG
  633. // NSString* versionNum = [NSString stringWithFormat:@"HMLG %@ Build %@",version,build];
  634. //#endif
  635. //#if defined(BUILD_NPD) || defined(BUILD_USAI)
  636. // NSString* versionNum = [NSString stringWithFormat:@"npd %@ Build %@",version,build];
  637. //#endif
  638. //#ifdef BUILD_HOMER
  639. NSString* versionNum = [NSString stringWithFormat:@"%@ %@ Build %@",COMPANY_SHORT_NAME,version,build];
  640. //#endif
  641. [self initAppDelegate]; // 初始化scan order 参数
  642. [self initMenuItems];
  643. self.homeViewController =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanHomeViewController"];
  644. // self.categoryViewController =[ [UIStoryboard storyboardWithName:@"ERP_Mobile_Search" bundle:nil] instantiateViewControllerWithIdentifier:@"CategoryViewController"];
  645. self.settingViewController=[ [UIStoryboard storyboardWithName:@"OLM" bundle:nil] instantiateViewControllerWithIdentifier:@"ServerSettingViewController"];
  646. self.cartViewController =[[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"CartViewController"];
  647. __block MainViewController *brself= self;
  648. self.scanorderViewController =[[UIStoryboard storyboardWithName:@"ERP_Mobile_Order" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanOrderListViewController"];
  649. self.contactListViewController = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  650. self.contactListViewController.contact_type = @"Sales_Order_Customer";
  651. self.contactListViewController.edit_icon = true;
  652. self.contactListViewController.assig_icon = true;
  653. self.contactListViewController.reset_icon = false;
  654. self.contactListViewController.ui_type = CONTACT_LIST;
  655. self.contactListViewController.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  656. appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  657. appDelegate.customerInfo = value;
  658. [brself refreshContactDisplay];
  659. [brself switchToCart:nil];
  660. // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  661. //
  662. // if(self.returnValue)
  663. // self.returnValue(value);
  664. };
  665. //Capturing strongly warring;
  666. self.scanHistoryViewController =[[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanHistoryViewController"];
  667. // self.portfolioViewController = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Portfolio" bundle:nil] instantiateViewControllerWithIdentifier:@"PortfolioViewController" ];
  668. // [self addChildViewController:self.scanHistoryViewController];
  669. // self.pdfListViewController = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Portfolio" bundle:nil] instantiateViewControllerWithIdentifier:@"PortfolioListViewController" ];
  670. // self.itemSearchViewController=[[UIStoryboard storyboardWithName:@"ERP_Mobile_Search" bundle:nil] instantiateViewControllerWithIdentifier:@"ItemSearchViewController"];
  671. self.scansearchViewController=[ [UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanSearchViewController"];
  672. [self addChildViewController:self.homeViewController]; //1
  673. self.homeViewController.view.frame = self.container.bounds;
  674. [self.container addSubview:self.homeViewController.view]; //2
  675. [self.homeViewController didMoveToParentViewController:self];
  676. self.current_VC = self.homeViewController;
  677. // [self addChildViewController:self.scanorderViewController]; //1
  678. //
  679. // self.scanorderViewController.view.frame = self.container.bounds;
  680. // [self.container addSubview:self.scanorderViewController.view]; //2
  681. // [self.scanorderViewController didMoveToParentViewController:self];
  682. // self.current_VC = self.scanorderViewController;
  683. // // self.is_home = true;
  684. // [UIBezierPath bezierPathWithRect:self.headerView.bounds].CGPath;
  685. self.headerView.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.headerView.bounds].CGPath;
  686. self.headerView.layer.masksToBounds = false;
  687. //添加四个边阴影
  688. self.headerView.layer.shadowColor = [UIColor blackColor].CGColor;
  689. self.headerView.layer.shadowOffset = CGSizeMake(0, 0);
  690. self.headerView.layer.shadowOpacity = 0.5;
  691. self.headerView.layer.shadowRadius = 2.0;
  692. self.labelVer.text=versionNum;
  693. // UIApplication * app = [UIApplication sharedApplication];
  694. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  695. // Do any additional setup after loading the view, typically from a nib.
  696. // SetupServerViewController * servervc =[[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"SetupServerViewController"];
  697. // [self.navigationController pushViewController:servervc animated:true];
  698. }
  699. - (IBAction)onmenuButtonClicked:(id)sender {
  700. self.openMenuButton.hidden = true;
  701. self.sideMenu.hidden = false;
  702. [self showMenu];
  703. }
  704. - (IBAction)switchMenu:(UIButton *)sender {
  705. // if(self.menuShown==true)
  706. [self hideMenu];
  707. self.openMenuButton.hidden = false;
  708. self.sideMenu.hidden = true;
  709. // else
  710. // [self showMenu];
  711. }
  712. -(void) Loginout:(bool)showlogin
  713. {
  714. return;
  715. // 此接口 scan order 不会调用,但为了保证公共模块变异不会报错,保留空接口。
  716. }
  717. - (IBAction)onUserListClick:(id)sender {
  718. UIApplication * app = [UIApplication sharedApplication];
  719. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  720. if(!appDelegate.bLogin)
  721. return;
  722. UserListViewController * vc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"UserListViewController"];
  723. vc.returnValue = ^(bool blogin){
  724. if(blogin==false)
  725. {
  726. LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  727. loginvc.returnValue = ^(bool blogin){
  728. [self checklogin :true];
  729. };
  730. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  731. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  732. [self presentViewController:navi animated:YES completion:^{
  733. DebugLog(@"login present.........");
  734. }];
  735. }
  736. };
  737. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  738. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  739. [self presentViewController:navi animated:YES completion:^{
  740. DebugLog(@"login present.........");
  741. }];
  742. }
  743. - (IBAction)OnLoginClick:(UIButton *)sender {
  744. [self Loginout:true];
  745. }
  746. - (IBAction)onScanClick:(id)sender {
  747. ScannerViewController * scannerVC =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ScannerViewController"];
  748. ScanOrderModelListViewController* scanresult = [[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanOrderModelListViewController"];
  749. scannerVC.resultvc = scanresult;
  750. [self.navigationController pushViewController:scannerVC animated:true];
  751. }
  752. - (IBAction)switchToSearch:(UIButton *)sender {
  753. [self clearSelected];
  754. self.btnsearch.selected = true;
  755. if([self.current_VC isKindOfClass:[ScanSearchViewController class]])
  756. return;
  757. [self flipFromViewController:self.current_VC toViewController:self.scansearchViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  758. }
  759. //- (IBAction)switchToList:(UIButton *)sender {
  760. // [self switchtowishlist];
  761. //}
  762. - (IBAction)switchToList:(UIButton *)sender {
  763. [self clearSelected];
  764. self.btnlist.selected = true;
  765. [self switchtowishlist];
  766. }
  767. -(void)switchtowishlist
  768. {
  769. if([self.current_VC isKindOfClass:[ScanHistoryViewController class]])
  770. return;
  771. [self flipFromViewController:self.current_VC toViewController:self.scanHistoryViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  772. }
  773. - (IBAction)switchToContact:(UIButton *)sender {
  774. [self switchtocontact];
  775. }
  776. -(void)switchtocontact
  777. {
  778. if([self.current_VC isKindOfClass:[ContactListViewController class]])
  779. return;
  780. UIApplication * app = [UIApplication sharedApplication];
  781. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  782. if(appDelegate.bLogin==false)
  783. {
  784. LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  785. // loginvc.delegate = self;
  786. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  787. loginvc.returnValue = ^(bool blogin){
  788. if(blogin)
  789. {
  790. [self checklogin:true];
  791. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  792. {
  793. [self flipFromViewController:self.current_VC toViewController:self.contactListViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  794. }
  795. else
  796. {
  797. [RAUtils message_box:@"Contact List" message:@"Customer Login does not support this feature." completion:nil] ;
  798. }
  799. }
  800. };
  801. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  802. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  803. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  804. [self presentViewController:navi animated:YES completion:^{
  805. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  806. DebugLog(@"LoginViewController present.........");
  807. // self.btop = false;
  808. // <#code#>
  809. }];
  810. }
  811. else
  812. [self flipFromViewController:self.current_VC toViewController:self.contactListViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  813. }
  814. - (void) reload
  815. {
  816. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  817. return;
  818. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  819. //
  820. //
  821. // NSDictionary* category=[RANetwork request_Cagegory];
  822. //
  823. // dispatch_async(dispatch_get_main_queue(), ^{
  824. //
  825. // if([[category valueForKey:@"result"] intValue]==2)
  826. // {
  827. // appDelegate.categoryMenu = category;
  828. // }
  829. // else
  830. // {
  831. // // [RAUtils error_alert:[category valueForKey:@"err_msg"]] ;
  832. // }
  833. //
  834. // });
  835. // });
  836. }
  837. -(void) scanTempsave
  838. {
  839. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  840. // RASingleton.sharedInstance.scan_temp_code
  841. NSString *orderdir =[OLDataProvider getScanPath];
  842. // appDelegate.order_code = RASingleton.sharedInstance.scan_temp_code;
  843. // [OLDataProvider moveScanTemp2Order];
  844. // NSString *orderdir = [OLDataProvider getScanPath];
  845. // NSString* userdir = [OLDataProvider getUserPath];
  846. // NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  847. // [RAUtils dicttofile:orderPath dict:self.content_data_download];
  848. // NSString* order_code = RASingleton.sharedInstance.scan_temp_code;
  849. //
  850. // int section_count = [self.content_data_download[@"section_count"] intValue];
  851. //
  852. // for(int i=0;i<section_count;i++)
  853. // {
  854. // NSMutableDictionary* section = [self.content_data_download[[NSString stringWithFormat:@"section_%d",i]] mutableCopy];
  855. // NSString* title = section[@"title"];
  856. //
  857. // if([title isEqualToString:@"Customer"])
  858. // {
  859. // // 订单信息会写customer info
  860. //
  861. // int scount = [section[@"count"] intValue];
  862. // for(int j=0;j<scount;j++)
  863. // {
  864. // NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  865. // NSString * name = item[@"name"];
  866. //
  867. //
  868. // if(item[@"value"]!=nil )
  869. // appDelegate.customerInfo[name]=item[@"value"];
  870. //
  871. //
  872. // }
  873. //
  874. //
  875. //
  876. // }
  877. //
  878. // NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  879. //
  880. //
  881. //
  882. // [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  883. // orderdir = [OLDataProvider getScanOrderPath];
  884. NSString *cartpath = [orderdir stringByAppendingPathComponent:@"cart.json"];
  885. RASingleton.sharedInstance.scan_cart[@"price_type"] = @(RASingleton.sharedInstance.price_type);
  886. [RAUtils dicttofile:cartpath dict:RASingleton.sharedInstance.scan_cart];
  887. NSMutableDictionary* orderlist = [OLDataProvider getScanOrderList];
  888. // NSString *orderlistPath = [userdir stringByAppendingPathComponent:@"orderlist.json"];
  889. //
  890. //
  891. // if (![[NSFileManager defaultManager] fileExistsAtPath:orderlistPath]) {
  892. //
  893. //
  894. // orderlist = [NSMutableDictionary new];
  895. //
  896. //// [orderlist addObject:appDelegate.order_code];
  897. //// [RAUtils dicttofile:orderlistPath dict:orderlist];
  898. //
  899. // }
  900. // else
  901. // {
  902. // orderlist=[[RAUtils dictfromfile:orderlistPath] mutableCopy];
  903. //
  904. //// [orderlist insertObject:appDelegate.order_code atIndex:0];
  905. //
  906. //// [RAUtils dicttofile:orderlistPath dict:orderlist];
  907. // }
  908. float p =0;
  909. float s =0;
  910. // NSDictionary* price_group = [RADataProvider get_price_group:appDelegate.price_group];
  911. int order_qty=0;
  912. for(int j=0;j<[RASingleton.sharedInstance.scan_cart[@"section_0"][@"count"] intValue];j++)
  913. {
  914. NSDictionary* cartitem =RASingleton.sharedInstance.scan_cart[@"section_0"][[NSString stringWithFormat:@"item_%d",j]];
  915. p+=[cartitem[@"unit_price"] doubleValue]*[cartitem[@"count"]intValue] * (1-[cartitem[@"discount"]doubleValue]/100.0);
  916. int mcount = [cartitem[@"count"] intValue];
  917. order_qty+=mcount;
  918. double msurcharge =0;
  919. // remove net price
  920. // if(RASingleton.sharedInstance.price_type==1)
  921. // {
  922. // if([cartitem[@"special_price"] boolValue])
  923. // {
  924. // msurcharge=([cartitem[price_group[@"price_3"][@"name"]] doubleValue]-[cartitem[price_group[@"price_2"][@"name"]] doubleValue])*mcount*(1-[cartitem[@"discount"]doubleValue]/100.0);
  925. // }
  926. // else
  927. // {
  928. // msurcharge=([cartitem[price_group[@"price_3"][@"name"]] doubleValue]-[cartitem[price_group[@"price_1"][@"name"]] doubleValue])*mcount*(1-[cartitem[@"discount"]doubleValue]/100.0);
  929. // }
  930. // }
  931. s+=msurcharge;
  932. }
  933. NSMutableDictionary* orderitem = [NSMutableDictionary new];
  934. orderitem[@"create_by"] = appDelegate.user;
  935. orderitem[@"price"] = [RAConvertor currencyNumber:p+s];//[NSString stringWithFormat:@"%.2f",p+s];
  936. orderitem[@"model_count"] =[ NSString stringWithFormat:@"%d",order_qty];
  937. // orderitem[@"price"] = upparams[@"totalPrice"];
  938. // NSString*
  939. orderitem[@"customer_name"] = appDelegate.customerInfo[@"customer_contact"];
  940. orderitem[@"purchase_time"] = [RAUtils current_date_time];
  941. orderitem[@"order_status"] = @"Saved Order";
  942. orderitem[@"order_code"] = appDelegate.order_code;
  943. // NSMutableDictionary* section =RASingleton.sharedInstance.scan_cart[@"section_0"];
  944. // orderitem[@"model_count"] =[ NSString stringWithFormat:@"%d",order_qty];//RASingleton.sharedInstance.scan_cart[@"section_0"][@"count"] ];
  945. int count = [orderlist[@"count"] intValue];
  946. NSMutableDictionary* newlist = [NSMutableDictionary new];
  947. newlist[@"item_0"]=orderitem;
  948. int newcount = 1;
  949. for(int i=0;i<count;i++)
  950. {
  951. NSMutableDictionary* item = orderlist[[NSString stringWithFormat:@"item_%d",i]];
  952. if([item[@"order_code"] isEqualToString: appDelegate.order_code ])
  953. continue;
  954. else
  955. {
  956. newlist[[NSString stringWithFormat:@"item_%d",newcount]] = item;
  957. newcount++;
  958. }
  959. }
  960. newlist[@"count"] = @(newcount);
  961. [OLDataProvider saveScanOrderList:newlist];
  962. // [RAUtils dicttofile:orderlistPath dict:newlist];
  963. #ifdef RA_NOTIFICATION
  964. [ActiveViewController Notify:@"CartViewController,ScanOrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  965. #else
  966. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  967. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  968. #endif
  969. }
  970. - (IBAction)onUserButtonClick:(id)sender {
  971. DebugLog(@"header view login");
  972. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  973. if( appDelegate.user ==nil /*|| [appDelegate.user isEqualToString:@"GUEST"]*/)
  974. {
  975. // appDelegate.user = nil;
  976. // appDelegate.password = nil;
  977. LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  978. // loginvc.delegate = self;
  979. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  980. loginvc.returnValue = ^(bool blogin){
  981. [self checklogin:true];
  982. };
  983. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  984. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  985. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  986. [self presentViewController:navi animated:YES completion:^{
  987. // <#code#>
  988. }];
  989. }
  990. else
  991. {
  992. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Sign Out" message:@"" preferredStyle:UIAlertControllerStyleAlert];
  993. UIAlertAction *action_1 = [UIAlertAction actionWithTitle:@"Sign Out" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  994. //open exist
  995. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  996. // int cc=[RASingleton.sharedInstance.scan_cart[@"section_0"][@"count"] intValue];
  997. bool issaved = [OLDataProvider isSavedScanOrder:appDelegate.order_code];
  998. if(/*appDelegate.order_code == nil*/!issaved && [RASingleton.sharedInstance.scan_cart[@"section_0"][@"count"] intValue]>0)
  999. {
  1000. UIAlertController *alertController1 = [UIAlertController alertControllerWithTitle:@"Save Cart?" message:@"" preferredStyle:UIAlertControllerStyleAlert];
  1001. UIAlertAction *action_1 = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  1002. [self scanTempsave];
  1003. [OLDataProvider scanCloseOrder];
  1004. [appDelegate Logout];
  1005. // appDelegate.cart_count = 0;//[[jsobj :@"cart_count"] intValue];
  1006. // appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  1007. // appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  1008. //
  1009. // [appDelegate update_count_mark];
  1010. //
  1011. //
  1012. // appDelegate.can_show_price =false;
  1013. // appDelegate.can_see_price =false;
  1014. // appDelegate.can_create_portfolio =false;
  1015. // appDelegate.can_create_order =false;
  1016. //
  1017. //
  1018. // appDelegate.can_cancel_order =false;
  1019. // appDelegate.can_set_cart_price =false;
  1020. // appDelegate.can_delete_order =false;
  1021. // appDelegate.can_submit_order =false;
  1022. // appDelegate.can_set_tearsheet_price =false;
  1023. // appDelegate.can_update_contact_info = false;
  1024. //
  1025. // appDelegate.save_order_logout = false;
  1026. // appDelegate.submit_order_logout = false;
  1027. // appDelegate.alert_sold_in_quantities = false;
  1028. //
  1029. // appDelegate.ipad_perm =nil ;
  1030. // appDelegate.user_type = USER_ROLE_UNKNOWN;
  1031. // appDelegate.OrderFilter= nil;
  1032. // [appDelegate SetSo:nil];
  1033. // [appDelegate set_main_button_panel];
  1034. #ifdef RA_NOTIFICATION
  1035. [ActiveViewController Notify:@"ScanSearchViewController" Message:RA_NOTIFICATION_REFRESH_UI];
  1036. [ActiveViewController Notify:@"ScanHistoryViewController" Message:RA_NOTIFICATION_REFRESH_UI];
  1037. #endif
  1038. // [appDelegate Logout];
  1039. }];
  1040. UIAlertAction *action_2 = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  1041. //create new;
  1042. [OLDataProvider scanCloseOrder];
  1043. [appDelegate Logout];
  1044. // appDelegate.cart_count = 0;//[[jsobj :@"cart_count"] intValue];
  1045. // appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  1046. // appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  1047. //
  1048. // [appDelegate update_count_mark];
  1049. //
  1050. //
  1051. // appDelegate.can_show_price =false;
  1052. // appDelegate.can_see_price =false;
  1053. // appDelegate.can_create_portfolio =false;
  1054. // appDelegate.can_create_order =false;
  1055. //
  1056. //
  1057. // appDelegate.can_cancel_order =false;
  1058. // appDelegate.can_set_cart_price =false;
  1059. // appDelegate.can_delete_order =false;
  1060. // appDelegate.can_submit_order =false;
  1061. // appDelegate.can_set_tearsheet_price =false;
  1062. // appDelegate.can_update_contact_info = false;
  1063. //
  1064. // appDelegate.save_order_logout = false;
  1065. // appDelegate.submit_order_logout = false;
  1066. // appDelegate.alert_sold_in_quantities = false;
  1067. //
  1068. // appDelegate.ipad_perm =nil ;
  1069. // appDelegate.user_type = USER_ROLE_UNKNOWN;
  1070. // appDelegate.OrderFilter= nil;
  1071. // [appDelegate SetSo:nil];
  1072. // [appDelegate set_main_button_panel];
  1073. #ifdef RA_NOTIFICATION
  1074. [ActiveViewController Notify:@"ScanSearchViewController" Message:RA_NOTIFICATION_REFRESH_UI];
  1075. [ActiveViewController Notify:@"ScanHIstoryViewController" Message:RA_NOTIFICATION_REFRESH_UI];
  1076. #endif
  1077. // [appDelegate Logout];
  1078. }];
  1079. [alertController1 addAction:action_1];
  1080. [alertController1 addAction:action_2];
  1081. [self presentViewController:alertController1 animated:YES completion:nil];
  1082. return;
  1083. }
  1084. [OLDataProvider scanCloseOrder];
  1085. [appDelegate Logout];
  1086. // appDelegate.cart_count = 0;//[[jsobj :@"cart_count"] intValue];
  1087. // appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  1088. // appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  1089. //
  1090. // [appDelegate update_count_mark];
  1091. //
  1092. //
  1093. // appDelegate.can_show_price =false;
  1094. // appDelegate.can_see_price =false;
  1095. // appDelegate.can_create_portfolio =false;
  1096. // appDelegate.can_create_order =false;
  1097. //
  1098. //
  1099. // appDelegate.can_cancel_order =false;
  1100. // appDelegate.can_set_cart_price =false;
  1101. // appDelegate.can_delete_order =false;
  1102. // appDelegate.can_submit_order =false;
  1103. // appDelegate.can_set_tearsheet_price =false;
  1104. // appDelegate.can_update_contact_info = false;
  1105. //
  1106. // appDelegate.save_order_logout = false;
  1107. // appDelegate.submit_order_logout = false;
  1108. // appDelegate.alert_sold_in_quantities = false;
  1109. //
  1110. // appDelegate.ipad_perm =nil ;
  1111. // appDelegate.user_type = USER_ROLE_UNKNOWN;
  1112. // appDelegate.OrderFilter= nil;
  1113. // [appDelegate SetSo:nil];
  1114. //
  1115. // [appDelegate set_main_button_panel];
  1116. #ifdef RA_NOTIFICATION
  1117. [ActiveViewController Notify:@"ScanSearchViewController" Message:RA_NOTIFICATION_REFRESH_UI];
  1118. [ActiveViewController Notify:@"ScanHistoryViewController" Message:RA_NOTIFICATION_REFRESH_UI];
  1119. #endif
  1120. // [appDelegate Logout];
  1121. }];
  1122. UIAlertAction *action_2 = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  1123. //create new;
  1124. }];
  1125. [alertController addAction:action_1];
  1126. [alertController addAction:action_2];
  1127. [self presentViewController:alertController animated:YES completion:nil];
  1128. }
  1129. }
  1130. #pragma mark - LoginViewControllerDelegate
  1131. -(void)LoginViewControllerDidLogin:(LoginViewController *)viewController
  1132. {
  1133. [viewController dismissViewControllerAnimated:YES completion:^{
  1134. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1135. self.sideMenu_UserName.text =appDelegate.user;
  1136. [self.btn_sideMenu_UserName setTitle:appDelegate.user forState:UIControlStateNormal];
  1137. [self.btnLogin setTitle:@"Sign out" forState:UIControlStateNormal];
  1138. [RANetwork LoadImage:appDelegate.user_icon into:self.user_head ];
  1139. // if(/*appDelegate.user_type==USER_ROLE_EMPLOYEE*/true)
  1140. // self.btnContact.hidden = NO;
  1141. // else
  1142. // self.btnContact.hidden = YES;
  1143. NSDictionary * customerinfo=appDelegate.customerInfo;
  1144. NSString * contact=nil;
  1145. NSString * customer=nil;
  1146. if(customerinfo==nil)
  1147. {
  1148. contact=@"Select Contact";
  1149. [self.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  1150. }
  1151. else
  1152. {
  1153. contact=[customerinfo valueForKey:@"customer_contact"];
  1154. customer=[customerinfo valueForKey:@"customer_name"];
  1155. if(contact==nil||contact.length==0)
  1156. {
  1157. contact=@"No Name";
  1158. [self.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  1159. }
  1160. else
  1161. {
  1162. [self.btnContact setTitleColor:UIColorFromRGB(0x009900) forState:UIControlStateNormal];
  1163. }
  1164. }
  1165. NSMutableArray* arr_contact = [[NSMutableArray alloc] init];
  1166. if(contact.length>0)
  1167. [arr_contact addObject:contact];
  1168. if(customer.length>0)
  1169. [arr_contact addObject:customer];
  1170. NSString *contact_string = [arr_contact componentsJoinedByString:@" @"];
  1171. [self.btnContact setTitle:contact_string forState:UIControlStateNormal];
  1172. // [self.buttonUser setTitle:appDelegate.user forState:UIControlStateNormal];
  1173. [self reload];
  1174. }];
  1175. }
  1176. - (void) flipFromViewController:(UIViewController*) fromController
  1177. toViewController:(UIViewController*) toController
  1178. withDirection:(UIViewAnimationOptions) direction
  1179. {
  1180. toController.view.frame = self.container.bounds; // 1
  1181. // UIViewAutoresizingFlexibleLeftMargin = 1 << 0,
  1182. // UIViewAutoresizingFlexibleWidth = 1 << 1,
  1183. // UIViewAutoresizingFlexibleRightMargin = 1 << 2,
  1184. // UIViewAutoresizingFlexibleTopMargin = 1 << 3,
  1185. // UIViewAutoresizingFlexibleHeight = 1 << 4,
  1186. // UIViewAutoresizingFlexibleBottomMargin = 1 << 5
  1187. toController.view.autoresizingMask = UIViewAutoresizingFlexibleHeight |UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin;
  1188. DebugLog(@"MAIN VIEWCONTROLLER CHILD COUNT %lu",(unsigned long)self.childViewControllers.count);
  1189. [self addChildViewController:toController]; //
  1190. [fromController willMoveToParentViewController:nil]; //
  1191. [self transitionFromViewController:fromController
  1192. toViewController:toController
  1193. duration:0.0
  1194. options:direction | UIViewAnimationOptionCurveEaseIn
  1195. animations:nil
  1196. completion:^(BOOL finished) {
  1197. [toController didMoveToParentViewController:self]; // 2
  1198. [fromController removeFromParentViewController]; // 3
  1199. self.current_VC = toController;
  1200. // if([fromController isKindOfClass:[HomeViewController class]])
  1201. // {
  1202. // // [[NSNotificationCenter defaultCenter] postNotificationName:CYCLESCROLL_STOPTIMMER object:nil];
  1203. // // self.homeViewController = nil;
  1204. //
  1205. // }
  1206. }];
  1207. }
  1208. -(void)topicViewSelected:(int) type _id: (int) _id
  1209. {
  1210. // [self switchToCagegory:nil];
  1211. // if(type==0)
  1212. // {
  1213. // // [self.categoryViewController showDetailat:_id];
  1214. // }
  1215. // else
  1216. // {
  1217. // [self.categoryViewController showCategory];
  1218. //
  1219. // }
  1220. }
  1221. -(void)categoryMenuSelected:(NSString*)_id
  1222. {
  1223. // [self switchToCagegory:_id];
  1224. // [self.categoryViewController showCategory];
  1225. }
  1226. //- (void)switchToItemSearch:(NSString* )coverttype {
  1227. //
  1228. //
  1229. // self.itemSearchViewController.default_filter = nil;
  1230. // self.itemSearchViewController.covertype = coverttype;
  1231. // self.itemSearchViewController.saved_covertype = coverttype;
  1232. //
  1233. //
  1234. //
  1235. // self.itemSearchViewController.p_available = nil;
  1236. // self.itemSearchViewController.p_price = nil;
  1237. // self.itemSearchViewController.p_QTY = nil;
  1238. // self.itemSearchViewController.p_bestseller = nil;
  1239. //#ifdef RA_NOTIFICATION
  1240. // [ActiveViewController Notify:@"ItemSearchViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1241. //#else
  1242. // [self.itemSearchViewController reload_container_getdata:true];
  1243. //#endif
  1244. //
  1245. // if([self.current_VC isKindOfClass:[ItemSearchViewController class]])
  1246. //
  1247. // return;
  1248. // [self flipFromViewController:self.current_VC toViewController:self.itemSearchViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1249. //
  1250. // [[self navigationController] setNavigationBarHidden:YES animated:NO];
  1251. //
  1252. //
  1253. // // self.is_home = false;
  1254. // // self.current_vc = VC_CATEGORY;
  1255. // // [self.homeViewController willMoveToParentViewController:nil]; //1
  1256. // // [self.homeViewController.view removeFromSuperview]; //2
  1257. // // [self.homeViewController removeFromParentViewController]; //3
  1258. // //
  1259. // // [self.container addSubview:self.cagegoryViewController.view]; //2
  1260. // // [self.cagegoryViewController didMoveToParentViewController:self];
  1261. //}
  1262. //- (void)switchToCagegory:(NSString* )categoryid {
  1263. // // NSString* ttt =[@"Category" stringByAppendingString:[self categoryString:categoryid node:self.categoryMenu level:0]];
  1264. //
  1265. //
  1266. // UIApplication * app = [UIApplication sharedApplication];
  1267. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1268. // #if defined(BUILD_UWAVER)
  1269. // self.categoryViewController.categoryString = [@"Collections" stringByAppendingString:[self categoryString:categoryid node:appDelegate.categoryMenu level:0]];
  1270. //#else
  1271. // self.categoryViewController.categoryString = [@"Category" stringByAppendingString:[self categoryString:categoryid node:appDelegate.categoryMenu level:0]];
  1272. //#endif
  1273. //
  1274. // self.categoryViewController.cagegoryLabel.text =self.categoryViewController.categoryString;
  1275. // self.categoryViewController.categoryid = categoryid ;
  1276. // self.categoryViewController.loadall=false;
  1277. //// self.categoryViewController.collectionview
  1278. // self.categoryViewController.p_alert = nil;
  1279. // self.categoryViewController.p_available = nil;
  1280. // self.categoryViewController.p_price = nil;
  1281. // self.categoryViewController.p_QTY = nil;
  1282. // self.categoryViewController.p_bestseller = nil;
  1283. //
  1284. // self.categoryViewController.modelname = nil;
  1285. // self.categoryViewController.modeldescrip = nil;
  1286. //#ifdef RA_NOTIFICATION
  1287. // [ActiveViewController Notify:@"CategoryViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1288. //#else
  1289. // [self.categoryViewController reload_container_getdata:true];
  1290. //#endif
  1291. //
  1292. // [self.categoryViewController showCategory];
  1293. // if([self.current_VC isKindOfClass:[CategoryViewController class]])
  1294. //
  1295. // return;
  1296. // [self flipFromViewController:self.current_VC toViewController:self.categoryViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1297. //
  1298. // [[self navigationController] setNavigationBarHidden:YES animated:NO];
  1299. //
  1300. //
  1301. // // self.is_home = false;
  1302. // // self.current_vc = VC_CATEGORY;
  1303. // // [self.homeViewController willMoveToParentViewController:nil]; //1
  1304. // // [self.homeViewController.view removeFromSuperview]; //2
  1305. // // [self.homeViewController removeFromParentViewController]; //3
  1306. // //
  1307. // // [self.container addSubview:self.cagegoryViewController.view]; //2
  1308. // // [self.cagegoryViewController didMoveToParentViewController:self];
  1309. //}
  1310. - (IBAction)switchToHome:(UIButton *)sender {
  1311. [self clearSelected];
  1312. [self switchToHome];
  1313. // self.current_vc = VC_HOME;
  1314. // self.is_home = true;
  1315. //
  1316. // [self.cagegoryViewController willMoveToParentViewController:nil]; //1
  1317. // [self.cagegoryViewController.view removeFromSuperview]; //2
  1318. // [self.cagegoryViewController removeFromParentViewController]; //3
  1319. //
  1320. // [self.container addSubview:self.homeViewController.view]; //2
  1321. // [self.homeViewController didMoveToParentViewController:self];
  1322. }
  1323. -(void)switchToHome
  1324. {
  1325. [self clearSelected];
  1326. if([self.current_VC isKindOfClass:[ScanHomeViewController class]])
  1327. return;
  1328. if(self.homeViewController == nil)
  1329. {
  1330. self.homeViewController =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanHomeViewController"];
  1331. self.homeViewController.view.frame = self.container.bounds;
  1332. }
  1333. [self flipFromViewController:self.current_VC toViewController:self.homeViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1334. }
  1335. -(void) switchToPreviousVC
  1336. {
  1337. if(self.previous_VC==nil)
  1338. return;
  1339. if([self.current_VC isKindOfClass:[self.previous_VC class]])
  1340. return;
  1341. [self flipFromViewController:self.current_VC toViewController:self.previous_VC withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1342. }
  1343. - (IBAction)switchToCart:(UIButton *)sender {
  1344. // [self.btncart setBackgroundColor:UIColor.whiteColor];
  1345. // [self.btncart setTintColor:UIColor.clearColor];
  1346. // UIColor *color0=[self.btncart titleColorForState:UIControlStateNormal];
  1347. // UIColor *color1=[self.btncart titleColorForState:UIControlStateSelected];
  1348. [self switchToCart];
  1349. // self.current_vc = VC_HOME;
  1350. }
  1351. -(void) switchToCart
  1352. {
  1353. if([self.current_VC isKindOfClass:[CartViewController class]])
  1354. return;
  1355. [self clearSelected];
  1356. self.btncart.selected = true;
  1357. self.previous_VC = self.current_VC;
  1358. [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1359. }
  1360. -(void) switchToOrder
  1361. {
  1362. [self clearSelected];
  1363. self.btnorder.selected = true;
  1364. if([self.current_VC isKindOfClass:[ScanOrderListViewController class]])
  1365. return;
  1366. // UIApplication * app = [UIApplication sharedApplication];
  1367. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1368. [self flipFromViewController:self.current_VC toViewController:self.scanorderViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1369. }
  1370. - (IBAction)switchToOrder:(id)sender {
  1371. [self switchToOrder];
  1372. }
  1373. #pragma mark - CategoryMenuDelegate
  1374. -(void)SelectCategory:(NSString *)category
  1375. {
  1376. // [self switchToCagegory:category];
  1377. }
  1378. -(NSString*) categoryString:(NSString*) categoryid node:(NSDictionary*) json level:(int) level;
  1379. {
  1380. if(categoryid.length==0)
  1381. return @">All Products>";
  1382. //NSString* idString = [NSString stringWithFormat:@"%d",categoryid];
  1383. NSString* categoryString =@">";
  1384. int count = [[json valueForKey:@"count"] intValue];
  1385. for(int i=0;i<count;i++)
  1386. {
  1387. NSDictionary * category_json = [json objectForKey:[NSString stringWithFormat:@"category_%d",i]];
  1388. NSString* cid = [category_json valueForKey:@"id"] ;
  1389. // NSString* ttt =[categoryid substringToIndex:2+level*2];
  1390. // NSString * qqq =[cid substringToIndex:2+level*2];
  1391. // NSString *ds1=[categoryid substringToIndex:3+level*3];
  1392. // NSString*ds2 = [cid substringToIndex:3+level*3];
  1393. if(cid.length<3+level*3)
  1394. continue;
  1395. if(categoryid.length<3+level*3)
  1396. continue;
  1397. if([[categoryid substringToIndex:3+level*3] isEqualToString: [cid substringToIndex:3+level*3]])
  1398. {
  1399. //categoryString = [categoryString stringByAppendingString:@">"];
  1400. categoryString =[categoryString stringByAppendingString: [category_json valueForKey:@"title" ] ];
  1401. categoryString = [categoryString stringByAppendingString:[ self categoryString:categoryid node:category_json level:level+1]];
  1402. break;
  1403. }
  1404. }
  1405. return categoryString;
  1406. }
  1407. - (void)didReceiveMemoryWarning
  1408. {
  1409. [super didReceiveMemoryWarning];
  1410. // Dispose of any resources that can be recreated.
  1411. }
  1412. - (IBAction)openMenu:(UIButton *)sender {
  1413. [self showMenu];
  1414. }
  1415. - (UIImage*)screen_shot
  1416. {
  1417. // CGRect r = self.view.frame;
  1418. // CGRect r1 = self.view.bounds;
  1419. // double width,height;
  1420. //
  1421. // UIInterfaceOrientation orientation =[UIApplication sharedApplication].statusBarOrientation;
  1422. // ;
  1423. // if(orientation == UIDeviceOrientationLandscapeLeft ||orientation == UIDeviceOrientationLandscapeRight)
  1424. // {
  1425. // width = self.view.frame.size.width>self.view.frame.size.height? self.view.frame.size.width:self.view.frame.size.height;
  1426. // height =self.view.frame.size.width<self.view.frame.size.height? self.view.frame.size.width:self.view.frame.size.height;
  1427. // }
  1428. // else
  1429. // {
  1430. // width = self.view.frame.size.width<self.view.frame.size.height? self.view.frame.size.width:self.view.frame.size.height;
  1431. // height =self.view.frame.size.width>self.view.frame.size.height? self.view.frame.size.width:self.view.frame.size.height;
  1432. // }
  1433. UIGraphicsBeginImageContext(CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height));
  1434. [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
  1435. UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
  1436. UIGraphicsEndImageContext();
  1437. return viewImage;
  1438. }
  1439. - (IBAction)onhideMenuClick:(id)sender {
  1440. [self hideMenu];
  1441. self.backgroundButton.hidden=true;
  1442. self.openMenuButton.hidden = false;
  1443. self.sideMenu.hidden = true;
  1444. }
  1445. - (void)hideMenu
  1446. {
  1447. CGRect frame ;
  1448. frame.origin.x = -300;
  1449. frame.origin.y = 0;
  1450. frame.size.height = self.view.bounds.size.height;
  1451. frame.size.width = 364;
  1452. self.sideMenu.frame=frame;
  1453. self.sideMenu.hidden = true;
  1454. self.blurView.alpha = 0;
  1455. [self.menuButton setImage:[UIImage imageNamed:@"menu_open"] forState:UIControlStateNormal];
  1456. self.menuShown = false;
  1457. self.backgroundButton.hidden=true;
  1458. self.openMenuButton.hidden = false;
  1459. }
  1460. - (void)showMenu
  1461. {
  1462. [self.sideMenuTable reloadData];
  1463. UIImage* imgsource = [self screen_shot];
  1464. self.blurView.alpha = 0;
  1465. UIImage* imgBlur =[self applyBlurWithRadius:5 sourceImage:imgsource tintColor:[UIColor colorWithWhite:0.2 alpha:0.73] saturationDeltaFactor:1.8 maskImage:nil];
  1466. self.blurView.image = imgBlur;
  1467. // self.blurView.hidden = imgBlur;
  1468. // [self.sideMenu becomeFirstResponder];
  1469. self.sideMenu.hidden = false;
  1470. self.backgroundButton.hidden=false;
  1471. CGRect frame ;
  1472. frame.origin.x = 0;
  1473. frame.origin.y = 0;
  1474. frame.size.height = self.view.bounds.size.height;
  1475. frame.size.width = 364;
  1476. // [UIView animateWithDuration:1.0 animations:^{ self.sideMenu.frame=frame;
  1477. // self.blurView.alpha = 1;
  1478. // [self.menuButton setImage:[UIImage imageNamed:@"menu"] forState:UIControlStateNormal];
  1479. //
  1480. // }];
  1481. [UIView animateWithDuration:0.5 animations:^{ self.sideMenu.frame=frame;
  1482. self.blurView.alpha = 1;
  1483. }
  1484. completion:^(BOOL finished) {
  1485. [self.menuButton setImage:[UIImage imageNamed:@"menu"] forState:UIControlStateNormal];
  1486. }];
  1487. // UIImage* img= [UIImage imageNamed:@"menu"];
  1488. // self.menuButton.imageView.image = nil;
  1489. self.menuShown = true;
  1490. }
  1491. -(void)initMenuItems
  1492. {
  1493. UIApplication * app = [UIApplication sharedApplication];
  1494. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1495. self.sideMenuItems = [[NSMutableArray alloc] init];
  1496. NSMutableDictionary* map = [[NSMutableDictionary alloc] init];
  1497. if(appDelegate.user!=nil)
  1498. {
  1499. [map setValue:@"Wish List" forKey:@"title"];
  1500. [map setValue:@"rect_market_news" forKey:@"img"];
  1501. [self.sideMenuItems addObject:map.copy];
  1502. }
  1503. #if !defined(BUILD_HOMER) && !defined(BUILD_GATIT)
  1504. //#ifndef BUILD_HOMER //homer 要求去掉cam scan 2017/12/20
  1505. // if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  1506. {
  1507. [map setValue:@"Cam Scan" forKey:@"title"];
  1508. [map setValue:@"rect_contact_list" forKey:@"img"];
  1509. [self.sideMenuItems addObject:map.copy];
  1510. }
  1511. #endif
  1512. if(appDelegate.user_type==USER_ROLE_EMPLOYEE || (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeCustomer))
  1513. {
  1514. // [map setValue:@"Contact" forKey:@"title"];
  1515. // [map setValue:@"rect_contact_list" forKey:@"img"];
  1516. // [self.sideMenuItems addObject:map.copy];
  1517. //#ifdef BUILD_UWAVER
  1518. // [map setValue:@"Hang Tag" forKey:@"title"];
  1519. //#else
  1520. [map setValue:@"Portfolio" forKey:@"title"];
  1521. //#endif
  1522. [map setValue:@"rect_market_news" forKey:@"img"];
  1523. [self.sideMenuItems addObject:map.copy];
  1524. //#ifdef BUILD_UWAVER
  1525. // [map setValue:@"View Hang Tags" forKey:@"title"];
  1526. //#else
  1527. [map setValue:@"View Portfolios" forKey:@"title"];
  1528. //#endif
  1529. [map setValue:@"rect_pdf_list" forKey:@"img"];
  1530. [self.sideMenuItems addObject:map.copy];
  1531. }
  1532. if(appDelegate.can_show_price)
  1533. {
  1534. if(appDelegate.price_hidden)
  1535. [map setValue:@"Show Price" forKey:@"title"];
  1536. else
  1537. [map setValue:@"Hide Price" forKey:@"title"];
  1538. [map setValue:@"rect_announcements" forKey:@"img"];
  1539. [self.sideMenuItems addObject:map.copy];
  1540. }
  1541. // [map setValue:@"Contact" forKey:@"title"];
  1542. // [map setValue:@"rect_market_news" forKey:@"img"];
  1543. // [self.sideMenuItems addObject:map.copy];
  1544. // [map setValue:@"Cache" forKey:@"title"];
  1545. // [map setValue:@"rect_announcements" forKey:@"img"];
  1546. //[self.sideMenuItems addObject:map.copy];
  1547. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  1548. // [map setValue:@"Message" forKey:@"title"];
  1549. // [map setValue:@"rect_search_history" forKey:@"img"];
  1550. // [self.sideMenuItems addObject:map.copy];
  1551. //
  1552. #if defined(BUILD_NPD)
  1553. [map setValue:@"Scanner Setting" forKey:@"title"];
  1554. [map setValue:@"rect_change_password" forKey:@"img"];
  1555. [self.sideMenuItems addObject:map.copy];
  1556. # endif
  1557. #if defined(SCANNER_ORDER)
  1558. [map setValue:@"Scanner Order" forKey:@"title"];
  1559. [map setValue:@"rect_change_password" forKey:@"img"];
  1560. [self.sideMenuItems addObject:map.copy];
  1561. # endif
  1562. #if defined(BUILD_NPD)|| defined (BUILD_CONTRAST)
  1563. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  1564. {
  1565. [map setValue:@"Offline Setting" forKey:@"title"];
  1566. [map setValue:@"rect_market_news" forKey:@"img"];
  1567. [self.sideMenuItems addObject:map.copy];
  1568. }
  1569. #endif
  1570. if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore ) {
  1571. [map setValue:@"Price Setting" forKey:@"title"];
  1572. // [map setValue:@"rect_market_news" forKey:@"img"];
  1573. [self.sideMenuItems addObject:map.copy];
  1574. }
  1575. if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore ) {
  1576. if ([RASingleton sharedInstance].global_lock) {
  1577. [map setValue:@"Unlock" forKey:@"title"];
  1578. } else {
  1579. [map setValue:@"Lock" forKey:@"title"];
  1580. }
  1581. [self.sideMenuItems addObject:map.copy];
  1582. }
  1583. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  1584. /*
  1585. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  1586. {
  1587. [map setValue:@"Offline Setting" forKey:@"title"];
  1588. [map setValue:@"rect_market_news" forKey:@"img"];
  1589. [self.sideMenuItems addObject:map.copy];
  1590. }
  1591. */
  1592. // if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER) {
  1593. // [map setValue:@"Price Setting" forKey:@"title"];
  1594. // // [map setValue:@"rect_market_news" forKey:@"img"];
  1595. // [self.sideMenuItems addObject:map.copy];
  1596. // }
  1597. if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore ) {
  1598. if ([Singleton sharedInstance].global_lock) {
  1599. [map setValue:@"Unlock" forKey:@"title"];
  1600. } else {
  1601. [map setValue:@"Lock" forKey:@"title"];
  1602. }
  1603. [self.sideMenuItems addObject:map.copy];
  1604. }
  1605. # endif
  1606. #ifdef DEBUG
  1607. // if([[appDelegate.user lowercaseString] isEqualToString:@"larryl"]||[[appDelegate.user lowercaseString] isEqualToString:@"arpithat"])
  1608. {
  1609. // [map setValue:@"Contact" forKey:@"title"];
  1610. // [map setValue:@"rect_contact_list" forKey:@"img"];
  1611. // [self.sideMenuItems addObject:map.copy];
  1612. [map setValue:@"Function Test" forKey:@"title"];
  1613. [map setValue:@"rect_market_news" forKey:@"img"];
  1614. [self.sideMenuItems addObject:map.copy];
  1615. }
  1616. #endif
  1617. [map setValue:@"Privacy Policy" forKey:@"title"];
  1618. [map setValue:@"rect_change_password" forKey:@"img"];
  1619. [self.sideMenuItems addObject:map.copy];
  1620. [map setValue:@"About us" forKey:@"title"];
  1621. [map setValue:@"rect_change_password" forKey:@"img"];
  1622. [self.sideMenuItems addObject:map.copy];
  1623. #ifdef BUILD_HMLG
  1624. [map setValue:@"Homelegance Website" forKey:@"title"];
  1625. [map setValue:@"rect_change_password" forKey:@"img"];
  1626. [self.sideMenuItems addObject:map.copy];
  1627. #endif
  1628. #if defined(BUILD_NPD)
  1629. [map setValue:@"BLOG" forKey:@"title"];
  1630. [map setValue:@"rect_change_password" forKey:@"img"];
  1631. [self.sideMenuItems addObject:map.copy];
  1632. [map setValue:[NSString stringWithFormat:@"%@ Website",COMPANY_SHORT_NAME] forKey:@"title"];
  1633. [map setValue:@"rect_change_password" forKey:@"img"];
  1634. [self.sideMenuItems addObject:map.copy];
  1635. [map setValue:[NSString stringWithFormat:@"%@ Policy",COMPANY_SHORT_NAME] forKey:@"title"];
  1636. [map setValue:@"rect_change_password" forKey:@"img"];
  1637. [self.sideMenuItems addObject:map.copy];
  1638. [map setValue:@"Simplified Buying Program" forKey:@"title"];
  1639. [map setValue:@"rect_change_password" forKey:@"img"];
  1640. [self.sideMenuItems addObject:map.copy];
  1641. #endif
  1642. #ifdef BUILD_USAI
  1643. // [map setValue:@"BLOG" forKey:@"title"];
  1644. // [map setValue:@"rect_change_password" forKey:@"img"];
  1645. // [self.sideMenuItems addObject:map.copy];
  1646. [map setValue:@"USAI Website" forKey:@"title"];
  1647. [map setValue:@"rect_change_password" forKey:@"img"];
  1648. [self.sideMenuItems addObject:map.copy];
  1649. #endif
  1650. #ifdef BUILD_HOMER
  1651. /*
  1652. [map setValue:@"BLOG" forKey:@"title"];
  1653. [map setValue:@"rect_change_password" forKey:@"img"];
  1654. [self.sideMenuItems addObject:map.copy];
  1655. */
  1656. [map setValue:@"HOMER Website" forKey:@"title"];
  1657. [map setValue:@"rect_change_password" forKey:@"img"];
  1658. [self.sideMenuItems addObject:map.copy];
  1659. #endif
  1660. #ifdef BUILD_GATIT
  1661. [map setValue:@"TITAN Website" forKey:@"title"];
  1662. [map setValue:@"rect_change_password" forKey:@"img"];
  1663. [self.sideMenuItems addObject:map.copy];
  1664. # endif
  1665. [self.sideMenuTable reloadData];
  1666. //
  1667. }
  1668. - (UIImage *)applyBlurWithRadius:(CGFloat)blurRadius sourceImage:(UIImage*)sourceImage tintColor:(UIColor *)tintColor saturationDeltaFactor:(CGFloat)saturationDeltaFactor maskImage:(UIImage *)maskImage
  1669. {
  1670. // Check pre-conditions.
  1671. if (sourceImage.size.width < 1 || sourceImage.size.height < 1) {
  1672. DebugLog (@"*** error: invalid size: (%.2f x %.2f). Both dimensions must be >= 1: %@", sourceImage.size.width, sourceImage.size.height, self);
  1673. return nil;
  1674. }
  1675. if (!sourceImage.CGImage) {
  1676. DebugLog (@"*** error: image must be backed by a CGImage: %@", self);
  1677. return nil;
  1678. }
  1679. if (maskImage && !maskImage.CGImage) {
  1680. DebugLog (@"*** error: maskImage must be backed by a CGImage: %@", maskImage);
  1681. return nil;
  1682. }
  1683. CGRect imageRect = { CGPointZero, sourceImage.size };
  1684. UIImage *effectImage = sourceImage;
  1685. BOOL hasBlur = blurRadius > __FLT_EPSILON__;
  1686. BOOL hasSaturationChange = fabs(saturationDeltaFactor - 1.) > __FLT_EPSILON__;
  1687. if (hasBlur || hasSaturationChange) {
  1688. UIGraphicsBeginImageContextWithOptions(sourceImage.size, NO, [[UIScreen mainScreen] scale]);
  1689. CGContextRef effectInContext = UIGraphicsGetCurrentContext();
  1690. CGContextScaleCTM(effectInContext, 1.0, -1.0);
  1691. CGContextTranslateCTM(effectInContext, 0, -sourceImage.size.height);
  1692. CGContextDrawImage(effectInContext, imageRect, sourceImage.CGImage);
  1693. vImage_Buffer effectInBuffer;
  1694. effectInBuffer.data = CGBitmapContextGetData(effectInContext);
  1695. effectInBuffer.width = CGBitmapContextGetWidth(effectInContext);
  1696. effectInBuffer.height = CGBitmapContextGetHeight(effectInContext);
  1697. effectInBuffer.rowBytes = CGBitmapContextGetBytesPerRow(effectInContext);
  1698. UIGraphicsBeginImageContextWithOptions(sourceImage.size, NO, [[UIScreen mainScreen] scale]);
  1699. CGContextRef effectOutContext = UIGraphicsGetCurrentContext();
  1700. vImage_Buffer effectOutBuffer;
  1701. effectOutBuffer.data = CGBitmapContextGetData(effectOutContext);
  1702. effectOutBuffer.width = CGBitmapContextGetWidth(effectOutContext);
  1703. effectOutBuffer.height = CGBitmapContextGetHeight(effectOutContext);
  1704. effectOutBuffer.rowBytes = CGBitmapContextGetBytesPerRow(effectOutContext);
  1705. if (hasBlur) {
  1706. // A description of how to compute the box kernel width from the Gaussian
  1707. // radius (aka standard deviation) appears in the SVG spec:
  1708. // http://www.w3.org/TR/SVG/filters.html#feGaussianBlurElement
  1709. //
  1710. // For larger values of 's' (s >= 2.0), an approximation can be used: Three
  1711. // successive box-blurs build a piece-wise quadratic convolution kernel, which
  1712. // approximates the Gaussian kernel to within roughly 3%.
  1713. //
  1714. // let d = floor(s * 3*sqrt(2*pi)/4 + 0.5)
  1715. //
  1716. // ... if d is odd, use three box-blurs of size 'd', centered on the output pixel.
  1717. //
  1718. CGFloat inputRadius = blurRadius * [[UIScreen mainScreen] scale];
  1719. NSUInteger radius = floor(inputRadius * 3. * sqrt(2 * M_PI) / 4 + 0.5);
  1720. if (radius % 2 != 1) {
  1721. radius += 1; // force radius to be odd so that the three box-blur methodology works.
  1722. }
  1723. vImageBoxConvolve_ARGB8888(&effectInBuffer, &effectOutBuffer, NULL, 0, 0, (unsigned int)radius, (unsigned int)radius, 0, kvImageEdgeExtend);
  1724. vImageBoxConvolve_ARGB8888(&effectOutBuffer, &effectInBuffer, NULL, 0, 0, (unsigned int)radius, (unsigned int)radius, 0, kvImageEdgeExtend);
  1725. vImageBoxConvolve_ARGB8888(&effectInBuffer, &effectOutBuffer, NULL, 0, 0, (unsigned int)radius, (unsigned int)radius, 0, kvImageEdgeExtend);
  1726. }
  1727. BOOL effectImageBuffersAreSwapped = NO;
  1728. if (hasSaturationChange) {
  1729. CGFloat s = saturationDeltaFactor;
  1730. CGFloat floatingPointSaturationMatrix[] = {
  1731. 0.0722 + 0.9278 * s, 0.0722 - 0.0722 * s, 0.0722 - 0.0722 * s, 0,
  1732. 0.7152 - 0.7152 * s, 0.7152 + 0.2848 * s, 0.7152 - 0.7152 * s, 0,
  1733. 0.2126 - 0.2126 * s, 0.2126 - 0.2126 * s, 0.2126 + 0.7873 * s, 0,
  1734. 0, 0, 0, 1,
  1735. };
  1736. const int32_t divisor = 256;
  1737. NSUInteger matrixSize = sizeof(floatingPointSaturationMatrix)/sizeof(floatingPointSaturationMatrix[0]);
  1738. int16_t saturationMatrix[matrixSize];
  1739. for (NSUInteger i = 0; i < matrixSize; ++i) {
  1740. saturationMatrix[i] = (int16_t)roundf(floatingPointSaturationMatrix[i] * divisor);
  1741. }
  1742. if (hasBlur) {
  1743. vImageMatrixMultiply_ARGB8888(&effectOutBuffer, &effectInBuffer, saturationMatrix, divisor, NULL, NULL, kvImageNoFlags);
  1744. effectImageBuffersAreSwapped = YES;
  1745. }
  1746. else {
  1747. vImageMatrixMultiply_ARGB8888(&effectInBuffer, &effectOutBuffer, saturationMatrix, divisor, NULL, NULL, kvImageNoFlags);
  1748. }
  1749. }
  1750. if (!effectImageBuffersAreSwapped)
  1751. effectImage = UIGraphicsGetImageFromCurrentImageContext();
  1752. UIGraphicsEndImageContext();
  1753. if (effectImageBuffersAreSwapped)
  1754. effectImage = UIGraphicsGetImageFromCurrentImageContext();
  1755. UIGraphicsEndImageContext();
  1756. }
  1757. // Set up output context.
  1758. UIGraphicsBeginImageContextWithOptions(sourceImage.size, NO, [[UIScreen mainScreen] scale]);
  1759. CGContextRef outputContext = UIGraphicsGetCurrentContext();
  1760. CGContextScaleCTM(outputContext, 1.0, -1.0);
  1761. CGContextTranslateCTM(outputContext, 0, -sourceImage.size.height);
  1762. // Draw base image.
  1763. CGContextDrawImage(outputContext, imageRect, sourceImage.CGImage);
  1764. // Draw effect image.
  1765. if (hasBlur) {
  1766. CGContextSaveGState(outputContext);
  1767. if (maskImage) {
  1768. CGContextClipToMask(outputContext, imageRect, maskImage.CGImage);
  1769. }
  1770. CGContextDrawImage(outputContext, imageRect, effectImage.CGImage);
  1771. CGContextRestoreGState(outputContext);
  1772. }
  1773. // Add in color tint.
  1774. if (tintColor) {
  1775. CGContextSaveGState(outputContext);
  1776. CGContextSetFillColorWithColor(outputContext, tintColor.CGColor);
  1777. CGContextFillRect(outputContext, imageRect);
  1778. CGContextRestoreGState(outputContext);
  1779. }
  1780. // Output image is ready.
  1781. UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext();
  1782. UIGraphicsEndImageContext();
  1783. return outputImage;
  1784. }
  1785. //- (IBAction)openMenu:(UIButton *)sender {
  1786. //}
  1787. #pragma mark - Table view data source
  1788. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  1789. {
  1790. return 1;
  1791. }
  1792. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  1793. {
  1794. return self.sideMenuItems.count;
  1795. }
  1796. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  1797. {
  1798. UIApplication * app = [UIApplication sharedApplication];
  1799. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1800. NSString *CellIdentifier = @"SideMenuItem";
  1801. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1802. NSString* title = [self.sideMenuItems[indexPath.row] valueForKey:@"title"];
  1803. cell.backgroundColor = [UIColor clearColor];
  1804. // [cell.backgroundColor:[UIColor clearColor]];
  1805. // UIImageView* iv= [[UIImageView alloc] initWithImage:];
  1806. cell.textLabel.text = title;
  1807. cell.detailTextLabel.textColor =[UIColor redColor];
  1808. if([title isEqualToString:@"Wish List"]&&appDelegate.wish_count>0)
  1809. cell.detailTextLabel.text = [NSString stringWithFormat:@"%ld",appDelegate.wish_count];
  1810. else if(([title isEqualToString:@"Portfolio"] || [title isEqualToString:@"Hang Tag"])&&appDelegate.port_count>0)
  1811. cell.detailTextLabel.text = [NSString stringWithFormat:@"%ld",appDelegate.port_count];
  1812. else
  1813. {
  1814. cell.detailTextLabel.text =nil;
  1815. }
  1816. // cell.imageView.image = [UIImage imageNamed:[self.toolsinfo[indexPath.row] valueForKey:@"img"]];
  1817. return cell;
  1818. }
  1819. #ifdef SCANNER_ORDER
  1820. -(void) scanLogin
  1821. {
  1822. [self onUserButtonClick:nil];
  1823. }
  1824. -(void) initAppDelegate
  1825. {
  1826. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1827. // appDelegate.user_type = USER_ROLE_EMPLOYEE;
  1828. // appDelegate.can_set_cart_price = true;
  1829. // appDelegate.can_see_price = true;
  1830. // appDelegate.can_set_cart_price = true;
  1831. // appDelegate.can_show_price = true;
  1832. // appDelegate.can_cancel_order = true;
  1833. // appDelegate.can_create_order=true;
  1834. // appDelegate.can_delete_order = true;
  1835. // appDelegate.can_submit_order = true;
  1836. // appDelegate.bLogin = true;
  1837. // RASingleton.sharedInstance.permissions_edit_order = true;
  1838. RASingleton.sharedInstance.price_type = 1;
  1839. // [OLDataProvider createScanTempFolder];
  1840. NSDictionary *addressDic = [[NSUserDefaults standardUserDefaults] valueForKey:@"ScanAddress"] ;
  1841. if (addressDic) {
  1842. // NSUInteger selectedIndex = [[addressDic objectForKey:@"selectedIndex"] integerValue];
  1843. // if (selectedIndex == 1) {
  1844. // self.address = [addressDic objectForKey:@"serverAddress"];
  1845. // }
  1846. // if (selectedIndex == 2) {
  1847. // self.address = [addressDic objectForKey:@"serverAddress"];
  1848. // }
  1849. appDelegate.address = [addressDic objectForKey:@"serverAddress"];
  1850. // [OLDataProvider guestLogin];
  1851. NSMutableDictionary* guestjson=[OLDataProvider loadScanTemplate:@"guest.json"];
  1852. if(!guestjson)
  1853. {
  1854. dispatch_async(dispatch_get_main_queue(), ^{
  1855. [RADataProvider updateTemplate:self];
  1856. });
  1857. }
  1858. else
  1859. dispatch_async(dispatch_get_main_queue(), ^{
  1860. [self onUserButtonClick:nil];
  1861. });
  1862. }
  1863. else
  1864. {
  1865. // return;
  1866. SetupServerViewController * servervc =[[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"SetupServerViewController"];
  1867. servervc.returnValue = ^{
  1868. NSDictionary *addressDic = [[NSUserDefaults standardUserDefaults] valueForKey:@"ScanAddress"];
  1869. if (addressDic) {
  1870. self.labelServer.text = [addressDic objectForKey:@"show_name"];
  1871. }
  1872. dispatch_async(dispatch_get_main_queue(), ^{
  1873. [RADataProvider updateTemplate:self];
  1874. });
  1875. };
  1876. [self.navigationController pushViewController:servervc animated:true];
  1877. }
  1878. [RADataProvider default_price_group];
  1879. }
  1880. #endif
  1881. #pragma mark - Table view delegate
  1882. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  1883. {
  1884. NSString* title = [self.sideMenuItems[indexPath.row] valueForKey:@"title"];
  1885. if([title isEqualToString:@"Cache"])
  1886. {
  1887. CacheViewController * settingvc=[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"CacheViewController"];
  1888. PopupNavigationController * navi=[[PopupNavigationController alloc] initWithRootViewController:settingvc];
  1889. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1890. [self presentViewController:navi animated:YES completion:^{
  1891. //DebugLog(@"login.........");
  1892. // <#code#>
  1893. }];
  1894. }
  1895. #ifdef SCANNER_ORDER
  1896. #endif
  1897. else if([title isEqualToString:@"Scanner Setting"])
  1898. {
  1899. //
  1900. #ifndef RA_NOTIFICATION
  1901. UIApplication * app = [UIApplication sharedApplication];
  1902. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1903. UIViewController* active_vc = appDelegate.active_controller;
  1904. ScannerSettingViewController * gunVC =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ScannerSettingViewController"];
  1905. appDelegate.active_controller = gunVC;
  1906. gunVC.onDismissVC = ^(){
  1907. appDelegate.active_controller = active_vc;
  1908. };
  1909. #else
  1910. ScannerSettingViewController * gunVC =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ScannerSettingViewController"];
  1911. #endif
  1912. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:gunVC] ;
  1913. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1914. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1915. [self presentViewController:navi animated:YES completion:^{
  1916. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1917. DebugLog(@"about present.........");
  1918. // self.btop = false;
  1919. // <#code#>
  1920. }];
  1921. }
  1922. else if([title isEqualToString:@"Offline Setting"])
  1923. {
  1924. // UIApplication * app = [UIApplication sharedApplication];
  1925. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1926. //UIViewController* active_vc = appDelegate.active_controller;
  1927. OfflineSettingViewController * offlineVC =[ [UIStoryboard storyboardWithName:@"OLM" bundle:nil] instantiateViewControllerWithIdentifier:@"OfflineSettingViewController"];
  1928. // loginvc.delegate = self;
  1929. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1930. // appDelegate.active_controller = gunVC;
  1931. // gunVC.onDismissVC = ^(){
  1932. // appDelegate.active_controller = active_vc;
  1933. // };
  1934. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:offlineVC] ;
  1935. navi.modalInPresentation=true;
  1936. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1937. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1938. [self presentViewController:navi animated:YES completion:^{
  1939. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1940. DebugLog(@"about present.........");
  1941. // self.btop = false;
  1942. // <#code#>
  1943. }];
  1944. // [iSalesDB testdata];
  1945. }
  1946. else if([title isEqualToString:@"Function Test"])
  1947. {
  1948. // NSString* url = @"https://shopla.homelegance.com/";
  1949. //
  1950. //
  1951. // NSString* title = @"NPD";
  1952. // UIApplication * app = [UIApplication sharedApplication];
  1953. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1954. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  1955. //
  1956. //
  1957. FunctionTestViewController *ViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"FunctionTestViewController"];
  1958. // ViewController.url = url;
  1959. // ViewController.title = title;
  1960. [self.navigationController pushViewController:ViewController animated:YES];
  1961. }
  1962. else if ([title isEqualToString:@"BLOG"]) {
  1963. NSString* url = URL_BLOG;
  1964. #ifdef BUILD_HOMER
  1965. NSString* title = @"HOMER BLOG";
  1966. #endif
  1967. #ifdef BUILD_GATIT
  1968. NSString* title = @"TITAN BLOG";
  1969. #endif
  1970. #ifdef BUILD_NPD
  1971. NSString* title = @"NPD BLOG";
  1972. #endif
  1973. #ifdef BUILD_USAI
  1974. NSString* title = @"USAI BLOG";
  1975. #endif
  1976. #ifdef BUILD_CONTRAST
  1977. NSString* title = @"CONTRAST BLOG";
  1978. #endif
  1979. title = [NSString stringWithFormat:@"%@ BLOG",COMPANY_SHORT_NAME];
  1980. WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  1981. ViewController.url = url;
  1982. ViewController.title = title;
  1983. [self.navigationController pushViewController:ViewController animated:YES];
  1984. }
  1985. else if([title isEqualToString:@"NPD Website"])
  1986. {
  1987. NSString* url = @"https://www.newpacificdirect.com";//@"https://shopla.homelegance.com/general.htm?websiteId=1";//
  1988. NSString* title = @"NPD";
  1989. // UIApplication * app = [UIApplication sharedApplication];
  1990. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1991. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  1992. //
  1993. //
  1994. WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  1995. ViewController.url = url;
  1996. ViewController.title = title;
  1997. [self.navigationController pushViewController:ViewController animated:YES];
  1998. }
  1999. else if([title isEqualToString:@"USAI Website"])
  2000. {
  2001. NSString* url = @"http://www.united-us.net/";//@"https://shopla.homelegance.com/general.htm?websiteId=1";//
  2002. NSString* title = @"USAI";
  2003. // UIApplication * app = [UIApplication sharedApplication];
  2004. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  2005. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  2006. //
  2007. //
  2008. WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  2009. ViewController.url = url;
  2010. ViewController.title = title;
  2011. [self.navigationController pushViewController:ViewController animated:YES];
  2012. }
  2013. else if([title isEqualToString:@"Homelegance Website"])
  2014. {
  2015. NSString* url = @"http://207.140.24.83";//@"https://shopla.homelegance.com/general.htm?websiteId=1";//
  2016. NSString* title = @"Homelegance";
  2017. // UIApplication * app = [UIApplication sharedApplication];
  2018. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  2019. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  2020. //
  2021. //
  2022. WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  2023. ViewController.url = url;
  2024. ViewController.title = title;
  2025. [self.navigationController pushViewController:ViewController animated:YES];
  2026. }
  2027. else if([title isEqualToString:@"HOMER Website"])
  2028. {
  2029. NSString* url = COMPANY_WEB;
  2030. NSString* title = @"HOMER";
  2031. WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  2032. ViewController.url = url;
  2033. ViewController.title = title;
  2034. [self.navigationController pushViewController:ViewController animated:YES];
  2035. }
  2036. else if([title isEqualToString:@"TITAN Website"])
  2037. {
  2038. NSString* url = COMPANY_WEB;
  2039. NSString* title = @"TITAN";
  2040. WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  2041. ViewController.url = url;
  2042. ViewController.title = title;
  2043. [self.navigationController pushViewController:ViewController animated:YES];
  2044. }
  2045. else if([title isEqualToString:@"NPD Policy"])
  2046. {
  2047. NSString* url = URL_NPD_POLICY;//@"https://shopla.homelegance.com/general.htm?websiteId=1";//
  2048. NSString* title = @"NPD Policy";
  2049. // UIApplication * app = [UIApplication sharedApplication];
  2050. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  2051. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  2052. //
  2053. //
  2054. WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  2055. ViewController.url = url;
  2056. ViewController.title = title;
  2057. [self.navigationController pushViewController:ViewController animated:YES];
  2058. }
  2059. else if([title isEqualToString:@"USAI Policy"])
  2060. {
  2061. NSString* url = URL_NPD_POLICY;
  2062. NSString* title = @"USAI Policy";
  2063. WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  2064. ViewController.url = url;
  2065. ViewController.title = title;
  2066. [self.navigationController pushViewController:ViewController animated:YES];
  2067. }
  2068. else if([title isEqualToString:@"HOMER Policy"])
  2069. {
  2070. NSString* url = URL_NPD_POLICY;
  2071. NSString* title = @"HOMER Policy";
  2072. WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  2073. ViewController.url = url;
  2074. ViewController.title = title;
  2075. [self.navigationController pushViewController:ViewController animated:YES];
  2076. }
  2077. else if([title isEqualToString:@"Simplified Buying Program"])
  2078. {
  2079. SimplifiedBuyingProgramViewController *ViewController = [[UIStoryboard storyboardWithName:@"NPD_Mobile" bundle:nil] instantiateViewControllerWithIdentifier:@"SimplifiedBuyingProgramViewController"];
  2080. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:ViewController] ;
  2081. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  2082. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  2083. [self presentViewController:navi animated:YES completion:^{
  2084. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  2085. DebugLog(@"about present.........");
  2086. // self.btop = false;
  2087. // <#code#>
  2088. }];
  2089. }
  2090. else if ([title isEqualToString:@"Privacy Policy"]) {
  2091. NSString* url = URL_PRIVACY;
  2092. NSString* title = @"Privacy Policy";
  2093. WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  2094. ViewController.url = url;
  2095. ViewController.title = title;
  2096. [self.navigationController pushViewController:ViewController animated:YES];
  2097. }
  2098. else if([title isEqualToString:@"About us"])
  2099. {
  2100. AboutViewController * aboutVC =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"AboutViewController"];
  2101. // loginvc.delegate = self;
  2102. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  2103. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:aboutVC] ;
  2104. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  2105. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  2106. [self presentViewController:navi animated:YES completion:^{
  2107. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  2108. DebugLog(@"about present.........");
  2109. // self.btop = false;
  2110. // <#code#>
  2111. }];
  2112. }
  2113. // else if([title isEqualToString:@"Wish List"])
  2114. // {
  2115. // [self hideMenu];
  2116. // [self switchtowishlist];
  2117. // }
  2118. else if([title isEqualToString:@"Show Price"])
  2119. {
  2120. UIApplication * app = [UIApplication sharedApplication];
  2121. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  2122. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore && [RASingleton sharedInstance].global_lock) {
  2123. JKLockController *lockVC = [[JKLockController alloc] init];
  2124. [lockVC setPasswordKey:[NSString stringWithFormat:@"%@_password",appDelegate.user]];
  2125. __weak typeof(self) weakself = self;
  2126. lockVC.authoReturn = ^(BOOL failure) {
  2127. if (weakself) {
  2128. __strong typeof(weakself) strongself = weakself;
  2129. [appDelegate set_priceHidden:false];
  2130. [strongself initMenuItems];
  2131. [strongself hideMenu];
  2132. }
  2133. };
  2134. [self.navigationController pushViewController:lockVC animated:YES];
  2135. } else {
  2136. [appDelegate set_priceHidden:false];
  2137. [self initMenuItems];
  2138. [self hideMenu];
  2139. }
  2140. }
  2141. else if([title isEqualToString:@"Hide Price"])
  2142. {
  2143. UIApplication * app = [UIApplication sharedApplication];
  2144. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  2145. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore && [RASingleton sharedInstance].global_lock) {
  2146. JKLockController *lockVC = [[JKLockController alloc] init];
  2147. [lockVC setPasswordKey:[NSString stringWithFormat:@"%@_password",appDelegate.user]];
  2148. __weak typeof(self) weakself = self;
  2149. lockVC.authoReturn = ^(BOOL failure) {
  2150. if (weakself) {
  2151. __strong typeof(weakself) strongself = weakself;
  2152. [appDelegate set_priceHidden:true];
  2153. [strongself initMenuItems];
  2154. [strongself hideMenu];
  2155. }
  2156. };
  2157. [self.navigationController pushViewController:lockVC animated:YES];
  2158. } else {
  2159. [appDelegate set_priceHidden:true];
  2160. [self initMenuItems];
  2161. [self hideMenu];
  2162. }
  2163. }
  2164. // else if([title isEqualToString:@"Portfolio"] || [title isEqualToString:@"Hang Tag"])
  2165. // {
  2166. // [self hideMenu];
  2167. // if([self.current_VC isKindOfClass:[PortfolioViewController class]])
  2168. // return;
  2169. // [self flipFromViewController:self.current_VC toViewController:self.portfolioViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  2170. // }
  2171. // else if([title isEqualToString:@"View Portfolios"] || [title isEqualToString:@"View Hang Tags"])
  2172. // {
  2173. // [self hideMenu];
  2174. // if([self.current_VC isKindOfClass:[PortfolioListViewController class]])
  2175. // return;
  2176. // [self flipFromViewController:self.current_VC toViewController:self.pdfListViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  2177. // }
  2178. else if([title isEqualToString:@"Contact"])
  2179. {
  2180. // UITableViewCell* cell =(UITableViewCell*) sender.superview.superview;
  2181. //
  2182. // NSIndexPath * indexPath = [self.detailTable indexPathForCell:cell];
  2183. //
  2184. // if(indexPath.section!=1)
  2185. // return ;
  2186. // // DebugLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
  2187. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  2188. //
  2189. // NSString* product_id = [item_json valueForKey:@"product_id"];
  2190. [self hideMenu];
  2191. [self switchtocontact];
  2192. }
  2193. else if([title isEqualToString:@"Cam Scan"])
  2194. {
  2195. // UITableViewCell* cell =(UITableViewCell*) sender.superview.superview;
  2196. //
  2197. // NSIndexPath * indexPath = [self.detailTable indexPathForCell:cell];
  2198. //
  2199. // if(indexPath.section!=1)
  2200. // return ;
  2201. // // DebugLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
  2202. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  2203. //
  2204. // NSString* product_id = [item_json valueForKey:@"product_id"];
  2205. [self hideMenu];
  2206. //
  2207. // [self switchtocontact];
  2208. ScannerViewController * scannerVC =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ScannerViewController"];
  2209. [self.navigationController pushViewController:scannerVC animated:true];
  2210. } else if ([title isEqualToString:@"Price Setting"]) {
  2211. UIApplication * app = [UIApplication sharedApplication];
  2212. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  2213. if ([RASingleton sharedInstance].global_lock) {
  2214. JKLockController *lockVC = [[JKLockController alloc] init];
  2215. [lockVC setPasswordKey:[NSString stringWithFormat:@"%@_password",appDelegate.user]];
  2216. __weak typeof(self) weakself = self;
  2217. lockVC.authoReturn = ^(BOOL failure) {
  2218. if (weakself) {
  2219. __strong typeof(weakself) strongself = weakself;
  2220. PriceSettingViewController *priceSettingVC =[ [UIStoryboard storyboardWithName:@"CUL" bundle:nil] instantiateViewControllerWithIdentifier:@"PriceSettingViewController"];
  2221. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:priceSettingVC] ;
  2222. navi.navigationBar.translucent = NO;
  2223. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  2224. [strongself presentViewController:navi animated:YES completion:^{
  2225. }];
  2226. }
  2227. };
  2228. [self.navigationController pushViewController:lockVC animated:YES];
  2229. } else {
  2230. PriceSettingViewController *priceSettingVC =[ [UIStoryboard storyboardWithName:@"CUL" bundle:nil] instantiateViewControllerWithIdentifier:@"PriceSettingViewController"];
  2231. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:priceSettingVC] ;
  2232. navi.navigationBar.translucent = NO;
  2233. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  2234. [self presentViewController:navi animated:YES completion:^{
  2235. }];
  2236. }
  2237. } else if ([title isEqualToString:@"Lock"] || [title isEqualToString:@"Unlock"]) {
  2238. UIApplication * app = [UIApplication sharedApplication];
  2239. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  2240. JKLockController *lockVC = [[JKLockController alloc] init];
  2241. [lockVC setPasswordKey:[NSString stringWithFormat:@"%@_password",appDelegate.user]];
  2242. __weak typeof(self) weakself = self;
  2243. lockVC.authoReturn = ^(BOOL failure) {
  2244. if (weakself) {
  2245. __strong typeof(weakself) strongself = weakself;
  2246. [RASingleton sharedInstance].global_lock = ![RASingleton sharedInstance].global_lock;
  2247. [strongself initMenuItems];
  2248. [strongself hideMenu];
  2249. }
  2250. };
  2251. [self.navigationController pushViewController:lockVC animated:YES];
  2252. }
  2253. }
  2254. //#pragma mark - UIAlertViewDelegate
  2255. //// Called when a button is clicked. The view will be automatically dismissed after this call returns
  2256. //- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  2257. //{
  2258. // UIApplication * app = [UIApplication sharedApplication];
  2259. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  2260. //
  2261. //
  2262. //
  2263. // // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  2264. // if(buttonIndex==alertView.cancelButtonIndex)
  2265. // {
  2266. //
  2267. //
  2268. //
  2269. // }
  2270. // else if(buttonIndex==1)
  2271. // {
  2272. // //open exist
  2273. //
  2274. // OrderListViewController* ovc =[ [UIStoryboard storyboardWithName:@"ERP_Mobile_Order" bundle:nil] instantiateViewControllerWithIdentifier:@"OrderListViewController"];
  2275. // ovc.showNavibar = true;
  2276. // ovc.selectOrder = ^(NSMutableDictionary* order_detail){
  2277. // if(appDelegate.order_code==nil)
  2278. // {
  2279. // [self neworderforCart];
  2280. // }
  2281. // else
  2282. // {
  2283. // self.previous_VC = self.current_VC;
  2284. // [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  2285. //
  2286. // [self checklogin:true];
  2287. //
  2288. // }
  2289. //
  2290. // };
  2291. // ovc.init_style = OL_OPEN;
  2292. // ovc.onCancel = ^(){
  2293. //
  2294. // [self checklogin:true];
  2295. //
  2296. // };
  2297. // ovc.title = @"SAVED ORDER";
  2298. // [self.navigationController pushViewController:ovc animated:true];
  2299. // }
  2300. // else
  2301. // {
  2302. // //create new;
  2303. //
  2304. // if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  2305. // {
  2306. //
  2307. // ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  2308. // cvc.showNavibar = true;
  2309. // cvc.contact_type = @"Sales_Order_Customer";
  2310. // cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  2311. //
  2312. // appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  2313. // appDelegate.customerInfo = value;
  2314. //
  2315. //
  2316. // if(appDelegate.order_code==nil)
  2317. // [self neworderforCart];
  2318. //
  2319. //
  2320. // };
  2321. //
  2322. // cvc.onCancel = ^(){
  2323. //
  2324. // [RAUtils message_box:@"" message:@"Cannot create order without customer infomation." completion:nil];
  2325. //
  2326. //
  2327. //
  2328. // };
  2329. // cvc.onReset = ^(){
  2330. // [self checklogin:true];
  2331. // };
  2332. //
  2333. // [self.navigationController pushViewController:cvc animated:true];
  2334. // }
  2335. // else
  2336. // {
  2337. // [self neworderforCart];
  2338. // }
  2339. //
  2340. // }
  2341. //}
  2342. -(void) neworderforCart
  2343. {
  2344. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Create Order" completion:^{
  2345. PopWaitAlert* pop = [RAUtils waiting_pop:@"Create Order" completion:nil];
  2346. [RANetwork request_create_order:^(NSMutableDictionary *result) {
  2347. NSMutableDictionary* return_json = result;
  2348. // [waitalert dismissViewControllerAnimated:YES completion:^{
  2349. [pop hide];
  2350. if([[return_json valueForKey:@"result"] intValue]==2)
  2351. {
  2352. int result=[[return_json valueForKey:@"result"] intValue];
  2353. if(result==2)
  2354. {
  2355. //successed.
  2356. NSString* order_code = [return_json valueForKey:@"orderCode"];
  2357. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2358. appDelegate.order_code = order_code;
  2359. appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
  2360. self.previous_VC = self.current_VC;
  2361. [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  2362. #ifdef RA_NOTIFICATION
  2363. [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2364. #else
  2365. [self reloadCart:true immediately:false];
  2366. [self reloadOrder:true immediately:false];
  2367. #endif
  2368. }
  2369. }
  2370. else
  2371. {
  2372. [RAUtils message_box:@"Add To Cart" message:[return_json valueForKey:@"err_msg"] completion:nil] ;
  2373. }
  2374. // }];
  2375. }];
  2376. // }];
  2377. }
  2378. - (void)showPriceAuth:(NSInteger)from {
  2379. }
  2380. @end