private void btnEditCustomer_Click(object sender, EventArgs e) { //update the customer record try { using (HairSalonDBContext context = new HairSalonDBContext()) { int id = Convert.ToInt32(txtCustomerID.Text); Customer cust = context.Customers.Where(r => r.CustID == id).FirstOrDefault(); cust.CustFirstName = txtCustFirstName.Text; cust.CustLastName = txtCustLastName.Text; cust.CustPhone = txtCustPhone.Text; cust.CustEmail = txtCustEmail.Text; context.SaveChanges(); MessageBox.Show("Record is modified successfully."); //Clear texboxes values txtSearchBox.Clear(); txtCustFirstName.Clear(); txtCustLastName.Clear(); txtCustPhone.Clear(); txtCustEmail.Clear(); } } catch (Exception ex) { MessageBox.Show("The system could not connect to database. Please check the database connection settings." + ex.Message); } }
private void btnEditCustomer_Click_1(object sender, EventArgs e) { try { using (HairSalonDBContext context = new HairSalonDBContext()) { Customer cust = new Customer(); cust.CustFirstName = txtCustFirstName.Text; cust.CustLastName = txtCustLastName.Text; cust.CustPhone = txtCustPhone.Text; cust.CustEmail = txtCustEmail.Text; context.SaveChanges(); MessageBox.Show("Record is Added successfully."); //Clear texboxes values txtCustFirstName.Clear(); txtCustLastName.Clear(); txtCustPhone.Clear(); txtCustEmail.Clear(); } } catch (Exception ex) { MessageBox.Show("The system could not connect to database. Please check the database connection settings." + ex.Message); } }
private void btnEditCustomer_Click(object sender, EventArgs e) { //update the employee record using (HairSalonDBContext context = new HairSalonDBContext()) { string id = comboEmpID.SelectedItem.ToString(); Employee emp = context.Employees.Where(r => r.EmpID == id).FirstOrDefault(); emp.EmpFirstName = txtEmpFirstName.Text; emp.EmpLastName = txtEmpLastName.Text; emp.Phone = txtPhone.Text; emp.Email = txtEmpEmail.Text; emp.Pass = txtPass.Text; emp.Position = txtPosition.Text; emp.DaysAvailable = txtAvailability.Text; emp.Salary = Convert.ToDecimal(txtSalary.Text); context.SaveChanges(); MessageBox.Show("Record is modified successfully."); //Clear texboxes values txtEmpFirstName.Clear(); txtEmpLastName.Clear(); txtPhone.Clear(); txtEmpEmail.Clear(); txtPass.Clear(); txtPosition.Clear(); txtAvailability.Clear(); txtSalary.Clear(); } }
private void btnSched_Click(object sender, EventArgs e) { try { //insert record into database using (HairSalonDBContext context = new HairSalonDBContext()) { //Add appoinment Appointment appt = new Appointment() { EmpID = txtEmpID.Text, CustID = Convert.ToInt32(txtCustID.Text), AptDate = (dtpDate.Value), AptTime = (dateTimePicker2).Value.TimeOfDay // AptTime = TimeSpan.Parse(txtTime.Text) }; context.Appointments.Add(appt); context.SaveChanges(); MessageBox.Show("The Appointment Is Added"); //mainMenu main = new mainMenu(); //this.Hide(); //main.Show(); } } catch (Exception ex) { MessageBox.Show("The Appointment was not added! Please check database connection settings." + ex.Message); } }
private void btnAddCustomer_Click(object sender, EventArgs e) { try { //Input Validation if (txtCustFirstName.Text == "" || txtCustLastName.Text == "") { MessageBox.Show("First name and last name are required."); } else if (!Regex.IsMatch(txtCustFirstName.Text, @"^([a-zA-Z]+$)") || !Regex.IsMatch(txtCustLastName.Text, @"^([a-zA-Z]+$)")) { MessageBox.Show("First and last names must only contain letters."); } else if (!IsEmailValid(txtCustEmail.Text)) { MessageBox.Show("Please enter a valid email address."); } else if (txtCustPhone.Text == "" && !Regex.IsMatch(txtCustPhone.Text, @"^([1-9]{1}[0-9]{9}$)")) { MessageBox.Show("Phone number cand only contain numbers and 10 digits long."); } else { // add new record using (HairSalonDBContext context = new HairSalonDBContext()) { //Add Client Customer cust = new Customer() { CustFirstName = txtCustFirstName.Text, CustLastName = txtCustLastName.Text, CustPhone = txtCustPhone.Text, CustEmail = txtCustEmail.Text }; context.Customers.Add(cust); context.SaveChanges(); MessageBox.Show("Client is added successfully."); //Clear texboxes values txtCustFirstName.Clear(); txtCustLastName.Clear(); txtCustPhone.Clear(); txtCustEmail.Clear(); } } } catch (Exception ex) { MessageBox.Show("The system could not connect to database. Please check the database connection settings." + ex.Message); } }
private void btnAddCustomer_Click(object sender, EventArgs e) { try { // add new record using (HairSalonDBContext context = new HairSalonDBContext()) { //Input Validation if (txtEmpFirstName.Text == "" || txtEmpLastName.Text == "") { MessageBox.Show("First name and last name are required."); } else if (!Regex.IsMatch(txtEmpFirstName.Text, @"^([a-zA-Z]+$)") || !Regex.IsMatch(txtEmpLastName.Text, @"^([a-zA-Z]+$)")) { MessageBox.Show("First and last names must only contain letters."); } else if (!IsEmailValid(txtEmpEmail.Text)) { MessageBox.Show("Please enter a valid email address."); } else if (txtPhone.Text == "" && !Regex.IsMatch(txtPhone.Text, @"^([1-9]{1}[0-9]{9}$)")) { MessageBox.Show("Phone number cand only contain numbers and 10 digits long."); } else { //Add Emploee Employee emp = new Employee() { EmpID = txtNewEmpID.Text, EmpFirstName = txtEmpFirstName.Text, EmpLastName = txtEmpLastName.Text, Phone = txtPhone.Text, Email = txtEmpEmail.Text, Pass = txtPass.Text, Position = txtPosition.Text, DaysAvailable = txtAvailability.Text, Salary = Convert.ToInt32(txtSalary.Text) }; context.Employees.Add(emp); context.SaveChanges(); MessageBox.Show("Employee is added successfully."); //Clear texboxes values txtNewEmpID.Clear(); txtEmpFirstName.Clear(); txtEmpLastName.Clear(); txtPhone.Clear(); txtEmpEmail.Clear(); txtPass.Clear(); txtPosition.Clear(); txtAvailability.Clear(); txtSalary.Clear(); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }