MainViewController.m 119 KB

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