MainViewController.m 83 KB

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