| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using UAS_MES_NEW.DataOperate;
- using UAS_MES_NEW.Entity;
- using UAS_MES_NEW.PublicMethod;
- namespace UAS_MES_NEW.Make
- {
- public partial class Make_PartDry : Form
- {
- AutoSizeFormClass asc = new AutoSizeFormClass();
- DataHelper dh;
- DataTable dt;
- // 工序类型:烘烤页面固定写DRY,写入SB_STEPCODE用于和零件清洗区分
- const string StepCode = "DRY";
- // 当前批次号:结束烘烤后置空,下一个录入的SN会生成新的批次号
- string currentBatch = "";
- public Make_PartDry()
- {
- InitializeComponent();
- }
- private void Make_PartDry_Load(object sender, EventArgs e)
- {
- asc.controllInitializeSize(this);
- dh = SystemInf.dh;
- // 恢复未结束的批次(比如中途退出页面的情况)
- object b = dh.getFieldDataByCondition("SINGLEBOARD", "max(SB_BATCHCODE)", "SB_STEPCODE='" + StepCode + "' and SB_ENDTIME is null");
- currentBatch = b == null ? "" : b.ToString();
- if (currentBatch == "")
- {
- lblBatchCode.Text = "(暂无,录入SN时自动生成)";
- }
- else
- {
- lblBatchCode.Text = currentBatch;
- LoadBatchData(currentBatch);
- }
- SetStatus("就绪,请录入SN");
- sncode.Focus();
- }
- /// <summary>
- /// 录入框回车:插入SN到SINGLEBOARD,本批次共用同一个批次号
- /// </summary>
- private void sncode_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- {
- InsertSN();
- e.Handled = true;
- e.SuppressKeyPress = true;
- }
- }
- private void InsertSN()
- {
- string sn = sncode.Text.Trim();
- if (sn == "")
- {
- SetStatus("SN不能为空!");
- return;
- }
- try
- {
- // 没有进行中的批次时生成新批次号:PD+年月日时分秒
- if (currentBatch == "")
- {
- currentBatch = GenBatchCode();
- lblBatchCode.Text = currentBatch;
- }
- // 同一批次内SN不允许重复录入
- dt = (DataTable)dh.ExecuteSql("select SB_ID from SINGLEBOARD where SB_SNCODE='" + sn + "' and SB_BATCHCODE='" + currentBatch + "' and SB_STEPCODE='" + StepCode + "'", "select");
- if (dt.Rows.Count > 0)
- {
- SetStatus("SN【" + sn + "】在本批次已录入,请勿重复!");
- sncode.Clear();
- sncode.Focus();
- return;
- }
- 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");
- SetStatus("SN【" + sn + "】录入成功,批次号" + currentBatch);
- sncode.Clear();
- sncode.Focus();
- LoadBatchData(currentBatch);
- }
- catch (Exception ex)
- {
- SetStatus("录入失败:" + ex.Message);
- }
- }
- /// <summary>
- /// 生成批次号:PD+年月日时分秒,长度16在SB_BATCHCODE(20)范围内
- /// </summary>
- private string GenBatchCode()
- {
- return "PD" + DateTime.Now.ToString("yyyyMMddHHmmss");
- }
- /// <summary>
- /// 开始烘烤:给当前批次所有未开始的记录写开始时间
- /// </summary>
- private void btnStart_Click(object sender, EventArgs e)
- {
- if (currentBatch == "")
- {
- MessageBox.Show("当前没有进行中的批次,请先录入SN!");
- return;
- }
- try
- {
- 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");
- SetStatus("批次【" + currentBatch + "】烘烤已开始");
- LoadBatchData(currentBatch);
- }
- catch (Exception ex)
- {
- SetStatus("开始烘烤失败:" + ex.Message);
- }
- }
- /// <summary>
- /// 结束烘烤:给当前批次所有未结束的记录写结束时间,之后录入的SN生成新批次
- /// </summary>
- private void btnEnd_Click(object sender, EventArgs e)
- {
- if (currentBatch == "")
- {
- MessageBox.Show("当前没有进行中的批次!");
- return;
- }
- try
- {
- 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");
- SetStatus("批次【" + currentBatch + "】已结束,下一批录入SN时生成新批次号");
- // 保留显示刚结束批次的数据,批次号置空
- LoadBatchData(currentBatch);
- currentBatch = "";
- lblBatchCode.Text = "(暂无,录入SN时自动生成)";
- }
- catch (Exception ex)
- {
- SetStatus("结束烘烤失败:" + ex.Message);
- }
- }
- /// <summary>
- /// 按批次号查询
- /// </summary>
- private void btnQuery_Click(object sender, EventArgs e)
- {
- string b = txtQueryBatch.Text.Trim();
- if (b == "")
- {
- MessageBox.Show("请输入要查询的批次号!");
- return;
- }
- LoadBatchData(b);
- }
- /// <summary>
- /// 加载指定批次的数据显示在表格里
- /// </summary>
- private void LoadBatchData(string batch)
- {
- 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");
- DGV.DataSource = dt;
- }
- private void SetStatus(string text)
- {
- lblStatus.Text = "状态:" + text;
- }
- private void Make_PartDry_SizeChanged(object sender, EventArgs e)
- {
- asc.controlAutoSize(this);
- }
- }
- }
|