/// <summary> /// 编辑记录 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void BtnEditClickAsync(object sender, RoutedEventArgs e) { if (RecordListBox.SelectedItem is Lib.MemberHoliday SelectedRec) { Lib.MemberHoliday RecCloneObj = CloneObject <Lib.MemberHoliday, Lib.MemberHoliday> .Trans(SelectedRec); PageHolidayInputWin AddWin = new PageHolidayInputWin(RecCloneObj); AddWin.Owner = AppSet.AppMainWindow; if (AddWin.ShowDialog().Value) { ExcuteResult excuteResult = await DataMemberHolidayRepository.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: "失败"); } } } }
/// <summary> /// 新增记录 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void BtnAddClickAsync(object sender, RoutedEventArgs e) { Lib.MemberHoliday NewRecord = new Lib.MemberHoliday() { UnitName = AppSet.LoginUser.UnitName, Member = _PageViewModel.CurMember, MemberId = _PageViewModel.CurMember.Id, UserId = AppSet.LoginUser.Id }; PageHolidayInputWin AddWin = new PageHolidayInputWin(NewRecord); AddWin.Owner = AppSet.AppMainWindow; if (AddWin.ShowDialog().Value) { ExcuteResult excuteResult = await DataMemberHolidayRepository.AddRecord(NewRecord); if (excuteResult != null) { if (excuteResult.State == 0) { NewRecord.Id = excuteResult.Tag; _PageViewModel.MemberHolidays.Add(NewRecord); } else { AppFuns.ShowMessage(excuteResult.Msg, Caption: "失败"); } } else { AppFuns.ShowMessage("数据输入不正确!", Caption: "失败"); } } }