/// <summary> /// 新增记录 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void BtnAddClickAsync(object sender, RoutedEventArgs e) { Lib.MemberAppraise NewRecord = new Lib.MemberAppraise() { MemberId = _CurUcViewModel.CurMember.Id, UserId = AppSet.LoginUser.Id }; UC_AppraiseWin AddWin = new UC_AppraiseWin(NewRecord); if (AddWin.ShowDialog().Value) { IEnumerable <MemberAppraise> MemberPlayMonths = await DataMemberAppraiseRepository.GetRecords(new MemberAppraiseSearch() { MemberId = NewRecord.MemberId, UserId = NewRecord.UserId }); ExcuteResult excuteResult = await DataMemberAppraiseRepository.AddRecord(NewRecord); if (excuteResult.State == 0) { NewRecord.Id = excuteResult.Tag; _CurUcViewModel.CurRecords.Add(NewRecord); } else { AppFuns.ShowMessage(excuteResult.Msg, Caption: "失败"); } } }
/// <summary> /// 编辑一条记录 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void BtnEditClickAsync(object sender, RoutedEventArgs e) { if (RecordListBox.SelectedItem is Lib.MemberAppraise SelectedRec) { Lib.MemberAppraise RecCloneObj = CloneObject <Lib.MemberAppraise, Lib.MemberAppraise> .Trans(SelectedRec); UC_AppraiseWin AddWin = new UC_AppraiseWin(RecCloneObj); if (AddWin.ShowDialog().Value) { ExcuteResult excuteResult = await DataMemberAppraiseRepository.UpdateRecord(RecCloneObj); if (excuteResult.State == 0) { PropertyInfo[] TargetAttris = SelectedRec.GetType().GetProperties(); PropertyInfo[] SourceAttris = RecCloneObj.GetType().GetProperties(); foreach (PropertyInfo item in SourceAttris) { var tempObj = TargetAttris.Where(x => x.Name.Equals(item.Name, StringComparison.Ordinal)).FirstOrDefault(); if (tempObj != null) { item.SetValue(SelectedRec, item.GetValue(RecCloneObj)); } } } else { AppFuns.ShowMessage(excuteResult.Msg, Caption: "失败", isErr: true); } } } }