MainViewController.m 85 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358
  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(@"Switch to pending order", nil),NSLocalizedString(@"Switch to 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(@"Switch to pending 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(@"Switch to pending order", nil),NSLocalizedString(@"Switch to 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. if(false&&appDelegate.user_type==USER_ROLE_EMPLOYEE)
  1211. {
  1212. [map setValue:@"Offline Setting" forKey:@"title"];
  1213. [map setValue:@"rect_market_news" forKey:@"img"];
  1214. [self.sideMenuItems addObject:map.copy];
  1215. }
  1216. // if([[appDelegate.user lowercaseString] isEqualToString:@"larryl"]||[[appDelegate.user lowercaseString] isEqualToString:@"arpithat"])
  1217. // {
  1218. // // [map setValue:@"Contact" forKey:@"title"];
  1219. // // [map setValue:@"rect_contact_list" forKey:@"img"];
  1220. // // [self.sideMenuItems addObject:map.copy];
  1221. //
  1222. //
  1223. // [map setValue:@"Function Test" forKey:@"title"];
  1224. // [map setValue:@"rect_market_news" forKey:@"img"];
  1225. // [self.sideMenuItems addObject:map.copy];
  1226. //
  1227. //
  1228. // }
  1229. //
  1230. [map setValue:@"About us" forKey:@"title"];
  1231. [map setValue:@"rect_change_password" forKey:@"img"];
  1232. [self.sideMenuItems addObject:map.copy];
  1233. #ifdef BUILD_HMLG
  1234. #endif
  1235. #ifdef BUILD_NPD
  1236. [map setValue:@"NPD Website" forKey:@"title"];
  1237. [map setValue:@"rect_change_password" forKey:@"img"];
  1238. [self.sideMenuItems addObject:map.copy];
  1239. [map setValue:@"NPD Policy" forKey:@"title"];
  1240. [map setValue:@"rect_change_password" forKey:@"img"];
  1241. [self.sideMenuItems addObject:map.copy];
  1242. [map setValue:@"Simplified Buying Program" forKey:@"title"];
  1243. [map setValue:@"rect_change_password" forKey:@"img"];
  1244. [self.sideMenuItems addObject:map.copy];
  1245. #endif
  1246. [self.sideMenuTable reloadData];
  1247. //
  1248. }
  1249. - (UIImage *)applyBlurWithRadius:(CGFloat)blurRadius sourceImage:(UIImage*)sourceImage tintColor:(UIColor *)tintColor saturationDeltaFactor:(CGFloat)saturationDeltaFactor maskImage:(UIImage *)maskImage
  1250. {
  1251. // Check pre-conditions.
  1252. if (sourceImage.size.width < 1 || sourceImage.size.height < 1) {
  1253. NSLog (@"*** error: invalid size: (%.2f x %.2f). Both dimensions must be >= 1: %@", sourceImage.size.width, sourceImage.size.height, self);
  1254. return nil;
  1255. }
  1256. if (!sourceImage.CGImage) {
  1257. NSLog (@"*** error: image must be backed by a CGImage: %@", self);
  1258. return nil;
  1259. }
  1260. if (maskImage && !maskImage.CGImage) {
  1261. NSLog (@"*** error: maskImage must be backed by a CGImage: %@", maskImage);
  1262. return nil;
  1263. }
  1264. CGRect imageRect = { CGPointZero, sourceImage.size };
  1265. UIImage *effectImage = sourceImage;
  1266. BOOL hasBlur = blurRadius > __FLT_EPSILON__;
  1267. BOOL hasSaturationChange = fabs(saturationDeltaFactor - 1.) > __FLT_EPSILON__;
  1268. if (hasBlur || hasSaturationChange) {
  1269. UIGraphicsBeginImageContextWithOptions(sourceImage.size, NO, [[UIScreen mainScreen] scale]);
  1270. CGContextRef effectInContext = UIGraphicsGetCurrentContext();
  1271. CGContextScaleCTM(effectInContext, 1.0, -1.0);
  1272. CGContextTranslateCTM(effectInContext, 0, -sourceImage.size.height);
  1273. CGContextDrawImage(effectInContext, imageRect, sourceImage.CGImage);
  1274. vImage_Buffer effectInBuffer;
  1275. effectInBuffer.data = CGBitmapContextGetData(effectInContext);
  1276. effectInBuffer.width = CGBitmapContextGetWidth(effectInContext);
  1277. effectInBuffer.height = CGBitmapContextGetHeight(effectInContext);
  1278. effectInBuffer.rowBytes = CGBitmapContextGetBytesPerRow(effectInContext);
  1279. UIGraphicsBeginImageContextWithOptions(sourceImage.size, NO, [[UIScreen mainScreen] scale]);
  1280. CGContextRef effectOutContext = UIGraphicsGetCurrentContext();
  1281. vImage_Buffer effectOutBuffer;
  1282. effectOutBuffer.data = CGBitmapContextGetData(effectOutContext);
  1283. effectOutBuffer.width = CGBitmapContextGetWidth(effectOutContext);
  1284. effectOutBuffer.height = CGBitmapContextGetHeight(effectOutContext);
  1285. effectOutBuffer.rowBytes = CGBitmapContextGetBytesPerRow(effectOutContext);
  1286. if (hasBlur) {
  1287. // A description of how to compute the box kernel width from the Gaussian
  1288. // radius (aka standard deviation) appears in the SVG spec:
  1289. // http://www.w3.org/TR/SVG/filters.html#feGaussianBlurElement
  1290. //
  1291. // For larger values of 's' (s >= 2.0), an approximation can be used: Three
  1292. // successive box-blurs build a piece-wise quadratic convolution kernel, which
  1293. // approximates the Gaussian kernel to within roughly 3%.
  1294. //
  1295. // let d = floor(s * 3*sqrt(2*pi)/4 + 0.5)
  1296. //
  1297. // ... if d is odd, use three box-blurs of size 'd', centered on the output pixel.
  1298. //
  1299. CGFloat inputRadius = blurRadius * [[UIScreen mainScreen] scale];
  1300. NSUInteger radius = floor(inputRadius * 3. * sqrt(2 * M_PI) / 4 + 0.5);
  1301. if (radius % 2 != 1) {
  1302. radius += 1; // force radius to be odd so that the three box-blur methodology works.
  1303. }
  1304. vImageBoxConvolve_ARGB8888(&effectInBuffer, &effectOutBuffer, NULL, 0, 0, (unsigned int)radius, (unsigned int)radius, 0, kvImageEdgeExtend);
  1305. vImageBoxConvolve_ARGB8888(&effectOutBuffer, &effectInBuffer, NULL, 0, 0, (unsigned int)radius, (unsigned int)radius, 0, kvImageEdgeExtend);
  1306. vImageBoxConvolve_ARGB8888(&effectInBuffer, &effectOutBuffer, NULL, 0, 0, (unsigned int)radius, (unsigned int)radius, 0, kvImageEdgeExtend);
  1307. }
  1308. BOOL effectImageBuffersAreSwapped = NO;
  1309. if (hasSaturationChange) {
  1310. CGFloat s = saturationDeltaFactor;
  1311. CGFloat floatingPointSaturationMatrix[] = {
  1312. 0.0722 + 0.9278 * s, 0.0722 - 0.0722 * s, 0.0722 - 0.0722 * s, 0,
  1313. 0.7152 - 0.7152 * s, 0.7152 + 0.2848 * s, 0.7152 - 0.7152 * s, 0,
  1314. 0.2126 - 0.2126 * s, 0.2126 - 0.2126 * s, 0.2126 + 0.7873 * s, 0,
  1315. 0, 0, 0, 1,
  1316. };
  1317. const int32_t divisor = 256;
  1318. NSUInteger matrixSize = sizeof(floatingPointSaturationMatrix)/sizeof(floatingPointSaturationMatrix[0]);
  1319. int16_t saturationMatrix[matrixSize];
  1320. for (NSUInteger i = 0; i < matrixSize; ++i) {
  1321. saturationMatrix[i] = (int16_t)roundf(floatingPointSaturationMatrix[i] * divisor);
  1322. }
  1323. if (hasBlur) {
  1324. vImageMatrixMultiply_ARGB8888(&effectOutBuffer, &effectInBuffer, saturationMatrix, divisor, NULL, NULL, kvImageNoFlags);
  1325. effectImageBuffersAreSwapped = YES;
  1326. }
  1327. else {
  1328. vImageMatrixMultiply_ARGB8888(&effectInBuffer, &effectOutBuffer, saturationMatrix, divisor, NULL, NULL, kvImageNoFlags);
  1329. }
  1330. }
  1331. if (!effectImageBuffersAreSwapped)
  1332. effectImage = UIGraphicsGetImageFromCurrentImageContext();
  1333. UIGraphicsEndImageContext();
  1334. if (effectImageBuffersAreSwapped)
  1335. effectImage = UIGraphicsGetImageFromCurrentImageContext();
  1336. UIGraphicsEndImageContext();
  1337. }
  1338. // Set up output context.
  1339. UIGraphicsBeginImageContextWithOptions(sourceImage.size, NO, [[UIScreen mainScreen] scale]);
  1340. CGContextRef outputContext = UIGraphicsGetCurrentContext();
  1341. CGContextScaleCTM(outputContext, 1.0, -1.0);
  1342. CGContextTranslateCTM(outputContext, 0, -sourceImage.size.height);
  1343. // Draw base image.
  1344. CGContextDrawImage(outputContext, imageRect, sourceImage.CGImage);
  1345. // Draw effect image.
  1346. if (hasBlur) {
  1347. CGContextSaveGState(outputContext);
  1348. if (maskImage) {
  1349. CGContextClipToMask(outputContext, imageRect, maskImage.CGImage);
  1350. }
  1351. CGContextDrawImage(outputContext, imageRect, effectImage.CGImage);
  1352. CGContextRestoreGState(outputContext);
  1353. }
  1354. // Add in color tint.
  1355. if (tintColor) {
  1356. CGContextSaveGState(outputContext);
  1357. CGContextSetFillColorWithColor(outputContext, tintColor.CGColor);
  1358. CGContextFillRect(outputContext, imageRect);
  1359. CGContextRestoreGState(outputContext);
  1360. }
  1361. // Output image is ready.
  1362. UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext();
  1363. UIGraphicsEndImageContext();
  1364. return outputImage;
  1365. }
  1366. //- (IBAction)openMenu:(UIButton *)sender {
  1367. //}
  1368. #pragma mark - Table view data source
  1369. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  1370. {
  1371. return 1;
  1372. }
  1373. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  1374. {
  1375. return self.sideMenuItems.count;
  1376. }
  1377. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  1378. {
  1379. UIApplication * app = [UIApplication sharedApplication];
  1380. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1381. NSString *CellIdentifier = @"SideMenuItem";
  1382. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1383. NSString* title = [self.sideMenuItems[indexPath.row] valueForKey:@"title"];
  1384. cell.backgroundColor = [UIColor clearColor];
  1385. // [cell.backgroundColor:[UIColor clearColor]];
  1386. // UIImageView* iv= [[UIImageView alloc] initWithImage:];
  1387. cell.textLabel.text = title;
  1388. cell.detailTextLabel.textColor =[UIColor redColor];
  1389. if([title isEqualToString:@"Wish List"]&&appDelegate.wish_count>0)
  1390. cell.detailTextLabel.text = [NSString stringWithFormat:@"%ld",appDelegate.wish_count];
  1391. else if([title isEqualToString:@"Portfolio"]&&appDelegate.port_count>0)
  1392. cell.detailTextLabel.text = [NSString stringWithFormat:@"%ld",appDelegate.port_count];
  1393. else
  1394. {
  1395. cell.detailTextLabel.text =nil;
  1396. }
  1397. // cell.imageView.image = [UIImage imageNamed:[self.toolsinfo[indexPath.row] valueForKey:@"img"]];
  1398. return cell;
  1399. }
  1400. #pragma mark - Table view delegate
  1401. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  1402. {
  1403. NSString* title = [self.sideMenuItems[indexPath.row] valueForKey:@"title"];
  1404. if([title isEqualToString:@"Cache"])
  1405. {
  1406. CacheViewController * settingvc=[ self.storyboard instantiateViewControllerWithIdentifier:@"CacheViewController"];
  1407. PopupNavigationController * navi=[[PopupNavigationController alloc] initWithRootViewController:settingvc];
  1408. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1409. [self presentViewController:navi animated:YES completion:^{
  1410. //NSLog(@"login.........");
  1411. // <#code#>
  1412. }];
  1413. }
  1414. else if([title isEqualToString:@"Scanner Setting"])
  1415. {
  1416. UIApplication * app = [UIApplication sharedApplication];
  1417. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1418. UIViewController* active_vc = appDelegate.active_controller;
  1419. ScannerSettingViewController * gunVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"ScannerSettingViewController"];
  1420. // loginvc.delegate = self;
  1421. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1422. appDelegate.active_controller = gunVC;
  1423. gunVC.onDismissVC = ^(){
  1424. appDelegate.active_controller = active_vc;
  1425. };
  1426. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:gunVC] ;
  1427. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1428. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  1429. [self presentViewController:navi animated:YES completion:^{
  1430. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1431. NSLog(@"about present.........");
  1432. // self.btop = false;
  1433. // <#code#>
  1434. }];
  1435. }
  1436. else if([title isEqualToString:@"Offline Setting"])
  1437. {
  1438. UIApplication * app = [UIApplication sharedApplication];
  1439. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1440. //UIViewController* active_vc = appDelegate.active_controller;
  1441. OfflineSettingViewController * offlineVC =[ [UIStoryboard storyboardWithName:@"OLM" bundle:nil] instantiateViewControllerWithIdentifier:@"OfflineSettingViewController"];
  1442. // loginvc.delegate = self;
  1443. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1444. // appDelegate.active_controller = gunVC;
  1445. // gunVC.onDismissVC = ^(){
  1446. // appDelegate.active_controller = active_vc;
  1447. // };
  1448. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:offlineVC] ;
  1449. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1450. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  1451. [self presentViewController:navi animated:YES completion:^{
  1452. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1453. NSLog(@"about present.........");
  1454. // self.btop = false;
  1455. // <#code#>
  1456. }];
  1457. // [iSalesDB testdata];
  1458. }
  1459. else if([title isEqualToString:@"Function Test"])
  1460. {
  1461. // NSString* url = @"https://www.newpacificdirect.com";
  1462. //
  1463. //
  1464. // NSString* title = @"NPD";
  1465. // UIApplication * app = [UIApplication sharedApplication];
  1466. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1467. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  1468. //
  1469. //
  1470. FunctionTestViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"FunctionTestViewController"];
  1471. // ViewController.url = url;
  1472. // ViewController.title = title;
  1473. [self.navigationController pushViewController:ViewController animated:YES];
  1474. }
  1475. else if([title isEqualToString:@"NPD Website"])
  1476. {
  1477. NSString* url = @"https://www.newpacificdirect.com";//@"https://www.newpacificdirect.com/general.htm?websiteId=1";//
  1478. NSString* title = @"NPD";
  1479. // UIApplication * app = [UIApplication sharedApplication];
  1480. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1481. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  1482. //
  1483. //
  1484. WebViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"WebViewController"];
  1485. ViewController.url = url;
  1486. ViewController.title = title;
  1487. [self.navigationController pushViewController:ViewController animated:YES];
  1488. }
  1489. else if([title isEqualToString:@"NPD Policy"])
  1490. {
  1491. NSString* url = URL_NPD_POLICY;//@"https://www.newpacificdirect.com/general.htm?websiteId=1";//
  1492. NSString* title = @"NPD Policy";
  1493. // UIApplication * app = [UIApplication sharedApplication];
  1494. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1495. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  1496. //
  1497. //
  1498. WebViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"WebViewController"];
  1499. ViewController.url = url;
  1500. ViewController.title = title;
  1501. [self.navigationController pushViewController:ViewController animated:YES];
  1502. }
  1503. else if([title isEqualToString:@"Simplified Buying Program"])
  1504. {
  1505. SimplifiedBuyingProgramViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"SimplifiedBuyingProgramViewController"];
  1506. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:ViewController] ;
  1507. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1508. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  1509. [self presentViewController:navi animated:YES completion:^{
  1510. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1511. NSLog(@"about present.........");
  1512. // self.btop = false;
  1513. // <#code#>
  1514. }];
  1515. }
  1516. else if([title isEqualToString:@"About us"])
  1517. {
  1518. AboutViewController * aboutVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"AboutViewController"];
  1519. // loginvc.delegate = self;
  1520. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1521. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:aboutVC] ;
  1522. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1523. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  1524. [self presentViewController:navi animated:YES completion:^{
  1525. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1526. NSLog(@"about present.........");
  1527. // self.btop = false;
  1528. // <#code#>
  1529. }];
  1530. }
  1531. else if([title isEqualToString:@"Wish List"])
  1532. {
  1533. [self hideMenu];
  1534. [self switchtowishlist];
  1535. }
  1536. else if([title isEqualToString:@"Show Price"])
  1537. {
  1538. UIApplication * app = [UIApplication sharedApplication];
  1539. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1540. [appDelegate set_priceHidden:false];
  1541. //appDelegate.price_hidden = false;
  1542. //[self.sideMenuTable reloadData];
  1543. [self initMenuItems];
  1544. [self hideMenu];
  1545. }
  1546. else if([title isEqualToString:@"Hide Price"])
  1547. {
  1548. UIApplication * app = [UIApplication sharedApplication];
  1549. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1550. [appDelegate set_priceHidden:true];
  1551. // appDelegate.price_hidden = true;
  1552. [self initMenuItems];
  1553. // [self.sideMenuTable reloadData];
  1554. [self hideMenu];
  1555. }
  1556. else if([title isEqualToString:@"Portfolio"])
  1557. {
  1558. [self hideMenu];
  1559. if([self.current_VC isKindOfClass:[PortfolioViewController class]])
  1560. return;
  1561. [self flipFromViewController:self.current_VC toViewController:self.portfolioViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1562. }
  1563. else if([title isEqualToString:@"View Portfolios"])
  1564. {
  1565. [self hideMenu];
  1566. if([self.current_VC isKindOfClass:[PDFListViewController class]])
  1567. return;
  1568. [self flipFromViewController:self.current_VC toViewController:self.pdfListViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1569. }
  1570. else if([title isEqualToString:@"Contact"])
  1571. {
  1572. // UITableViewCell* cell =(UITableViewCell*) sender.superview.superview;
  1573. //
  1574. // NSIndexPath * indexPath = [self.detailTable indexPathForCell:cell];
  1575. //
  1576. // if(indexPath.section!=1)
  1577. // return ;
  1578. // // NSLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
  1579. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1580. //
  1581. // NSString* product_id = [item_json valueForKey:@"product_id"];
  1582. [self hideMenu];
  1583. [self switchtocontact];
  1584. }
  1585. else if([title isEqualToString:@"Cam Scan"])
  1586. {
  1587. // UITableViewCell* cell =(UITableViewCell*) sender.superview.superview;
  1588. //
  1589. // NSIndexPath * indexPath = [self.detailTable indexPathForCell:cell];
  1590. //
  1591. // if(indexPath.section!=1)
  1592. // return ;
  1593. // // NSLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
  1594. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1595. //
  1596. // NSString* product_id = [item_json valueForKey:@"product_id"];
  1597. [self hideMenu];
  1598. //
  1599. // [self switchtocontact];
  1600. ScannerViewController * scannerVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"ScannerViewController"];
  1601. [self.navigationController pushViewController:scannerVC animated:true];
  1602. }
  1603. }
  1604. #pragma mark - UIAlertViewDelegate
  1605. // Called when a button is clicked. The view will be automatically dismissed after this call returns
  1606. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  1607. {
  1608. UIApplication * app = [UIApplication sharedApplication];
  1609. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1610. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  1611. if(buttonIndex==alertView.cancelButtonIndex)
  1612. {
  1613. }
  1614. else if(buttonIndex==1)
  1615. {
  1616. //open exist
  1617. OrderListViewController* ovc =[ self.storyboard instantiateViewControllerWithIdentifier:@"OrderListViewController"];
  1618. ovc.showNavibar = true;
  1619. ovc.selectOrder = ^(NSMutableDictionary* order_detail){
  1620. if(appDelegate.order_code==nil)
  1621. {
  1622. [self neworderforCart];
  1623. }
  1624. else
  1625. {
  1626. self.previous_VC = self.current_VC;
  1627. [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1628. [self checklogin:true];
  1629. }
  1630. };
  1631. ovc.init_style = OL_OPEN;
  1632. ovc.onCancel = ^(){
  1633. [self checklogin:true];
  1634. };
  1635. [self.navigationController pushViewController:ovc animated:true];
  1636. }
  1637. else
  1638. {
  1639. //create new;
  1640. if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  1641. {
  1642. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  1643. cvc.showNavibar = true;
  1644. cvc.contact_type = @"Sales_Order_Customer";
  1645. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1646. appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  1647. appDelegate.customerInfo = value;
  1648. if(appDelegate.order_code==nil)
  1649. [self neworderforCart];
  1650. };
  1651. cvc.onCancel = ^(){
  1652. [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"" controller:self];
  1653. };
  1654. cvc.onReset = ^(){
  1655. [self checklogin:true];
  1656. };
  1657. [self.navigationController pushViewController:cvc animated:true];
  1658. }
  1659. else
  1660. {
  1661. [self neworderforCart];
  1662. }
  1663. }
  1664. }
  1665. -(void) neworderforCart
  1666. {
  1667. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Create Order"];
  1668. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1669. NSDictionary* return_json = [iSalesNetwork new_Order];
  1670. dispatch_async(dispatch_get_main_queue(), ^{
  1671. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  1672. if([[return_json valueForKey:@"result"] intValue]==2)
  1673. {
  1674. int result=[[return_json valueForKey:@"result"] intValue];
  1675. if(result==2)
  1676. {
  1677. //successed.
  1678. NSString* order_code = [return_json valueForKey:@"orderCode"];
  1679. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1680. appDelegate.order_code = order_code;
  1681. appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
  1682. self.previous_VC = self.current_VC;
  1683. [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1684. }
  1685. }
  1686. else
  1687. {
  1688. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
  1689. }
  1690. });
  1691. });
  1692. }
  1693. @end