public MainWindow(int passedMonth, int passedYear, User passedUser)
        {
            calendar = Utils.ReadEventsSerialFile();
            InitializeComponent();
            year  = passedYear;
            month = passedMonth;
            if (passedUser == null)
            {
                passedUser = new User(defaultUserName);
            }
            user = passedUser;
            buttonLastMonth.Click  += new RoutedEventHandler(LastMonthBtn_Click);
            buttonNextMonth.Click  += new RoutedEventHandler(NextMonthBtn_Click);
            buttonWeeklyView.Click += new RoutedEventHandler(WeeklyViewBtn_Click);
            buttonNewEvent.Click   += new RoutedEventHandler(NewEventBtn_Click);

            textBlockUserName.Text = string.Format(CultureInfo.InvariantCulture, "Hola, {0}", user.Name);

            textBlocksDaysOfMonth = new TextBlock[] { this.TextBlockDay1, this.TextBlockDay2, this.TextBlockDay3, this.TextBlockDay4, this.TextBlockDay5, this.TextBlockDay6, this.TextBlockDay7,
                                                      this.TextBlockDay8, this.TextBlockDay9, this.TextBlockDay10, this.TextBlockDay11, this.TextBlockDay12, this.TextBlockDay13, this.TextBlockDay14,
                                                      this.TextBlockDay15, this.TextBlockDay16, this.TextBlockDay17, this.TextBlockDay18, this.TextBlockDay19, this.TextBlockDay20, this.TextBlockDay21,
                                                      this.TextBlockDay22, this.TextBlockDay23, this.TextBlockDay24, this.TextBlockDay25, this.TextBlockDay26, this.TextBlockDay27, this.TextBlockDay28,
                                                      this.TextBlockDay29, this.TextBlockDay30, this.TextBlockDay31, this.TextBlockDay32, this.TextBlockDay33, this.TextBlockDay34, this.TextBlockDay35,
                                                      this.TextBlockDay36, this.TextBlockDay37, this.TextBlockDay38, this.TextBlockDay39, this.TextBlockDay40, this.TextBlockDay41, this.TextBlockDay42 };

            listItemsControlEvents = new List <ItemsControl>();

            SetDaysOfMonth();
        }
        private void SetDaysOfMonth()
        {
            if (month.Equals(null) || year.Equals(null))
            {
                month = DateTime.Now.Month;
                year  = DateTime.Now.Year;
            }

            ClearEvents();
            monthEvents = Utils.GetMonthEvents(calendar, month, year, user);

            textBlockMonth.Text = months[month - positionUnit];
            textBlockYear.Text  = year.ToString(CultureInfo.InvariantCulture);

            DateTime firstDayOfMonthDate = new DateTime(year, month, firstDayOfMonth);

            int firstWeekDay = Utils.SetFirstWeekDay((int)firstDayOfMonthDate.DayOfWeek);

            int lastDay = DateTime.DaysInMonth(year, month);
            int day     = firstDayOfMonth;

            for (int dayIndex = 0; dayIndex < textBlocksDaysOfMonth.Length; dayIndex++)
            {
                if (Utils.IsNotMonthDay(dayIndex, firstWeekDay, day, lastDay))
                {
                    textBlocksDaysOfMonth[dayIndex].Text = "";
                }
                else
                {
                    textBlocksDaysOfMonth[dayIndex].Text = day.ToString(CultureInfo.InvariantCulture);
                    SetDayEvents(day, dayIndex);
                    day++;
                }
            }
        }
Exemple #3
0
 public bool AreAvailable(DateTime date, string[] start, string[] end, AppointmentsList calendar)
 {
     if (calendar == null)
     {
         return(true);
     }
     foreach (Appointment appointment in calendar.Appointments)
     {
         if (Utils.DatesCollide(appointment, date, start, end))
         {
             foreach (User selectedUser in users)
             {
                 if (appointment.Owner.HasSameNameAs(selectedUser.Name))
                 {
                     return(false);
                 }
                 if (appointment.Participants != null)
                 {
                     foreach (User participant in appointment.Participants.Users)
                     {
                         if (participant.HasSameNameAs(selectedUser.Name))
                         {
                             return(false);
                         }
                     }
                 }
             }
         }
     }
     return(true);
 }
