ServerSettingViewController.m 31 KB

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