MainViewController.m 120 KB

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