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

233 lines
9.7 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.Data.Entity;
  10. using ICSSoft.Frame.Data.BLL;
  11. using ICSSoft.Base.Config.AppConfig;
  12. using ICSSoft.Base.Config.DBHelper;
  13. namespace ICSSoft.Frame.APP
  14. {
  15. public partial class FormICSEqpWithLocationAdd : DevExpress.XtraEditors.XtraForm
  16. {
  17. String guid = "";
  18. IcsEqpWithLocation entity = new IcsEqpWithLocation();
  19. public FormICSEqpWithLocationAdd()
  20. {
  21. InitializeComponent();
  22. init();
  23. }
  24. public FormICSEqpWithLocationAdd(string id)
  25. {
  26. InitializeComponent();
  27. guid = id;
  28. init();
  29. }
  30. #region 关闭 退出
  31. private void btnClose_Click(object sender, EventArgs e)
  32. {
  33. this.Close();
  34. }
  35. #endregion
  36. #region 移动窗体
  37. private const int WM_NCHITTEST = 0x84;
  38. private const int HTCLIENT = 0x1;
  39. private const int HTCAPTION = 0x2;
  40. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  41. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  42. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  43. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  44. //重写窗体,使窗体可以不通过自带标题栏实现移动
  45. protected override void WndProc(ref Message m)
  46. {
  47. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  48. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  49. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  50. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  51. switch (m.Msg)
  52. {
  53. case WM_NCHITTEST:
  54. base.WndProc(ref m);
  55. if ((int)m.Result == HTCLIENT)
  56. m.Result = (IntPtr)HTCAPTION;
  57. return;
  58. }
  59. //拦截双击标题栏、移动窗体的系统消息
  60. if (m.Msg != 0xA3)
  61. {
  62. base.WndProc(ref m);
  63. }
  64. }
  65. #endregion
  66. //#region 存货编码按钮
  67. //private void txtItemCode_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
  68. //{
  69. // ButtonEdit btn = (ButtonEdit)sender;
  70. // string sql = "select distinct ItemCode as [存货编码], ItemName as [存货名称] from ICSItemLot with(nolock) WHERE 1=1";
  71. // //object obj = AppConfig.InvokeWebservice(AppConfig.BaseServiceUri, "WebBaseService", "BaseService", "GetHuaRongErpConnectString", new object[] { });
  72. // //if (obj == null)
  73. // //{
  74. // // ICSBaseSimpleCode.AppshowMessageBox(1, "ERP数据库连接取得失败!");
  75. // //}
  76. // DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql).Tables[0];
  77. // FormDataRefer reForm = new FormDataRefer();
  78. // reForm.FormTitle = "产品信息";
  79. // DataTable menuData = data;
  80. // reForm.DataSource = menuData;
  81. // reForm.MSelectFlag = false;
  82. // reForm.RowIndexWidth = 35;
  83. // reForm.HideCols.Add("ID");
  84. // reForm.FormWidth = 500;
  85. // reForm.FormHeight = 500;
  86. // reForm.FilterKey = btn.Text; //grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, grvDetail.FocusedColumn).ToString().Trim();
  87. // if (reForm.ShowDialog() == DialogResult.OK)
  88. // {
  89. // DataTable retData = reForm.ReturnData;
  90. // foreach (DataRow dr in retData.Rows)
  91. // {
  92. // txtItemCode.Text = dr["存货编码"].ToString();
  93. // txtItemName.Text = dr["存货名称"].ToString();
  94. // }
  95. // }
  96. //}
  97. //#endregion
  98. #region 新增 修改
  99. private void save_Click(object sender, EventArgs e)
  100. {
  101. if (TxtEqpcode.Text.Trim() == ""||TxtEqpName.Text.Trim()=="")
  102. {
  103. ICSBaseSimpleCode.AppshowMessageBox("设备编码不能为空!");
  104. return;
  105. }
  106. if (TxtLocationCode.Text.Trim() == ""|| TxtLocationName.Text.Trim() == "")
  107. {
  108. ICSBaseSimpleCode.AppshowMessageBox("点位编码不能为空!");
  109. return;
  110. }
  111. entity.ID = guid;
  112. entity.EqpCode = TxtEqpcode.Text.Trim();
  113. entity.LocationCode = TxtLocationCode.Text.Trim();
  114. entity.Muser = AppConfig.UserCode;
  115. entity.Mtime = Convert.ToDateTime(AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss").ToString());
  116. entity.Workpoint = AppConfig.WorkPointCode;
  117. entity.MuserName = AppConfig.UserName;
  118. List<IcsEqpWithLocation> list = new List<IcsEqpWithLocation>();
  119. list.Add(entity);
  120. try
  121. {
  122. ICSEqpWithLocationBLL.AddList(list, AppConfig.AppConnectString);
  123. this.Close();
  124. ICSBaseSimpleCode.AppshowMessageBox("操作成功");
  125. }
  126. catch (Exception ex)
  127. {
  128. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  129. }
  130. }
  131. #endregion
  132. #region 取消
  133. private void can_Click(object sender, EventArgs e)
  134. {
  135. this.Close();
  136. }
  137. #endregion
  138. #region 页面加载
  139. private void FormICSItenLotAdd_Load(object sender, EventArgs e)
  140. {
  141. if (guid != "")
  142. {
  143. labelControl1.Text = "修改";
  144. entity = ICSEqpWithLocationBLL.searchInfoByID(guid, AppConfig.AppConnectString);
  145. TxtEqpcode.EditValue = entity.EqpCode;
  146. TxtLocationCode.EditValue = entity.LocationCode;
  147. }
  148. else
  149. {
  150. labelControl1.Text = "新增";
  151. }
  152. }
  153. #endregion
  154. private void gluItemCode_EditValueChanged(object sender, EventArgs e)
  155. {
  156. var o = TxtEqpcode.Properties.GetRowByKeyValue(TxtEqpcode.EditValue);
  157. if (o is DataRowView)
  158. {
  159. DataRowView RowView = o as DataRowView;
  160. TxtEqpName.Text = RowView.Row["设备名称"].ToString();
  161. }
  162. }
  163. private void txtOPCODE_EditValueChanged(object sender, EventArgs e)
  164. {
  165. var o = TxtLocationCode.Properties.GetRowByKeyValue(TxtLocationCode.EditValue);
  166. if (o is DataRowView)
  167. {
  168. DataRowView RowView = o as DataRowView;
  169. TxtLocationName.Text = RowView.Row["点位名称"].ToString();
  170. }
  171. }
  172. #region 初始化查询条件
  173. private void init()
  174. {
  175. #region 设备
  176. string sql = "SELECT DISTINCT EqpCode AS [设备编码],EqpName AS [设备名称] FROM ICSEquipment ORDER BY EqpCode";
  177. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql).Tables[0];
  178. TxtEqpcode.Properties.ValueMember = "设备编码";
  179. TxtEqpcode.Properties.DisplayMember = "设备编码";
  180. TxtEqpcode.Properties.DataSource = dt;
  181. TxtEqpcode.Properties.NullText = "";//空时的值
  182. TxtEqpcode.Properties.ImmediatePopup = true;//输入值是否马上弹出窗体
  183. TxtEqpcode.Properties.ValidateOnEnterKey = true;//回车确认
  184. TxtEqpcode.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;//要使用户可以输入,这里须设为Standard
  185. TxtEqpcode.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True; //可用Ctrl + Delete清空选择內容
  186. //自适应宽度
  187. TxtEqpcode.Properties.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
  188. #endregion
  189. #region 点位
  190. string sql2 = @"select LocationCode as 点位编码,LocationName as 点位名称 from IcsAGVLocation ORDER BY LocationCode";
  191. DataTable dt2 = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql2).Tables[0];
  192. TxtLocationCode.Properties.ValueMember = "点位编码";
  193. TxtLocationCode.Properties.DisplayMember = "点位编码";
  194. TxtLocationCode.Properties.DataSource = dt2;
  195. TxtLocationCode.Properties.NullText = "";//空时的值
  196. TxtLocationCode.Properties.ImmediatePopup = true;//输入值是否马上弹出窗体
  197. TxtLocationCode.Properties.ValidateOnEnterKey = true;//回车确认
  198. TxtLocationCode.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;//要使用户可以输入,这里须设为Standard
  199. TxtLocationCode.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True; //可用Ctrl + Delete清空选择內容
  200. //自适应宽度
  201. TxtLocationCode.Properties.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
  202. #endregion
  203. }
  204. #endregion
  205. }
  206. }