MainViewController.m 83 KB

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