MainViewController.m 101 KB

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