| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879 |
- //
- // LoginSettingViewController.m
- // RA Image
- //
- // Created by Jack on 2017/4/27.
- // Copyright © 2017年 USAI. All rights reserved.
- //
- #import "ServerSettingViewController.h"
- //#import "ScannerViewController.h"
- #import "RAQRCodeScannerViewController.h"
- #import "RAUtils.h"
- #import "RAUploadManager.h"
- #import "AppDelegate.h"
- #import "RADataProvider.h"
- #import "ZipArchive.h"
- #import "AboutViewController.h"
- #import "WebViewController.h"
- #import "MainViewController.h"
- #import "ChangePasswordViewController.h"
- #import "SetupServerViewController.h"
- #import "PriceGroupListViewController.h"
- @interface ServerSettingViewController ()<UITextFieldDelegate>
- @property (strong, nonatomic) IBOutlet UITextField *nameTextField;
- //@property (strong, nonatomic) IBOutlet UITextField *internalTextField;
- @property (strong, nonatomic) NSString *internalText;
- @property (nonatomic,copy) NSString *checkedAddress;
- @end
- @implementation ServerSettingViewController
- - (IBAction)onAboutClick:(id)sender {
-
-
- AboutViewController * aboutVC =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"AboutViewController"];
- // loginvc.delegate = self;
- // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
-
-
- UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:aboutVC] ;
-
-
-
-
- // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
-
- navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
- [self presentViewController:navi animated:YES completion:^{
-
- // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
-
- DebugLog(@"about present.........");
-
- // self.btop = false;
- // <#code#>
- }];
-
-
- //
- //
- // 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);
- //
- // DebugLog(@"about present.........");
- //
- // // self.btop = false;
- // // <#code#>
- // }];
- }
- - (IBAction)onPrivacyClick:(id)sender {
-
- NSString* url = URL_PRIVACY;
-
- NSString* title = @"Privacy Policy";
-
- WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
- ViewController.url = url;
- ViewController.title = title;
- [self.navigationController pushViewController:ViewController animated:YES];
- }
- -(void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
- // if(appDelegate.price_group.length>0)
- self.labelPriceGroup.text =appDelegate.price_group;
- // else
- // {
- // [RADataProvider default_price_group];
- // self.labelPriceGroup.text =appDelegate.price_group;
- //
- // }
- if(appDelegate.user==nil)
- self.btnSetPriceGroup.hidden =true;
- else
- self.btnSetPriceGroup.hidden =false;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- NSDictionary *addressDic = [[NSUserDefaults standardUserDefaults] valueForKey:@"ScanAddress"];
- if([RADataProvider scanRtime]&& addressDic!=nil)
- {
- _btnSetServer.hidden=true;
- }
- else
- _btnSetServer.hidden = false;
-
-
- // _btnSetServer.hidden = false;
-
- // return;
- // Do any additional setup after loading the view.
- // UIView *v = [UIView new];
- // [self.view insertSubview:v atIndex:0];
-
- // self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStylePlain target:self action:@selector(doneItemClick:)];
- // self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Scan" style:UIBarButtonItemStylePlain target:self action:@selector(scanItemClick:)];
- //
- [self loadAddress];
- // [self registListenKeyboard];
-
-
-
-
- RAUPloadManagerConfigure *configure = [[RAUPloadManagerConfigure alloc] init];
-
- self.autoSwitch.on = configure.autoUpload;
- // self.autoRmFinishSwitch.on = autoRmFinish;
- // self.autoRmErrorSwith.on = autoRmErr;
- self.retryCountBox.text = [NSString stringWithFormat:@"%d",configure.retryCount];
-
- self.retryTimeIntervalBox.text = [NSString stringWithFormat:@"%d",(int)configure.retryTimeIntetval];
-
-
- [self loadTemplate];
-
-
-
-
-
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- - (id)userDefaultsValue:(NSString *)key {
-
- return [[NSUserDefaults standardUserDefaults] valueForKey:key];
-
- }
- - (void)loadAddress {
- NSDictionary *addressDic = [self userDefaultsValue:kScanAddress];
- if (addressDic) {
- NSString* ia=addressDic[@"internalAddress"];
- NSString* ea=addressDic[@"externalAddress"];
- NSString* sa=addressDic[@"serverAddress"];
- if(sa.length==0)
- {
- if(ea.length>0)
- sa=ea;
- else if(ia.length>0)
- sa=ia;
- }
- self.internalText= sa;
- self.nameTextField.text = [addressDic objectForKey:@"show_name"];
- // RASingleton.sharedInstance.price_index =[addressDic[@"price_type"] intValue];
- // NSUInteger selectedIndex = [[addressDic objectForKey:@"selectedIndex"] integerValue];
- // switch (selectedIndex) {
- // case 0:
- // case 1: {
- // [self internalCheckBtnClick:self.internalCheckBtn];
- // }
- // break;
- // case 2: {
- // [self externalCheckBtnClick:self.externalCheckBtn];
- // }
- // break;
- //
- // default:
- // break;
- // }
- } else {
- // [self internalCheckBtnClick:self.internalCheckBtn];
- }
- }
- - (void)loadTemplate {
- NSDictionary *addressDic = [self userDefaultsValue:@"ScanTemplate"];
- if (addressDic) {
- NSString* updatetime=addressDic[@"updatetime"];
- self.labelUpdate.text = updatetime;
- }
- }
- #pragma mark - Button Click
- - (void)doneItemClick:(UIBarButtonItem *)sender {
- self.checkedAddress = nil;
- NSUInteger selectedIndex = 1;
- self.checkedAddress = self.internalText;
- // if (self.internalCheckBtn.selected) {
- // self.checkedAddress = self.internalTextField.text;
- // selectedIndex = 1;
- // }
- // if (self.externalCheckBtn.selected) {
- // self.checkedAddress = self.externalTextField.text;
- // selectedIndex = 2;
- // }
-
- // if (self.returnValue) {
- // self.returnValue(self.nameTextField.text, self.checkedAddress);
- // }
- __weak typeof(self) weakself = self;
- [self.navigationController dismissViewControllerAnimated:YES completion:^{
- if (weakself.checkedAddress.length) {
- // 保存信息
- NSString *name = weakself.nameTextField.text;
- NSString *internalAddr = weakself.internalText;
- // NSString *externalAddr = weakself.externalTextField.text;
- NSMutableDictionary *addressDic = [NSMutableDictionary dictionary];
- if (internalAddr.length) {
- [addressDic setObject:internalAddr forKey:@"serverAddress"];
- }
- // if (externalAddr.length) {
- // [addressDic setObject:externalAddr forKey:@"externalAddress"];
- // }
- if (name.length) {
- [addressDic setObject:name forKey:@"name"];
- }
- [addressDic setObject:@(selectedIndex) forKey:@"selectedIndex"];
- [weakself setUserDefaultsValue:addressDic forKey:kScanAddress];
- }
- }];
- }
- - (void)setUserDefaultsValue:(id)value forKey:(NSString *)key {
- NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
- [userDefaults setValue:value forKey:key];
- [userDefaults synchronize];
- }
- - (IBAction)onUnlockCodeClick:(id)sender {
-
- }
- - (IBAction)onUpdateClick:(id)sender {
-
- if(self.internalText.length>0)
- {
-
- [RADataProvider updateTemplate:self];
- return;
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *documents = [paths objectAtIndex:0];
-
- [RAUtils deletefiles:[documents stringByAppendingPathComponent:@"download"]];
- RASingleton.sharedInstance.scan_list = nil;
- [RADataProvider load_scan_models];
-
- // NSString* file_name=[appDelegate.downloadurl lastPathComponent];
- __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Update local data" completion:^{
- dispatch_async(dispatch_get_global_queue(0, 0), ^{
-
-
- NSData* download_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:appDelegate.downloadurl]];
- dispatch_async(dispatch_get_main_queue(), ^{
-
- [waitalert dismissViewControllerAnimated:false completion:^{
- if(download_data!=nil)
- {
-
- NSString* file_name=[appDelegate.downloadurl lastPathComponent];
- NSString* path = [documents stringByAppendingPathComponent:file_name];
- [RAUtils saveData:download_data toPath:path];
-
- ZipArchive* zip = [[ZipArchive alloc] init];
- NSString* unZipTo=[documents stringByAppendingPathComponent:@"download"];
- // NSFileManager* fileManager=[NSFileManager defaultManager];
- // [fileManager removeItemAtPath:unZipTo error:nil];
- // NSString *unZipTo = [temp stringByAppendingPathComponent:unziplocation];
- //
- // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- // NSString *documentPath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
- //NSString* zipFile = [documentPath stringByAppendingString:@"/images.zip"] ;
- // NSString* unZipTo = img_cache;//[documentPath stringByAppendingString:@"/images"] ;
-
- DebugLog(@"path: %@",unZipTo);
- if( [zip UnzipOpenFile:path Password:nil] ){
- BOOL result = [zip UnzipFileTo:unZipTo overWrite:YES];
- if( NO==result )
- {
- // int aaa=0;
- //解压失败
-
- [zip UnzipCloseFile];
- //文件损坏,删除文件重试
-
-
- NSFileManager* fileManager=[NSFileManager defaultManager];
- //debug
- // BOOL blDele= [fileManager removeItemAtPath:zipFile error:nil];
- [fileManager removeItemAtPath:path error:nil];
- [fileManager removeItemAtPath:unZipTo error:nil];
-
- [RAUtils message_alert:@"Can not unzip template file, please try download again." title:@"Warrning" controller:self];
-
-
-
-
- }
- else
- {
- [zip UnzipCloseFile];
-
-
- NSFileManager *fileManager = [NSFileManager defaultManager];
- [fileManager removeItemAtPath:path error:nil];
- [RAUtils message_alert:@"Update template file successful." title:@"Message" controller:self];
-
- // [RADataProvider encrypt_scan_models];
- NSMutableDictionary *templateDic = [NSMutableDictionary dictionary];
- NSString* datetime= [RAUtils current_date_time];
- templateDic[@"updatetime"]= datetime;
- [self setUserDefaultsValue:templateDic forKey:@"ScanTemplate"];
- [self loadTemplate];
- [RADataProvider load_scan_models];
- [RADataProvider default_price_group];
-
- }
- //[zip UnzipCloseFile];
- }
- else
- {
- //打开文件失败,通常是文件路径有问题或密码错误。
- [RAUtils message_alert:@"Can not unzip template file, please contact the Administrator." title:@"Warrning" controller:self];
-
- // NSFileManager *fileManager = [NSFileManager defaultManager];
- // [fileManager removeItemAtPath:zipFile error:nil];
- }
-
-
- // [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
- //
- // UIImage * img =[UIImage imageWithData:downloadimg_data];
- // cell.imageView.image=img;
- }
- else
- [RAUtils message_alert:@"Can not download template file. Please check online ERP setting or contact your administrator." title:@"Warrning" controller:self];
-
- [ActiveViewController Notify:@"ScanSearchViewController" Message:@"Clear"];
- }];
-
-
- // cell.imageView.image=[UIImage imageNamed:@"notfound_s"];
-
- });
-
- });
- }];
-
-
- // NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:appDelegate.downloadurl]];
- // [RADataProvider downloadFileOffset:0 Param:nil from:appDelegate.downloadurl method:@"post" toPath:[documents stringByAppendingPathComponent:file_name] progressHandler:nil completionHandler:^(NSMutableDictionary *result) {
- // int i=0; ;
- // }];
- }
- else
- {
- [RAUtils message_alert:@"Please setup the server first." title:@"Warrning" controller:self];
- }
- }
- - (IBAction)onScanClick:(id)sender {
- // __weak typeof(self) weakself = self;
- //// ScannerViewController *scannerVC = [[UIStoryboard storyboardWithName:@"cam_scan" bundle:nil] instantiateViewControllerWithIdentifier:@"NewScannerViewController"];
- //// scannerVC.returnCode = ^(NSString *code) {
- //// // 扫描成功保存扫描值
- //// if (weakself) {
- //// __strong typeof(weakself) strongSelf = weakself;
- //// [strongSelf processScanResult:code];
- //// }
- //// };
- //// [self presentViewController:scannerVC animated:YES completion:nil];
- //
- // RAQRCodeScannerViewController *scannerVC = [[UIStoryboard storyboardWithName:@"QRCode" bundle:nil] instantiateViewControllerWithIdentifier:@"RAQRCodeScannerViewControllerAuto"];
- //
- //// RAQRCodeScannerViewController *scannerVC = [RAQRCodeScannerViewController viewControllerFromStoryboard];
- // scannerVC.QRCodeViewControllerDidCompletion = ^(RAQRCodeScannerViewController *qrcodeViewController, NSString *value) {
- //
- // if (weakself) {
- // __strong typeof(weakself) strongSelf = weakself;
- // [strongSelf processScanResult:value];
- //
- //
- // }
- //
- // [qrcodeViewController dismissViewControllerAnimated:YES completion:nil];
- // };
- //
- // scannerVC.QRCodeViewControllerDidCanceled = ^(RAQRCodeScannerViewController *qrcodeViewController) {
- //
- // [qrcodeViewController dismissViewControllerAnimated:YES completion:nil];
- // };
- //
- // [self presentViewController:scannerVC animated:YES completion:nil];
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- if(appDelegate.bLogin)
- {
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Set Server" message:@"Are you sure you to sign out and setup the server?" preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction *action_1 = [UIAlertAction actionWithTitle:@"Sign out and set" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
- //open exist
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
-
-
- appDelegate.cart_count = 0;//[[jsobj :@"cart_count"] intValue];
- appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
- appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
-
- [appDelegate update_count_mark];
-
-
- appDelegate.can_show_price =false;
- appDelegate.can_see_price =false;
- appDelegate.can_create_portfolio =false;
- appDelegate.can_create_order =false;
-
-
- appDelegate.can_cancel_order =false;
- appDelegate.can_set_cart_price =false;
- appDelegate.can_delete_order =false;
- appDelegate.can_submit_order =false;
- appDelegate.can_set_tearsheet_price =false;
- appDelegate.can_update_contact_info = false;
-
- appDelegate.save_order_logout = false;
- appDelegate.submit_order_logout = false;
- appDelegate.alert_sold_in_quantities = false;
-
- appDelegate.ipad_perm =nil ;
- appDelegate.user_type = USER_ROLE_UNKNOWN;
- appDelegate.OrderFilter= nil;
- [appDelegate SetSo:nil];
- [appDelegate set_main_button_panel];
- #ifdef RA_NOTIFICATION
- [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
- #endif
- [appDelegate Logout];
-
- SetupServerViewController * servervc =[[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"SetupServerViewController"];
- servervc.showCancel = true;
- servervc.returnValue = ^{
- NSDictionary *addressDic = [[NSUserDefaults standardUserDefaults] valueForKey:@"ScanAddress"];
- if (addressDic) {
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
- main_vc.labelServer.text = [addressDic objectForKey:@"show_name"];
- self.nameTextField.text = [addressDic objectForKey:@"show_name"];
- self.internalText = [addressDic objectForKey:@"serverAddress"];
- }
- };
- [self.navigationController pushViewController:servervc animated:true];
- }];
- UIAlertAction *action_2 = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
- //create new;
-
- }];
-
- [alertController addAction:action_1];
- [alertController addAction:action_2];
- [self presentViewController:alertController animated:YES completion:nil];
-
-
-
- }
- else
- {
- SetupServerViewController * servervc =[[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"SetupServerViewController"];
- servervc.showCancel = true;
- servervc.returnValue = ^{
- NSDictionary *addressDic = [[NSUserDefaults standardUserDefaults] valueForKey:@"ScanAddress"];
- if (addressDic) {
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
- main_vc.labelServer.text = [addressDic objectForKey:@"show_name"];
- self.nameTextField.text = [addressDic objectForKey:@"name"];
- self.internalText = [addressDic objectForKey:@"serverAddress"];
- }
-
-
- [self onUpdateClick:nil];
- };
- [self.navigationController pushViewController:servervc animated:true];
-
- }
- }
- - (IBAction)onSetPriceGroup:(id)sender {
- PriceGroupListViewController * listvc =[[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"PriceGroupListViewController"];
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
-
-
- NSMutableDictionary* pricegroup=[RADataProvider all_price_group];
- NSMutableArray* arrlist = [NSMutableArray new];
- for(int i=0;i<appDelegate.available_price_group.count;i++)
- {
- if(pricegroup[appDelegate.available_price_group[i]]!=nil)
- [arrlist addObject:appDelegate.available_price_group[i]];
- }
- listvc.pricelist = arrlist;//appDelegate.available_price_group;
- listvc.returnValue = ^(int index) {
- NSString * pricegroup=appDelegate.available_price_group[index];
- self.labelPriceGroup.text =pricegroup;
- appDelegate.price_group = pricegroup;
-
- [ActiveViewController Notify:@"CartViewController" Message:@"RA_NOTIFICATION_CART_REFRESH"];
- // self.server = self.serverlist[index];
- // [self.btnSelectServer setTitle:self.server[@"show_name"] forState:UIControlStateNormal];
- };
- [self.navigationController pushViewController:listvc animated:true];
-
-
- }
- - (void)scanItemClick:(UIBarButtonItem *)sender {
-
- __weak typeof(self) weakself = self;
- // ScannerViewController *scannerVC = [[UIStoryboard storyboardWithName:@"cam_scan" bundle:nil] instantiateViewControllerWithIdentifier:@"NewScannerViewController"];
- // scannerVC.returnCode = ^(NSString *code) {
- // // 扫描成功保存扫描值
- // if (weakself) {
- // __strong typeof(weakself) strongSelf = weakself;
- // [strongSelf processScanResult:code];
- // }
- // };
- // [self presentViewController:scannerVC animated:YES completion:nil];
-
- RAQRCodeScannerViewController *scannerVC = [RAQRCodeScannerViewController viewControllerFromStoryboard];
- scannerVC.QRCodeViewControllerDidCompletion = ^(RAQRCodeScannerViewController *qrcodeViewController, NSString *value) {
-
- if (weakself) {
- __strong typeof(weakself) strongSelf = weakself;
- [strongSelf processScanResult:value];
- }
-
- [qrcodeViewController dismissViewControllerAnimated:YES completion:nil];
- };
-
- scannerVC.QRCodeViewControllerDidCanceled = ^(RAQRCodeScannerViewController *qrcodeViewController) {
-
- [qrcodeViewController dismissViewControllerAnimated:YES completion:nil];
- };
-
- [self presentViewController:scannerVC animated:YES completion:nil];
- }
- //- (IBAction)internalCheckBtnClick:(UIButton *)sender {
- // sender.selected = !sender.selected;
- // if (sender.selected) self.externalCheckBtn.selected = NO;
- //}
- //
- //- (IBAction)externalCheckBtnClick:(UIButton *)sender {
- // sender.selected = !sender.selected;
- // if (sender.selected) self.internalCheckBtn.selected = NO;
- //}
- #pragma mark - TextField Delegate
- - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
- self.currentFirstResponder = textField;
- return YES;
- }
- - (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
- return YES;
- }
- #pragma mark - Private
- - (void)processScanResult:(NSString *)result {
-
- if (result.length) {
-
- NSArray *dataArr = [result componentsSeparatedByString:@";"];
- if (dataArr.count == 3) {
- NSString *name = [dataArr objectAtIndex:0];
- NSString *internalAddr = [dataArr objectAtIndex:2];
- // NSString *externalAddr = [dataArr objectAtIndex:2];
-
- self.nameTextField.text = name;
- self.internalText = internalAddr;
- // strongself.externalTextField.text = externalAddr;
- }
- else if (dataArr.count == 2) {
- NSString *name = [dataArr objectAtIndex:0];
- NSString *internalAddr = [dataArr objectAtIndex:1];
- // NSString *externalAddr = [dataArr objectAtIndex:2];
-
- self.nameTextField.text = name;
- self.internalText = internalAddr;
- // strongself.externalTextField.text = externalAddr;
- }
- else {
-
-
- [RAUtils message_alert:@"Wrong QR-CODE?" title:@"Can not setup server" controller:self];
-
- // [RAUtils alert_view:@"Wrong QR-CODE?" title:@"Can not setup server"];
- // strongself.nameTextField.text = nil;
- // strongself.internalTextField.text = [dataArr firstObject];
- // strongself.externalTextField.text = nil;
- }
-
-
- self.checkedAddress = nil;
- NSUInteger selectedIndex = 1;
- self.checkedAddress = self.internalText;
-
- // if (self.returnValue) {
- // self.returnValue(self.nameTextField.text, self.checkedAddress);
- // }
-
-
- if (self.checkedAddress.length) {
- // 保存信息
- NSString *name = self.nameTextField.text;
- NSString *internalAddr = self.internalText;
- // NSString *externalAddr = weakself.externalTextField.text;
- NSMutableDictionary *addressDic = [NSMutableDictionary dictionary];
- if (internalAddr.length) {
- [addressDic setObject:internalAddr forKey:@"serverAddress"];
- }
- // if (externalAddr.length) {
- // [addressDic setObject:externalAddr forKey:@"externalAddress"];
- // }
- if (name.length) {
- [addressDic setObject:name forKey:@"name"];
- }
- [addressDic setObject:@(selectedIndex) forKey:@"selectedIndex"];
- [self setUserDefaultsValue:addressDic forKey:kScanAddress];
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- appDelegate.address = [addressDic objectForKey:@"serverAddress"];
- }
-
-
- }
-
- }
- - (IBAction)onNameChange:(id)sender {
-
- self.checkedAddress = nil;
- NSUInteger selectedIndex = 1;
- self.checkedAddress = self.internalText;
-
- // 保存信息
- NSString *name = self.nameTextField.text;
- NSString *internalAddr = self.internalText;
- // NSString *externalAddr = weakself.externalTextField.text;
- NSMutableDictionary *addressDic = [NSMutableDictionary dictionary];
- if (internalAddr.length) {
- [addressDic setObject:internalAddr forKey:@"serverAddress"];
- }
- // if (externalAddr.length) {
- // [addressDic setObject:externalAddr forKey:@"externalAddress"];
- // }
- if (name.length) {
- [addressDic setObject:name forKey:@"name"];
- }
- [addressDic setObject:@(selectedIndex) forKey:@"selectedIndex"];
- [self setUserDefaultsValue:addressDic forKey:kScanAddress];
-
- }
- - (IBAction)onServerChange:(id)sender {
-
- self.checkedAddress = nil;
- NSUInteger selectedIndex = 1;
- self.checkedAddress = self.internalText;
-
- // 保存信息
- NSString *name = self.nameTextField.text;
- NSString *internalAddr = self.internalText;
- // NSString *externalAddr = weakself.externalTextField.text;
- NSMutableDictionary *addressDic = [NSMutableDictionary dictionary];
- if (internalAddr.length) {
- [addressDic setObject:internalAddr forKey:@"serverAddress"];
- }
- // if (externalAddr.length) {
- // [addressDic setObject:externalAddr forKey:@"externalAddress"];
- // }
- if (name.length) {
- [addressDic setObject:name forKey:@"name"];
- }
- [addressDic setObject:@(selectedIndex) forKey:@"selectedIndex"];
- [self setUserDefaultsValue:addressDic forKey:kScanAddress];
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- appDelegate.address = [addressDic objectForKey:@"serverAddress"];
- }
- - (IBAction)onAutoUpload:(id)sender {
- BOOL autoUpload = self.autoSwitch.isOn;
-
- [RAUploadManager configureUploadManager:^(RAUPloadManagerConfigure *configure) {
-
- configure.autoUpload = autoUpload;
- }];
-
-
- }
- - (IBAction)onRetryChange:(id)sender {
- int retryCount = [self.retryCountBox.text intValue];
- [RAUploadManager configureUploadManager:^(RAUPloadManagerConfigure *configure) {
-
- configure.retryCount = retryCount;
- }];
- }
- - (IBAction)onWaitingChange:(id)sender {
-
- int retryTimeInterval = [self.retryTimeIntervalBox.text intValue];
-
- [RAUploadManager configureUploadManager:^(RAUPloadManagerConfigure *configure) {
-
- configure.retryTimeIntetval = retryTimeInterval;
- }];
- }
- - (IBAction)onChangePasswordClick:(id)sender {
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- if(appDelegate.user.length==0)
- {
- [RAUtils message_alert:@"You must sign in first." title:@"Change Password" controller:self];
- return;
- }
-
-
- ChangePasswordViewController * vc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ChangePasswordViewController"];
- // loginvc.delegate = self;
- // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
-
-
- UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
-
-
-
-
- // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
-
- navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
- [self presentViewController:navi animated:YES completion:^{
-
- // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
-
- DebugLog(@"about present.........");
-
- // self.btop = false;
- // <#code#>
- }];
- }
- - (IBAction)onDeleteAccountClick:(id)sender {
-
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- if(appDelegate.user.length==0)
- {
- [RAUtils message_alert:@"You must sign in first." title:@"Delete Account" controller:self];
- return;
- }
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Delete Account" message:@"Are you sure you want to permanently delete your account?" preferredStyle:UIAlertControllerStyleAlert];
- //增加确定按钮
- [alertController addAction:[UIAlertAction actionWithTitle:@"Delete" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){
- //获取第1个输入框;
- UITextField *titleTextField = alertController.textFields.firstObject;
- if([appDelegate.password isEqualToString:titleTextField.text])
- {
- NSLog(@"%@", @"run process");
- __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Delete Account" completion:^{
- [RANetwork request_delete_account:^(NSMutableDictionary *result) {
- NSMutableDictionary* return_json =result;
-
- [waitalert dismissViewControllerAnimated:YES completion:^{
- if([[return_json valueForKey:@"result"] intValue]==2)
- {
- // [self hideMenu];
- // [self switchToHome:nil];
- [appDelegate Logout];
- MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
- [main_vc checklogin :false];
- [RAUtils message_alert:@"Account deleted." title:nil controller:self];
- }
- else
- {
- [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Delete Account" controller:self] ;
- }
- }];
-
-
-
-
-
-
-
-
- }];
- }];
-
-
- }
- else
- {
- [RAUtils message_alert:@"Wrong password." title:nil controller:self];
- }
-
- }]];
- //增加取消按钮;
- [alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:nil]];
- //定义第一个输入框;
- [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
- textField.placeholder = @"Login Password";
- textField.textContentType = UITextContentTypePassword;
- }];
- [self presentViewController:alertController animated:true completion:nil];
- }
- #pragma mark - RA_NOTIFICAITON
- -(void) refresh_ui
- {
-
- [self loadTemplate];
- }
- -(void) reload_data
- {
-
- [self refresh_ui];
- }
- @end
|