| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275 |
- using DevComponents.DotNetBar.Controls;
- using NPOI.SS.Formula.Eval;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Data.SqlClient;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- 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_HandFeedQualityConfirm : Form
- {
- public Make_HandFeedQualityConfirm()
- {
- InitializeComponent();
- }
- StringBuilder SQL = new StringBuilder();
- DataTable dt, data;
- DataHelper dh;
- private void Make_HandFeedQualityConfirm_Load(object sender, EventArgs e)
- {
- dh = SystemInf.dh;
- dgv.AutoGenerateColumns = false;
- data = new DataTable();
- data.Columns.Add("isScan", typeof(bool));
- data.Columns.Add("rn", typeof(int));
- data.Columns.Add("ms_sncode", typeof(string));
- data.Columns.Add("line_name", typeof(string));
- data.Columns.Add("side", typeof(string));
- data.Columns.Add("position", typeof(string));
- data.Columns.Add("reel_position", typeof(string));
- data.Columns.Add("part_no", typeof(string));
- data.Columns.Add("reel_qty", typeof(string));
- data.Columns.Add("reelremark", typeof(string));
- data.Columns.Add("reelnum", typeof(string));
- data.Columns.Add("qa_emp", typeof(string));
- data.Columns.Add("qa_date", typeof(string));
- dgv.DataSource = data;
- submit.Enabled = false;
- LockMakeCode.GetMakeCodeCtl(ma_code);
- ma_code.SetLockCheckBox(LockMakeCode);
- ma_code.TableName = "make left join product on ma_prodcode=pr_code";
- ma_code.SelectField = "ma_code # 工单号,ma_prodcode # 产品编号,ma_qty # 工单数量,pr_spec # 产品规格,ma_softversion # 软件版本,ma_salecode # 销售单号,pr_sendchecktype # 产品送检方式,pr_pcbacount # 拼版数";
- ma_code.FormName = Name;
- ma_code.SetValueField = new string[] { "ma_code", "ma_prodcode", "ma_qty", "pr_spec", "ma_softversion", "ma_salecode", "nvl(pr_sendchecktype,'LineCode')pr_sendchecktype", "pr_pcbacount" };
- ma_code.Condition = "ma_statuscode='STARTED'";
- ma_code.Focus();
- }
- private void ma_code_DbChange(object sender, EventArgs e)
- {
- BaseUtil.SetFormValue(this.Controls, ma_code.ReturnData);
- LoadHandReel();
- }
- private void LoadHandReel()
- {
- string makeCode = ma_code.Text.Trim();
- if (string.IsNullOrEmpty(makeCode))
- {
- MessageBox.Show("请输入工单", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- ma_code.Focus();
- return;
- }
- string makeSql = makeCode.Replace("'", "''");
- SQL.Clear();
- SQL.Append($@"SELECT m.ms_sncode, h.line_name, h.side,
- h.position, h.reel_position, h.part_no, h.reel_qty, h.reelremark, h.reelnum,
- h.qa_emp, to_char(h.qa_date,'yyyy-mm-dd hh24:mi:ss') qa_date
- FROM makeserial m, smt_handreel_log h
- WHERE h.serial_number = m.ms_sncode AND m.ms_makecode = '{makeSql}'
- ORDER BY m.ms_sncode, h.handreel_id");
- dt = (DataTable)dh.ExecuteSql(SQL.ToString(), "select");
- data.Rows.Clear();
- if (dt.Rows.Count == 0)
- {
- submit.Enabled = false;
- MessageBox.Show("该工单没有手补料序列号", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- ma_code.Focus();
- return;
- }
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- DataRow src = dt.Rows[i];
- data.Rows.Add(false, i + 1,
- src["ms_sncode"].ToString(),
- src["line_name"].ToString(),
- src["side"].ToString(),
- src["position"].ToString(),
- src["reel_position"].ToString(),
- src["part_no"].ToString(),
- src["reel_qty"].ToString(),
- src["reelremark"].ToString(),
- src["reelnum"].ToString(),
- src["qa_emp"].ToString(),
- src["qa_date"].ToString());
- }
- submit.Enabled = true;
- snVal.Text = "";
- snVal.Focus();
- }
- private void snVal_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode != Keys.Enter) return;
- e.Handled = true;
- e.SuppressKeyPress = true;
- string scanSn = snVal.Text.Replace(";", ";").Trim();
- snVal.Text = scanSn;
- if (string.IsNullOrEmpty(scanSn))
- {
- MessageBox.Show("请扫描序列号", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- snVal.Focus();
- return;
- }
- if (data.Rows.Count == 0)
- {
- MessageBox.Show("请先输入工单", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- ma_code.Focus();
- return;
- }
- bool found = false;
- bool already = true;
- int firstRow = -1;
- for (int i = 0; i < data.Rows.Count; i++)
- {
- if (!string.Equals(data.Rows[i]["ms_sncode"].ToString(), scanSn, StringComparison.OrdinalIgnoreCase))
- continue;
- found = true;
- if (firstRow < 0)
- firstRow = i;
- if (data.Rows[i]["isScan"] == DBNull.Value || !Convert.ToBoolean(data.Rows[i]["isScan"]))
- {
- data.Rows[i]["isScan"] = true;
- already = false;
- }
- dgv.Rows[i].DefaultCellStyle.BackColor = Color.Green;
- dgv.Rows[i].DefaultCellStyle.ForeColor = Color.Black;
- }
- if (!found)
- {
- UpdateSN("C");
- MessageBox.Show("该序列号不在当前工单手补料记录中", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- else
- {
- UpdateSN("L", scanSn);
- if (already)
- MessageBox.Show("序列号已标记", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- else if (firstRow >= 0)
- dgv.FirstDisplayedScrollingRowIndex = firstRow;
- }
- snVal.Focus();
- snVal.SelectAll();
- }
- private void submit_Click(object sender, EventArgs e)
- {
- if (data.Rows.Count == 0)
- {
- MessageBox.Show("请先输入工单", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- ma_code.Focus();
- return;
- }
- List<string> snList = new List<string>();
- foreach (DataRow row in data.Rows)
- {
- bool scanned = row["isScan"] != DBNull.Value && Convert.ToBoolean(row["isScan"]);
- string sn = row["ms_sncode"].ToString();
- if (scanned && !snList.Contains(sn))
- snList.Add(sn);
- }
- if (snList.Count == 0)
- {
- MessageBox.Show("请先扫描序列号", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- snVal.Focus();
- return;
- }
- string emp = User.UserName ?? "";
- if (emp.Length > 20)
- emp = emp.Substring(0, 20);
- string empSql = emp.Replace("'", "''");
- string makeSql = ma_code.Text.Trim().Replace("'", "''");
- string confirmTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
- try
- {
- foreach (string sn in snList)
- {
- string snSql = sn.Replace("'", "''");
- SQL.Clear();
- SQL.Append($@"UPDATE smt_handreel_log SET qa_emp = '{empSql}', qa_date = sysdate
- WHERE serial_number = '{snSql}'
- AND serial_number IN (SELECT ms_sncode FROM makeserial WHERE ms_makecode = '{makeSql}' AND ms_sncode = '{snSql}')");
- dh.ExecuteSql(SQL.ToString(), "update");
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show("品质确认失败:" + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- foreach (DataRow row in data.Rows)
- {
- if (row["isScan"] == DBNull.Value || !Convert.ToBoolean(row["isScan"]))
- continue;
- row["qa_emp"] = emp;
- row["qa_date"] = confirmTime;
- }
- MessageBox.Show($"已确认{snList.Count}个序列号:{string.Join("、", snList)}", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- snVal.Focus();
- snVal.SelectAll();
- snVal.Text = "";
- }
- private void UpdateSN(string type, string sn = "")
- {
- if (type == "C")
- {
- serialNumber.Text = "";
- workOrder.Text = "";
- productCode.Text = "";
- productName.Text = "";
- }
- else if (type == "L")
- {
- string snSql = sn.Replace("'", "''");
- SQL.Clear();
- SQL.Append($@"SELECT ms_sncode,ma_code,pr_code,pr_spec FROM makeserial,make,product
- WHERE ms_sncode = '{snSql}' AND ms_makecode = ma_code AND ms_prodcode = pr_code");
- dt = (DataTable)dh.ExecuteSql(SQL.ToString(), "select");
- if (dt.Rows.Count > 0)
- {
- serialNumber.Text = dt.Rows[0]["ms_sncode"].ToString();
- workOrder.Text = dt.Rows[0]["ma_code"].ToString();
- productCode.Text = dt.Rows[0]["pr_code"].ToString();
- productName.Text = dt.Rows[0]["pr_spec"].ToString();
- }
- else
- {
- UpdateSN("C");
- }
- }
- }
- }
- }
|