Exemple #4
0
        private void SetNextWeek_Click(Object sender, EventArgs e)
        {
            ClearEvents();
            int  lastDayOfMonth = DateTime.DaysInMonth(year, month);
            bool changeOfMonth  = false;

            for (int weekDay = 0; weekDay < weekLength; weekDay++)
            {
                bool monthEnded = day > lastDayOfMonth;
                if (monthEnded)
                {
                    day           = firstDayOfMonth;
                    changeOfMonth = true;
                    dayEvents     = Utils.GetDayEvents(calendar, day, month + oneMonth, year, user);
                }
                else
                {
                    dayEvents = Utils.GetDayEvents(calendar, day, month, year, user);
                }
                SetDayEvents(dayEvents, weekDay + positionUnit);
                daysOfWeekTextBlocks[weekDay].Text = String.Format(CultureInfo.InvariantCulture, "{0}{1}", daysOfWeek[weekDay], day);
                day++;
            }
            SetNextWeekMonthAndYear(changeOfMonth);
        }
        private void ButtonEvents_Click(object sender, RoutedEventArgs e)
        {
            MyEvents myEvents = new MyEvents(user);

            myEvents.ShowDialog();
            calendar = Utils.ReadEventsSerialFile();
            SetDaysOfMonth();
        }
        private void NewEventBtn_Click(Object sender, EventArgs e)
        {
            NewEvent newEvent = new NewEvent(user);

            newEvent.ShowDialog();
            calendar = Utils.ReadEventsSerialFile();
            SetDaysOfMonth();
        }
Exemple #7
0
        public static bool WriteEventsSerialFile(AppointmentsList calendar, string fileName)
        {
            IFormatter formatter = new BinaryFormatter();
            Stream     stream    = new FileStream(fileName, FileMode.Create, FileAccess.Write);

            formatter.Serialize(stream, calendar);
            stream.Close();
            return(true);
        }
Exemple #8
0
 public MyEvents(User passedUser)
 {
     InitializeComponent();
     ButtonDelete.IsEnabled = false;
     calendar = Utils.ReadEventsSerialFile();
     allUsers = Utils.ReadUsersSerialFile();
     user     = passedUser;
     FilterCalendar();
     AddEventsToListBox();
     listBoxAllUsers.ItemsSource = allUsers.Users;
 }
Exemple #9
0
        private void ButtonEvents_Click(object sender, RoutedEventArgs e)
        {
            MyEvents myEvents = new MyEvents(user);

            myEvents.ShowDialog();
            calendar = Utils.ReadEventsSerialFile();
            Week newWeekView = new Week(month, year, user);

            newWeekView.Show();
            this.Close();
        }
Exemple #10
0
        private void NewEventBtn_Click(Object sender, EventArgs e)
        {
            NewEvent newEvent = new NewEvent(user);

            newEvent.ShowDialog();
            calendar = Utils.ReadEventsSerialFile();
            Week newWeekView = new Week(month, year, user);

            newWeekView.Show();
            this.Close();
        }
        public NewEvent(User passedUser)
        {
            calendar = Utils.ReadEventsSerialFile();
            allUsers = Utils.ReadUsersSerialFile();
            user     = passedUser;

            InitializeComponent();
            SetListBoxItems();
            DatePickerEventDate.SelectedDate = DateTime.Today;

            ButtonCancel.Click += new RoutedEventHandler(CancelBtn_Click);
            ButtonSave.Click   += new RoutedEventHandler(SaveBtn_Click);
        }
Exemple #12
0
 private void SetLastWeek()
 {
     day = day - twoWeeks;
     for (int weekDay = 0; weekDay < weekLength; weekDay++)
     {
         daysOfWeekTextBlocks[weekDay].Text = daysOfWeek[weekDay] + day.ToString(CultureInfo.InvariantCulture);
         dayEvents = Utils.GetDayEvents(calendar, day, month, year, user);
         SetDayEvents(dayEvents, weekDay + positionUnit);
         day++;
     }
     TextBlockMonth.Text = months[month - positionUnit];
     TextBlockYear.Text  = year.ToString(CultureInfo.InvariantCulture);
 }
Exemple #13
0
 public static AppointmentsList ReadEventsSerialFile()
 {
     if (File.Exists(eventsFile))
     {
         IFormatter       formatter = new BinaryFormatter();
         Stream           stream    = new FileStream(eventsFile, FileMode.Open, FileAccess.Read);
         AppointmentsList events    = (AppointmentsList)formatter.Deserialize(stream);
         stream.Close();
         return(events);
     }
     else
     {
         return(new AppointmentsList());
     }
 }
