华恒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.

281 lines
10 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.Language.Tool;
  10. using ICSSoft.Base.UserControl.MessageControl;
  11. using System.Data.SqlClient;
  12. using ICSSoft.Base.Config.AppConfig;
  13. using ICSSoft.Base.Report.Filter;
  14. using ICSSoft.Base.Config.DBHelper;
  15. using ICSSoft.Base.UserControl.FormControl;
  16. using ICSSoft.Base.ReferForm.AppReferForm;
  17. using ICSSoft.Frame.Data.BLL;
  18. using ICSSoft.Frame.Data.Entity;
  19. namespace ICSSoft.Frame.APP
  20. {
  21. public partial class FormICSEQPMaterialINVAdd : DevExpress.XtraEditors.XtraForm
  22. {
  23. FormICSEQPMaterialINVUIModel equipmentUIModel;
  24. int Flag;
  25. string eqpid;
  26. int museqty=0;
  27. int mscrapqty=0;
  28. /// <summary>
  29. /// add new
  30. /// </summary>
  31. public FormICSEQPMaterialINVAdd()
  32. {
  33. InitializeComponent();
  34. chargeFormState("Add");
  35. Flag = 0;
  36. }
  37. /// <summary>
  38. /// edit
  39. /// </summary>
  40. /// <param name="cPersonCode"></param>
  41. public FormICSEQPMaterialINVAdd(string id)
  42. {
  43. InitializeComponent();
  44. chargeFormState("Edit");
  45. SearchShiftInfo(id);
  46. Flag = 1;
  47. }
  48. private void chargeFormState(string state)
  49. {
  50. switch (state)
  51. {
  52. case "Add":
  53. //txtModel.Properties.ReadOnly = false;
  54. //txtEQPStatus.Properties.ReadOnly = false;
  55. txtMUSERName.Text = AppConfig.UserName;
  56. txtMTIME.Text = AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss").ToString();
  57. txtMUSERName.Properties.ReadOnly = true;
  58. txtMTIME.Properties.ReadOnly = true;
  59. break;
  60. case "Edit":
  61. //txtEQPCode.Properties.ReadOnly = true;
  62. //txtType.Properties.ReadOnly = true;
  63. txtMINVQty.Properties.ReadOnly = true;
  64. txtMUSERName.Properties.ReadOnly = true;
  65. txtMTIME.Properties.ReadOnly = true;
  66. break;
  67. }
  68. }
  69. #region 移动窗体
  70. private const int WM_NCHITTEST = 0x84;
  71. private const int HTCLIENT = 0x1;
  72. private const int HTCAPTION = 0x2;
  73. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  74. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  75. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  76. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  77. //重写窗体,使窗体可以不通过自带标题栏实现移动
  78. protected override void WndProc(ref Message m)
  79. {
  80. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  81. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  82. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  83. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  84. switch (m.Msg)
  85. {
  86. case WM_NCHITTEST:
  87. base.WndProc(ref m);
  88. if ((int)m.Result == HTCLIENT)
  89. m.Result = (IntPtr)HTCAPTION;
  90. return;
  91. }
  92. //拦截双击标题栏、移动窗体的系统消息
  93. if (m.Msg != 0xA3)
  94. {
  95. base.WndProc(ref m);
  96. }
  97. }
  98. #endregion
  99. private void SearchShiftInfo(string id)
  100. {
  101. equipmentUIModel = ICSEQPMaterialINVBLL.SearchEquipmentInfoByCode(id, AppConfig.AppConnectString);
  102. equipmentUIModel.inventory = new FormICSINVENTORYUIModel();
  103. txtMCODE.Text = equipmentUIModel.inventory.INVCODE;
  104. txtMtype.Text = equipmentUIModel.MType;
  105. txtMINVQty.Text = equipmentUIModel.MINVQty.ToString();
  106. museqty = equipmentUIModel.MUSEQty;
  107. mscrapqty = equipmentUIModel.MScrapQty;
  108. txtMUSERName.Text = AppConfig.UserName;
  109. txtMTIME.Text = AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss").ToString();
  110. }
  111. #region 关闭
  112. private void btnCancle_Click(object sender, EventArgs e)
  113. {
  114. this.Close();
  115. this.DialogResult = DialogResult.Cancel;
  116. }
  117. private void btnClose_Click(object sender, EventArgs e)
  118. {
  119. this.Close();
  120. this.DialogResult = DialogResult.Cancel;
  121. }
  122. #endregion
  123. #region 设备类型按钮
  124. private void txtEType_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
  125. {
  126. ButtonEdit btn = (ButtonEdit)sender;
  127. string sql = "select distinct EnumValue as [类型编码],EnumText as [设备类型] from dbo.Sys_EnumValues with(nolock) WHERE EnumKey='001' and 1=1";
  128. //object obj = AppConfig.InvokeWebservice(AppConfig.BaseServiceUri, "WebBaseService", "BaseService", "GetHuaRongErpConnectString", new object[] { });
  129. //if (obj == null)
  130. //{
  131. // ICSBaseSimpleCode.AppshowMessageBox(1, "ERP数据库连接取得失败!");
  132. //}
  133. DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql).Tables[0];
  134. FormDataRefer reForm = new FormDataRefer();
  135. reForm.FormTitle = "设备类型信息";
  136. DataTable menuData = data;
  137. reForm.DataSource = menuData;
  138. reForm.MSelectFlag = false;
  139. reForm.RowIndexWidth = 35;
  140. reForm.HideCols.Add("ID");
  141. reForm.FormWidth = 500;
  142. reForm.FormHeight = 500;
  143. //reForm.FilterKey = btn.Text;
  144. //grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, grvDetail.FocusedColumn).ToString().Trim();
  145. if (reForm.ShowDialog() == DialogResult.OK)
  146. {
  147. DataTable retData = reForm.ReturnData;
  148. foreach (DataRow dr in retData.Rows)
  149. {
  150. txtMCODE.Text = dr["设备类型"].ToString();
  151. //txtItemName.Text = dr["存货名称"].ToString();
  152. }
  153. }
  154. }
  155. #endregion
  156. #region 新增 修改
  157. private void btnOK_Click(object sender, EventArgs e)
  158. {
  159. if (txtMCODE.Text.Trim() == "")
  160. {
  161. ICSBaseSimpleCode.AppshowMessageBox("备件料号不能为空!");
  162. return;
  163. }
  164. if (txtMtype.Text.Trim() == "")
  165. {
  166. ICSBaseSimpleCode.AppshowMessageBox("备件类型不能为空!");
  167. return;
  168. }
  169. FormICSEQPMaterialINVUIModel equipmentInfo = new FormICSEQPMaterialINVUIModel();
  170. equipmentInfo.MCODE = txtMCODE.Text.Trim();
  171. equipmentInfo.MType = txtMtype.Text.Trim();
  172. equipmentInfo.MINVQty =Convert.ToInt32(txtMINVQty.Text.Equals("") ? "0" : txtMINVQty.Text);
  173. equipmentInfo.MUSEQty = museqty;
  174. equipmentInfo.MScrapQty = mscrapqty;
  175. equipmentInfo.MUSER = AppConfig.UserId;
  176. equipmentInfo.MUSERName = AppConfig.UserName;
  177. equipmentInfo.MTIME = System.DateTime.Parse(txtMTIME.Text);
  178. equipmentInfo.WorkPoint = AppConfig.WorkPointCode;
  179. equipmentInfo.EATTRIBUTE1 = null;
  180. try
  181. {
  182. ICSEQPMaterialINVBLL.Add(equipmentInfo, AppConfig.AppConnectString);
  183. this.Close();
  184. ICSBaseSimpleCode.AppshowMessageBox("操作成功");
  185. }
  186. catch (Exception ex)
  187. {
  188. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  189. }
  190. }
  191. #endregion
  192. #region 备件料号按钮
  193. private void txtMCODE_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
  194. {
  195. ButtonEdit btn = (ButtonEdit)sender;
  196. string sql = "select distinct ID as [备件ID],INVCODE as [备件料号],INVNAME as [备件名称] from dbo.ICSINVENTORY with(nolock) WHERE 1=1";
  197. //object obj = AppConfig.InvokeWebservice(AppConfig.BaseServiceUri, "WebBaseService", "BaseService", "GetHuaRongErpConnectString", new object[] { });
  198. //if (obj == null)
  199. //{
  200. // ICSBaseSimpleCode.AppshowMessageBox(1, "ERP数据库连接取得失败!");
  201. //}
  202. DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql).Tables[0];
  203. FormDataRefer reForm = new FormDataRefer();
  204. reForm.FormTitle = "备件信息";
  205. DataTable menuData = data;
  206. reForm.DataSource = menuData;
  207. reForm.MSelectFlag = false;
  208. reForm.RowIndexWidth = 35;
  209. reForm.HideCols.Add("备件ID");
  210. reForm.FormWidth = 500;
  211. reForm.FormHeight = 500;
  212. //reForm.FilterKey = btn.Text;
  213. //grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, grvDetail.FocusedColumn).ToString().Trim();
  214. if (reForm.ShowDialog() == DialogResult.OK)
  215. {
  216. DataTable retData = reForm.ReturnData;
  217. foreach (DataRow dr in retData.Rows)
  218. {
  219. txtMCODE.Text = dr["备件料号"].ToString();
  220. //itemid = dr["备件ID"].ToString();
  221. }
  222. }
  223. }
  224. #endregion
  225. private void txtMtype_SelectedIndexChanged(object sender, EventArgs e)
  226. {
  227. if (txtMtype.SelectedItem == "A")
  228. {
  229. txtMINVQty.Properties.ReadOnly = true;
  230. }
  231. if (txtMtype.SelectedItem == "B" || txtMtype.SelectedItem == "C")
  232. {
  233. txtMINVQty.Properties.ReadOnly = false;
  234. }
  235. }
  236. }
  237. }