WinDictDetialAddOrEdit.xaml.cs
4.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
using HHECS.Bll;
using HHECS.Model.BllModel;
using HHECS.Model.Entities;
using HHECS.View.Win;
using System;
using System.Windows;
namespace HHECS.View.SystemInfo
{
/// <summary>
/// WinDictDetialAddOrEdit.xaml 的交互逻辑
/// </summary>
public partial class WinDictDetialAddOrEdit : BaseWindow
{
public int? Id { get; set; }
public int HeadId { get; set; }
public DictDetail CurrentDictDetial { get; set; } = new DictDetail();
public Dict DictMain { get; set; }
public WinDictDetialAddOrEdit(int? id,int headId)
{
InitializeComponent();
Id = id;
HeadId = headId;
this.Title = Id == null ? "新增" : "编辑";
Init();
GridMain.DataContext = CurrentDictDetial;
}
private void Init()
{
var result = AppSession.Bll.GetCommonModelByCondition<Dict>($"where id = {HeadId}");
if (result.Success)
{
DictMain = result.Data[0];
if (Id == null)
{
//新增
CurrentDictDetial.HeadCode = DictMain.Code;
CurrentDictDetial.HeadName = DictMain.Name;
CurrentDictDetial.HeadId = DictMain.Id.Value;
}
else
{
//编辑
var a = AppSession.Bll.GetCommonModelByCondition<DictDetail>($"where id = {Id}");
if (a.Success)
{
var temp = a.Data[0];
CurrentDictDetial.Id = temp.Id;
CurrentDictDetial.HeadId = temp.HeadId;
CurrentDictDetial.Code = temp.Code;
CurrentDictDetial.Name = temp.Name;
CurrentDictDetial.Value = temp.Value;
CurrentDictDetial.Sort = temp.Sort;
CurrentDictDetial.Created = temp.Created;
CurrentDictDetial.CreatedBy = temp.CreatedBy;
//主表的
CurrentDictDetial.HeadCode = DictMain.Code;
CurrentDictDetial.HeadName = DictMain.Name;
//
TxtDictDetailCode.IsReadOnly = true;
}
else
{
MessageBox.Show("查询明细失败");
}
}
}
else
{
MessageBox.Show($"查询字典失败:{result.Msg}");
this.Close();
}
}
private void BtnSave_Click(object sender, RoutedEventArgs e)
{
if (CurrentDictDetial.Id == null)
{
//新增
CurrentDictDetial.HeadId = DictMain.Id.Value;
CurrentDictDetial.Created = DateTime.Now;
CurrentDictDetial.CreatedBy = AppSession.User.UserCode;
BllResult<int?> result = AppSession.Bll.SaveCommonModel<DictDetail>(CurrentDictDetial);
if (result.Success)
{
MessageBox.Show("新增成功");
TxtDictDetailCode.IsReadOnly = true;
CurrentDictDetial.Id = result.Data;
}
else
{
MessageBox.Show($"新增失败:{result.Msg}");
}
}
else
{
//更新
CurrentDictDetial.Updated = DateTime.Now;
CurrentDictDetial.UpdatedBy = AppSession.User.UserCode;
BllResult result = AppSession.Bll.UpdateCommonModel<DictDetail>(CurrentDictDetial);
if (result.Success)
{
MessageBox.Show("更新成功");
}
else
{
MessageBox.Show($"更新失败:{result.Msg}");
}
}
}
private void BtnCancel_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}