WinPermission.xaml.cs
8.06 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
using HHECS.Bll;
using HHECS.Model;
using HHECS.View.Win;
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.UserOperation
{
/// <summary>
/// Permission.xaml 的交互逻辑
/// </summary>
public partial class WinPermission : MyWindow
{
public List<MenuOperation> MenuOperations { get; set; }
public MenuOperation CurrentMenuOperation { get; set; } = new MenuOperation();
public List<DictDetail> DictDetails { get; set; }
public WinPermission()
{
InitializeComponent();
this.GridDetail.DataContext = CurrentMenuOperation;
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
var result = AppSession.Bll.GetAllMenuOperation();
if (result.Success)
{
MenuOperations = result.Data.OrderBy(t=>t.OrderNum).ToList();
}
else
{
MessageBox.Show("获取操作权限和菜单出错");
return;
}
//组合层级菜单
AppSession.Bll.Combine(MenuOperations.FindAll(t => t.ParentId == null),MenuOperations);
treeMain.ItemsSource = MenuOperations.FindAll(t => t.ParentId == null);
BllResult<Dict> a = AppSession.Bll.GetDictWithDetails("menuType");
if (a.Success)
{
CBType.ItemsSource = DictDetails = a.Data.DictDetails;
CBType.DisplayMemberPath = "Name";
CBType.SelectedValuePath = "Code";
CBType.SelectedIndex = 0;
}
else
{
MessageBox.Show("获取菜单类型出错");
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
MenuOperation o = (MenuOperation)treeMain.SelectedItem;
if (o?.MenuType == "按钮")
{
MessageBox.Show("按钮类型无法增加子节点");
return;
}
CurrentMenuOperation.Id = null;
CurrentMenuOperation.MenuName = "";
CurrentMenuOperation.ParentId = o?.Id;
CurrentMenuOperation.Url = "";
CurrentMenuOperation.MenuType = "";
CurrentMenuOperation.Perms = "";
CurrentMenuOperation.Remark = "";
CurrentMenuOperation.OrderNum = 0;
CurrentMenuOperation.Created = DateTime.Now;
CurrentMenuOperation.CreatedBy = AppSession.User?.UserName;
CurrentMenuOperation.Updated = null;
CurrentMenuOperation.UpdatedBy = "";
}
private void treeMain_Selected(object sender, RoutedEventArgs e)
{
MenuOperation o = (MenuOperation)treeMain.SelectedItem;
CurrentMenuOperation.Id = o.Id;
CurrentMenuOperation.MenuName = o.MenuName;
CurrentMenuOperation.ParentId = o.ParentId;
CurrentMenuOperation.Url = o.Url;
CurrentMenuOperation.MenuType = o.MenuType;
CurrentMenuOperation.Perms = o.Perms;
CurrentMenuOperation.Remark = o.Remark;
CurrentMenuOperation.OrderNum = o.OrderNum;
CurrentMenuOperation.Created = o.Created;
CurrentMenuOperation.CreatedBy = o.CreatedBy;
CurrentMenuOperation.Updated = DateTime.Now;
CurrentMenuOperation.UpdatedBy = AppSession.User?.UserName;
CBType.SelectedIndex = DictDetails.FindIndex(t => t.Code == CurrentMenuOperation.MenuType);
}
private void BtnDelete_Click(object sender, RoutedEventArgs e)
{
MenuOperation o = (MenuOperation)treeMain.SelectedItem;
if (o == null)
{
MessageBox.Show("请先选中节点");
}
else
{
if (o.Id == null)
{
MessageBox.Show("Id不存在,无法删除");
return;
}
if (MessageBox.Show("是否确认删除?", "警告", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
//级联查出所有待删的Id;
List<int> ids = new List<int>();
ids.Add(CurrentMenuOperation.Id.Value);
AppSession.Bll.GetMenuOperationIds(new List<MenuOperation>() { CurrentMenuOperation },MenuOperations, ids);
BllResult result = AppSession.Bll.DeleteMenuOperationByIds(ids);
if (result.Success)
{
MessageBox.Show("删除成功");
}
else
{
MessageBox.Show("删除失败" + result.Msg);
}
}
Window_Loaded(null, null);
}
}
private void BtnEdit_Click(object sender, RoutedEventArgs e)
{
}
private void BtnSave_Click(object sender, RoutedEventArgs e)
{
//至少名称和类型不能为空
if (String.IsNullOrWhiteSpace(CurrentMenuOperation.MenuName) || String.IsNullOrWhiteSpace(CurrentMenuOperation.MenuType))
{
MessageBox.Show("名称和类型不能为空");
}
switch (CurrentMenuOperation.MenuType)
{
case "menu":
CurrentMenuOperation.Icon = "/Content/Icon/菜单.png";
break;
case "button":
CurrentMenuOperation.Icon = "/Content/Icon/按钮.png";
break;
case "catalog":
CurrentMenuOperation.Icon = "/Content/Icon/目录.png";
break;
default:
CurrentMenuOperation.Icon = "/Content/Icon/未识别.png";
break;
}
if (CurrentMenuOperation.Id == null)
{
//新增
BllResult<MenuOperation> result = AppSession.Bll.SaveMenuOperation(CurrentMenuOperation);
if (result.Success)
{
MessageBox.Show("新增成功");
CurrentMenuOperation.Id = result.Data.Id;
}
else
{
MessageBox.Show("新增失败" + result.Msg);
}
}
else
{
//更新
BllResult result = AppSession.Bll.UpdateMenuOperation(CurrentMenuOperation);
if (result.Success)
{
MessageBox.Show("更新成功");
}
else
{
MessageBox.Show("更新失败" + result.Msg);
}
}
Window_Loaded(null,null);
}
private void BtnCancel_Click(object sender, RoutedEventArgs e)
{
MenuOperation o = (MenuOperation)treeMain.SelectedItem;
if (o != null)
{
CurrentMenuOperation.Id = o.Id;
CurrentMenuOperation.MenuName = o.MenuName;
CurrentMenuOperation.ParentId = o.ParentId;
CurrentMenuOperation.Url = o.Url;
CurrentMenuOperation.MenuType = o.MenuType;
CurrentMenuOperation.Perms = o.Perms;
CurrentMenuOperation.Remark = o.Remark;
CurrentMenuOperation.Created = o.Created;
CurrentMenuOperation.CreatedBy = o.CreatedBy;
CurrentMenuOperation.Updated = DateTime.Now;
CurrentMenuOperation.UpdatedBy = AppSession.User?.UserName;
}
}
private void BtnUpdate_Click(object sender, RoutedEventArgs e)
{
Window_Loaded(null, null);
}
}
}