锐腾搅拌上料功能
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

349 lines
14 KiB

5 months ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using DevExpress.XtraEditors;
  9. using ICSSoft.Base.Config.AppConfig;
  10. using System.Data.Linq;
  11. using System.Linq;
  12. using ICSSoft.Base.Language.Tool;
  13. using System.Reflection;
  14. using ICSSoft.Base.Config.DBHelper;
  15. using ICSSoft.Base.ReferForm;
  16. using ICSSoft.Base.Report;
  17. using ICSSoft.Base.ReferForm.AppReferForm;
  18. using ICSSoft.Frame.Data.Entity;
  19. using ICSSoft.Frame.Data.BLL;
  20. using System.Text.RegularExpressions;
  21. namespace ICSSoft.Frame.APP
  22. {
  23. public partial class FormICSUserInfoAdd : DevExpress.XtraEditors.XtraForm
  24. {
  25. string UserCode = "";
  26. string SEGCode = "";
  27. ICSUserInfo user = new ICSUserInfo();
  28. bool Add = true;
  29. #region 构造函数
  30. public FormICSUserInfoAdd()
  31. {
  32. InitializeComponent();
  33. this.UserCode = "";
  34. Add = true;
  35. }
  36. public FormICSUserInfoAdd(String userid)
  37. {
  38. InitializeComponent();
  39. this.UserCode = userid;
  40. Add = false;
  41. }
  42. #endregion
  43. #region 关闭 退出
  44. private void btnClose_Click(object sender, EventArgs e)
  45. {
  46. this.Close();
  47. }
  48. #endregion
  49. #region 移动窗体
  50. private const int WM_NCHITTEST = 0x84;
  51. private const int HTCLIENT = 0x1;
  52. private const int HTCAPTION = 0x2;
  53. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  54. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  55. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  56. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  57. //重写窗体,使窗体可以不通过自带标题栏实现移动
  58. protected override void WndProc(ref Message m)
  59. {
  60. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  61. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  62. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  63. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  64. switch (m.Msg)
  65. {
  66. case WM_NCHITTEST:
  67. base.WndProc(ref m);
  68. if ((int)m.Result == HTCLIENT)
  69. m.Result = (IntPtr)HTCAPTION;
  70. return;
  71. }
  72. //拦截双击标题栏、移动窗体的系统消息
  73. if (m.Msg != 0xA3)
  74. {
  75. base.WndProc(ref m);
  76. }
  77. }
  78. #endregion
  79. #region 新增 修改
  80. private void save_Click(object sender, EventArgs e)
  81. {
  82. if (this.UserCode == "")
  83. {
  84. ICSBaseSimpleCode.AppshowMessageBox("员工不能为空!");
  85. return;
  86. }
  87. if (this.SEGCode == "")
  88. {
  89. ICSBaseSimpleCode.AppshowMessageBox("车间不能为空!");
  90. return;
  91. }
  92. if (chkFrontLine.Checked && txtSGroup.Text.Trim() == "")
  93. {
  94. ICSBaseSimpleCode.AppshowMessageBox("勾选一线人员后,班组不能为空!");
  95. return;
  96. }
  97. user.UserCode = this.UserCode;
  98. user.SEGCode = this.SEGCode;
  99. user.FrontLine = chkFrontLine.Checked;
  100. user.Mail = txtMail.Text.Trim();
  101. user.Phone = txtPhone.Text.Trim();
  102. user.SGroup = user.FrontLine ? txtSGroup.Text.Trim() : "";
  103. user.ModifyUserCode = AppConfig.UserCode;
  104. user.ModifyDate = DateTime.Now;
  105. user.WorkPoint = AppConfig.WorkPointCode;
  106. bool exist = ICSUserInfoBLL.ExistUserCode(user.UserCode);
  107. if (!exist)
  108. {
  109. ICSBaseSimpleCode.AppshowMessageBox(user.UserCode + "不存在");
  110. return;
  111. }
  112. bool isNew = ICSUserInfoBLL.AllowAdd(user.UserCode);
  113. try
  114. {
  115. if (Add)
  116. {
  117. if (!isNew)
  118. {
  119. ICSBaseSimpleCode.AppshowMessageBox(user.UserCode + "已存在");
  120. return;
  121. }
  122. user.CreateUserCode = user.ModifyUserCode;
  123. user.CreateDate = user.ModifyDate;
  124. }
  125. else
  126. {
  127. if (isNew)
  128. {
  129. ICSBaseSimpleCode.AppshowMessageBox(user.UserCode + "不存在");
  130. return;
  131. }
  132. }
  133. int[] iou= ICSUserInfoBLL.AddAndEdit(new List<ICSUserInfo> { user });
  134. this.Close();
  135. ICSBaseSimpleCode.AppshowMessageBox("成功 新增" + iou[0].ToString()+ "修改"+ iou[1].ToString());
  136. }
  137. catch (Exception ex)
  138. {
  139. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  140. }
  141. }
  142. #endregion
  143. #region 取消
  144. private void can_Click(object sender, EventArgs e)
  145. {
  146. this.Close();
  147. }
  148. #endregion
  149. #region 页面加载
  150. private void FormICSUserInfoAdd_Load(object sender, EventArgs e)
  151. {
  152. init();
  153. if (Add)
  154. {
  155. lblTitle.Text = "新增";
  156. }
  157. else
  158. {
  159. //只能修改手机号,邮件,车间
  160. lblTitle.Text = "修改";
  161. txtUserCode.Properties.ReadOnly = true;
  162. chkFrontLine.Enabled = false;
  163. txtSGroup.Properties.ReadOnly = true;
  164. DataTable dt = ICSUserInfoBLL.Select(UserCode);
  165. if (dt == null || dt.Rows.Count == 0)
  166. {
  167. throw new Exception("没有用户数据");
  168. }
  169. txtUserCode.Text = dt.Rows[0]["UserCode"].ToString();
  170. txtUserName.Text = dt.Rows[0]["UserName"].ToString();
  171. txtSEGCode.Text = dt.Rows[0]["SEGCode"].ToString();
  172. txtSEGDesc.Text = dt.Rows[0]["SEGDesc"].ToString();
  173. chkFrontLine.Checked = Convert.ToBoolean(dt.Rows[0]["FrontLine"]);
  174. txtSGroup.Text = dt.Rows[0]["SGroup"].ToString();
  175. txtPhone.Text = dt.Rows[0]["Phone"].ToString();
  176. txtMail.Text = dt.Rows[0]["Mail"].ToString();
  177. }
  178. this.chkFrontLine.CheckedChanged += new System.EventHandler(this.chkFrontLine_CheckedChanged);
  179. }
  180. #endregion
  181. #region 初始化查询条件
  182. private void init()
  183. {
  184. #region 人员信息
  185. string sql1 = @"
  186. SELECT A.UserCode ,A.UserName FROM dbo.Sys_User A with(nolock)
  187. LEFT JOIN dbo.ICSUserInfo B with(nolock) ON A.UserCode=B.UserCode AND A.WorkPointCode=B.WorkPoint
  188. WHERE A.WorkPointCode='{0}' AND A.StartFlag=1 AND B.UserCode IS NULL
  189. ORDER BY A.UserCode";
  190. sql1 = string.Format(sql1, AppConfig.WorkPointCode);
  191. DataTable dt1 = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql1).Tables[0];
  192. txtUserCode.Properties.ValueMember = "工号";
  193. txtUserCode.Properties.DisplayMember = "工号";
  194. txtUserCode.Properties.DataSource = dt1;
  195. txtUserCode.Properties.NullText = "";//空时的值
  196. txtUserCode.Properties.ImmediatePopup = true;//输入值是否马上弹出窗体
  197. txtUserCode.Properties.ValidateOnEnterKey = true;//回车确认
  198. txtUserCode.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;//要使用户可以输入,这里须设为Standard
  199. txtUserCode.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True; //可用Ctrl + Delete清空选择內容
  200. //自适应宽度
  201. txtUserCode.Properties.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
  202. #endregion
  203. #region 车间
  204. string sql2 = @"SELECT SEGCODE 车间代码,SEGDESC 车间描述 FROM dbo.ICSSEG WHERE WorkPoint='{0}' ORDER BY SEGCODE ";
  205. sql2 = string.Format(sql2, AppConfig.WorkPointCode);
  206. DataTable dt2 = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql2).Tables[0];
  207. txtSEGCode.Properties.ValueMember = "车间代码";
  208. txtSEGCode.Properties.DisplayMember = "车间代码";
  209. txtSEGCode.Properties.DataSource = dt2;
  210. txtSEGCode.Properties.NullText = "";//空时的值
  211. txtSEGCode.Properties.ImmediatePopup = true;//输入值是否马上弹出窗体
  212. txtSEGCode.Properties.ValidateOnEnterKey = true;//回车确认
  213. txtSEGCode.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;//要使用户可以输入,这里须设为Standard
  214. txtSEGCode.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True; //可用Ctrl + Delete清空选择內容
  215. //自适应宽度
  216. txtSEGCode.Properties.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
  217. #endregion
  218. #region 班组
  219. string sql3 = @"SELECT EnumKey ,EnumValue AS 班组代码,EnumText AS 班组说明 FROM dbo.Sys_EnumValues WHERE EnumKey='00022' AND StartFlag=1 AND WorkPointCode='{0}' ORDER BY EnumKey ";
  220. sql3 = string.Format(sql3, AppConfig.WorkPointCode);
  221. DataTable dt3 = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql3).Tables[0];
  222. txtSGroup.Properties.ValueMember = "班组代码";
  223. txtSGroup.Properties.DisplayMember = "班组说明";
  224. txtSGroup.Properties.DataSource = dt3;
  225. txtSGroup.Properties.NullText = "";//空时的值
  226. txtSGroup.Properties.ImmediatePopup = true;//输入值是否马上弹出窗体
  227. txtSGroup.Properties.ValidateOnEnterKey = true;//回车确认
  228. txtSGroup.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;//要使用户可以输入,这里须设为Standard
  229. txtSGroup.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True; //可用Ctrl + Delete清空选择內容
  230. //自适应宽度
  231. txtSGroup.Properties.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
  232. #endregion
  233. }
  234. #endregion
  235. /// <summary>
  236. /// 选择人员
  237. /// </summary>
  238. /// <param name="sender"></param>
  239. /// <param name="e"></param>
  240. private void txtUserCode_EditValueChanged(object sender, EventArgs e)
  241. {
  242. try
  243. {
  244. GridLookUpEdit lookUP = sender as GridLookUpEdit;
  245. if (!string.IsNullOrWhiteSpace(lookUP.EditValue.ToString()))
  246. {
  247. var o = lookUP.Properties.GetRowByKeyValue(lookUP.EditValue);
  248. if (o is DataRowView)
  249. {
  250. DataRowView view = o as DataRowView;
  251. txtUserName.Text = view.Row["姓名"].ToString();
  252. UserCode = view.Row["工号"].ToString();
  253. }
  254. else
  255. {
  256. txtUserName.Text = "";
  257. UserCode = "";
  258. }
  259. }
  260. }
  261. catch (Exception ex)
  262. {
  263. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  264. }
  265. }
  266. /// <summary>
  267. /// 选择车间
  268. /// </summary>
  269. /// <param name="sender"></param>
  270. /// <param name="e"></param>
  271. private void txtSEG_EditValueChanged(object sender, EventArgs e)
  272. {
  273. try
  274. {
  275. GridLookUpEdit lookUP = sender as GridLookUpEdit;
  276. if (!string.IsNullOrWhiteSpace(lookUP.EditValue.ToString()))
  277. {
  278. var o = lookUP.Properties.GetRowByKeyValue(lookUP.EditValue);
  279. if (o is DataRowView)
  280. {
  281. DataRowView view = o as DataRowView;
  282. txtSEGDesc.Text = view.Row["车间描述"].ToString();
  283. SEGCode = view.Row["车间代码"].ToString();
  284. }
  285. else
  286. {
  287. txtSEGDesc.Text = "";
  288. SEGCode = "";
  289. }
  290. }
  291. }
  292. catch (Exception ex)
  293. {
  294. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  295. }
  296. }
  297. /// <summary>
  298. /// 是否是一线员工
  299. /// </summary>
  300. /// <param name="sender"></param>
  301. /// <param name="e"></param>
  302. private void chkFrontLine_CheckedChanged(object sender, EventArgs e)
  303. {
  304. if (chkFrontLine.Checked)
  305. {
  306. txtSGroup.Properties.ReadOnly = false;
  307. txtSGroup.Focus();
  308. }
  309. else
  310. {
  311. txtSGroup.Text = "";
  312. txtSGroup.Properties.ReadOnly = true;
  313. txtPhone.SelectAll();
  314. txtPhone.Focus();
  315. }
  316. }
  317. }
  318. }