Exemple #1
0
        private void Edit()
        {
            SubProgramClass     model     = new SubProgramClass();                                     //实例化一个新的model
            SubProgramViewModel viewmodel = new SubProgramViewModel(model, _subprogramRepository, ""); //实例化一个新的view model

            viewmodel.Name        = _selectedItem.Name;
            viewmodel.TestCount   = _selectedItem.TestCount;
            viewmodel.DisplayName = "SubProgram-Edit";
            viewmodel.commandType = CommandType.Edit;
            var SubProgramViewInstance = new SubProgramTemplateView();      //实例化一个新的view

            SubProgramViewInstance.DataContext = viewmodel;
            SubProgramViewInstance.ShowDialog();
            if (viewmodel.IsOK == true)
            {
                _selectedItem.Name      = viewmodel.Name;
                _selectedItem.TestCount = viewmodel.TestCount;
                using (var dbContext = new AppDbContext())
                {
                    var sub = dbContext.SubPrograms.SingleOrDefault(i => i.Id == _selectedItem.Id);
                    sub.Name      = _selectedItem.Name;
                    sub.TestCount = _selectedItem.TestCount;
                    dbContext.SaveChanges();
                }
            }
        }
Exemple #2
0
        private void Create()
        {
            SubProgramClass     model     = new SubProgramClass();                                     //实例化一个新的model
            SubProgramViewModel viewmodel = new SubProgramViewModel(model, _subprogramRepository, ""); //实例化一个新的view model

            viewmodel.DisplayName = "SubProgram-Create";
            viewmodel.commandType = CommandType.Create;
            var SubProgramViewInstance = new SubProgramTemplateView();      //实例化一个新的view

            SubProgramViewInstance.DataContext = viewmodel;
            SubProgramViewInstance.ShowDialog();                   //设置viewmodel属性
            if (viewmodel.IsOK == true)
            {
                //_subprogramRepository.AddItem(model);
                using (var dbContext = new AppDbContext())
                {
                    dbContext.SubPrograms.Add(model);
                    dbContext.SaveChanges();
                    this.AllSubPrograms.Add(viewmodel);
                }
            }
        }
Exemple #3
0
        private void SaveAs()
        {
            SubProgramClass     model     = new SubProgramClass();                                     //实例化一个新的model
            SubProgramViewModel viewmodel = new SubProgramViewModel(model, _subprogramRepository, ""); //实例化一个新的view model

            viewmodel.Name        = _selectedItem.Name;
            viewmodel.TestCount   = _selectedItem.TestCount;
            viewmodel.DisplayName = "SubProgram-Save As";
            viewmodel.commandType = CommandType.SaveAs;
            var SubProgramViewInstance = new SubProgramTemplateView();      //实例化一个新的view

            SubProgramViewInstance.DataContext = viewmodel;
            SubProgramViewInstance.ShowDialog();
            if (viewmodel.IsOK == true)
            {
                using (var dbContext = new AppDbContext())
                {
                    dbContext.SubPrograms.Add(model);
                    dbContext.SaveChanges();
                    this.AllSubPrograms.Add(viewmodel);
                }
            }
        }