MainViewController.m 97 KB

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