MainViewController.m 92 KB

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