Example #1
0
        //Generate calendar
        private void ButtonGenerate_Click(object sender, RoutedEventArgs e)
        {
            int year  = DateTime.Now.Year;
            int month = DateTime.Now.Month;

            try
            {
                IEnumerable <ClassCalendar> query =
                    from elem in sql.CalendarList()
                    where elem.Year == year && elem.Month == month
                    select elem;
                if (query.Any())
                {
                    throw new Exception("Calendar already created");
                }

                ClassGenerateCalendar.GenerateCalendar(DateTime.Now.Year, DateTime.Now.Month + 1, sql);
                MessageBox.Show("Succesfully generated calendar");

                ComboBoxPickDate.ItemsSource = sql.CalendarList();
                if (ComboBoxPickDate.Items.Count == 0)
                {
                    return;
                }
                ComboBoxPickDate.SelectedIndex = ComboBoxPickDate.Items.Count - 1;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error");
            }
        }
Example #2
0
        public void TestGenerationOfCalendar()
        {
            SqlCalendar sql      = new SqlCalendar();
            List <int>  expected = ClassGenerateCalendar.WorkingDaysInMonth(2000, 1);

            ClassGenerateCalendar.GenerateCalendar(2000, 1, sql);

            List <ClassCalendar>        list  = sql.CalendarList();
            IEnumerable <ClassCalendar> query =
                from elem in list
                where elem.Year == 2000 && elem.Month == 1
                select elem;

            Assert.Single(query);
            int calendarId = (query.First()).CalendarId;
            List <ClassCalendarDay> actual = sql.ListOfCalendarDays(calendarId);

            for (int i = 0; i < expected.Count; i++)
            {
                Assert.Equal(expected[i], actual[i].Day);
            }
        }