private void signUpButton_Click_1(object sender, EventArgs e) { var textboxs = new Object[] { firstNameTextBox, lastNameTextBox, emailTextBox, departmentComboBox, passwordTextBox, retypePasswordTextBox, empCodeTextBox, addressTextBox }; if (!isFilled(textboxs)) { MessageBox.Show("Please fill out the form", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { if (!agreeCheckBox.Checked) { MessageBox.Show("You must agree with conditions and terms", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } var appPath = Application.StartupPath; Console.WriteLine(appPath); var constring = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=" + appPath + "\\CriminalRecord.mdf;Integrated Security=True;Connect Timeout=30"; var con = new SqlConnection(constring); if (con.State != ConnectionState.Open) { con.Open(); } var sql = "INSERT INTO UserInformations (First_name, Last_name, Address, Phone, Officer_Department_ID, profile_image) " + "VALUES (@first_name, @last_name, @address, @phone, @officer, @profile_image)" + " SELECT @user_id = SCOPE_IDENTITY(); " + "INSERT INTO LoginInformation(User_Login_ID, Email, Password) " + "VALUES (@user_id, @email , @password)"; var command = new SqlCommand(sql, con); if (checkEmail(emailTextBox.Text) == true) { MessageBox.Show("Email's already existed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { if (!passwordTextBox.Text.Equals(retypePasswordTextBox.Text)) { MessageBox.Show("Retype password not match", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { command.Parameters.Add("@first_name", SqlDbType.VarChar, 38).Value = firstNameTextBox.Text; command.Parameters.Add("@last_name", SqlDbType.VarChar, 38).Value = lastNameTextBox.Text; command.Parameters.Add("@address", SqlDbType.VarChar, 38).Value = addressTextBox.Text; command.Parameters.Add("@phone", SqlDbType.VarChar, 38).Value = string.Empty; command.Parameters.Add("@officer", SqlDbType.Int).Value = 1; command.Parameters.Add("@email", SqlDbType.VarChar, 38).Value = emailTextBox.Text; var ePass = SaltPassword.ComputeHash(passwordTextBox.Text, "SHA512", null); command.Parameters.Add("@user_id", SqlDbType.Int).Direction = ParameterDirection.Output; command.Parameters.Add("@password", SqlDbType.VarChar).Value = ePass; command.Parameters.Add("@profile_image", SqlDbType.VarChar).Value = image; command.ExecuteNonQuery(); Console.WriteLine("COMPLETE"); Close(); } } } }
private void btn_submit_Click(object sender, EventArgs e) { String appPath = Application.StartupPath; string constring = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=" + appPath + "\\CriminalRecord.mdf;Integrated Security=True;Connect Timeout=30"; Console.WriteLine(appPath + "Hello"); SqlConnection con = new SqlConnection(constring); if (con.State != ConnectionState.Open) { con.Open(); } string sql = "INSERT INTO LoginInformation (User_Login_ID, Email, Password) VALUES (@id, @email, @password)"; SqlCommand command = new SqlCommand(sql, con); command.Parameters.Add("@id", SqlDbType.Int).Value = id; command.Parameters.Add("@email", SqlDbType.VarChar, 38).Value = "*****@*****.**"; string ePass = SaltPassword.ComputeHash("JohnWick", "SHA512", null); Console.WriteLine(ePass); command.Parameters.Add("@password", SqlDbType.VarChar).Value = ePass; command.ExecuteNonQuery(); Console.WriteLine("COMPLETE"); }