// bring user to alterbookingform private void ViewBookingButton_Click(object sender, EventArgs e) { AlterBookingForm alterbookingForm = new AlterBookingForm(); alterbookingForm.Show(); this.Close(); }
private void CreateAccountButton_Click(object sender, EventArgs e) { //opening connection to database if not already open if (conn.State == ConnectionState.Closed) { conn.Open(); } //store textboxes text to global variables nameText = CreateFirstNameTextBox.Text + " " + CreateLastNameTextBox.Text; companyNameText = CreateCompanyTextBox.Text; emailText = CreateEmailTextBox.Text; userName = CreateUserNameTextBox.Text; if (CreatePasswordTextBox.Text == ConfirmPasswordTextBox.Text) { password = CreatePasswordTextBox.Text; if (CreateFirstNameTextBox.Text != "" && CreateLastNameTextBox.Text != "" && CreateEmailTextBox.Text != "" && CreateUserNameTextBox.Text != "" && password != "") { try { string query = "INSERT INTO UserTable (Name, CompanyName, Email, UserName, Password) VALUES ('" + CreateFirstNameTextBox.Text + " " + CreateLastNameTextBox.Text + "', '" + CreateCompanyTextBox.Text + "', '" + CreateEmailTextBox.Text + "', '" + userName + "', '" + password + "')"; SqlCommand command = new SqlCommand(query, conn); command.ExecuteNonQuery(); //Jump to AlterBookingForm AlterBookingForm alterBookingForm = new AlterBookingForm(); alterBookingForm.Show(); this.Hide(); } catch (SqlException) { MessageTextBox.Text = "User name invlad or used already"; } } } else { MessageTextBox.Text = "Password does not match password confirm please try again"; } conn.Close(); }
// grabs all of users information and displays it on the alter booking form private void LoginButton_Click(object sender, EventArgs e) { //opening connection to database if not already open if (conn.State == ConnectionState.Closed) { conn.Open(); } // variables for comaring user to database string compareUserName = ""; string comparePassword = ""; // grabing user information and storing it a DataTable string getUserName = "******" + UserNameTextBox.Text + "'"; SqlCommand command1 = new SqlCommand(getUserName, conn); SqlDataAdapter adapter1 = new SqlDataAdapter(command1); DataTable dataTable1 = new DataTable(); dataTable1.Columns.Add("UserName", typeof(string)); dataTable1.Columns.Add("Password", typeof(string)); dataTable1.Columns.Add("Name", typeof(string)); dataTable1.Columns.Add("Email", typeof(string)); dataTable1.Columns.Add("CompanyName", typeof(string)); adapter1.Fill(dataTable1); //storing user information in variables try { compareUserName = Convert.ToString(dataTable1.Rows[0][0]); comparePassword = Convert.ToString(dataTable1.Rows[0][1]); } catch (IndexOutOfRangeException) { MessageTextBox.Text = "User name or password do not match records please try again"; } // checking if login information matches data table if (UserNameTextBox.Text == compareUserName && PasswordTextBox.Text == comparePassword) { // storing user information in global variables userName = Convert.ToString(dataTable1.Rows[0][0]); password = Convert.ToString(dataTable1.Rows[0][1]); nameText = Convert.ToString(dataTable1.Rows[0][2]); emailText = Convert.ToString(dataTable1.Rows[0][3]); companyNameText = Convert.ToString(dataTable1.Rows[0][4]); //Jump to AlterBookingForm AlterBookingForm alterBookingForm = new AlterBookingForm(); alterBookingForm.Show(); // hiding form incase user wants to logout this.Hide(); conn.Close(); } // if information does match records in database else { MessageTextBox.Text = "User name or password do not match records please try again"; } }