UserListViewController.m 26 KB

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