UserListViewController.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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. UIApplication * app = [UIApplication sharedApplication];
  62. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  63. if(appDelegate.bLogin)
  64. {
  65. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Switch user"];
  66. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  67. NSDictionary* return_json = [RANetwork logout];
  68. dispatch_async(dispatch_get_main_queue(), ^{
  69. appDelegate.cart_count = 0;
  70. appDelegate.wish_count =0;
  71. appDelegate.port_count =0;
  72. [appDelegate update_count_mark];
  73. appDelegate.can_show_price =false;
  74. appDelegate.can_see_price =false;
  75. appDelegate.can_create_portfolio =false;
  76. appDelegate.can_create_order =false;
  77. appDelegate.can_cancel_order =false;
  78. appDelegate.can_set_cart_price =false;
  79. appDelegate.can_delete_order =false;
  80. appDelegate.can_submit_order =false;
  81. appDelegate.can_set_tearsheet_price =false;
  82. appDelegate.can_update_contact_info = false;
  83. appDelegate.save_order_logout = false;
  84. appDelegate.submit_order_logout = false;
  85. appDelegate.alert_sold_in_quantities = false;
  86. appDelegate.ipad_perm =nil ;
  87. appDelegate.user_type = USER_ROLE_UNKNOWN;
  88. appDelegate.OrderFilter= nil;
  89. [appDelegate SetSo:nil];
  90. [appDelegate set_main_button_panel];
  91. [appDelegate Logout];
  92. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  93. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  94. int ret=[RANetwork Authorize:up[@"name"] password:up[@"pwd"]];
  95. dispatch_async(dispatch_get_main_queue(), ^{
  96. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  97. if(ret==RESULT_TRUE)
  98. {
  99. //
  100. // NSString* contactid=[self.content_data[indexPath.row] valueForKey:@"contact_id"] ;
  101. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  102. // appDelegate.contact_id=contactid;
  103. // appDelegate.contact_name =[self.content_data[indexPath.row] valueForKey:@"name"];
  104. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  105. [defaults removeObjectForKey:@"user"];
  106. [defaults removeObjectForKey:@"password"];
  107. if(true)
  108. {
  109. NSString* encryptu=[AESCrypt encrypt:appDelegate.user password:@"usai"];
  110. NSString* encryptp=[AESCrypt encrypt:up[@"pwd"] password:@"usai"] ;
  111. [defaults setValue:encryptu forKey:@"user"];
  112. [defaults setValue:encryptp forKey:@"password"];
  113. // [defaults setBool:TRUE forKey:@"autologin"];
  114. }
  115. [defaults synchronize];
  116. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  117. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  118. {
  119. [main_vc checklogin:false];
  120. }
  121. else
  122. {
  123. [main_vc checklogin:false];
  124. }
  125. [self dismissViewControllerAnimated:true completion:^{
  126. if(self.returnValue)
  127. self.returnValue(true);
  128. }];
  129. }
  130. else
  131. {
  132. NSString* msg=nil;
  133. switch (ret) {
  134. case RESULT_NET_NOTAVAILABLE:
  135. msg = MSG_NET_NOTAVAILABLE;
  136. break;
  137. case RESULT_NET_ERROR:
  138. msg = MSG_NET_ERROR;
  139. break;
  140. case RESULT_FALSE:
  141. msg = MSG_USERAUTH_ERROR;
  142. break;
  143. case RESULT_VER_LOW:
  144. msg = MSG_VER_LOW;
  145. break;
  146. default:
  147. break;
  148. }
  149. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Switch User" message:msg preferredStyle:UIAlertControllerStyleAlert];
  150. //block代码块取代了delegate
  151. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  152. [self dismissViewControllerAnimated:true completion:^{
  153. if(self.returnValue)
  154. self.returnValue(false);
  155. }];
  156. }];
  157. [alertControl addAction:actionOne];
  158. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  159. [self presentViewController:alertControl animated:YES completion:nil];
  160. //[RAUtils alert_view:msg title:@"Sign in"];
  161. }
  162. });
  163. });
  164. });
  165. });
  166. }
  167. // self.edituser.text = up[@"name"];
  168. // self.editpass.text = up[@"pwd"];
  169. //
  170. // self.showList=false;
  171. // self.Loginlist.hidden=true;
  172. }
  173. //- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
  174. //{
  175. //
  176. // return true;
  177. //}
  178. @end