// // CreateOrderViewController.m // RedAnt ERP Mobile // // Created by Ray on 8/24/15. // Copyright (c) 2015 United Software Applications, Inc. All rights reserved. // #import "CreateOrderViewController.h" #import "iSalesNetwork.h" #import "MainViewController.h" #define SUBMIT_CONFIRM 123 #define KEEP_TAIL 456 #define CLOSE_ACTION 567 @interface CreateOrderViewController () // static const char associatedkey; @end @implementation CreateOrderViewController -(void) viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; if(appDelegate.can_submit_order) { [self.btnSubmitOrder setImage:[UIImage imageNamed:@"commit"]]; self.btnSubmitOrder.enabled = true; } else { [self.btnSubmitOrder setImage:nil]; self.btnSubmitOrder.enabled = false; } self.navigationController.navigationBarHidden=false; } -(void) download_success { // 用于处理不同child,在成功去的数据后,需要附加的操作。 self.have_tail=[[self.content_data_download valueForKey:@"has_reItem"] boolValue]; NSString* order_customerid=[self getValue:@"customer_cid"]; AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; appDelegate.order_customer_id = order_customerid; } - (void)viewDidLoad { [super viewDidLoad]; UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"close"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(onCloseClick:)]; //[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Close", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onCloseClick:)]; // closeButton.title = @"Close"; self.navigationItem.leftBarButtonItem = closeButton; NSMutableArray * items = [[NSMutableArray alloc]init]; UIBarButtonItem *savebtn = nil;//[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onSaveClick:)]; savebtn = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"save"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(onSaveClick:)]; self.btnSubmitOrder = nil; self.btnSubmitOrder =[[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"commit"] imageWithRenderingMode:UIImageRenderingModeAutomatic] style:UIBarButtonItemStylePlain target:self action:@selector(onCommitOrderClick:)]; self.btnSubmitOrder.tintColor= UIColorFromRGB(0x996633); //savebtn setBackgroundImage:(nullable UIImage *) forState:<#(UIControlState)#> style:<#(UIBarButtonItemStyle)#> barMetrics:<#(UIBarMetrics)#> //[savebtn setImage:[UIImage imageNamed:@"save"] ]; /* UIBarMetricsDefault, UIBarMetricsCompact, UIBarMetricsDefaultPrompt = 101, // Applicable only in bars with the prompt property, such as UINavigationBar and UISearchBar UIBarMetricsCompactPrompt */ // [savebtn setBackgroundImage:[UIImage imageNamed:@"save"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; // UIBarButtonItem *item1 = [[UIBarButtonItem alloc] init]; // item1.title = @"item1"; //// item1.image = [UIImage imageNamed:@"rect_setting"]; // UIBarButtonItem *item2 = [[UIBarButtonItem alloc] init]; //// item2.image = [UIImage imageNamed:@"rect_about"]; // item2.title = @"item2"; UIBarButtonItem *fixedItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; fixedItem.width = 20.0f; AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; if(appDelegate.user_type ==USER_ROLE_EMPLOYEE) { [items addObject:savebtn]; [items addObject:fixedItem]; } [items addObject:self.btnSubmitOrder]; // [items addObject:item2]; self.navigationItem.rightBarButtonItems=items; // self.navigationItem.backBarButtonItem = backButton; // Do any additional setup after loading the view. } - (void)onCommitOrderClick:(id)sender { // get customer info UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Submit Confirm.", nil) message:NSLocalizedString(@"Are you sure to submit order?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil]; alert.tag = SUBMIT_CONFIRM; [alert show]; } - (void)onCloseClick:(UIButton *)sender { UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Choose your action", nil) message:NSLocalizedString(@"", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Switch to cart", nil),@"Switch to order history",NSLocalizedString(@"Close and release order", nil), nil]; alert.tag = CLOSE_ACTION; // alert. [alert show]; // if ([[upparams valueForKey:@"close_on_save"] boolValue]) { // appDelegate.order_code = nil; // // } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (IBAction)onSaveClick:(id)sender { // add params check here. [self.lastedit endEditing:true]; [self.lasttextview endEditing:true]; self.cancommit=true; NSMutableDictionary* upparams=[[NSMutableDictionary alloc] init]; [upparams setValue:[self.params valueForKey:@"cart2Checkbox"] forKey:@"cart2Checkbox"]; int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue]; for(int i=0;i */ }else if([[itemjson valueForKey:@"control"] isEqualToString:@"action"]) { if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"data"]==nil) self.cancommit = false; } else if([[itemjson valueForKey:@"control"] isEqualToString:@"signature"]) { if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"value"]==nil) self.cancommit = false; NSString* valuestr = [itemjson valueForKey:@"value"]; [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]]; } else if([[itemjson valueForKey:@"control"] isEqualToString:@"switch"]) { NSString* valuestr = [itemjson valueForKey:@"value"]; [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]]; NSString* value = [itemjson valueForKey:@"value"]; NSMutableDictionary* boolitem=nil; NSMutableDictionary* subjson=nil; if([value isEqualToString:@"true"]) { boolitem =[[itemjson objectForKey:@"true"] mutableCopy]; } else { boolitem =[[itemjson objectForKey:@"false"] mutableCopy]; } subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy]; if( subjson!=nil /*&& !active*/) { int sub_count = [[subjson valueForKey:@"count"] intValue]; for(int l=0;l=0) { NSUInteger newIndex[] = {indexPath.section, total_row_idx}; NSIndexPath *newPath = [[NSIndexPath alloc] initWithIndexes:newIndex length:2]; // NSLog(@"before refresh %@",NSStringFromCGSize(self.editorTable.contentSize)); [self.editorTable reloadRowsAtIndexPaths:@[newPath]withRowAnimation:UITableViewRowAnimationMiddle]; // NSLog(@"after refresh %@",NSStringFromCGSize(self.editorTable.contentSize)); // CGSize tablecontent =self.editorTable.contentSize; // tablecontent.height=tablecontent.height+self.keyboard_h; // self.editorTable.contentSize=tablecontent; // // // NSLog(@"resize to %@",NSStringFromCGSize(self.editorTable.contentSize)); } // self.content_data = [editor_json mutableCopy]; // self.content_data = [self translate_json:editor_json]; // NSMutableDictionary* content_data1 = [self translate_json:self.content_data]; // [self.editorTable reloadData]; } // // [item_json setValue:@"true" forKey:@"dirty"]; // [item_json setValue:textField.text forKey:@"value"]; } -(float) getprice:(NSString*) name section :(long) index { NSMutableDictionary* section_json=nil; section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",index ]] mutableCopy]; int count=0; count=[[section_json valueForKey:@"count"] intValue]; for(int i=0;i */ }else if([[itemjson valueForKey:@"control"] isEqualToString:@"action"]) { if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"data"]==nil) self.cancommit = false; } else if([[itemjson valueForKey:@"control"] isEqualToString:@"signature"]) { if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"value"] ==nil) self.cancommit = false; NSString* valuestr = [itemjson valueForKey:@"value"]; [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]]; } else if([[itemjson valueForKey:@"control"] isEqualToString:@"switch"]) { NSString* valuestr = [itemjson valueForKey:@"value"]; [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]]; NSString* value = [itemjson valueForKey:@"value"]; NSMutableDictionary* boolitem=nil; NSMutableDictionary* subjson=nil; if([value isEqualToString:@"true"]) { boolitem =[[itemjson objectForKey:@"true"] mutableCopy]; } else { boolitem =[[itemjson objectForKey:@"false"] mutableCopy]; } subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy]; if( subjson!=nil /*&& !active*/) { int sub_count = [[subjson valueForKey:@"count"] intValue]; for(int l=0;l