UserListViewController.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  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:appDelegate.user.lowercaseString]) { // 当前用户
  72. [self dismissViewControllerAnimated:YES completion:nil];
  73. return;
  74. }
  75. UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Switch user"];
  76. [RANetwork request_logout:^(NSMutableDictionary *result) {
  77. appDelegate.cart_count = 0;
  78. appDelegate.wish_count =0;
  79. appDelegate.port_count =0;
  80. [appDelegate update_count_mark];
  81. appDelegate.can_show_price =false;
  82. appDelegate.can_see_price =false;
  83. appDelegate.can_create_portfolio =false;
  84. appDelegate.can_create_order =false;
  85. appDelegate.can_cancel_order =false;
  86. appDelegate.can_set_cart_price =false;
  87. appDelegate.can_delete_order =false;
  88. appDelegate.can_submit_order =false;
  89. appDelegate.can_set_tearsheet_price =false;
  90. appDelegate.can_update_contact_info = false;
  91. appDelegate.save_order_logout = false;
  92. appDelegate.submit_order_logout = false;
  93. appDelegate.alert_sold_in_quantities = false;
  94. appDelegate.ipad_perm =nil ;
  95. appDelegate.user_type = USER_ROLE_UNKNOWN;
  96. appDelegate.OrderFilter= nil;
  97. [appDelegate SetSo:nil];
  98. [appDelegate set_main_button_panel];
  99. [appDelegate Logout];
  100. [appDelegate checkLogin:NO];
  101. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  102. [RANetwork request_login:user password:password completionHandler:^(NSMutableDictionary *result) {
  103. int ret=[result[@"result"]intValue];
  104. [waitalert dismissViewControllerAnimated:YES completion:nil];
  105. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  106. if(ret==RESULT_TRUE)
  107. {
  108. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  109. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  110. [defaults removeObjectForKey:@"user"];
  111. [defaults removeObjectForKey:@"password"];
  112. if(true)
  113. {
  114. NSString* encryptu=[AESCrypt encrypt:appDelegate.user password:@"usai"];
  115. NSString* encryptp=[AESCrypt encrypt:appDelegate.password password:@"usai"] ;
  116. [defaults setValue:encryptu forKey:@"user"];
  117. [defaults setValue:encryptp forKey:@"password"];
  118. }
  119. [defaults synchronize];
  120. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  121. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  122. {
  123. [main_vc checklogin:false];
  124. }
  125. else
  126. {
  127. [main_vc checklogin:false];
  128. }
  129. [self dismissViewControllerAnimated:true completion:^{
  130. if(self.returnValue)
  131. self.returnValue(true);
  132. }];
  133. } // 登陆成功
  134. else
  135. {
  136. NSString* msg=nil;
  137. switch (ret) {
  138. case RESULT_NET_NOTAVAILABLE:
  139. msg = MSG_NET_NOTAVAILABLE;
  140. break;
  141. case RESULT_NET_ERROR:
  142. msg = MSG_NET_ERROR;
  143. break;
  144. case RESULT_FALSE:
  145. msg = MSG_USERAUTH_ERROR;
  146. break;
  147. case RESULT_VER_LOW:
  148. msg = MSG_VER_LOW;
  149. break;
  150. default:
  151. break;
  152. }
  153. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Switch User" message:msg preferredStyle:UIAlertControllerStyleAlert];
  154. //block代码块取代了delegate
  155. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  156. [self dismissViewControllerAnimated:true completion:^{
  157. if(self.returnValue)
  158. self.returnValue(false);
  159. }];
  160. }];
  161. [alertControl addAction:actionOne];
  162. [self presentViewController:alertControl animated:YES completion:nil];
  163. } // 登陆失败
  164. }];
  165. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  166. //
  167. // int ret=[RANetwork Authorize:user password:password];
  168. //
  169. // dispatch_async(dispatch_get_main_queue(), ^{
  170. //
  171. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  172. //
  173. // if(ret==RESULT_TRUE)
  174. // {
  175. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  176. //
  177. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  178. // [defaults removeObjectForKey:@"user"];
  179. // [defaults removeObjectForKey:@"password"];
  180. // if(true)
  181. // {
  182. // NSString* encryptu=[AESCrypt encrypt:appDelegate.user password:@"usai"];
  183. // NSString* encryptp=[AESCrypt encrypt:appDelegate.password password:@"usai"] ;
  184. //
  185. // [defaults setValue:encryptu forKey:@"user"];
  186. // [defaults setValue:encryptp forKey:@"password"];
  187. //
  188. // }
  189. // [defaults synchronize];
  190. //
  191. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  192. // if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  193. // {
  194. // [main_vc checklogin:false];
  195. // }
  196. // else
  197. // {
  198. // [main_vc checklogin:false];
  199. // }
  200. //
  201. // [self dismissViewControllerAnimated:true completion:^{
  202. // if(self.returnValue)
  203. // self.returnValue(true);
  204. // }];
  205. //
  206. // } // 登陆成功
  207. // else
  208. // {
  209. // NSString* msg=nil;
  210. //
  211. // switch (ret) {
  212. //
  213. // case RESULT_NET_NOTAVAILABLE:
  214. // msg = MSG_NET_NOTAVAILABLE;
  215. // break;
  216. //
  217. //
  218. // case RESULT_NET_ERROR:
  219. // msg = MSG_NET_ERROR;
  220. // break;
  221. //
  222. //
  223. // case RESULT_FALSE:
  224. // msg = MSG_USERAUTH_ERROR;
  225. // break;
  226. //
  227. // case RESULT_VER_LOW:
  228. // msg = MSG_VER_LOW;
  229. // break;
  230. // default:
  231. // break;
  232. // }
  233. //
  234. //
  235. // UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Switch User" message:msg preferredStyle:UIAlertControllerStyleAlert];
  236. // //block代码块取代了delegate
  237. // UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  238. //
  239. // [self dismissViewControllerAnimated:true completion:^{
  240. // if(self.returnValue)
  241. // self.returnValue(false);
  242. // }];
  243. //
  244. // }];
  245. //
  246. //
  247. // [alertControl addAction:actionOne];
  248. //
  249. // [self presentViewController:alertControl animated:YES completion:nil];
  250. //
  251. // } // 登陆失败
  252. //
  253. // }); // update login ui
  254. //
  255. // }); // attemp login
  256. }];
  257. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  258. //
  259. // [RANetwork logout];
  260. //
  261. // dispatch_async(dispatch_get_main_queue(), ^{
  262. //
  263. //
  264. // appDelegate.cart_count = 0;
  265. // appDelegate.wish_count =0;
  266. // appDelegate.port_count =0;
  267. //
  268. // [appDelegate update_count_mark];
  269. //
  270. //
  271. // appDelegate.can_show_price =false;
  272. // appDelegate.can_see_price =false;
  273. // appDelegate.can_create_portfolio =false;
  274. // appDelegate.can_create_order =false;
  275. //
  276. //
  277. // appDelegate.can_cancel_order =false;
  278. // appDelegate.can_set_cart_price =false;
  279. // appDelegate.can_delete_order =false;
  280. // appDelegate.can_submit_order =false;
  281. // appDelegate.can_set_tearsheet_price =false;
  282. // appDelegate.can_update_contact_info = false;
  283. //
  284. // appDelegate.save_order_logout = false;
  285. // appDelegate.submit_order_logout = false;
  286. // appDelegate.alert_sold_in_quantities = false;
  287. //
  288. // appDelegate.ipad_perm =nil ;
  289. // appDelegate.user_type = USER_ROLE_UNKNOWN;
  290. // appDelegate.OrderFilter= nil;
  291. // [appDelegate SetSo:nil];
  292. // [appDelegate set_main_button_panel];
  293. //
  294. // [appDelegate Logout];
  295. // [appDelegate checkLogin:NO];
  296. //
  297. //// [waitalert dismissViewControllerAnimated:YES completion:nil];
  298. //
  299. // [RANetwork request_login:user password:password completionHandler:^(NSMutableDictionary *result) {
  300. // int ret=[result[@"result"]intValue];
  301. //
  302. //
  303. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  304. //
  305. // if(ret==RESULT_TRUE)
  306. // {
  307. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  308. //
  309. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  310. // [defaults removeObjectForKey:@"user"];
  311. // [defaults removeObjectForKey:@"password"];
  312. // if(true)
  313. // {
  314. // NSString* encryptu=[AESCrypt encrypt:appDelegate.user password:@"usai"];
  315. // NSString* encryptp=[AESCrypt encrypt:appDelegate.password password:@"usai"] ;
  316. //
  317. // [defaults setValue:encryptu forKey:@"user"];
  318. // [defaults setValue:encryptp forKey:@"password"];
  319. //
  320. // }
  321. // [defaults synchronize];
  322. //
  323. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  324. // if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  325. // {
  326. // [main_vc checklogin:false];
  327. // }
  328. // else
  329. // {
  330. // [main_vc checklogin:false];
  331. // }
  332. //
  333. // [self dismissViewControllerAnimated:true completion:^{
  334. // if(self.returnValue)
  335. // self.returnValue(true);
  336. // }];
  337. //
  338. // } // 登陆成功
  339. // else
  340. // {
  341. // NSString* msg=nil;
  342. //
  343. // switch (ret) {
  344. //
  345. // case RESULT_NET_NOTAVAILABLE:
  346. // msg = MSG_NET_NOTAVAILABLE;
  347. // break;
  348. //
  349. //
  350. // case RESULT_NET_ERROR:
  351. // msg = MSG_NET_ERROR;
  352. // break;
  353. //
  354. //
  355. // case RESULT_FALSE:
  356. // msg = MSG_USERAUTH_ERROR;
  357. // break;
  358. //
  359. // case RESULT_VER_LOW:
  360. // msg = MSG_VER_LOW;
  361. // break;
  362. // default:
  363. // break;
  364. // }
  365. //
  366. //
  367. // UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Switch User" message:msg preferredStyle:UIAlertControllerStyleAlert];
  368. // //block代码块取代了delegate
  369. // UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  370. //
  371. // [self dismissViewControllerAnimated:true completion:^{
  372. // if(self.returnValue)
  373. // self.returnValue(false);
  374. // }];
  375. //
  376. // }];
  377. //
  378. //
  379. // [alertControl addAction:actionOne];
  380. //
  381. // [self presentViewController:alertControl animated:YES completion:nil];
  382. //
  383. // } // 登陆失败
  384. //
  385. //
  386. // }];
  387. //
  388. //
  389. //// dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  390. ////
  391. //// int ret=[RANetwork Authorize:user password:password];
  392. ////
  393. //// dispatch_async(dispatch_get_main_queue(), ^{
  394. ////
  395. //// [waitalert dismissViewControllerAnimated:YES completion:nil];
  396. ////
  397. //// if(ret==RESULT_TRUE)
  398. //// {
  399. //// AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  400. ////
  401. //// NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  402. //// [defaults removeObjectForKey:@"user"];
  403. //// [defaults removeObjectForKey:@"password"];
  404. //// if(true)
  405. //// {
  406. //// NSString* encryptu=[AESCrypt encrypt:appDelegate.user password:@"usai"];
  407. //// NSString* encryptp=[AESCrypt encrypt:appDelegate.password password:@"usai"] ;
  408. ////
  409. //// [defaults setValue:encryptu forKey:@"user"];
  410. //// [defaults setValue:encryptp forKey:@"password"];
  411. ////
  412. //// }
  413. //// [defaults synchronize];
  414. ////
  415. //// MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  416. //// if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  417. //// {
  418. //// [main_vc checklogin:false];
  419. //// }
  420. //// else
  421. //// {
  422. //// [main_vc checklogin:false];
  423. //// }
  424. ////
  425. //// [self dismissViewControllerAnimated:true completion:^{
  426. //// if(self.returnValue)
  427. //// self.returnValue(true);
  428. //// }];
  429. ////
  430. //// } // 登陆成功
  431. //// else
  432. //// {
  433. //// NSString* msg=nil;
  434. ////
  435. //// switch (ret) {
  436. ////
  437. //// case RESULT_NET_NOTAVAILABLE:
  438. //// msg = MSG_NET_NOTAVAILABLE;
  439. //// break;
  440. ////
  441. ////
  442. //// case RESULT_NET_ERROR:
  443. //// msg = MSG_NET_ERROR;
  444. //// break;
  445. ////
  446. ////
  447. //// case RESULT_FALSE:
  448. //// msg = MSG_USERAUTH_ERROR;
  449. //// break;
  450. ////
  451. //// case RESULT_VER_LOW:
  452. //// msg = MSG_VER_LOW;
  453. //// break;
  454. //// default:
  455. //// break;
  456. //// }
  457. ////
  458. ////
  459. //// UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Switch User" message:msg preferredStyle:UIAlertControllerStyleAlert];
  460. //// //block代码块取代了delegate
  461. //// UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  462. ////
  463. //// [self dismissViewControllerAnimated:true completion:^{
  464. //// if(self.returnValue)
  465. //// self.returnValue(false);
  466. //// }];
  467. ////
  468. //// }];
  469. ////
  470. ////
  471. //// [alertControl addAction:actionOne];
  472. ////
  473. //// [self presentViewController:alertControl animated:YES completion:nil];
  474. ////
  475. //// } // 登陆失败
  476. ////
  477. //// }); // update login ui
  478. ////
  479. //// }); // attemp login
  480. //
  481. // }); // update logout ui
  482. //
  483. // }); // logout
  484. }
  485. // self.edituser.text = up[@"name"];
  486. // self.editpass.text = up[@"pwd"];
  487. //
  488. // self.showList=false;
  489. // self.Loginlist.hidden=true;
  490. }
  491. //- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
  492. //{
  493. //
  494. // return true;
  495. //}
  496. @end