コード例 #1
0
        private void PopulateTimeSlotList()
        {
            //Create an allAttraction list that is opoulated from the database
            List <TimeSlot> allTimeSlots = TimeSlotDb.GetAllTimeSlots();

            //Clear the list before adding to avoid duplicates
            TimeSlotCbox.Items.Clear();

            //Add all the attractions in the attraction combo box
            foreach (TimeSlot t in allTimeSlots)
            {
                TimeSlotCbox.Items.Add(t);
            }
        }
コード例 #2
0
        private void EditTimeSlotBtn_Click(object sender, EventArgs e)
        {
            if (IsDataValid() == true)
            {
                //Grab the newly inputted values
                existingTimeSlot.StartTime      = Convert.ToDateTime(StartTimeTxt.Text);
                existingTimeSlot.EndTime        = Convert.ToDateTime(EndTimeTxt.Text);
                existingTimeSlot.TimeSlotLength = TimeSpan.Parse((Convert.ToDateTime(EndTimeTxt.Text) - Convert.ToDateTime(StartTimeTxt.Text)).ToString());

                try
                {
                    TimeSlotDb.Update(existingTimeSlot);
                    DialogResult = DialogResult.OK;
                }
                catch (ArgumentException)
                {
                    MessageBox.Show("Time slot no longer exists");
                }
            }
        }
コード例 #3
0
        private void DeleteTimeSlotBtn_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(TimeSlotCbox.Text))
            {
                MessageBox.Show("Please select a time slot to delete");
                return;
            }

            //Grab the selected attraction
            TimeSlot selectedTimeSlot = (TimeSlot)TimeSlotCbox.SelectedItem;

            string message = $"Are you sure you want to delete {selectedTimeSlot.StartTime.ToShortTimeString()} - " +
                             $"{selectedTimeSlot.EndTime.ToShortTimeString()}?";

            DialogResult result = MessageBox.Show(text: message,
                                                  caption: "Delete?",
                                                  buttons: MessageBoxButtons.YesNo,
                                                  icon: MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                try
                {
                    //Remove in database
                    TimeSlotDb.Delete(selectedTimeSlot);

                    //Remove it from the list
                    TimeSlotCbox.Items.Remove(selectedTimeSlot);

                    MessageBox.Show("Time slot deleted");

                    PopulateTimeSlotList();

                    TimeSlotCbox.Text = "";
                }
                catch (Exception)
                {
                    MessageBox.Show("No time slots deleted");
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Adds a single time slot to the database
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddTimeSlotBtn_Click(object sender, EventArgs e)
        {
            if (IsDataValid() == true)
            {
                //Create a time slot object
                TimeSlot time = new TimeSlot()
                {
                    StartTime      = Convert.ToDateTime(StartTimeTxt.Text),
                    EndTime        = Convert.ToDateTime(EndTimeTxt.Text),
                    TimeSlotLength = TimeSpan.Parse((Convert.ToDateTime(EndTimeTxt.Text) - Convert.ToDateTime(StartTimeTxt.Text)).ToString())
                };

                try
                {
                    TimeSlotDb.Add(time);
                    MessageBox.Show("Time slot successfully added");
                    DialogResult = DialogResult.OK;
                }
                catch
                {
                    MessageBox.Show("We're currently having server issues");
                }
            }
        }