コード例 #1
0
        /// <summary>
        ///  新增记录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void BtnAddClickAsync(object sender, RoutedEventArgs e)
        {
            Lib.MemberRelations NewRecord = new Lib.MemberRelations()
            {
                MemberId = _CurUcViewModel.CurMember.Id,
                Birthday = _CurUcViewModel.CurMember.Birthday.AddYears(-25),
                UserId   = AppSet.LoginUser.Id
            };

            UC_RelationsWin AddWin = new UC_RelationsWin(NewRecord);

            AddWin.Owner = AppSet.AppMainWindow;

            if (AddWin.ShowDialog().Value)
            {
                ExcuteResult excuteResult = await DataMemberRelationsRepository.AddRecord(NewRecord);

                if (excuteResult.State == 0)
                {
                    NewRecord.Id = excuteResult.Tag;
                    _CurUcViewModel.CurRecords.Add(NewRecord);
                    _CurUcViewModel.CurRecords.OrderBy(x => x.OrderIndex);
                }
                else
                {
                    AppFuns.ShowMessage(excuteResult.Msg, Caption: "失败");
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// 编辑一条记录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void BtnEditClickAsync(object sender, RoutedEventArgs e)
        {
            if (RecordListBox.SelectedItem is Lib.MemberRelations SelectedRec)
            {
                Lib.MemberRelations RecCloneObj = CloneObject <Lib.MemberRelations, Lib.MemberRelations> .Trans(SelectedRec);

                UC_RelationsWin AddWin = new UC_RelationsWin(RecCloneObj);
                AddWin.Owner = AppSet.AppMainWindow;

                if (AddWin.ShowDialog().Value)
                {
                    ExcuteResult excuteResult = await DataMemberRelationsRepository.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: "失败");
                    }
                }
            }
        }