示例#1
0
        private void saveButton_Click(object sender, RoutedEventArgs e)
        {
            bool ret = checkDateValidity();

            if (ret && (hours != 0) && (timeSlot != 0))
            {
                var uriSource = new Uri("/Resources/Save_tick.png", UriKind.Relative);
                tickImage.Source = new BitmapImage(uriSource);

                //Adding the daysAndHours object to the DB
                try
                {
                    if (daysAndHours != null)
                    {
                        daysAndHours.NoOfDays = noOfDays;
                        daysAndHours.Hours    = hours;
                        daysAndHours.Mins     = mins;
                        daysAndHours.TimeSlot = timeSlot;

                        timetableManagerDbContext.DaysAndHours.Update(daysAndHours);
                    }
                    else
                    {
                        daysAndHours          = new DaysAndHours();
                        daysAndHours.NoOfDays = noOfDays;
                        daysAndHours.Hours    = hours;
                        daysAndHours.Mins     = mins;
                        daysAndHours.TimeSlot = timeSlot;

                        timetableManagerDbContext.DaysAndHours.Add(daysAndHours);
                    }

                    timetableManagerDbContext.SaveChanges();

                    //popup to set the interval time
                    openTimetablePopup();

                    MessageBox.Show("Changes saved");
                }
                catch (Exception ex)
                {
                    //in case if the connection to the DB is lost
                    MessageBox.Show("Error! " + ex.Message);
                }
            }
            else
            {
                var uriSource = new Uri("/Resources/Cancel_tick.png", UriKind.Relative);
                tickImage.Source = new BitmapImage(uriSource);
                MessageBox.Show("Not all values match. Please try again");
            }
        }
示例#2
0
        public Tab_Main_Days()
        {
            InitializeComponent();

            stackPanelBorderCreated = false;

            //retrieving the DaysAndHours data from the DB if exists
            try
            {
                //setting the selected Days list to an ObservableCollection so it could be bound to the view
                theDaysList      = new ObservableCollection <Day>(timetableManagerDbContext.Days);
                selectedDaysList = new ObservableCollection <string>();

                //the DataService for Days table
                DayDataService dayDataService = new DayDataService(new EntityFramework.TimetableManagerDbContext());

                //setting the rest of the saved data
                daysAndHours = timetableManagerDbContext.DaysAndHours.FirstOrDefault <DaysAndHours>();

                if (daysAndHours != null)
                {
                    noOfDays = daysAndHours.NoOfDays;
                    hours    = daysAndHours.Hours;
                    mins     = daysAndHours.Mins;
                    timeSlot = daysAndHours.TimeSlot;

                    //setting data to the view
                    comboBoxNoOfDays.SelectedIndex = noOfDays;
                    comboBoxHours.SelectedIndex    = hours;

                    if (mins.Equals(30))
                    {
                        comboBoxMinutes.Text = "30";
                    }
                    else if (mins.Equals(60))
                    {
                        comboBoxMinutes.Text = "00";
                    }

                    if (timeSlot.Equals(30))
                    {
                        comboBoxDuration.Text = "30 mins";
                    }
                    else if (timeSlot.Equals(60))
                    {
                        comboBoxDuration.Text = "1 hour";
                    }
                }
                if (theDaysList != null)
                {
                    foreach (Day day in theDaysList)
                    {
                        if (day.IsSelected == true)
                        {
                            createStackPanelBorder();
                            createStackPanel(day.DayName, day.IsSelected, day.startHour, day.startMin, day.endHour, day.endMin);
                        }
                    }
                }
                this.DataContext = this;
            }
            catch (Exception e)
            {
                //in case if the connection to the DB is lost
                MessageBox.Show("first error " + e.Message);
            }
        }