ServerSettingViewController.m 33 KB

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