华恒Mes鼎捷代码
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.

363 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.Frame.User.BLL;
  10. using ICSSoft.Base.Language.Tool;
  11. using ICSSoft.Base.UserControl.MessageControl;
  12. using System.Data.SqlClient;
  13. using ICSSoft.Base.Config.AppConfig;
  14. using ICSSoft.Base.Report.Filter;
  15. using ICSSoft.Base.Config.DBHelper;
  16. using ICSSoft.Base.UserControl.FormControl;
  17. using ICSSoft.Base.ReferForm.AppReferForm;
  18. using ICSSoft.Base.Lable.PrintTool;
  19. using ICSSoft.Frame.Data.BLL;
  20. using ICSSoft.Frame.Data.Entity;
  21. //using ZHCSoft.AntiwearValveExpanded.DAL;
  22. //using ZHCSoft.AntiwearValveExpanded.BLL;
  23. //using ZHCSoft.AntiwearValveExpanded.Entity;
  24. namespace ICSSoft.Frame.APP
  25. {
  26. public partial class FormICSOP2UserAdd : DevExpress.XtraEditors.XtraForm
  27. {
  28. String guid = "";
  29. int flag;
  30. string opid;
  31. string username;
  32. FormICSOP2UserUIModel model;
  33. #region 构造函数
  34. public FormICSOP2UserAdd()
  35. {
  36. InitializeComponent();
  37. flag = 0;
  38. chargeFormState("Add");
  39. INIT();
  40. }
  41. public FormICSOP2UserAdd(string opCode, string userCode)
  42. {
  43. InitializeComponent();
  44. INIT();
  45. flag = 1;
  46. SearchInfo(opCode, userCode);
  47. chargeFormState("Edit");
  48. }
  49. #endregion
  50. private void chargeFormState(string state)
  51. {
  52. switch (state)
  53. {
  54. case "Add":
  55. txtOPCODE.Properties.ReadOnly = false;
  56. txtUSERCODE.Properties.ReadOnly = false;
  57. txtMUSERName.Text = AppConfig.UserName;
  58. txtMTIME.Text = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss").ToString();
  59. txtMUSERName.Properties.ReadOnly = true;
  60. txtMTIME.Properties.ReadOnly = true;
  61. break;
  62. case "Edit":
  63. txtOPCODE.Properties.ReadOnly = true;
  64. txtUSERCODE.Properties.ReadOnly = true;
  65. txtMUSERName.Text = AppConfig.UserName;
  66. txtMTIME.Text = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss").ToString();
  67. txtMUSERName.Properties.ReadOnly = true;
  68. txtMTIME.Properties.ReadOnly = true;
  69. break;
  70. }
  71. }
  72. private void SearchInfo(string opCode, string userCode)
  73. {
  74. model = ICSOP2UserBLL.SearchInfoByCode(opCode, userCode, AppConfig.AppConnectString);
  75. opid = model.OPID;
  76. txtOPCODE.EditValue= model.OPCODE;
  77. txtUSERCODE.EditValue = model.USERCODE;
  78. txtLevel.Text = model.Level;
  79. username = model.USERName;
  80. }
  81. #region 关闭 退出
  82. private void btnClose_Click(object sender, EventArgs e)
  83. {
  84. this.Close();
  85. }
  86. #endregion
  87. #region 移动窗体
  88. private const int WM_NCHITTEST = 0x84;
  89. private const int HTCLIENT = 0x1;
  90. private const int HTCAPTION = 0x2;
  91. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  92. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  93. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  94. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  95. //重写窗体,使窗体可以不通过自带标题栏实现移动
  96. protected override void WndProc(ref Message m)
  97. {
  98. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  99. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  100. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  101. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  102. switch (m.Msg)
  103. {
  104. case WM_NCHITTEST:
  105. base.WndProc(ref m);
  106. if ((int)m.Result == HTCLIENT)
  107. m.Result = (IntPtr)HTCAPTION;
  108. return;
  109. }
  110. //拦截双击标题栏、移动窗体的系统消息
  111. if (m.Msg != 0xA3)
  112. {
  113. base.WndProc(ref m);
  114. }
  115. }
  116. #endregion
  117. #region 新增 修改
  118. private void save_Click(object sender, EventArgs e)
  119. {
  120. try
  121. {
  122. if (txtOPCODE.Text.Trim()=="")
  123. {
  124. ICSBaseSimpleCode.AppshowMessageBox("工序不能为空");
  125. return;
  126. }
  127. if (txtUSERCODE.Text.Trim()=="")
  128. {
  129. ICSBaseSimpleCode.AppshowMessageBox("人员不能为空");
  130. return;
  131. }
  132. FormICSOP2UserUIModel test = new FormICSOP2UserUIModel();
  133. test.op = new FormICSOPUIModel();
  134. test.op.ID = opid;
  135. test.op.OPCODE = txtOPCODE.Text;
  136. test.user = new FormICSUserUIModel();
  137. test.user.UserCode=txtUSERCODE.Text;
  138. test.user.UserName = username;
  139. test.MUSER = AppConfig.UserId;
  140. test.MUSERName = AppConfig.UserName;
  141. test.MTIME = DateTime.Now;
  142. test.WorkPoint = AppConfig.WorkPointCode;
  143. test.EATTRIBUTE1 = "";
  144. test.Level = txtLevel.Text.Trim();
  145. ICSOP2UserBLL.Add(flag,test, AppConfig.AppConnectString);
  146. ICSBaseSimpleCode.AppshowMessageBox("操作成功");
  147. }
  148. catch (Exception ex)
  149. {
  150. MessageBox.Show(ex.Message);
  151. }
  152. this.Close();
  153. this.DialogResult = DialogResult.Yes;
  154. }
  155. #endregion
  156. #region 取消
  157. private void can_Click(object sender, EventArgs e)
  158. {
  159. this.Close();
  160. }
  161. #endregion
  162. #region 工序代码按钮
  163. private void txtOPCODE_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
  164. {
  165. ButtonEdit btn = (ButtonEdit)sender;
  166. string sql = "select distinct ID as [工序ID],OPCODE as [工序代码],OPDESC as [工序描述] from dbo.ICSOP with(nolock) WHERE 1=1";
  167. //object obj = AppConfig.InvokeWebservice(AppConfig.BaseServiceUri, "WebBaseService", "BaseService", "GetHuaRongErpConnectString", new object[] { });
  168. //if (obj == null)
  169. //{
  170. // ICSBaseSimpleCode.AppshowMessageBox(1, "ERP数据库连接取得失败!");
  171. //}
  172. DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql).Tables[0];
  173. FormDataRefer reForm = new FormDataRefer();
  174. reForm.FormTitle = "工序信息";
  175. DataTable menuData = data;
  176. reForm.DataSource = menuData;
  177. reForm.MSelectFlag = false;
  178. reForm.RowIndexWidth = 35;
  179. reForm.HideCols.Add("工序ID");
  180. reForm.FormWidth = 500;
  181. reForm.FormHeight = 500;
  182. //reForm.FilterKey = btn.Text;
  183. //grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, grvDetail.FocusedColumn).ToString().Trim();
  184. if (reForm.ShowDialog() == DialogResult.OK)
  185. {
  186. DataTable retData = reForm.ReturnData;
  187. foreach (DataRow dr in retData.Rows)
  188. {
  189. txtOPCODE.Text = dr["工序代码"].ToString();
  190. opid = dr["工序ID"].ToString();
  191. }
  192. }
  193. }
  194. #endregion
  195. #region 人员代码按钮
  196. private void txtUSERCODE_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
  197. {
  198. ButtonEdit btn = (ButtonEdit)sender;
  199. string sql = @"select distinct ID as [人员ID],UserCode as [人员代码],USERName as [人员名称] from dbo.Sys_User with(nolock)
  200. WHERE UserCode not in(select USERCODE from ICSOP2User where OPCODE='" +txtOPCODE.Text+"') and 1=1";
  201. //object obj = AppConfig.InvokeWebservice(AppConfig.BaseServiceUri, "WebBaseService", "BaseService", "GetHuaRongErpConnectString", new object[] { });
  202. //if (obj == null)
  203. //{
  204. // ICSBaseSimpleCode.AppshowMessageBox(1, "ERP数据库连接取得失败!");
  205. //}
  206. DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql).Tables[0];
  207. FormDataRefer reForm = new FormDataRefer();
  208. reForm.FormTitle = "人员信息";
  209. DataTable menuData = data;
  210. reForm.DataSource = menuData;
  211. reForm.MSelectFlag = false;
  212. reForm.RowIndexWidth = 35;
  213. reForm.HideCols.Add("人员ID");
  214. reForm.FormWidth = 500;
  215. reForm.FormHeight = 500;
  216. //reForm.FilterKey = btn.Text;
  217. //grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, grvDetail.FocusedColumn).ToString().Trim();
  218. if (reForm.ShowDialog() == DialogResult.OK)
  219. {
  220. DataTable retData = reForm.ReturnData;
  221. foreach (DataRow dr in retData.Rows)
  222. {
  223. txtUSERCODE.Text = dr["人员代码"].ToString();
  224. username = dr["人员名称"].ToString();
  225. }
  226. }
  227. }
  228. private void panelControl1_Paint(object sender, PaintEventArgs e)
  229. {
  230. }
  231. private void FormICSOP2UserAdd_Load(object sender, EventArgs e)
  232. {
  233. }
  234. public void INIT() {
  235. #region 工序
  236. string sql = "select distinct OPCODE as [工序代码],OPDESC as [工序描述],ID from dbo.ICSOP with(nolock) WHERE 1=1";
  237. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql).Tables[0];
  238. txtOPCODE.Properties.ValueMember = "工序代码";
  239. txtOPCODE.Properties.DisplayMember = "工序代码";
  240. txtOPCODE.Properties.DataSource = dt;
  241. txtOPCODE.Properties.NullText = "";//空时的值
  242. txtOPCODE.Properties.ImmediatePopup = true;//输入值是否马上弹出窗体
  243. txtOPCODE.Properties.ValidateOnEnterKey = true;//回车确认
  244. txtOPCODE.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;//要使用户可以输入,这里须设为Standard
  245. txtOPCODE.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True; //可用Ctrl + Delete清空选择內容
  246. //自适应宽度
  247. txtOPCODE.Properties.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
  248. #endregion
  249. }
  250. private void txtOPCODE_EditValueChanged(object sender, EventArgs e)
  251. {
  252. var o = txtOPCODE.Properties.GetRowByKeyValue(txtOPCODE.EditValue);
  253. if (o is DataRowView)
  254. {
  255. DataRowView RowView = o as DataRowView;
  256. opid = RowView.Row["ID"].ToString();
  257. }
  258. #region 设备编码
  259. string sql = "";
  260. if (txtOPCODE.Properties.ReadOnly)
  261. {
  262. sql = @"select UserCode as [人员代码],USERName as [人员名称] from dbo.Sys_User with(nolock)
  263. WHERE UserCode not in(select USERCODE from ICSOP2User where OPCODE='" + txtOPCODE.Text + "') and 1=1";
  264. }
  265. else {
  266. sql = @"select UserCode as [人员代码],USERName as [人员名称] from dbo.Sys_User with(nolock)";
  267. }
  268. DataTable dt1 = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql).Tables[0];
  269. txtUSERCODE.Properties.ValueMember = "人员代码";
  270. txtUSERCODE.Properties.DisplayMember = "人员代码";
  271. txtUSERCODE.Properties.DataSource = dt1;
  272. txtUSERCODE.Properties.NullText = "";//空时的值
  273. txtUSERCODE.Properties.ImmediatePopup = true;//输入值是否马上弹出窗体
  274. txtUSERCODE.Properties.ValidateOnEnterKey = true;//回车确认
  275. txtUSERCODE.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;//要使用户可以输入,这里须设为Standard
  276. txtUSERCODE.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True; //可用Ctrl + Delete清空选择內容
  277. //自适应宽度
  278. txtUSERCODE.Properties.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
  279. #endregion
  280. }
  281. private void txtUSERCODE_EditValueChanged(object sender, EventArgs e)
  282. {
  283. var o = txtUSERCODE.Properties.GetRowByKeyValue(txtUSERCODE.EditValue);
  284. if (o is DataRowView)
  285. {
  286. DataRowView RowView = o as DataRowView;
  287. username = RowView.Row["人员名称"].ToString();
  288. }
  289. }
  290. #endregion
  291. //private void txtITEMCODE_KeyPress(object sender, KeyPressEventArgs e)
  292. //{
  293. // if (e.KeyChar != (char)Keys.Back)
  294. // {
  295. // e.Handled = true;
  296. // }
  297. //}
  298. //private void txtROUTECODE_KeyPress(object sender, KeyPressEventArgs e)
  299. //{
  300. // if (e.KeyChar != (char)Keys.Back)
  301. // {
  302. // e.Handled = true;
  303. // }
  304. //}
  305. //private void txtITEMCODE_KeyDown(object sender, KeyEventArgs e)
  306. //{
  307. // this.txtITEMCODE.Text = "";
  308. // this.txtITEMCODE.Tag = null;
  309. //}
  310. //private void txtROUTECODE_KeyDown(object sender, KeyEventArgs e)
  311. //{
  312. // this.txtROUTECODE.Text = "";
  313. // this.txtROUTECODE.Tag = null;
  314. //}
  315. }
  316. }