UserListViewController.m 23 KB

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