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 template 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. [RADataProvider load_scan_models];
  236. }
  237. //[zip UnzipCloseFile];
  238. }
  239. else
  240. {
  241. //打开文件失败,通常是文件路径有问题或密码错误。
  242. [RAUtils message_alert:@"Can not unzip template file, please contact the Administrator." title:@"Warrning" controller:self];
  243. // NSFileManager *fileManager = [NSFileManager defaultManager];
  244. // [fileManager removeItemAtPath:zipFile error:nil];
  245. }
  246. // [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  247. //
  248. // UIImage * img =[UIImage imageWithData:downloadimg_data];
  249. // cell.imageView.image=img;
  250. }
  251. else
  252. [RAUtils message_alert:@"Can not download template file, please check your server setting or contact the Administrator." title:@"Warrning" controller:self];
  253. // cell.imageView.image=[UIImage imageNamed:@"notfound_s"];
  254. });
  255. });
  256. // NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:appDelegate.downloadurl]];
  257. // [RADataProvider downloadFileOffset:0 Param:nil from:appDelegate.downloadurl method:@"post" toPath:[documents stringByAppendingPathComponent:file_name] progressHandler:nil completionHandler:^(NSMutableDictionary *result) {
  258. // int i=0; ;
  259. // }];
  260. }
  261. else
  262. {
  263. [RAUtils message_alert:@"Please setup the server first." title:@"Warrning" controller:self];
  264. }
  265. }
  266. - (IBAction)onScanClick:(id)sender {
  267. // __weak typeof(self) weakself = self;
  268. //// ScannerViewController *scannerVC = [[UIStoryboard storyboardWithName:@"cam_scan" bundle:nil] instantiateViewControllerWithIdentifier:@"NewScannerViewController"];
  269. //// scannerVC.returnCode = ^(NSString *code) {
  270. //// // 扫描成功保存扫描值
  271. //// if (weakself) {
  272. //// __strong typeof(weakself) strongSelf = weakself;
  273. //// [strongSelf processScanResult:code];
  274. //// }
  275. //// };
  276. //// [self presentViewController:scannerVC animated:YES completion:nil];
  277. //
  278. // RAQRCodeScannerViewController *scannerVC = [[UIStoryboard storyboardWithName:@"QRCode" bundle:nil] instantiateViewControllerWithIdentifier:@"RAQRCodeScannerViewControllerAuto"];
  279. //
  280. //// RAQRCodeScannerViewController *scannerVC = [RAQRCodeScannerViewController viewControllerFromStoryboard];
  281. // scannerVC.QRCodeViewControllerDidCompletion = ^(RAQRCodeScannerViewController *qrcodeViewController, NSString *value) {
  282. //
  283. // if (weakself) {
  284. // __strong typeof(weakself) strongSelf = weakself;
  285. // [strongSelf processScanResult:value];
  286. //
  287. //
  288. // }
  289. //
  290. // [qrcodeViewController dismissViewControllerAnimated:YES completion:nil];
  291. // };
  292. //
  293. // scannerVC.QRCodeViewControllerDidCanceled = ^(RAQRCodeScannerViewController *qrcodeViewController) {
  294. //
  295. // [qrcodeViewController dismissViewControllerAnimated:YES completion:nil];
  296. // };
  297. //
  298. // [self presentViewController:scannerVC animated:YES completion:nil];
  299. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  300. if(appDelegate.bLogin)
  301. {
  302. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Set Server" message:@"Are you sure you to sign out and setup the server?" preferredStyle:UIAlertControllerStyleAlert];
  303. UIAlertAction *action_1 = [UIAlertAction actionWithTitle:@"Sign out and set" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  304. //open exist
  305. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  306. appDelegate.cart_count = 0;//[[jsobj :@"cart_count"] intValue];
  307. appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  308. appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  309. [appDelegate update_count_mark];
  310. appDelegate.can_show_price =false;
  311. appDelegate.can_see_price =false;
  312. appDelegate.can_create_portfolio =false;
  313. appDelegate.can_create_order =false;
  314. appDelegate.can_cancel_order =false;
  315. appDelegate.can_set_cart_price =false;
  316. appDelegate.can_delete_order =false;
  317. appDelegate.can_submit_order =false;
  318. appDelegate.can_set_tearsheet_price =false;
  319. appDelegate.can_update_contact_info = false;
  320. appDelegate.save_order_logout = false;
  321. appDelegate.submit_order_logout = false;
  322. appDelegate.alert_sold_in_quantities = false;
  323. appDelegate.ipad_perm =nil ;
  324. appDelegate.user_type = USER_ROLE_UNKNOWN;
  325. appDelegate.OrderFilter= nil;
  326. [appDelegate SetSo:nil];
  327. [appDelegate set_main_button_panel];
  328. #ifdef RA_NOTIFICATION
  329. [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
  330. #endif
  331. [appDelegate Logout];
  332. SetupServerViewController * servervc =[[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"SetupServerViewController"];
  333. servervc.showCancel = true;
  334. servervc.returnValue = ^{
  335. NSDictionary *addressDic = [[NSUserDefaults standardUserDefaults] valueForKey:@"ScanAddress"];
  336. if (addressDic) {
  337. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  338. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  339. main_vc.labelServer.text = [addressDic objectForKey:@"show_name"];
  340. self.nameTextField.text = [addressDic objectForKey:@"show_name"];
  341. self.internalText = [addressDic objectForKey:@"serverAddress"];
  342. }
  343. };
  344. [self.navigationController pushViewController:servervc animated:true];
  345. }];
  346. UIAlertAction *action_2 = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  347. //create new;
  348. }];
  349. [alertController addAction:action_1];
  350. [alertController addAction:action_2];
  351. [self presentViewController:alertController animated:YES completion:nil];
  352. }
  353. else
  354. {
  355. SetupServerViewController * servervc =[[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"SetupServerViewController"];
  356. servervc.showCancel = true;
  357. servervc.returnValue = ^{
  358. NSDictionary *addressDic = [[NSUserDefaults standardUserDefaults] valueForKey:@"ScanAddress"];
  359. if (addressDic) {
  360. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  361. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  362. main_vc.labelServer.text = [addressDic objectForKey:@"show_name"];
  363. self.nameTextField.text = [addressDic objectForKey:@"name"];
  364. self.internalText = [addressDic objectForKey:@"serverAddress"];
  365. }
  366. };
  367. [self.navigationController pushViewController:servervc animated:true];
  368. }
  369. }
  370. - (void)scanItemClick:(UIBarButtonItem *)sender {
  371. __weak typeof(self) weakself = self;
  372. // ScannerViewController *scannerVC = [[UIStoryboard storyboardWithName:@"cam_scan" bundle:nil] instantiateViewControllerWithIdentifier:@"NewScannerViewController"];
  373. // scannerVC.returnCode = ^(NSString *code) {
  374. // // 扫描成功保存扫描值
  375. // if (weakself) {
  376. // __strong typeof(weakself) strongSelf = weakself;
  377. // [strongSelf processScanResult:code];
  378. // }
  379. // };
  380. // [self presentViewController:scannerVC animated:YES completion:nil];
  381. RAQRCodeScannerViewController *scannerVC = [RAQRCodeScannerViewController viewControllerFromStoryboard];
  382. scannerVC.QRCodeViewControllerDidCompletion = ^(RAQRCodeScannerViewController *qrcodeViewController, NSString *value) {
  383. if (weakself) {
  384. __strong typeof(weakself) strongSelf = weakself;
  385. [strongSelf processScanResult:value];
  386. }
  387. [qrcodeViewController dismissViewControllerAnimated:YES completion:nil];
  388. };
  389. scannerVC.QRCodeViewControllerDidCanceled = ^(RAQRCodeScannerViewController *qrcodeViewController) {
  390. [qrcodeViewController dismissViewControllerAnimated:YES completion:nil];
  391. };
  392. [self presentViewController:scannerVC animated:YES completion:nil];
  393. }
  394. //- (IBAction)internalCheckBtnClick:(UIButton *)sender {
  395. // sender.selected = !sender.selected;
  396. // if (sender.selected) self.externalCheckBtn.selected = NO;
  397. //}
  398. //
  399. //- (IBAction)externalCheckBtnClick:(UIButton *)sender {
  400. // sender.selected = !sender.selected;
  401. // if (sender.selected) self.internalCheckBtn.selected = NO;
  402. //}
  403. #pragma mark - TextField Delegate
  404. - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
  405. self.currentFirstResponder = textField;
  406. return YES;
  407. }
  408. - (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
  409. return YES;
  410. }
  411. #pragma mark - Private
  412. - (void)processScanResult:(NSString *)result {
  413. if (result.length) {
  414. NSArray *dataArr = [result componentsSeparatedByString:@";"];
  415. if (dataArr.count == 3) {
  416. NSString *name = [dataArr objectAtIndex:0];
  417. NSString *internalAddr = [dataArr objectAtIndex:2];
  418. // NSString *externalAddr = [dataArr objectAtIndex:2];
  419. self.nameTextField.text = name;
  420. self.internalText = internalAddr;
  421. // strongself.externalTextField.text = externalAddr;
  422. }
  423. else if (dataArr.count == 2) {
  424. NSString *name = [dataArr objectAtIndex:0];
  425. NSString *internalAddr = [dataArr objectAtIndex:1];
  426. // NSString *externalAddr = [dataArr objectAtIndex:2];
  427. self.nameTextField.text = name;
  428. self.internalText = internalAddr;
  429. // strongself.externalTextField.text = externalAddr;
  430. }
  431. else {
  432. [RAUtils message_alert:@"Wrong QR-CODE?" title:@"Can not setup server" controller:self];
  433. // [RAUtils alert_view:@"Wrong QR-CODE?" title:@"Can not setup server"];
  434. // strongself.nameTextField.text = nil;
  435. // strongself.internalTextField.text = [dataArr firstObject];
  436. // strongself.externalTextField.text = nil;
  437. }
  438. self.checkedAddress = nil;
  439. NSUInteger selectedIndex = 1;
  440. self.checkedAddress = self.internalText;
  441. // if (self.returnValue) {
  442. // self.returnValue(self.nameTextField.text, self.checkedAddress);
  443. // }
  444. if (self.checkedAddress.length) {
  445. // 保存信息
  446. NSString *name = self.nameTextField.text;
  447. NSString *internalAddr = self.internalText;
  448. // NSString *externalAddr = weakself.externalTextField.text;
  449. NSMutableDictionary *addressDic = [NSMutableDictionary dictionary];
  450. if (internalAddr.length) {
  451. [addressDic setObject:internalAddr forKey:@"serverAddress"];
  452. }
  453. // if (externalAddr.length) {
  454. // [addressDic setObject:externalAddr forKey:@"externalAddress"];
  455. // }
  456. if (name.length) {
  457. [addressDic setObject:name forKey:@"name"];
  458. }
  459. [addressDic setObject:@(selectedIndex) forKey:@"selectedIndex"];
  460. [self setUserDefaultsValue:addressDic forKey:kScanAddress];
  461. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  462. appDelegate.address = [addressDic objectForKey:@"serverAddress"];
  463. }
  464. }
  465. }
  466. - (IBAction)onNameChange:(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. }
  487. - (IBAction)onServerChange:(id)sender {
  488. self.checkedAddress = nil;
  489. NSUInteger selectedIndex = 1;
  490. self.checkedAddress = self.internalText;
  491. // 保存信息
  492. NSString *name = self.nameTextField.text;
  493. NSString *internalAddr = self.internalText;
  494. // NSString *externalAddr = weakself.externalTextField.text;
  495. NSMutableDictionary *addressDic = [NSMutableDictionary dictionary];
  496. if (internalAddr.length) {
  497. [addressDic setObject:internalAddr forKey:@"serverAddress"];
  498. }
  499. // if (externalAddr.length) {
  500. // [addressDic setObject:externalAddr forKey:@"externalAddress"];
  501. // }
  502. if (name.length) {
  503. [addressDic setObject:name forKey:@"name"];
  504. }
  505. [addressDic setObject:@(selectedIndex) forKey:@"selectedIndex"];
  506. [self setUserDefaultsValue:addressDic forKey:kScanAddress];
  507. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  508. appDelegate.address = [addressDic objectForKey:@"serverAddress"];
  509. }
  510. - (IBAction)onAutoUpload:(id)sender {
  511. BOOL autoUpload = self.autoSwitch.isOn;
  512. [RAUploadManager configureUploadManager:^(RAUPloadManagerConfigure *configure) {
  513. configure.autoUpload = autoUpload;
  514. }];
  515. }
  516. - (IBAction)onRetryChange:(id)sender {
  517. int retryCount = [self.retryCountBox.text intValue];
  518. [RAUploadManager configureUploadManager:^(RAUPloadManagerConfigure *configure) {
  519. configure.retryCount = retryCount;
  520. }];
  521. }
  522. - (IBAction)onWaitingChange:(id)sender {
  523. int retryTimeInterval = [self.retryTimeIntervalBox.text intValue];
  524. [RAUploadManager configureUploadManager:^(RAUPloadManagerConfigure *configure) {
  525. configure.retryTimeIntetval = retryTimeInterval;
  526. }];
  527. }
  528. - (IBAction)onChangePasswordClick:(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:@"Change Password" controller:self];
  534. return;
  535. }
  536. ChangePasswordViewController * vc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ChangePasswordViewController"];
  537. // loginvc.delegate = self;
  538. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  539. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  540. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  541. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  542. [self presentViewController:navi animated:YES completion:^{
  543. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  544. DebugLog(@"about present.........");
  545. // self.btop = false;
  546. // <#code#>
  547. }];
  548. }
  549. - (IBAction)onDeleteAccountClick:(id)sender {
  550. UIApplication * app = [UIApplication sharedApplication];
  551. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  552. if(appDelegate.user.length==0)
  553. {
  554. [RAUtils message_alert:@"You must sign in first." title:@"Delete Account" controller:self];
  555. return;
  556. }
  557. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Delete Account" message:@"Are you sure you want to permanently delete your account?" preferredStyle:UIAlertControllerStyleAlert];
  558. //增加确定按钮
  559. [alertController addAction:[UIAlertAction actionWithTitle:@"Delete" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){
  560. //获取第1个输入框;
  561. UITextField *titleTextField = alertController.textFields.firstObject;
  562. if([appDelegate.password isEqualToString:titleTextField.text])
  563. {
  564. NSLog(@"%@", @"run process");
  565. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Delete Account" completion:^{
  566. [RANetwork request_delete_account:^(NSMutableDictionary *result) {
  567. NSMutableDictionary* return_json =result;
  568. [waitalert dismissViewControllerAnimated:YES completion:^{
  569. if([[return_json valueForKey:@"result"] intValue]==2)
  570. {
  571. // [self hideMenu];
  572. // [self switchToHome:nil];
  573. [appDelegate Logout];
  574. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  575. [main_vc checklogin :false];
  576. [RAUtils message_alert:@"Account deleted." title:nil controller:self];
  577. }
  578. else
  579. {
  580. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Delete Account" controller:self] ;
  581. }
  582. }];
  583. }];
  584. }];
  585. }
  586. else
  587. {
  588. [RAUtils message_alert:@"Wrong password." title:nil controller:self];
  589. }
  590. }]];
  591. //增加取消按钮;
  592. [alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:nil]];
  593. //定义第一个输入框;
  594. [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
  595. textField.placeholder = @"Login Password";
  596. textField.textContentType = UITextContentTypePassword;
  597. }];
  598. [self presentViewController:alertController animated:true completion:nil];
  599. }
  600. @end