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