| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
- 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;
- namespace UAS_MES_NEW.Make
- {
- public partial class Make_HandFeedRegistration : Form
- {
- public Make_HandFeedRegistration()
- {
- InitializeComponent();
- }
- StringBuilder SQL = new StringBuilder();
- DataTable dt;
- DataHelper dh;
- int checkedCount = 0;
- private void Make_HandFeedRegistration_Load(object sender, EventArgs e)
- {
- dh = SystemInf.dh;
- snVal.Focus();
- snVal.SelectAll();
- submit.Enabled = false;
- handCount.Text = $"补料数量: {checkedCount}";
- }
- private void snVal_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode != Keys.Enter) return;
- snVal.Text = snVal.Text.Replace(";", ";").Trim();
- SQL.Clear();
- //SQL.Append($@"SELECT * FROM (SELECT ms_makecode,ms_prodcode,ps_linecode,ps_processcode,
- // ps_table,ROW_NUMBER() OVER(PARTITION BY ps_processcode ORDER BY ps_auditdate DESC) AS rn
- // FROM makeserial a,productsmt b WHERE a.ms_sncode = '{snVal.Text}' AND a.ms_prodcode = b.ps_prodcode
- // AND instr(ps_linecode, a.ms_linecode) > 0) WHERE rn = 1 ORDER BY ps_processcode");
- SQL.Append($@"SELECT ps_processcode FROM makeserial a,productsmt b
- WHERE a.ms_sncode = '{snVal.Text}' AND a.ms_prodcode = b.ps_prodcode");
- dt = (DataTable)dh.ExecuteSql(SQL.ToString(), "select");
- if (dt.Rows.Count > 0)
- {
- machineVal.Items.Clear();
- foreach (DataRow dr in dt.Rows)
- {
- machineVal.Items.Add(dr["ps_processcode"].ToString());
- }
- machineVal.SelectedIndex = 0;
- machineVal.SelectAll();
- UpdateSN("L", snVal.Text);
- query_Click(null, null);
- }
- else
- {
- UpdateSN("C");
- machineVal.Items.Clear();
- machineVal.SelectedIndex = -1;
- snVal.Focus();
- snVal.SelectAll();
- MessageBox.Show("该序列号没有对应机台", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- }
- private void query_Click(object sender, EventArgs e)
- {
- if (string.IsNullOrEmpty(snVal.Text))
- {
- MessageBox.Show("请扫描序列号", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- snVal.Focus();
- snVal.SelectAll();
- return;
- }
- if (string.IsNullOrEmpty(machineVal.Text))
- {
- MessageBox.Show("请选择机台名称", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- machineVal.SelectAll();
- return;
- }
- SQL.Clear();
- SQL.Append($@"SELECT rownum rn,ms_sncode,ps_linecode,
- ps_processcode,ps_table,psl_location,psl_bomlocation,psl_prodcode,psl_baseqty
- FROM makeserial a,productsmt b,productsmtlocation c
- WHERE a.ms_sncode = '{snVal.Text}' AND b.ps_processcode = '{machineVal.Text}'
- AND a.ms_prodcode = b.ps_prodcode AND b.ps_id = c.psl_psid ORDER BY psl_detno");
- dt = (DataTable)dh.ExecuteSql(SQL.ToString(), "select");
- if (dt.Rows.Count > 0)
- {
- dgv.DataSource = dt;
- checkedCount = 0;
- handCount.Text = $"补料数量: {checkedCount}";
- submit.Enabled = true;
- }
- }
- private void dgv_CellClick(object sender, DataGridViewCellEventArgs e)
- {
- if (e.RowIndex < 0 || e.ColumnIndex < 0) return;
- var column = dgv.Columns[e.ColumnIndex];
- if (column is DataGridViewCheckBoxColumn)
- {
- var cell = dgv[e.ColumnIndex, e.RowIndex] as DataGridViewCheckBoxCell;
- if (cell != null && !cell.ReadOnly)
- {
- bool currentValue = false;
- if (cell.Value != null && cell.Value != DBNull.Value)
- {
- currentValue = Convert.ToBoolean(cell.Value);
- }
- cell.Value = !currentValue;
- dgv.CommitEdit(DataGridViewDataErrorContexts.Commit);
- dgv.EndEdit();
- var row = dgv.Rows[e.RowIndex];
- if (currentValue)
- {
- row.DefaultCellStyle.BackColor = dgv.DefaultCellStyle.BackColor;
- row.DefaultCellStyle.ForeColor = dgv.DefaultCellStyle.ForeColor;
- checkedCount--;
- }
- else
- {
- row.DefaultCellStyle.BackColor = Color.LightSkyBlue;
- row.DefaultCellStyle.ForeColor = Color.Black;
- checkedCount++;
- }
- handCount.Text = $"补料数量: {checkedCount}";
- if (checkedCount > 0)
- {
- submit.Enabled = true;
- }
- else
- {
- submit.Enabled = false;
- }
- }
- }
- }
- private void submit_Click(object sender, EventArgs e)
- {
- if (checkedCount == 0)
- {
- MessageBox.Show("请勾选所补物料对应站位信息", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- DataTable upLoadDatas = new DataTable();
- upLoadDatas.Columns.Add(new DataColumn("rn"));
- upLoadDatas.Columns.Add(new DataColumn("ms_sncode"));
- upLoadDatas.Columns.Add(new DataColumn("ps_linecode"));
- upLoadDatas.Columns.Add(new DataColumn("ps_processcode"));
- upLoadDatas.Columns.Add(new DataColumn("ps_table"));
- upLoadDatas.Columns.Add(new DataColumn("psl_location"));
- upLoadDatas.Columns.Add(new DataColumn("psl_bomlocation"));
- upLoadDatas.Columns.Add(new DataColumn("psl_prodcode"));
- upLoadDatas.Columns.Add(new DataColumn("psl_baseqty"));
- foreach (DataGridViewRow item in dgv.Rows)
- {
- var checkCell = item.Cells["isHandReel"] as DataGridViewCheckBoxCell;
- if (Convert.ToBoolean(checkCell.Value))
- {
- upLoadDatas.Rows.Add(item.Cells["rn"].Value, item.Cells["ms_sncode"].Value, item.Cells["ps_linecode"].Value,
- item.Cells["ps_processcode"].Value, item.Cells["ps_table"].Value, item.Cells["psl_location"].Value,
- item.Cells["psl_bomlocation"].Value, item.Cells["psl_prodcode"].Value, item.Cells["psl_baseqty"].Value);
- }
- }
- dgv.DataSource = upLoadDatas;
- foreach (DataGridViewRow rw in dgv.Rows)
- {
- var checkCell = rw.Cells["isHandReel"] as DataGridViewCheckBoxCell;
- checkCell.Value = true;
- try
- {
- SQL.Clear();
- SQL.Append($@"INSERT INTO smt_handreel_log (serial_number,line_name,machine_name,side,
- position,reel_position, part_no, reel_qty,
- update_time, update_name) VALUES
- ( '{rw.Cells["ms_sncode"].Value}','{rw.Cells["ps_linecode"].Value}','{rw.Cells["ps_processcode"].Value}','{rw.Cells["ps_table"].Value}',
- '{rw.Cells["psl_location"].Value}','{rw.Cells["psl_bomlocation"].Value}','{rw.Cells["psl_prodcode"].Value}','{rw.Cells["psl_baseqty"].Value}',
- sysdate,'{User.UserName}' )");
- dh.ExecuteSql(SQL.ToString(), "insert");
- }
- catch (Exception ex)
- {
- MessageBox.Show($"提交手补料异常{ex.Message}", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- }
- MessageBox.Show("已提交手补料记录", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
- submit.Enabled = false;
- }
- 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", sn);
- }
- }
- }
- }
- }
|