提交 | 用户 | 时间
|
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 WeifenLuo.WinFormsUI.Docking; |
|
10 |
using YX.BLL; |
|
11 |
using YX.Entity; |
|
12 |
|
|
13 |
namespace YX |
|
14 |
{ |
|
15 |
public partial class FrmMenu : WindowParent |
|
16 |
{ |
|
17 |
YX.BLL.SystemMenu_Bll menu_bll = new BLL.SystemMenu_Bll(); |
|
18 |
|
|
19 |
public FrmMenu(string ParentId) |
|
20 |
{ |
|
21 |
InitializeComponent(); |
|
22 |
|
|
23 |
SetButton(ParentId, this.toolStrip1);//设置按钮权限 |
|
24 |
} |
|
25 |
|
|
26 |
private void FrmMenu_Load(object sender, EventArgs e) |
|
27 |
{ |
|
28 |
GetComboxList(); |
|
29 |
BindTreeView(); |
|
30 |
if (treeView1.Nodes.Count > 0)//展开一级节点 |
|
31 |
{ |
|
32 |
treeView1.Nodes[0].Expand(); |
|
33 |
} |
|
34 |
//设置隔行背景色 |
|
35 |
this.dataGridView1.RowsDefaultCellStyle.BackColor = Color.White; |
|
36 |
this.dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.BlanchedAlmond; |
|
37 |
//设置不自动显示数据库中未绑定的列 |
|
38 |
this.dataGridView1.AutoGenerateColumns = false; |
|
39 |
} |
|
40 |
private void GetComboxList() |
|
41 |
{ |
|
42 |
DataTable dt = new DataTable(); |
|
43 |
DataColumn Name = new DataColumn("Name"); |
|
44 |
DataColumn Value = new DataColumn("Value"); |
|
45 |
dt.Columns.Add(Name); |
|
46 |
dt.Columns.Add(Value); |
|
47 |
|
|
48 |
DataRow dr1 = dt.NewRow(); |
|
49 |
dr1["Name"] = "菜单名称"; |
|
50 |
dr1["Value"] = "Menu_Name"; |
|
51 |
|
|
52 |
DataRow dr2 = dt.NewRow(); |
|
53 |
dr2["Name"] = "创 建 人"; |
|
54 |
dr2["Value"] = "CreateUserName"; |
|
55 |
|
|
56 |
dt.Rows.Add(dr1); |
|
57 |
dt.Rows.Add(dr2); |
|
58 |
this.com_querylist.ComboBox.DisplayMember = "name"; |
|
59 |
this.com_querylist.ComboBox.ValueMember = "value"; |
|
60 |
|
|
61 |
this.com_querylist.ComboBox.DataSource=dt; |
|
62 |
} |
|
63 |
private void BindTreeView() |
|
64 |
{ |
|
65 |
try |
|
66 |
{ |
|
67 |
this.treeView1.Nodes.Clear(); |
|
68 |
this.treeView1.ImageList = imageList1; |
|
69 |
var list = menu_bll.GetSysMenus(); |
|
70 |
var parents = list.Where(o => o.ParentId == "0"); |
|
71 |
foreach (var item in parents) |
|
72 |
{ |
|
73 |
TreeNode tn = new TreeNode(); |
|
74 |
tn.Text = item.Menu_Name; |
|
75 |
tn.Tag = item.Menu_Id; |
|
76 |
tn.ImageIndex = 0; |
|
77 |
FillTree(tn, list); |
|
78 |
treeView1.Nodes.Add(tn); |
|
79 |
} |
|
80 |
} |
|
81 |
catch (Exception ex) |
|
82 |
{ |
|
83 |
|
|
84 |
System_Bll.WriteLogToDB(new Entity.Base_Log |
|
85 |
{ |
|
86 |
CreateUserID = FrmLogin.LoginUserID, |
|
87 |
CreateUserName = FrmLogin.loginUserName, |
|
88 |
LocalIP = FrmLogin.LocalIP, |
|
89 |
LogMessage = ex.Message, |
|
90 |
Type = "系统错误!", |
|
91 |
ClassName = typeof(FrmMenu).ToString() |
|
92 |
}); |
|
93 |
MessageBox.Show(ex.Message); |
|
94 |
} |
|
95 |
} |
|
96 |
|
|
97 |
private void FillTree(TreeNode node, List<Base_SysMenu> list) |
|
98 |
{ |
|
99 |
|
|
100 |
var childs = list.Where(o => o.ParentId == node.Tag.ToString()); |
|
101 |
if (childs.Count() > 0) |
|
102 |
{ |
|
103 |
foreach (var item in childs) |
|
104 |
{ |
|
105 |
TreeNode tnn = new TreeNode(); |
|
106 |
tnn.Text = item.Menu_Name; |
|
107 |
tnn.Tag = item.Menu_Id; |
|
108 |
tnn.ImageIndex = 0; |
|
109 |
if (item.ParentId == node.Tag.ToString()) |
|
110 |
{ |
|
111 |
FillTree(tnn, list); |
|
112 |
} |
|
113 |
node.Nodes.Add(tnn); |
|
114 |
} |
|
115 |
|
|
116 |
} |
|
117 |
} |
|
118 |
|
|
119 |
private void btn_Add_Click(object sender, EventArgs e) |
|
120 |
{ |
|
121 |
FrmMenuEdit edit = new FrmMenuEdit(this); |
|
122 |
edit.ShowDialog(); |
|
123 |
} |
|
124 |
|
|
125 |
private void btn_edit_Click(object sender, EventArgs e) |
|
126 |
{ |
|
127 |
if (dataGridView1.DataSource == null) |
|
128 |
{ |
|
129 |
MessageBox.Show("请选择要编辑的行!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information); |
|
130 |
} |
|
131 |
else |
|
132 |
{ |
|
133 |
DataGridViewRow dr = dataGridView1.SelectedRows[0]; |
|
134 |
|
|
135 |
if (dr != null) |
|
136 |
{ |
|
137 |
FrmMenuEdit edit = new FrmMenuEdit(this, ref dr); |
|
138 |
edit.ShowDialog(); |
|
139 |
} |
|
140 |
} |
|
141 |
} |
|
142 |
|
|
143 |
private void btn_delete_Click(object sender, EventArgs e) |
|
144 |
{ |
|
145 |
try |
|
146 |
{ |
|
147 |
DataGridViewRow dr = dataGridView1.SelectedRows[0]; |
|
148 |
if (dr != null) |
|
149 |
{ |
|
150 |
int result= menu_bll.DeleteSysMenu(dr.Cells["Menu_Id"].Value.ToString()); |
|
151 |
if (result == 1) |
|
152 |
{ |
|
153 |
MessageBox.Show("删除成功!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information); |
|
154 |
this.dataGridView1.DataSource = menu_bll.GetSysMenuChilds(treeView1.SelectedNode.Tag.ToString(),FrmLogin.LoginUserID); |
|
155 |
} |
|
156 |
else |
|
157 |
{ |
|
158 |
MessageBox.Show("删除失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); |
|
159 |
} |
|
160 |
} |
|
161 |
} |
|
162 |
catch (Exception ex) |
|
163 |
{ |
|
164 |
|
|
165 |
System_Bll.WriteLogToDB(new Entity.Base_Log |
|
166 |
{ |
|
167 |
CreateUserID = FrmLogin.LoginUserID, |
|
168 |
CreateUserName = FrmLogin.loginUserName, |
|
169 |
LocalIP = FrmLogin.LocalIP, |
|
170 |
LogMessage = ex.Message, |
|
171 |
Type = "系统错误!", |
|
172 |
ClassName = typeof(FrmDeptInfoEdit).ToString() |
|
173 |
}); |
|
174 |
MessageBox.Show(ex.Message); |
|
175 |
} |
|
176 |
} |
|
177 |
|
|
178 |
private void btn_refresh_Click(object sender, EventArgs e) |
|
179 |
{ |
|
180 |
|
|
181 |
this.dataGridView1.DataSource = menu_bll.GetSysMenuChilds(treeView1.SelectedNode.Tag.ToString()); |
|
182 |
|
|
183 |
} |
|
184 |
|
|
185 |
private void btn_select_Click(object sender, EventArgs e) |
|
186 |
{ |
|
187 |
//this.dataGridView1.DataSource= bll.QueryMenusByCondition(this.listView1.SelectedItems[0].Tag.ToString(),com_querylist.ComboBox.SelectedValue.ToString(),txt_query.Text); |
|
188 |
// string ParentId = this.listView1.SelectedItems[0].Tag.ToString(); |
|
189 |
string ParentId = treeView1.SelectedNode.Tag.ToString(); |
|
190 |
string condition = com_querylist.ComboBox.SelectedValue.ToString(); |
|
191 |
string queryValue = txt_query.Text; |
|
192 |
switch (condition) |
|
193 |
{ |
|
194 |
case "Menu_Name": |
|
195 |
this.dataGridView1.DataSource = menu_bll.GetMenusByCondition(o => o.ParentId == ParentId && o.Menu_Name.Contains(queryValue)); |
|
196 |
break; |
|
197 |
case "CreateUserName": |
|
198 |
this.dataGridView1.DataSource = menu_bll.GetMenusByCondition(o => o.ParentId == ParentId && o.CreateUserName.Contains(queryValue)); |
|
199 |
break; |
|
200 |
} |
|
201 |
|
|
202 |
} |
|
203 |
|
|
204 |
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) |
|
205 |
{ |
|
206 |
if (this.treeView1.SelectedNode.Nodes.Count > 0) |
|
207 |
{ |
|
208 |
this.dataGridView1.DataSource = menu_bll.GetSysMenuChilds(treeView1.SelectedNode.Tag.ToString()); |
|
209 |
} |
|
210 |
} |
|
211 |
|
|
212 |
private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e) |
|
213 |
{ |
|
214 |
BindTreeView(); |
|
215 |
if (treeView1.Nodes.Count > 0)//展开一级节点 |
|
216 |
{ |
|
217 |
treeView1.Nodes[0].Expand(); |
|
218 |
} |
|
219 |
} |
|
220 |
} |
|
221 |
} |