MainViewController.m 101 KB

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