MainViewController.m 140 KB

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