Esempio n. 1
0
        private void UpdateButton_Click_1(object sender, EventArgs e)
        {
            string   timestamp     = SqlUpdater.CreateTimestamp();
            int      userId        = SqlUpdater.GetCurrentUserID();
            string   username      = SqlUpdater.GetCurrentUserName();
            int      appointmentId = Convert.ToInt32(SearchBar.Text);
            int      customerId    = Convert.ToInt32(CustomerIdBox.Text);
            string   type          = TypeBox.Text;
            DateTime startTime     = DateTime.Parse(StartTimeBox.Text).ToUniversalTime();
            DateTime endTime       = DateTime.Parse(EndTimeBox.Text).ToUniversalTime();
            String   st            = DateTime.Parse(StartTimeBox.Text).ToUniversalTime().ToString("u");
            String   et            = DateTime.Parse(EndTimeBox.Text).ToUniversalTime().ToString("u");

            bool pass = Validator();

            if (pass)
            {
                try
                {
                    if (AppHasConflict(startTime, endTime))
                    {
                        throw new AppointmentException();
                    }
                    else
                    {
                        try
                        {
                            if (OutsideBusinessHours(startTime, endTime))
                            {
                                throw new AppointmentException();
                            }
                            else
                            {
                                SqlUpdater.UpdateAppt(customerId, userId, st, et, type, timestamp, username, appointmentId);

                                mainFormObject.UpdateCalendar();
                                MessageBox.Show("Update Sucessfull.");
                                Close();
                            }
                        }
                        catch (AppointmentException ex) { ex.BusinessHours(); }
                    }
                }
                catch (AppointmentException ex) { ex.AppOverlap(); }
            }

            else
            {
                MessageBox.Show("Add Appointment Error.");
            }
        }