Эх сурвалжийг харах

160805
optimised login dialog save password logic

Ray Zhang 9 жил өмнө
parent
commit
a2b156ba94

+ 57 - 38
RedAnt ERP Mobile/common/Functions/sidemenu/LoginViewController.m

@@ -41,7 +41,7 @@
 #endif
 #endif
     self.showList = false;
     self.showList = false;
     
     
-  
+    
     self.bb_close.image=[[UIImage imageNamed:@"close"] imageWithRenderingMode:UIImageRenderingModeAutomatic];
     self.bb_close.image=[[UIImage imageNamed:@"close"] imageWithRenderingMode:UIImageRenderingModeAutomatic];
     
     
     [self.checkSavePassword setImage:[UIImage imageNamed:@"checkbox"] forState:UIControlStateNormal];
     [self.checkSavePassword setImage:[UIImage imageNamed:@"checkbox"] forState:UIControlStateNormal];
@@ -66,12 +66,12 @@
         self.checkSavePassword.selected=true;
         self.checkSavePassword.selected=true;
         
         
     }
     }
- //   NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
-//    [defaults removeObjectForKey:@"EnableOfflineMode"];
-//    [defaults setBool:self.checkOfflineMode.selected forKey:@"EnableOfflineMode"];
+    //   NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
+    //    [defaults removeObjectForKey:@"EnableOfflineMode"];
+    //    [defaults setBool:self.checkOfflineMode.selected forKey:@"EnableOfflineMode"];
     self.checkOfflineMode.selected=[defaults boolForKey:@"EnableOfflineMode"];
     self.checkOfflineMode.selected=[defaults boolForKey:@"EnableOfflineMode"];
     
     
-     [self.checkOfflineMode addTarget:self action:@selector(checkboxClick:) forControlEvents:UIControlEventTouchUpInside];
+    [self.checkOfflineMode addTarget:self action:@selector(checkboxClick:) forControlEvents:UIControlEventTouchUpInside];
     
     
     [self.checkSavePassword addTarget:self action:@selector(checkboxClick:) forControlEvents:UIControlEventTouchUpInside];
     [self.checkSavePassword addTarget:self action:@selector(checkboxClick:) forControlEvents:UIControlEventTouchUpInside];
     self.checkOfflineMode.tag=999;
     self.checkOfflineMode.tag=999;
@@ -82,7 +82,7 @@
     
     
     UIButton* combobutton=[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 24, 24)];
     UIButton* combobutton=[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 24, 24)];
     [combobutton setBackgroundImage:[UIImage imageNamed:@"combo_24"] forState:UIControlStateNormal];
     [combobutton setBackgroundImage:[UIImage imageNamed:@"combo_24"] forState:UIControlStateNormal];
-        [combobutton addTarget:self action:@selector(LoginList:) forControlEvents:UIControlEventTouchUpInside];
+    [combobutton addTarget:self action:@selector(LoginList:) forControlEvents:UIControlEventTouchUpInside];
     
     
     self.edituser.rightView = combobutton;
     self.edituser.rightView = combobutton;
     self.edituser.rightViewMode=UITextFieldViewModeAlways;
     self.edituser.rightViewMode=UITextFieldViewModeAlways;
@@ -91,7 +91,7 @@
     
     
     self.Loginlist.layer.borderColor = [UIColor lightGrayColor].CGColor;
     self.Loginlist.layer.borderColor = [UIColor lightGrayColor].CGColor;
     self.Loginlist.layer.borderWidth = 1.0;
     self.Loginlist.layer.borderWidth = 1.0;
-  //  self.Loginlist.layer.cornerRadius=15;
+    //  self.Loginlist.layer.cornerRadius=15;
     self.Loginlist.layer.masksToBounds=true;
     self.Loginlist.layer.masksToBounds=true;
     // Do any additional setup after loading the view.
     // Do any additional setup after loading the view.
 }
 }
@@ -99,7 +99,7 @@
     [self.edituser endEditing:true];
     [self.edituser endEditing:true];
     self.showList= !self.showList;
     self.showList= !self.showList;
     self.Loginlist.hidden = !self.showList;
     self.Loginlist.hidden = !self.showList;
