ServerSettingViewController.m 32 KB

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