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"
-
- private void login_button_Click(object sender, EventArgs e)
- {
- var organisationId = Convert.ToInt32(organissationlabel.Text);
- string connectionString;
- Password.Text = Encrypt(Password.Text);
- using (var connection = DatabaseLayer.OpenConnection())
- connectionString = ConnectionstringBusinessLogic.GetConnectionStringByOrgid(connection, null, Convert.ToInt32(organissationlabel.Text));
-
- using (var connection = DatabaseLayer.OpenSecondConnection(connectionString))
- using (var transaction = connection.BeginTransaction())
- {
- var userAmmountByOrgId = UserBusinessLogic.GetUserAmmountByOrgId(connection, transaction, organisationId);
- var userAmmountContract = UserBusinessLogic.GetAllowedUsersByOrgId(connection, transaction, organisationId);
-
- if (userAmmountByOrgId >= userAmmountContract)
- label2.Visible = false;
-
- UserBusinessLogic.UserLogin(connection, transaction, Username.Text, Password.Text, organisationId, connectionString);
- transaction.Commit();
- Hide();
- }
- }
- public static void UserLogin(SqlConnection connection, SqlTransaction transaction, string username, string password, int organisationId, string connectionString)
- {
- UserDal.UserLogin(connection, transaction, username, password, organisationId, connectionString);
- }
-
- public static void UserLogin(SqlConnection connection, SqlTransaction transaction, string username, string password, int organisationId, string connectionString)
- {
- if (!username.Equals("") | !password.Equals(""))
- {
- try
- {
- using (var command = connection.CreateCommand())
- {
- command.Transaction = transaction;
- command.CommandText = "SELECT * FROM Employes WHERE Username=@Username and Password=@Password and OrgId=@OrgId";
- command.Parameters.Add("@Username", SqlDbType.NVarChar).Value = username;
- command.Parameters.Add("@Password", SqlDbType.NVarChar).Value = password;
- command.Parameters.Add("@OrgId", SqlDbType.Int).Value = organisationId;
- using (var reader = command.ExecuteReader())
- {
- if (reader.Read())
- {
- MessageBox.Show(Resources.Login_login_button_Click_Login_Successful);;
- var form = new Form1(connectionString);
- form.Show();
-
- }
- else
- MessageBox.Show(Resources.Login_login_button_Click_Invalid_Credentials__Please_Re_Enter);
- }
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- }