private void nextDay_Btn_Click(object sender, EventArgs e) { bool firstMove = false; List <Booking> bookings = GData.bookings.Where(b => b.bookingDate.Date == dateTimePicker1.Value.Date).ToList(); foreach (Booking booking in bookings) { if (booking.timeRemaining < 0) { //booking.estimatedTime = - booking.timeRemaining; if (!firstMove) { DatabaseControl.moveBookingToNextDate(booking, -booking.timeRemaining); booking.estimatedTime += booking.timeRemaining; DatabaseControl.updateBooking(booking); } else { DatabaseControl.moveBookingToNextDate(booking, booking.estimatedTime); booking.estimatedTime = 0; DatabaseControl.updateBooking(booking); } firstMove = true; } } dateTimePicker1.Value = dateTimePicker1.Value.AddDays(1); }
private void save_Btn_Click(object sender, EventArgs e) { // Check if Job NO is not empty if (jobNO_Txt.Text == "") { MessageBox.Show("Job No can not be empty. Please input!"); jobNO_Txt.Focus(); return; } // Check if Job NO is not empty if (jobType_Cmb.Text == "") { MessageBox.Show("Job Type can not be empty. Please input!"); jobType_Cmb.Focus(); return; } // Check if a Customer filed is not empty if (customerName_Txt.Text == "") { MessageBox.Show("Customer field can not be empty. Please input!"); customerName_Txt.Focus(); return; } // Check if an Address filed is not empty. if (address1_Txt.Text == "") { MessageBox.Show("Address field can not be empty. Please input!"); address1_Txt.Focus(); return; } if (address2_Txt.Text == "") { MessageBox.Show("Address field can not be empty. Please input!"); address2_Txt.Focus(); return; } if (address3_Txt.Text == "") { MessageBox.Show("Address field can not be empty. Please input!"); address3_Txt.Focus(); return; } // Check if an Post Code filed is not empty. if (postCode_Txt.Text == "") { MessageBox.Show("Post Code can not be empty. Please input!"); postCode_Txt.Focus(); return; } // Check if an email filed is not empty. if (email_Txt.Text == "") { MessageBox.Show("Email field can not be empty. Please input!"); email_Txt.Focus(); return; } // Check if an Tel filed is not empty. if (tel_Txt.Text == "") { MessageBox.Show("Tel field can not be empty. Please input!"); tel_Txt.Focus(); return; } // Check if an Vehicle Model filed is not empty. if (vehicleModel_Txt.Text == "") { MessageBox.Show("Vehicle Model field can not be empty. Please input!"); vehicleModel_Txt.Focus(); return; } // Check if an Vehicle Reg.No filed is not empty. if (vehicleRegNo_Txt.Text == "") { MessageBox.Show("Vehicle Reg.NO field can not be empty. Please input!"); vehicleRegNo_Txt.Focus(); return; } // Check if an Booked By filed is not empty. if (bookedBy_Cmb.Text == "") { MessageBox.Show("Booked By field can not be empty. Please input!"); bookedBy_Cmb.Focus(); return; } // Check if an Job Description filed is not empty. if (jobDescription_Txt.Text == "") { MessageBox.Show("Work Title field can not be empty. Please input!"); jobDescription_Txt.Focus(); return; } // Compare Time in and Time Out if (timeIn_Dtp.Value.Hour * 60 + timeIn_Dtp.Value.Minute > timeOut_Dtp.Value.Hour * 60 + timeOut_Dtp.Value.Minute) { MessageBox.Show("Time in should be less than Time Out!"); timeIn_Dtp.Focus(); return; } int customerId = 0; Customer customer = new Customer { honor = honor_Cmb.Text, name = customerName_Txt.Text, address1 = address1_Txt.Text, address2 = address2_Txt.Text, address3 = address3_Txt.Text, postCode = postCode_Txt.Text, email = email_Txt.Text, tel = tel_Txt.Text }; if (existingCustomer_Cmb.SelectedIndex == 0) { customerId = DatabaseControl.addCustomer(customer); } else { customerId = GData.customers[existingCustomer_Cmb.SelectedIndex - 1].id; DatabaseControl.updateCustomer(customer, customerId); } bookingToEdit.jobNO = jobNO_Txt.Text; bookingToEdit.jobType = jobType_Cmb.Text; bookingToEdit.customerID = customerId; bookingToEdit.servicePlan = servicePlan_Cmb.Text; bookingToEdit.vehicleMake = vehicleMake_Txt.Text; bookingToEdit.vehicleModel = vehicleModel_Txt.Text; bookingToEdit.regNo = vehicleRegNo_Txt.Text; bookingToEdit.mileage = Convert.ToDouble(mileage_Txt.Text); bookingToEdit.loanCar = loanCar_Cmb.Text; bookingToEdit.timeIn = timeIn_Dtp.Value; bookingToEdit.timeOut = timeOut_Dtp.Value; bookingToEdit.bookedBy = bookedBy_Cmb.Text; bookingToEdit.estimatedTime = Convert.ToDouble(estimatedTime_Txt.Text); //bookingToEdit.timeRemaining = DatabaseControl.getBookingDates(bookingToEdit.bookingDate.Date) - bookingToEdit.estimatedTime; //if (bookingToEdit.timeRemaining < 0) // bookingToEdit.timeRemaining = 0; bookingToEdit.insuranceRequired = insurance_Cmb.Text; bookingToEdit.jobDescription = jobDescription_Txt.Text; bookingToEdit.notes = notes_Txt.Text; if (DatabaseControl.updateBooking(bookingToEdit)) { MessageBox.Show("Booking data has been updated succesfully!"); UIControl.bookingGridForm.showBookings(); UIControl.showForm(UIControl.bookingGridForm); updateCustomers(); UIControl.newBookingForm.updateCustomers(); } }