懒羊羊
2023-12-28 e46d3baaf3e8d7d85f4bafec3aad75e52b078408
提交 | 用户 | 时间
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 namespace YX
13 {
14     public partial class FrmDeptInfo : WindowParent
15     {
16
17         SystemOrganization_Bll org_bll = new SystemOrganization_Bll();
18         SystemMenu_Bll menu_bll = new SystemMenu_Bll();
19         public FrmDeptInfo(string ParentId)
20         {
21             InitializeComponent();
22             SetButton(ParentId, this.toolStrip1);//设置按钮权限
23         }
24       
25         private void FrmDeptInfo_Load(object sender, EventArgs e)
26         {
27  
28             //设置不自动显示数据库中未绑定的列
29             this.dataGridView1.AutoGenerateColumns = false;
30             BindTreeView();
31         
32         }
33         public void BindTreeView()
34         {
35             try
36             {
37                 treeView1.Nodes.Clear();
38                var  list = org_bll.GetOrganizations();
39                 var parents = list.Where(o=>o.ParentId=="0");
40                 foreach (var item in parents)
41                 {
42                     TreeNode tn = new TreeNode();
43                     tn.Text = item.Organization_Name;
44                     tn.Tag = item.Organization_ID;
45                     tn.ImageIndex = 0;
46                     FillTree(tn, list);
47                     treeView1.Nodes.Add(tn);
48                 }
49
50                 treeView1.ExpandAll();
51                 
52             }
53             catch (Exception ex)
54             {
55                 System_Bll.WriteLogToDB(
56                    new Entity.Base_Log
57                   {
58                       CreateUserID = FrmLogin.LoginUserID,
59                       CreateUserName = FrmLogin.loginUserName,
60                       LocalIP = FrmLogin.LocalIP,
61                       LogMessage = ex.Message,
62                       Type = "系统错误!",
63                       ClassName = typeof(FrmDeptInfo).ToString()
64
65                   });
66                 MessageBox.Show(ex.Message);
67             }
68         }
69
70         private void FillTree(TreeNode node, List<Base_Organization> list)
71         {
72            
73             var childs = list.Where(o=>o.ParentId==node.Tag.ToString());
74             if (childs.Count() > 0)
75             {
76                 foreach (var item in childs)
77                 {
78                     TreeNode tnn = new TreeNode();
79                     tnn.Text = item.Organization_Name;
80                     tnn.Tag = item.Organization_ID;
81                     tnn.ImageIndex = 0;
82                     if (item.ParentId == node.Tag.ToString())
83                     {
84                         FillTree(tnn, list);
85                     }
86                     node.Nodes.Add(tnn);
87                 }
88               
89             }
90         }
91
92         private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
93         {         
94             string Organization_ID = e.Node.Tag.ToString();                  
95             this.dataGridView1.DataSource = org_bll.GetOrganizationDetail(Organization_ID);
96             
97         }
98
99         private void btn_Add_Click(object sender, EventArgs e)
100         {
101             FrmDeptInfoEdit edit = new FrmDeptInfoEdit(this);
102             edit.StartPosition = FormStartPosition.CenterParent;
103             edit.ShowDialog();
104             
105         }
106
107         private void btn_edit_Click(object sender, EventArgs e)
108         {
109             if (dataGridView1.DataSource == null)
110             {
111                 MessageBox.Show("请选择要编辑的行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
112             }
113             else
114             {
115                 DataGridViewRow dr = dataGridView1.SelectedRows[0];
116                 if (dr != null)
117                 {
118                     FrmDeptInfoEdit edit = new FrmDeptInfoEdit(this,ref dr);
119                     edit.ShowDialog();
120                 }
121             }
122         }
123
124         private void btn_delete_Click(object sender, EventArgs e)
125         {
126             try
127             {
128                 DataGridViewRow dr = dataGridView1.SelectedRows[0];
129                 if (dr != null)
130                 {
131                     int result = org_bll.DeleteSysOrganization(dr.Cells["Organization_ID"].Value.ToString());
132                     if (result == 1)
133                     {
134                         MessageBox.Show("删除成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
135                         this.dataGridView1.DataSource = org_bll.GetOrganizationDetail(treeView1.SelectedNode.Tag.ToString());
136                         BindTreeView();
137                     }
138                     else
139                     {
140                         MessageBox.Show("删除失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
141                     }
142                 }
143             }
144             catch (Exception ex)
145             {
146
147                 System_Bll.WriteLogToDB(
148                    new Entity.Base_Log
149                    {
150                        CreateUserID = FrmLogin.LoginUserID,
151                        CreateUserName = FrmLogin.loginUserName,
152                        LocalIP = FrmLogin.LocalIP,
153                        LogMessage = ex.Message,
154                        Type = "系统错误!",
155                        ClassName = typeof(FrmDeptInfo).ToString()
156
157                    });
158                 MessageBox.Show(ex.Message);
159             }
160         }
161     }
162 }