/// <summary> /// 新增记录 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void BtnAddClickAsync(object sender, RoutedEventArgs e) { Lib.MemberPrizePunishEntity NewRecord = new Lib.MemberPrizePunishEntity() { MemberId = _UCPrizePunishVM.CurMember.Id, UserId = AppSet.LoginUser.Id }; UC_PrizePunishWin AddWin = new UC_PrizePunishWin(NewRecord); AddWin.Owner = AppSet.AppMainWindow; if (AddWin.ShowDialog().Value) { IEnumerable <MemberPrizePunishDto> MemberPlayMonths = await DataMemberPrizePunishRepository.GetRecords(new MemberPrizePunishSearch() { MemberId = NewRecord.MemberId, UserId = NewRecord.UserId }); ExcuteResult excuteResult = await DataMemberPrizePunishRepository.AddRecord(NewRecord); if (excuteResult.State == 0) { NewRecord.Id = excuteResult.Tag; _UCPrizePunishVM.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.MemberPrizePunishEntity SelectedRec) { Lib.MemberPrizePunishEntity RecCloneObj = CloneObject <Lib.MemberPrizePunishEntity, Lib.MemberPrizePunishEntity> .Trans(SelectedRec); UC_PrizePunishWin AddWin = new UC_PrizePunishWin(RecCloneObj); AddWin.Owner = AppSet.AppMainWindow; if (AddWin.ShowDialog().Value) { ExcuteResult excuteResult = await DataMemberPrizePunishRepository.UpdateRecord(RecCloneObj); if (excuteResult != null && 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: "失败"); } } } }