UserListViewController.m 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. //
  2. // UserListViewController.m
  3. // iSales-NPD
  4. //
  5. // Created by Ray on 4/19/16.
  6. // Copyright © 2016 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "UserListViewController.h"
  9. #import "MainViewController.h"
  10. @interface UserListViewController ()
  11. @end
  12. @implementation UserListViewController
  13. - (void)viewDidLoad {
  14. [super viewDidLoad];
  15. // self.edgesForExtendedLayout = UIRectEdgeNone;
  16. self.bb_close.image=[[UIImage imageNamed:@"close"] imageWithRenderingMode:UIImageRenderingModeAutomatic];
  17. self.logindata = [iSalesDB get_saveduser];
  18. }
  19. - (void)didReceiveMemoryWarning {
  20. [super didReceiveMemoryWarning];
  21. // Dispose of any resources that can be recreated.
  22. }
  23. - (IBAction)CloseClick:(id)sender {
  24. [self dismissViewControllerAnimated:true completion:nil];
  25. // if(self.returnValue)
  26. // self.returnValue(false);
  27. }
  28. /*
  29. #pragma mark - Navigation
  30. // In a storyboard-based application, you will often want to do a little preparation before navigation
  31. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  32. // Get the new view controller using [segue destinationViewController].
  33. // Pass the selected object to the new view controller.
  34. }
  35. */
  36. #pragma mark - Table view data source
  37. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  38. {
  39. return 44;
  40. }
  41. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  42. {
  43. return 1;
  44. }
  45. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  46. {
  47. return self.logindata.count;
  48. }
  49. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  50. {
  51. NSMutableDictionary* up = self.logindata[indexPath.row];
  52. NSString *CellIdentifier = @"LoginListCell";
  53. UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  54. NSString* name=up[@"name"];
  55. cell.textLabel.text = name;
  56. return cell;
  57. }
  58. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  59. {
  60. NSMutableDictionary* up = self.logindata[indexPath.row];
  61. NSString *user = up[@"name"];
  62. NSString *password = up[@"pwd"];
  63. if (user.length == 0 || password.length == 0) {
  64. [self dismissViewControllerAnimated:YES completion:nil];
  65. return;
  66. }
  67. UIApplication * app = [UIApplication sharedApplication];
  68. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  69. if(appDelegate.bLogin)
  70. {
  71. if ([user.lowercaseString isEqualToString:RASingleton.sharedInstance.user.lowercaseString]) { // 当前用户
  72. [self dismissViewControllerAnimated:YES completion:nil];
  73. return;
  74. }
  75. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Switch user" completion:^{
  76. PopWaitAlert* pop=[RAUtils waiting_pop:@"Switch user" completion:nil];
  77. [RANetwork request_logout:^(NSMutableDictionary *result) {
  78. appDelegate.cart_count = 0;
  79. appDelegate.wish_count =0;
  80. appDelegate.port_count =0;
  81. [appDelegate update_count_mark];
  82. appDelegate.can_show_price =false;
  83. appDelegate.can_see_price =false;
  84. appDelegate.can_create_portfolio =false;
  85. appDelegate.can_create_order =false;
  86. appDelegate.can_cancel_order =false;
  87. appDelegate.can_set_cart_price =false;
  88. appDelegate.can_delete_order =false;
  89. appDelegate.can_submit_order =false;
  90. appDelegate.can_set_tearsheet_price =false;
  91. appDelegate.can_update_contact_info = false;
  92. appDelegate.save_order_logout = false;
  93. appDelegate.submit_order_logout = false;
  94. appDelegate.alert_sold_in_quantities = false;
  95. appDelegate.ipad_perm =nil ;
  96. appDelegate.user_type = USER_ROLE_UNKNOWN;
  97. appDelegate.OrderFilter= nil;
  98. [appDelegate SetSo:nil];
  99. [appDelegate set_main_button_panel];
  100. [appDelegate Logout];
  101. [appDelegate checkLogin:NO];
  102. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  103. [RANetwork request_login:user password:password completionHandler:^(NSMutableDictionary *result) {
  104. int ret=[result[@"result"]intValue];
  105. [pop hide];
  106. // [waitalert dismissViewControllerAnimated:YES completion:^{
  107. if(ret==RESULT_TRUE)
  108. {
  109. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  110. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  111. [defaults removeObjectForKey:@"user"];
  112. [defaults removeObjectForKey:@"password"];
  113. if(true)
  114. {
  115. NSString* encryptu=[AESCrypt encrypt:RASingleton.sharedInstance.user password:@"usai"];
  116. NSString* encryptp=[AESCrypt encrypt:appDelegate.password password:@"usai"] ;
  117. [defaults setValue:encryptu forKey:@"user"];
  118. [defaults setValue:encryptp forKey:@"password"];
  119. }
  120. [defaults synchronize];
  121. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  122. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  123. {
  124. [main_vc checklogin:false];
  125. }
  126. else
  127. {
  128. [main_vc checklogin:false];
  129. }
  130. [self dismissViewControllerAnimated:true completion:^{
  131. if(self.returnValue)
  132. self.returnValue(true);
  133. }];
  134. } // 登陆成功
  135. else
  136. {
  137. NSString* msg=nil;
  138. switch (ret) {
  139. case RESULT_NET_NOTAVAILABLE:
  140. msg = MSG_NET_NOTAVAILABLE;
  141. break;
  142. case RESULT_NET_ERROR:
  143. msg = MSG_NET_ERROR;
  144. break;
  145. case RESULT_FALSE:
  146. msg = MSG_USERAUTH_ERROR;
  147. break;
  148. case RESULT_VER_LOW:
  149. msg = MSG_VER_LOW;
  150. break;
  151. default:
  152. break;
  153. }
  154. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Switch User" message:msg preferredStyle:UIAlertControllerStyleAlert];
  155. //block代码块取代了delegate
  156. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  157. [self dismissViewControllerAnimated:true completion:^{
  158. if(self.returnValue)
  159. self.returnValue(false);
  160. }];
  161. }];
  162. [alertControl addAction:actionOne];
  163. [self presentViewController:alertControl animated:YES completion:nil];
  164. } // 登陆失败
  165. // }];
  166. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  167. }];
  168. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  169. //
  170. // int ret=[RANetwork Authorize:user password:password];
  171. //
  172. // dispatch_async(dispatch_get_main_queue(), ^{
  173. //
  174. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  175. //
  176. // if(ret==RESULT_TRUE)
  177. // {
  178. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  179. //
  180. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  181. // [defaults removeObjectForKey:@"user"];
  182. // [defaults removeObjectForKey:@"password"];
  183. // if(true)
  184. // {
  185. // NSString* encryptu=[AESCrypt encrypt:RASingleton.sharedInstance.user password:@"usai"];
  186. // NSString* encryptp=[AESCrypt encrypt:appDelegate.password password:@"usai"] ;
  187. //
  188. // [defaults setValue:encryptu forKey:@"user"];
  189. // [defaults setValue:encryptp forKey:@"password"];
  190. //
  191. // }
  192. // [defaults synchronize];
  193. //
  194. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  195. // if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  196. // {
  197. // [main_vc checklogin:false];
  198. // }
  199. // else
  200. // {
  201. // [main_vc checklogin:false];
  202. // }
  203. //
  204. // [self dismissViewControllerAnimated:true completion:^{
  205. // if(self.returnValue)
  206. // self.returnValue(true);
  207. // }];
  208. //
  209. // } // 登陆成功
  210. // else
  211. // {
  212. // NSString* msg=nil;
  213. //
  214. // switch (ret) {
  215. //
  216. // case RESULT_NET_NOTAVAILABLE:
  217. // msg = MSG_NET_NOTAVAILABLE;
  218. // break;
  219. //
  220. //
  221. // case RESULT_NET_ERROR:
  222. // msg = MSG_NET_ERROR;
  223. // break;
  224. //
  225. //
  226. // case RESULT_FALSE:
  227. // msg = MSG_USERAUTH_ERROR;
  228. // break;
  229. //
  230. // case RESULT_VER_LOW:
  231. // msg = MSG_VER_LOW;
  232. // break;
  233. // default:
  234. // break;
  235. // }
  236. //
  237. //
  238. // UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Switch User" message:msg preferredStyle:UIAlertControllerStyleAlert];
  239. // //block代码块取代了delegate
  240. // UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  241. //
  242. // [self dismissViewControllerAnimated:true completion:^{
  243. // if(self.returnValue)
  244. // self.returnValue(false);
  245. // }];
  246. //
  247. // }];
  248. //
  249. //
  250. // [alertControl addAction:actionOne];
  251. //
  252. // [self presentViewController:alertControl animated:YES completion:nil];
  253. //
  254. // } // 登陆失败
  255. //
  256. // }); // update login ui
  257. //
  258. // }); // attemp login
  259. }];
  260. // }];
  261. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  262. //
  263. // [RANetwork logout];
  264. //
  265. // dispatch_async(dispatch_get_main_queue(), ^{
  266. //
  267. //
  268. // appDelegate.cart_count = 0;
  269. // appDelegate.wish_count =0;
  270. // appDelegate.port_count =0;
  271. //
  272. // [appDelegate update_count_mark];
  273. //
  274. //
  275. // appDelegate.can_show_price =false;
  276. // appDelegate.can_see_price =false;
  277. // appDelegate.can_create_portfolio =false;
  278. // appDelegate.can_create_order =false;
  279. //
  280. //
  281. // appDelegate.can_cancel_order =false;
  282. // appDelegate.can_set_cart_price =false;
  283. // appDelegate.can_delete_order =false;
  284. // appDelegate.can_submit_order =false;
  285. // appDelegate.can_set_tearsheet_price =false;
  286. // appDelegate.can_update_contact_info = false;
  287. //
  288. // appDelegate.save_order_logout = false;
  289. // appDelegate.submit_order_logout = false;
  290. // appDelegate.alert_sold_in_quantities = false;
  291. //
  292. // appDelegate.ipad_perm =nil ;
  293. // appDelegate.user_type = USER_ROLE_UNKNOWN;
  294. // appDelegate.OrderFilter= nil;
  295. // [appDelegate SetSo:nil];
  296. // [appDelegate set_main_button_panel];
  297. //
  298. // [appDelegate Logout];
  299. // [appDelegate checkLogin:NO];
  300. //
  301. //// [waitalert dismissViewControllerAnimated:YES completion:nil];
  302. //
  303. // [RANetwork request_login:user password:password completionHandler:^(NSMutableDictionary *result) {
  304. // int ret=[result[@"result"]intValue];
  305. //
  306. //
  307. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  308. //
  309. // if(ret==RESULT_TRUE)
  310. // {
  311. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  312. //
  313. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  314. // [defaults removeObjectForKey:@"user"];
  315. // [defaults removeObjectForKey:@"password"];
  316. // if(true)
  317. // {
  318. // NSString* encryptu=[AESCrypt encrypt:RASingleton.sharedInstance.user password:@"usai"];
  319. // NSString* encryptp=[AESCrypt encrypt:appDelegate.password password:@"usai"] ;
  320. //
  321. // [defaults setValue:encryptu forKey:@"user"];
  322. // [defaults setValue:encryptp forKey:@"password"];
  323. //
  324. // }
  325. // [defaults synchronize];
  326. //
  327. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  328. // if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  329. // {
  330. // [main_vc checklogin:false];
  331. // }
  332. // else
  333. // {
  334. // [main_vc checklogin:false];
  335. // }
  336. //
  337. // [self dismissViewControllerAnimated:true completion:^{
  338. // if(self.returnValue)
  339. // self.returnValue(true);
  340. // }];
  341. //
  342. // } // 登陆成功
  343. // else
  344. // {
  345. // NSString* msg=nil;
  346. //
  347. // switch (ret) {
  348. //
  349. // case RESULT_NET_NOTAVAILABLE:
  350. // msg = MSG_NET_NOTAVAILABLE;
  351. // break;
  352. //
  353. //
  354. // case RESULT_NET_ERROR:
  355. // msg = MSG_NET_ERROR;
  356. // break;
  357. //
  358. //
  359. // case RESULT_FALSE:
  360. // msg = MSG_USERAUTH_ERROR;
  361. // break;
  362. //
  363. // case RESULT_VER_LOW:
  364. // msg = MSG_VER_LOW;
  365. // break;
  366. // default:
  367. // break;
  368. // }
  369. //
  370. //
  371. // UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Switch User" message:msg preferredStyle:UIAlertControllerStyleAlert];
  372. // //block代码块取代了delegate
  373. // UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  374. //
  375. // [self dismissViewControllerAnimated:true completion:^{
  376. // if(self.returnValue)
  377. // self.returnValue(false);
  378. // }];
  379. //
  380. // }];
  381. //
  382. //
  383. // [alertControl addAction:actionOne];
  384. //
  385. // [self presentViewController:alertControl animated:YES completion:nil];
  386. //
  387. // } // 登陆失败
  388. //
  389. //
  390. // }];
  391. //
  392. //
  393. //// dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  394. ////
  395. //// int ret=[RANetwork Authorize:user password:password];
  396. ////
  397. //// dispatch_async(dispatch_get_main_queue(), ^{
  398. ////
  399. //// [waitalert dismissViewControllerAnimated:YES completion:nil];
  400. ////
  401. //// if(ret==RESULT_TRUE)
  402. //// {
  403. //// AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  404. ////
  405. //// NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  406. //// [defaults removeObjectForKey:@"user"];
  407. //// [defaults removeObjectForKey:@"password"];
  408. //// if(true)
  409. //// {
  410. //// NSString* encryptu=[AESCrypt encrypt:RASingleton.sharedInstance.user password:@"usai"];
  411. //// NSString* encryptp=[AESCrypt encrypt:appDelegate.password password:@"usai"] ;
  412. ////
  413. //// [defaults setValue:encryptu forKey:@"user"];
  414. //// [defaults setValue:encryptp forKey:@"password"];
  415. ////
  416. //// }
  417. //// [defaults synchronize];
  418. ////
  419. //// MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  420. //// if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  421. //// {
  422. //// [main_vc checklogin:false];
  423. //// }
  424. //// else
  425. //// {
  426. //// [main_vc checklogin:false];
  427. //// }
  428. ////
  429. //// [self dismissViewControllerAnimated:true completion:^{
  430. //// if(self.returnValue)
  431. //// self.returnValue(true);
  432. //// }];
  433. ////
  434. //// } // 登陆成功
  435. //// else
  436. //// {
  437. //// NSString* msg=nil;
  438. ////
  439. //// switch (ret) {
  440. ////
  441. //// case RESULT_NET_NOTAVAILABLE:
  442. //// msg = MSG_NET_NOTAVAILABLE;
  443. //// break;
  444. ////
  445. ////
  446. //// case RESULT_NET_ERROR:
  447. //// msg = MSG_NET_ERROR;
  448. //// break;
  449. ////
  450. ////
  451. //// case RESULT_FALSE:
  452. //// msg = MSG_USERAUTH_ERROR;
  453. //// break;
  454. ////
  455. //// case RESULT_VER_LOW:
  456. //// msg = MSG_VER_LOW;
  457. //// break;
  458. //// default:
  459. //// break;
  460. //// }
  461. ////
  462. ////
  463. //// UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Switch User" message:msg preferredStyle:UIAlertControllerStyleAlert];
  464. //// //block代码块取代了delegate
  465. //// UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  466. ////
  467. //// [self dismissViewControllerAnimated:true completion:^{
  468. //// if(self.returnValue)
  469. //// self.returnValue(false);
  470. //// }];
  471. ////
  472. //// }];
  473. ////
  474. ////
  475. //// [alertControl addAction:actionOne];
  476. ////
  477. //// [self presentViewController:alertControl animated:YES completion:nil];
  478. ////
  479. //// } // 登陆失败
  480. ////
  481. //// }); // update login ui
  482. ////
  483. //// }); // attemp login
  484. //
  485. // }); // update logout ui
  486. //
  487. // }); // logout
  488. }
  489. // self.edituser.text = up[@"name"];
  490. // self.editpass.text = up[@"pwd"];
  491. //
  492. // self.showList=false;
  493. // self.Loginlist.hidden=true;
  494. }
  495. //- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
  496. //{
  497. //
  498. // return true;
  499. //}
  500. @end