| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399 |
- 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;
- bool qaSwitching;
- 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));
- data.Columns.Add("qa_type", typeof(string));
- data.Columns.Add("qa_result", typeof(string));
- data.Columns.Add("update_time", typeof(string));
- data.Columns.Add("handreel_id", 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;
- }
- 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, h.qa_type,
- to_char(h.update_time,'yyyy-mm-dd hh24:mi:ss') update_time, h.handreel_id
- FROM makeserial m, smt_handreel_log h
- WHERE h.serial_number = m.ms_sncode AND m.ms_makecode = '{makeCode}'
- ORDER BY m.ms_sncode, h.handreel_id");*/
- 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,
- h.qa_type, to_char(h.update_time, 'yyyy-mm-dd hh24:mi:ss') update_time, h.handreel_id
- FROM makeserial m, smt_handreel_log h WHERE h.serial_number = m.ms_sncode
- AND m.ms_makecode = '{makeCode}' AND h.update_time IN(SELECT MAX(t2.update_time) update_time
- FROM makeserial t1, smt_handreel_log t2 WHERE t2.serial_number = t1.ms_sncode
- AND t1.ms_makecode = '{makeCode}' GROUP BY t2.serial_number)
- 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];
- string qaType = NormalizeQaType(src["qa_type"]);
- 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(),
- qaType,
- QaTypeText(qaType),
- src["update_time"].ToString(),
- src["handreel_id"].ToString());
- }
- ApplyLoadedStyle();
- 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;
- }
- string qaType = SelectedQaType();
- if (qaType == "")
- {
- MessageBox.Show("请先选择合格或不合格", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- 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;
- bool scanned = data.Rows[i]["isScan"] != DBNull.Value && Convert.ToBoolean(data.Rows[i]["isScan"]);
- if (!scanned || data.Rows[i]["qa_type"].ToString() != qaType)
- already = false;
- MarkScanRow(i, qaType);
- }
- 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<DataRow> scanRows = new List<DataRow>();
- List<string> missing = new List<string>();
- foreach (DataRow row in data.Rows)
- {
- bool scanned = row["isScan"] != DBNull.Value && Convert.ToBoolean(row["isScan"]);
- if (!scanned)
- continue;
- string sn = row["ms_sncode"].ToString();
- string position = row["position"].ToString();
- string qaType = NormalizeQaType(row["qa_type"]);
- if (qaType == "")
- {
- missing.Add("序列号" + sn + "当前站位" + position);
- continue;
- }
- scanRows.Add(row);
- }
- if (missing.Count > 0)
- {
- MessageBox.Show(string.Join("、", missing) + "未选择合格或不合格", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- if (scanRows.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 confirmTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
- try
- {
- foreach (DataRow row in scanRows)
- {
- string idSql = row["handreel_id"].ToString();
- string qaType = NormalizeQaType(row["qa_type"]);
- SQL.Clear();
- SQL.Append($@"UPDATE smt_handreel_log SET qa_emp = '{emp}', qa_date = sysdate, qa_type = '{qaType}'
- WHERE handreel_id = '{idSql}'");
- dh.ExecuteSql(SQL.ToString(), "update");
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show("品质确认失败:" + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- List<string> snList = new List<string>();
- foreach (DataRow row in scanRows)
- {
- row["qa_emp"] = emp;
- row["qa_date"] = confirmTime;
- string sn = row["ms_sncode"].ToString();
- if (!snList.Contains(sn))
- snList.Add(sn);
- }
- MessageBox.Show($"序列号:{string.Join("、", snList)},数量{snList.Count},品质确认完成", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- snVal.Focus();
- snVal.SelectAll();
- snVal.Text = "";
- }
- private void qaPass_CheckedChanged(object sender, EventArgs e)
- {
- if (qaSwitching || !qaPass.Checked)
- return;
- qaSwitching = true;
- qaFail.Checked = false;
- qaSwitching = false;
- }
- private void qaFail_CheckedChanged(object sender, EventArgs e)
- {
- if (qaSwitching || !qaFail.Checked)
- return;
- qaSwitching = true;
- qaPass.Checked = false;
- qaSwitching = false;
- }
- private string SelectedQaType()
- {
- if (qaPass.Checked)
- return "1";
- if (qaFail.Checked)
- return "0";
- return "";
- }
- private string NormalizeQaType(object value)
- {
- string text = value == null || value == DBNull.Value ? "" : value.ToString().Trim();
- decimal number;
- if (decimal.TryParse(text, out number))
- {
- if (number == 1)
- return "1";
- if (number == 0 && text != "")
- return "0";
- }
- return "";
- }
- private string QaTypeText(string qaType)
- {
- if (qaType == "1")
- return "合格";
- if (qaType == "0")
- return "不合格";
- return "";
- }
- private void MarkScanRow(int rowIndex, string qaType)
- {
- data.Rows[rowIndex]["isScan"] = true;
- data.Rows[rowIndex]["qa_type"] = qaType;
- data.Rows[rowIndex]["qa_result"] = QaTypeText(qaType);
- PaintRow(rowIndex, qaType);
- }
- private void ApplyLoadedStyle()
- {
- int count = Math.Min(data.Rows.Count, dgv.Rows.Count);
- for (int i = 0; i < count; i++)
- PaintRow(i, NormalizeQaType(data.Rows[i]["qa_type"]));
- }
- private void PaintRow(int rowIndex, string qaType)
- {
- if (qaType == "1")
- {
- dgv.Rows[rowIndex].DefaultCellStyle.BackColor = Color.Green;
- dgv.Rows[rowIndex].DefaultCellStyle.ForeColor = Color.Black;
- }
- else if (qaType == "0")
- {
- dgv.Rows[rowIndex].DefaultCellStyle.BackColor = Color.DarkRed;
- dgv.Rows[rowIndex].DefaultCellStyle.ForeColor = Color.White;
- }
- else
- {
- dgv.Rows[rowIndex].DefaultCellStyle.BackColor = dgv.DefaultCellStyle.BackColor;
- dgv.Rows[rowIndex].DefaultCellStyle.ForeColor = dgv.DefaultCellStyle.ForeColor;
- }
- }
- private void UpdateSN(string type, string sn = "")
- {
- if (type == "C")
- {
- serialNumber.Text = "";
- workOrder.Text = "";
- productCode.Text = "";
- productName.Text = "";
- }
- else if (type == "L")
- {
- SQL.Clear();
- SQL.Append($@"SELECT ms_sncode,ma_code,pr_code,pr_spec FROM makeserial,make,product
- WHERE ms_sncode = '{sn}' 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");
- }
- }
- }
- }
- }
|