MainViewController.m 142 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737
  1. //
  2. // ViewController.m
  3. // RedAnt ERP Suite
  4. //
  5. // Created by Ray on 14-5-19.
  6. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "MainViewController.h"
  9. //#import "SideMenuViewController.h"
  10. //#import "RootContainerViewController.h"
  11. #import <Accelerate/Accelerate.h>
  12. #import "PopupNavigationController.h"
  13. //#import "CommonGridViewController.h"
  14. #import "CacheViewController.h"
  15. #import "ScannerViewController.h"
  16. #import "ContactListViewController.h"
  17. #import "RAUtils.h"
  18. #import "AboutViewController.h"
  19. #import "ScannerSettingViewController.h"
  20. #import "ActiveViewController.h"
  21. #import "WebViewController.h"
  22. #import "FunctionTestViewController.h"
  23. #import "SimplifiedBuyingProgramViewController.h"
  24. #import "UserListViewController.h"
  25. #import "OfflineSettingViewController.h"
  26. #import "DefaultAppearance.h"
  27. #import "PriceSettingViewController.h"
  28. #import "JKLockController.h"
  29. #import "RASingleton.h"
  30. #import "NotificationNameCenter.h"
  31. //#import "OLOSettingViewController.h"
  32. //#import "ScanHistoryViewController.h"
  33. #import "CustomerEditViewController.h"
  34. #import "ScanOrderScanModelViewController.h"
  35. #import "ScanOrderModelListViewController.h"
  36. #import "SetupServerViewController.h"
  37. #import "ScanUserListViewController.h"
  38. @interface MainViewController ()
  39. // scan order main frame
  40. @end
  41. @implementation MainViewController
  42. -(void) logoutDocuments
  43. {
  44. // [self.pdfListViewController logout];
  45. }
  46. -(void) logoutCart
  47. {
  48. [self.cartViewController logout];
  49. RASingleton.sharedInstance.scan_cart = nil;
  50. RASingleton.sharedInstance.price_type = 0;
  51. }
  52. -(void) logoutWish
  53. {
  54. // [self.watchListViewController logout];
  55. }
  56. -(void) logoutPortfolio
  57. {
  58. // [self.portfolioViewController logout];
  59. }
  60. -(void) logoutOrder
  61. {
  62. [self.scanorderViewController logout];
  63. }
  64. -(void) logoutContact
  65. {
  66. [self.contactListViewController logout];
  67. }
  68. -(void) logoutCategory
  69. {
  70. // [self.categoryViewController logout];
  71. }
  72. - (IBAction)onScanOrderSetting:(id)sender {
  73. [self clearSelected];
  74. self.btnsetting.selected = true;
  75. if([self.current_VC isKindOfClass:[ServerSettingViewController class]])
  76. return;
  77. [self flipFromViewController:self.current_VC toViewController:self.settingViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  78. }
  79. - (IBAction)onSelectSales:(id)sender {
  80. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  81. ScanUserListViewController * userVC =[ [UIStoryboard storyboardWithName:@"OLM" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanUserListViewController"];
  82. userVC.returnValue=^(NSString* user)
  83. {
  84. // self.btnContact.hidden = false;
  85. appDelegate.user = user;
  86. [self.buttonUser setTitle:user forState:UIControlStateNormal];
  87. [self refreshContactDisplay];
  88. //
  89. };
  90. // loginvc.delegate = self;
  91. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  92. // appDelegate.active_controller = gunVC;
  93. // gunVC.onDismissVC = ^(){
  94. // appDelegate.active_controller = active_vc;
  95. // };
  96. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:userVC] ;
  97. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  98. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  99. [self presentViewController:navi animated:YES completion:^{
  100. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  101. DebugLog(@"about present.........");
  102. // self.btop = false;
  103. // <#code#>
  104. }];
  105. [appDelegate update_count_mark];
  106. // appDelegate.bLogin = true;
  107. }
  108. #ifndef RA_NOTIFICATION
  109. -(void) reloadCategory:(BOOL) update_data immediately:(bool)immediately
  110. {
  111. if(immediately)
  112. [ self.categoryViewController reload_container_getdata:update_data];
  113. else
  114. {
  115. if(update_data&&self.categoryViewController.refresh_type<=REFRESH_DATA)
  116. self.categoryViewController.refresh_type = REFRESH_DATA;
  117. else if(self.categoryViewController.refresh_type<=REFRESH_VIEW)
  118. self.categoryViewController.refresh_type = REFRESH_VIEW;
  119. }
  120. }
  121. -(void) reloadDocuments:(BOOL) update_data immediately:(bool)immediately
  122. {
  123. if(immediately)
  124. [ self.pdfListViewController reload_container_getdata:update_data];
  125. else
  126. {
  127. if(update_data&&self.pdfListViewController.refresh_type<=REFRESH_DATA)
  128. self.pdfListViewController.refresh_type = REFRESH_DATA;
  129. else if(self.pdfListViewController.refresh_type<=REFRESH_VIEW)
  130. self.pdfListViewController.refresh_type = REFRESH_VIEW;
  131. }
  132. //[self.pdfListViewController reload_container_getdata:update_data];
  133. }
  134. -(void) reloadCart:(BOOL) update_data immediately:(bool)immediately
  135. {
  136. if(immediately)
  137. [ self.cartViewController reload_container_getdata:update_data];
  138. else
  139. {
  140. if(update_data&&self.cartViewController.refresh_type<=REFRESH_DATA)
  141. self.cartViewController.refresh_type = REFRESH_DATA;
  142. else if(self.cartViewController.refresh_type<=REFRESH_VIEW)
  143. self.cartViewController.refresh_type = REFRESH_VIEW;
  144. }
  145. // [self.cartViewController reload_container_getdata:update_data];
  146. }
  147. -(void) reloadWish:(BOOL) update_data immediately:(bool)immediately
  148. {
  149. if(immediately)
  150. [ self.watchListViewController reload_container_getdata:update_data];
  151. else
  152. {
  153. if(update_data&&self.watchListViewController.refresh_type<=REFRESH_DATA)
  154. self.watchListViewController.refresh_type = REFRESH_DATA;
  155. else if(self.watchListViewController.refresh_type<=REFRESH_VIEW)
  156. self.watchListViewController.refresh_type = REFRESH_VIEW;
  157. }
  158. // [self.watchListViewController reload_container_getdata:update_data];
  159. }
  160. -(void) reloadPortfolio:(BOOL) update_data immediately:(bool)immediately
  161. {
  162. // NSMutableDictionary* dict = [NSMutableDictionary new];
  163. // dict[@"receiver"]=@[@"PortfolioViewController"];
  164. // NSString* notificationname = nil;
  165. // if(update_data)
  166. // notificationname = RA_NOTIFICATION_RELOAD_DATA;
  167. // else
  168. // notificationname = RA_NOTIFICATION_REFRESH_UI;
  169. // NSNotification *notification =[NSNotification notificationWithName:notificationname object:nil userInfo:dict];
  170. //
  171. // //通过通知中心发送通知
  172. //
  173. // [[NSNotificationCenter defaultCenter] postNotification:notification];
  174. // return;
  175. if(immediately)
  176. [ self.portfolioViewController reload_container_getdata:update_data];
  177. else
  178. {
  179. if(update_data&&self.portfolioViewController.refresh_type<=REFRESH_DATA)
  180. self.portfolioViewController.refresh_type = REFRESH_DATA;
  181. else if(self.portfolioViewController.refresh_type<=REFRESH_VIEW)
  182. self.portfolioViewController.refresh_type = REFRESH_VIEW;
  183. }
  184. // [self.portfolioViewController reload_container_getdata:update_data];
  185. }
  186. -(void) reloadOrder:(BOOL) update_data immediately:(bool)immediately
  187. {
  188. if(immediately)
  189. [ self.orderViewController reload_container_getdata:update_data];
  190. else
  191. {
  192. if(update_data&&self.orderViewController.refresh_type<=REFRESH_DATA)
  193. self.orderViewController.refresh_type = REFRESH_DATA;
  194. else if(self.orderViewController.refresh_type<=REFRESH_VIEW)
  195. self.orderViewController.refresh_type = REFRESH_VIEW;
  196. }
  197. // [self.orderViewController reload_container_getdata:update_data];
  198. }
  199. -(void) reloadContact:(BOOL) update_data immediately:(bool)immediately
  200. {
  201. //[self.con reload_container];
  202. if(immediately)
  203. [ self.contactListViewController reload_container_getdata:update_data];
  204. else
  205. {
  206. if(update_data&&self.contactListViewController.refresh_type<=REFRESH_DATA)
  207. self.contactListViewController.refresh_type = REFRESH_DATA;
  208. else if(self.contactListViewController.refresh_type<=REFRESH_VIEW)
  209. self.contactListViewController.refresh_type = REFRESH_VIEW;
  210. }
  211. }
  212. #endif
  213. -(void)viewWillLayoutSubviews
  214. {
  215. self.headerView.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.headerView.bounds].CGPath;
  216. }
  217. -(void) viewWillAppear:(BOOL)animated
  218. {
  219. [super viewWillAppear:animated];
  220. // [self.label_ccount.layer setMasksToBounds:YES];
  221. [self refreshContactDisplay];
  222. [[self navigationController] setNavigationBarHidden:YES animated:NO];
  223. }
  224. -(void) refreshContactDisplay
  225. {
  226. UIApplication * app = [UIApplication sharedApplication];
  227. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  228. // self.labelContact.text=appDelegate.contact_name;
  229. NSString * contact =[appDelegate.customerInfo valueForKey:@"customer_contact"];
  230. NSString * customer=[appDelegate.customerInfo valueForKey:@"customer_name"];
  231. NSDictionary * customerinfo=appDelegate.customerInfo;
  232. if(customerinfo==nil)
  233. {
  234. contact=@"Select Contact";
  235. [self.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  236. }
  237. // if(contact==nil||contact.length==0)
  238. // {
  239. // contact=@"No Name";
  240. // [self.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  241. // }
  242. else
  243. {
  244. if(contact==nil||contact.length==0)
  245. {
  246. contact=@"No Name";
  247. [self.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  248. }
  249. else
  250. {
  251. [self.btnContact setTitleColor:UIColorFromRGB(0x009900) forState:UIControlStateNormal];
  252. }
  253. }
  254. NSMutableArray* arr_contact = [[NSMutableArray alloc] init];
  255. if(contact.length>0)
  256. [arr_contact addObject:contact];
  257. if(customer.length>0)
  258. [arr_contact addObject:customer];
  259. NSString *contact_string = [arr_contact componentsJoinedByString:@" @"];
  260. [self.btnContact setTitle:contact_string forState:UIControlStateNormal];
  261. }
  262. - (void) checklogin:(bool) reloadCurrentVC
  263. {
  264. [self initMenuItems];
  265. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  266. self.sideMenu_UserName.text =appDelegate.user;
  267. [self.btn_sideMenu_UserName setTitle:appDelegate.user forState:UIControlStateNormal];
  268. if(appDelegate.bLogin)
  269. [self.btnLogin setTitle:@"Sign out" forState:UIControlStateNormal];
  270. else
  271. [self.btnLogin setTitle:@"Sign in" forState:UIControlStateNormal];
  272. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  273. [RANetwork LoadImage:appDelegate.user_icon into:self.user_head ];
  274. });
  275. // if(/*appDelegate.user_type==USER_ROLE_EMPLOYEE*/true)
  276. // self.btnContact.hidden = NO;
  277. // else
  278. // self.btnContact.hidden = YES;
  279. NSDictionary * customerinfo=appDelegate.customerInfo;
  280. NSString * contact=nil;
  281. NSString * customer=nil;
  282. if(customerinfo==nil)
  283. {
  284. contact=@"Select Contact";
  285. [self.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  286. }
  287. else
  288. {
  289. contact=[customerinfo valueForKey:@"customer_contact"];
  290. customer=[customerinfo valueForKey:@"customer_name"];
  291. if(contact==nil||contact.length==0)
  292. {
  293. contact=@"No Name";
  294. [self.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  295. }
  296. else
  297. {
  298. [self.btnContact setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
  299. }
  300. }
  301. // self.btnContact.hidden = !appDelegate.bLogin;// 修复登出后仍旧显示select contact
  302. NSMutableArray* arr_contact = [[NSMutableArray alloc] init];
  303. if(contact.length>0)
  304. [arr_contact addObject:contact];
  305. if(customer.length>0)
  306. [arr_contact addObject:customer];
  307. NSString *contact_string = [arr_contact componentsJoinedByString:@" @"];
  308. [self.btnContact setTitle:contact_string forState:UIControlStateNormal];
  309. // if(appDelegate.bLogin)
  310. // [self.buttonUser setTitle:appDelegate.user forState:UIControlStateNormal];
  311. // else
  312. // [self.buttonUser setTitle:@"Sign in" forState:UIControlStateNormal];
  313. #ifdef RA_NOTIFICATION
  314. [ActiveViewController Notify:@"DetailViewController,PDFListViewController,CartViewController,PortfolioViewController,WatchListViewController,OrderListViewController,OrderListViewController,ContactListViewController,CategoryViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  315. #else
  316. [self reloadDocuments:true immediately:false];
  317. [self reloadCart:true immediately:false];
  318. [self reloadPortfolio:true immediately:false];
  319. [self reloadWish:true immediately:false];
  320. [self reloadOrder:true immediately:false];
  321. [self reloadContact:true immediately:false];
  322. [self reloadCategory:true immediately:false];
  323. ActiveViewController* lrvc = (ActiveViewController*)appDelegate.active_controller;
  324. if(reloadCurrentVC)
  325. {
  326. if(lrvc!=nil)
  327. [ lrvc refresh_on_login];
  328. }
  329. else
  330. {
  331. if(lrvc.refresh_type<=REFRESH_DATA)
  332. lrvc.refresh_type = REFRESH_DATA;
  333. else if(lrvc.refresh_type<=REFRESH_VIEW)
  334. lrvc.refresh_type = REFRESH_VIEW;
  335. }
  336. #endif
  337. // [self reload];
  338. }
  339. - (IBAction)onContactClick:(id)sender {
  340. UIApplication * app = [UIApplication sharedApplication];
  341. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  342. NSString* contactid=appDelegate.contact_id ;
  343. if(contactid==nil)
  344. {
  345. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  346. CustomerEditViewController * cuseditVC = [[CustomerEditViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  347. cuseditVC.bnewcustomer=true;
  348. cuseditVC.bolocustomer = true;
  349. cuseditVC.url_type = URL_FILE;
  350. cuseditVC.request_url=[OLDataProvider scanTemplatePath:@"scan_contact.json"];;
  351. cuseditVC.params = params;
  352. cuseditVC.returnValue=^(NSMutableDictionary* value)
  353. {
  354. if(value == nil)
  355. {
  356. return; //canceled
  357. }
  358. NSString* contact_id=[[NSUUID new] UUIDString];
  359. value[@"business_card"] = value[@"customer_cid"];
  360. NSArray*arr =[RAConvertor string2arr:value[@"business_card"] separator:@","];
  361. for(int l=0;l<arr.count;l++)
  362. {
  363. value[[NSString stringWithFormat:@"business_card_%d",l]]=arr[l];
  364. }
  365. //---------------- construct customer_contact----------------------
  366. NSString* customer_first_name = [value valueForKey:@"customer_first_name"];
  367. if(customer_first_name==nil)
  368. customer_first_name=@"";
  369. NSString* customer_last_name= [value valueForKey:@"customer_last_name"];
  370. if(customer_last_name==nil)
  371. customer_last_name=@"";
  372. NSString* customer_contact = [NSString stringWithFormat:@"%@ %@",customer_first_name,customer_last_name];
  373. customer_contact=[customer_contact stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
  374. [value setValue:customer_contact forKey:@"customer_contact"];
  375. value [@"customer_cid"] = contact_id;
  376. appDelegate.contact_id=contact_id;
  377. appDelegate.customerInfo = value;
  378. };
  379. [[self navigationController] setNavigationBarHidden:NO animated:NO];
  380. [self.navigationController pushViewController:cuseditVC animated:false];
  381. }
  382. else
  383. {
  384. CustomerInfoViewController * vc = [[CustomerInfoViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  385. vc.url_type = URL_FILE;
  386. // if(appDelegate.order_code.length>0)
  387. {
  388. vc.edit_icon = false;
  389. vc.assig_icon = true;
  390. vc.reset_icon = true;
  391. vc.request_url=[OLDataProvider scanTemplatePath:@"scan_contact.json"];
  392. }
  393. // else
  394. // {
  395. // vc.edit_icon = false;
  396. // vc.assig_icon = false;
  397. // vc.reset_icon = true;
  398. // vc.request_url=LOCAL_URL_CUSTOMER_INFO_EDITOR;
  399. // }
  400. // NSDictionary* dd=appDelegate.customerInfo;;
  401. vc.data_init = appDelegate.customerInfo;
  402. vc.update_order = true;
  403. vc.contactId=contactid;
  404. // vc.delegate = self;
  405. vc.returnValue = ^(NSMutableDictionary* value){
  406. if(value==nil)
  407. {
  408. //reset
  409. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  410. {
  411. [OLDataProvider deleteScanOrder:appDelegate.order_code];
  412. [appDelegate closeOrder];
  413. //
  414. // [self prepareReturn:nil];
  415. [self.navigationController popViewControllerAnimated:true];
  416. [((MainViewController*)appDelegate.main_vc) switchToOrder];
  417. return;
  418. }
  419. }
  420. else
  421. {
  422. value[@"business_card"] = value[@"business_card"];
  423. NSArray*arr =[RAConvertor string2arr:value[@"business_card"] separator:@","];
  424. for(int l=0;l<arr.count;l++)
  425. {
  426. value[[NSString stringWithFormat:@"business_card_%d",l]]=arr[l];
  427. }
  428. //---------------- construct customer_contact----------------------
  429. NSString* customer_first_name = [value valueForKey:@"customer_first_name"];
  430. if(customer_first_name==nil)
  431. customer_first_name=@"";
  432. NSString* customer_last_name= [value valueForKey:@"customer_last_name"];
  433. if(customer_last_name==nil)
  434. customer_last_name=@"";
  435. NSString* customer_contact = [NSString stringWithFormat:@"%@ %@",customer_first_name,customer_last_name];
  436. customer_contact=[customer_contact stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
  437. [value setValue:customer_contact forKey:@"customer_contact"];
  438. value [@"customer_cid"] = appDelegate.customerInfo[@"customer_cid"];
  439. // appDelegate.contact_id=contact_id;
  440. appDelegate.customerInfo = value;
  441. }
  442. // appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  443. // appDelegate.customerInfo = value;
  444. };
  445. [self.navigationController pushViewController:vc animated:true];
  446. }
  447. }
  448. -(void) clearSelected
  449. {
  450. self.btncart.selected = false;
  451. self.btnorder.selected = false;
  452. self.btnlist.selected = false;
  453. self.btnsearch.selected = false;
  454. self.btnsetting.selected = false;
  455. }
  456. - (void)viewDidLoad
  457. {
  458. [super viewDidLoad];
  459. // NSLog(@"decrypt:%@",[AESCrypt fastdecrypt:@"vafHUwfRPIUbPNVnKhLc5aAVK7sOFRztlfJVRHW7QVa/qGgm11E5UwfYWZEBTQpH"]);
  460. [self.btncart setBackgroundImage:[UIImage imageNamed:@"btn_bg"] forState:UIControlStateSelected];
  461. [self.btnorder setBackgroundImage:[UIImage imageNamed:@"btn_bg"] forState:UIControlStateSelected];
  462. [self.btnlist setBackgroundImage:[UIImage imageNamed:@"btn_bg"] forState:UIControlStateSelected];
  463. [self.btnsearch setBackgroundImage:[UIImage imageNamed:@"btn_bg"] forState:UIControlStateSelected];
  464. [self.btnsetting setBackgroundImage:[UIImage imageNamed:@"btn_bg"] forState:UIControlStateSelected];
  465. // [self.btncart setTintColor:UIColor.whiteColor];
  466. // self.btncart.configuration.baseForegroundColor = UIColor.redColor;
  467. // [self.btncart updateConfiguration];
  468. // [self.btncart setBackgroundImage:[UIImage imageNamed:@"btn_bg"] forState:UIControlStateHighlighted];
  469. NSDictionary *addressDic = [[NSUserDefaults standardUserDefaults] valueForKey:@"ScanAddress"];
  470. if (addressDic) {
  471. self.labelServer.text = [addressDic objectForKey:@"show_name"];
  472. // NSUInteger selectedIndex = [[addressDic objectForKey:@"selectedIndex"] integerValue];
  473. // switch (selectedIndex) {
  474. // case 0:
  475. // case 1: {
  476. // [self internalCheckBtnClick:self.internalCheckBtn];
  477. // }
  478. // break;
  479. // case 2: {
  480. // [self externalCheckBtnClick:self.externalCheckBtn];
  481. // }
  482. // break;
  483. //
  484. // default:
  485. // break;
  486. // }
  487. }
  488. // self.btnContact.hidden = NO;
  489. self.automaticallyAdjustsScrollViewInsets = NO;
  490. NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultColor" valuename:@"labelcolor"];
  491. if(value==nil)
  492. value=@"";
  493. unsigned long frontcolor = strtoul([value UTF8String],0,16);
  494. [self.labelSo setTextColor:UIColorFromRGB(frontcolor)];
  495. float vx =[[DefaultAppearance get_noneappearance_value:@"MainLogo" valuename:@"x"] floatValue];
  496. float vy =[[DefaultAppearance get_noneappearance_value:@"MainLogo" valuename:@"y"] floatValue];
  497. float vwidth =[[DefaultAppearance get_noneappearance_value:@"MainLogo" valuename:@"width"] floatValue];
  498. float vheight =[[DefaultAppearance get_noneappearance_value:@"MainLogo" valuename:@"height"] floatValue];
  499. self.btn_LogoHome.frame = CGRectMake(vx, vy, vwidth, vheight);
  500. float mvx =[[DefaultAppearance get_noneappearance_value:@"ModePos" valuename:@"x"] floatValue];
  501. float mvy =[[DefaultAppearance get_noneappearance_value:@"ModePos" valuename:@"y"] floatValue];
  502. float mvwidth =[[DefaultAppearance get_noneappearance_value:@"ModePos" valuename:@"width"] floatValue];
  503. float mvheight =[[DefaultAppearance get_noneappearance_value:@"ModePos" valuename:@"height"] floatValue];
  504. self.labelMode.frame = CGRectMake(mvx, mvy, mvwidth, mvheight);
  505. self.label_ccount.layer.cornerRadius=10.5;
  506. self.label_ccount.layer.masksToBounds=true;
  507. self.label_wcount.layer.cornerRadius=10.5;
  508. self.label_wcount.layer.masksToBounds=true;
  509. self.label_cccount.layer.cornerRadius=10.5;
  510. self.label_cccount.layer.masksToBounds=true;
  511. self.label_cwcount.layer.cornerRadius=10.5;
  512. self.label_cwcount.layer.masksToBounds=true;
  513. self.employee_bp.hidden = false;
  514. // self.customer_bp.hidden = true;
  515. UIApplication * app = [UIApplication sharedApplication];
  516. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  517. appDelegate.main_vc = self;
  518. [appDelegate update_count_mark];
  519. NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  520. NSString* build =[infoDict objectForKey:@"CFBundleVersion"];
  521. NSString* version =[infoDict objectForKey:@"CFBundleShortVersionString"];
  522. //#ifdef BUILD_HMLG
  523. // NSString* versionNum = [NSString stringWithFormat:@"HMLG %@ Build %@",version,build];
  524. //#endif
  525. //#if defined(BUILD_NPD) || defined(BUILD_USAI)
  526. // NSString* versionNum = [NSString stringWithFormat:@"npd %@ Build %@",version,build];
  527. //#endif
  528. //#ifdef BUILD_HOMER
  529. NSString* versionNum = [NSString stringWithFormat:@"%@ %@ Build %@",COMPANY_SHORT_NAME,version,build];
  530. //#endif
  531. [self initMenuItems];
  532. self.homeViewController =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanHomeViewController"];
  533. // self.categoryViewController =[ [UIStoryboard storyboardWithName:@"ERP_Mobile_Search" bundle:nil] instantiateViewControllerWithIdentifier:@"CategoryViewController"];
  534. self.settingViewController=[ [UIStoryboard storyboardWithName:@"OLM" bundle:nil] instantiateViewControllerWithIdentifier:@"ServerSettingViewController"];
  535. self.cartViewController =[[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"CartViewController"];
  536. __block MainViewController *brself= self;
  537. self.scanorderViewController =[[UIStoryboard storyboardWithName:@"ERP_Mobile_Order" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanOrderListViewController"];
  538. self.contactListViewController = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  539. self.contactListViewController.contact_type = @"Sales_Order_Customer";
  540. self.contactListViewController.edit_icon = true;
  541. self.contactListViewController.assig_icon = true;
  542. self.contactListViewController.reset_icon = false;
  543. self.contactListViewController.ui_type = CONTACT_LIST;
  544. self.contactListViewController.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  545. appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  546. appDelegate.customerInfo = value;
  547. [brself refreshContactDisplay];
  548. [brself switchToCart:nil];
  549. // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  550. //
  551. // if(self.returnValue)
  552. // self.returnValue(value);
  553. };
  554. //Capturing strongly warring;
  555. self.scanHistoryViewController =[[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanHistoryViewController"];
  556. // self.portfolioViewController = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Portfolio" bundle:nil] instantiateViewControllerWithIdentifier:@"PortfolioViewController" ];
  557. // [self addChildViewController:self.scanHistoryViewController];
  558. // self.pdfListViewController = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Portfolio" bundle:nil] instantiateViewControllerWithIdentifier:@"PortfolioListViewController" ];
  559. // self.itemSearchViewController=[[UIStoryboard storyboardWithName:@"ERP_Mobile_Search" bundle:nil] instantiateViewControllerWithIdentifier:@"ItemSearchViewController"];
  560. self.scansearchViewController=[ [UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanSearchViewController"];
  561. [self addChildViewController:self.homeViewController]; //1
  562. self.homeViewController.view.frame = self.container.bounds;
  563. [self.container addSubview:self.homeViewController.view]; //2
  564. [self.homeViewController didMoveToParentViewController:self];
  565. self.current_VC = self.homeViewController;
  566. // [self addChildViewController:self.scanorderViewController]; //1
  567. //
  568. // self.scanorderViewController.view.frame = self.container.bounds;
  569. // [self.container addSubview:self.scanorderViewController.view]; //2
  570. // [self.scanorderViewController didMoveToParentViewController:self];
  571. // self.current_VC = self.scanorderViewController;
  572. // // self.is_home = true;
  573. // [UIBezierPath bezierPathWithRect:self.headerView.bounds].CGPath;
  574. self.headerView.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.headerView.bounds].CGPath;
  575. self.headerView.layer.masksToBounds = false;
  576. //添加四个边阴影
  577. self.headerView.layer.shadowColor = [UIColor blackColor].CGColor;
  578. self.headerView.layer.shadowOffset = CGSizeMake(0, 0);
  579. self.headerView.layer.shadowOpacity = 0.5;
  580. self.headerView.layer.shadowRadius = 2.0;
  581. self.labelVer.text=versionNum;
  582. [self initAppDelegate]; // 初始化scan order 参数
  583. // UIApplication * app = [UIApplication sharedApplication];
  584. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  585. // Do any additional setup after loading the view, typically from a nib.
  586. // SetupServerViewController * servervc =[[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"SetupServerViewController"];
  587. // [self.navigationController pushViewController:servervc animated:true];
  588. }
  589. - (IBAction)onmenuButtonClicked:(id)sender {
  590. self.openMenuButton.hidden = true;
  591. self.sideMenu.hidden = false;
  592. [self showMenu];
  593. }
  594. - (IBAction)switchMenu:(UIButton *)sender {
  595. // if(self.menuShown==true)
  596. [self hideMenu];
  597. self.openMenuButton.hidden = false;
  598. self.sideMenu.hidden = true;
  599. // else
  600. // [self showMenu];
  601. }
  602. -(void) Loginout:(bool)showlogin
  603. {
  604. UIApplication * app = [UIApplication sharedApplication];
  605. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  606. if(appDelegate.bLogin)
  607. {
  608. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Sign out" completion:^{
  609. [RANetwork request_logout:^(NSMutableDictionary *result) {
  610. NSMutableDictionary* return_json =result;
  611. [waitalert dismissViewControllerAnimated:YES completion:^{
  612. if([[return_json valueForKey:@"result"] intValue]==2)
  613. {
  614. // [self hideMenu];
  615. // [self switchToHome:nil];
  616. [appDelegate Logout];
  617. [self checklogin :false];
  618. if(showlogin)
  619. {
  620. LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  621. loginvc.returnValue = ^(bool blogin){
  622. [self checklogin :true];
  623. };
  624. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  625. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  626. [self presentViewController:navi animated:YES completion:^{
  627. DebugLog(@"login present.........");
  628. }];
  629. }
  630. }
  631. else
  632. {
  633. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Sign Out" controller:self] ;
  634. }
  635. }];
  636. }];
  637. }];
  638. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  639. //
  640. // NSDictionary* return_json = [RANetwork logout];
  641. //
  642. // dispatch_async(dispatch_get_main_queue(), ^{
  643. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  644. //
  645. //
  646. // if([[return_json valueForKey:@"result"] intValue]==2)
  647. // {
  648. //// [self hideMenu];
  649. //// [self switchToHome:nil];
  650. // [appDelegate Logout];
  651. // [self checklogin :false];
  652. // if(showlogin)
  653. // {
  654. // LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  655. // loginvc.returnValue = ^(bool blogin){
  656. //
  657. // [self checklogin :true];
  658. //
  659. // };
  660. //
  661. // UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  662. //
  663. //
  664. //
  665. //
  666. //
  667. //
  668. // navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  669. // [self presentViewController:navi animated:YES completion:^{
  670. //
  671. // DebugLog(@"login present.........");
  672. //
  673. // }];
  674. // }
  675. // }
  676. // else
  677. // {
  678. // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Sign Out" controller:self] ;
  679. // }
  680. //
  681. //
  682. //
  683. //
  684. // });
  685. // });
  686. }
  687. else
  688. {
  689. LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  690. loginvc.returnValue = ^(bool blogin){
  691. [self checklogin :true];
  692. };
  693. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  694. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  695. [self presentViewController:navi animated:YES completion:^{
  696. DebugLog(@"login present.........");
  697. }];
  698. }
  699. }
  700. - (IBAction)onUserListClick:(id)sender {
  701. UIApplication * app = [UIApplication sharedApplication];
  702. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  703. if(!appDelegate.bLogin)
  704. return;
  705. UserListViewController * vc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"UserListViewController"];
  706. vc.returnValue = ^(bool blogin){
  707. if(blogin==false)
  708. {
  709. LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  710. loginvc.returnValue = ^(bool blogin){
  711. [self checklogin :true];
  712. };
  713. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  714. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  715. [self presentViewController:navi animated:YES completion:^{
  716. DebugLog(@"login present.........");
  717. }];
  718. }
  719. };
  720. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  721. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  722. [self presentViewController:navi animated:YES completion:^{
  723. DebugLog(@"login present.........");
  724. }];
  725. }
  726. - (IBAction)OnLoginClick:(UIButton *)sender {
  727. [self Loginout:true];
  728. }
  729. - (IBAction)onScanClick:(id)sender {
  730. ScannerViewController * scannerVC =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ScannerViewController"];
  731. // LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  732. // ScanOrderScanModelViewController *scanresult = [[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanOrderScanModelViewController"];
  733. ScanOrderModelListViewController* scanresult = [[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanOrderModelListViewController"];
  734. scannerVC.resultvc = scanresult;
  735. [self.navigationController pushViewController:scannerVC animated:true];
  736. }
  737. - (IBAction)switchToSearch:(UIButton *)sender {
  738. [self clearSelected];
  739. self.btnsearch.selected = true;
  740. if([self.current_VC isKindOfClass:[ScanSearchViewController class]])
  741. return;
  742. [self flipFromViewController:self.current_VC toViewController:self.scansearchViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  743. }
  744. //- (IBAction)switchToList:(UIButton *)sender {
  745. // [self switchtowishlist];
  746. //}
  747. - (IBAction)switchToList:(UIButton *)sender {
  748. [self clearSelected];
  749. self.btnlist.selected = true;
  750. [self switchtowishlist];
  751. }
  752. -(void)switchtowishlist
  753. {
  754. if([self.current_VC isKindOfClass:[ScanHistoryViewController class]])
  755. return;
  756. // if([self.current_VC isKindOfClass:[OrderListViewController class]])
  757. // return;
  758. // UIApplication * app = [UIApplication sharedApplication];
  759. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  760. // if(appDelegate.bLogin==false)
  761. // {
  762. // LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  763. // // loginvc.delegate = self;
  764. // // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  765. //
  766. // loginvc.returnValue = ^(bool blogin){
  767. //
  768. //
  769. // if(blogin)
  770. // {
  771. // [self checklogin:true];
  772. //
  773. //
  774. // [self flipFromViewController:self.current_VC toViewController:self.watchListViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  775. // }
  776. //
  777. //
  778. // };
  779. //
  780. // UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  781. //
  782. //
  783. //
  784. //
  785. //
  786. // // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  787. //
  788. // navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  789. // [self presentViewController:navi animated:YES completion:^{
  790. //
  791. // // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  792. //
  793. // DebugLog(@"LoginViewController present.........");
  794. //
  795. // // self.btop = false;
  796. // // <#code#>
  797. // }];
  798. // }
  799. // else
  800. [self flipFromViewController:self.current_VC toViewController:self.scanHistoryViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  801. }
  802. - (IBAction)switchToContact:(UIButton *)sender {
  803. [self switchtocontact];
  804. }
  805. -(void)switchtocontact
  806. {
  807. if([self.current_VC isKindOfClass:[ContactListViewController class]])
  808. return;
  809. UIApplication * app = [UIApplication sharedApplication];
  810. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  811. if(appDelegate.bLogin==false)
  812. {
  813. LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  814. // loginvc.delegate = self;
  815. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  816. loginvc.returnValue = ^(bool blogin){
  817. if(blogin)
  818. {
  819. [self checklogin:true];
  820. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  821. {
  822. [self flipFromViewController:self.current_VC toViewController:self.contactListViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  823. }
  824. else
  825. {
  826. [RAUtils message_alert:@"Customer Login does not support this feature." title:@"Contact List" controller:self] ;
  827. }
  828. }
  829. };
  830. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  831. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  832. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  833. [self presentViewController:navi animated:YES completion:^{
  834. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  835. DebugLog(@"LoginViewController present.........");
  836. // self.btop = false;
  837. // <#code#>
  838. }];
  839. }
  840. else
  841. [self flipFromViewController:self.current_VC toViewController:self.contactListViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  842. }
  843. - (void) reload
  844. {
  845. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  846. return;
  847. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  848. //
  849. //
  850. // NSDictionary* category=[RANetwork request_Cagegory];
  851. //
  852. // dispatch_async(dispatch_get_main_queue(), ^{
  853. //
  854. // if([[category valueForKey:@"result"] intValue]==2)
  855. // {
  856. // appDelegate.categoryMenu = category;
  857. // }
  858. // else
  859. // {
  860. // // [RAUtils error_alert:[category valueForKey:@"err_msg"]] ;
  861. // }
  862. //
  863. // });
  864. // });
  865. }
  866. - (IBAction)onUserButtonClick:(id)sender {
  867. DebugLog(@"header view login");
  868. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  869. if( appDelegate.user ==nil /*|| [appDelegate.user isEqualToString:@"GUEST"]*/)
  870. {
  871. // appDelegate.user = nil;
  872. // appDelegate.password = nil;
  873. LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  874. // loginvc.delegate = self;
  875. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  876. loginvc.returnValue = ^(bool blogin){
  877. [self checklogin:true];
  878. };
  879. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  880. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  881. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  882. [self presentViewController:navi animated:YES completion:^{
  883. // <#code#>
  884. }];
  885. }
  886. else
  887. {
  888. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Sign Out" message:@"" preferredStyle:UIAlertControllerStyleAlert];
  889. UIAlertAction *action_1 = [UIAlertAction actionWithTitle:@"Sign Out" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  890. //open exist
  891. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  892. appDelegate.cart_count = 0;//[[jsobj :@"cart_count"] intValue];
  893. appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  894. appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  895. [appDelegate update_count_mark];
  896. appDelegate.can_show_price =false;
  897. appDelegate.can_see_price =false;
  898. appDelegate.can_create_portfolio =false;
  899. appDelegate.can_create_order =false;
  900. appDelegate.can_cancel_order =false;
  901. appDelegate.can_set_cart_price =false;
  902. appDelegate.can_delete_order =false;
  903. appDelegate.can_submit_order =false;
  904. appDelegate.can_set_tearsheet_price =false;
  905. appDelegate.can_update_contact_info = false;
  906. appDelegate.save_order_logout = false;
  907. appDelegate.submit_order_logout = false;
  908. appDelegate.alert_sold_in_quantities = false;
  909. appDelegate.ipad_perm =nil ;
  910. appDelegate.user_type = USER_ROLE_UNKNOWN;
  911. appDelegate.OrderFilter= nil;
  912. [appDelegate SetSo:nil];
  913. [appDelegate set_main_button_panel];
  914. #ifdef RA_NOTIFICATION
  915. [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
  916. #endif
  917. [appDelegate Logout];
  918. }];
  919. UIAlertAction *action_2 = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  920. //create new;
  921. }];
  922. [alertController addAction:action_1];
  923. [alertController addAction:action_2];
  924. [self presentViewController:alertController animated:YES completion:nil];
  925. }
  926. }
  927. #pragma mark - LoginViewControllerDelegate
  928. -(void)LoginViewControllerDidLogin:(LoginViewController *)viewController
  929. {
  930. [viewController dismissViewControllerAnimated:YES completion:^{
  931. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  932. self.sideMenu_UserName.text =appDelegate.user;
  933. [self.btn_sideMenu_UserName setTitle:appDelegate.user forState:UIControlStateNormal];
  934. [self.btnLogin setTitle:@"Sign out" forState:UIControlStateNormal];
  935. [RANetwork LoadImage:appDelegate.user_icon into:self.user_head ];
  936. // if(/*appDelegate.user_type==USER_ROLE_EMPLOYEE*/true)
  937. // self.btnContact.hidden = NO;
  938. // else
  939. // self.btnContact.hidden = YES;
  940. NSDictionary * customerinfo=appDelegate.customerInfo;
  941. NSString * contact=nil;
  942. NSString * customer=nil;
  943. if(customerinfo==nil)
  944. {
  945. contact=@"Select Contact";
  946. [self.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  947. }
  948. else
  949. {
  950. contact=[customerinfo valueForKey:@"customer_contact"];
  951. customer=[customerinfo valueForKey:@"customer_name"];
  952. if(contact==nil||contact.length==0)
  953. {
  954. contact=@"No Name";
  955. [self.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  956. }
  957. else
  958. {
  959. [self.btnContact setTitleColor:UIColorFromRGB(0x009900) forState:UIControlStateNormal];
  960. }
  961. }
  962. NSMutableArray* arr_contact = [[NSMutableArray alloc] init];
  963. if(contact.length>0)
  964. [arr_contact addObject:contact];
  965. if(customer.length>0)
  966. [arr_contact addObject:customer];
  967. NSString *contact_string = [arr_contact componentsJoinedByString:@" @"];
  968. [self.btnContact setTitle:contact_string forState:UIControlStateNormal];
  969. // [self.buttonUser setTitle:appDelegate.user forState:UIControlStateNormal];
  970. [self reload];
  971. }];
  972. }
  973. - (void) flipFromViewController:(UIViewController*) fromController
  974. toViewController:(UIViewController*) toController
  975. withDirection:(UIViewAnimationOptions) direction
  976. {
  977. toController.view.frame = self.container.bounds; // 1
  978. // UIViewAutoresizingFlexibleLeftMargin = 1 << 0,
  979. // UIViewAutoresizingFlexibleWidth = 1 << 1,
  980. // UIViewAutoresizingFlexibleRightMargin = 1 << 2,
  981. // UIViewAutoresizingFlexibleTopMargin = 1 << 3,
  982. // UIViewAutoresizingFlexibleHeight = 1 << 4,
  983. // UIViewAutoresizingFlexibleBottomMargin = 1 << 5
  984. toController.view.autoresizingMask = UIViewAutoresizingFlexibleHeight |UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin;
  985. NSLog(@"MAIN VIEWCONTROLLER CHILD COUNT %lu",(unsigned long)self.childViewControllers.count);
  986. [self addChildViewController:toController]; //
  987. [fromController willMoveToParentViewController:nil]; //
  988. [self transitionFromViewController:fromController
  989. toViewController:toController
  990. duration:0.0
  991. options:direction | UIViewAnimationOptionCurveEaseIn
  992. animations:nil
  993. completion:^(BOOL finished) {
  994. [toController didMoveToParentViewController:self]; // 2
  995. [fromController removeFromParentViewController]; // 3
  996. self.current_VC = toController;
  997. // if([fromController isKindOfClass:[HomeViewController class]])
  998. // {
  999. // // [[NSNotificationCenter defaultCenter] postNotificationName:CYCLESCROLL_STOPTIMMER object:nil];
  1000. // // self.homeViewController = nil;
  1001. //
  1002. // }
  1003. }];
  1004. }
  1005. -(void)topicViewSelected:(int) type _id: (int) _id
  1006. {
  1007. // [self switchToCagegory:nil];
  1008. // if(type==0)
  1009. // {
  1010. // // [self.categoryViewController showDetailat:_id];
  1011. // }
  1012. // else
  1013. // {
  1014. // [self.categoryViewController showCategory];
  1015. //
  1016. // }
  1017. }
  1018. -(void)categoryMenuSelected:(NSString*)_id
  1019. {
  1020. [self switchToCagegory:_id];
  1021. // [self.categoryViewController showCategory];
  1022. }
  1023. //- (void)switchToItemSearch:(NSString* )coverttype {
  1024. //
  1025. //
  1026. // self.itemSearchViewController.default_filter = nil;
  1027. // self.itemSearchViewController.covertype = coverttype;
  1028. // self.itemSearchViewController.saved_covertype = coverttype;
  1029. //
  1030. //
  1031. //
  1032. // self.itemSearchViewController.p_available = nil;
  1033. // self.itemSearchViewController.p_price = nil;
  1034. // self.itemSearchViewController.p_QTY = nil;
  1035. // self.itemSearchViewController.p_bestseller = nil;
  1036. //#ifdef RA_NOTIFICATION
  1037. // [ActiveViewController Notify:@"ItemSearchViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1038. //#else
  1039. // [self.itemSearchViewController reload_container_getdata:true];
  1040. //#endif
  1041. //
  1042. // if([self.current_VC isKindOfClass:[ItemSearchViewController class]])
  1043. //
  1044. // return;
  1045. // [self flipFromViewController:self.current_VC toViewController:self.itemSearchViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1046. //
  1047. // [[self navigationController] setNavigationBarHidden:YES animated:NO];
  1048. //
  1049. //
  1050. // // self.is_home = false;
  1051. // // self.current_vc = VC_CATEGORY;
  1052. // // [self.homeViewController willMoveToParentViewController:nil]; //1
  1053. // // [self.homeViewController.view removeFromSuperview]; //2
  1054. // // [self.homeViewController removeFromParentViewController]; //3
  1055. // //
  1056. // // [self.container addSubview:self.cagegoryViewController.view]; //2
  1057. // // [self.cagegoryViewController didMoveToParentViewController:self];
  1058. //}
  1059. //- (void)switchToCagegory:(NSString* )categoryid {
  1060. // // NSString* ttt =[@"Category" stringByAppendingString:[self categoryString:categoryid node:self.categoryMenu level:0]];
  1061. //
  1062. //
  1063. // UIApplication * app = [UIApplication sharedApplication];
  1064. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1065. // #if defined(BUILD_UWAVER)
  1066. // self.categoryViewController.categoryString = [@"Collections" stringByAppendingString:[self categoryString:categoryid node:appDelegate.categoryMenu level:0]];
  1067. //#else
  1068. // self.categoryViewController.categoryString = [@"Category" stringByAppendingString:[self categoryString:categoryid node:appDelegate.categoryMenu level:0]];
  1069. //#endif
  1070. //
  1071. // self.categoryViewController.cagegoryLabel.text =self.categoryViewController.categoryString;
  1072. // self.categoryViewController.categoryid = categoryid ;
  1073. // self.categoryViewController.loadall=false;
  1074. //// self.categoryViewController.collectionview
  1075. // self.categoryViewController.p_alert = nil;
  1076. // self.categoryViewController.p_available = nil;
  1077. // self.categoryViewController.p_price = nil;
  1078. // self.categoryViewController.p_QTY = nil;
  1079. // self.categoryViewController.p_bestseller = nil;
  1080. //
  1081. // self.categoryViewController.modelname = nil;
  1082. // self.categoryViewController.modeldescrip = nil;
  1083. //#ifdef RA_NOTIFICATION
  1084. // [ActiveViewController Notify:@"CategoryViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1085. //#else
  1086. // [self.categoryViewController reload_container_getdata:true];
  1087. //#endif
  1088. //
  1089. // [self.categoryViewController showCategory];
  1090. // if([self.current_VC isKindOfClass:[CategoryViewController class]])
  1091. //
  1092. // return;
  1093. // [self flipFromViewController:self.current_VC toViewController:self.categoryViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1094. //
  1095. // [[self navigationController] setNavigationBarHidden:YES animated:NO];
  1096. //
  1097. //
  1098. // // self.is_home = false;
  1099. // // self.current_vc = VC_CATEGORY;
  1100. // // [self.homeViewController willMoveToParentViewController:nil]; //1
  1101. // // [self.homeViewController.view removeFromSuperview]; //2
  1102. // // [self.homeViewController removeFromParentViewController]; //3
  1103. // //
  1104. // // [self.container addSubview:self.cagegoryViewController.view]; //2
  1105. // // [self.cagegoryViewController didMoveToParentViewController:self];
  1106. //}
  1107. - (IBAction)switchToHome:(UIButton *)sender {
  1108. [self clearSelected];
  1109. [self switchToHome];
  1110. // self.current_vc = VC_HOME;
  1111. // self.is_home = true;
  1112. //
  1113. // [self.cagegoryViewController willMoveToParentViewController:nil]; //1
  1114. // [self.cagegoryViewController.view removeFromSuperview]; //2
  1115. // [self.cagegoryViewController removeFromParentViewController]; //3
  1116. //
  1117. // [self.container addSubview:self.homeViewController.view]; //2
  1118. // [self.homeViewController didMoveToParentViewController:self];
  1119. }
  1120. -(void)switchToHome
  1121. {
  1122. [self clearSelected];
  1123. if([self.current_VC isKindOfClass:[ScanHomeViewController class]])
  1124. return;
  1125. if(self.homeViewController == nil)
  1126. {
  1127. self.homeViewController =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanHomeViewController"];
  1128. self.homeViewController.view.frame = self.container.bounds;
  1129. }
  1130. [self flipFromViewController:self.current_VC toViewController:self.homeViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1131. }
  1132. -(void) switchToPreviousVC
  1133. {
  1134. if(self.previous_VC==nil)
  1135. return;
  1136. if([self.current_VC isKindOfClass:[self.previous_VC class]])
  1137. return;
  1138. [self flipFromViewController:self.current_VC toViewController:self.previous_VC withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1139. }
  1140. - (IBAction)switchToCart:(UIButton *)sender {
  1141. // [self.btncart setBackgroundColor:UIColor.whiteColor];
  1142. // [self.btncart setTintColor:UIColor.clearColor];
  1143. // UIColor *color0=[self.btncart titleColorForState:UIControlStateNormal];
  1144. // UIColor *color1=[self.btncart titleColorForState:UIControlStateSelected];
  1145. [self switchToCart];
  1146. // self.current_vc = VC_HOME;
  1147. }
  1148. -(void) switchToCart
  1149. {
  1150. if([self.current_VC isKindOfClass:[CartViewController class]])
  1151. return;
  1152. [self clearSelected];
  1153. self.btncart.selected = true;
  1154. //
  1155. //
  1156. // UIApplication * app = [UIApplication sharedApplication];
  1157. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1158. // // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  1159. // if(appDelegate.bLogin==false&& !RASingleton.sharedInstance.enable_OfflineOrder)
  1160. // {
  1161. //
  1162. // LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  1163. // // loginvc.delegate = self;
  1164. // // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1165. //
  1166. // loginvc.returnValue = ^(bool blogin){
  1167. //
  1168. //
  1169. // // UIApplication * app = [UIApplication sharedApplication];
  1170. // // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1171. //
  1172. //
  1173. //
  1174. //
  1175. // if(blogin)
  1176. // {
  1177. // if(/*appDelegate.user_type==USER_ROLE_EMPLOYEE*/true)
  1178. // {
  1179. //
  1180. // [self checklogin:false];
  1181. // if(appDelegate.can_create_order)
  1182. // {
  1183. //
  1184. // NSString* msg =@"";
  1185. // if(appDelegate.contact_id.length>0)
  1186. // {
  1187. // msg = [msg stringByAppendingString:@"\n\nCustomer:"];
  1188. // msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
  1189. //
  1190. // }
  1191. //
  1192. // UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Switch To Cart" message:msg preferredStyle:UIAlertControllerStyleAlert];
  1193. //
  1194. // UIAlertAction *action_1 = [UIAlertAction actionWithTitle:@"Check for saved order" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  1195. // //open exist
  1196. //
  1197. // ScanOrderListViewController* ovc =[ [UIStoryboard storyboardWithName:@"ERP_Mobile_Order" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanOrderListViewController"];
  1198. // ovc.showNavibar = true;
  1199. // ovc.selectOrder = ^(NSMutableDictionary* order_detail){
  1200. // if(appDelegate.order_code==nil)
  1201. // {
  1202. // [self neworderforCart];
  1203. // }
  1204. // else
  1205. // {
  1206. // self.previous_VC = self.current_VC;
  1207. // [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1208. //
  1209. // [self checklogin:true];
  1210. //
  1211. // }
  1212. //
  1213. // };
  1214. //// ovc.init_style = OL_OPEN;
  1215. // ovc.onCancel = ^(){
  1216. //
  1217. // [self checklogin:true];
  1218. //
  1219. // };
  1220. // ovc.title = @"SAVED ORDER";
  1221. // [self.navigationController pushViewController:ovc animated:true];
  1222. // }];
  1223. // UIAlertAction *action_2 = [UIAlertAction actionWithTitle:@"Create new order" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1224. // //create new;
  1225. //
  1226. // if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  1227. // {
  1228. //
  1229. // ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  1230. // cvc.showNavibar = true;
  1231. // cvc.contact_type = @"Sales_Order_Customer";
  1232. // cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1233. //
  1234. // appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  1235. // appDelegate.customerInfo = value;
  1236. //
  1237. //
  1238. // if(appDelegate.order_code==nil)
  1239. // [self neworderforCart];
  1240. //
  1241. //
  1242. // };
  1243. //
  1244. // cvc.onCancel = ^(){
  1245. //
  1246. // [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"" controller:self];
  1247. //
  1248. //
  1249. //
  1250. // };
  1251. // cvc.onReset = ^(){
  1252. // [self checklogin:true];
  1253. // };
  1254. //
  1255. // [self.navigationController pushViewController:cvc animated:true];
  1256. // }
  1257. // else
  1258. // {
  1259. // [self neworderforCart];
  1260. // }
  1261. //
  1262. // }];
  1263. // UIAlertAction *action_3 = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  1264. //
  1265. //
  1266. //
  1267. // }];
  1268. //
  1269. // [alertController addAction:action_1];
  1270. // [alertController addAction:action_2];
  1271. // [alertController addAction:action_3];
  1272. //
  1273. //
  1274. // [self presentViewController:alertController animated:YES completion:nil];
  1275. //// 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];
  1276. ////
  1277. ////
  1278. ////
  1279. //// // alert.
  1280. //// [alert show];
  1281. // }
  1282. // else
  1283. // {
  1284. //
  1285. // UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Switch To Cart" message:@"Do you want to switch to a pending order?" preferredStyle:UIAlertControllerStyleAlert];
  1286. //
  1287. //
  1288. // UIAlertAction *action_2 = [UIAlertAction actionWithTitle:@"Check for saved order" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1289. // //open exist
  1290. //
  1291. // ScanOrderListViewController* ovc =[ [UIStoryboard storyboardWithName:@"ERP_Mobile_Order" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanOrderListViewController"];
  1292. // ovc.showNavibar = true;
  1293. // ovc.selectOrder = ^(NSMutableDictionary* order_detail){
  1294. // if(appDelegate.order_code==nil)
  1295. // {
  1296. // [self neworderforCart];
  1297. // }
  1298. // else
  1299. // {
  1300. // self.previous_VC = self.current_VC;
  1301. // [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1302. //
  1303. // [self checklogin:true];
  1304. //
  1305. // }
  1306. //
  1307. // };
  1308. //// ovc.init_style = OL_OPEN;
  1309. // ovc.onCancel = ^(){
  1310. //
  1311. // [self checklogin:true];
  1312. //
  1313. // };
  1314. // ovc.title = @"SAVED ORDER";
  1315. // [self.navigationController pushViewController:ovc animated:true];
  1316. // }];
  1317. // UIAlertAction *action_3 = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  1318. //
  1319. //
  1320. //
  1321. // }];
  1322. //
  1323. //
  1324. // [alertController addAction:action_2];
  1325. // [alertController addAction:action_3];
  1326. //
  1327. //
  1328. // [self presentViewController:alertController animated:YES completion:nil];
  1329. //
  1330. //
  1331. //// 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];
  1332. ////
  1333. //// // alert.
  1334. //// [alert show];
  1335. // }
  1336. // }
  1337. //// else
  1338. //// {
  1339. //// [self checklogin:true];
  1340. //// self.previous_VC = self.current_VC;
  1341. //// [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1342. //// }
  1343. // }
  1344. //
  1345. // // self.offset = 0;
  1346. // // [self.content_data removeAllObjects];
  1347. // // [self loadpage];
  1348. // //
  1349. // // [[self navigationController] setNavigationBarHidden:YES animated:NO];
  1350. //
  1351. // };
  1352. //
  1353. // UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  1354. //
  1355. //
  1356. //
  1357. //
  1358. //
  1359. // // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1360. //
  1361. // navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  1362. // [self presentViewController:navi animated:YES completion:^{
  1363. //
  1364. // // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1365. //
  1366. // DebugLog(@"LoginViewController present.........");
  1367. //
  1368. // // self.btop = false;
  1369. // // <#code#>
  1370. // }];
  1371. // }
  1372. // else
  1373. // {
  1374. //// if(/*appDelegate.user_type==USER_ROLE_EMPLOYEE&&/*appDelegate.contact_id==nil&&*/appDelegate.order_code==nil)
  1375. // if(appDelegate.order_code==nil)
  1376. // {
  1377. //// [self checklogin:false];
  1378. // if(appDelegate.can_create_order)
  1379. // {
  1380. // NSString* msg =@"";
  1381. // if(appDelegate.contact_id.length>0)
  1382. // {
  1383. // msg = [msg stringByAppendingString:@"\n\nCustomer:"];
  1384. // msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
  1385. //
  1386. // }
  1387. //
  1388. // UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Switch To Cart" message:msg preferredStyle:UIAlertControllerStyleAlert];
  1389. //
  1390. // UIAlertAction *action_1 = [UIAlertAction actionWithTitle:@"Check for saved order" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  1391. // //open exist
  1392. //
  1393. // ScanOrderListViewController* ovc =[ [UIStoryboard storyboardWithName:@"ERP_Mobile_Order" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanOrderListViewController"];
  1394. // ovc.showNavibar = true;
  1395. // ovc.selectOrder = ^(NSMutableDictionary* order_detail){
  1396. // if(appDelegate.order_code==nil)
  1397. // {
  1398. // [self neworderforCart];
  1399. // }
  1400. // else
  1401. // {
  1402. // self.previous_VC = self.current_VC;
  1403. // [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1404. //
  1405. // [self checklogin:true];
  1406. //
  1407. // }
  1408. //
  1409. // };
  1410. //// ovc.init_style = OL_OPEN;
  1411. // ovc.onCancel = ^(){
  1412. //
  1413. // [self checklogin:true];
  1414. //
  1415. // };
  1416. // ovc.title = @"SAVED ORDER";
  1417. // [self.navigationController pushViewController:ovc animated:true];
  1418. // }];
  1419. // UIAlertAction *action_2 = [UIAlertAction actionWithTitle:@"Create new order" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1420. // //create new;
  1421. //
  1422. // if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  1423. // {
  1424. //
  1425. // ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  1426. // cvc.showNavibar = true;
  1427. // cvc.contact_type = @"Sales_Order_Customer";
  1428. // cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1429. //
  1430. // appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  1431. // appDelegate.customerInfo = value;
  1432. //
  1433. //
  1434. // if(appDelegate.order_code==nil)
  1435. // [self neworderforCart];
  1436. //
  1437. //
  1438. // };
  1439. //
  1440. // cvc.onCancel = ^(){
  1441. //
  1442. // [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"" controller:self];
  1443. //
  1444. //
  1445. //
  1446. // };
  1447. // cvc.onReset = ^(){
  1448. // [self checklogin:true];
  1449. // };
  1450. //
  1451. // [self.navigationController pushViewController:cvc animated:true];
  1452. // }
  1453. // else
  1454. // {
  1455. // [self neworderforCart];
  1456. // }
  1457. //
  1458. // }];
  1459. // UIAlertAction *action_3 = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  1460. //
  1461. //
  1462. //
  1463. // }];
  1464. //
  1465. // [alertController addAction:action_1];
  1466. // [alertController addAction:action_2];
  1467. // [alertController addAction:action_3];
  1468. //
  1469. //
  1470. // [self presentViewController:alertController animated:YES completion:nil];
  1471. //
  1472. //
  1473. //// 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];
  1474. ////
  1475. //// // alert.
  1476. //// [alert show];
  1477. // }
  1478. // else
  1479. // {
  1480. // UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Switch To Cart" message:@"Do you want to switch to a pending order?" preferredStyle:UIAlertControllerStyleAlert];
  1481. //
  1482. //
  1483. // UIAlertAction *action_2 = [UIAlertAction actionWithTitle:@"Switch to pending order" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1484. // //open exist
  1485. //
  1486. // ScanOrderListViewController* ovc =[ [UIStoryboard storyboardWithName:@"ERP_Mobile_Order" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanOrderListViewController"];
  1487. // ovc.showNavibar = true;
  1488. // ovc.selectOrder = ^(NSMutableDictionary* order_detail){
  1489. // if(appDelegate.order_code==nil)
  1490. // {
  1491. // [self neworderforCart];
  1492. // }
  1493. // else
  1494. // {
  1495. // self.previous_VC = self.current_VC;
  1496. // [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1497. //
  1498. // [self checklogin:true];
  1499. //
  1500. // }
  1501. //
  1502. // };
  1503. //// ovc.init_style = OL_OPEN;
  1504. // ovc.onCancel = ^(){
  1505. //
  1506. // [self checklogin:true];
  1507. //
  1508. // };
  1509. // ovc.title = @"SAVED ORDER";
  1510. // [self.navigationController pushViewController:ovc animated:true];
  1511. // }];
  1512. // UIAlertAction *action_3 = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  1513. //
  1514. //
  1515. //
  1516. // }];
  1517. //
  1518. //
  1519. // [alertController addAction:action_2];
  1520. // [alertController addAction:action_3];
  1521. //
  1522. //
  1523. // [self presentViewController:alertController animated:YES completion:nil];
  1524. //
  1525. //// 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];
  1526. ////
  1527. //// // alert.
  1528. //// [alert show];
  1529. // }
  1530. // }
  1531. // else
  1532. // {
  1533. //
  1534. // self.previous_VC = self.current_VC;
  1535. // [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1536. //
  1537. //
  1538. //
  1539. // }
  1540. // }
  1541. //
  1542. self.previous_VC = self.current_VC;
  1543. [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1544. }
  1545. -(void) switchToOrder
  1546. {
  1547. [self clearSelected];
  1548. self.btnorder.selected = true;
  1549. if([self.current_VC isKindOfClass:[ScanOrderListViewController class]])
  1550. return;
  1551. UIApplication * app = [UIApplication sharedApplication];
  1552. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1553. [self flipFromViewController:self.current_VC toViewController:self.scanorderViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1554. }
  1555. - (IBAction)switchToOrder:(id)sender {
  1556. [self switchToOrder];
  1557. }
  1558. #pragma mark - CategoryMenuDelegate
  1559. -(void)SelectCategory:(NSString *)category
  1560. {
  1561. [self switchToCagegory:category];
  1562. }
  1563. -(NSString*) categoryString:(NSString*) categoryid node:(NSDictionary*) json level:(int) level;
  1564. {
  1565. if(categoryid.length==0)
  1566. return @">All Products>";
  1567. //NSString* idString = [NSString stringWithFormat:@"%d",categoryid];
  1568. NSString* categoryString =@">";
  1569. int count = [[json valueForKey:@"count"] intValue];
  1570. for(int i=0;i<count;i++)
  1571. {
  1572. NSDictionary * category_json = [json objectForKey:[NSString stringWithFormat:@"category_%d",i]];
  1573. NSString* cid = [category_json valueForKey:@"id"] ;
  1574. // NSString* ttt =[categoryid substringToIndex:2+level*2];
  1575. // NSString * qqq =[cid substringToIndex:2+level*2];
  1576. // NSString *ds1=[categoryid substringToIndex:3+level*3];
  1577. // NSString*ds2 = [cid substringToIndex:3+level*3];
  1578. if(cid.length<3+level*3)
  1579. continue;
  1580. if(categoryid.length<3+level*3)
  1581. continue;
  1582. if([[categoryid substringToIndex:3+level*3] isEqualToString: [cid substringToIndex:3+level*3]])
  1583. {
  1584. //categoryString = [categoryString stringByAppendingString:@">"];
  1585. categoryString =[categoryString stringByAppendingString: [category_json valueForKey:@"title" ] ];
  1586. categoryString = [categoryString stringByAppendingString:[ self categoryString:categoryid node:category_json level:level+1]];
  1587. break;
  1588. }
  1589. }
  1590. return categoryString;
  1591. }
  1592. - (void)didReceiveMemoryWarning
  1593. {
  1594. [super didReceiveMemoryWarning];
  1595. // Dispose of any resources that can be recreated.
  1596. }
  1597. - (IBAction)openMenu:(UIButton *)sender {
  1598. [self showMenu];
  1599. }
  1600. - (UIImage*)screen_shot
  1601. {
  1602. // CGRect r = self.view.frame;
  1603. // CGRect r1 = self.view.bounds;
  1604. // double width,height;
  1605. //
  1606. // UIInterfaceOrientation orientation =[UIApplication sharedApplication].statusBarOrientation;
  1607. // ;
  1608. // if(orientation == UIDeviceOrientationLandscapeLeft ||orientation == UIDeviceOrientationLandscapeRight)
  1609. // {
  1610. // width = self.view.frame.size.width>self.view.frame.size.height? self.view.frame.size.width:self.view.frame.size.height;
  1611. // height =self.view.frame.size.width<self.view.frame.size.height? self.view.frame.size.width:self.view.frame.size.height;
  1612. // }
  1613. // else
  1614. // {
  1615. // width = self.view.frame.size.width<self.view.frame.size.height? self.view.frame.size.width:self.view.frame.size.height;
  1616. // height =self.view.frame.size.width>self.view.frame.size.height? self.view.frame.size.width:self.view.frame.size.height;
  1617. // }
  1618. UIGraphicsBeginImageContext(CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height));
  1619. [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
  1620. UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
  1621. UIGraphicsEndImageContext();
  1622. return viewImage;
  1623. }
  1624. - (IBAction)onhideMenuClick:(id)sender {
  1625. [self hideMenu];
  1626. self.backgroundButton.hidden=true;
  1627. self.openMenuButton.hidden = false;
  1628. self.sideMenu.hidden = true;
  1629. }
  1630. - (void)hideMenu
  1631. {
  1632. CGRect frame ;
  1633. frame.origin.x = -300;
  1634. frame.origin.y = 0;
  1635. frame.size.height = self.view.bounds.size.height;
  1636. frame.size.width = 364;
  1637. self.sideMenu.frame=frame;
  1638. self.sideMenu.hidden = true;
  1639. self.blurView.alpha = 0;
  1640. [self.menuButton setImage:[UIImage imageNamed:@"menu_open"] forState:UIControlStateNormal];
  1641. self.menuShown = false;
  1642. self.backgroundButton.hidden=true;
  1643. self.openMenuButton.hidden = false;
  1644. }
  1645. - (void)showMenu
  1646. {
  1647. [self.sideMenuTable reloadData];
  1648. UIImage* imgsource = [self screen_shot];
  1649. self.blurView.alpha = 0;
  1650. UIImage* imgBlur =[self applyBlurWithRadius:5 sourceImage:imgsource tintColor:[UIColor colorWithWhite:0.2 alpha:0.73] saturationDeltaFactor:1.8 maskImage:nil];
  1651. self.blurView.image = imgBlur;
  1652. // self.blurView.hidden = imgBlur;
  1653. // [self.sideMenu becomeFirstResponder];
  1654. self.sideMenu.hidden = false;
  1655. self.backgroundButton.hidden=false;
  1656. CGRect frame ;
  1657. frame.origin.x = 0;
  1658. frame.origin.y = 0;
  1659. frame.size.height = self.view.bounds.size.height;
  1660. frame.size.width = 364;
  1661. // [UIView animateWithDuration:1.0 animations:^{ self.sideMenu.frame=frame;
  1662. // self.blurView.alpha = 1;
  1663. // [self.menuButton setImage:[UIImage imageNamed:@"menu"] forState:UIControlStateNormal];
  1664. //
  1665. // }];
  1666. [UIView animateWithDuration:0.5 animations:^{ self.sideMenu.frame=frame;
  1667. self.blurView.alpha = 1;
  1668. }
  1669. completion:^(BOOL finished) {
  1670. [self.menuButton setImage:[UIImage imageNamed:@"menu"] forState:UIControlStateNormal];
  1671. }];
  1672. // UIImage* img= [UIImage imageNamed:@"menu"];
  1673. // self.menuButton.imageView.image = nil;
  1674. self.menuShown = true;
  1675. }
  1676. -(void)initMenuItems
  1677. {
  1678. UIApplication * app = [UIApplication sharedApplication];
  1679. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1680. self.sideMenuItems = [[NSMutableArray alloc] init];
  1681. NSMutableDictionary* map = [[NSMutableDictionary alloc] init];
  1682. if(appDelegate.user!=nil)
  1683. {
  1684. [map setValue:@"Wish List" forKey:@"title"];
  1685. [map setValue:@"rect_market_news" forKey:@"img"];
  1686. [self.sideMenuItems addObject:map.copy];
  1687. }
  1688. #if !defined(BUILD_HOMER) && !defined(BUILD_GATIT)
  1689. //#ifndef BUILD_HOMER //homer 要求去掉cam scan 2017/12/20
  1690. // if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  1691. {
  1692. [map setValue:@"Cam Scan" forKey:@"title"];
  1693. [map setValue:@"rect_contact_list" forKey:@"img"];
  1694. [self.sideMenuItems addObject:map.copy];
  1695. }
  1696. #endif
  1697. if(appDelegate.user_type==USER_ROLE_EMPLOYEE || (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeCustomer))
  1698. {
  1699. // [map setValue:@"Contact" forKey:@"title"];
  1700. // [map setValue:@"rect_contact_list" forKey:@"img"];
  1701. // [self.sideMenuItems addObject:map.copy];
  1702. //#ifdef BUILD_UWAVER
  1703. // [map setValue:@"Hang Tag" forKey:@"title"];
  1704. //#else
  1705. [map setValue:@"Portfolio" forKey:@"title"];
  1706. //#endif
  1707. [map setValue:@"rect_market_news" forKey:@"img"];
  1708. [self.sideMenuItems addObject:map.copy];
  1709. //#ifdef BUILD_UWAVER
  1710. // [map setValue:@"View Hang Tags" forKey:@"title"];
  1711. //#else
  1712. [map setValue:@"View Portfolios" forKey:@"title"];
  1713. //#endif
  1714. [map setValue:@"rect_pdf_list" forKey:@"img"];
  1715. [self.sideMenuItems addObject:map.copy];
  1716. }
  1717. if(appDelegate.can_show_price)
  1718. {
  1719. if(appDelegate.price_hidden)
  1720. [map setValue:@"Show Price" forKey:@"title"];
  1721. else
  1722. [map setValue:@"Hide Price" forKey:@"title"];
  1723. [map setValue:@"rect_announcements" forKey:@"img"];
  1724. [self.sideMenuItems addObject:map.copy];
  1725. }
  1726. // [map setValue:@"Contact" forKey:@"title"];
  1727. // [map setValue:@"rect_market_news" forKey:@"img"];
  1728. // [self.sideMenuItems addObject:map.copy];
  1729. // [map setValue:@"Cache" forKey:@"title"];
  1730. // [map setValue:@"rect_announcements" forKey:@"img"];
  1731. //[self.sideMenuItems addObject:map.copy];
  1732. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  1733. // [map setValue:@"Message" forKey:@"title"];
  1734. // [map setValue:@"rect_search_history" forKey:@"img"];
  1735. // [self.sideMenuItems addObject:map.copy];
  1736. //
  1737. #if defined(BUILD_NPD)
  1738. [map setValue:@"Scanner Setting" forKey:@"title"];
  1739. [map setValue:@"rect_change_password" forKey:@"img"];
  1740. [self.sideMenuItems addObject:map.copy];
  1741. # endif
  1742. #if defined(SCANNER_ORDER)
  1743. [map setValue:@"Scanner Order" forKey:@"title"];
  1744. [map setValue:@"rect_change_password" forKey:@"img"];
  1745. [self.sideMenuItems addObject:map.copy];
  1746. # endif
  1747. #if defined(BUILD_NPD)|| defined (BUILD_CONTRAST)
  1748. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  1749. {
  1750. [map setValue:@"Offline Setting" forKey:@"title"];
  1751. [map setValue:@"rect_market_news" forKey:@"img"];
  1752. [self.sideMenuItems addObject:map.copy];
  1753. }
  1754. #endif
  1755. if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore ) {
  1756. [map setValue:@"Price Setting" forKey:@"title"];
  1757. // [map setValue:@"rect_market_news" forKey:@"img"];
  1758. [self.sideMenuItems addObject:map.copy];
  1759. }
  1760. if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore ) {
  1761. if ([RASingleton sharedInstance].global_lock) {
  1762. [map setValue:@"Unlock" forKey:@"title"];
  1763. } else {
  1764. [map setValue:@"Lock" forKey:@"title"];
  1765. }
  1766. [self.sideMenuItems addObject:map.copy];
  1767. }
  1768. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  1769. /*
  1770. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  1771. {
  1772. [map setValue:@"Offline Setting" forKey:@"title"];
  1773. [map setValue:@"rect_market_news" forKey:@"img"];
  1774. [self.sideMenuItems addObject:map.copy];
  1775. }
  1776. */
  1777. // if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER) {
  1778. // [map setValue:@"Price Setting" forKey:@"title"];
  1779. // // [map setValue:@"rect_market_news" forKey:@"img"];
  1780. // [self.sideMenuItems addObject:map.copy];
  1781. // }
  1782. if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore ) {
  1783. if ([Singleton sharedInstance].global_lock) {
  1784. [map setValue:@"Unlock" forKey:@"title"];
  1785. } else {
  1786. [map setValue:@"Lock" forKey:@"title"];
  1787. }
  1788. [self.sideMenuItems addObject:map.copy];
  1789. }
  1790. # endif
  1791. #ifdef DEBUG
  1792. // if([[appDelegate.user lowercaseString] isEqualToString:@"larryl"]||[[appDelegate.user lowercaseString] isEqualToString:@"arpithat"])
  1793. {
  1794. // [map setValue:@"Contact" forKey:@"title"];
  1795. // [map setValue:@"rect_contact_list" forKey:@"img"];
  1796. // [self.sideMenuItems addObject:map.copy];
  1797. [map setValue:@"Function Test" forKey:@"title"];
  1798. [map setValue:@"rect_market_news" forKey:@"img"];
  1799. [self.sideMenuItems addObject:map.copy];
  1800. }
  1801. #endif
  1802. [map setValue:@"Privacy Policy" forKey:@"title"];
  1803. [map setValue:@"rect_change_password" forKey:@"img"];
  1804. [self.sideMenuItems addObject:map.copy];
  1805. [map setValue:@"About us" forKey:@"title"];
  1806. [map setValue:@"rect_change_password" forKey:@"img"];
  1807. [self.sideMenuItems addObject:map.copy];
  1808. #ifdef BUILD_HMLG
  1809. [map setValue:@"Homelegance Website" forKey:@"title"];
  1810. [map setValue:@"rect_change_password" forKey:@"img"];
  1811. [self.sideMenuItems addObject:map.copy];
  1812. #endif
  1813. #if defined(BUILD_NPD)
  1814. [map setValue:@"BLOG" forKey:@"title"];
  1815. [map setValue:@"rect_change_password" forKey:@"img"];
  1816. [self.sideMenuItems addObject:map.copy];
  1817. [map setValue:[NSString stringWithFormat:@"%@ Website",COMPANY_SHORT_NAME] forKey:@"title"];
  1818. [map setValue:@"rect_change_password" forKey:@"img"];
  1819. [self.sideMenuItems addObject:map.copy];
  1820. [map setValue:[NSString stringWithFormat:@"%@ Policy",COMPANY_SHORT_NAME] forKey:@"title"];
  1821. [map setValue:@"rect_change_password" forKey:@"img"];
  1822. [self.sideMenuItems addObject:map.copy];
  1823. [map setValue:@"Simplified Buying Program" forKey:@"title"];
  1824. [map setValue:@"rect_change_password" forKey:@"img"];
  1825. [self.sideMenuItems addObject:map.copy];
  1826. #endif
  1827. #ifdef BUILD_USAI
  1828. // [map setValue:@"BLOG" forKey:@"title"];
  1829. // [map setValue:@"rect_change_password" forKey:@"img"];
  1830. // [self.sideMenuItems addObject:map.copy];
  1831. [map setValue:@"USAI Website" forKey:@"title"];
  1832. [map setValue:@"rect_change_password" forKey:@"img"];
  1833. [self.sideMenuItems addObject:map.copy];
  1834. #endif
  1835. #ifdef BUILD_HOMER
  1836. /*
  1837. [map setValue:@"BLOG" forKey:@"title"];
  1838. [map setValue:@"rect_change_password" forKey:@"img"];
  1839. [self.sideMenuItems addObject:map.copy];
  1840. */
  1841. [map setValue:@"HOMER Website" forKey:@"title"];
  1842. [map setValue:@"rect_change_password" forKey:@"img"];
  1843. [self.sideMenuItems addObject:map.copy];
  1844. #endif
  1845. #ifdef BUILD_GATIT
  1846. [map setValue:@"TITAN Website" forKey:@"title"];
  1847. [map setValue:@"rect_change_password" forKey:@"img"];
  1848. [self.sideMenuItems addObject:map.copy];
  1849. # endif
  1850. [self.sideMenuTable reloadData];
  1851. //
  1852. }
  1853. - (UIImage *)applyBlurWithRadius:(CGFloat)blurRadius sourceImage:(UIImage*)sourceImage tintColor:(UIColor *)tintColor saturationDeltaFactor:(CGFloat)saturationDeltaFactor maskImage:(UIImage *)maskImage
  1854. {
  1855. // Check pre-conditions.
  1856. if (sourceImage.size.width < 1 || sourceImage.size.height < 1) {
  1857. DebugLog (@"*** error: invalid size: (%.2f x %.2f). Both dimensions must be >= 1: %@", sourceImage.size.width, sourceImage.size.height, self);
  1858. return nil;
  1859. }
  1860. if (!sourceImage.CGImage) {
  1861. DebugLog (@"*** error: image must be backed by a CGImage: %@", self);
  1862. return nil;
  1863. }
  1864. if (maskImage && !maskImage.CGImage) {
  1865. DebugLog (@"*** error: maskImage must be backed by a CGImage: %@", maskImage);
  1866. return nil;
  1867. }
  1868. CGRect imageRect = { CGPointZero, sourceImage.size };
  1869. UIImage *effectImage = sourceImage;
  1870. BOOL hasBlur = blurRadius > __FLT_EPSILON__;
  1871. BOOL hasSaturationChange = fabs(saturationDeltaFactor - 1.) > __FLT_EPSILON__;
  1872. if (hasBlur || hasSaturationChange) {
  1873. UIGraphicsBeginImageContextWithOptions(sourceImage.size, NO, [[UIScreen mainScreen] scale]);
  1874. CGContextRef effectInContext = UIGraphicsGetCurrentContext();
  1875. CGContextScaleCTM(effectInContext, 1.0, -1.0);
  1876. CGContextTranslateCTM(effectInContext, 0, -sourceImage.size.height);
  1877. CGContextDrawImage(effectInContext, imageRect, sourceImage.CGImage);
  1878. vImage_Buffer effectInBuffer;
  1879. effectInBuffer.data = CGBitmapContextGetData(effectInContext);
  1880. effectInBuffer.width = CGBitmapContextGetWidth(effectInContext);
  1881. effectInBuffer.height = CGBitmapContextGetHeight(effectInContext);
  1882. effectInBuffer.rowBytes = CGBitmapContextGetBytesPerRow(effectInContext);
  1883. UIGraphicsBeginImageContextWithOptions(sourceImage.size, NO, [[UIScreen mainScreen] scale]);
  1884. CGContextRef effectOutContext = UIGraphicsGetCurrentContext();
  1885. vImage_Buffer effectOutBuffer;
  1886. effectOutBuffer.data = CGBitmapContextGetData(effectOutContext);
  1887. effectOutBuffer.width = CGBitmapContextGetWidth(effectOutContext);
  1888. effectOutBuffer.height = CGBitmapContextGetHeight(effectOutContext);
  1889. effectOutBuffer.rowBytes = CGBitmapContextGetBytesPerRow(effectOutContext);
  1890. if (hasBlur) {
  1891. // A description of how to compute the box kernel width from the Gaussian
  1892. // radius (aka standard deviation) appears in the SVG spec:
  1893. // http://www.w3.org/TR/SVG/filters.html#feGaussianBlurElement
  1894. //
  1895. // For larger values of 's' (s >= 2.0), an approximation can be used: Three
  1896. // successive box-blurs build a piece-wise quadratic convolution kernel, which
  1897. // approximates the Gaussian kernel to within roughly 3%.
  1898. //
  1899. // let d = floor(s * 3*sqrt(2*pi)/4 + 0.5)
  1900. //
  1901. // ... if d is odd, use three box-blurs of size 'd', centered on the output pixel.
  1902. //
  1903. CGFloat inputRadius = blurRadius * [[UIScreen mainScreen] scale];
  1904. NSUInteger radius = floor(inputRadius * 3. * sqrt(2 * M_PI) / 4 + 0.5);
  1905. if (radius % 2 != 1) {
  1906. radius += 1; // force radius to be odd so that the three box-blur methodology works.
  1907. }
  1908. vImageBoxConvolve_ARGB8888(&effectInBuffer, &effectOutBuffer, NULL, 0, 0, (unsigned int)radius, (unsigned int)radius, 0, kvImageEdgeExtend);
  1909. vImageBoxConvolve_ARGB8888(&effectOutBuffer, &effectInBuffer, NULL, 0, 0, (unsigned int)radius, (unsigned int)radius, 0, kvImageEdgeExtend);
  1910. vImageBoxConvolve_ARGB8888(&effectInBuffer, &effectOutBuffer, NULL, 0, 0, (unsigned int)radius, (unsigned int)radius, 0, kvImageEdgeExtend);
  1911. }
  1912. BOOL effectImageBuffersAreSwapped = NO;
  1913. if (hasSaturationChange) {
  1914. CGFloat s = saturationDeltaFactor;
  1915. CGFloat floatingPointSaturationMatrix[] = {
  1916. 0.0722 + 0.9278 * s, 0.0722 - 0.0722 * s, 0.0722 - 0.0722 * s, 0,
  1917. 0.7152 - 0.7152 * s, 0.7152 + 0.2848 * s, 0.7152 - 0.7152 * s, 0,
  1918. 0.2126 - 0.2126 * s, 0.2126 - 0.2126 * s, 0.2126 + 0.7873 * s, 0,
  1919. 0, 0, 0, 1,
  1920. };
  1921. const int32_t divisor = 256;
  1922. NSUInteger matrixSize = sizeof(floatingPointSaturationMatrix)/sizeof(floatingPointSaturationMatrix[0]);
  1923. int16_t saturationMatrix[matrixSize];
  1924. for (NSUInteger i = 0; i < matrixSize; ++i) {
  1925. saturationMatrix[i] = (int16_t)roundf(floatingPointSaturationMatrix[i] * divisor);
  1926. }
  1927. if (hasBlur) {
  1928. vImageMatrixMultiply_ARGB8888(&effectOutBuffer, &effectInBuffer, saturationMatrix, divisor, NULL, NULL, kvImageNoFlags);
  1929. effectImageBuffersAreSwapped = YES;
  1930. }
  1931. else {
  1932. vImageMatrixMultiply_ARGB8888(&effectInBuffer, &effectOutBuffer, saturationMatrix, divisor, NULL, NULL, kvImageNoFlags);
  1933. }
  1934. }
  1935. if (!effectImageBuffersAreSwapped)
  1936. effectImage = UIGraphicsGetImageFromCurrentImageContext();
  1937. UIGraphicsEndImageContext();
  1938. if (effectImageBuffersAreSwapped)
  1939. effectImage = UIGraphicsGetImageFromCurrentImageContext();
  1940. UIGraphicsEndImageContext();
  1941. }
  1942. // Set up output context.
  1943. UIGraphicsBeginImageContextWithOptions(sourceImage.size, NO, [[UIScreen mainScreen] scale]);
  1944. CGContextRef outputContext = UIGraphicsGetCurrentContext();
  1945. CGContextScaleCTM(outputContext, 1.0, -1.0);
  1946. CGContextTranslateCTM(outputContext, 0, -sourceImage.size.height);
  1947. // Draw base image.
  1948. CGContextDrawImage(outputContext, imageRect, sourceImage.CGImage);
  1949. // Draw effect image.
  1950. if (hasBlur) {
  1951. CGContextSaveGState(outputContext);
  1952. if (maskImage) {
  1953. CGContextClipToMask(outputContext, imageRect, maskImage.CGImage);
  1954. }
  1955. CGContextDrawImage(outputContext, imageRect, effectImage.CGImage);
  1956. CGContextRestoreGState(outputContext);
  1957. }
  1958. // Add in color tint.
  1959. if (tintColor) {
  1960. CGContextSaveGState(outputContext);
  1961. CGContextSetFillColorWithColor(outputContext, tintColor.CGColor);
  1962. CGContextFillRect(outputContext, imageRect);
  1963. CGContextRestoreGState(outputContext);
  1964. }
  1965. // Output image is ready.
  1966. UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext();
  1967. UIGraphicsEndImageContext();
  1968. return outputImage;
  1969. }
  1970. //- (IBAction)openMenu:(UIButton *)sender {
  1971. //}
  1972. #pragma mark - Table view data source
  1973. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  1974. {
  1975. return 1;
  1976. }
  1977. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  1978. {
  1979. return self.sideMenuItems.count;
  1980. }
  1981. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  1982. {
  1983. UIApplication * app = [UIApplication sharedApplication];
  1984. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1985. NSString *CellIdentifier = @"SideMenuItem";
  1986. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1987. NSString* title = [self.sideMenuItems[indexPath.row] valueForKey:@"title"];
  1988. cell.backgroundColor = [UIColor clearColor];
  1989. // [cell.backgroundColor:[UIColor clearColor]];
  1990. // UIImageView* iv= [[UIImageView alloc] initWithImage:];
  1991. cell.textLabel.text = title;
  1992. cell.detailTextLabel.textColor =[UIColor redColor];
  1993. if([title isEqualToString:@"Wish List"]&&appDelegate.wish_count>0)
  1994. cell.detailTextLabel.text = [NSString stringWithFormat:@"%ld",appDelegate.wish_count];
  1995. else if(([title isEqualToString:@"Portfolio"] || [title isEqualToString:@"Hang Tag"])&&appDelegate.port_count>0)
  1996. cell.detailTextLabel.text = [NSString stringWithFormat:@"%ld",appDelegate.port_count];
  1997. else
  1998. {
  1999. cell.detailTextLabel.text =nil;
  2000. }
  2001. // cell.imageView.image = [UIImage imageNamed:[self.toolsinfo[indexPath.row] valueForKey:@"img"]];
  2002. return cell;
  2003. }
  2004. #ifdef SCANNER_ORDER
  2005. //#pragma mark - Offline Order
  2006. //-(void) CreateOfflineOrder
  2007. //{
  2008. //
  2009. // RASingleton.sharedInstance.enable_OfflineOrder = true;
  2010. //
  2011. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2012. // __block MainViewController *brself= self;
  2013. // if(appDelegate.contact_id.length<=0)
  2014. // {
  2015. //
  2016. // UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"New Offline Order" message:nil preferredStyle:UIAlertControllerStyleAlert];
  2017. // UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"With Offline Contact" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  2018. //
  2019. //// if(appDelegate.order_code && appDelegate.order_code.length>0)
  2020. //// {
  2021. //// [RAUtils message_alert:@"Please close current order and try again." title:@"" controller:self];
  2022. //// }
  2023. //// NSLog(@"new click");
  2024. //
  2025. // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  2026. //
  2027. //// NSString *path = [[NSBundle mainBundle] pathForResource:@"editContact.json" ofType:nil];
  2028. //
  2029. // CustomerEditViewController * cuseditVC = [[CustomerEditViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  2030. // cuseditVC.bnewcustomer=true;
  2031. // cuseditVC.bolocustomer = true;
  2032. // cuseditVC.url_type = URL_LOCAL;
  2033. // cuseditVC.request_url=URL_SO_NEW_CONTACT;
  2034. //
  2035. // cuseditVC.params = params;
  2036. //
  2037. // cuseditVC.returnValue=^(NSMutableDictionary* value)
  2038. // {
  2039. // if(value==nil)
  2040. // {
  2041. // [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"" controller:self];
  2042. // }
  2043. // else
  2044. // {
  2045. // NSString* contact_id=[[NSUUID new] UUIDString];
  2046. //
  2047. //
  2048. //
  2049. //
  2050. //
  2051. //
  2052. // value [@"customer_cid"] = contact_id;
  2053. // appDelegate.contact_id=contact_id;
  2054. // appDelegate.customerInfo = value;
  2055. // [brself refreshContactDisplay];
  2056. // [self newoloorder];
  2057. //// [brself switchToCart:nil];
  2058. //
  2059. // }
  2060. // };
  2061. //
  2062. //
  2063. // // cuseditVC.delegate=self;
  2064. // //
  2065. // // if(checked.count==count)
  2066. // // {
  2067. // // orderinfoVC.have_tail = true
  2068. // // }
  2069. //
  2070. // [[self navigationController] setNavigationBarHidden:NO animated:NO];
  2071. // [self.navigationController pushViewController:cuseditVC animated:false];
  2072. //
  2073. //// [self dismissViewControllerAnimated:NO completion:^{
  2074. ////// [(UINavigationController*)[self parentViewController] pushViewController:cuseditVC animated:false];;
  2075. ////// [[self navigationController] setNavigationBarHidden:NO animated:NO];
  2076. ////
  2077. ////// [self pushViewController:cuseditVC animated:false];
  2078. //// }];
  2079. //
  2080. //// [[self navigationController] setNavigationBarHidden:NO animated:NO];
  2081. //// [self.navigationController pushViewController:cuseditVC animated:false];
  2082. //
  2083. //
  2084. // }];
  2085. //
  2086. // UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"With Online Contact" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  2087. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2088. //
  2089. // if(appDelegate.order_code && appDelegate.order_code.length>0)
  2090. // {
  2091. // // appDelegate.order_code= nil;
  2092. // // [appDelegate SetSo:nil];
  2093. //
  2094. //
  2095. // // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  2096. // ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  2097. // cvc.showNavibar = true;
  2098. // cvc.contact_type = @"Sales_Order_Customer";
  2099. // cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  2100. //
  2101. // appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  2102. // appDelegate.customerInfo = value;
  2103. //
  2104. //// self.norefresh = true;
  2105. // [self newoloorder];
  2106. //
  2107. //
  2108. //
  2109. // // [main_vc checklogin:true];
  2110. // // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  2111. //
  2112. // //
  2113. // // if(self.returnValue)
  2114. // // self.returnValue(value);
  2115. // };
  2116. //
  2117. // cvc.onCancel = ^(){
  2118. //// self.norefresh = true;
  2119. // if(appDelegate.customerInfo==nil)
  2120. // {
  2121. // [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"" controller:self];
  2122. // }
  2123. // else
  2124. // {
  2125. // [self newoloorder];
  2126. // }
  2127. // // [main_vc checklogin:true];
  2128. // };
  2129. // cvc.onReset = ^(){
  2130. // // [main_vc checklogin:true];
  2131. // };
  2132. //
  2133. // [self.navigationController pushViewController:cvc animated:true];
  2134. //
  2135. //
  2136. //
  2137. // }
  2138. // else
  2139. // {
  2140. // //create new;
  2141. //
  2142. // if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  2143. // {
  2144. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  2145. // ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  2146. // cvc.showNavibar = true;
  2147. // cvc.contact_type = @"Sales_Order_Customer";
  2148. // cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  2149. //
  2150. // appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  2151. // appDelegate.customerInfo = value;
  2152. //
  2153. //
  2154. // if(appDelegate.order_code==nil)
  2155. // [self newoloorder];
  2156. //
  2157. // // [main_vc checklogin:true];
  2158. // // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  2159. //
  2160. // //
  2161. // // if(self.returnValue)
  2162. // // self.returnValue(value);
  2163. // };
  2164. //
  2165. // cvc.onCancel = ^(){
  2166. //
  2167. // [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"" controller:self];
  2168. //
  2169. //
  2170. //
  2171. // };
  2172. // cvc.onReset = ^(){
  2173. // [main_vc checklogin:true];
  2174. // };
  2175. //
  2176. // [self.navigationController pushViewController:cvc animated:true];
  2177. // }
  2178. // else
  2179. // {
  2180. // [self newoloorder];
  2181. // }
  2182. // }
  2183. //
  2184. // }];
  2185. //
  2186. // UIAlertAction *alertCancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  2187. //
  2188. // }];
  2189. //
  2190. // [alertControl addAction:actionOne];
  2191. //
  2192. // [alertControl addAction:alertthree];
  2193. // [alertControl addAction:alertCancel];
  2194. //
  2195. // [self presentViewController:alertControl animated:YES completion:nil];
  2196. // }
  2197. // else
  2198. // {
  2199. // [self newoloorder];
  2200. // }
  2201. //}
  2202. -(void) initAppDelegate
  2203. {
  2204. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2205. // appDelegate.user_type = USER_ROLE_EMPLOYEE;
  2206. // appDelegate.can_set_cart_price = true;
  2207. // appDelegate.can_see_price = true;
  2208. // appDelegate.can_set_cart_price = true;
  2209. // appDelegate.can_show_price = true;
  2210. // appDelegate.can_cancel_order = true;
  2211. // appDelegate.can_create_order=true;
  2212. // appDelegate.can_delete_order = true;
  2213. // appDelegate.can_submit_order = true;
  2214. // appDelegate.bLogin = true;
  2215. // RASingleton.sharedInstance.permissions_edit_order = true;
  2216. [OLDataProvider createScanTempFolder];
  2217. NSDictionary *addressDic = [[NSUserDefaults standardUserDefaults] valueForKey:@"ScanAddress"] ;
  2218. if (addressDic) {
  2219. // NSUInteger selectedIndex = [[addressDic objectForKey:@"selectedIndex"] integerValue];
  2220. // if (selectedIndex == 1) {
  2221. // self.address = [addressDic objectForKey:@"serverAddress"];
  2222. // }
  2223. // if (selectedIndex == 2) {
  2224. // self.address = [addressDic objectForKey:@"serverAddress"];
  2225. // }
  2226. appDelegate.address = [addressDic objectForKey:@"serverAddress"];
  2227. [OLDataProvider guestLogin];
  2228. }
  2229. else
  2230. {
  2231. // return;
  2232. SetupServerViewController * servervc =[[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"SetupServerViewController"];
  2233. servervc.returnValue = ^{
  2234. NSDictionary *addressDic = [[NSUserDefaults standardUserDefaults] valueForKey:@"ScanAddress"];
  2235. if (addressDic) {
  2236. self.labelServer.text = [addressDic objectForKey:@"show_name"];
  2237. }
  2238. };
  2239. [self.navigationController pushViewController:servervc animated:true];
  2240. }
  2241. }
  2242. //-(void) newoloorder
  2243. //{
  2244. // NSString* order_code = [[NSUUID new] UUIDString];
  2245. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2246. // appDelegate.order_code = order_code;
  2247. //
  2248. // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_CART ofType:@"json" ]];
  2249. // RASingleton.sharedInstance.scan_cart=[[RAConvertor data2dict:json] mutableCopy];
  2250. //
  2251. //
  2252. //// __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Create Order" completion:^{
  2253. //// [RANetwork request_create_order:^(NSMutableDictionary *result) {
  2254. //// NSMutableDictionary* return_json =result;
  2255. ////
  2256. //// [waitalert dismissViewControllerAnimated:YES completion:^{
  2257. //// if([[return_json valueForKey:@"result"] intValue]==2)
  2258. //// {
  2259. //// int result=[[return_json valueForKey:@"result"] intValue];
  2260. //// if(result==2)
  2261. //// {
  2262. //// //successed.
  2263. ////
  2264. //// NSString* order_code = [return_json valueForKey:@"orderCode"];
  2265. //// AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2266. //// appDelegate.order_code = order_code;
  2267. //// appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
  2268. ////
  2269. ////
  2270. //// #ifdef RA_NOTIFICATION
  2271. //// [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2272. //// #else
  2273. //// MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  2274. //// [main_vc reloadCart:true immediately:false];
  2275. //// #endif
  2276. ////
  2277. ////// [self ReloadData];
  2278. ////
  2279. ////
  2280. //// // [self performSelector:@selector(loadpage) withObject:nil afterDelay:1];
  2281. //// // [self loadpage];
  2282. ////
  2283. ////
  2284. //// // if(self.shopCartBlock!=nil)
  2285. //// // {
  2286. //// // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  2287. //// //
  2288. //// //
  2289. //// // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  2290. //// // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  2291. //// // iv.image = img;
  2292. //// // // [self.contentView addSubview:iv];
  2293. //// // self.shopCartBlock(iv);
  2294. //// //
  2295. //// // }
  2296. ////
  2297. //// }
  2298. //// }
  2299. //// else
  2300. //// {
  2301. //// [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Create Order" controller:self] ;
  2302. //// }
  2303. //// }];
  2304. //// // [waitalert dismissViewControllerAnimated:YES completion:nil];
  2305. ////
  2306. ////
  2307. ////
  2308. ////
  2309. ////
  2310. ////
  2311. ////
  2312. ////
  2313. //// }];
  2314. ////
  2315. //// }];
  2316. //
  2317. //// dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2318. ////
  2319. //// NSDictionary* return_json = [RANetwork new_Order];
  2320. ////
  2321. //// dispatch_async(dispatch_get_main_queue(), ^{
  2322. //// [waitalert dismissViewControllerAnimated:YES completion:nil];
  2323. ////
  2324. ////
  2325. //// if([[return_json valueForKey:@"result"] intValue]==2)
  2326. //// {
  2327. //// int result=[[return_json valueForKey:@"result"] intValue];
  2328. //// if(result==2)
  2329. //// {
  2330. //// //successed.
  2331. ////
  2332. //// NSString* order_code = [return_json valueForKey:@"orderCode"];
  2333. //// AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2334. //// appDelegate.order_code = order_code;
  2335. //// appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
  2336. ////
  2337. ////
  2338. ////#ifdef RA_NOTIFICATION
  2339. //// [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2340. ////#else
  2341. //// MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  2342. //// [main_vc reloadCart:true immediately:false];
  2343. ////#endif
  2344. ////
  2345. //// [self ReloadData];
  2346. ////
  2347. ////
  2348. //// // [self performSelector:@selector(loadpage) withObject:nil afterDelay:1];
  2349. //// // [self loadpage];
  2350. ////
  2351. ////
  2352. //// // if(self.shopCartBlock!=nil)
  2353. //// // {
  2354. //// // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  2355. //// //
  2356. //// //
  2357. //// // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  2358. //// // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  2359. //// // iv.image = img;
  2360. //// // // [self.contentView addSubview:iv];
  2361. //// // self.shopCartBlock(iv);
  2362. //// //
  2363. //// // }
  2364. ////
  2365. //// }
  2366. //// }
  2367. //// else
  2368. //// {
  2369. //// [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Create Order" controller:self] ;
  2370. //// }
  2371. ////
  2372. ////
  2373. ////
  2374. ////
  2375. //// });
  2376. //// });
  2377. //}
  2378. #endif
  2379. #pragma mark - Table view delegate
  2380. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  2381. {
  2382. NSString* title = [self.sideMenuItems[indexPath.row] valueForKey:@"title"];
  2383. if([title isEqualToString:@"Cache"])
  2384. {
  2385. CacheViewController * settingvc=[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"CacheViewController"];
  2386. PopupNavigationController * navi=[[PopupNavigationController alloc] initWithRootViewController:settingvc];
  2387. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  2388. [self presentViewController:navi animated:YES completion:^{
  2389. //DebugLog(@"login.........");
  2390. // <#code#>
  2391. }];
  2392. }
  2393. #ifdef SCANNER_ORDER
  2394. // else if([title isEqualToString:@"Scanner Order"])
  2395. // {
  2396. //
  2397. // OLOSettingViewController * offlineVC =[ [UIStoryboard storyboardWithName:@"OLM" bundle:nil] instantiateViewControllerWithIdentifier:@"OLOSettingViewController"];
  2398. // offlineVC.returnValue=^(int type){
  2399. // if(type == OOC_CREATE_ORDER){
  2400. // [self CreateOfflineOrder];
  2401. // }
  2402. // };
  2403. // // loginvc.delegate = self;
  2404. // // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  2405. // // appDelegate.active_controller = gunVC;
  2406. //// gunVC.onDismissVC = ^(){
  2407. //// appDelegate.active_controller = active_vc;
  2408. //// };
  2409. // UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:offlineVC] ;
  2410. //
  2411. //
  2412. //
  2413. //
  2414. //
  2415. // // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  2416. //
  2417. // navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  2418. // [self presentViewController:navi animated:YES completion:^{
  2419. //
  2420. // // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  2421. //
  2422. // DebugLog(@"about present.........");
  2423. //
  2424. // // self.btop = false;
  2425. // // <#code#>
  2426. // }];
  2427. //
  2428. // }
  2429. #endif
  2430. else if([title isEqualToString:@"Scanner Setting"])
  2431. {
  2432. //
  2433. #ifndef RA_NOTIFICATION
  2434. UIApplication * app = [UIApplication sharedApplication];
  2435. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  2436. UIViewController* active_vc = appDelegate.active_controller;
  2437. ScannerSettingViewController * gunVC =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ScannerSettingViewController"];
  2438. appDelegate.active_controller = gunVC;
  2439. gunVC.onDismissVC = ^(){
  2440. appDelegate.active_controller = active_vc;
  2441. };
  2442. #else
  2443. ScannerSettingViewController * gunVC =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ScannerSettingViewController"];
  2444. #endif
  2445. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:gunVC] ;
  2446. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  2447. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  2448. [self presentViewController:navi animated:YES completion:^{
  2449. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  2450. DebugLog(@"about present.........");
  2451. // self.btop = false;
  2452. // <#code#>
  2453. }];
  2454. }
  2455. else if([title isEqualToString:@"Offline Setting"])
  2456. {
  2457. // UIApplication * app = [UIApplication sharedApplication];
  2458. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  2459. //UIViewController* active_vc = appDelegate.active_controller;
  2460. OfflineSettingViewController * offlineVC =[ [UIStoryboard storyboardWithName:@"OLM" bundle:nil] instantiateViewControllerWithIdentifier:@"OfflineSettingViewController"];
  2461. // loginvc.delegate = self;
  2462. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  2463. // appDelegate.active_controller = gunVC;
  2464. // gunVC.onDismissVC = ^(){
  2465. // appDelegate.active_controller = active_vc;
  2466. // };
  2467. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:offlineVC] ;
  2468. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  2469. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  2470. [self presentViewController:navi animated:YES completion:^{
  2471. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  2472. DebugLog(@"about present.........");
  2473. // self.btop = false;
  2474. // <#code#>
  2475. }];
  2476. // [iSalesDB testdata];
  2477. }
  2478. else if([title isEqualToString:@"Function Test"])
  2479. {
  2480. // NSString* url = @"https://shopla.homelegance.com/";
  2481. //
  2482. //
  2483. // NSString* title = @"NPD";
  2484. // UIApplication * app = [UIApplication sharedApplication];
  2485. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  2486. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  2487. //
  2488. //
  2489. FunctionTestViewController *ViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"FunctionTestViewController"];
  2490. // ViewController.url = url;
  2491. // ViewController.title = title;
  2492. [self.navigationController pushViewController:ViewController animated:YES];
  2493. }
  2494. else if ([title isEqualToString:@"BLOG"]) {
  2495. NSString* url = URL_BLOG;
  2496. #ifdef BUILD_HOMER
  2497. NSString* title = @"HOMER BLOG";
  2498. #endif
  2499. #ifdef BUILD_GATIT
  2500. NSString* title = @"TITAN BLOG";
  2501. #endif
  2502. #ifdef BUILD_NPD
  2503. NSString* title = @"NPD BLOG";
  2504. #endif
  2505. #ifdef BUILD_USAI
  2506. NSString* title = @"USAI BLOG";
  2507. #endif
  2508. #ifdef BUILD_CONTRAST
  2509. NSString* title = @"CONTRAST BLOG";
  2510. #endif
  2511. title = [NSString stringWithFormat:@"%@ BLOG",COMPANY_SHORT_NAME];
  2512. WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  2513. ViewController.url = url;
  2514. ViewController.title = title;
  2515. [self.navigationController pushViewController:ViewController animated:YES];
  2516. }
  2517. else if([title isEqualToString:@"NPD Website"])
  2518. {
  2519. NSString* url = @"https://www.newpacificdirect.com";//@"https://shopla.homelegance.com/general.htm?websiteId=1";//
  2520. NSString* title = @"NPD";
  2521. // UIApplication * app = [UIApplication sharedApplication];
  2522. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  2523. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  2524. //
  2525. //
  2526. WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  2527. ViewController.url = url;
  2528. ViewController.title = title;
  2529. [self.navigationController pushViewController:ViewController animated:YES];
  2530. }
  2531. else if([title isEqualToString:@"USAI Website"])
  2532. {
  2533. NSString* url = @"http://www.united-us.net/";//@"https://shopla.homelegance.com/general.htm?websiteId=1";//
  2534. NSString* title = @"USAI";
  2535. // UIApplication * app = [UIApplication sharedApplication];
  2536. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  2537. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  2538. //
  2539. //
  2540. WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  2541. ViewController.url = url;
  2542. ViewController.title = title;
  2543. [self.navigationController pushViewController:ViewController animated:YES];
  2544. }
  2545. else if([title isEqualToString:@"Homelegance Website"])
  2546. {
  2547. NSString* url = @"http://207.140.24.83";//@"https://shopla.homelegance.com/general.htm?websiteId=1";//
  2548. NSString* title = @"Homelegance";
  2549. // UIApplication * app = [UIApplication sharedApplication];
  2550. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  2551. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  2552. //
  2553. //
  2554. WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  2555. ViewController.url = url;
  2556. ViewController.title = title;
  2557. [self.navigationController pushViewController:ViewController animated:YES];
  2558. }
  2559. else if([title isEqualToString:@"HOMER Website"])
  2560. {
  2561. NSString* url = COMPANY_WEB;
  2562. NSString* title = @"HOMER";
  2563. WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  2564. ViewController.url = url;
  2565. ViewController.title = title;
  2566. [self.navigationController pushViewController:ViewController animated:YES];
  2567. }
  2568. else if([title isEqualToString:@"TITAN Website"])
  2569. {
  2570. NSString* url = COMPANY_WEB;
  2571. NSString* title = @"TITAN";
  2572. WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  2573. ViewController.url = url;
  2574. ViewController.title = title;
  2575. [self.navigationController pushViewController:ViewController animated:YES];
  2576. }
  2577. else if([title isEqualToString:@"NPD Policy"])
  2578. {
  2579. NSString* url = URL_NPD_POLICY;//@"https://shopla.homelegance.com/general.htm?websiteId=1";//
  2580. NSString* title = @"NPD Policy";
  2581. // UIApplication * app = [UIApplication sharedApplication];
  2582. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  2583. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  2584. //
  2585. //
  2586. WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  2587. ViewController.url = url;
  2588. ViewController.title = title;
  2589. [self.navigationController pushViewController:ViewController animated:YES];
  2590. }
  2591. else if([title isEqualToString:@"USAI Policy"])
  2592. {
  2593. NSString* url = URL_NPD_POLICY;
  2594. NSString* title = @"USAI Policy";
  2595. WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  2596. ViewController.url = url;
  2597. ViewController.title = title;
  2598. [self.navigationController pushViewController:ViewController animated:YES];
  2599. }
  2600. else if([title isEqualToString:@"HOMER Policy"])
  2601. {
  2602. NSString* url = URL_NPD_POLICY;
  2603. NSString* title = @"HOMER Policy";
  2604. WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  2605. ViewController.url = url;
  2606. ViewController.title = title;
  2607. [self.navigationController pushViewController:ViewController animated:YES];
  2608. }
  2609. else if([title isEqualToString:@"Simplified Buying Program"])
  2610. {
  2611. SimplifiedBuyingProgramViewController *ViewController = [[UIStoryboard storyboardWithName:@"NPD_Mobile" bundle:nil] instantiateViewControllerWithIdentifier:@"SimplifiedBuyingProgramViewController"];
  2612. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:ViewController] ;
  2613. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  2614. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  2615. [self presentViewController:navi animated:YES completion:^{
  2616. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  2617. DebugLog(@"about present.........");
  2618. // self.btop = false;
  2619. // <#code#>
  2620. }];
  2621. }
  2622. else if ([title isEqualToString:@"Privacy Policy"]) {
  2623. NSString* url = URL_PRIVACY;
  2624. NSString* title = @"Privacy Policy";
  2625. WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  2626. ViewController.url = url;
  2627. ViewController.title = title;
  2628. [self.navigationController pushViewController:ViewController animated:YES];
  2629. }
  2630. else if([title isEqualToString:@"About us"])
  2631. {
  2632. AboutViewController * aboutVC =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"AboutViewController"];
  2633. // loginvc.delegate = self;
  2634. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  2635. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:aboutVC] ;
  2636. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  2637. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  2638. [self presentViewController:navi animated:YES completion:^{
  2639. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  2640. DebugLog(@"about present.........");
  2641. // self.btop = false;
  2642. // <#code#>
  2643. }];
  2644. }
  2645. // else if([title isEqualToString:@"Wish List"])
  2646. // {
  2647. // [self hideMenu];
  2648. // [self switchtowishlist];
  2649. // }
  2650. else if([title isEqualToString:@"Show Price"])
  2651. {
  2652. UIApplication * app = [UIApplication sharedApplication];
  2653. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  2654. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore && [RASingleton sharedInstance].global_lock) {
  2655. JKLockController *lockVC = [[JKLockController alloc] init];
  2656. [lockVC setPasswordKey:[NSString stringWithFormat:@"%@_password",appDelegate.user]];
  2657. __weak typeof(self) weakself = self;
  2658. lockVC.authoReturn = ^(BOOL failure) {
  2659. if (weakself) {
  2660. __strong typeof(weakself) strongself = weakself;
  2661. [appDelegate set_priceHidden:false];
  2662. [strongself initMenuItems];
  2663. [strongself hideMenu];
  2664. }
  2665. };
  2666. [self.navigationController pushViewController:lockVC animated:YES];
  2667. } else {
  2668. [appDelegate set_priceHidden:false];
  2669. [self initMenuItems];
  2670. [self hideMenu];
  2671. }
  2672. }
  2673. else if([title isEqualToString:@"Hide Price"])
  2674. {
  2675. UIApplication * app = [UIApplication sharedApplication];
  2676. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  2677. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore && [RASingleton sharedInstance].global_lock) {
  2678. JKLockController *lockVC = [[JKLockController alloc] init];
  2679. [lockVC setPasswordKey:[NSString stringWithFormat:@"%@_password",appDelegate.user]];
  2680. __weak typeof(self) weakself = self;
  2681. lockVC.authoReturn = ^(BOOL failure) {
  2682. if (weakself) {
  2683. __strong typeof(weakself) strongself = weakself;
  2684. [appDelegate set_priceHidden:true];
  2685. [strongself initMenuItems];
  2686. [strongself hideMenu];
  2687. }
  2688. };
  2689. [self.navigationController pushViewController:lockVC animated:YES];
  2690. } else {
  2691. [appDelegate set_priceHidden:true];
  2692. [self initMenuItems];
  2693. [self hideMenu];
  2694. }
  2695. }
  2696. // else if([title isEqualToString:@"Portfolio"] || [title isEqualToString:@"Hang Tag"])
  2697. // {
  2698. // [self hideMenu];
  2699. // if([self.current_VC isKindOfClass:[PortfolioViewController class]])
  2700. // return;
  2701. // [self flipFromViewController:self.current_VC toViewController:self.portfolioViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  2702. // }
  2703. // else if([title isEqualToString:@"View Portfolios"] || [title isEqualToString:@"View Hang Tags"])
  2704. // {
  2705. // [self hideMenu];
  2706. // if([self.current_VC isKindOfClass:[PortfolioListViewController class]])
  2707. // return;
  2708. // [self flipFromViewController:self.current_VC toViewController:self.pdfListViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  2709. // }
  2710. else if([title isEqualToString:@"Contact"])
  2711. {
  2712. // UITableViewCell* cell =(UITableViewCell*) sender.superview.superview;
  2713. //
  2714. // NSIndexPath * indexPath = [self.detailTable indexPathForCell:cell];
  2715. //
  2716. // if(indexPath.section!=1)
  2717. // return ;
  2718. // // DebugLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
  2719. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  2720. //
  2721. // NSString* product_id = [item_json valueForKey:@"product_id"];
  2722. [self hideMenu];
  2723. [self switchtocontact];
  2724. }
  2725. else if([title isEqualToString:@"Cam Scan"])
  2726. {
  2727. // UITableViewCell* cell =(UITableViewCell*) sender.superview.superview;
  2728. //
  2729. // NSIndexPath * indexPath = [self.detailTable indexPathForCell:cell];
  2730. //
  2731. // if(indexPath.section!=1)
  2732. // return ;
  2733. // // DebugLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
  2734. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  2735. //
  2736. // NSString* product_id = [item_json valueForKey:@"product_id"];
  2737. [self hideMenu];
  2738. //
  2739. // [self switchtocontact];
  2740. ScannerViewController * scannerVC =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ScannerViewController"];
  2741. [self.navigationController pushViewController:scannerVC animated:true];
  2742. } else if ([title isEqualToString:@"Price Setting"]) {
  2743. UIApplication * app = [UIApplication sharedApplication];
  2744. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  2745. if ([RASingleton sharedInstance].global_lock) {
  2746. JKLockController *lockVC = [[JKLockController alloc] init];
  2747. [lockVC setPasswordKey:[NSString stringWithFormat:@"%@_password",appDelegate.user]];
  2748. __weak typeof(self) weakself = self;
  2749. lockVC.authoReturn = ^(BOOL failure) {
  2750. if (weakself) {
  2751. __strong typeof(weakself) strongself = weakself;
  2752. PriceSettingViewController *priceSettingVC =[ [UIStoryboard storyboardWithName:@"CUL" bundle:nil] instantiateViewControllerWithIdentifier:@"PriceSettingViewController"];
  2753. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:priceSettingVC] ;
  2754. navi.navigationBar.translucent = NO;
  2755. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  2756. [strongself presentViewController:navi animated:YES completion:^{
  2757. }];
  2758. }
  2759. };
  2760. [self.navigationController pushViewController:lockVC animated:YES];
  2761. } else {
  2762. PriceSettingViewController *priceSettingVC =[ [UIStoryboard storyboardWithName:@"CUL" bundle:nil] instantiateViewControllerWithIdentifier:@"PriceSettingViewController"];
  2763. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:priceSettingVC] ;
  2764. navi.navigationBar.translucent = NO;
  2765. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  2766. [self presentViewController:navi animated:YES completion:^{
  2767. }];
  2768. }
  2769. } else if ([title isEqualToString:@"Lock"] || [title isEqualToString:@"Unlock"]) {
  2770. UIApplication * app = [UIApplication sharedApplication];
  2771. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  2772. JKLockController *lockVC = [[JKLockController alloc] init];
  2773. [lockVC setPasswordKey:[NSString stringWithFormat:@"%@_password",appDelegate.user]];
  2774. __weak typeof(self) weakself = self;
  2775. lockVC.authoReturn = ^(BOOL failure) {
  2776. if (weakself) {
  2777. __strong typeof(weakself) strongself = weakself;
  2778. [RASingleton sharedInstance].global_lock = ![RASingleton sharedInstance].global_lock;
  2779. [strongself initMenuItems];
  2780. [strongself hideMenu];
  2781. }
  2782. };
  2783. [self.navigationController pushViewController:lockVC animated:YES];
  2784. }
  2785. }
  2786. //#pragma mark - UIAlertViewDelegate
  2787. //// Called when a button is clicked. The view will be automatically dismissed after this call returns
  2788. //- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  2789. //{
  2790. // UIApplication * app = [UIApplication sharedApplication];
  2791. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  2792. //
  2793. //
  2794. //
  2795. // // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  2796. // if(buttonIndex==alertView.cancelButtonIndex)
  2797. // {
  2798. //
  2799. //
  2800. //
  2801. // }
  2802. // else if(buttonIndex==1)
  2803. // {
  2804. // //open exist
  2805. //
  2806. // OrderListViewController* ovc =[ [UIStoryboard storyboardWithName:@"ERP_Mobile_Order" bundle:nil] instantiateViewControllerWithIdentifier:@"OrderListViewController"];
  2807. // ovc.showNavibar = true;
  2808. // ovc.selectOrder = ^(NSMutableDictionary* order_detail){
  2809. // if(appDelegate.order_code==nil)
  2810. // {
  2811. // [self neworderforCart];
  2812. // }
  2813. // else
  2814. // {
  2815. // self.previous_VC = self.current_VC;
  2816. // [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  2817. //
  2818. // [self checklogin:true];
  2819. //
  2820. // }
  2821. //
  2822. // };
  2823. // ovc.init_style = OL_OPEN;
  2824. // ovc.onCancel = ^(){
  2825. //
  2826. // [self checklogin:true];
  2827. //
  2828. // };
  2829. // ovc.title = @"SAVED ORDER";
  2830. // [self.navigationController pushViewController:ovc animated:true];
  2831. // }
  2832. // else
  2833. // {
  2834. // //create new;
  2835. //
  2836. // if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  2837. // {
  2838. //
  2839. // ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  2840. // cvc.showNavibar = true;
  2841. // cvc.contact_type = @"Sales_Order_Customer";
  2842. // cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  2843. //
  2844. // appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  2845. // appDelegate.customerInfo = value;
  2846. //
  2847. //
  2848. // if(appDelegate.order_code==nil)
  2849. // [self neworderforCart];
  2850. //
  2851. //
  2852. // };
  2853. //
  2854. // cvc.onCancel = ^(){
  2855. //
  2856. // [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"" controller:self];
  2857. //
  2858. //
  2859. //
  2860. // };
  2861. // cvc.onReset = ^(){
  2862. // [self checklogin:true];
  2863. // };
  2864. //
  2865. // [self.navigationController pushViewController:cvc animated:true];
  2866. // }
  2867. // else
  2868. // {
  2869. // [self neworderforCart];
  2870. // }
  2871. //
  2872. // }
  2873. //}
  2874. -(void) neworderforCart
  2875. {
  2876. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Create Order" completion:^{
  2877. [RANetwork request_create_order:^(NSMutableDictionary *result) {
  2878. NSMutableDictionary* return_json = result;
  2879. [waitalert dismissViewControllerAnimated:YES completion:^{
  2880. if([[return_json valueForKey:@"result"] intValue]==2)
  2881. {
  2882. int result=[[return_json valueForKey:@"result"] intValue];
  2883. if(result==2)
  2884. {
  2885. //successed.
  2886. NSString* order_code = [return_json valueForKey:@"orderCode"];
  2887. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2888. appDelegate.order_code = order_code;
  2889. appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
  2890. self.previous_VC = self.current_VC;
  2891. [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  2892. #ifdef RA_NOTIFICATION
  2893. [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2894. #else
  2895. [self reloadCart:true immediately:false];
  2896. [self reloadOrder:true immediately:false];
  2897. #endif
  2898. }
  2899. }
  2900. else
  2901. {
  2902. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
  2903. }
  2904. }];
  2905. }];
  2906. }];
  2907. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2908. //
  2909. // NSDictionary* return_json = [RANetwork new_Order];
  2910. //
  2911. // dispatch_async(dispatch_get_main_queue(), ^{
  2912. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  2913. //
  2914. //
  2915. // if([[return_json valueForKey:@"result"] intValue]==2)
  2916. // {
  2917. // int result=[[return_json valueForKey:@"result"] intValue];
  2918. // if(result==2)
  2919. // {
  2920. // //successed.
  2921. //
  2922. // NSString* order_code = [return_json valueForKey:@"orderCode"];
  2923. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2924. // appDelegate.order_code = order_code;
  2925. // appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
  2926. //
  2927. // self.previous_VC = self.current_VC;
  2928. // [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  2929. //
  2930. //
  2931. //#ifdef RA_NOTIFICATION
  2932. // [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2933. //#else
  2934. // [self reloadCart:true immediately:false];
  2935. // [self reloadOrder:true immediately:false];
  2936. //#endif
  2937. //
  2938. //
  2939. // }
  2940. // }
  2941. // else
  2942. // {
  2943. // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
  2944. // }
  2945. //
  2946. //
  2947. //
  2948. //
  2949. // });
  2950. // });
  2951. }
  2952. - (void)showPriceAuth:(NSInteger)from {
  2953. }
  2954. @end