MainViewController.m 119 KB

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