MainViewController.m 89 KB

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