ServerSettingViewController.m 30 KB

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