ServerSettingViewController.m 33 KB

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