ServerSettingViewController.m 32 KB

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