private void btnSubmit_Click(object sender, EventArgs e) { if (tbEmail.Text == tbConfirmEmail.Text) { Globals.email = tbEmail.Text; if (tbPass.Text == tbConfirmPass.Text) { if (CheckEntries() == 0) { String connectionString = @"Data Source=(LocalDB)\ProjectsV12;Initial Catalog=FullerTV;Integrated Security=true"; String commandString = "EXEC [dbo].[spInsertNewMember] @FirstName,@LastName,@Email,@Password,@Address,@City,@State,@ZipCode,@DOB,@Sex"; using (var conn = new SqlConnection(connectionString)) { try { conn.Open(); string txtSex; string txtAddress = tbAddress.Text; string txtCity = tbCity.Text; string txtState = cbState.Text; string txtZipCode = tbZipCode.Text; var txtDOB = dtpDOB.Value; string txtEmail = tbEmail.Text; string txtPass = tbPass.Text; string txtFirstName = tbFirstName.Text; string txtLastName = tbLastName.Text; if (rbMale.Checked) { txtSex = "M"; } else { txtSex = "F"; } using (var cmd = new SqlCommand(commandString, conn)) { var param1 = new SqlParameter(); param1.ParameterName = "@FirstName"; param1.SqlDbType = SqlDbType.VarChar; param1.Direction = ParameterDirection.Input; param1.Value = txtFirstName; var param2 = new SqlParameter(); param2.ParameterName = "@LastName"; param2.SqlDbType = SqlDbType.VarChar; param2.Direction = ParameterDirection.Input; param2.Value = txtLastName; var param3 = new SqlParameter(); param3.ParameterName = "@Email"; param3.SqlDbType = SqlDbType.VarChar; param3.Direction = ParameterDirection.Input; param3.Value = txtEmail; var param4 = new SqlParameter(); param4.ParameterName = "@Password"; param4.SqlDbType = SqlDbType.VarChar; param4.Direction = ParameterDirection.Input; param4.Value = txtPass; var param5 = new SqlParameter(); param5.ParameterName = "@Address"; param5.SqlDbType = SqlDbType.VarChar; param5.Direction = ParameterDirection.Input; param5.Value = txtAddress; var param6 = new SqlParameter(); param6.ParameterName = "@City"; param6.SqlDbType = SqlDbType.VarChar; param6.Direction = ParameterDirection.Input; param6.Value = txtCity; var param7 = new SqlParameter(); param7.ParameterName = "@State"; param7.SqlDbType = SqlDbType.VarChar; param7.Direction = ParameterDirection.Input; param7.Value = txtState; var param8 = new SqlParameter(); param8.ParameterName = "@ZipCode"; param8.SqlDbType = SqlDbType.VarChar; param8.Direction = ParameterDirection.Input; param8.Value = txtZipCode; var param9 = new SqlParameter(); param9.ParameterName = "@DOB"; param9.SqlDbType = SqlDbType.Date; param9.Direction = ParameterDirection.Input; param9.Value = txtDOB; var param10 = new SqlParameter(); param10.ParameterName = "@Sex"; param10.SqlDbType = SqlDbType.VarChar; param10.Direction = ParameterDirection.Input; param10.Value = txtSex; cmd.Parameters.Add(param1); cmd.Parameters.Add(param2); cmd.Parameters.Add(param3); cmd.Parameters.Add(param4); cmd.Parameters.Add(param5); cmd.Parameters.Add(param6); cmd.Parameters.Add(param7); cmd.Parameters.Add(param8); cmd.Parameters.Add(param9); cmd.Parameters.Add(param10); cmd.ExecuteNonQuery(); MessageBox.Show(string.Format("{0} {1} added successfully :)", txtFirstName, txtLastName, MessageBoxButtons.OK)); ClearTextBoxes(); this.Hide(); var setact = new SetAccountForm(); setact.FormClosed += (s, args) => this.Close(); setact.Show(); } } catch (Exception ee) { string str = ee.ToString(); if (str.Contains("email already exists")) { MessageBox.Show("Error: Member with this email already exists!"); } else { MessageBox.Show(str); } ClearTextBoxes(); } } } } else { MessageBox.Show("Passwords do not match!"); } } else { MessageBox.Show("Emails do not match!"); } }
private void btnSubmit_Click(object sender, EventArgs e) { String connectionString = @"Data Source=(LocalDB)\ProjectsV12;Initial Catalog=FullerTV;Integrated Security=true"; String commandString = "EXEC [dbo].[spLoginMember] @Email,@Password"; using (var conn = new SqlConnection(connectionString)) { try { try { conn.Open(); string txtEmail = tbEmail.Text; string txtPass = tbPass.Text; if (string.IsNullOrWhiteSpace(txtEmail)) { MessageBox.Show("Email required"); } else if (string.IsNullOrWhiteSpace(txtPass)) { MessageBox.Show("Password required"); } using (var cmd = new SqlCommand(commandString, conn)) { var param1 = new SqlParameter(); param1.ParameterName = "@Email"; param1.SqlDbType = SqlDbType.VarChar; param1.Direction = ParameterDirection.Input; param1.Value = txtEmail; var param2 = new SqlParameter(); param2.ParameterName = "@Password"; param2.SqlDbType = SqlDbType.VarChar; param2.Direction = ParameterDirection.Input; param2.Value = txtPass; cmd.Parameters.Add(param1); cmd.Parameters.Add(param2); cmd.ExecuteNonQuery(); //MessageBox.Show("Successful Login"); Globals.email = txtEmail; this.Hide(); var login = new SetAccountForm(); login.FormClosed += (s, args) => this.Close(); login.Show(); } } catch (SqlException) { MessageBox.Show("Invalid Email or Password"); } } catch (Exception ee) { MessageBox.Show(ee.ToString()); ClearTextBoxes(); } } }