예제 #1
0
        public MainWindowVM()
        {
            _model.PropertyChanged += (sender, args) => { RaisePropertyChanged(args.PropertyName); };

            RefreshCitizenTable = new DelegateCommand(() =>
            {
                _model.RefreshTables();
            });

            AddCitizen = new DelegateCommand(() =>
            {
                AddCitizenWindow acw = new AddCitizenWindow();
                acw.ShowDialog();
                _model.RefreshTables();
            });

            EditCitizen = new DelegateCommand(() =>
            {
                EditCitizenWindow ecw = new EditCitizenWindow();
                ecw.DataContext       = SelectedCitizen;
                Citizen ctz           = SelectedCitizen;
                if (ecw.ShowDialog() == true)
                {
                    using (var db = new CitizenDbContext())
                    {
                        var citizen      = (from i in db.Citizens where i.Id == ctz.Id select i).First();
                        citizen.Name     = ctz.Name;
                        citizen.Surname  = ctz.Surname;
                        citizen.Patronym = ctz.Patronym;
                        db.SaveChanges();
                    }
                    _model.RefreshTables();
                }
            });

            DeleteCitizen = new DelegateCommand(() =>
            {
                using (var db = new CitizenDbContext())
                {
                    var citizen = (from i in db.Citizens where i.Id == SelectedCitizen.Id select i).First();
                    db.Citizens.Remove(citizen);
                    db.SaveChanges();
                }
                _model.RefreshTables();
            });

            AddPerson = new DelegateCommand(() =>
            {
                AddPersonWindow apw = new AddPersonWindow();
                apw.ShowDialog();
                _model.RefreshTables();
            });

            EditPerson = new DelegateCommand(() =>
            {
                EditPersonWindow epw = new EditPersonWindow();
                Person prs           = SelectedPerson;
                epw.DataContext      = prs;
                if (epw.ShowDialog() == true)
                {
                    using (var db = new CitizenDbContext())
                    {
                        var person       = (from i in db.Persons where i.Id == prs.Id select i).First();
                        person.Cypher    = prs.Cypher;
                        person.Inn       = prs.Inn;
                        person.Type      = prs.Type;
                        person.Date      = prs.Date;
                        person.CitizenId = prs.CitizenId;
                        db.SaveChanges();
                    }
                    _model.RefreshTables();
                }
            });

            DeletePerson = new DelegateCommand(() =>
            {
                using (var db = new CitizenDbContext())
                {
                    var person = (from i in db.Persons where i.Id == SelectedPerson.Id select i).First();
                    db.Persons.Remove(person);
                    db.SaveChanges();
                }
                _model.RefreshTables();
            });

            AddDocument = new DelegateCommand(() =>
            {
                AddDocumentWindow adw = new AddDocumentWindow();
                adw.ShowDialog();
                _model.RefreshTables();
            });

            EditDocument = new DelegateCommand(() =>
            {
                EditDocumentWindow edw = new EditDocumentWindow();
                Document doc           = SelectedDocument;
                edw.DataContext        = doc;
                if (edw.ShowDialog() == true)
                {
                    using (var db = new CitizenDbContext())
                    {
                        var document         = (from i in db.Documents where i.Id == doc.Id select i).First();
                        document.Name        = doc.Name;
                        document.Serial      = doc.Serial;
                        document.WhereIssued = doc.WhereIssued;
                        document.DateIssued  = doc.DateIssued;
                        document.CitizenId   = doc.CitizenId;
                        db.SaveChanges();
                    }
                    _model.RefreshTables();
                }
            });

            DeleteDocument = new DelegateCommand(() =>
            {
                using (var db = new CitizenDbContext())
                {
                    var document = (from i in db.Documents where i.Id == SelectedDocument.Id select i).First();
                    db.Documents.Remove(document);
                    db.SaveChanges();
                }
                _model.RefreshTables();
            });

            FindByCypher = new DelegateCommand(() =>
            {
                FindByCypherWindow fbc = new FindByCypherWindow();
                fbc.Show();
            });

            SaveToJSON = new DelegateCommand(() =>
            {
                _model.SaveToJSON(Citizens, Persons, Documents);
                MessageBox.Show("Все сохранено");
            });
        }
