MainViewController.m 120 KB

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