| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395 |
- 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_RepairQualityConfirm : Form
- {
- public Make_RepairQualityConfirm()
- {
- InitializeComponent();
- }
- StringBuilder SQL = new StringBuilder();
- DataTable dt, data;
- DataHelper dh;
- bool qaSwitching;
- private void Make_RepairQualityConfirm_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("mb_id", typeof(string));
- data.Columns.Add("mb_makecode", typeof(string));
- data.Columns.Add("mb_sncode", typeof(string));
- data.Columns.Add("mb_indate", typeof(string));
- data.Columns.Add("mb_stepcode", typeof(string));
- data.Columns.Add("mb_badcode", typeof(string));
- data.Columns.Add("mb_status", typeof(string));
- data.Columns.Add("mb_bgcode", typeof(string));
- data.Columns.Add("mb_bgname", typeof(string));
- data.Columns.Add("mb_badname", typeof(string));
- data.Columns.Add("mb_linecode", typeof(string));
- data.Columns.Add("qa_type", typeof(string));
- data.Columns.Add("mb_qa_confirm", 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);
- LoadMakeBad();
- }
- private void LoadMakeBad()
- {
- 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 mb_id, mb_makecode, mb_sncode,
- to_char(mb_indate, 'yyyy-mm-dd hh24:mi:ss') mb_indate, mb_stepcode, mb_badcode,
- mb_status, mb_bgcode, mb_bgname, mb_badname, mb_linecode, mb_qa_confirm
- FROM makebad WHERE mb_makecode = '{makeCode}'
- ORDER BY mb_sncode, mb_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["mb_qa_confirm"]);
- DataRow row = data.NewRow();
- row["isScan"] = false;
- row["rn"] = i + 1;
- row["mb_id"] = src["mb_id"].ToString();
- row["mb_makecode"] = src["mb_makecode"].ToString();
- row["mb_sncode"] = src["mb_sncode"].ToString();
- row["mb_indate"] = src["mb_indate"].ToString();
- row["mb_stepcode"] = src["mb_stepcode"].ToString();
- row["mb_badcode"] = src["mb_badcode"].ToString();
- row["mb_status"] = StatusText(src["mb_status"]);
- row["mb_bgcode"] = src["mb_bgcode"].ToString();
- row["mb_bgname"] = src["mb_bgname"].ToString();
- row["mb_badname"] = src["mb_badname"].ToString();
- row["mb_linecode"] = src["mb_linecode"].ToString();
- row["qa_type"] = qaType;
- row["mb_qa_confirm"] = QaTypeText(qaType);
- data.Rows.Add(row);
- }
- 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]["mb_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["mb_sncode"].ToString();
- string badCode = row["mb_badcode"].ToString();
- string qaType = NormalizeQaType(row["qa_type"]);
- if (qaType == "")
- {
- missing.Add("序列号" + sn + "不良代码" + badCode);
- 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;
- }
- try
- {
- foreach (DataRow row in scanRows)
- {
- string idSql = row["mb_id"].ToString();
- string qaType = NormalizeQaType(row["qa_type"]);
- SQL.Clear();
- SQL.Append($@"UPDATE makebad SET mb_qa_confirm = '{qaType}' WHERE mb_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)
- {
- string sn = row["mb_sncode"].ToString();
- if (!snList.Contains(sn))
- snList.Add(sn);
- }
- MessageBox.Show($"序列号:{string.Join("、", snList)},数量{snList.Count},品质确认完成", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- MessageBox.Show("确认成功", "提示", 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 StatusText(object value)
- {
- string text = value == null || value == DBNull.Value ? "" : value.ToString().Trim();
- decimal number;
- if (decimal.TryParse(text, out number))
- {
- if (number == -1)
- return "已维修";
- if (number == 0)
- return "未维修";
- if (number == -2)
- return "报废";
- }
- return text;
- }
- 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]["mb_qa_confirm"] = 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");
- }
- }
- }
- }
- }
|