I have created a window form for login, where user can login with an id and password. After authentication the user can move to the Select_Company form. From there the user select the company and branch and moves to transaction window form.
On initial login the user properly logged in and moved to Select_company window form. When he clicks the log out button on Select_company window form he is moved to the login form again.
On further login from login form he is supposed to move to the select_company form again but the select_company form does not display.
I properly debugged the program. It runs well but I am unable to find the reasons for it not displaying the Select_company window form after further login.
Please advise me on what to do. Thanks in advance.
Below is the code:
Login form:
private void btnLogin_Click(object sender, EventArgs e)
{
if (validation() == true)
{
try
{
conn = Aryan.connString();
Aryan.sqlcon = new System.Data.SqlClient.SqlConnection(conn);
if (Aryan.sqlcon.State == ConnectionState.Closed)
{
Aryan.sqlcon.Open();
}
Aryan.sqlcom = new System.Data.SqlClient.SqlCommand("Str_UserLogin", Aryan.sqlcon);
Aryan.sqlcom.CommandType = CommandType.StoredProcedure;
Aryan.sqlcom.Parameters.AddWithValue("@LoginId", txtUserName.Text);
Aryan.sqlcom.Parameters.AddWithValue("@Password", txtPassword.Text);
System.Data.SqlClient.SqlParameter pm = new System.Data.SqlClient.SqlParameter("@return", SqlDbType.Int);
pm.Direction = ParameterDirection.Output;
pm.Size = 50;
Aryan.sqlcom.Parameters.Add(pm);
System.Data.SqlClient.SqlParameter pm1 = new System.Data.SqlClient.SqlParameter("@UserId", SqlDbType.Int);
pm1.Direction = ParameterDirection.Output;
pm1.Size = 50;
Aryan.sqlcom.Parameters.Add(pm1);
System.Data.SqlClient.SqlParameter pm2 = new System.Data.SqlClient.SqlParameter("@UserType", SqlDbType.VarChar);
pm2.Direction = ParameterDirection.Output;
pm2.Size = 50;
Aryan.sqlcom.Parameters.Add(pm2);
Aryan.sqlcom.ExecuteNonQuery();
int output = (int)Aryan.sqlcom.Parameters["@return"].Value;
if (output == 1)
{
int usercode = (int)Aryan.sqlcom.Parameters["@UserId"].Value;
string userType = (string)Aryan.sqlcom.Parameters["@UserType"].Value;
updateUser(usercode);
Aryan.GetID = usercode;
Aryan.CurrentUserType = userType;
Aryan.CurrentUser = txtUserName.Text;
Aryan.CurrentSession = session;
pAccept = true;
this.Close();
}
else if (output == 10)
{
MessageBox.Show("Invalid Login Id or Password", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtUserName.Text = "";
txtPassword.Text = "";
txtUserName.Focus();
return;
}
else if (output == 20)
{
MessageBox.Show("This User Already Logged in. Contact to Administrator !");
txtUserName.Text = "";
txtPassword.Text = "";
txtUserName.Focus();
return;
}
else if (output == 30)
{
MessageBox.Show("This User Not Permitted For Any Transaction.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtUserName.Text = "";
txtPassword.Text = "";
txtUserName.Focus();
}
else if (output == 40)
{
MessageBox.Show("This User is No Longer Active. Contact to Administrator.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtUserName.Text = "";
txtPassword.Text = "";
txtUserName.Focus();
return;
}
else
{
MessageBox.Show("Problem occur while Login");
return;
}
}
catch (Exception err)
{
MessageBox.Show(err.Message);
}
finally
{
Aryan.sqlcon.Close();
}
}
}
Log out:
private void LogOut()
{
conn = Aryan.connString();
Aryan.sqlcon = new System.Data.SqlClient.SqlConnection(conn);
try
{
if (Aryan.sqlcon.State == ConnectionState.Closed)
{
Aryan.sqlcon.Open();
}
Aryan.sqlcom = new System.Data.SqlClient.SqlCommand("str_LogOut", Aryan.sqlcon);
Aryan.sqlcom.CommandType = CommandType.StoredProcedure;
Aryan.sqlcom.Parameters.AddWithValue("@userId", Aryan.GetID);
Aryan.sqlcom.Parameters.AddWithValue("@LogOut", Aryan.getSqlDateStr(System.DateTime.Now));
Aryan.sqlcom.Parameters.AddWithValue("@TimeOut", Aryan.getSqlTimeStr(System.DateTime.Now));
Aryan.sqlcom.Parameters.AddWithValue("@Session", Aryan.CurrentSession);
Aryan.sqlcom.ExecuteNonQuery();
Aryan.GetID = 0;
Aryan.CurrentUser = "";
Aryan.CurrentSession = 0;
Aryan.CurrentUserType = "";
Aryan.CurrentCompany = "";
Aryan.CurrentBranch = "";
}
catch (Exception err)
{
MessageBox.Show(err.Message);
}
finally
{
Aryan.sqlcon.Close();
}
}
private void btnLogOut_Click(object sender, EventArgs e)
{
LogOut();
lstCompany.Items.Clear();
lstBranch.Items.Clear();
this.Visible = false;
this.Close();
frmLogin Login = new frmLogin();
Login.ShowDialog();
}
MainPage(Parent Form):
private void CheckUser()
{
conn = Aryan.connString();
Aryan.sqlcon = new System.Data.SqlClient.SqlConnection(conn);
try
{
if (Aryan.sqlcon.State == ConnectionState.Closed)
{
Aryan.sqlcon.Open();
}
Aryan.sqlcom = new System.Data.SqlClient.SqlCommand("str_CheckUserFirstTime", Aryan.sqlcon);
Aryan.sqlcom.CommandType = CommandType.StoredProcedure;
System.Data.SqlClient.SqlParameter pm = new System.Data.SqlClient.SqlParameter("return", SqlDbType.Int);
pm.Direction = ParameterDirection.Output;
pm.Size = 50;
Aryan.sqlcom.Parameters.Add(pm);
Aryan.sqlcom.ExecuteNonQuery();
int output = (int)Aryan.sqlcom.Parameters["return"].Value;
if (output == 0)
{
frmSuperuser Super = new frmSuperuser();
Super.ShowDialog();
}
else if (Aryan.CheckInstalledCompany())
{
frmInstallCompany company = new frmInstallCompany();
company.ShowDialog();
}
else
{
frmLogin Login = new frmLogin();
Login.ShowDialog();
if (Login.pAccept)
{
frmSelectCompany SelectCompany = new frmSelectCompany();
SelectCompany.ShowDialog();
if (SelectCompany.DialogResult == DialogResult.Cancel)
{
statusBar.Panels[0].Text = "User Name:" + Aryan.CurrentUser;
statusBar.Panels[1].Text = "User Type:" + Aryan.CurrentUserType;
statusBar.Panels[2].Text = "Session:" + Aryan.CurrentSession;
statusBar.Panels[3].Text = "Branch:" + Aryan.CurrentBranch;
statusBar.Panels[4].Text = "Clock:";
}
}
}
}
catch (Exception err)
{
MessageBox.Show(err.Message);
return;
}
finally
{
Aryan.sqlcon.Close();
}
}