private async void UpdateTeacher_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { TeacherModel selectTeacher = this.gvTeacher.SelectedItem as TeacherModel; if (selectTeacher != null) { string strErrorMsg = string.Empty; try { EditTeacherWindow newTeacherWindow = new EditTeacherWindow(); newTeacherWindow.SelectedTeacher = selectTeacher; newTeacherWindow.Om = OperationMode.EditMode; if (newTeacherWindow.ShowDialog() == true) { await bindTeacherList(); } } catch (TimeoutException timeProblem) { strErrorMsg = timeProblem.Message + UIResources.TimeOut + timeProblem.Message; } catch (FaultException <LCFault> af) { strErrorMsg = af.Detail.Message; } catch (FaultException unknownFault) { strErrorMsg = UIResources.UnKnowFault + unknownFault.Message; } catch (CommunicationException commProblem) { strErrorMsg = UIResources.ConProblem + commProblem.Message + commProblem.StackTrace; } catch (Exception ex) { strErrorMsg = ex.Message; } if (strErrorMsg != string.Empty) { await DialogManager.ShowMessageAsync(this.GetMainWindow(), UIResources.MsgError, "更新教师信息失败!原因:" + strErrorMsg, MessageDialogStyle.Affirmative, null); } } }
private async void gvTeacher_AddingNewDataItem(object sender, Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs e) { string strErrorMsg = string.Empty; try { EditTeacherWindow newTeacherWindow = new EditTeacherWindow(); newTeacherWindow.Om = OperationMode.AddMode; if (newTeacherWindow.ShowDialog() == true) { await bindTeacherList(); } } catch (TimeoutException timeProblem) { strErrorMsg = timeProblem.Message + UIResources.TimeOut + timeProblem.Message; } catch (FaultException <LCFault> af) { strErrorMsg = af.Detail.Message; } catch (FaultException unknownFault) { strErrorMsg = UIResources.UnKnowFault + unknownFault.Message; } catch (CommunicationException commProblem) { strErrorMsg = UIResources.ConProblem + commProblem.Message + commProblem.StackTrace; } catch (Exception ex) { strErrorMsg = ex.Message; } if (strErrorMsg != string.Empty) { await DialogManager.ShowMessageAsync(this.GetMainWindow(), UIResources.MsgError, "添加教师信息失败!原因:" + strErrorMsg, MessageDialogStyle.Affirmative, null); } }
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("Все сохранено"); }); }