懒羊羊
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 YX.BLL;
10 using YX.Common.DoNetCode;
11 using YX.Entity;
12
13 namespace YX
14 {
15     public partial class FrmDeptInfoEdit : Form
16     {
17    
18         YX.BLL.SystemOrganization_Bll org_bll = new BLL.SystemOrganization_Bll();
19         OperationType type;
20         FrmDeptInfo _frmDeptInfo;
21         public FrmDeptInfoEdit(FrmDeptInfo frmDeptInfo)
22         {
23           
24             type = OperationType.Add;
25             this._frmDeptInfo = frmDeptInfo;
26             InitializeComponent();
27             this.Text = "部门信息-添加";
28             com_ParentId.DataSource = org_bll.GetInitParentId();
29             com_ParentId.DisplayMember = "Organization_Name";
30             com_ParentId.ValueMember = "Organization_ID";
31         }
32         public FrmDeptInfoEdit(FrmDeptInfo frmDeptInfo,ref DataGridViewRow dvr)
33         {
34           
35             type = OperationType.Edit;
36             this._frmDeptInfo = frmDeptInfo;
37             InitializeComponent();
38             this.Text = "部门信息-修改";
39
40             com_ParentId.DataSource = org_bll.GetInitParentId();
41             com_ParentId.DisplayMember = "Organization_Name";
42             com_ParentId.ValueMember = "Organization_ID";
43             try
44             {
45
46                 this.txt_Organization_Address.Text = dvr.Cells["Organization_Address"].Value==null?"": dvr.Cells["Organization_Address"].Value.ToString();
47                 this.txt_Organization_Code.Text = dvr.Cells["Organization_Code"].Value==null?"": dvr.Cells["Organization_Code"].Value.ToString();
48                 this.txt_Organization_AssistantManager.Text = dvr.Cells["Organization_AssistantManager"].Value==null?"" : dvr.Cells["Organization_AssistantManager"].Value.ToString();
49                 this.txt_Organization_Fax.Text = dvr.Cells["Organization_Fax"].Value == null ? "" : dvr.Cells["Organization_Fax"].Value.ToString();
50                 this.txt_Organization_InnerPhone.Text = dvr.Cells["Organization_InnerPhone"].Value==null?"": dvr.Cells["Organization_InnerPhone"].Value.ToString();
51                 this.txt_Organization_Manager.Text = dvr.Cells["Organization_Manager"].Value==null?"": dvr.Cells["Organization_Manager"].Value.ToString();
52                 this.txt_Organization_Name.Text = dvr.Cells["Organization_Name"].Value==null?"": dvr.Cells["Organization_Name"].Value.ToString();
53                 this.txt_Organization_OuterPhone.Text = dvr.Cells["Organization_OuterPhone"].Value==null?"": dvr.Cells["Organization_OuterPhone"].Value.ToString();
54                 this.txt_Organization_Remark.Text = dvr.Cells["Organization_Remark"].Value==null?"": dvr.Cells["Organization_Remark"].Value.ToString();
55                 this.txt_Organization_Zipcode.Text = dvr.Cells["Organization_Zipcode"].Value==null?"": dvr.Cells["Organization_Zipcode"].Value.ToString();
56                 this.txt_SortCode.Text = dvr.Cells["SortCode"].Value==null?"": dvr.Cells["SortCode"].Value.ToString();
57                 com_ParentId.SelectedValue = dvr.Cells["ParentId"].Value==null?"": dvr.Cells["ParentId"].Value.ToString();
58             }
59             catch (Exception ex)
60             {
61                 System_Bll.WriteLogToDB(
62                 new Entity.Base_Log
63                 {
64                     CreateUserID = FrmLogin.LoginUserID,
65                     CreateUserName = FrmLogin.loginUserName,
66                     LocalIP = FrmLogin.LocalIP,
67                     LogMessage = ex.Message,
68                     Type = "系统错误!",
69                     ClassName = typeof(FrmDeptInfoEdit).ToString()
70
71                 });
72                 MessageBox.Show(ex.Message);
73             }
74         }
75         private void FrmDeptInfoEdit_Load(object sender, EventArgs e)
76         {
77             this.MaximizeBox = false;
78             this.MinimizeBox = false;
79
80         }
81
82         private void btn_concel_Click(object sender, EventArgs e)
83         {
84             this.Close();
85         }
86         private bool CheckInputData()
87         {
88             bool result = true;
89             if(string.IsNullOrEmpty(txt_Organization_Code.Text))
90             {
91                 MessageBox.Show("请输入部门编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
92                 txt_Organization_Code.Focus();
93                 result = false;
94             }else if (string.IsNullOrEmpty(txt_Organization_Name.Text))
95             {
96                 MessageBox.Show("请输入部门名称!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
97                 txt_Organization_Name.Focus();
98                 result = false;
99             }else if (string.IsNullOrEmpty(txt_SortCode.Text))
100             {
101                 MessageBox.Show("请输入显示顺序!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
102                 txt_SortCode.Focus();
103                 result = false;
104             }else if(!string .IsNullOrEmpty(txt_SortCode.Text) && !ValidateUtil.IsNumber(txt_SortCode.Text.Trim()))
105             {
106                 MessageBox.Show("显示顺序必须为正整数!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
107                 txt_SortCode.Focus();
108                 result = false;
109             }
110             else if (string.IsNullOrEmpty(com_ParentId.Text))
111             {
112                 MessageBox.Show("请选择节点位置!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
113                 com_ParentId.Focus();
114                 result = false;
115             }
116
117             return result;
118         }
119         private void btn_save_Click(object sender, EventArgs e)
120         {
121             try
122             {
123                 if (CheckInputData())
124                 {
125                     if (type == OperationType.Add)
126                     {
127                         Base_Organization Org = new Base_Organization
128                         {
129                             CreateDate = DateTime.Now,
130                             CreateUserId = FrmLogin.LoginUserID,
131                             CreateUserName = FrmLogin.loginUserName,
132                             Organization_Address = txt_Organization_Address.Text,
133                             Organization_AssistantManager = txt_Organization_AssistantManager.Text,
134                             Organization_Code = txt_Organization_Code.Text,
135                             Organization_Fax = txt_Organization_Fax.Text,
136                             Organization_ID = Guid.NewGuid().ToString(),
137                             Organization_InnerPhone = txt_Organization_InnerPhone.Text,
138                             Organization_Manager = txt_Organization_Manager.Text,
139                             Organization_Name = txt_Organization_Name.Text,
140                             Organization_OuterPhone = txt_Organization_OuterPhone.Text,
141                             Organization_Remark = txt_Organization_Remark.Text,
142                             Organization_Zipcode = txt_Organization_Zipcode.Text,
143                             ParentId = com_ParentId.SelectedValue.ToString(),
144                             SortCode = int.Parse(txt_SortCode.Text),
145                             DeleteMark = 1
146                         };
147                         int result = org_bll.AddSysOrganization(Org);
148                         if (result == 1)
149                         {
150                             MessageBox.Show("添加成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
151                             _frmDeptInfo.BindTreeView();
152                             this.Close();
153                         }
154                         else
155                         {
156                             MessageBox.Show("添加失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
157                         }
158                     }
159                     else
160                     {
161                         Base_Organization Org = new Base_Organization
162                         {
163
164                             ModifyDate = DateTime.Now,
165                             ModifyUserId = FrmLogin.LoginUserID,
166                             ModifyUserName = FrmLogin.loginUserName,
167                             Organization_Address = txt_Organization_Address.Text,
168                             Organization_AssistantManager = txt_Organization_AssistantManager.Text,
169                             Organization_Code = txt_Organization_Code.Text,
170                             Organization_Fax = txt_Organization_Fax.Text,
171                             Organization_ID = _frmDeptInfo.treeView1.SelectedNode.Tag.ToString(),
172                             Organization_InnerPhone = txt_Organization_InnerPhone.Text,
173                             Organization_Manager = txt_Organization_Manager.Text,
174                             Organization_Name = txt_Organization_Name.Text,
175                             Organization_OuterPhone = txt_Organization_OuterPhone.Text,
176                             Organization_Remark = txt_Organization_Remark.Text,
177                             Organization_Zipcode = txt_Organization_Zipcode.Text,
178                             ParentId = com_ParentId.SelectedValue.ToString(),
179                             SortCode = int.Parse(txt_SortCode.Text),
180                             DeleteMark = 1
181                         };
182                         int result = org_bll.UpdateSysOrganization(Org);
183                         if (result == 1)
184                         {
185                             MessageBox.Show("修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
186                             _frmDeptInfo.BindTreeView();
187                             this.Close();
188                         }
189                         else
190                         {
191                             MessageBox.Show("修改失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
192                         }
193                     }
194                 }
195                
196             }
197             catch (Exception ex)
198             {
199
200                 System_Bll.WriteLogToDB( new Entity.Base_Log{
201                 CreateUserID = FrmLogin.LoginUserID,
202                 CreateUserName = FrmLogin.loginUserName,
203                 LocalIP = FrmLogin.LocalIP,
204                 LogMessage = ex.Message,
205                 Type = "系统错误!",
206                 ClassName = typeof(FrmDeptInfoEdit).ToString() });
207                 MessageBox.Show(ex.Message);
208             }
209         }
210     }
211 }