예제 #1
0
        public AddEventViewModel(User user, MonthControlViewModel MonthVM = null)
        {
            RepeatList = new List <RepeatMode>();
            RepeatList.Add(RepeatMode.DoNotRepeat);
            RepeatList.Add(RepeatMode.RepeatDaily);
            RepeatList.Add(RepeatMode.RepeatMonthly);
            RepeatList.Add(RepeatMode.RepeatTwiceAWeek);
            RepeatList.Add(RepeatMode.RepeatWeekly);

            NotificationList = new List <NotificationMode>();
            NotificationList.Add(NotificationMode.DoNotNotify);
            NotificationList.Add(NotificationMode.NotifyDayBefore);
            NotificationList.Add(NotificationMode.NotifyHourBefore);
            NotificationList.Add(NotificationMode.NotifyThreeDaysBefore);
            NotificationList.Add(NotificationMode.NotifyThreeHoursBefore);

            AddCommand = new RelayCommand(o =>
            {
                try
                {
                    var uow      = UnitOfWorkSingleton.Instance;
                    var newevent = new Model.PrimaryModels.Event(Name,
                                                                 ChangeTime((DateTime)Start,
                                                                            (DateTime)StartTime),
                                                                 ChangeTime((DateTime)End,
                                                                            (DateTime)EndTime),
                                                                 Note,
                                                                 Status.InProcess,
                                                                 user,
                                                                 Contact,
                                                                 Repeat,
                                                                 Notification);
                    newevent.ContactId = Contact?.Id;
                    newevent.Contact   = null;
                    uow.Events.Create(newevent);
                    uow.SaveChanges();
                    MonthVM.LoadTasksAndEvents();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message + ex);
                }
            });
            AddContactCommand = new RelayCommand(o =>
            {
                try
                {
                    ContactListWindow taskWin = new ContactListWindow()
                    {
                        DataContext = new ContactListViewModel(user, this, null)
                    };
                    taskWin.ShowDialog();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            });
        }