-//    showList;
+    //    showList;
 }
 }
 -(void)checkboxClick:(UIButton *)btn
 -(void)checkboxClick:(UIButton *)btn
 {
 {
@@ -131,7 +131,7 @@
         }
         }
         else
         else
         {
         {
-                        NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
+            NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
             [defaults removeObjectForKey:@"EnableOfflineMode"];
             [defaults removeObjectForKey:@"EnableOfflineMode"];
             [defaults setBool:self.checkOfflineMode.selected forKey:@"EnableOfflineMode"];
             [defaults setBool:self.checkOfflineMode.selected forKey:@"EnableOfflineMode"];
             
             
@@ -139,15 +139,34 @@
             AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
             AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
             appDelegate.offline_mode = self.checkOfflineMode.selected;
             appDelegate.offline_mode = self.checkOfflineMode.selected;
         }
         }
-
-
+        
+        
+    }
+    else
+    {
+        if(!btn.selected)
+        {
+            NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
+            [defaults removeObjectForKey:@"user"];
+            [defaults removeObjectForKey:@"password"];
+            [defaults synchronize];
+            
+            
+            NSString* encryptu=[AESCrypt encrypt:self.edituser.text password:@"usai"];
+            
+            NSString* sql=[NSString stringWithFormat:@"delete from login_info where name='%@'",encryptu];
+            [iSalesDB execSql:sql];
+            self.logindata = [iSalesDB get_saveduser];
+            [self.Loginlist reloadData];
+        }
+        
     }
     }
 }
 }
 - (IBAction)CloseClick:(id)sender {
 - (IBAction)CloseClick:(id)sender {
     
     
     [self dismissViewControllerAnimated:true completion:nil];
     [self dismissViewControllerAnimated:true completion:nil];
-                    if(self.returnValue)
-                        self.returnValue(false);
+    if(self.returnValue)
+        self.returnValue(false);
     
     
     
     
     
     
@@ -165,12 +184,12 @@
     
     
     if(user.length==0||password.length==0)
     if(user.length==0||password.length==0)
     {
     {
-//        UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Error!" message:@"user or password can not be empty." delegate:nil cancelButtonTitle:NSLocalizedString(@"ok", nil) otherButtonTitles:nil, nil];
-//        //        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Error!" message:@"User&Password can not be empty!" delegate:nil cancelButtonTitle:NSLocalizedString(@"ok", nil) , nil];
-//        
-//        
-//        //[[UILabel appearanceWhenContainedIn:UIAlertView.class, nil] setAppearanceFont:[UIFont boldSystemFontOfSize:10]];
-//        [alert show];
+        //        UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Error!" message:@"user or password can not be empty." delegate:nil cancelButtonTitle:NSLocalizedString(@"ok", nil) otherButtonTitles:nil, nil];
+        //        //        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Error!" message:@"User&Password can not be empty!" delegate:nil cancelButtonTitle:NSLocalizedString(@"ok", nil) , nil];
+        //
+        //
+        //        //[[UILabel appearanceWhenContainedIn:UIAlertView.class, nil] setAppearanceFont:[UIFont boldSystemFontOfSize:10]];
+        //        [alert show];
         
         
         
         
         [RAUtils alert_view:@"User or password cannot be empty." title:@"Input Error!"];
         [RAUtils alert_view:@"User or password cannot be empty." title:@"Input Error!"];
@@ -179,7 +198,7 @@
     DebugLog(@"Login...   user= %@ ; password= %@",user,password);
     DebugLog(@"Login...   user= %@ ; password= %@",user,password);
     
     
     
     
-
+    
     
     
     self.btnLogin.enabled = false;
     self.btnLogin.enabled = false;
     UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Sign in"];
     UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Sign in"];
@@ -196,11 +215,11 @@
                 
                 
             {
             {
                 
                 
-//                
-//                NSString* contactid=[self.content_data[indexPath.row] valueForKey:@"contact_id"] ;
+                //
+                //                NSString* contactid=[self.content_data[indexPath.row] valueForKey:@"contact_id"] ;
                 AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
                 AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-//                appDelegate.contact_id=contactid;
-//                appDelegate.contact_name =[self.content_data[indexPath.row] valueForKey:@"name"];
+                //                appDelegate.contact_id=contactid;
+                //                appDelegate.contact_name =[self.content_data[indexPath.row] valueForKey:@"name"];
                 
                 
                 NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
                 NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
                 [defaults removeObjectForKey:@"user"];
                 [defaults removeObjectForKey:@"user"];
@@ -218,9 +237,9 @@
                     
                     
                     if(count==0)
                     if(count==0)
                     {
                     {
-                    
-                    NSString * savelogin=[NSString stringWithFormat:@"insert into login_info(name,pwd) values('%@','%@')",encryptu,encryptp];
-                    [iSalesDB execSql:savelogin db:db];
+                        
+                        NSString * savelogin=[NSString stringWithFormat:@"insert into login_info(name,pwd) values('%@','%@')",encryptu,encryptp];
+                        [iSalesDB execSql:savelogin db:db];
                     }
                     }
                     else
                     else
                     {
                     {
@@ -229,8 +248,8 @@
                     }
                     }
                     
                     
                     [iSalesDB close_db:db];
                     [iSalesDB close_db:db];
-
-//                    [defaults setBool:TRUE forKey:@"autologin"];
+                    
+                    //                    [defaults setBool:TRUE forKey:@"autologin"];
                 }
                 }
                 else
                 else
                 {
                 {
@@ -243,16 +262,16 @@
                 if(self.returnValue)
                 if(self.returnValue)
                     self.returnValue(true);
                     self.returnValue(true);
                 
                 
-//                if (self.delegate && [self.delegate respondsToSelector:@selector(LoginViewControllerDidLogin:)]) {
-//                    [self.delegate LoginViewControllerDidLogin:self];
-//                }
+                //                if (self.delegate && [self.delegate respondsToSelector:@selector(LoginViewControllerDidLogin:)]) {
+                //                    [self.delegate LoginViewControllerDidLogin:self];
+                //                }
             }
             }
             else
             else
             {
             {
                 NSString* msg=nil;
                 NSString* msg=nil;
                 
                 
                 switch (ret) {
                 switch (ret) {
-
+                        
                     case RESULT_NET_NOTAVAILABLE:
                     case RESULT_NET_NOTAVAILABLE:
                         msg = MSG_NET_NOTAVAILABLE;
                         msg = MSG_NET_NOTAVAILABLE;
                         break;
                         break;
@@ -280,7 +299,7 @@
                 
                 
                 [RAUtils alert_view:msg title:@"Sign in"];
                 [RAUtils alert_view:msg title:@"Sign in"];
                 
                 
-
+                
                 
                 
             }
             }
             
             
@@ -329,14 +348,14 @@
     UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
     UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
     NSString* name=up[@"name"];
     NSString* name=up[@"name"];
     cell.textLabel.text = name;
     cell.textLabel.text = name;
-       return cell;
-
+    return cell;
+    
 }
 }
 
 
 
 
 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
 {
 {
- 
+    
     NSMutableDictionary* up = self.logindata[indexPath.row];
     NSMutableDictionary* up = self.logindata[indexPath.row];
     self.edituser.text = up[@"name"];
     self.edituser.text = up[@"name"];
     self.editpass.text = up[@"pwd"];
     self.editpass.text = up[@"pwd"];
@@ -344,7 +363,7 @@
     self.showList=false;
     self.showList=false;
     self.Loginlist.hidden=true;
     self.Loginlist.hidden=true;
     self.checkSavePassword.selected=true;
     self.checkSavePassword.selected=true;
-
+    
 }
 }
 //- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
 //- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
 //{
 //{

+ 57 - 53
RedAnt ERP Mobile/iSales-NPD/AppDelegate.m

@@ -535,65 +535,23 @@
     //  [appearanceLabel setAppearanceFont:[UIFont boldSystemFontOfSize:10]]; //for example
     //  [appearanceLabel setAppearanceFont:[UIFont boldSystemFontOfSize:10]]; //for example
     return YES;
     return YES;
 }
 }
--(void)test_descrypt
-{
-    sqlite3 *db = [iSalesDB get_db];
-    
-   int result= [iSalesDB AddExFunction:db];
-    
-    NSString *sqlQuery = [NSString stringWithFormat:@"select decrypt(company_name) from offline_contact;"];
-    sqlite3_stmt * statement;
-    
-    
-    if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
-    {
-        
-        
-        while (sqlite3_step(statement) == SQLITE_ROW)
-        {
-           
-            
-            char *url = (char*)sqlite3_column_text(statement, 0);
-            if(url==nil)
-                url="";
-            NSString *nsurl = [[NSString alloc]initWithUTF8String:url];
-            NSLog(nsurl);
-            
-            
-           
-            
-        }
-      //  [ret setValue:[NSString stringWithFormat:@"%d",i] forKey:@"img_count"];
-        
-        
-        sqlite3_finalize(statement);
-    }
-    
-    [iSalesDB close_db:db];
-}
-
--(void)test_descrypt1
-{
-    sqlite3 *db = [iSalesDB get_db];
-    
-    int result= [iSalesDB AddExFunction:db];
-    
-    NSString* sqlindex= @"CREATE INDEX hijk ON offline_contact (lower(company_name));";
-    
-    [iSalesDB execSql:sqlindex];
+//-(void)test_descrypt
+//{
+//    sqlite3 *db = [iSalesDB get_db];
+//    
+//   int result= [iSalesDB AddExFunction:db];
 //    
 //    
 //    NSString *sqlQuery = [NSString stringWithFormat:@"select decrypt(company_name) from offline_contact;"];
 //    NSString *sqlQuery = [NSString stringWithFormat:@"select decrypt(company_name) from offline_contact;"];
 //    sqlite3_stmt * statement;
 //    sqlite3_stmt * statement;
 //    
 //    
 //    
 //    
-//    
 //    if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
 //    if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
 //    {
 //    {
 //        
 //        
 //        
 //        
 //        while (sqlite3_step(statement) == SQLITE_ROW)
 //        while (sqlite3_step(statement) == SQLITE_ROW)
 //        {
 //        {
-//            
+//           
 //            
 //            
 //            char *url = (char*)sqlite3_column_text(statement, 0);
 //            char *url = (char*)sqlite3_column_text(statement, 0);
 //            if(url==nil)
 //            if(url==nil)
@@ -602,17 +560,59 @@
 //            NSLog(nsurl);
 //            NSLog(nsurl);
 //            
 //            
 //            
 //            
-//            
+//           
 //            
 //            
 //        }
 //        }
-//        //  [ret setValue:[NSString stringWithFormat:@"%d",i] forKey:@"img_count"];
+//      //  [ret setValue:[NSString stringWithFormat:@"%d",i] forKey:@"img_count"];
 //        
 //        
 //        
 //        
 //        sqlite3_finalize(statement);
 //        sqlite3_finalize(statement);
 //    }
 //    }
-    
-    [iSalesDB close_db:db];
-}
+//    
+//    [iSalesDB close_db:db];
+//}
+//
+//-(void)test_descrypt1
+//{
+//    sqlite3 *db = [iSalesDB get_db];
+//    
+//    int result= [iSalesDB AddExFunction:db];
+//    
+//    NSString* sqlindex= @"CREATE INDEX hijk ON offline_contact (lower(company_name));";
+//    
+//    [iSalesDB execSql:sqlindex];
+////    
+////    NSString *sqlQuery = [NSString stringWithFormat:@"select decrypt(company_name) from offline_contact;"];
+////    sqlite3_stmt * statement;
+////    
+////    
+////    
+////    if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
+////    {
+////        
+////        
+////        while (sqlite3_step(statement) == SQLITE_ROW)
+////        {
+////            
+////            
+////            char *url = (char*)sqlite3_column_text(statement, 0);
+////            if(url==nil)
+////                url="";
+////            NSString *nsurl = [[NSString alloc]initWithUTF8String:url];
+////            NSLog(nsurl);
+////            
+////            
+////            
+////            
+////        }
+////        //  [ret setValue:[NSString stringWithFormat:@"%d",i] forKey:@"img_count"];
+////        
+////        
+////        sqlite3_finalize(statement);
+////    }
+//    
+//    [iSalesDB close_db:db];
+//}
 
 
 - (void)applicationWillResignActive:(UIApplication *)application
 - (void)applicationWillResignActive:(UIApplication *)application
 {
 {
@@ -1569,6 +1569,10 @@
                     //  [self SelectData];
                     //  [self SelectData];
                 }
                 }
                 
                 
+            }
+            else if([type isEqualToString:@"script"])
+            {
+                
             }
             }
             else if([type isEqualToString:@"resource"])
             else if([type isEqualToString:@"resource"])
             {
             {