// // 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;l0) // { // // [alert dismissWithClickedButtonIndex:0 animated:FALSE]; // //[self downloadpdf:pdf_url]; // // // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout) // { // //bbb // [((MainViewController*)appDelegate.main_vc) Loginout:false]; // } // // [self prepareReturn:nil]; // // [self.navigationController popViewControllerAnimated:true]; // // [appDelegate printPdf:pdf_url]; //// if(self.printPdfCallback) //// self.printPdfCallback(pdf_url); // } // else { if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout) { //bbb [((MainViewController*)appDelegate.main_vc) Loginout:false]; } [self prepareReturn:nil]; [self.navigationController popViewControllerAnimated:true]; if(pdf_url.length>0) { [alert dismissWithClickedButtonIndex:0 animated:FALSE]; [appDelegate printPdf:pdf_url]; } } } else { [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Submit Order" controller:self] ; } }); }); } else { UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Retain models", nil) message:NSLocalizedString(@"There are some models left in cart,do you want to keep them?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil]; alert.tag = KEEP_TAIL; self.upparams = upparams; [alert show]; } } else { //USER_ROLE_CUSTOMER // if(self.have_tail) // [upparams setValue:@"true" forKey:@"isHold"]; // else // [upparams setValue:@"false" forKey:@"isHold"]; UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Submit Order"]; [upparams setValue:@"true" forKey:@"isHold"]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:upparams]; dispatch_async(dispatch_get_main_queue(), ^{ [waitalert dismissWithClickedButtonIndex:0 animated:FALSE]; if([[editor_json valueForKey:@"result"] intValue]==2) { // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table]; AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; // appDelegate.customerInfo = customerInfo; NSString* orderCode = [editor_json valueForKey:@"orderCode"]; appDelegate.order_code = orderCode; [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false]; UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Submit successful." message:[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; [alert show]; // // self.labelContact.text=appDelegate.contact_name; // // NSDictionary * customerinfo = appDelegate.customerInfo; [self prepareReturn:nil]; [self.navigationController popViewControllerAnimated:true]; // [self.navigationController dismissViewControllerAnimated:true completion:^{ // // // ; // }]; } else { [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Submit Order" controller:self] ; } }); }); } }]; UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { //NSLog(@"Cancel"); }]; [alertControl addAction:actionOne]; [alertControl addAction:alertthree]; //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField) [self presentViewController:alertControl animated:YES completion:nil]; } else { commit_order: { AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; if(appDelegate.user_type ==USER_ROLE_EMPLOYEE ) { if(/*!self.have_tail*/ true) {UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Submit Order"]; [upparams setValue:@"false" forKey:@"isHold"]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:upparams]; dispatch_async(dispatch_get_main_queue(), ^{ [waitalert dismissWithClickedButtonIndex:0 animated:FALSE]; if([[editor_json valueForKey:@"result"] intValue]==2) { //debug bbb // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table]; AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; // appDelegate.customerInfo = customerInfo; // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"]; // appDelegate.order_code = nil; [appDelegate closeOrder]; [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false]; UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Submit successful." message:[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; [alert show]; NSString* pdf_url = [editor_json valueForKey:@"pdf_url"]; // if(pdf_url.length>0) // { // // [alert dismissWithClickedButtonIndex:0 animated:FALSE]; //// [self downloadpdf:pdf_url]; // // // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout) // { // //bbb // [((MainViewController*)appDelegate.main_vc) Loginout:false]; // } // // [self prepareReturn:nil]; // // [self.navigationController popViewControllerAnimated:true]; // // [appDelegate printPdf:pdf_url]; // //// if(self.printPdfCallback) //// self.printPdfCallback(pdf_url); // } // else { if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout) { //bbb [((MainViewController*)appDelegate.main_vc) Loginout:false]; } [self prepareReturn:nil]; [self.navigationController popViewControllerAnimated:true]; if(pdf_url.length>0) { [alert dismissWithClickedButtonIndex:0 animated:FALSE]; [appDelegate printPdf:pdf_url]; } } // // self.labelContact.text=appDelegate.contact_name; // // NSDictionary * customerinfo = appDelegate.customerInfo; } else { [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Submit Order" controller:self] ; } }); }); } else { UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Retain models", nil) message:NSLocalizedString(@"There are some models left in cart,do you want to keep them?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil]; alert.tag = KEEP_TAIL; self.upparams = upparams; [alert show]; } } else { //USER_ROLE_CUSTOMER // if(self.have_tail) // [upparams setValue:@"true" forKey:@"isHold"]; // else // [upparams setValue:@"false" forKey:@"isHold"]; UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Submit Order"]; [upparams setValue:@"true" forKey:@"isHold"]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:upparams]; dispatch_async(dispatch_get_main_queue(), ^{ [waitalert dismissWithClickedButtonIndex:0 animated:FALSE]; if([[editor_json valueForKey:@"result"] intValue]==2) { // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table]; AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; // appDelegate.customerInfo = customerInfo; NSString* orderCode = [editor_json valueForKey:@"orderCode"]; appDelegate.order_code = orderCode; [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false]; UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Submit successful." message:[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; [alert show]; // // self.labelContact.text=appDelegate.contact_name; // // NSDictionary * customerinfo = appDelegate.customerInfo; [self prepareReturn:nil]; // [self.navigationController dismissViewControllerAnimated:true completion:^{ // // // ; // }]; [self.navigationController popViewControllerAnimated:true]; } else { [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Submit Order" controller:self] ; } }); }); } } } } // else if( alertView.tag == KEEP_TAIL) // {UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Submit Order"]; // if(buttonIndex!=alertView.cancelButtonIndex) // {//keep tail; // // [self.upparams setValue:@"true" forKey:@"isHold"]; // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ // // NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:self.upparams]; // // dispatch_async(dispatch_get_main_queue(), ^{ // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE]; // // // if([[editor_json valueForKey:@"result"] intValue]==2) // { // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table]; // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Submit successful." message:[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; // // [alert show]; // // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; // appDelegate.customerInfo = customerInfo; // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"]; // NSString* orderCode = [editor_json valueForKey:@"orderCode"]; // appDelegate.order_code = orderCode; // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false]; // // // self.labelContact.text=appDelegate.contact_name; // // // // NSDictionary * customerinfo = appDelegate.customerInfo; // [self prepareReturn:nil]; //// [self.navigationController dismissViewControllerAnimated:true completion:^{ //// //// //// ; //// }]; // [self.navigationController popViewControllerAnimated:true]; // // } // else // { // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Submit Order" controller:self] ; // } // // // // // }); // }); // } // else // {// not keep tail; // [self.upparams setValue:@"false" forKey:@"isHold"]; // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ // // NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:self.upparams]; // // dispatch_async(dispatch_get_main_queue(), ^{ // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE]; // // // if([[editor_json valueForKey:@"result"] intValue]==2) // { // // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table]; // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Submit successful." message:[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; // // [alert show]; // // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; // // appDelegate.customerInfo = customerInfo; // // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"]; // // appDelegate.order_code = nil; // [appDelegate closeOrder]; // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false]; // // // self.labelContact.text=appDelegate.contact_name; // // // // NSDictionary * customerinfo = appDelegate.customerInfo; // [self prepareReturn:nil]; //// [self.navigationController dismissViewControllerAnimated:true completion:^{ //// //// //// ; //// }]; // [self.navigationController popViewControllerAnimated:true]; // // } // else // { // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Submit Order" controller:self] ; // } // // // // // }); // }); // } // } else if(alertView.tag == CLOSE_ACTION) { if(buttonIndex==1) { [self.navigationController popViewControllerAnimated:true]; // back to cart; // [self.navigationController dismissViewControllerAnimated:true completion:^{ // ; // }]; // if ([[upparams valueForKey:@"close_on_save"] boolValue]) { // appDelegate.order_code = nil; // // } } if(buttonIndex==2) { [self.navigationController popViewControllerAnimated:true]; AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false]; [((MainViewController*)appDelegate.main_vc) switchToOrder]; // back to cart; // [self.navigationController dismissViewControllerAnimated:true completion:^{ // ; // }]; // if ([[upparams valueForKey:@"close_on_save"] boolValue]) { // appDelegate.order_code = nil; // // } } else if(buttonIndex==3) { // close order; AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; 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) reloadCart:true immediately:false]; [((MainViewController*)appDelegate.main_vc) switchToHome]; if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout) { [((MainViewController*)appDelegate.main_vc) Loginout:false]; } [self prepareReturn:nil]; [self.navigationController popViewControllerAnimated:true]; // [self.navigationController dismissViewControllerAnimated:true completion:^{ // ; // }]; } else { [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order"controller:self] ; } }); }); // // } } } } // // //-(void) downloadpdf:(NSString* )url //{ // UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Printing..."]; // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ // // // NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60*5]; // // //设置请求方式为get // // [request setHTTPMethod:@"GET"]; // // //添加用户会话id // // [request addValue:@"text/html" forHTTPHeaderField:@"Content-Type"]; // // //连接发送请求 // // // NSHTTPURLResponse* urlResponse = nil; // // NSError *error = [[NSError alloc] init]; // // NSData* content= [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error]; // // // self.filename = [urlResponse suggestedFilename]; // // // dispatch_async(dispatch_get_main_queue(), ^{ // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE]; // // self.navigationItem.title = self.save_name; // // UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200]; // // self.content=nil; // if(content!=nil&&content.length>0) // { // // // [self startAirPrintWithData:content]; // // // } // else // { // [RAUtils message_alert:nil title:@"Open PDF Failed" controller:self]; // // self.content = [self.url dataUsingEncoding:NSUTF8StringEncoding]; // } // // ; // // NSLog(@"%@",[[NSString alloc] initWithData:self.content encoding:NSASCIIStringEncoding]); // // // // // // [self.webView loadData:self.content MIMEType:urlResponse.MIMEType textEncodingName:nil baseURL:nil]; // // // // // }); // }); //} // //- (void)startAirPrintWithData:(id )data //{ // // // // // UIPrintInteractionController* airPrinterController=[UIPrintInteractionController sharedPrintController]; // UIPrintInfo *printInfo = [UIPrintInfo printInfo]; // printInfo.outputType = UIPrintInfoOutputGeneral; // printInfo.orientation = UIPrintInfoOrientationPortrait; // printInfo.jobName = @"CoolVisitAirPrint"; // airPrinterController.printInfo = printInfo; // airPrinterController.printingItem = data; // airPrinterController.delegate = self; // // // airPrinterController.showsNumberOfCopies=true; // airPrinterController.showsPageRange = true; // airPrinterController.showsPaperSelectionForLoadedPapers=true; // // void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) { // if(completed && error) // NSLog(@"Printing failed due to error in domain %@ with error code %lu. Localized description: %@, and failure reason: %@", error.domain, (long)error.code, error.localizedDescription, error.localizedFailureReason); // }; // // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; // // UIPrinter *airPrinter = [UIPrinter printerWithURL:[NSURL URLWithString:appDelegate.printerURL] ];///*self.printer;*/ // // // // // [[UIPrinter printerWithURL:[NSURL URLWithString:appDelegate.printerURL]] contactPrinter:^(BOOL available) // { // if (available&& appDelegate.printerURL.length>0) // { // // [airPrinterController printToPrinter:airPrinter completionHandler:completionHandler]; // NSLog(@"AIRPRINTER AVAILABLE"); // } // else // { // // // [airPrinterController presentFromRect:CGRectMake(0, 0, 300, 500) inView:self.view animated:YES completionHandler: // // // // // // // // // [printPicker presentAnimated:YES completionHandler: // // ^(UIPrintInteractionController *printerController, BOOL userDidSelect, NSError *error) // // { // // if (userDidSelect) // // { // // NSString* sid= printerController.printInfo.printerID; // // UIPrintPaper*paper= printerController.printPaper; // // // // } // // }]; // // // NSLog(@"AIRPRINTER NOT AVAILABLE"); // // // // if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1) // { // UIPrinterPickerController *printPicker = [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:nil]; // // [printPicker presentFromBarButtonItem:self.btnSubmitOrder animated:yes completionHandler: // // // // [ printPicker presentFromBarButtonItem:self.btnSubmitOrder animated:YES completionHandler: // // // // [printPicker presentFromRect:CGRectMake(0, 0, 300, 500) inView:self.view animated:YES completionHandler: // // // // // [printPicker presentAnimated:YES completionHandler: // ^(UIPrinterPickerController *printerPicker, BOOL userDidSelect, NSError *error) // { // if (userDidSelect) // { // //User selected the item in the UIPrinterPickerController and got the printer details. // // [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:printerPicker.selectedPrinter]; // // //Here you will get the printer and printer details.ie, // // printerPicker.selectedPrinter, printerPicker.selectedPrinter.displayName, printerPicker.selectedPrinter.URL etc. So you can display the printer name in your label text or button title. // // // // // appDelegate.printerURL =printerPicker.selectedPrinter.URL.absoluteString; // // [self startAirPrintWithData:data]; // // } // else // { // // // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout) // { // // [((MainViewController*)appDelegate.main_vc) Loginout:false]; // } // [self prepareReturn:nil]; // // [self.navigationController popViewControllerAnimated:true]; // } // }]; // } // } // }]; // // // //} // //#pragma mark - UIPrintInteractionControllerDelegate //- (UIPrintPaper *)printInteractionController:(UIPrintInteractionController *)printInteractionController choosePaper:(NSArray *)paperList //{ // // ; // // // (int) width = 29700 // // Printing description of (*( (int *)0x7caa3a40)): // // (int) height = 42000 // //设置纸张大小 // // // for(UIPrintPaper* paper in paperList) // { // if (CGSizeEqualToSize(paper.paperSize, CGSizeMake(612, 792))) // return paper; // // } // CGSize paperSize = CGSizeMake(612, 792); // UIPrintPaper * p=[UIPrintPaper bestPaperForPageSize:paperSize withPapersFromArray:paperList]; // return p; //} //- (void)printInteractionControllerWillPresentPrinterOptions:(UIPrintInteractionController *)printInteractionController //{ // //} //- (void)printInteractionControllerDidPresentPrinterOptions:(UIPrintInteractionController *)printInteractionController //{ // //} //- (void)printInteractionControllerWillDismissPrinterOptions:(UIPrintInteractionController *)printInteractionController //{ // //} //- (void)printInteractionControllerDidDismissPrinterOptions:(UIPrintInteractionController *)printInteractionController //{ // //} // //- (void)printInteractionControllerWillStartJob:(UIPrintInteractionController *)printInteractionController //{ // //} //- (void)printInteractionControllerDidFinishJob:(UIPrintInteractionController *)printInteractionController //{ // // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout) // { // // [((MainViewController*)appDelegate.main_vc) Loginout:false]; // } // // [self prepareReturn:nil]; // // [self.navigationController popViewControllerAnimated:true]; //} @end