Beispiel #1
0
 private void Button_Click_3(object sender, RoutedEventArgs e)
 {
     try
     {
         AddPersonWindow window = new AddPersonWindow();
         window.ShowDialog();
     }
     catch (Exception)
     {
     }
     InitUI();
 }
Beispiel #2
0
        /// <summary>
        /// The user wants to add a line.
        /// </summary>
        private void AddLine()
        {
            // TODO: call a dialog using the MVVM pattern to add a line.

            AddPersonWindow addPersonView = new AddPersonWindow(Lines);
            var             result        = addPersonView.ShowDialog();

            // Do not forget to subscribe to line.PenaltyAlreadyExistsAtThisDate and
            // line.PropertyChanged.
            if (result.HasValue && result.Value)
            {
                // If a person has been added, their are located at the end of the list
                Lines.Last().PenaltyAlreadyExistsAtThisDate += HandlePenaltyAlreadyExistsAtThisDate;
                Lines.Last().PropertyChanged += HandleLinePropertyChanded;
            }
        }
Beispiel #3
0
        private void AddPerson_Click(object sender, RoutedEventArgs e)
        {
            AddPersonWindow addPersonWindow = new AddPersonWindow(vm);

            addPersonWindow.ShowDialog();
        }
Beispiel #4
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("Все сохранено");
            });
        }