WinDict.xaml.cs
8.07 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
using HHECS.Bll;
using HHECS.Controls;
using HHECS.Model;
using HHECS.Model.BllModel;
using HHECS.Model.Entities;
using HHECS.View.Win;
using HHECS.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace HHECS.View.SystemInfo
{
/// <summary>
/// WinDict.xaml 的交互逻辑
/// </summary>
public partial class WinDict : MyWindow
{
/// <summary>
/// 用于明细页绑定
/// </summary>
public Dict CurrentDict { get; set; } = new Dict();
public PageInfoVM PageInfo { get; set; } = new PageInfoVM();
public WinDict()
{
InitializeComponent();
this.page.DataContext = PageInfo;
this.GridDetail.DataContext = CurrentDict;
}
private void BtnQuery_Click(object sender, RoutedEventArgs e)
{
Query();
}
private void Query()
{
string sql = "where 1=1 ";
if (!String.IsNullOrWhiteSpace(TxtCode.Text))
{
sql += $" and code like '{TxtCode.Text}%'";
}
if (!String.IsNullOrWhiteSpace(TxtName.Text))
{
sql += $" and name like '{TxtName.Text}%'";
}
BllResult<int> result = AppSession.Bll.GetCommonModelCount<Dict>(sql);
if (result.Success)
{
PageInfo.TotalCount = result.Data;
BllResult<List<Dict>> a = AppSession.Bll.GetCommonModeByPageCondition<Dict>(PageInfo.PageIndex, PageInfo.PageSize, sql, "");
if (a.Success)
{
DGMain.ItemsSource = a.Data;
TIMain.IsSelected = true;
DGDetail.ItemsSource = null;
}
else
{
MessageBox.Show($"查询失败{a.Msg}");
}
}
else
{
MessageBox.Show($"查询失败{result.Msg}");
}
}
private void QueryDetail(Dict dict)
{
BllResult<List<DictDetail>> result = AppSession.Bll.GetCommonModelByCondition<DictDetail>($"where headId ={dict.Id}");
if (result.Success)
{
var temp = result.Data;
temp.ForEach(t => { t.HeadCode = dict.Code; t.HeadName = dict.Name; });
DGDetail.ItemsSource = temp;
TIDetail.IsSelected = true;
CurrentDict = dict;
GridDetail.DataContext = CurrentDict;
}
else
{
MessageBox.Show($"查询明细失败{result.Msg}");
}
}
private void BtnAdd_Click(object sender, RoutedEventArgs e)
{
WinDictAddOrEdit win = new WinDictAddOrEdit(null);
win.ShowDialog();
}
private void BtnEdit_Click(object sender, RoutedEventArgs e)
{
if (DGMain.SelectedItem == null)
{
MessageBox.Show("请先选中一条数据");
}
else
{
Dict temp = (Dict)DGMain.SelectedItem;
WinDictAddOrEdit win = new WinDictAddOrEdit(temp.Id);
win.ShowDialog();
}
}
private void BtnDelete_Click(object sender, RoutedEventArgs e)
{
if (DGMain.SelectedItems == null || DGMain.SelectedItems.Count == 0)
{
MessageBox.Show("请至少选中一条数据");
}
else
{
if (MessageBox.Show("删除数据字典可能导致程序异常,是否继续?", "警告", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
List<Dict> list = new List<Dict>();
foreach (var item in DGMain.SelectedItems)
{
list.Add((Dict)item);
}
BllResult result = AppSession.Bll.DeleteDictByIds(list.Select(t => t.Id.Value).ToList());
if (result.Success)
{
MessageBox.Show("删除成功");
}
else
{
MessageBox.Show($"删除失败:{result.Msg}");
}
Query();
}
}
}
private void BtnAddDetail_Click(object sender, RoutedEventArgs e)
{
if (CurrentDict.Id.HasValue)
{
WinDictDetialAddOrEdit win = new WinDictDetialAddOrEdit(null, CurrentDict.Id.Value);
win.ShowDialog();
}
else
{
MessageBox.Show("无主数据");
}
}
private void BtnEditDetial_Click(object sender, RoutedEventArgs e)
{
if (DGDetail.SelectedItem == null)
{
MessageBox.Show("请先选中一条字典明细数据,再行编辑");
}
else
{
DictDetail detail = (DictDetail)DGDetail.SelectedItem;
WinDictDetialAddOrEdit win = new WinDictDetialAddOrEdit(detail.Id, detail.HeadId);
win.ShowDialog();
}
}
private void BtnDeleteDetail_Click(object sender, RoutedEventArgs e)
{
if (DGDetail.SelectedItems == null || DGDetail.SelectedItems.Count == 0)
{
MessageBox.Show("请至少选中一条字典明细");
}
else
{
if (MessageBox.Show("删除数据字典明细可能导致程序异常,是否继续?", "警告", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
List<DictDetail> list = new List<DictDetail>();
foreach (var item in DGDetail.SelectedItems)
{
list.Add((DictDetail)item);
}
BllResult result = AppSession.Bll.DeleteCommonModelByIds<DictDetail>(list.Select(t => t.Id.Value).ToList());
if (result.Success)
{
MessageBox.Show("删除成功");
}
else
{
MessageBox.Show($"删除失败:{result.Msg}");
}
//这里重新按照headid来查询下
BllResult<List<Dict>> a = AppSession.Bll.GetCommonModelByCondition<Dict>($"where id = {list[0].HeadId}");
if (a.Success)
{
QueryDetail(a.Data[0]);
}
else
{
DGDetail.ItemsSource = null;
}
}
}
}
/// <summary>
/// 主表双击事件响应
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void DataGridRow_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
if (sender != null)
{
DataGridRow dgr = sender as DataGridRow;
if (!dgr.IsNewItem)
{
QueryDetail((Dict)dgr.Item);
//事件不再向上传递,防止设置其他tabitem的isselected属性失败
e.Handled = true;
DGMain.SelectedItem = dgr.Item;
}
}
}
private void BtnQueryDetail_Click(object sender, RoutedEventArgs e)
{
QueryDetail(CurrentDict);
}
private void page_PageChanged(object sender, PageChangedEventArgs e)
{
PageInfo.PageSize = e.CurrentPageIndex;
Query();
}
}
}