ServerSettingViewController.m 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  1. //
  2. // LoginSettingViewController.m
  3. // RA Image
  4. //
  5. // Created by Jack on 2017/4/27.
  6. // Copyright © 2017年 USAI. All rights reserved.
  7. //
  8. #import "ServerSettingViewController.h"
  9. //#import "ScannerViewController.h"
  10. #import "RAQRCodeScannerViewController.h"
  11. #import "RAUtils.h"
  12. #import "RAUploadManager.h"
  13. #import "AppDelegate.h"
  14. #import "RADataProvider.h"
  15. #import "ZipArchive.h"
  16. #import "AboutViewController.h"
  17. #import "WebViewController.h"
  18. #import "MainViewController.h"
  19. #import "ChangePasswordViewController.h"
  20. #import "SetupServerViewController.h"
  21. @interface ServerSettingViewController ()<UITextFieldDelegate>
  22. @property (strong, nonatomic) IBOutlet UITextField *nameTextField;
  23. //@property (strong, nonatomic) IBOutlet UITextField *internalTextField;
  24. @property (strong, nonatomic) NSString *internalText;
  25. @property (nonatomic,copy) NSString *checkedAddress;
  26. @end
  27. @implementation ServerSettingViewController
  28. - (IBAction)onAboutClick:(id)sender {
  29. AboutViewController * aboutVC =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"AboutViewController"];
  30. // loginvc.delegate = self;
  31. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  32. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:aboutVC] ;
  33. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  34. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  35. [self presentViewController:navi animated:YES completion:^{
  36. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  37. DebugLog(@"about present.........");
  38. // self.btop = false;
  39. // <#code#>
  40. }];
  41. //
  42. //
  43. // UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:aboutVC] ;
  44. //
  45. //
  46. //
  47. //
  48. //
  49. // // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  50. //
  51. // navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  52. // [self presentViewController:navi animated:YES completion:^{
  53. //
  54. // // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  55. //
  56. // DebugLog(@"about present.........");
  57. //
  58. // // self.btop = false;
  59. // // <#code#>
  60. // }];
  61. }
  62. - (IBAction)onPrivacyClick:(id)sender {
  63. NSString* url = URL_PRIVACY;
  64. NSString* title = @"Privacy Policy";
  65. WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  66. ViewController.url = url;
  67. ViewController.title = title;
  68. [self.navigationController pushViewController:ViewController animated:YES];
  69. }
  70. - (void)viewDidLoad {
  71. [super viewDidLoad];
  72. // return;
  73. // Do any additional setup after loading the view.
  74. // UIView *v = [UIView new];
  75. // [self.view insertSubview:v atIndex:0];
  76. // self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStylePlain target:self action:@selector(doneItemClick:)];
  77. // self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Scan" style:UIBarButtonItemStylePlain target:self action:@selector(scanItemClick:)];
  78. //
  79. [self loadAddress];
  80. // [self registListenKeyboard];
  81. RAUPloadManagerConfigure *configure = [[RAUPloadManagerConfigure alloc] init];
  82. self.autoSwitch.on = configure.autoUpload;
  83. // self.autoRmFinishSwitch.on = autoRmFinish;
  84. // self.autoRmErrorSwith.on = autoRmErr;
  85. self.retryCountBox.text = [NSString stringWithFormat:@"%d",configure.retryCount];
  86. self.retryTimeIntervalBox.text = [NSString stringWithFormat:@"%d",(int)configure.retryTimeIntetval];
  87. [self loadTemplate];
  88. }
  89. - (void)didReceiveMemoryWarning {
  90. [super didReceiveMemoryWarning];
  91. // Dispose of any resources that can be recreated.
  92. }
  93. - (id)userDefaultsValue:(NSString *)key {
  94. return [[NSUserDefaults standardUserDefaults] valueForKey:key];
  95. }
  96. - (void)loadAddress {
  97. NSDictionary *addressDic = [self userDefaultsValue:kScanAddress];
  98. if (addressDic) {
  99. NSString* ia=addressDic[@"internalAddress"];
  100. NSString* ea=addressDic[@"externalAddress"];
  101. NSString* sa=addressDic[@"serverAddress"];
  102. if(sa.length==0)
  103. {
  104. if(ea.length>0)
  105. sa=ea;
  106. else if(ia.length>0)
  107. sa=ia;
  108. }
  109. self.internalText= sa;
  110. self.nameTextField.text = [addressDic objectForKey:@"show_name"];
  111. // RASingleton.sharedInstance.price_index =[addressDic[@"price_type"] intValue];
  112. // NSUInteger selectedIndex = [[addressDic objectForKey:@"selectedIndex"] integerValue];
  113. // switch (selectedIndex) {
  114. // case 0:
  115. // case 1: {
  116. // [self internalCheckBtnClick:self.internalCheckBtn];
  117. // }
  118. // break;
  119. // case 2: {
  120. // [self externalCheckBtnClick:self.externalCheckBtn];
  121. // }
  122. // break;
  123. //
  124. // default:
  125. // break;
  126. // }
  127. } else {
  128. // [self internalCheckBtnClick:self.internalCheckBtn];
  129. }
  130. }
  131. - (void)loadTemplate {
  132. NSDictionary *addressDic = [self userDefaultsValue:@"ScanTemplate"];
  133. if (addressDic) {
  134. NSString* updatetime=addressDic[@"updatetime"];
  135. self.labelUpdate.text = updatetime;
  136. }
  137. }
  138. #pragma mark - Button Click
  139. - (void)doneItemClick:(UIBarButtonItem *)sender {
  140. self.checkedAddress = nil;
  141. NSUInteger selectedIndex = 1;
  142. self.checkedAddress = self.internalText;
  143. // if (self.internalCheckBtn.selected) {
  144. // self.checkedAddress = self.internalTextField.text;
  145. // selectedIndex = 1;
  146. // }
  147. // if (self.externalCheckBtn.selected) {
  148. // self.checkedAddress = self.externalTextField.text;
  149. // selectedIndex = 2;
  150. // }
  151. // if (self.returnValue) {
  152. // self.returnValue(self.nameTextField.text, self.checkedAddress);
  153. // }
  154. __weak typeof(self) weakself = self;
  155. [self.navigationController dismissViewControllerAnimated:YES completion:^{
  156. if (weakself.checkedAddress.length) {
  157. // 保存信息
  158. NSString *name = weakself.nameTextField.text;
  159. NSString *internalAddr = weakself.internalText;
  160. // NSString *externalAddr = weakself.externalTextField.text;
  161. NSMutableDictionary *addressDic = [NSMutableDictionary dictionary];
  162. if (internalAddr.length) {
  163. [addressDic setObject:internalAddr forKey:@"serverAddress"];
  164. }
  165. // if (externalAddr.length) {
  166. // [addressDic setObject:externalAddr forKey:@"externalAddress"];
  167. // }
  168. if (name.length) {
  169. [addressDic setObject:name forKey:@"name"];
  170. }
  171. [addressDic setObject:@(selectedIndex) forKey:@"selectedIndex"];
  172. [weakself setUserDefaultsValue:addressDic forKey:kScanAddress];
  173. }
  174. }];
  175. }
  176. - (void)setUserDefaultsValue:(id)value forKey:(NSString *)key {
  177. NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
  178. [userDefaults setValue:value forKey:key];
  179. [userDefaults synchronize];
  180. }
  181. - (IBAction)onUnlockCodeClick:(id)sender {
  182. }
  183. - (IBAction)onUpdateClick:(id)sender {
  184. if(self.internalText.length>0)
  185. {
  186. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  187. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  188. NSString *documents = [paths objectAtIndex:0];
  189. // NSString* file_name=[appDelegate.downloadurl lastPathComponent];
  190. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  191. NSData* download_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:appDelegate.downloadurl]];
  192. dispatch_async(dispatch_get_main_queue(), ^{
  193. if(download_data!=nil)
  194. {
  195. NSString* file_name=[appDelegate.downloadurl lastPathComponent];
  196. NSString* path = [documents stringByAppendingPathComponent:file_name];
  197. [RAUtils saveData:download_data toPath:path];
  198. ZipArchive* zip = [[ZipArchive alloc] init];
  199. NSString* unZipTo=[documents stringByAppendingPathComponent:@"download"];
  200. // NSFileManager* fileManager=[NSFileManager defaultManager];
  201. // [fileManager removeItemAtPath:unZipTo error:nil];
  202. // NSString *unZipTo = [temp stringByAppendingPathComponent:unziplocation];
  203. //
  204. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  205. // NSString *documentPath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
  206. //NSString* zipFile = [documentPath stringByAppendingString:@"/images.zip"] ;
  207. // NSString* unZipTo = img_cache;//[documentPath stringByAppendingString:@"/images"] ;
  208. DebugLog(@"path: %@",unZipTo);
  209. if( [zip UnzipOpenFile:path Password:nil] ){
  210. BOOL result = [zip UnzipFileTo:unZipTo overWrite:YES];
  211. if( NO==result )
  212. {
  213. // int aaa=0;
  214. //解压失败
  215. [zip UnzipCloseFile];
  216. //文件损坏,删除文件重试
  217. NSFileManager* fileManager=[NSFileManager defaultManager];
  218. //debug
  219. // BOOL blDele= [fileManager removeItemAtPath:zipFile error:nil];
  220. [fileManager removeItemAtPath:path error:nil];
  221. [fileManager removeItemAtPath:unZipTo error:nil];
  222. [RAUtils message_alert:@"Can not unzip template file, please try download again." title:@"Warrning" controller:self];
  223. }
  224. else
  225. {
  226. [zip UnzipCloseFile];
  227. NSFileManager *fileManager = [NSFileManager defaultManager];
  228. [fileManager removeItemAtPath:path error:nil];
  229. [RAUtils message_alert:@"Update templete file successful." title:@"Message" controller:self];
  230. NSMutableDictionary *templateDic = [NSMutableDictionary dictionary];
  231. NSString* datetime= [RAUtils current_date_time];
  232. templateDic[@"updatetime"]= datetime;
  233. [self setUserDefaultsValue:templateDic forKey:@"ScanTemplate"];
  234. [self loadTemplate];
  235. }
  236. //[zip UnzipCloseFile];
  237. }
  238. else
  239. {
  240. //打开文件失败,通常是文件路径有问题或密码错误。
  241. [RAUtils message_alert:@"Can not unzip template file, please contact the Administrator." title:@"Warrning" controller:self];
  242. // NSFileManager *fileManager = [NSFileManager defaultManager];
  243. // [fileManager removeItemAtPath:zipFile error:nil];
  244. }
  245. // [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  246. //
  247. // UIImage * img =[UIImage imageWithData:downloadimg_data];
  248. // cell.imageView.image=img;
  249. }
  250. else
  251. [RAUtils message_alert:@"Can not download template file, please check your server setting or contact the Administrator." title:@"Warrning" controller:self];
  252. // cell.imageView.image=[UIImage imageNamed:@"notfound_s"];
  253. });
  254. });
  255. // NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:appDelegate.downloadurl]];
  256. // [RADataProvider downloadFileOffset:0 Param:nil from:appDelegate.downloadurl method:@"post" toPath:[documents stringByAppendingPathComponent:file_name] progressHandler:nil completionHandler:^(NSMutableDictionary *result) {
  257. // int i=0; ;
  258. // }];
  259. }
  260. else
  261. {
  262. [RAUtils message_alert:@"Please setup the server first." title:@"Warrning" controller:self];
  263. }
  264. }
  265. - (IBAction)onScanClick:(id)sender {
  266. // __weak typeof(self) weakself = self;
  267. //// ScannerViewController *scannerVC = [[UIStoryboard storyboardWithName:@"cam_scan" bundle:nil] instantiateViewControllerWithIdentifier:@"NewScannerViewController"];
  268. //// scannerVC.returnCode = ^(NSString *code) {
  269. //// // 扫描成功保存扫描值
  270. //// if (weakself) {
  271. //// __strong typeof(weakself) strongSelf = weakself;
  272. //// [strongSelf processScanResult:code];
  273. //// }
  274. //// };
  275. //// [self presentViewController:scannerVC animated:YES completion:nil];
  276. //
  277. // RAQRCodeScannerViewController *scannerVC = [[UIStoryboard storyboardWithName:@"QRCode" bundle:nil] instantiateViewControllerWithIdentifier:@"RAQRCodeScannerViewControllerAuto"];
  278. //
  279. //// RAQRCodeScannerViewController *scannerVC = [RAQRCodeScannerViewController viewControllerFromStoryboard];
  280. // scannerVC.QRCodeViewControllerDidCompletion = ^(RAQRCodeScannerViewController *qrcodeViewController, NSString *value) {
  281. //
  282. // if (weakself) {
  283. // __strong typeof(weakself) strongSelf = weakself;
  284. // [strongSelf processScanResult:value];
  285. //
  286. //
  287. // }
  288. //
  289. // [qrcodeViewController dismissViewControllerAnimated:YES completion:nil];
  290. // };
  291. //
  292. // scannerVC.QRCodeViewControllerDidCanceled = ^(RAQRCodeScannerViewController *qrcodeViewController) {
  293. //
  294. // [qrcodeViewController dismissViewControllerAnimated:YES completion:nil];
  295. // };
  296. //
  297. // [self presentViewController:scannerVC animated:YES completion:nil];
  298. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  299. if(appDelegate.bLogin)
  300. {
  301. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Set Server" message:@"Are you sure you to sign out and setup the server?" preferredStyle:UIAlertControllerStyleAlert];
  302. UIAlertAction *action_1 = [UIAlertAction actionWithTitle:@"Sign out and set" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  303. //open exist
  304. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  305. appDelegate.cart_count = 0;//[[jsobj :@"cart_count"] intValue];
  306. appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  307. appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  308. [appDelegate update_count_mark];
  309. appDelegate.can_show_price =false;
  310. appDelegate.can_see_price =false;
  311. appDelegate.can_create_portfolio =false;
  312. appDelegate.can_create_order =false;
  313. appDelegate.can_cancel_order =false;
  314. appDelegate.can_set_cart_price =false;
  315. appDelegate.can_delete_order =false;
  316. appDelegate.can_submit_order =false;
  317. appDelegate.can_set_tearsheet_price =false;
  318. appDelegate.can_update_contact_info = false;
  319. appDelegate.save_order_logout = false;
  320. appDelegate.submit_order_logout = false;
  321. appDelegate.alert_sold_in_quantities = false;
  322. appDelegate.ipad_perm =nil ;
  323. appDelegate.user_type = USER_ROLE_UNKNOWN;
  324. appDelegate.OrderFilter= nil;
  325. [appDelegate SetSo:nil];
  326. [appDelegate set_main_button_panel];
  327. #ifdef RA_NOTIFICATION
  328. [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
  329. #endif
  330. [appDelegate Logout];
  331. SetupServerViewController * servervc =[[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"SetupServerViewController"];
  332. servervc.showCancel = true;
  333. servervc.returnValue = ^{
  334. NSDictionary *addressDic = [[NSUserDefaults standardUserDefaults] valueForKey:@"ScanAddress"];
  335. if (addressDic) {
  336. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  337. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  338. main_vc.labelServer.text = [addressDic objectForKey:@"show_name"];
  339. self.nameTextField.text = [addressDic objectForKey:@"show_name"];
  340. self.internalText = [addressDic objectForKey:@"serverAddress"];
  341. }
  342. };
  343. [self.navigationController pushViewController:servervc animated:true];
  344. }];
  345. UIAlertAction *action_2 = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  346. //create new;
  347. }];
  348. [alertController addAction:action_1];
  349. [alertController addAction:action_2];
  350. [self presentViewController:alertController animated:YES completion:nil];
  351. }
  352. else
  353. {
  354. SetupServerViewController * servervc =[[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"SetupServerViewController"];
  355. servervc.showCancel = true;
  356. servervc.returnValue = ^{
  357. NSDictionary *addressDic = [[NSUserDefaults standardUserDefaults] valueForKey:@"ScanAddress"];
  358. if (addressDic) {
  359. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  360. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  361. main_vc.labelServer.text = [addressDic objectForKey:@"name"];
  362. self.nameTextField.text = [addressDic objectForKey:@"name"];
  363. self.internalText = [addressDic objectForKey:@"serverAddress"];
  364. }
  365. };
  366. [self.navigationController pushViewController:servervc animated:true];
  367. }
  368. }
  369. - (void)scanItemClick:(UIBarButtonItem *)sender {
  370. __weak typeof(self) weakself = self;
  371. // ScannerViewController *scannerVC = [[UIStoryboard storyboardWithName:@"cam_scan" bundle:nil] instantiateViewControllerWithIdentifier:@"NewScannerViewController"];
  372. // scannerVC.returnCode = ^(NSString *code) {
  373. // // 扫描成功保存扫描值
  374. // if (weakself) {
  375. // __strong typeof(weakself) strongSelf = weakself;
  376. // [strongSelf processScanResult:code];
  377. // }
  378. // };
  379. // [self presentViewController:scannerVC animated:YES completion:nil];
  380. RAQRCodeScannerViewController *scannerVC = [RAQRCodeScannerViewController viewControllerFromStoryboard];
  381. scannerVC.QRCodeViewControllerDidCompletion = ^(RAQRCodeScannerViewController *qrcodeViewController, NSString *value) {
  382. if (weakself) {
  383. __strong typeof(weakself) strongSelf = weakself;
  384. [strongSelf processScanResult:value];
  385. }
  386. [qrcodeViewController dismissViewControllerAnimated:YES completion:nil];
  387. };
  388. scannerVC.QRCodeViewControllerDidCanceled = ^(RAQRCodeScannerViewController *qrcodeViewController) {
  389. [qrcodeViewController dismissViewControllerAnimated:YES completion:nil];
  390. };
  391. [self presentViewController:scannerVC animated:YES completion:nil];
  392. }
  393. //- (IBAction)internalCheckBtnClick:(UIButton *)sender {
  394. // sender.selected = !sender.selected;
  395. // if (sender.selected) self.externalCheckBtn.selected = NO;
  396. //}
  397. //
  398. //- (IBAction)externalCheckBtnClick:(UIButton *)sender {
  399. // sender.selected = !sender.selected;
  400. // if (sender.selected) self.internalCheckBtn.selected = NO;
  401. //}
  402. #pragma mark - TextField Delegate
  403. - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
  404. self.currentFirstResponder = textField;
  405. return YES;
  406. }
  407. - (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
  408. return YES;
  409. }
  410. #pragma mark - Private
  411. - (void)processScanResult:(NSString *)result {
  412. if (result.length) {
  413. NSArray *dataArr = [result componentsSeparatedByString:@";"];
  414. if (dataArr.count == 3) {
  415. NSString *name = [dataArr objectAtIndex:0];
  416. NSString *internalAddr = [dataArr objectAtIndex:2];
  417. // NSString *externalAddr = [dataArr objectAtIndex:2];
  418. self.nameTextField.text = name;
  419. self.internalText = internalAddr;
  420. // strongself.externalTextField.text = externalAddr;
  421. }
  422. else if (dataArr.count == 2) {
  423. NSString *name = [dataArr objectAtIndex:0];
  424. NSString *internalAddr = [dataArr objectAtIndex:1];
  425. // NSString *externalAddr = [dataArr objectAtIndex:2];
  426. self.nameTextField.text = name;
  427. self.internalText = internalAddr;
  428. // strongself.externalTextField.text = externalAddr;
  429. }
  430. else {
  431. [RAUtils message_alert:@"Wrong QR-CODE?" title:@"Can not setup server" controller:self];
  432. // [RAUtils alert_view:@"Wrong QR-CODE?" title:@"Can not setup server"];
  433. // strongself.nameTextField.text = nil;
  434. // strongself.internalTextField.text = [dataArr firstObject];
  435. // strongself.externalTextField.text = nil;
  436. }
  437. self.checkedAddress = nil;
  438. NSUInteger selectedIndex = 1;
  439. self.checkedAddress = self.internalText;
  440. // if (self.returnValue) {
  441. // self.returnValue(self.nameTextField.text, self.checkedAddress);
  442. // }
  443. if (self.checkedAddress.length) {
  444. // 保存信息
  445. NSString *name = self.nameTextField.text;
  446. NSString *internalAddr = self.internalText;
  447. // NSString *externalAddr = weakself.externalTextField.text;
  448. NSMutableDictionary *addressDic = [NSMutableDictionary dictionary];
  449. if (internalAddr.length) {
  450. [addressDic setObject:internalAddr forKey:@"serverAddress"];
  451. }
  452. // if (externalAddr.length) {
  453. // [addressDic setObject:externalAddr forKey:@"externalAddress"];
  454. // }
  455. if (name.length) {
  456. [addressDic setObject:name forKey:@"name"];
  457. }
  458. [addressDic setObject:@(selectedIndex) forKey:@"selectedIndex"];
  459. [self setUserDefaultsValue:addressDic forKey:kScanAddress];
  460. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  461. appDelegate.address = [addressDic objectForKey:@"serverAddress"];
  462. }
  463. }
  464. }
  465. - (IBAction)onNameChange:(id)sender {
  466. self.checkedAddress = nil;
  467. NSUInteger selectedIndex = 1;
  468. self.checkedAddress = self.internalText;
  469. // 保存信息
  470. NSString *name = self.nameTextField.text;
  471. NSString *internalAddr = self.internalText;
  472. // NSString *externalAddr = weakself.externalTextField.text;
  473. NSMutableDictionary *addressDic = [NSMutableDictionary dictionary];
  474. if (internalAddr.length) {
  475. [addressDic setObject:internalAddr forKey:@"serverAddress"];
  476. }
  477. // if (externalAddr.length) {
  478. // [addressDic setObject:externalAddr forKey:@"externalAddress"];
  479. // }
  480. if (name.length) {
  481. [addressDic setObject:name forKey:@"name"];
  482. }
  483. [addressDic setObject:@(selectedIndex) forKey:@"selectedIndex"];
  484. [self setUserDefaultsValue:addressDic forKey:kScanAddress];
  485. }
  486. - (IBAction)onServerChange:(id)sender {
  487. self.checkedAddress = nil;
  488. NSUInteger selectedIndex = 1;
  489. self.checkedAddress = self.internalText;
  490. // 保存信息
  491. NSString *name = self.nameTextField.text;
  492. NSString *internalAddr = self.internalText;
  493. // NSString *externalAddr = weakself.externalTextField.text;
  494. NSMutableDictionary *addressDic = [NSMutableDictionary dictionary];
  495. if (internalAddr.length) {
  496. [addressDic setObject:internalAddr forKey:@"serverAddress"];
  497. }
  498. // if (externalAddr.length) {
  499. // [addressDic setObject:externalAddr forKey:@"externalAddress"];
  500. // }
  501. if (name.length) {
  502. [addressDic setObject:name forKey:@"name"];
  503. }
  504. [addressDic setObject:@(selectedIndex) forKey:@"selectedIndex"];
  505. [self setUserDefaultsValue:addressDic forKey:kScanAddress];
  506. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  507. appDelegate.address = [addressDic objectForKey:@"serverAddress"];
  508. }
  509. - (IBAction)onAutoUpload:(id)sender {
  510. BOOL autoUpload = self.autoSwitch.isOn;
  511. [RAUploadManager configureUploadManager:^(RAUPloadManagerConfigure *configure) {
  512. configure.autoUpload = autoUpload;
  513. }];
  514. }
  515. - (IBAction)onRetryChange:(id)sender {
  516. int retryCount = [self.retryCountBox.text intValue];
  517. [RAUploadManager configureUploadManager:^(RAUPloadManagerConfigure *configure) {
  518. configure.retryCount = retryCount;
  519. }];
  520. }
  521. - (IBAction)onWaitingChange:(id)sender {
  522. int retryTimeInterval = [self.retryTimeIntervalBox.text intValue];
  523. [RAUploadManager configureUploadManager:^(RAUPloadManagerConfigure *configure) {
  524. configure.retryTimeIntetval = retryTimeInterval;
  525. }];
  526. }
  527. - (IBAction)onChangePasswordClick:(id)sender {
  528. UIApplication * app = [UIApplication sharedApplication];
  529. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  530. if(appDelegate.user.length==0)
  531. {
  532. [RAUtils message_alert:@"You must sign in first." title:@"Change Password" controller:self];
  533. return;
  534. }
  535. ChangePasswordViewController * vc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ChangePasswordViewController"];
  536. // loginvc.delegate = self;
  537. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  538. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  539. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  540. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  541. [self presentViewController:navi animated:YES completion:^{
  542. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  543. DebugLog(@"about present.........");
  544. // self.btop = false;
  545. // <#code#>
  546. }];
  547. }
  548. - (IBAction)onDeleteAccountClick:(id)sender {
  549. UIApplication * app = [UIApplication sharedApplication];
  550. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  551. if(appDelegate.user.length==0)
  552. {
  553. [RAUtils message_alert:@"You must sign in first." title:@"Delete Account" controller:self];
  554. return;
  555. }
  556. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Delete Account" message:@"Are you sure you want to permanently delete your account?" preferredStyle:UIAlertControllerStyleAlert];
  557. //增加确定按钮
  558. [alertController addAction:[UIAlertAction actionWithTitle:@"Delete" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){
  559. //获取第1个输入框;
  560. UITextField *titleTextField = alertController.textFields.firstObject;
  561. if([appDelegate.password isEqualToString:titleTextField.text])
  562. {
  563. NSLog(@"%@", @"run process");
  564. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Delete Account" completion:^{
  565. [RANetwork request_delete_account:^(NSMutableDictionary *result) {
  566. NSMutableDictionary* return_json =result;
  567. [waitalert dismissViewControllerAnimated:YES completion:^{
  568. if([[return_json valueForKey:@"result"] intValue]==2)
  569. {
  570. // [self hideMenu];
  571. // [self switchToHome:nil];
  572. [appDelegate Logout];
  573. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  574. [main_vc checklogin :false];
  575. [RAUtils message_alert:@"Account deleted." title:nil controller:self];
  576. }
  577. else
  578. {
  579. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Delete Account" controller:self] ;
  580. }
  581. }];
  582. }];
  583. }];
  584. }
  585. else
  586. {
  587. [RAUtils message_alert:@"Wrong password." title:nil controller:self];
  588. }
  589. }]];
  590. //增加取消按钮;
  591. [alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:nil]];
  592. //定义第一个输入框;
  593. [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
  594. textField.placeholder = @"Login Password";
  595. textField.textContentType = UITextContentTypePassword;
  596. }];
  597. [self presentViewController:alertController animated:true completion:nil];
  598. }
  599. @end