Exemple #14
0
        private void SetDayEvents(AppointmentsList events, int weekDay)
        {
            for (int hour = 0; hour < 24; hour++)
            {
                ItemsControl itemsControlEvents = new ItemsControl();
                itemControlListEvents.Add(itemsControlEvents);
                GridHours.Children.Add(itemsControlEvents);
                Grid.SetColumn(itemsControlEvents, weekDay);
                Grid.SetRow(itemsControlEvents, hour + positionUnit);

                foreach (Appointment appointment in events.Appointments)
                {
                    TextBlock textBlockEvent = new TextBlock();
                    textBlockEvent.Text = appointment.WeekViewAppointmentText(hour);
                    itemsControlEvents.Items.Add(textBlockEvent);
                }
            }
        }
Exemple #15
0
        private void SetLastMonth()
        {
            month--;
            if (Utils.IsLastYear(month))
            {
                month = december;
                year--;
            }
            int lastDayOfMonth = DateTime.DaysInMonth(year, month);

            day = lastDayOfMonth + (day - twoWeeks);
            for (int weekDay = 0; weekDay < weekLength; weekDay++)
            {
                daysOfWeekTextBlocks[weekDay].Text = String.Format(CultureInfo.InvariantCulture, "{0}{1}", daysOfWeek[weekDay], day);
                dayEvents = Utils.GetDayEvents(calendar, day, month, year, user);
                SetDayEvents(dayEvents, weekDay + positionUnit);
                day++;
            }
            TextBlockMonth.Text = months[month - positionUnit];
            TextBlockYear.Text  = year.ToString(CultureInfo.InvariantCulture);
        }
Exemple #16
0
 private void SetCalendarDays(int firstWeekdayOfMonth, int lastDayOfLastMonth, int lastMonthYear, int lastMonth)
 {
     for (int weekDay = 0; weekDay < daysOfWeekTextBlocks.Length; weekDay++)
     {
         bool   isThisMonth = firstWeekdayOfMonth <= weekDay + positionUnit;
         string text;
         if (isThisMonth)
         {
             text      = String.Format(CultureInfo.InvariantCulture, "{0} {1}", daysOfWeek[weekDay], day);
             dayEvents = Utils.GetDayEvents(calendar, day, month, year, user);
             day++;
         }
         else
         {
             int lastMonthDay = lastDayOfLastMonth - (firstWeekdayOfMonth - oneDay) + weekDay + positionUnit;
             text      = String.Format(CultureInfo.InvariantCulture, "{0} {1}", daysOfWeek[weekDay], lastMonthDay);
             dayEvents = Utils.GetDayEvents(calendar, lastMonthDay, lastMonth, lastMonthYear, user);
         }
         daysOfWeekTextBlocks[weekDay].Text = text;
         SetDayEvents(dayEvents, weekDay + positionUnit);
     }
 }
Exemple #17
0
        public static AppointmentsList GetDayEvents(AppointmentsList calendar, int day, int month, int year, User user)
        {
            AppointmentsList dayEvents = new AppointmentsList();

            if (calendar == null)
            {
                return(dayEvents);
            }
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            foreach (Appointment appointment in calendar.Appointments)
            {
                if (appointment.IsThisDay(day, month, year) && user.ParticipatesInEvent(appointment))
                {
                    dayEvents.AddAppointment(appointment);
                }
            }
            return(dayEvents);
        }
Exemple #18
0
        public Week(int passedMonth, int passedYear, User passedUser)
        {
            month = passedMonth;
            year  = passedYear;
            if (passedUser == null)
            {
                passedUser = new User(defaultUserName);
            }
            user = passedUser;

            calendar = Utils.ReadEventsSerialFile();

            InitializeComponent();

            daysOfWeekTextBlocks     = new TextBlock[] { TextBlockMonday, TextBlockTuesday, TextBlockWednesday, TextBlockThursday, TextBlockFriday, TextBlockSaturday, TextBlockSunday };
            ButtonMonthlyView.Click += new RoutedEventHandler(MonthlyViewBtn_Click);
            ButtonNextWeek.Click    += new RoutedEventHandler(SetNextWeek_Click);
            ButtonLastWeek.Click    += new RoutedEventHandler(SetLastWeek_Click);
            ButtonNewEvent.Click    += new RoutedEventHandler(NewEventBtn_Click);
            textBlockUserName.Text   = string.Format(CultureInfo.InvariantCulture, "Hola, {0}", user.Name);

            itemControlListEvents = new List <ItemsControl>();
            SetFirstWeek();
        }