private void btnSubmit_Click(object sender, EventArgs e) { //Gets result of validation false = incorrect inputs, true = program may procceed var result = ValidationExistingUser(tb_Username.Text, tb_Password.Text); if (result) { //Checks if there is a matching username and password in tbl_Login using (connection = new SqlConnection(GlobalVariablesClass.connectionString)) using (SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM tbl_Login WHERE username = '******' AND password = '******'", connection)) { DataTable loginTable = new DataTable(); adapter.Fill(loginTable); //No match found, error message shown if (loginTable.Rows.Count == 0) { MessageBox.Show("Login Incorrect, Please try again."); } //Match found and program proceeds to post login screen using this login else if (loginTable.Rows.Count >= 1) { GlobalVariablesClass.customerID = loginTable.Rows[0][3].ToString(); PostLoginScreen frm = new PostLoginScreen(); this.Hide(); frm.ShowDialog(); this.Close(); } } } else { MessageBox.Show(masterMessage); } }
private void button2_Click(object sender, EventArgs e) { PostLoginScreen frm = new PostLoginScreen(); this.Hide(); frm.ShowDialog(); this.Close(); }
private void btnSubmit_Click(object sender, EventArgs e) { //Gets result of validation false = incorrect inputs, true = program may procceed var result1 = ValidationLoginDetails(tb_Username.Text, tb_Password.Text); var result2 = ValidationCustomerDetails(tb_FName.Text, tb_LName.Text, tb_Dob.Text, tb_HomeAddress.Text); if (result1 && result2) { using (connection = new SqlConnection(GlobalVariablesClass.connectionString)) { //Inserts the customer details into tbl_Customer and returns the customerID for use in forming the tbl_Login part of the record using (SqlDataAdapter adapter = new SqlDataAdapter("INSERT INTO tbl_Customer ([First Name],[Last Name],[Gender],[Date Of Birth],[House Address]) VALUES (@FName,@LName,@Gender,@Dob,@HAddress); SELECT SCOPE_IDENTITY()", connection)) { adapter.SelectCommand.Parameters.AddWithValue("@FName", tb_FName.Text.ToLower()); adapter.SelectCommand.Parameters.AddWithValue("@LName", tb_LName.Text.ToLower()); adapter.SelectCommand.Parameters.AddWithValue("@Gender", drpbx_Gender.SelectedItem); adapter.SelectCommand.Parameters.AddWithValue("@Dob", tb_Dob.Text); adapter.SelectCommand.Parameters.AddWithValue("@HAddress", tb_HomeAddress.Text.ToLower()); DataTable customerID = new DataTable(); adapter.Fill(customerID); GlobalVariablesClass.customerID = customerID.Rows[0][0].ToString(); } //Inserts the login details into tbl_Login where the code above provides the customerID foreign key link. using (SqlCommand command = new SqlCommand("INSERT INTO tbl_Login ([username],[password],[customerID]) VALUES (@username,@password,@customerID)", connection)) { command.Parameters.AddWithValue("@username", tb_Username.Text.ToLower()); command.Parameters.AddWithValue("@password", tb_Password.Text.ToLower()); command.Parameters.AddWithValue("@customerID", Convert.ToInt32(GlobalVariablesClass.customerID)); connection.Open(); command.ExecuteNonQuery(); connection.Close(); } //Loads the post login screen upon successful database addition PostLoginScreen frm = new PostLoginScreen(); this.Hide(); frm.ShowDialog(); this.Close(); } } else { MessageBox.Show(masterMessage); } }