// // OLOSettingViewController.m // iSales-UWAVER // // Created by Rui Zhang on 1/7/22. // Copyright © 2022 United Software Applications, Inc. All rights reserved. // #import "OLOSettingViewController.h" #import "AppDelegate.h" #import "RASingleton.h" #import "ContactListViewController.h" #import "MainViewController.h" #import "CustomerEditViewController.h" #import "UploadCell.h" #import "UIView+Toast.h" //#import "ServerSettingViewController.h" #define OOC_OFFLINE_CONTACT 0 #define OOC_ONLINE_CONTACT 1 #define OOC_CREATE_ORDER 10 @interface OLOSettingViewController () @end @implementation OLOSettingViewController - (IBAction)onSetUnlockCode:(id)sender { } - (IBAction)onUpdateLocalData:(id)sender { } - (IBAction)onSetServer:(id)sender { // ServerSettingViewController *loginSettingVC = [[UIStoryboard storyboardWithName:@"OLM" bundle:nil] instantiateViewControllerWithIdentifier:@"ServerSettingViewController"]; // __weak typeof(self) weakself = self; // loginSettingVC.returnValue = ^(NSString *name,NSString *address) { // if (weakself) { // __strong typeof(weakself) strongself = weakself; // AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; // appDelegate.address = address; // weakself.textfieldName.text = name; // weakself.textfieldServer.text = address; //// [strongself.loginTable reloadData]; // } // }; // UINavigationController *settingRootNav = [[UINavigationController alloc] initWithRootViewController:loginSettingVC]; // [self presentViewController:settingRootNav animated:YES completion:nil]; // } - (void)viewDidLoad { [super viewDidLoad]; #ifdef SCANNER_ORDER { self.switch_enable.on=true; } #else { self.switch_enable.on=false; } #endif // Do any additional setup after loading the view. } //- (IBAction)onEnableOLOChanged:(id)sender { // // RASingleton.sharedInstance.enable_OfflineOrder = [self.switch_enable isOn]; //} - (IBAction)onCreateOO:(id)sender { AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; if(appDelegate.user.length<=0) { [RAUtils message_alert:@"Please login first" title:@"Create Offline Order" controller:self]; return; } [self dismissViewControllerAnimated:NO completion:^{ if(self.returnValue) self.returnValue(OOC_CREATE_ORDER); }]; return; // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; // __block bool abort = false; if(appDelegate.contact_id.length<=0) { UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"New Offline Order" message:nil preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"With Offline Contact" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { // if(appDelegate.order_code && appDelegate.order_code.length>0) // { // [RAUtils message_alert:@"Please close current order and try again." title:@"" controller:self]; // } // NSLog(@"new click"); NSMutableDictionary * params= [[NSMutableDictionary alloc] init]; // NSString *path = [[NSBundle mainBundle] pathForResource:@"editContact.json" ofType:nil]; CustomerEditViewController * cuseditVC = [[CustomerEditViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil]; cuseditVC.bnewcustomer=true; cuseditVC.url_type = URL_LOCAL; cuseditVC.request_url=LOCAL_URL_CUSTOMER_INFO_EDIT; cuseditVC.params = params; // cuseditVC.delegate=self; // // if(checked.count==count) // { // orderinfoVC.have_tail = true // } [self dismissViewControllerAnimated:NO completion:^{ [(UINavigationController*)[self parentViewController] pushViewController:cuseditVC animated:false];; }]; // [[self navigationController] setNavigationBarHidden:NO animated:NO]; // [self.navigationController pushViewController:cuseditVC animated:false]; }]; UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"With Online Contact" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; if(appDelegate.order_code && appDelegate.order_code.length>0) { // appDelegate.order_code= nil; // [appDelegate SetSo:nil]; // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc; ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] 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; // self.norefresh = true; [self neworder]; // [main_vc checklogin:true]; // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION]; // // if(self.returnValue) // self.returnValue(value); }; cvc.onCancel = ^(){ // self.norefresh = true; if(appDelegate.customerInfo==nil) { [RAUtils message_alert:@"Cannot create order without customer infomation." title:@"" controller:self]; } else { [self neworder]; } // [main_vc checklogin:true]; }; cvc.onReset = ^(){ // [main_vc checklogin:true]; }; [self.navigationController pushViewController:cvc animated:true]; } else { //create new; if(appDelegate.customerInfo==nil)// select contact if current contact not exist { MainViewController* main_vc=(MainViewController*)appDelegate.main_vc; ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] 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 neworder]; // [main_vc checklogin:true]; // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION]; // // if(self.returnValue) // self.returnValue(value); }; cvc.onCancel = ^(){ [RAUtils message_alert:@"Cannot create order without customer infomation." title:@"" controller:self]; }; cvc.onReset = ^(){ [main_vc checklogin:true]; }; [self.navigationController pushViewController:cvc animated:true]; } else { [self neworder]; } } }]; UIAlertAction *alertCancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { }]; [alertControl addAction:actionOne]; [alertControl addAction:alertthree]; [alertControl addAction:alertCancel]; [self presentViewController:alertControl animated:YES completion:nil]; } else { [self neworder]; } //block代码块取代了delegate //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField) } -(void) neworder { __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Create Order" completion:^{ [RANetwork request_create_order:^(NSMutableDictionary *result) { NSMutableDictionary* return_json =result; [waitalert dismissViewControllerAnimated:YES completion:^{ 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; appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue]; #ifdef RA_NOTIFICATION [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA]; #else MainViewController* main_vc=(MainViewController*)appDelegate.main_vc; [main_vc reloadCart:true immediately:false]; #endif // [self ReloadData]; // [self performSelector:@selector(loadpage) withObject:nil afterDelay:1]; // [self loadpage]; // if(self.shopCartBlock!=nil) // { // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0]; // // // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100); // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect]; // iv.image = img; // // [self.contentView addSubview:iv]; // self.shopCartBlock(iv); // // } } } else { [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Create Order" controller:self] ; } }]; // [waitalert dismissViewControllerAnimated:YES completion:nil]; }]; }]; // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ // // NSDictionary* return_json = [RANetwork new_Order]; // // dispatch_async(dispatch_get_main_queue(), ^{ // [waitalert dismissViewControllerAnimated:YES completion:nil]; // // // 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; // appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue]; // // //#ifdef RA_NOTIFICATION // [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA]; //#else // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc; // [main_vc reloadCart:true immediately:false]; //#endif // // [self ReloadData]; // // // // [self performSelector:@selector(loadpage) withObject:nil afterDelay:1]; // // [self loadpage]; // // // // if(self.shopCartBlock!=nil) // // { // // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0]; // // // // // // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100); // // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect]; // // iv.image = img; // // // [self.contentView addSubview:iv]; // // self.shopCartBlock(iv); // // // // } // // } // } // else // { // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Create Order" controller:self] ; // } // // // // // }); // }); } - (IBAction)onSelectSales:(id)sender { AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; appDelegate.user = @"OLOTEST"; appDelegate.bLogin = true; } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end