// // CustomerInfoViewController.m // RedAnt ERP Mobile // // Created by Ray on 9/10/15. // Copyright (c) 2015 United Software Applications, Inc. All rights reserved. // #import "CustomerInfoViewController.h" #import "iSalesNetwork.h" #import "CustomerEditViewController.h" #import "MainViewController.h" @interface CustomerInfoViewController () @end @implementation CustomerInfoViewController - (void)onEditClick:(id)sender { NSMutableDictionary * params= [[NSMutableDictionary alloc] init]; [params setValue:self.contactId forKey:@"contact_id"]; CustomerEditViewController * cuseditVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"CustomerEditViewController"]; cuseditVC.bnewcustomer=false; cuseditVC.url_type = URL_REMOTE; cuseditVC.request_url=URL_EDIT_CUSTOMER; cuseditVC.params = params; cuseditVC.delegate=self; [[self navigationController] setNavigationBarHidden:NO animated:NO]; [self.navigationController pushViewController:cuseditVC animated:false]; } - (void)onAssignClick:(id)sender { [self.lastedit endEditing:true]; [self.lasttextview endEditing:true]; // [self.navigationController popViewControllerAnimated:(false)]; int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue]; // NSMutableDictionary* data = [[self.data_init objectForKey:@"customerInfo"] mutableCopy]; for(int i=0;i0) { //当前已打开订单则关闭订单。 UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure to release order and reset contact?" message:nil preferredStyle:UIAlertControllerStyleAlert]; //block代码块取代了delegate UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) { UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Release Order"]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSDictionary* order_json = [iSalesNetwork release_Order:appDelegate.order_code]; dispatch_async(dispatch_get_main_queue(), ^{ [waitalert dismissWithClickedButtonIndex:0 animated:FALSE]; if([[order_json valueForKey:@"result"] intValue]==2) { AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; // appDelegate.order_code = nil; [appDelegate closeOrder]; [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false]; [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false]; [self.navigationController popToRootViewControllerAnimated:false]; } else { [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Release Order" controller:self] ; } }); }); }]; UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { NSLog(@"Cancel"); }]; [alertControl addAction:actionOne]; [alertControl addAction:alertthree]; [self presentViewController:alertControl animated:YES completion:nil]; } else { //询问并清空当前的全局contact_id、customer UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure to reset contact?" message:nil preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) { appDelegate.contact_id=nil; appDelegate.customerInfo = nil; [self.navigationController popViewControllerAnimated:(false)]; }]; UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { NSLog(@"Cancel"); }]; [alertControl addAction:actionOne]; [alertControl addAction:alertthree]; [self presentViewController:alertControl animated:YES completion:nil]; } } - (void)viewDidLoad { [super viewDidLoad]; [[self navigationController] setNavigationBarHidden:NO animated:NO]; if(self.rightbtn_title!=nil) [ self.right_btn setTitle:self.rightbtn_title]; // UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Back", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onBackClick:)]; // // closeButton.title = @"Close"; UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector( onBackClick:)]; self.navigationItem.leftBarButtonItem = backButton; NSMutableArray * items = [[NSMutableArray alloc]init]; self.btn_edit = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"edit"] imageWithRenderingMode:UIImageRenderingModeAutomatic] style:UIBarButtonItemStylePlain target:self action:@selector(onEditClick:)];//[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Download", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onDownloadOrderClick:)]; self.btn_edit.tintColor = UIColorFromRGB(0x996633); self.btn_assign = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"assign"] imageWithRenderingMode:UIImageRenderingModeAutomatic] style:UIBarButtonItemStylePlain target:self action:@selector(onAssignClick:)];//[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Download", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onDownloadOrderClick:)]; self.btn_assign.tintColor = UIColorFromRGB(0x996633); self.btn_reset = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"reset"] imageWithRenderingMode:UIImageRenderingModeAutomatic] style:UIBarButtonItemStylePlain target:self action:@selector(onResetClick:)];//[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Download", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onDownloadOrderClick:)]; self.btn_reset.tintColor = UIColorFromRGB(0x996633); // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; if(self.edit_icon) [items addObject:self.btn_edit]; if(self.assig_icon) [items addObject:self.btn_assign]; if(self.reset_icon) [items addObject:self.btn_reset]; self.navigationItem.rightBarButtonItems=items; if (self.data_init==nil) { UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Loading Contact information"]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSDictionary* editor_json = [iSalesNetwork request_CustomerInfo:self.contactId]; dispatch_async(dispatch_get_main_queue(), ^{ [waitalert dismissWithClickedButtonIndex:0 animated:FALSE]; if([[editor_json valueForKey:@"result"] intValue]==2) { self.data_init = [[editor_json objectForKey:@"customerInfo" ] mutableCopy]; [self fillData]; self.btn_assign.enabled=true; } else { [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Loading Contact Information" controller:self] ; self.btn_assign.enabled=false; } }); }); } else { [self fillData]; } // Do any additional setup after loading the view. } - (void)onBackClick:(UIButton *)sender { [self.lastedit endEditing:true]; [self.lasttextview endEditing:true]; NSMutableDictionary* back_data = [self.data_init mutableCopy]; // [self.navigationController popViewControllerAnimated:(false)]; int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue]; // NSMutableDictionary* data = [[self.data_init objectForKey:@"customerInfo"] mutableCopy]; for(int i=0;i