コード例 #1
0
        // Save Button click
        private void appointmentSaveButton_Click(object sender, EventArgs e)
        {
            // If inputs are valid, continue
            if (inputValidation())
            {
                // If appointment is within business hours or user clicked 'Yes', continue
                if (checkBusinessHours(appointmentStartDate.Value, appointmentEndDate.Value))
                {
                    // Store data within form
                    appointmentID = DataInterface.getNextID("appointmentId", "appointment", DataInterface.getAppointmentIDList());
                    customerID    = selectedCustomerID;
                    title         = appointmentTitleTextBox.Text;
                    description   = appointmentDescriptionTextBox.Text;
                    location      = appointmentLocationTextBox.Text;
                    contact       = appointmentContactTextBox.Text;
                    url           = appointmentURLTextBox.Text;
                    start         = appointmentStartDate.Value.ToUniversalTime().ToString("u");
                    end           = appointmentEndDate.Value.ToUniversalTime().ToString("u");

                    // Check if appointment being created overlaps an existing appointment
                    if (checkForOverlap(DateTime.Parse(start), DateTime.Parse(end)) == true)
                    {
                        // If there is overlap, prompt user and cancel save
                        MessageBox.Show("The appointment you are trying to add overlaps an existing appointment." +
                                        "\n\nPlease correct and try again.");
                        return;
                    }
                    // If no overlap, continue with save
                    else
                    {
                        // Use DataInterface method to pass data to query for creating new appointment
                        DataInterface.createAppointment(customerID, title, description, location, contact, url, start, end, currentUser);
                        // Set MainForms form to this form, show mainForm again, close this form
                        MainForm.addAppointmentForm = this;
                        mainForm.Show();
                        MainForm.addAppointmentForm.Close();
                    }
                }
            }
            // If inputs are not valid or user chose to not allow it outside business hours, cancel save
            return;
        }