예제 #2
0
        public MainWindowVM()
        {
            _model.PropertyChanged += (sender, args) => { RaisePropertyChanged(args.PropertyName); };

            FindComplexSearch = new DelegateCommand(() =>
            {
                Search cs = new Search();
                cs.Show();
            });

            RefreshTeacherTable = new DelegateCommand(() =>
            {
                _model.RefreshTables();
            });

            AddTeacher = new DelegateCommand(() =>
            {
                AddTeacherWindow atw = new AddTeacherWindow();
                atw.ShowDialog();
                _model.RefreshTables();
            });

            EditTeacher = new DelegateCommand(() =>
            {
                EditTeacherWindow ecw = new EditTeacherWindow();
                ecw.DataContext       = SelectedTeacher;
                Teacher tch           = SelectedTeacher;
                if (ecw.ShowDialog() == true)
                {
                    using (var db = new MyDbcontext())
                    {
                        var Teacher        = (from i in db.Teachers where i.Id == tch.Id select i).First();
                        Teacher.FirstName  = tch.FirstName;
                        Teacher.LastName   = tch.LastName;
                        Teacher.SecondName = tch.SecondName;
                        db.SaveChanges();
                    }
                    _model.RefreshTables();
                }
            });

            DeleteTeacher = new DelegateCommand(() =>
            {
                using (var db = new MyDbcontext())
                {
                    var Teacher = (from i in db.Teachers where i.Id == SelectedTeacher.Id select i).First();
                    db.Teachers.Remove(Teacher);
                    db.SaveChanges();
                }
                _model.RefreshTables();
            });

            AddChair = new DelegateCommand(() =>
            {
                AddChairWindow apw = new AddChairWindow();
                apw.DataContext    = new AddChairVM();
                apw.ShowDialog();
                _model.RefreshTables();
            });

            EditChair = new DelegateCommand(() =>
            {
                EditChairWindow epw = new EditChairWindow();
                Chair chr           = SelectedChair;
                epw.DataContext     = chr;
                if (epw.ShowDialog() == true)
                {
                    using (var db = new MyDbcontext())
                    {
                        var Chair            = (from i in db.Chairs where i.Id == chr.Id select i).First();
                        Chair.NameChair      = chr.NameChair;
                        Chair.ShortNameChair = chr.ShortNameChair;
                        db.SaveChanges();
                    }
                    _model.RefreshTables();
                }
            });

            DeleteChair = new DelegateCommand(() =>
            {
                using (var db = new MyDbcontext())
                {
                    var Chair = (from i in db.Chairs where i.Id == SelectedChair.Id select i).First();
                    db.Chairs.Remove(Chair);
                    db.SaveChanges();
                }
                _model.RefreshTables();
            });

            AddFaculty = new DelegateCommand(() =>
            {
                AddFacultyWindow adw = new AddFacultyWindow();
                adw.DataContext      = new AddFacultyVM();
                adw.ShowDialog();
                _model.RefreshTables();
            });

            EditFaculty = new DelegateCommand(() =>
            {
                EditFacultyWindow edw = new EditFacultyWindow();
                Faculty fcl           = SelectedFaculty;
                edw.DataContext       = fcl;
                if (edw.ShowDialog() == true)
                {
                    using (var db = new MyDbcontext())
                    {
                        var Faculty              = (from i in db.Faculties where i.Id == fcl.Id select i).First();
                        Faculty.NameFaculty      = fcl.NameFaculty;
                        Faculty.ShortNameFaculty = fcl.ShortNameFaculty;
                        db.SaveChanges();
                    }
                    _model.RefreshTables();
                }
            });

            DeleteFaculty = new DelegateCommand(() =>
            {
                using (var db = new MyDbcontext())
                {
                    var Faculty = (from i in db.Faculties where i.Id == SelectedFaculty.Id select i).First();
                    db.Faculties.Remove(Faculty);
                    db.SaveChanges();
                }
                _model.RefreshTables();
            });

            FindByCypher = new DelegateCommand(() =>
            {
                FindByCypherWindow fbc = new FindByCypherWindow();
                fbc.Show();
            });

            SaveToJSON = new DelegateCommand(() =>
            {
                _model.SaveToJSON(Teachers, Chairs, Faculties);
                MessageBox.Show("Все сохранено");
            });
        }