ServerSettingViewController.m 35 KB

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