MainViewController.m 142 KB

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