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

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