// // ViewController.m // RedAnt ERP Suite // // Created by Ray on 14-5-19. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved. // #import "MainViewController.h" //#import "SideMenuViewController.h" //#import "RootContainerViewController.h" #import #import "PopupNavigationController.h" //#import "CommonGridViewController.h" #import "CacheViewController.h" #import "ScannerViewController.h" #import "ContactListViewController.h" #import "RAUtils.h" #import "AboutViewController.h" #import "ScannerSettingViewController.h" #import "ActiveViewController.h" @interface MainViewController () @end @implementation MainViewController -(void) logoutDocuments { [self.pdfListViewController logout]; } -(void) logoutCart { [self.cartViewController logout]; } -(void) logoutWish { [self.watchListViewController logout]; } -(void) logoutPortfolio { [self.portfolioViewController logout]; } -(void) logoutOrder { [self.orderViewController logout]; } -(void) logoutContact { [self.contactListViewController logout]; } -(void) logoutCategory { [self.categoryViewController logout]; } -(void) reloadCategory:(BOOL) update_data immediately:(bool)immediately { if(immediately) [ self.categoryViewController reload_container_getdata:update_data]; else { if(update_data&&self.categoryViewController.refresh_type<=REFRESH_DATA) self.categoryViewController.refresh_type = REFRESH_DATA; else if(self.categoryViewController.refresh_type<=REFRESH_VIEW) self.categoryViewController.refresh_type = REFRESH_VIEW; } } -(void) reloadDocuments:(BOOL) update_data immediately:(bool)immediately { if(immediately) [ self.pdfListViewController reload_container_getdata:update_data]; else { if(update_data&&self.pdfListViewController.refresh_type<=REFRESH_DATA) self.pdfListViewController.refresh_type = REFRESH_DATA; else if(self.pdfListViewController.refresh_type<=REFRESH_VIEW) self.pdfListViewController.refresh_type = REFRESH_VIEW; } //[self.pdfListViewController reload_container_getdata:update_data]; } -(void) reloadCart:(BOOL) update_data immediately:(bool)immediately { if(immediately) [ self.cartViewController reload_container_getdata:update_data]; else { if(update_data&&self.cartViewController.refresh_type<=REFRESH_DATA) self.cartViewController.refresh_type = REFRESH_DATA; else if(self.cartViewController.refresh_type<=REFRESH_VIEW) self.cartViewController.refresh_type = REFRESH_VIEW; } // [self.cartViewController reload_container_getdata:update_data]; } -(void) reloadWish:(BOOL) update_data immediately:(bool)immediately { if(immediately) [ self.watchListViewController reload_container_getdata:update_data]; else { if(update_data&&self.watchListViewController.refresh_type<=REFRESH_DATA) self.watchListViewController.refresh_type = REFRESH_DATA; else if(self.watchListViewController.refresh_type<=REFRESH_VIEW) self.watchListViewController.refresh_type = REFRESH_VIEW; } // [self.watchListViewController reload_container_getdata:update_data]; } -(void) reloadPortfolio:(BOOL) update_data immediately:(bool)immediately { if(immediately) [ self.portfolioViewController reload_container_getdata:update_data]; else { if(update_data&&self.portfolioViewController.refresh_type<=REFRESH_DATA) self.portfolioViewController.refresh_type = REFRESH_DATA; else if(self.portfolioViewController.refresh_type<=REFRESH_VIEW) self.portfolioViewController.refresh_type = REFRESH_VIEW; } // [self.portfolioViewController reload_container_getdata:update_data]; } -(void) reloadOrder:(BOOL) update_data immediately:(bool)immediately { if(immediately) [ self.orderViewController reload_container_getdata:update_data]; else { if(update_data&&self.orderViewController.refresh_type<=REFRESH_DATA) self.orderViewController.refresh_type = REFRESH_DATA; else if(self.orderViewController.refresh_type<=REFRESH_VIEW) self.orderViewController.refresh_type = REFRESH_VIEW; } // [self.orderViewController reload_container_getdata:update_data]; } -(void) reloadContact:(BOOL) update_data immediately:(bool)immediately { //[self.con reload_container]; if(immediately) [ self.contactListViewController reload_container_getdata:update_data]; else { if(update_data&&self.contactListViewController.refresh_type<=REFRESH_DATA) self.contactListViewController.refresh_type = REFRESH_DATA; else if(self.contactListViewController.refresh_type<=REFRESH_VIEW) self.contactListViewController.refresh_type = REFRESH_VIEW; } } -(void)viewWillLayoutSubviews { self.headerView.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.headerView.bounds].CGPath; } -(void) viewWillAppear:(BOOL)animated { // [self.label_ccount.layer setMasksToBounds:YES]; UIApplication * app = [UIApplication sharedApplication]; AppDelegate *appDelegate = (AppDelegate *)[app delegate]; // self.labelContact.text=appDelegate.contact_name; NSString * contact =[appDelegate.customerInfo valueForKey:@"customer_contact"]; NSString * customer=[appDelegate.customerInfo valueForKey:@"customer_name"]; if(contact==nil||contact.length==0) { contact=@"No Name"; [self.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal]; } else { if(contact==nil||contact.length==0) { contact=@"No Name"; [self.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal]; } else { [self.btnContact setTitleColor:UIColorFromRGB(0x009900) forState:UIControlStateNormal]; } } NSMutableArray* arr_contact = [[NSMutableArray alloc] init]; if(contact.length>0) [arr_contact addObject:contact]; if(customer.length>0) [arr_contact addObject:customer]; NSString *contact_string = [arr_contact componentsJoinedByString:@" @"]; [self.btnContact setTitle:contact_string forState:UIControlStateNormal]; [[self navigationController] setNavigationBarHidden:YES animated:NO]; } - (void) checklogin:(bool) reloadCurrentVC { [self initMenuItems]; AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; self.sideMenu_UserName.text =appDelegate.user; if(appDelegate.bLogin) [self.btnLogin setTitle:@"Logout" forState:UIControlStateNormal]; else [self.btnLogin setTitle:@"Login" forState:UIControlStateNormal]; [iSalesNetwork LoadImage:appDelegate.user_icon into:self.user_head ]; if(appDelegate.user_type==USER_ROLE_EMPLOYEE) self.btnContact.hidden = NO; else self.btnContact.hidden = YES; NSDictionary * customerinfo=appDelegate.customerInfo; NSString * contact=nil; NSString * customer=nil; if(customerinfo==nil) { contact=@"Select Contact"; [self.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal]; } else { contact=[customerinfo valueForKey:@"customer_contact"]; customer=[customerinfo valueForKey:@"customer_name"]; if(contact==nil||contact.length==0) { contact=@"No Name"; [self.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal]; } else { [self.btnContact setTitleColor:[UIColor greenColor] forState:UIControlStateNormal]; } } NSMutableArray* arr_contact = [[NSMutableArray alloc] init]; if(contact.length>0) [arr_contact addObject:contact]; if(customer.length>0) [arr_contact addObject:customer]; NSString *contact_string = [arr_contact componentsJoinedByString:@" @"]; [self.btnContact setTitle:contact_string forState:UIControlStateNormal]; // if(appDelegate.bLogin) // [self.buttonUser setTitle:appDelegate.user forState:UIControlStateNormal]; // else // [self.buttonUser setTitle:@"Sign in" forState:UIControlStateNormal]; [self reloadDocuments:true immediately:false]; [self reloadCart:true immediately:false]; [self reloadWish:true immediately:false]; [self reloadPortfolio:true immediately:false]; [self reloadOrder:true immediately:false]; [self reloadContact:true immediately:false]; [self reloadCategory:true immediately:false]; ActiveViewController* lrvc = (ActiveViewController*)appDelegate.active_controller; if(reloadCurrentVC) { if(lrvc!=nil) [ lrvc refresh_on_login]; } else { if(lrvc.refresh_type<=REFRESH_DATA) lrvc.refresh_type = REFRESH_DATA; else if(lrvc.refresh_type<=REFRESH_VIEW) lrvc.refresh_type = REFRESH_VIEW; } // [self reload]; } - (IBAction)onContactClick:(id)sender { UIApplication * app = [UIApplication sharedApplication]; AppDelegate *appDelegate = (AppDelegate *)[app delegate]; NSString* contactid=appDelegate.contact_id ; if(contactid==nil) { ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ]; cvc.update_order = true; cvc.showNavibar = true; cvc.contact_type = @"Sales_Order_Customer"; cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){ appDelegate.contact_id=[value valueForKey:@"customer_cid"]; appDelegate.customerInfo = value; // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION]; // // if(self.returnValue) // self.returnValue(value); }; [self.navigationController pushViewController:cvc animated:true]; } else { CustomerInfoViewController * vc =[ self.storyboard instantiateViewControllerWithIdentifier:@"CustomerInfoViewController"]; vc.url_type = URL_LOCAL; vc.request_url=LOCAL_URL_CUSTOMER_INFO_EDITOR; vc.data_init = appDelegate.customerInfo; vc.update_order = true; vc.contactId=contactid; // vc.delegate = self; vc.returnValue = ^(NSMutableDictionary* value){ appDelegate.contact_id=[value valueForKey:@"customer_cid"]; appDelegate.customerInfo = value; }; [self.navigationController pushViewController:vc animated:true]; } } - (void)viewDidLoad { [super viewDidLoad]; self.label_ccount.layer.cornerRadius=10.5; self.label_ccount.layer.masksToBounds=true; UIApplication * app = [UIApplication sharedApplication]; AppDelegate *appDelegate = (AppDelegate *)[app delegate]; appDelegate.main_vc = self; [appDelegate update_count_mark]; NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary]; NSString* build =[infoDict objectForKey:@"CFBundleVersion"]; NSString* version =[infoDict objectForKey:@"CFBundleShortVersionString"]; NSString* versionNum = [NSString stringWithFormat:@"npd %@ Build %@",version,build]; [self initMenuItems]; self.homeViewController =[ self.storyboard instantiateViewControllerWithIdentifier:@"HomeViewController"]; self.categoryViewController =[ self.storyboard instantiateViewControllerWithIdentifier:@"CategoryViewController"]; self.cartViewController =[ self.storyboard instantiateViewControllerWithIdentifier:@"CartViewController"]; self.orderViewController =[ self.storyboard instantiateViewControllerWithIdentifier:@"OrderListViewController"]; self.contactListViewController =[ self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController"]; self.contactListViewController.contact_type = @"Sales_Order_Customer"; self.orderViewController.selectOrder=^(NSMutableDictionary* order_detail){ //main view 下打开order self.cartViewController.onFinishLoad=^() { [self.cartViewController placeOrder]; self.cartViewController.onFinishLoad=nil; }; [self switchToCart:nil]; }; self.watchListViewController =[ self.storyboard instantiateViewControllerWithIdentifier:@"WatchListViewController"]; self.portfolioViewController =[ self.storyboard instantiateViewControllerWithIdentifier:@"PortfolioViewController"]; self.pdfListViewController =[ self.storyboard instantiateViewControllerWithIdentifier:@"PDFListViewController"]; self.itemSearchViewController=[ self.storyboard instantiateViewControllerWithIdentifier:@"ItemSearchViewController"]; self.searchViewController=[ self.storyboard instantiateViewControllerWithIdentifier:@"SearchViewController"]; [self addChildViewController:self.homeViewController]; //1 self.homeViewController.view.frame = self.container.bounds; [self.container addSubview:self.homeViewController.view]; //2 [self.homeViewController didMoveToParentViewController:self]; self.current_VC = self.homeViewController; // self.is_home = true; // [UIBezierPath bezierPathWithRect:self.headerView.bounds].CGPath; self.headerView.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.headerView.bounds].CGPath; self.headerView.layer.masksToBounds = false; //添加四个边阴影 self.headerView.layer.shadowColor = [UIColor blackColor].CGColor; self.headerView.layer.shadowOffset = CGSizeMake(0, 0); self.headerView.layer.shadowOpacity = 0.5; self.headerView.layer.shadowRadius = 2.0; self.labelVer.text=versionNum; // UIApplication * app = [UIApplication sharedApplication]; // AppDelegate *appDelegate = (AppDelegate *)[app delegate]; if(appDelegate.categoryMenu==nil) { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSDictionary* category=[iSalesNetwork request_Cagegory]; dispatch_async(dispatch_get_main_queue(), ^{ if([[category valueForKey:@"result"] intValue]==2) { appDelegate.categoryMenu = category; } else { // [RAUtils error_alert:[category valueForKey:@"err_msg"] title:@"Failed to load category."] ; } // self.categoryViewController.categoryMenu = category; }); }); } // Do any additional setup after loading the view, typically from a nib. } - (IBAction)onmenuButtonClicked:(id)sender { self.openMenuButton.hidden = true; self.sideMenu.hidden = false; [self showMenu]; } - (IBAction)switchMenu:(UIButton *)sender { // if(self.menuShown==true) [self hideMenu]; self.openMenuButton.hidden = false; self.sideMenu.hidden = true; // else // [self showMenu]; } - (IBAction)OnLoginClick:(UIButton *)sender { UIApplication * app = [UIApplication sharedApplication]; AppDelegate *appDelegate = (AppDelegate *)[app delegate]; if(appDelegate.bLogin) { UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Logout"]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSDictionary* return_json = [iSalesNetwork logout]; dispatch_async(dispatch_get_main_queue(), ^{ [waitalert dismissWithClickedButtonIndex:0 animated:FALSE]; if([[return_json valueForKey:@"result"] intValue]==2) { [self hideMenu]; [self switchToHome:nil]; [appDelegate Logout]; LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"]; loginvc.returnValue = ^(bool blogin){ [self checklogin :true]; }; UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ; navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种 [self presentViewController:navi animated:YES completion:^{ NSLog(@"login present........."); }]; } else { [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ; } }); }); } else { LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"]; loginvc.returnValue = ^(bool blogin){ [self checklogin :true]; }; UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ; navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种 [self presentViewController:navi animated:YES completion:^{ NSLog(@"login present........."); }]; } } - (IBAction)onScanClick:(id)sender { ScannerViewController * scannerVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"ScannerViewController"]; [self.navigationController pushViewController:scannerVC animated:true]; } - (IBAction)switchToSearch:(UIButton *)sender { if([self.current_VC isKindOfClass:[SearchViewController class]]) return; [self flipFromViewController:self.current_VC toViewController:self.searchViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve]; } - (IBAction)switchToWishlist:(UIButton *)sender { [self switchtowishlist]; } -(void)switchtowishlist { if([self.current_VC isKindOfClass:[WatchListViewController class]]) return; [self flipFromViewController:self.current_VC toViewController:self.watchListViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve]; } - (IBAction)switchToContact:(UIButton *)sender { [self switchtocontact]; } -(void)switchtocontact { if([self.current_VC isKindOfClass:[ContactListViewController class]]) return; UIApplication * app = [UIApplication sharedApplication]; AppDelegate *appDelegate = (AppDelegate *)[app delegate]; if(appDelegate.bLogin==false) { LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"]; // loginvc.delegate = self; // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种 loginvc.returnValue = ^(bool blogin){ if(blogin) { [self checklogin:true]; [self flipFromViewController:self.current_VC toViewController:self.contactListViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve]; } }; UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ; // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi]; navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种 [self presentViewController:navi animated:YES completion:^{ // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320); NSLog(@"LoginViewController present........."); // self.btop = false; // <#code#> }]; } else [self flipFromViewController:self.current_VC toViewController:self.contactListViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve]; // // UIApplication * app = [UIApplication sharedApplication]; // AppDelegate *appDelegate = (AppDelegate *)[app delegate]; // ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ]; // cvc.update_order = true; // cvc.contact_type = @"Sales_Order_Customer"; // cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){ // // appDelegate.contact_id=[value valueForKey:@"customer_cid"]; // appDelegate.customerInfo = value; // // // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION]; // // // // // if(self.returnValue) // // self.returnValue(value); // }; // [self.navigationController pushViewController:cvc animated:true]; } - (void) reload { AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSDictionary* category=[iSalesNetwork request_Cagegory]; dispatch_async(dispatch_get_main_queue(), ^{ if([[category valueForKey:@"result"] intValue]==2) { appDelegate.categoryMenu = category; } else { // [RAUtils error_alert:[category valueForKey:@"err_msg"]] ; } }); }); } - (IBAction)onUserButtonClick:(id)sender { NSLog(@"header view login"); AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; if( appDelegate.user ==nil) { LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"]; // loginvc.delegate = self; // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种 loginvc.returnValue = ^(bool blogin){ [self checklogin:true]; }; UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ; // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi]; navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种 [self presentViewController:navi animated:YES completion:^{ // <#code#> }]; // LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"]; // loginvc.delegate = self; // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种 // [self presentViewController:loginvc animated:YES completion:^{ // // NSLog(@"login........."); // // <#code#> // }]; } } #pragma mark - LoginViewControllerDelegate -(void)LoginViewControllerDidLogin:(LoginViewController *)viewController { [viewController dismissViewControllerAnimated:YES completion:nil]; AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; self.sideMenu_UserName.text =appDelegate.user; [self.btnLogin setTitle:@"Logout" forState:UIControlStateNormal]; [iSalesNetwork LoadImage:appDelegate.user_icon into:self.user_head ]; if(appDelegate.user_type==USER_ROLE_EMPLOYEE) self.btnContact.hidden = NO; else self.btnContact.hidden = YES; NSDictionary * customerinfo=appDelegate.customerInfo; NSString * contact=nil; NSString * customer=nil; if(customerinfo==nil) { contact=@"Select Contact"; [self.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal]; } else { contact=[customerinfo valueForKey:@"customer_contact"]; customer=[customerinfo valueForKey:@"customer_name"]; if(contact==nil||contact.length==0) { contact=@"No Name"; [self.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal]; } else { [self.btnContact setTitleColor:UIColorFromRGB(0x009900) forState:UIControlStateNormal]; } } NSMutableArray* arr_contact = [[NSMutableArray alloc] init]; if(contact.length>0) [arr_contact addObject:contact]; if(customer.length>0) [arr_contact addObject:customer]; NSString *contact_string = [arr_contact componentsJoinedByString:@" @"]; [self.btnContact setTitle:contact_string forState:UIControlStateNormal]; // [self.buttonUser setTitle:appDelegate.user forState:UIControlStateNormal]; [self reload]; } - (void) flipFromViewController:(UIViewController*) fromController toViewController:(UIViewController*) toController withDirection:(UIViewAnimationOptions) direction { toController.view.frame = self.container.bounds; // 1 // UIViewAutoresizingFlexibleLeftMargin = 1 << 0, // UIViewAutoresizingFlexibleWidth = 1 << 1, // UIViewAutoresizingFlexibleRightMargin = 1 << 2, // UIViewAutoresizingFlexibleTopMargin = 1 << 3, // UIViewAutoresizingFlexibleHeight = 1 << 4, // UIViewAutoresizingFlexibleBottomMargin = 1 << 5 toController.view.autoresizingMask = UIViewAutoresizingFlexibleHeight |UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin; [self addChildViewController:toController]; // [fromController willMoveToParentViewController:nil]; // [self transitionFromViewController:fromController toViewController:toController duration:0.2 options:direction | UIViewAnimationOptionCurveEaseIn animations:nil completion:^(BOOL finished) { [toController didMoveToParentViewController:self]; // 2 [fromController removeFromParentViewController]; // 3 self.current_VC = toController; }]; } -(void)topicViewSelected:(int) type _id: (int) _id { [self switchToCagegory:nil]; if(type==0) { // [self.categoryViewController showDetailat:_id]; } else { [self.categoryViewController showCategory]; } } -(void)categoryMenuSelected:(NSString*)_id { [self switchToCagegory:_id]; // [self.categoryViewController showCategory]; } - (void)switchToItemSearch:(NSString* )coverttype { // NSString* ttt =[@"Category" stringByAppendingString:[self categoryString:categoryid node:self.categoryMenu level:0]]; // UIApplication * app = [UIApplication sharedApplication]; // AppDelegate *appDelegate = (AppDelegate *)[app delegate]; self.itemSearchViewController.covertype = coverttype; [self.itemSearchViewController reload_container_getdata:true]; // .categoryString = [@"Category" stringByAppendingString:[self categoryString:categoryid node:appDelegate.categoryMenu level:0]]; // self.categoryViewController.cagegoryLabel.text =self.categoryViewController.categoryString; // // NSString* sss =[@"Category" stringByAppendingString:[self categoryString:categoryid node:appDelegate.categoryMenu level:0]]; // self.categoryViewController.categoryid = categoryid ; // [self.itemSearchViewController reload]; // [self.itemSearchViewController showCategory]; if([self.current_VC isKindOfClass:[ItemSearchViewController class]]) return; [self flipFromViewController:self.current_VC toViewController:self.itemSearchViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve]; [[self navigationController] setNavigationBarHidden:YES animated:NO]; // self.is_home = false; // self.current_vc = VC_CATEGORY; // [self.homeViewController willMoveToParentViewController:nil]; //1 // [self.homeViewController.view removeFromSuperview]; //2 // [self.homeViewController removeFromParentViewController]; //3 // // [self.container addSubview:self.cagegoryViewController.view]; //2 // [self.cagegoryViewController didMoveToParentViewController:self]; } - (void)switchToCagegory:(NSString* )categoryid { // NSString* ttt =[@"Category" stringByAppendingString:[self categoryString:categoryid node:self.categoryMenu level:0]]; UIApplication * app = [UIApplication sharedApplication]; AppDelegate *appDelegate = (AppDelegate *)[app delegate]; self.categoryViewController.categoryString = [@"Category" stringByAppendingString:[self categoryString:categoryid node:appDelegate.categoryMenu level:0]]; self.categoryViewController.cagegoryLabel.text =self.categoryViewController.categoryString; // NSString* sss =[@"Category" stringByAppendingString:[self categoryString:categoryid node:appDelegate.categoryMenu level:0]]; self.categoryViewController.categoryid = categoryid ; [self.categoryViewController reload_container_getdata:true]; [self.categoryViewController showCategory]; if([self.current_VC isKindOfClass:[CategoryViewController class]]) return; [self flipFromViewController:self.current_VC toViewController:self.categoryViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve]; [[self navigationController] setNavigationBarHidden:YES animated:NO]; // self.is_home = false; // self.current_vc = VC_CATEGORY; // [self.homeViewController willMoveToParentViewController:nil]; //1 // [self.homeViewController.view removeFromSuperview]; //2 // [self.homeViewController removeFromParentViewController]; //3 // // [self.container addSubview:self.cagegoryViewController.view]; //2 // [self.cagegoryViewController didMoveToParentViewController:self]; } - (IBAction)switchToHome:(UIButton *)sender { if([self.current_VC isKindOfClass:[HomeViewController class]]) return; [self flipFromViewController:self.current_VC toViewController:self.homeViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve]; // self.current_vc = VC_HOME; // self.is_home = true; // // [self.cagegoryViewController willMoveToParentViewController:nil]; //1 // [self.cagegoryViewController.view removeFromSuperview]; //2 // [self.cagegoryViewController removeFromParentViewController]; //3 // // [self.container addSubview:self.homeViewController.view]; //2 // [self.homeViewController didMoveToParentViewController:self]; } -(void) switchToPreviousVC { if(self.previous_VC==nil) return; if([self.current_VC isKindOfClass:[self.previous_VC class]]) return; [self flipFromViewController:self.current_VC toViewController:self.previous_VC withDirection:UIViewAnimationOptionTransitionCrossDissolve]; } - (IBAction)switchToCart:(UIButton *)sender { [self switchToCart]; // self.current_vc = VC_HOME; } -(void) switchToCart { if([self.current_VC isKindOfClass:[CartViewController class]]) return; // // UIApplication * app = [UIApplication sharedApplication]; // AppDelegate *appDelegate = (AppDelegate *)[app delegate]; // if(appDelegate.bLogin==false) // { // LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"]; // // loginvc.delegate = self; // // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种 // // loginvc.returnValue = ^(bool blogin){ // // // // UIApplication * app = [UIApplication sharedApplication]; // // AppDelegate *appDelegate = (AppDelegate *)[app delegate]; // // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc; // // // if(blogin) // { // [self checklogin:true]; // // // // self.previous_VC = self.current_VC; // //self.cartViewController =[ self.storyboard instantiateViewControllerWithIdentifier:@"CartViewController"]; // // [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve]; // } // // // [self reload_data]; // // // // }; // // UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ; // // // // // // // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi]; // // navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种 // [self presentViewController:navi animated:YES completion:^{ // // // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320); // // NSLog(@"CreateOrderViewController present........."); // // // self.btop = false; // // <#code#> // }]; // } // else // { // self.previous_VC = self.current_VC; // [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve]; // } UIApplication * app = [UIApplication sharedApplication]; AppDelegate *appDelegate = (AppDelegate *)[app delegate]; // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc; if(appDelegate.bLogin==false) { LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"]; // loginvc.delegate = self; // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种 loginvc.returnValue = ^(bool blogin){ // UIApplication * app = [UIApplication sharedApplication]; // AppDelegate *appDelegate = (AppDelegate *)[app delegate]; if(blogin) { if(appDelegate.user_type==USER_ROLE_EMPLOYEE) { [self checklogin:false]; if(appDelegate.can_create_order) { UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Switch To Cart", nil) message:NSLocalizedString(@"Do you want to switch to a pending order or a new order", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Switch to pending order", nil),NSLocalizedString(@"Switch to new order", nil), nil]; // alert. [alert show]; } else { 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]; // alert. [alert show]; } } else { [self checklogin:true]; } } // self.offset = 0; // [self.content_data removeAllObjects]; // [self loadpage]; // // [[self navigationController] setNavigationBarHidden:YES animated:NO]; }; UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ; // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi]; navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种 [self presentViewController:navi animated:YES completion:^{ // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320); NSLog(@"CreateOrderViewController present........."); // self.btop = false; // <#code#> }]; } else { if(appDelegate.user_type==USER_ROLE_EMPLOYEE&&/*appDelegate.contact_id==nil&&*/appDelegate.order_code==nil) { [self checklogin:false]; if(appDelegate.can_create_order) { UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Switch to cart", nil) message:NSLocalizedString(@"Do you want to Switch to a pending order or a new order", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Switch to pending order", nil),NSLocalizedString(@"Switch to new order", nil), nil]; // alert. [alert show]; } else { 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]; // alert. [alert show]; } } else { self.previous_VC = self.current_VC; [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve]; } } } -(void) switchToOrder { if([self.current_VC isKindOfClass:[OrderListViewController class]]) return; UIApplication * app = [UIApplication sharedApplication]; AppDelegate *appDelegate = (AppDelegate *)[app delegate]; if(appDelegate.bLogin==false) { LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"]; // loginvc.delegate = self; // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种 loginvc.returnValue = ^(bool blogin){ if(blogin) { [self checklogin:true]; [self flipFromViewController:self.current_VC toViewController:self.orderViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve]; } }; UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ; // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi]; navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种 [self presentViewController:navi animated:YES completion:^{ // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320); NSLog(@"LoginViewController present........."); // self.btop = false; // <#code#> }]; } else [self flipFromViewController:self.current_VC toViewController:self.orderViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve]; } - (IBAction)switchToOrder:(id)sender { [self switchToOrder]; //self.orderViewController =[ self.storyboard instantiateViewControllerWithIdentifier:@"OrderListViewController"]; } #pragma mark - CategoryMenuDelegate -(void)SelectCategory:(NSString *)category { [self switchToCagegory:category]; } - (IBAction)showCategoryMenu:(id)sender { RAViewController * categorymenuVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"RAViewController"]; // categorymenuVC.rootViewController = self; categorymenuVC.CateMenu_delegate = self; // categorymenuVC.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种 // [self presentViewController:categorymenuVC animated:YES completion:^{ // // NSLog(@"login........."); // // <#code#> // }]; UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:categorymenuVC] ; navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种 [self presentViewController:navi animated:YES completion:^{ // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320); NSLog(@"bundle present........."); // self.btop = false; // <#code#> }]; // if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) { // categorymenuVC.providesPresentationContextTransitionStyle = YES; // categorymenuVC.definesPresentationContext = YES; // categorymenuVC.modalPresentationStyle = UIModalPresentationFormSheet; // [self presentViewController:categorymenuVC animated:YES completion:nil]; // } else { // categorymenuVC.modalPresentationStyle = UIModalPresentationFormSheet; // [self presentViewController:categorymenuVC animated:NO completion:nil]; //// self.view.window.rootViewController.modalPresentationStyle = UIModalPresentationFullScreen; // } UIApplication * app = [UIApplication sharedApplication]; AppDelegate *appDelegate = (AppDelegate *)[app delegate]; if(appDelegate.categoryMenu == nil) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSDictionary* category=[iSalesNetwork request_Cagegory]; dispatch_async(dispatch_get_main_queue(), ^{ if([[category valueForKey:@"result"] intValue]==2) { appDelegate.categoryMenu = category; [categorymenuVC SetMenu:appDelegate.categoryMenu ]; } else if([[category valueForKey:@"result"] intValue]==RESULT_NET_ERROR) { [categorymenuVC SetMenu:nil ]; } else { [RAUtils message_alert:[category valueForKey:@"err_msg"] title:@"Load Category Menu" controller:self] ; } }); }); else [categorymenuVC SetMenu:appDelegate.categoryMenu]; } -(NSString*) categoryString:(NSString*) categoryid node:(NSDictionary*) json level:(int) level; { //NSString* idString = [NSString stringWithFormat:@"%d",categoryid]; NSString* categoryString =@">"; int count = [[json valueForKey:@"count"] intValue]; for(int i=0;i"]; categoryString =[categoryString stringByAppendingString: [category_json valueForKey:@"title" ] ]; categoryString = [categoryString stringByAppendingString:[ self categoryString:categoryid node:category_json level:level+1]]; break; } } return categoryString; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (IBAction)openMenu:(UIButton *)sender { [self showMenu]; // [((RootContainerViewController *)self.parentViewController) showMenu]; // SideMenuViewController *sideMenuController = [self.storyboard instantiateViewControllerWithIdentifier:@"SideMenuViewController"]; // if (sideMenuController) { // //[sideMenuController openMenu]; // [UIView animateWithDuration:1.0 animations:^{ sideMenuController.view.alpha = 1.0; // self.view.alpha = 0.0; }]; // } } - (UIImage*)screen_shot { // CGRect r = self.view.frame; // CGRect r1 = self.view.bounds; // double width,height; // // UIInterfaceOrientation orientation =[UIApplication sharedApplication].statusBarOrientation; // ; // if(orientation == UIDeviceOrientationLandscapeLeft ||orientation == UIDeviceOrientationLandscapeRight) // { // width = self.view.frame.size.width>self.view.frame.size.height? self.view.frame.size.width:self.view.frame.size.height; // height =self.view.frame.size.widthself.view.frame.size.height? self.view.frame.size.width:self.view.frame.size.height; // } UIGraphicsBeginImageContext(CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height)); [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return viewImage; } - (IBAction)onhideMenuClick:(id)sender { [self hideMenu]; self.backgroundButton.hidden=true; self.openMenuButton.hidden = false; self.sideMenu.hidden = true; } - (void)hideMenu { CGRect frame ; frame.origin.x = -300; frame.origin.y = 0; frame.size.height = self.view.bounds.size.height; frame.size.width = 364; self.sideMenu.frame=frame; self.sideMenu.hidden = true; self.blurView.alpha = 0; [self.menuButton setImage:[UIImage imageNamed:@"menu_open"] forState:UIControlStateNormal]; self.menuShown = false; self.backgroundButton.hidden=true; self.openMenuButton.hidden = false; } - (void)showMenu { [self.sideMenuTable reloadData]; UIImage* imgsource = [self screen_shot]; self.blurView.alpha = 0; UIImage* imgBlur =[self applyBlurWithRadius:5 sourceImage:imgsource tintColor:[UIColor colorWithWhite:0.2 alpha:0.73] saturationDeltaFactor:1.8 maskImage:nil]; self.blurView.image = imgBlur; // self.blurView.hidden = imgBlur; // [self.sideMenu becomeFirstResponder]; self.sideMenu.hidden = false; self.backgroundButton.hidden=false; CGRect frame ; frame.origin.x = 0; frame.origin.y = 0; frame.size.height = self.view.bounds.size.height; frame.size.width = 364; // [UIView animateWithDuration:1.0 animations:^{ self.sideMenu.frame=frame; // self.blurView.alpha = 1; // [self.menuButton setImage:[UIImage imageNamed:@"menu"] forState:UIControlStateNormal]; // // }]; [UIView animateWithDuration:0.5 animations:^{ self.sideMenu.frame=frame; self.blurView.alpha = 1; } completion:^(BOOL finished) { [self.menuButton setImage:[UIImage imageNamed:@"menu"] forState:UIControlStateNormal]; }]; // UIImage* img= [UIImage imageNamed:@"menu"]; // self.menuButton.imageView.image = nil; self.menuShown = true; } -(void)initMenuItems { UIApplication * app = [UIApplication sharedApplication]; AppDelegate *appDelegate = (AppDelegate *)[app delegate]; self.sideMenuItems = [[NSMutableArray alloc] init]; NSMutableDictionary* map = [[NSMutableDictionary alloc] init]; if(appDelegate.user!=nil) { [map setValue:@"Wishlist" forKey:@"title"]; [map setValue:@"rect_market_news" forKey:@"img"]; [self.sideMenuItems addObject:map.copy]; [map setValue:@"Portfolio" forKey:@"title"]; [map setValue:@"rect_market_news" forKey:@"img"]; [self.sideMenuItems addObject:map.copy]; } // if(appDelegate.user_type==USER_ROLE_EMPLOYEE) { [map setValue:@"Cam Scan" forKey:@"title"]; [map setValue:@"rect_contact_list" forKey:@"img"]; [self.sideMenuItems addObject:map.copy]; } if(appDelegate.user_type==USER_ROLE_EMPLOYEE) { // [map setValue:@"Contact" forKey:@"title"]; // [map setValue:@"rect_contact_list" forKey:@"img"]; // [self.sideMenuItems addObject:map.copy]; [map setValue:@"View Portfolios" forKey:@"title"]; [map setValue:@"rect_pdf_list" forKey:@"img"]; [self.sideMenuItems addObject:map.copy]; } if(appDelegate.can_show_price) { if(appDelegate.price_hidden) [map setValue:@"Show Price" forKey:@"title"]; else [map setValue:@"Hide Price" forKey:@"title"]; [map setValue:@"rect_announcements" forKey:@"img"]; [self.sideMenuItems addObject:map.copy]; } // [map setValue:@"Contact" forKey:@"title"]; // [map setValue:@"rect_market_news" forKey:@"img"]; // [self.sideMenuItems addObject:map.copy]; [map setValue:@"Cache" forKey:@"title"]; [map setValue:@"rect_announcements" forKey:@"img"]; [self.sideMenuItems addObject:map.copy]; // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults]; // [map setValue:@"Message" forKey:@"title"]; // [map setValue:@"rect_search_history" forKey:@"img"]; // [self.sideMenuItems addObject:map.copy]; // [map setValue:@"Scanner Setting" forKey:@"title"]; [map setValue:@"rect_change_password" forKey:@"img"]; [self.sideMenuItems addObject:map.copy]; [map setValue:@"About" forKey:@"title"]; [map setValue:@"rect_change_password" forKey:@"img"]; [self.sideMenuItems addObject:map.copy]; [self.sideMenuTable reloadData]; // } - (UIImage *)applyBlurWithRadius:(CGFloat)blurRadius sourceImage:(UIImage*)sourceImage tintColor:(UIColor *)tintColor saturationDeltaFactor:(CGFloat)saturationDeltaFactor maskImage:(UIImage *)maskImage { // Check pre-conditions. if (sourceImage.size.width < 1 || sourceImage.size.height < 1) { NSLog (@"*** error: invalid size: (%.2f x %.2f). Both dimensions must be >= 1: %@", sourceImage.size.width, sourceImage.size.height, self); return nil; } if (!sourceImage.CGImage) { NSLog (@"*** error: image must be backed by a CGImage: %@", self); return nil; } if (maskImage && !maskImage.CGImage) { NSLog (@"*** error: maskImage must be backed by a CGImage: %@", maskImage); return nil; } CGRect imageRect = { CGPointZero, sourceImage.size }; UIImage *effectImage = sourceImage; BOOL hasBlur = blurRadius > __FLT_EPSILON__; BOOL hasSaturationChange = fabs(saturationDeltaFactor - 1.) > __FLT_EPSILON__; if (hasBlur || hasSaturationChange) { UIGraphicsBeginImageContextWithOptions(sourceImage.size, NO, [[UIScreen mainScreen] scale]); CGContextRef effectInContext = UIGraphicsGetCurrentContext(); CGContextScaleCTM(effectInContext, 1.0, -1.0); CGContextTranslateCTM(effectInContext, 0, -sourceImage.size.height); CGContextDrawImage(effectInContext, imageRect, sourceImage.CGImage); vImage_Buffer effectInBuffer; effectInBuffer.data = CGBitmapContextGetData(effectInContext); effectInBuffer.width = CGBitmapContextGetWidth(effectInContext); effectInBuffer.height = CGBitmapContextGetHeight(effectInContext); effectInBuffer.rowBytes = CGBitmapContextGetBytesPerRow(effectInContext); UIGraphicsBeginImageContextWithOptions(sourceImage.size, NO, [[UIScreen mainScreen] scale]); CGContextRef effectOutContext = UIGraphicsGetCurrentContext(); vImage_Buffer effectOutBuffer; effectOutBuffer.data = CGBitmapContextGetData(effectOutContext); effectOutBuffer.width = CGBitmapContextGetWidth(effectOutContext); effectOutBuffer.height = CGBitmapContextGetHeight(effectOutContext); effectOutBuffer.rowBytes = CGBitmapContextGetBytesPerRow(effectOutContext); if (hasBlur) { // A description of how to compute the box kernel width from the Gaussian // radius (aka standard deviation) appears in the SVG spec: // http://www.w3.org/TR/SVG/filters.html#feGaussianBlurElement // // For larger values of 's' (s >= 2.0), an approximation can be used: Three // successive box-blurs build a piece-wise quadratic convolution kernel, which // approximates the Gaussian kernel to within roughly 3%. // // let d = floor(s * 3*sqrt(2*pi)/4 + 0.5) // // ... if d is odd, use three box-blurs of size 'd', centered on the output pixel. // CGFloat inputRadius = blurRadius * [[UIScreen mainScreen] scale]; NSUInteger radius = floor(inputRadius * 3. * sqrt(2 * M_PI) / 4 + 0.5); if (radius % 2 != 1) { radius += 1; // force radius to be odd so that the three box-blur methodology works. } vImageBoxConvolve_ARGB8888(&effectInBuffer, &effectOutBuffer, NULL, 0, 0, (unsigned int)radius, (unsigned int)radius, 0, kvImageEdgeExtend); vImageBoxConvolve_ARGB8888(&effectOutBuffer, &effectInBuffer, NULL, 0, 0, (unsigned int)radius, (unsigned int)radius, 0, kvImageEdgeExtend); vImageBoxConvolve_ARGB8888(&effectInBuffer, &effectOutBuffer, NULL, 0, 0, (unsigned int)radius, (unsigned int)radius, 0, kvImageEdgeExtend); } BOOL effectImageBuffersAreSwapped = NO; if (hasSaturationChange) { CGFloat s = saturationDeltaFactor; CGFloat floatingPointSaturationMatrix[] = { 0.0722 + 0.9278 * s, 0.0722 - 0.0722 * s, 0.0722 - 0.0722 * s, 0, 0.7152 - 0.7152 * s, 0.7152 + 0.2848 * s, 0.7152 - 0.7152 * s, 0, 0.2126 - 0.2126 * s, 0.2126 - 0.2126 * s, 0.2126 + 0.7873 * s, 0, 0, 0, 0, 1, }; const int32_t divisor = 256; NSUInteger matrixSize = sizeof(floatingPointSaturationMatrix)/sizeof(floatingPointSaturationMatrix[0]); int16_t saturationMatrix[matrixSize]; for (NSUInteger i = 0; i < matrixSize; ++i) { saturationMatrix[i] = (int16_t)roundf(floatingPointSaturationMatrix[i] * divisor); } if (hasBlur) { vImageMatrixMultiply_ARGB8888(&effectOutBuffer, &effectInBuffer, saturationMatrix, divisor, NULL, NULL, kvImageNoFlags); effectImageBuffersAreSwapped = YES; } else { vImageMatrixMultiply_ARGB8888(&effectInBuffer, &effectOutBuffer, saturationMatrix, divisor, NULL, NULL, kvImageNoFlags); } } if (!effectImageBuffersAreSwapped) effectImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); if (effectImageBuffersAreSwapped) effectImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); } // Set up output context. UIGraphicsBeginImageContextWithOptions(sourceImage.size, NO, [[UIScreen mainScreen] scale]); CGContextRef outputContext = UIGraphicsGetCurrentContext(); CGContextScaleCTM(outputContext, 1.0, -1.0); CGContextTranslateCTM(outputContext, 0, -sourceImage.size.height); // Draw base image. CGContextDrawImage(outputContext, imageRect, sourceImage.CGImage); // Draw effect image. if (hasBlur) { CGContextSaveGState(outputContext); if (maskImage) { CGContextClipToMask(outputContext, imageRect, maskImage.CGImage); } CGContextDrawImage(outputContext, imageRect, effectImage.CGImage); CGContextRestoreGState(outputContext); } // Add in color tint. if (tintColor) { CGContextSaveGState(outputContext); CGContextSetFillColorWithColor(outputContext, tintColor.CGColor); CGContextFillRect(outputContext, imageRect); CGContextRestoreGState(outputContext); } // Output image is ready. UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return outputImage; } //- (IBAction)openMenu:(UIButton *)sender { //} #pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.sideMenuItems.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UIApplication * app = [UIApplication sharedApplication]; AppDelegate *appDelegate = (AppDelegate *)[app delegate]; NSString *CellIdentifier = @"SideMenuItem"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; NSString* title = [self.sideMenuItems[indexPath.row] valueForKey:@"title"]; cell.backgroundColor = [UIColor clearColor]; // [cell.backgroundColor:[UIColor clearColor]]; // UIImageView* iv= [[UIImageView alloc] initWithImage:]; cell.textLabel.text = title; cell.detailTextLabel.textColor =[UIColor redColor]; if([title isEqualToString:@"Wishlist"]&&appDelegate.wish_count>0) cell.detailTextLabel.text = [NSString stringWithFormat:@"%ld",appDelegate.wish_count]; else if([title isEqualToString:@"Portfolio"]&&appDelegate.port_count>0) cell.detailTextLabel.text = [NSString stringWithFormat:@"%ld",appDelegate.port_count]; else { cell.detailTextLabel.text =nil; } // cell.imageView.image = [UIImage imageNamed:[self.toolsinfo[indexPath.row] valueForKey:@"img"]]; return cell; } #pragma mark - Table view delegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSString* title = [self.sideMenuItems[indexPath.row] valueForKey:@"title"]; if([title isEqualToString:@"Cache"]) { CacheViewController * settingvc=[ self.storyboard instantiateViewControllerWithIdentifier:@"CacheViewController"]; PopupNavigationController * navi=[[PopupNavigationController alloc] initWithRootViewController:settingvc]; navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种 [self presentViewController:navi animated:YES completion:^{ //NSLog(@"login........."); // <#code#> }]; } else if([title isEqualToString:@"Scanner Setting"]) { UIApplication * app = [UIApplication sharedApplication]; AppDelegate *appDelegate = (AppDelegate *)[app delegate]; UIViewController* active_vc = appDelegate.active_controller; ScannerSettingViewController * gunVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"ScannerSettingViewController"]; // loginvc.delegate = self; // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种 appDelegate.active_controller = gunVC; gunVC.onDismissVC = ^(){ appDelegate.active_controller = active_vc; }; UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:gunVC] ; // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi]; navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种 [self presentViewController:navi animated:YES completion:^{ // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320); NSLog(@"about present........."); // self.btop = false; // <#code#> }]; } else if([title isEqualToString:@"About"]) { AboutViewController * aboutVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"AboutViewController"]; // loginvc.delegate = self; // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种 UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:aboutVC] ; // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi]; navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种 [self presentViewController:navi animated:YES completion:^{ // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320); NSLog(@"about present........."); // self.btop = false; // <#code#> }]; } else if([title isEqualToString:@"Wishlist"]) { [self hideMenu]; [self switchtowishlist]; } else if([title isEqualToString:@"Show Price"]) { UIApplication * app = [UIApplication sharedApplication]; AppDelegate *appDelegate = (AppDelegate *)[app delegate]; [appDelegate set_priceHidden:false]; //appDelegate.price_hidden = false; //[self.sideMenuTable reloadData]; [self initMenuItems]; [self hideMenu]; // if([self.current_VC isKindOfClass:[WatchListViewController class]]) // return; // [self flipFromViewController:self.current_VC toViewController:self.watchListViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve]; } else if([title isEqualToString:@"Hide Price"]) { UIApplication * app = [UIApplication sharedApplication]; AppDelegate *appDelegate = (AppDelegate *)[app delegate]; [appDelegate set_priceHidden:true]; // appDelegate.price_hidden = true; [self initMenuItems]; // [self.sideMenuTable reloadData]; [self hideMenu]; // if([self.current_VC isKindOfClass:[WatchListViewController class]]) // return; // [self flipFromViewController:self.current_VC toViewController:self.watchListViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve]; } else if([title isEqualToString:@"Portfolio"]) { [self hideMenu]; if([self.current_VC isKindOfClass:[PortfolioViewController class]]) return; [self flipFromViewController:self.current_VC toViewController:self.portfolioViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve]; } else if([title isEqualToString:@"View Portfolios"]) { [self hideMenu]; if([self.current_VC isKindOfClass:[PDFListViewController class]]) return; [self flipFromViewController:self.current_VC toViewController:self.pdfListViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve]; } else if([title isEqualToString:@"Contact"]) { // UITableViewCell* cell =(UITableViewCell*) sender.superview.superview; // // NSIndexPath * indexPath = [self.detailTable indexPathForCell:cell]; // // if(indexPath.section!=1) // return ; // // NSLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row); // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]]; // // NSString* product_id = [item_json valueForKey:@"product_id"]; [self hideMenu]; [self switchtocontact]; } else if([title isEqualToString:@"Cam Scan"]) { // UITableViewCell* cell =(UITableViewCell*) sender.superview.superview; // // NSIndexPath * indexPath = [self.detailTable indexPathForCell:cell]; // // if(indexPath.section!=1) // return ; // // NSLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row); // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]]; // // NSString* product_id = [item_json valueForKey:@"product_id"]; [self hideMenu]; // // [self switchtocontact]; ScannerViewController * scannerVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"ScannerViewController"]; [self.navigationController pushViewController:scannerVC animated:true]; } } #pragma mark - UIAlertViewDelegate // Called when a button is clicked. The view will be automatically dismissed after this call returns - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { UIApplication * app = [UIApplication sharedApplication]; AppDelegate *appDelegate = (AppDelegate *)[app delegate]; // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc; if(buttonIndex==alertView.cancelButtonIndex) { } else if(buttonIndex==1) { //open exist OrderListViewController* ovc =[ self.storyboard instantiateViewControllerWithIdentifier:@"OrderListViewController"]; ovc.showNavibar = true; ovc.selectOrder = ^(NSMutableDictionary* order_detail){ if(appDelegate.order_code==nil) { [self neworderforCart]; } else { self.previous_VC = self.current_VC; [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve]; [self checklogin:true]; } }; ovc.init_style = OL_OPEN; ovc.onCancel = ^(){ [self checklogin:true]; }; [self.navigationController pushViewController:ovc animated:true]; } else { //create new; if(appDelegate.customerInfo==nil)// select contact if current contact not exist { ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ]; cvc.showNavibar = true; cvc.contact_type = @"Sales_Order_Customer"; cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){ appDelegate.contact_id=[value valueForKey:@"customer_cid"]; appDelegate.customerInfo = value; if(appDelegate.order_code==nil) [self neworderforCart]; }; cvc.onCancel = ^(){ [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"" controller:self]; }; cvc.onReset = ^(){ [self checklogin:true]; }; [self.navigationController pushViewController:cvc animated:true]; } else { [self neworderforCart]; } } } -(void) neworderforCart { UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Create Order"]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSDictionary* return_json = [iSalesNetwork new_Order]; dispatch_async(dispatch_get_main_queue(), ^{ [waitalert dismissWithClickedButtonIndex:0 animated:FALSE]; if([[return_json valueForKey:@"result"] intValue]==2) { int result=[[return_json valueForKey:@"result"] intValue]; if(result==2) { //successed. NSString* order_code = [return_json valueForKey:@"orderCode"]; AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; appDelegate.order_code = order_code; self.previous_VC = self.current_VC; [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve]; } } else { [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ; } }); }); } @end