MainViewController.m 85 KB

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