Beispiel #1
0
        public MedRecordViewModel(Employee employee)
        {
            DownloadMedRecords();
            currentemployee = employee;

            FilterCollectionView.Filter = i =>
            {
                if (_searchKey == "" || _searchKey == null)
                {
                    return(true);
                }
                if (string.IsNullOrEmpty(FilterString))
                {
                    return(true);
                }
                if (_searchKey == "Фамилия")
                {
                    MedRecord m = i as MedRecord;
                    return(m.Surname.ToString().StartsWith(FilterString));
                }
                if (_searchKey == "Имя")
                {
                    MedRecord m = i as MedRecord;
                    return(m.Name.ToString().StartsWith(FilterString));
                }
                if (_searchKey == "Отчество")
                {
                    MedRecord m = i as MedRecord;
                    return(m.Patronymic.ToString().StartsWith(FilterString));
                }
                if (_searchKey == "Город")
                {
                    MedRecord m = i as MedRecord;
                    return(m.City.ToString().StartsWith(FilterString));
                }
                if (_searchKey == "Улица")
                {
                    MedRecord m = i as MedRecord;
                    return(m.Street.ToString().StartsWith(FilterString));
                }
                if (_searchKey == "Дом")
                {
                    MedRecord m = i as MedRecord;
                    return(m.Home.ToString().StartsWith(FilterString));
                }
                else
                {
                    return(true);
                }
            };

            EditMedRecord = new DelegateCommand(() =>
            {
                editoradd = false;
                selectedMedRecord?.BeginEdit();

                var w         = new MedRecordEdit();
                w.DataContext = this;
                w.ShowDialog();
            }, () => selectedMedRecord != null);


            AddMedRecord = new DelegateCommand(() =>
            {
                editoradd = true;

                MedRecord NewMedRecord = new MedRecord();
                SelectedMedRecord      = NewMedRecord;

                var w         = new MedRecordEdit();
                w.DataContext = this;
                w.ShowDialog();
            });

            SaveMedRecord = new DelegateCommand(() =>
            {
                if (editoradd == true)
                {
                    context.MedRecord.Add(selectedMedRecord);

                    context.SaveChanges();

                    MedRecords.Add(SelectedMedRecord);
                }
                else
                {
                    context.Entry(selectedMedRecord).State = EntityState.Modified;
                    context.SaveChanges();
                }
            });

            RemoveMedRecord = new DelegateCommand(() =>
            {
                if (MessageBox.Show("Удалить?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
                {
                    context.Entry(selectedMedRecord).State = EntityState.Deleted;
                    MedRecords.Remove(selectedMedRecord);
                    context.SaveChanges();
                }
                else
                {
                    return;
                }
            }, () => selectedMedRecord != null);

            CanselEdit = new DelegateCommand(() =>
            {
                if (editoradd == false)
                {
                    if (selectedMedRecord == null)
                    {
                        return;
                    }
                    SelectedMedRecord.CancelEdit();
                }
                else
                {
                    return;
                }
            });

            MedRecordOpen = new DelegateCommand(() =>
            {
                MedRecordOpenViewModel viewmodel = new MedRecordOpenViewModel(SelectedMedRecord, currentemployee);
                var w         = new OpenMedRecord();
                w.DataContext = viewmodel;
                w.ShowDialog();
            }, () => currentemployee.Post.Name == "Врач" || currentemployee.Post.Name == "Администратор");
        }
Beispiel #2
0
        public TimetableVIewModel(bool a)
        {
            if (a)
            {
                DownloadTimetables();
            }

            FilterCollectionView.Filter = i =>
            {
                if (_searchKey == "" || _searchKey == null)
                {
                    return(true);
                }
                if (string.IsNullOrEmpty(FilterString))
                {
                    return(true);
                }
                if (_searchKey == "Фамилия")
                {
                    MedRecord m = i as MedRecord;
                    return(m.Surname.ToString().StartsWith(FilterString));
                }
                if (_searchKey == "Имя")
                {
                    MedRecord m = i as MedRecord;
                    return(m.Name.ToString().StartsWith(FilterString));
                }
                if (_searchKey == "Отчество")
                {
                    MedRecord m = i as MedRecord;
                    return(m.Patronymic.ToString().StartsWith(FilterString));
                }
                if (_searchKey == "Город")
                {
                    MedRecord m = i as MedRecord;
                    return(m.City.ToString().StartsWith(FilterString));
                }
                if (_searchKey == "Улица")
                {
                    MedRecord m = i as MedRecord;
                    return(m.Street.ToString().StartsWith(FilterString));
                }
                if (_searchKey == "Дом")
                {
                    MedRecord m = i as MedRecord;
                    return(m.Home.ToString().StartsWith(FilterString));
                }
                else
                {
                    return(true);
                }
            };

            EditTimetable = new DelegateCommand(() =>
            {
                editoradd = false;

                var w         = new MedRecordEdit();
                w.DataContext = this;
                w.ShowDialog();
            }, () => selectedTimetable != null);


            //AddTimetable = new DelegateCommand(() =>
            //{
            //    editoradd = true;

            //    Timetable timetable = new Timetable();
            //    SelectedTimetable = timetable;

            //    var w = new MedRecordEdit();
            //    w.DataContext = this;
            //    w.Show();
            //});

            //SaveTimetable = new DelegateCommand(() =>
            //{
            //    if (editoradd == true)
            //    {
            //        context.Timetable.Add(SelectedTimetable);

            //        context.SaveChanges();

            //        Timetables.Add(SelectedTimetable);
            //    }
            //    else
            //    {
            //        context.Entry(selectedTimetable).State = EntityState.Modified;
            //        context.SaveChanges();
            //    }
            //});

            //RemoveTimetable = new DelegateCommand(() =>
            //{
            //    if (MessageBox.Show("Удалить?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
            //    {
            //        context.Entry(SelectedTimetable).State = EntityState.Deleted;
            //        Timetables.Remove(SelectedTimetable);
            //        context.SaveChanges();
            //    }
            //    else
            //    {
            //        return;
            //    }
            //}, () => selectedTimetable != null);

            //CanselEdit = new DelegateCommand(() =>
            //{
            //    if (editoradd == false)
            //    {
            //        if (selectedTimetable == null) return;
            //        SelectedTimetable.CancelEdit();
            //    }
            //    else
            //    {
            //        return;
            //    }
            //});
        }