예제 #2
0
        public ChangeTaskViewModel(Model.PrimaryModels.Task task, MonthControlViewModel monthControlViewModel)
        {
            Name    = task.Name;
            EndTime = task.EndTime;
            Note    = task.Notes;
            if (task.Status == Status.Finished)
            {
                CheckStatus = true;
            }
            else
            {
                CheckStatus = false;
            }

            SaveCommand = new RelayCommand(o =>
            {
                try
                {
                    var uow       = UnitOfWorkSingleton.Instance;
                    _task         = uow.Tasks.GetElement(task.Id);
                    _task.Name    = Name;
                    _task.EndTime = EndTime;
                    _task.Notes   = Note;
                    if (CheckStatus)
                    {
                        _task.Status = Model.PrimaryModels.Status.Finished;
                    }
                    uow.SaveChanges();
                    monthControlViewModel.LoadTasksAndEvents();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            });
            DelCommand = new RelayCommand(o =>
            {
                try
                {
                    var uow = UnitOfWorkSingleton.Instance;
                    uow.Tasks.Delete(task.Id);
                    uow.SaveChanges();
                    monthControlViewModel.LoadTasksAndEvents();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            });
        }
예제 #3
0
 public AddTaskViewModel(User user, MonthControlViewModel monthControlViewModel = null)
 {
     AddCommand = new RelayCommand(o =>
     {
         try
         {
             var uow = UnitOfWorkSingleton.Instance;
             uow.Tasks.Create(new Model.PrimaryModels.Task(Name, EndTime, Note, Status.Started, user));
             uow.SaveChanges();
             monthControlViewModel.LoadTasksAndEvents();
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     });
 }
예제 #4
0
        public MainViewModel(MonthControlViewModel MonthVM)
        {
            MonthVM     = new MonthControlViewModel();
            YearVM      = new YearControlViewModel();
            SettVM      = new SettingsControlViewModel();
            CurrentView = MonthVM;

            MonthViewCommand = new RelayCommand(o =>
            {
                CurrentView = MonthVM;
            });
            YearViewCommand = new RelayCommand(o =>
            {
                CurrentView = YearVM;
            });
            AddTaskCommand = new RelayCommand(o =>
            {
                new AddTaskWindow().ShowDialog();
            });
            AddEventCommand = new RelayCommand(o =>
            {
                new AddEventWindow().ShowDialog();
            });
            AddContactCommand = new RelayCommand(o =>
            {
                new AddContactWindow().ShowDialog();
            });
            RegistrationCommand = new RelayCommand(o =>
            {
                new RegistrationWindow().ShowDialog();
            });
            SettingsCommand = new RelayCommand(o =>
            {
                CurrentView = SettVM;
            });
        }
예제 #5
0
        public MainViewModel(MonthControlViewModel MonthVM, User authorisedUser)
        {
            MonthVM        = new MonthControlViewModel(authorisedUser);
            YearVM         = new YearControlViewModel();
            CurrentView    = MonthVM;
            AuthorisedUser = authorisedUser;

            UserName = AuthorisedUser.Name;
            Img      = AuthorisedUser.Img;

            MonthViewCommand = new RelayCommand(o =>
            {
                CurrentView = MonthVM;
            });
            YearViewCommand = new RelayCommand(o =>
            {
                CurrentView = YearVM;
            });
            AddTaskCommand = new RelayCommand(o =>
            {
                AddTaskWindow taskWin = new AddTaskWindow()
                {
                    DataContext = new AddTaskViewModel(_authorisedauser, MonthVM)
                };
                taskWin.ShowDialog();
            });
            AddEventCommand = new RelayCommand(o =>
            {
                AddEventWindow taskWin = new AddEventWindow()
                {
                    DataContext = new AddEventViewModel(_authorisedauser, MonthVM)
                };
                taskWin.ShowDialog();
            });
            AddContactCommand = new RelayCommand(o =>
            {
                AddContactWindow taskWin = new AddContactWindow()
                {
                    DataContext = new AddContactViewModel(_authorisedauser)
                };
                taskWin.ShowDialog();
            });
            RegistrationCommand = new RelayCommand(o =>
            {
                UserWindow taskWin = new UserWindow()
                {
                    DataContext = new UserViewModel(AuthorisedUser, this)
                };
                taskWin.ShowDialog();
            });

            Registry registry = new Registry();

            registry.Schedule(() =>
            {
                foreach (Event _event in UnitOfWorkSingleton.Instance.Events.List)
                {
                    TimeSpan?diffresult = _event.StartTime - DateTime.Now;
                    if (diffresult <= TimeSpan.FromMinutes(60))
                    {
                        MessageBox.Show("Час до начала события: " + _event.Name);
                    }
                }
            }).ToRunNow().AndEvery(20).Minutes();
            JobManager.Initialize(registry);
        }
예제 #6
0
        public ChangeEventViewModel(Diary.MVVM.Model.PrimaryModels.Event _SelectedEvent, MonthControlViewModel MonthVM, User user)
        {
            RepeatList = new List <RepeatMode>();
            RepeatList.Add(RepeatMode.DoNotRepeat);
            RepeatList.Add(RepeatMode.RepeatDaily);
            RepeatList.Add(RepeatMode.RepeatMonthly);
            RepeatList.Add(RepeatMode.RepeatTwiceAWeek);
            RepeatList.Add(RepeatMode.RepeatWeekly);

            NotificationList = new List <NotificationMode>();
            NotificationList.Add(NotificationMode.DoNotNotify);
            NotificationList.Add(NotificationMode.NotifyDayBefore);
            NotificationList.Add(NotificationMode.NotifyHourBefore);
            NotificationList.Add(NotificationMode.NotifyThreeDaysBefore);
            NotificationList.Add(NotificationMode.NotifyThreeHoursBefore);

            var uow = UnitOfWorkSingleton.Instance;

            Note         = _SelectedEvent.Notes;
            Name         = _SelectedEvent.Name;
            Start        = _SelectedEvent.StartTime;
            StartTime    = _SelectedEvent.StartTime;
            End          = _SelectedEvent.EndTime;
            EndTime      = _SelectedEvent.EndTime;
            Status       = _SelectedEvent.Status;
            Repeat       = _SelectedEvent.RepeatMode;
            Notification = _SelectedEvent.NotificationMode;
            Contact      = uow.Contacts.GetElement(_SelectedEvent.ContactId);

            _event = uow.Events.GetElement(_SelectedEvent.Id);

            SaveCommand = new RelayCommand(o =>
            {
                try
                {
                    _event.Name             = Name;
                    _event.Notes            = Note;
                    _event.EndTime          = ChangeTime((DateTime)End, (DateTime)EndTime);
                    _event.StartTime        = ChangeTime((DateTime)Start, (DateTime)StartTime);
                    _event.Status           = Status;
                    _event.RepeatMode       = Repeat;
                    _event.NotificationMode = Notification;
                    _event.ContactId        = Contact?.Id;
                    uow.SaveChanges();
                    MonthVM.LoadTasksAndEvents();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            });
            DelCommand = new RelayCommand(o =>
            {
                try
                {
                    //var uow = UnitOfWorkSingleton.Instance;
                    uow.Events.Delete(_event.Id);
                    uow.SaveChanges();
                    MonthVM.LoadTasksAndEvents();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            });
            AddContactCommand = new RelayCommand(o =>
            {
                try
                {
                    ContactListWindow taskWin = new ContactListWindow()
                    {
                        DataContext = new ContactListViewModel(user, null, this)
                    };
                    taskWin.ShowDialog();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            });
        }