| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583 |
- //
- // UserListViewController.m
- // iSales-NPD
- //
- // Created by Ray on 4/19/16.
- // Copyright © 2016 United Software Applications, Inc. All rights reserved.
- //
- #import "UserListViewController.h"
- #import "MainViewController.h"
- @interface UserListViewController ()
- @end
- @implementation UserListViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- self.edgesForExtendedLayout = UIRectEdgeNone;
-
- self.bb_close.image=[[UIImage imageNamed:@"close"] imageWithRenderingMode:UIImageRenderingModeAutomatic];
-
-
-
- self.logindata = [iSalesDB get_saveduser];
-
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- - (IBAction)CloseClick:(id)sender {
-
- [self dismissViewControllerAnimated:true completion:nil];
- // if(self.returnValue)
- // self.returnValue(false);
-
-
-
- }
- /*
- #pragma mark - Navigation
-
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- #pragma mark - Table view data source
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
- {
- return 44;
-
-
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return self.logindata.count;
-
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
-
- NSMutableDictionary* up = self.logindata[indexPath.row];
-
-
-
- NSString *CellIdentifier = @"LoginListCell";
- UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- NSString* name=up[@"name"];
- cell.textLabel.text = name;
- return cell;
-
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
-
-
- NSMutableDictionary* up = self.logindata[indexPath.row];
-
- NSString *user = up[@"name"];
- NSString *password = up[@"pwd"];
-
- if (user.length == 0 || password.length == 0) {
- [self dismissViewControllerAnimated:YES completion:nil];
- return;
- }
-
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
-
- if(appDelegate.bLogin)
- {
- if ([user.lowercaseString isEqualToString:appDelegate.user.lowercaseString]) { // 当前用户
- [self dismissViewControllerAnimated:YES completion:nil];
- return;
- }
-
- UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Switch user"];
-
- [RANetwork request_logout:^(NSMutableDictionary *result) {
-
-
-
- appDelegate.cart_count = 0;
- appDelegate.wish_count =0;
- appDelegate.port_count =0;
-
- [appDelegate update_count_mark];
-
-
- appDelegate.can_show_price =false;
- appDelegate.can_see_price =false;
- appDelegate.can_create_portfolio =false;
- appDelegate.can_create_order =false;
-
-
- appDelegate.can_cancel_order =false;
- appDelegate.can_set_cart_price =false;
- appDelegate.can_delete_order =false;
- appDelegate.can_submit_order =false;
- appDelegate.can_set_tearsheet_price =false;
- appDelegate.can_update_contact_info = false;
-
- appDelegate.save_order_logout = false;
- appDelegate.submit_order_logout = false;
- appDelegate.alert_sold_in_quantities = false;
-
- appDelegate.ipad_perm =nil ;
- appDelegate.user_type = USER_ROLE_UNKNOWN;
- appDelegate.OrderFilter= nil;
- [appDelegate SetSo:nil];
- [appDelegate set_main_button_panel];
-
- [appDelegate Logout];
- [appDelegate checkLogin:NO];
-
- // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
-
- [RANetwork request_login:user password:password completionHandler:^(NSMutableDictionary *result) {
- int ret=[result[@"result"]intValue];
-
-
- [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
-
- if(ret==RESULT_TRUE)
- {
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
- NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
- [defaults removeObjectForKey:@"user"];
- [defaults removeObjectForKey:@"password"];
- if(true)
- {
- NSString* encryptu=[AESCrypt encrypt:appDelegate.user password:@"usai"];
- NSString* encryptp=[AESCrypt encrypt:appDelegate.password password:@"usai"] ;
-
- [defaults setValue:encryptu forKey:@"user"];
- [defaults setValue:encryptp forKey:@"password"];
-
- }
- [defaults synchronize];
-
- MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
- if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
- {
- [main_vc checklogin:false];
- }
- else
- {
- [main_vc checklogin:false];
- }
-
- [self dismissViewControllerAnimated:true completion:^{
- if(self.returnValue)
- self.returnValue(true);
- }];
-
- } // 登陆成功
- else
- {
- NSString* msg=nil;
-
- switch (ret) {
-
- case RESULT_NET_NOTAVAILABLE:
- msg = MSG_NET_NOTAVAILABLE;
- break;
-
-
- case RESULT_NET_ERROR:
- msg = MSG_NET_ERROR;
- break;
-
-
- case RESULT_FALSE:
- msg = MSG_USERAUTH_ERROR;
- break;
-
- case RESULT_VER_LOW:
- msg = MSG_VER_LOW;
- break;
- default:
- break;
- }
-
-
- UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Switch User" message:msg preferredStyle:UIAlertControllerStyleAlert];
- //block代码块取代了delegate
- UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
-
- [self dismissViewControllerAnimated:true completion:^{
- if(self.returnValue)
- self.returnValue(false);
- }];
-
- }];
-
-
- [alertControl addAction:actionOne];
-
- [self presentViewController:alertControl animated:YES completion:nil];
-
- } // 登陆失败
-
-
- }];
-
-
- // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- //
- // int ret=[RANetwork Authorize:user password:password];
- //
- // dispatch_async(dispatch_get_main_queue(), ^{
- //
- // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
- //
- // if(ret==RESULT_TRUE)
- // {
- // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- //
- // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
- // [defaults removeObjectForKey:@"user"];
- // [defaults removeObjectForKey:@"password"];
- // if(true)
- // {
- // NSString* encryptu=[AESCrypt encrypt:appDelegate.user password:@"usai"];
- // NSString* encryptp=[AESCrypt encrypt:appDelegate.password password:@"usai"] ;
- //
- // [defaults setValue:encryptu forKey:@"user"];
- // [defaults setValue:encryptp forKey:@"password"];
- //
- // }
- // [defaults synchronize];
- //
- // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
- // if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
- // {
- // [main_vc checklogin:false];
- // }
- // else
- // {
- // [main_vc checklogin:false];
- // }
- //
- // [self dismissViewControllerAnimated:true completion:^{
- // if(self.returnValue)
- // self.returnValue(true);
- // }];
- //
- // } // 登陆成功
- // else
- // {
- // NSString* msg=nil;
- //
- // switch (ret) {
- //
- // case RESULT_NET_NOTAVAILABLE:
- // msg = MSG_NET_NOTAVAILABLE;
- // break;
- //
- //
- // case RESULT_NET_ERROR:
- // msg = MSG_NET_ERROR;
- // break;
- //
- //
- // case RESULT_FALSE:
- // msg = MSG_USERAUTH_ERROR;
- // break;
- //
- // case RESULT_VER_LOW:
- // msg = MSG_VER_LOW;
- // break;
- // default:
- // break;
- // }
- //
- //
- // UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Switch User" message:msg preferredStyle:UIAlertControllerStyleAlert];
- // //block代码块取代了delegate
- // UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
- //
- // [self dismissViewControllerAnimated:true completion:^{
- // if(self.returnValue)
- // self.returnValue(false);
- // }];
- //
- // }];
- //
- //
- // [alertControl addAction:actionOne];
- //
- // [self presentViewController:alertControl animated:YES completion:nil];
- //
- // } // 登陆失败
- //
- // }); // update login ui
- //
- // }); // attemp login
-
-
- }];
-
- // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- //
- // [RANetwork logout];
- //
- // dispatch_async(dispatch_get_main_queue(), ^{
- //
- //
- // appDelegate.cart_count = 0;
- // appDelegate.wish_count =0;
- // appDelegate.port_count =0;
- //
- // [appDelegate update_count_mark];
- //
- //
- // appDelegate.can_show_price =false;
- // appDelegate.can_see_price =false;
- // appDelegate.can_create_portfolio =false;
- // appDelegate.can_create_order =false;
- //
- //
- // appDelegate.can_cancel_order =false;
- // appDelegate.can_set_cart_price =false;
- // appDelegate.can_delete_order =false;
- // appDelegate.can_submit_order =false;
- // appDelegate.can_set_tearsheet_price =false;
- // appDelegate.can_update_contact_info = false;
- //
- // appDelegate.save_order_logout = false;
- // appDelegate.submit_order_logout = false;
- // appDelegate.alert_sold_in_quantities = false;
- //
- // appDelegate.ipad_perm =nil ;
- // appDelegate.user_type = USER_ROLE_UNKNOWN;
- // appDelegate.OrderFilter= nil;
- // [appDelegate SetSo:nil];
- // [appDelegate set_main_button_panel];
- //
- // [appDelegate Logout];
- // [appDelegate checkLogin:NO];
- //
- //// [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
- //
- // [RANetwork request_login:user password:password completionHandler:^(NSMutableDictionary *result) {
- // int ret=[result[@"result"]intValue];
- //
- //
- // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
- //
- // if(ret==RESULT_TRUE)
- // {
- // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- //
- // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
- // [defaults removeObjectForKey:@"user"];
- // [defaults removeObjectForKey:@"password"];
- // if(true)
- // {
- // NSString* encryptu=[AESCrypt encrypt:appDelegate.user password:@"usai"];
- // NSString* encryptp=[AESCrypt encrypt:appDelegate.password password:@"usai"] ;
- //
- // [defaults setValue:encryptu forKey:@"user"];
- // [defaults setValue:encryptp forKey:@"password"];
- //
- // }
- // [defaults synchronize];
- //
- // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
- // if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
- // {
- // [main_vc checklogin:false];
- // }
- // else
- // {
- // [main_vc checklogin:false];
- // }
- //
- // [self dismissViewControllerAnimated:true completion:^{
- // if(self.returnValue)
- // self.returnValue(true);
- // }];
- //
- // } // 登陆成功
- // else
- // {
- // NSString* msg=nil;
- //
- // switch (ret) {
- //
- // case RESULT_NET_NOTAVAILABLE:
- // msg = MSG_NET_NOTAVAILABLE;
- // break;
- //
- //
- // case RESULT_NET_ERROR:
- // msg = MSG_NET_ERROR;
- // break;
- //
- //
- // case RESULT_FALSE:
- // msg = MSG_USERAUTH_ERROR;
- // break;
- //
- // case RESULT_VER_LOW:
- // msg = MSG_VER_LOW;
- // break;
- // default:
- // break;
- // }
- //
- //
- // UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Switch User" message:msg preferredStyle:UIAlertControllerStyleAlert];
- // //block代码块取代了delegate
- // UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
- //
- // [self dismissViewControllerAnimated:true completion:^{
- // if(self.returnValue)
- // self.returnValue(false);
- // }];
- //
- // }];
- //
- //
- // [alertControl addAction:actionOne];
- //
- // [self presentViewController:alertControl animated:YES completion:nil];
- //
- // } // 登陆失败
- //
- //
- // }];
- //
- //
- //// dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- ////
- //// int ret=[RANetwork Authorize:user password:password];
- ////
- //// dispatch_async(dispatch_get_main_queue(), ^{
- ////
- //// [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
- ////
- //// if(ret==RESULT_TRUE)
- //// {
- //// AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- ////
- //// NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
- //// [defaults removeObjectForKey:@"user"];
- //// [defaults removeObjectForKey:@"password"];
- //// if(true)
- //// {
- //// NSString* encryptu=[AESCrypt encrypt:appDelegate.user password:@"usai"];
- //// NSString* encryptp=[AESCrypt encrypt:appDelegate.password password:@"usai"] ;
- ////
- //// [defaults setValue:encryptu forKey:@"user"];
- //// [defaults setValue:encryptp forKey:@"password"];
- ////
- //// }
- //// [defaults synchronize];
- ////
- //// MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
- //// if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
- //// {
- //// [main_vc checklogin:false];
- //// }
- //// else
- //// {
- //// [main_vc checklogin:false];
- //// }
- ////
- //// [self dismissViewControllerAnimated:true completion:^{
- //// if(self.returnValue)
- //// self.returnValue(true);
- //// }];
- ////
- //// } // 登陆成功
- //// else
- //// {
- //// NSString* msg=nil;
- ////
- //// switch (ret) {
- ////
- //// case RESULT_NET_NOTAVAILABLE:
- //// msg = MSG_NET_NOTAVAILABLE;
- //// break;
- ////
- ////
- //// case RESULT_NET_ERROR:
- //// msg = MSG_NET_ERROR;
- //// break;
- ////
- ////
- //// case RESULT_FALSE:
- //// msg = MSG_USERAUTH_ERROR;
- //// break;
- ////
- //// case RESULT_VER_LOW:
- //// msg = MSG_VER_LOW;
- //// break;
- //// default:
- //// break;
- //// }
- ////
- ////
- //// UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Switch User" message:msg preferredStyle:UIAlertControllerStyleAlert];
- //// //block代码块取代了delegate
- //// UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
- ////
- //// [self dismissViewControllerAnimated:true completion:^{
- //// if(self.returnValue)
- //// self.returnValue(false);
- //// }];
- ////
- //// }];
- ////
- ////
- //// [alertControl addAction:actionOne];
- ////
- //// [self presentViewController:alertControl animated:YES completion:nil];
- ////
- //// } // 登陆失败
- ////
- //// }); // update login ui
- ////
- //// }); // attemp login
- //
- // }); // update logout ui
- //
- // }); // logout
- }
-
-
- // self.edituser.text = up[@"name"];
- // self.editpass.text = up[@"pwd"];
- //
- // self.showList=false;
- // self.Loginlist.hidden=true;
-
-
- }
- //- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
- //{
- //
- // return true;
- //}
- @end
|