提交 | 用户 | 时间
|
e46d3b
|
1 |
using System; |
懒 |
2 |
using System.Collections.Generic; |
|
3 |
using System.ComponentModel; |
|
4 |
using System.Data; |
|
5 |
using System.Drawing; |
|
6 |
using System.Linq; |
|
7 |
using System.Text; |
|
8 |
using System.Windows.Forms; |
|
9 |
using YX.BLL; |
|
10 |
using YX.Entity; |
|
11 |
|
|
12 |
namespace YX |
|
13 |
{ |
|
14 |
public partial class FrmRoleEdit : Form |
|
15 |
{ |
|
16 |
SystemMenu_Bll menu_bll = new SystemMenu_Bll(); |
|
17 |
SystemRole_Bll role_bll = new SystemRole_Bll(); |
|
18 |
OperationType type; |
|
19 |
FrmRole _frmRole; |
|
20 |
string RoleID = ""; |
|
21 |
public FrmRoleEdit(FrmRole frmRole) |
|
22 |
{ |
|
23 |
InitializeComponent(); |
|
24 |
_frmRole = frmRole; |
|
25 |
type = OperationType.Add; |
|
26 |
this.Text = "角色管理-添加"; |
|
27 |
com_ParentId.DataSource = role_bll.GetRoleParentId(); |
|
28 |
com_ParentId.DisplayMember = "Roles_Name"; |
|
29 |
com_ParentId.ValueMember = "Roles_ID"; |
|
30 |
} |
|
31 |
public FrmRoleEdit(FrmRole frmRole,ref DataGridViewRow dvr) |
|
32 |
{ |
|
33 |
InitializeComponent(); |
|
34 |
_frmRole = frmRole; |
|
35 |
type = OperationType.Edit; |
|
36 |
this.Text = "角色管理-修改"; |
|
37 |
com_ParentId.DataSource = role_bll.GetRoleParentId(); |
|
38 |
com_ParentId.DisplayMember = "Roles_Name"; |
|
39 |
com_ParentId.ValueMember = "Roles_ID"; |
|
40 |
|
|
41 |
RoleID = dvr.Cells["Roles_ID"].Value.ToString(); |
|
42 |
txt_RoleName.Text= dvr.Cells["Roles_Name"].Value.ToString(); |
|
43 |
txt_RoleRemark.Text= dvr.Cells["Roles_Remark"].Value==null?"": dvr.Cells["Roles_Remark"].Value.ToString(); |
|
44 |
txt_SortCode.Text= dvr.Cells["SortCode"].Value.ToString(); |
|
45 |
com_ParentId.SelectedValue= dvr.Cells["ParentId"].Value.ToString(); |
|
46 |
|
|
47 |
} |
|
48 |
|
|
49 |
private void FrmRoleEdit_Load(object sender, EventArgs e) |
|
50 |
{ |
|
51 |
BindRoleRightTreeView(); |
|
52 |
if (tree_RoleRight.Nodes.Count > 0) |
|
53 |
{ |
|
54 |
tree_RoleRight.Nodes[0].Expand(); |
|
55 |
} |
|
56 |
|
|
57 |
} |
|
58 |
private void btn_concel_Click(object sender, EventArgs e) |
|
59 |
{ |
|
60 |
this.Close(); |
|
61 |
} |
|
62 |
#region 角色权限 |
|
63 |
/// <summary> |
|
64 |
/// 用户权限菜单树列表 |
|
65 |
/// </summary> |
|
66 |
public void BindRoleRightTreeView() |
|
67 |
{ |
|
68 |
try |
|
69 |
{ |
|
70 |
this.tree_RoleRight.ImageList = imageList1; |
|
71 |
this.tree_RoleRight.Nodes.Clear(); |
|
72 |
var list = menu_bll.GetSysMenus(); |
|
73 |
var role_right_list = menu_bll.GetRoleRightByCondition(o => o.Base_Roles.Roles_ID == RoleID); |
|
74 |
var parents = list.Where(o => o.ParentId == "0"); |
|
75 |
foreach (var item in parents) |
|
76 |
{ |
|
77 |
TreeNode tn = new TreeNode(); |
|
78 |
tn.Text = item.Menu_Name; |
|
79 |
tn.Tag = item.Menu_Id; |
|
80 |
tn.ImageIndex = item.Menu_Img == null ? 0 : item.Menu_Img.Value; |
|
81 |
foreach (var role_right in role_right_list) |
|
82 |
{ |
|
83 |
if (item.Menu_Id == role_right.Menu_Id) |
|
84 |
{ |
|
85 |
tn.Checked = true; |
|
86 |
} |
|
87 |
} |
|
88 |
RoleRightFillTree(tn, list, role_right_list); |
|
89 |
tree_RoleRight.Nodes.Add(tn); |
|
90 |
} |
|
91 |
} |
|
92 |
catch (Exception) |
|
93 |
{ |
|
94 |
|
|
95 |
throw; |
|
96 |
} |
|
97 |
} |
|
98 |
|
|
99 |
private void RoleRightFillTree(TreeNode node, List<Base_SysMenu> list, List<Base_RoleRight> role_right_list) |
|
100 |
{ |
|
101 |
|
|
102 |
var childs = list.Where(o => o.ParentId == node.Tag.ToString()); |
|
103 |
if (childs.Count() > 0) |
|
104 |
{ |
|
105 |
foreach (var item in childs) |
|
106 |
{ |
|
107 |
TreeNode tnn = new TreeNode(); |
|
108 |
tnn.Text = item.Menu_Name; |
|
109 |
tnn.Tag = item.Menu_Id; |
|
110 |
tnn.ImageIndex = item.Menu_Img == null ? 0 : item.Menu_Img.Value; |
|
111 |
foreach (var role_right in role_right_list) |
|
112 |
{ |
|
113 |
if (item.Menu_Id == role_right.Menu_Id) |
|
114 |
{ |
|
115 |
tnn.Checked = true; |
|
116 |
} |
|
117 |
} |
|
118 |
if (item.ParentId == node.Tag.ToString()) |
|
119 |
{ |
|
120 |
RoleRightFillTree(tnn, list, role_right_list); |
|
121 |
} |
|
122 |
node.Nodes.Add(tnn); |
|
123 |
} |
|
124 |
|
|
125 |
} |
|
126 |
} |
|
127 |
#endregion |
|
128 |
|
|
129 |
#region 保存 |
|
130 |
private void btn_save_Click(object sender, EventArgs e) |
|
131 |
{ |
|
132 |
try |
|
133 |
{ |
|
134 |
Base_Roles roles = new Base_Roles(); |
|
135 |
if (string.IsNullOrEmpty(RoleID)) |
|
136 |
{ |
|
137 |
roles.CreateDate = DateTime.Now; |
|
138 |
roles.CreateUserId = FrmLogin.LoginUserID; |
|
139 |
roles.CreateUserName = FrmLogin.loginUserName; |
|
140 |
roles.Roles_ID = Guid.NewGuid().ToString(); |
|
141 |
} |
|
142 |
else |
|
143 |
{ |
|
144 |
roles.ModifyDate = DateTime.Now; |
|
145 |
roles.ModifyUserId = FrmLogin.LoginUserID; |
|
146 |
roles.ModifyUserName = FrmLogin.loginUserName; |
|
147 |
roles.Roles_ID = RoleID; |
|
148 |
} |
|
149 |
RoleRightList.Clear(); |
|
150 |
CheckRoleRightTreeViewNode(tree_RoleRight.Nodes); |
|
151 |
roles.Base_RoleRight = RoleRightList; |
|
152 |
roles.ParentId = com_ParentId.SelectedValue.ToString(); |
|
153 |
roles.Roles_Name = txt_RoleName.Text; |
|
154 |
roles.Roles_Remark = txt_RoleRemark.Text; |
|
155 |
roles.SortCode = int.Parse(txt_SortCode.Text); |
|
156 |
int isOk = 0; |
|
157 |
if (type == OperationType.Add) |
|
158 |
{ |
|
159 |
isOk = role_bll.AddRoles(roles); |
|
160 |
} |
|
161 |
else if (type == OperationType.Edit) |
|
162 |
{ |
|
163 |
isOk = role_bll.UpdateRoles(roles); |
|
164 |
} |
|
165 |
if (isOk > 0) |
|
166 |
{ |
|
167 |
MessageBox.Show("保存成功!"); |
|
168 |
|
|
169 |
this.Close(); |
|
170 |
} |
|
171 |
else |
|
172 |
{ |
|
173 |
MessageBox.Show("保存失败!"); |
|
174 |
} |
|
175 |
} |
|
176 |
catch (Exception ex) |
|
177 |
{ |
|
178 |
|
|
179 |
System_Bll.WriteLogToDB(new Entity.Base_Log |
|
180 |
{ |
|
181 |
CreateUserID = FrmLogin.LoginUserID, |
|
182 |
CreateUserName = FrmLogin.loginUserName, |
|
183 |
LocalIP = FrmLogin.LocalIP, |
|
184 |
LogMessage = ex.Message, |
|
185 |
Type = "系统错误!", |
|
186 |
ClassName = typeof(FrmRoleEdit).ToString() |
|
187 |
}); |
|
188 |
MessageBox.Show(ex.Message); |
|
189 |
} |
|
190 |
} |
|
191 |
|
|
192 |
|
|
193 |
List<Base_RoleRight> RoleRightList = new List<Base_RoleRight>(); |
|
194 |
/// <summary> |
|
195 |
/// 遍历角色权限选中节点 |
|
196 |
/// </summary> |
|
197 |
/// <param name="node"></param> |
|
198 |
public void CheckRoleRightTreeViewNode(TreeNodeCollection node) |
|
199 |
{ |
|
200 |
|
|
201 |
foreach (TreeNode n in node) |
|
202 |
{ |
|
203 |
if (n.Checked) |
|
204 |
{ |
|
205 |
RoleRightList.Add(new Base_RoleRight |
|
206 |
{ |
|
207 |
RoleRight_ID = Guid.NewGuid().ToString(), |
|
208 |
Menu_Id = n.Tag.ToString(), |
|
209 |
CreateUserName = FrmLogin.loginUserName, |
|
210 |
CreateUserId = FrmLogin.LoginUserID, |
|
211 |
CreateDate = DateTime.Now |
|
212 |
}); |
|
213 |
} |
|
214 |
CheckRoleRightTreeViewNode(n.Nodes); |
|
215 |
} |
|
216 |
} |
|
217 |
#endregion |
|
218 |
} |
|
219 |
} |