Cassie Mod

Cassie Mod

  • NA
  • 488
  • 70.4k

how to hide a form when you are in a different method

May 30 2016 1:22 PM

 hi..

I have the following question. How can I hide a form ? when while i'm not in form itself??  I go from my form to my BusinessLocig to my DataAccesLayer. I want to hide the form in the dataAccessLayer because there it checked if the user is logged in. However when I use Login(form name).Hide() it doesn;t hide.

 
here is my code" 
  1. // method on form login  
  2.  private void login_button_Click(object sender, EventArgs e)  
  3.         {  
  4.             var organisationId = Convert.ToInt32(organissationlabel.Text);  
  5.             string connectionString;  
  6.             Password.Text = Encrypt(Password.Text);  
  7.             using (var connection = DatabaseLayer.OpenConnection())  
  8.                 connectionString = ConnectionstringBusinessLogic.GetConnectionStringByOrgid(connection, null, Convert.ToInt32(organissationlabel.Text));  
  9.   
  10.             using (var connection = DatabaseLayer.OpenSecondConnection(connectionString))  
  11.             using (var transaction = connection.BeginTransaction())  
  12.             {  
  13.                 var userAmmountByOrgId = UserBusinessLogic.GetUserAmmountByOrgId(connection, transaction, organisationId);  
  14.                 var userAmmountContract = UserBusinessLogic.GetAllowedUsersByOrgId(connection, transaction, organisationId);  
  15.   
  16.                 if (userAmmountByOrgId >= userAmmountContract)  
  17.                     label2.Visible = false;  
  18.   
  19.                 UserBusinessLogic.UserLogin(connection, transaction, Username.Text, Password.Text, organisationId, connectionString);  
  20.                 transaction.Commit();  
  21.                 Hide(); // hier moet nog naar gekeken worden  
  22.             }  
  23.         }  
    1. public static void UserLogin(SqlConnection connection, SqlTransaction transaction, string username, string password, int organisationId, string connectionString)  
    2.        {  
    3.            UserDal.UserLogin(connection, transaction, username, password, organisationId, connectionString);  
    4.        }  
    5.   
    6. public static  void UserLogin(SqlConnection connection, SqlTransaction transaction, string username, string password, int organisationId, string connectionString)  
    7.        {  
    8.            if (!username.Equals("") | !password.Equals(""))  
    9.            {  
    10.                try  
    11.                {  
    12.                    using (var command = connection.CreateCommand())  
    13.                    {  
    14.                        command.Transaction = transaction;  
    15.                        command.CommandText = "SELECT * FROM Employes WHERE Username=@Username and Password=@Password and OrgId=@OrgId";  
    16.                        command.Parameters.Add("@Username", SqlDbType.NVarChar).Value = username;  
    17.                        command.Parameters.Add("@Password", SqlDbType.NVarChar).Value = password;  
    18.                        command.Parameters.Add("@OrgId", SqlDbType.Int).Value = organisationId;  
    19.                        using (var reader = command.ExecuteReader())  
    20.                        {  
    21.                            if (reader.Read())  
    22.                            {  
    23.                                MessageBox.Show(Resources.Login_login_button_Click_Login_Successful);;  
    24.                                var form = new Form1(connectionString);  
    25.                                form.Show();  
    26.                                // the hiding should take place here but how ?? login.hide doesn't hide   
    27.                            }  
    28.                            else  
    29.                                MessageBox.Show(Resources.Login_login_button_Click_Invalid_Credentials__Please_Re_Enter);  
    30.                        }  
    31.                    }  
    32.                }  
    33.                catch (Exception ex)  
    34.                {  
    35.                    MessageBox.Show(ex.Message);  
    36.                }  
    37.            }  
    38.        }  

Answers (2)