ServerSettingViewController.m 35 KB

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