ServerSettingViewController.m 36 KB

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