this is the code from my menu and it creates an instance of another form when clicked.
private void btn_AdminReg_Click(object sender, EventArgs e)
{
this.Hide();
Admin_Login login = new Admin_Login(1);
login.Show();
}
it passes a parameter to varify which login wold it take (same login form is used to login to multiple forms)
in the next form the code looks something like this (Data is a class that i've defined.it has connection string and getting data form db and inserting, updating, deleting all of functions)
public partial class Admin_Login : MetroFramework.Forms.MetroForm
{
int separator; // this is used to separate different logins
public Admin_Login(int value)
{
InitializeComponent();
separator = value;
}
//------- Legend ---------
//if separator= 1 : AdminTerminal
//if separator= 2 : UpdatingTerminal
//if separator= 3 : View Registration
//if separator= 4 : Registration
//if separator= 5 : Reports
//if separator= 6 : Cancel Union
static string path = Path.GetFullPath(Environment.CurrentDirectory);
static string dataBaseName = "Trade_Union_Registration.mdf";
private void btn_Login_Click(object sender, EventArgs e)
{
if (separator == 1)
{
Data getTable = new Data();
DataTable table = getTable.GetData("select UserName,Password from SuperUser where UserName='" + txt_UserName.Text + "' and Password='" + txt_Password.Text + "'");
if (table.Rows.Count == 1)
{
this.Hide();
TerminalAdmin AdminTerminal = new TerminalAdmin();
AdminTerminal.Show();
}
else
{
MetroFramework.MetroMessageBox.Show(this, "Invalid Username/Password please check your Username and Password and try again.", "Access Denied", MessageBoxButtons.OK, MessageBoxIcon.Error);
txt_Password.Clear();
}
}
else if (separator == 2)
{
Data getTable = new Data();
DataTable table = getTable.GetData("select UserName,Password from Admin_Table where UserName='" + txt_UserName.Text + "' and Password='" + txt_Password.Text + "'");
if (table.Rows.Count == 1)
{
Data getter = new Data();
DataTable dt = getter.GetData("select UserID from Admin_Table where UserName='" + txt_UserName.Text + "'");
MessageBox.Show(dt.Rows[0][0].ToString());
this.Hide();
Updating form = new Updating(dt.Rows[0][0].ToString(), txt_UserName.Text);
form.Show();
}
when i run this code my form takes a lot of time to load one form to other form. how to solve this?