Make_PartDry.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 UAS_MES_NEW.DataOperate;
  9. using UAS_MES_NEW.Entity;
  10. using UAS_MES_NEW.PublicMethod;
  11. namespace UAS_MES_NEW.Make
  12. {
  13. public partial class Make_PartDry : Form
  14. {
  15. AutoSizeFormClass asc = new AutoSizeFormClass();
  16. DataHelper dh;
  17. DataTable dt;
  18. // 工序类型:烘烤页面固定写DRY,写入SB_STEPCODE用于和零件清洗区分
  19. const string StepCode = "DRY";
  20. // 当前批次号:结束烘烤后置空,下一个录入的SN会生成新的批次号
  21. string currentBatch = "";
  22. public Make_PartDry()
  23. {
  24. InitializeComponent();
  25. }
  26. private void Make_PartDry_Load(object sender, EventArgs e)
  27. {
  28. asc.controllInitializeSize(this);
  29. dh = SystemInf.dh;
  30. // 恢复未结束的批次(比如中途退出页面的情况)
  31. object b = dh.getFieldDataByCondition("SINGLEBOARD", "max(SB_BATCHCODE)", "SB_STEPCODE='" + StepCode + "' and SB_ENDTIME is null");
  32. currentBatch = b == null ? "" : b.ToString();
  33. if (currentBatch == "")
  34. {
  35. lblBatchCode.Text = "(暂无,录入SN时自动生成)";
  36. }
  37. else
  38. {
  39. lblBatchCode.Text = currentBatch;
  40. LoadBatchData(currentBatch);
  41. }
  42. SetStatus("就绪,请录入SN");
  43. sncode.Focus();
  44. }
  45. /// <summary>
  46. /// 录入框回车:插入SN到SINGLEBOARD,本批次共用同一个批次号
  47. /// </summary>
  48. private void sncode_KeyDown(object sender, KeyEventArgs e)
  49. {
  50. if (e.KeyCode == Keys.Enter)
  51. {
  52. InsertSN();
  53. e.Handled = true;
  54. e.SuppressKeyPress = true;
  55. }
  56. }
  57. private void InsertSN()
  58. {
  59. string sn = sncode.Text.Trim();
  60. if (sn == "")
  61. {
  62. SetStatus("SN不能为空!");
  63. return;
  64. }
  65. try
  66. {
  67. // 没有进行中的批次时生成新批次号:PD+年月日时分秒
  68. if (currentBatch == "")
  69. {
  70. currentBatch = GenBatchCode();
  71. lblBatchCode.Text = currentBatch;
  72. }
  73. // 同一批次内SN不允许重复录入
  74. dt = (DataTable)dh.ExecuteSql("select SB_ID from SINGLEBOARD where SB_SNCODE='" + sn + "' and SB_BATCHCODE='" + currentBatch + "' and SB_STEPCODE='" + StepCode + "'", "select");
  75. if (dt.Rows.Count > 0)
  76. {
  77. SetStatus("SN【" + sn + "】在本批次已录入,请勿重复!");
  78. sncode.Clear();
  79. sncode.Focus();
  80. return;
  81. }
  82. dh.ExecuteSql("insert into SINGLEBOARD(SB_ID,SB_SNCODE,SB_INDATE,SB_STATUS,SB_STEPCODE,SB_BATCHCODE,SB_INMAN)values(SINGLEBOARD_SEQ.nextval,'" + sn + "',sysdate,'在录入','" + StepCode + "','" + currentBatch + "','" + User.UserName + "')", "insert");
  83. SetStatus("SN【" + sn + "】录入成功,批次号" + currentBatch);
  84. sncode.Clear();
  85. sncode.Focus();
  86. LoadBatchData(currentBatch);
  87. }
  88. catch (Exception ex)
  89. {
  90. SetStatus("录入失败:" + ex.Message);
  91. }
  92. }
  93. /// <summary>
  94. /// 生成批次号:PD+年月日时分秒,长度16在SB_BATCHCODE(20)范围内
  95. /// </summary>
  96. private string GenBatchCode()
  97. {
  98. return "PD" + DateTime.Now.ToString("yyyyMMddHHmmss");
  99. }
  100. /// <summary>
  101. /// 开始烘烤:给当前批次所有未开始的记录写开始时间
  102. /// </summary>
  103. private void btnStart_Click(object sender, EventArgs e)
  104. {
  105. if (currentBatch == "")
  106. {
  107. MessageBox.Show("当前没有进行中的批次,请先录入SN!");
  108. return;
  109. }
  110. try
  111. {
  112. dh.ExecuteSql("update SINGLEBOARD set SB_STARTTIME='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "',SB_STATUS='烘烤中' where SB_BATCHCODE='" + currentBatch + "' and SB_STEPCODE='" + StepCode + "' and SB_STARTTIME is null", "update");
  113. SetStatus("批次【" + currentBatch + "】烘烤已开始");
  114. LoadBatchData(currentBatch);
  115. }
  116. catch (Exception ex)
  117. {
  118. SetStatus("开始烘烤失败:" + ex.Message);
  119. }
  120. }
  121. /// <summary>
  122. /// 结束烘烤:给当前批次所有未结束的记录写结束时间,之后录入的SN生成新批次
  123. /// </summary>
  124. private void btnEnd_Click(object sender, EventArgs e)
  125. {
  126. if (currentBatch == "")
  127. {
  128. MessageBox.Show("当前没有进行中的批次!");
  129. return;
  130. }
  131. try
  132. {
  133. dh.ExecuteSql("update SINGLEBOARD set SB_ENDTIME='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "',SB_STATUS='已完成' where SB_BATCHCODE='" + currentBatch + "' and SB_STEPCODE='" + StepCode + "' and SB_ENDTIME is null", "update");
  134. SetStatus("批次【" + currentBatch + "】已结束,下一批录入SN时生成新批次号");
  135. // 保留显示刚结束批次的数据,批次号置空
  136. LoadBatchData(currentBatch);
  137. currentBatch = "";
  138. lblBatchCode.Text = "(暂无,录入SN时自动生成)";
  139. }
  140. catch (Exception ex)
  141. {
  142. SetStatus("结束烘烤失败:" + ex.Message);
  143. }
  144. }
  145. /// <summary>
  146. /// 按批次号查询
  147. /// </summary>
  148. private void btnQuery_Click(object sender, EventArgs e)
  149. {
  150. string b = txtQueryBatch.Text.Trim();
  151. if (b == "")
  152. {
  153. MessageBox.Show("请输入要查询的批次号!");
  154. return;
  155. }
  156. LoadBatchData(b);
  157. }
  158. /// <summary>
  159. /// 加载指定批次的数据显示在表格里
  160. /// </summary>
  161. private void LoadBatchData(string batch)
  162. {
  163. dt = (DataTable)dh.ExecuteSql("select SB_SNCODE \"SN\",SB_INDATE \"录入时间\",SB_STARTTIME \"开始烘烤时间\",SB_INMAN \"录入人\",SB_STATUS \"状态\" from SINGLEBOARD where SB_BATCHCODE='" + batch + "' and SB_STEPCODE='" + StepCode + "' order by SB_ID", "select");
  164. DGV.DataSource = dt;
  165. }
  166. private void SetStatus(string text)
  167. {
  168. lblStatus.Text = "状态:" + text;
  169. }
  170. private void Make_PartDry_SizeChanged(object sender, EventArgs e)
  171. {
  172. asc.controlAutoSize(this);
  173. }
  174. }
  175. }