private void SaveButton_Click(object sender, EventArgs e)
        {
            Dictionary <string, string> form = new Dictionary <string, string>();

            string timeStamp = Data.createTimestamp();
            int    userId    = Data.getUserId();
            string username  = Data.getUserName();

            DateTime startTime = StartPicker.Value.ToUniversalTime();
            DateTime endTime   = EndPicker.Value.ToUniversalTime();

            try
            {
                if (ConflictingAppointment(startTime, endTime))
                {
                    throw new appointmentException();
                }
                else
                {
                    try
                    {
                        if (outsideOfBusinessHours(startTime, endTime))
                        {
                            throw new appointmentException();
                        }
                        else
                        {
                            form.Add("type", TypeBox.Text);
                            form.Add("customerId", CustomerIdBox.Text);
                            form.Add("start", StartPicker.Value.ToUniversalTime().ToString("u"));
                            form.Add("end", EndPicker.Value.ToUniversalTime().ToString("u"));

                            if (editAppointment(form))
                            {
                                mainScreen.calendarUpdate();
                                MessageBox.Show("Update Successful");
                            }
                        }
                    }
                    catch (appointmentException ex)
                    {
                        ex.outsideOfBusinessHours();
                    }
                }
            }
            catch (appointmentException ex)
            {
                ex.appointmentOverlap();
            }
            mainScreen.calendarUpdate();
            this.Close();
        }
Exemple #2
0
        private void DeleteButton_Click(object sender, EventArgs e)
        {
            //Confirm Delete
            DialogResult confirmRemove = MessageBox.Show("Removing appointment cannot be undone. Confirm?", "Confirm", MessageBoxButtons.YesNo);

            if (confirmRemove == DialogResult.Yes)
            {
                if (removeAppointment())
                {
                    mainScreen.calendarUpdate();
                    MessageBox.Show("Customer appointment successfully removed.");
                }
                else
                {
                    MessageBox.Show("Could not remove appointment, please try again.");
                }
            }
            this.Close();
        }
        private void AddAppointmentButton_Click(object sender, EventArgs e)
        {
            string timeStamp = Data.createTimestamp();
            int    userId    = Data.getUserId();
            string username  = Data.getUserName();

            DateTime startTime = StartPicker.Value.ToUniversalTime();
            DateTime endTime   = EndPicker.Value.ToUniversalTime();

            try
            {
                if (ConflictingAppointment(startTime, endTime))
                {
                    throw new appointmentException();
                }
                else
                {
                    try
                    {
                        if (outsideOfBusinessHours(startTime, endTime))
                        {
                            throw new appointmentException();
                        }
                        else
                        {
                            Data.createRecord(timeStamp, username, "appointment", $"'{CustomerIdBox.Text}', '{StartPicker.Value.ToUniversalTime().ToString("u")}'," +
                                              $"'{EndPicker.Value.ToUniversalTime().ToString("u")}', '{TypeBox.Text}'", userId);
                        }
                    }
                    catch (appointmentException ex)
                    {
                        ex.outsideOfBusinessHours();
                    }
                }
            }
            catch (appointmentException ex)
            {
                ex.appointmentOverlap();
            }
            mainScreen.calendarUpdate();
            this.Close();
        }