MainViewController.m 86 KB

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