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

234 lines
8.5 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. using ICSSoft.Base.ReferForm.AppReferForm;
  14. namespace ICSSoft.Frame.APP
  15. {
  16. public partial class FormICSNCRPT : DevExpress.XtraEditors.XtraForm
  17. {
  18. public decimal goodqty;
  19. public decimal ngqty;
  20. public decimal lotqty;
  21. public string status;
  22. public string desc;
  23. public FormICSNCRPT()
  24. {
  25. InitializeComponent();
  26. }
  27. public FormICSNCRPT(string qty)
  28. {
  29. InitializeComponent();
  30. lotqty = Convert.ToDecimal(qty);
  31. txtlotqty.Text = qty;
  32. }
  33. #region 关闭 退出
  34. private void btnClose_Click(object sender, EventArgs e)
  35. {
  36. this.Close();
  37. }
  38. #endregion
  39. #region 移动窗体
  40. private const int WM_NCHITTEST = 0x84;
  41. private const int HTCLIENT = 0x1;
  42. private const int HTCAPTION = 0x2;
  43. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  44. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  45. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  46. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  47. //重写窗体,使窗体可以不通过自带标题栏实现移动
  48. protected override void WndProc(ref Message m)
  49. {
  50. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  51. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  52. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  53. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  54. switch (m.Msg)
  55. {
  56. case WM_NCHITTEST:
  57. base.WndProc(ref m);
  58. if ((int)m.Result == HTCLIENT)
  59. m.Result = (IntPtr)HTCAPTION;
  60. return;
  61. }
  62. //拦截双击标题栏、移动窗体的系统消息
  63. if (m.Msg != 0xA3)
  64. {
  65. base.WndProc(ref m);
  66. }
  67. }
  68. #endregion
  69. #region 新增 修改
  70. private void save_Click(object sender, EventArgs e)
  71. {
  72. try {
  73. if(string.IsNullOrEmpty(txtfpqty.Text))
  74. throw new Exception("请先输入不良数量!");
  75. if (Convert.ToDecimal(txtfpqty.Text) > Convert.ToDecimal(txtlotqty.Text))
  76. throw new Exception("不良数量无法超过追踪单数量,请确认!");
  77. if (string.IsNullOrEmpty(txtItemCode.Text)) {
  78. throw new Exception("判定结果不能为空,请确认!");
  79. }
  80. if (txtItemCode.Text == "报废" && Convert.ToDecimal(txtfpqty.Text) <= 0) {
  81. throw new Exception("报废状态请填写不良数量!");
  82. }
  83. if (txtItemCode.Text == "返修" && Convert.ToDecimal(txtfpqty.Text) <= 0)
  84. {
  85. throw new Exception("返修状态请填写返修数量!");
  86. }
  87. if (txtItemCode.Text == "降级使用" && Convert.ToDecimal(txtfpqty.Text) <= 0)
  88. {
  89. throw new Exception("降级使用状态请填写降级使用数量!");
  90. }
  91. this.goodqty = Convert.ToDecimal(txtgoodqty.Text);
  92. this.ngqty = (Convert.ToDecimal(txtfpqty.Text));
  93. this.status = txtItemCode.Text;
  94. this.desc = txtdesc.Text;
  95. this.DialogResult =DialogResult.OK;
  96. this.Close();
  97. }
  98. catch (Exception ex)
  99. {
  100. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  101. }
  102. //}
  103. }
  104. #endregion
  105. #region 取消
  106. private void can_Click(object sender, EventArgs e)
  107. {
  108. this.DialogResult = DialogResult.Cancel;
  109. this.Close();
  110. }
  111. #endregion
  112. private void txtngqty_KeyPress(object sender, KeyPressEventArgs e)
  113. {
  114. if (txtItemCode.EditValue.ToString() == "") {
  115. e.Handled = true;
  116. return;
  117. }
  118. var textBox1 = (TextBox)sender;
  119. if (e.KeyChar == 0x20 || e.KeyChar == 0x2D || (int)e.KeyChar == 46) e.KeyChar = (char)0; //禁止空格键和负数/小数
  120. if (e.KeyChar > 0x20)
  121. {
  122. try
  123. {
  124. double.Parse(((TextBox)sender).Text + e.KeyChar.ToString());
  125. }
  126. catch
  127. {
  128. e.KeyChar = (char)0; //处理非法字符
  129. }
  130. }
  131. }
  132. private void txtngqty_TextChanged(object sender, EventArgs e)
  133. {
  134. if (String.IsNullOrEmpty(txtfpqty.Text))
  135. return;
  136. txtgoodqty.Text = (lotqty - Convert.ToDecimal(txtfpqty.Text)).ToString();
  137. }
  138. private void FormICSNCRPT_Load(object sender, EventArgs e)
  139. {
  140. #region 判定结果
  141. string sql = @"SELECT '返修' as 判定结果
  142. union all
  143. SELECT '使' as
  144. union all
  145. SELECT '' as
  146. union all
  147. SELECT '' as ";
  148. sql = string.Format(sql, AppConfig.WorkPointCode);
  149. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql).Tables[0];
  150. txtItemCode.Properties.ValueMember = "判定结果";
  151. txtItemCode.Properties.DisplayMember = "判定结果";
  152. txtItemCode.Properties.DataSource = dt;
  153. txtItemCode.Properties.NullText = "";//空时的值
  154. txtItemCode.Properties.ImmediatePopup = true;//输入值是否马上弹出窗体
  155. txtItemCode.Properties.ValidateOnEnterKey = true;//回车确认
  156. txtItemCode.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;//要使用户可以输入,这里须设为Standard
  157. txtItemCode.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True; //可用Ctrl + Delete清空选择內容
  158. //自适应宽度
  159. txtItemCode.Properties.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
  160. #endregion
  161. }
  162. private void txtItemCode_EditValueChanged(object sender, EventArgs e)
  163. {
  164. switch (txtItemCode.EditValue.ToString()) {
  165. case "返修":
  166. {
  167. txtfpqty.ReadOnly = false;
  168. labelFP.Text = "返修数量:";
  169. labelFP.Location = new Point(label3.Location.X, labelFP.Location.Y);
  170. break;
  171. }
  172. case "报废":
  173. {
  174. txtfpqty.ReadOnly = false;
  175. labelFP.Text = "不良数量:";
  176. labelFP.Location = new Point(label3.Location.X, labelFP.Location.Y);
  177. break;
  178. }
  179. case "合格":
  180. {
  181. txtfpqty.ReadOnly =true;
  182. labelFP.Text = "不良数量:";
  183. labelFP.Location = new Point(label3.Location.X, labelFP.Location.Y);
  184. txtfpqty.Text ="0";
  185. break;
  186. }
  187. case "降级使用":
  188. {
  189. txtfpqty.ReadOnly = false;
  190. labelFP.Text = "降级使用数量:";
  191. labelFP.Location = new Point(label3.Location.X-23, labelFP.Location.Y);
  192. txtfpqty.Text = "0";
  193. break;
  194. }
  195. }
  196. }
  197. }
  198. }