| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342 |
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- using NPOI.SS.Formula.Functions;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Drawing;
- using System.Net.Http;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using UAS_MES_NEW.CustomControl.ButtonUtil;
- using UAS_MES_NEW.CustomControl.RichText;
- using UAS_MES_NEW.DataOperate;
- using UAS_MES_NEW.Entity;
- using UAS_MES_NEW.PublicMethod;
- namespace UAS_MES_NEW.Make
- {
- public partial class Make_ToolingManager : Form
- {
- public Make_ToolingManager()
- {
- InitializeComponent();
- }
- DataHelper dh;
- DataTable Dbfind;
- DataTable dt;
- private void Make_ToolingManager_Load(object sender, EventArgs e)
- {
- dh = SystemInf.dh;
- li_code.Text = User.UserLineCode;
- ma_code.TableName = "make left join product on ma_prodcode=pr_code";
- ma_code.SelectField = "ma_code # 工单号,ma_prodcode # 产品编号,ma_qty # 工单数量,pr_detail # 产品名称,ma_softversion # 软件版本,ma_salecode # 销售单号,pr_sendchecktype # 产品送检方式";
- ma_code.FormName = Name;
- ma_code.SetValueField = new string[] { "ma_code" };
- ma_code.DbChange += Ma_code_DbChange;
- li_code.TableName = "Line";
- li_code.SelectField = "li_code # 线别编号,li_name # 线别名称";
- li_code.Condition = "li_wccode='SMT'";
- li_code.FormName = Name;
- li_code.SetValueField = new string[] { "li_code", "li_name" };
- li_code.DbChange += Li_code_DbChange;
- toolingVal.SelectAll();
- toolingVal.Focus();
- }
- private void Li_code_DbChange(object sender, EventArgs e)
- {
- Dbfind = li_code.ReturnData;
- BaseUtil.SetFormValue(this.Controls, Dbfind);
- }
- private void Ma_code_DbChange(object sender, EventArgs e)
- {
- Dbfind = ma_code.ReturnData;
- BaseUtil.SetFormValue(this.Controls, Dbfind);
- //Confirm.PerformClick();
- }
- private void toolingVal_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (e.KeyChar != (char)Keys.Enter) return;
- if (string.IsNullOrEmpty(toolingVal.Text.Trim()))
- {
- ShowMsg(MsgBox, 0, "NG,请输入治具编号");
- toolingVal.SelectAll();
- toolingVal.Focus();
- return;
- }
- dt = (DataTable)dh.ExecuteSql($"select st_kind,st_usestatus from stencil where st_code = '{toolingVal.Text.Trim()}' group by st_kind,st_usestatus", "select");
- if (dt.Rows.Count == 0)
- {
- ShowMsg(MsgBox, 0, "NG,未识别到治具类型,请先维护治具信息");
- toolingVal.SelectAll();
- toolingVal.Focus();
- return;
- }
- typeVal.Items.Clear();
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- typeVal.Items.Add(dt.Rows[i][0].ToString());
- }
- typeVal.SelectedIndex = 0;
- currStatusVal.Text = dt.Rows[0]["st_usestatus"].ToString();
- if (typeVal.Text == "钢网")
- {
- stA.Enabled = true;
- stB.Enabled = true;
- stC.Enabled = true;
- stD.Enabled = true;
- stE.Enabled = true;
- }
- else
- {
- stA.Enabled = false;
- stB.Enabled = false;
- stC.Enabled = false;
- stD.Enabled = false;
- stE.Enabled = false;
- }
- dt = (DataTable)dh.ExecuteSql($"select su_status,su_usedate from (select su_status,su_usedate from stenciluse where su_stcode = '{toolingVal.Text.Trim()}' order by su_usedate desc) where rownum=1", "select");
- if (dt.Rows.Count == 0)
- {
- ShowMsg(MsgBox, 2, "NG,未识别到治具上次操作");
- }
- else
- {
- prevTypeVal.Text = dt.Rows[0]["su_status"].ToString();
- prevTimeVal.Text = dt.Rows[0]["su_usedate"].ToString();
- }
- if(currStatusVal.Text == "出库")
- {
- Return.Enabled = true;
- Scrap.Enabled = true;
- Receive.Enabled = false;
- }
- else if (currStatusVal.Text == "在库")
- {
- Return.Enabled = false;
- Scrap.Enabled = false;
- Receive.Enabled = true;
- }
- else
- {
- Return.Enabled = false;
- Scrap.Enabled = false;
- Receive.Enabled = true;
- }
- toolingVal.Enabled = false;
- }
- private void ShowMsg(RichTextAutoBottom msgBox, int type, string msg)
- {
- msg = msg.Replace("\r", "").Replace("\n", "");
- string msgTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
- string showMsg = $"{msgTime}: {msg}\n";
- if (type == 0)
- {
- msgBox.AppendText(showMsg, Color.Red);
- msgBox.SelectionStart = msgBox.Text.Length;
- msgBox.ScrollToCaret();
- }
- else if (type == 1)
- {
- msgBox.AppendText(showMsg, Color.Green);
- msgBox.SelectionStart = msgBox.Text.Length;
- msgBox.ScrollToCaret();
- }
- else if (type == 2)
- {
- msgBox.AppendText(showMsg, Color.YellowGreen);
- msgBox.SelectionStart = msgBox.Text.Length;
- msgBox.ScrollToCaret();
- }
- }
- private void cancel_Click(object sender, EventArgs e)
- {
- toolingVal.Enabled = true;
- toolingVal.Focus();
- toolingVal.SelectAll();
- }
- private void Receive_Click(object sender, EventArgs e)
- {
- if (string.IsNullOrEmpty(ma_code.Text))
- {
- ShowMsg(MsgBox, 0, "NG,请选择使用工单");
- ma_code.Focus();
- return;
- }
- if (string.IsNullOrEmpty(li_code.Text))
- {
- ShowMsg(MsgBox, 0, "NG,请输入使用线体");
- li_code.Focus();
- return;
- }
- if (string.IsNullOrEmpty(sideVal.Text))
- {
- ShowMsg(MsgBox, 0, "NG,请选择使用面别");
- sideVal.Focus();
- return;
- }
- if (string.IsNullOrEmpty(empVal.Text))
- {
- ShowMsg(MsgBox, 0, "NG,请填写领用人员");
- empVal.Focus();
- empVal.SelectAll();
- return;
- }
- dt = (DataTable)dh.ExecuteSql($@"SELECT st_usestatus,st_version,nvl(st_maxusecount, 0) st_maxusecount,nvl(st_usecount, 0) st_usecount
- FROM stencil WHERE st_code = '{toolingVal.Text.Trim()}'", "select");
- string status = dt.Rows[0]["st_usestatus"].ToString();
- if (status == "出库" || status == "报废")
- {
- ShowMsg(MsgBox, 0, $"NG,无法领用,{typeVal.Text}:{toolingVal.Text}为{status}状态");
- return;
- }
- int maxCount = Convert.ToInt32(dt.Rows[0]["st_maxusecount"].ToString());
- int useCount = Convert.ToInt32(dt.Rows[0]["st_usecount"].ToString());
- int warnCount = Convert.ToInt32(dh.GetConfig("WaringCount", "Stencil"));
- if (maxCount - useCount < warnCount)
- {
- //ShowMsg(MsgBox, 2, "Warning,钢网:" + toolingVal.Text + "使用次数接近上限");
- DialogResult result = MessageBox.Show(this.ParentForm, $"Warning,{typeVal.Text}:{toolingVal.Text}使用次数接近上限,已使用{useCount},距离上限还有{(maxCount - useCount)}次", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
- if (result == DialogResult.No) return;
- }
- dt = (DataTable)dh.ExecuteSql($"select st_code from stencil where st_line='{li_code.Text}' and st_kind = '{typeVal.Text}'", "select");
- if(typeVal.Text == "钢网")
- {
- if (dt.Rows.Count > 0)
- {
- ShowMsg(MsgBox, 0, $"NG,线体已有在线{typeVal.Text},编号为:{dt.Rows[0]["st_code"].ToString()}");
- return;
- }
- }else if (typeVal.Text == "刮刀")
- {
- if (dt.Rows.Count > 1)
- {
- ShowMsg(MsgBox, 0, $"NG,线体已有在线{typeVal.Text},编号为:{dt.Rows[0]["st_code"].ToString()}");
- return;
- }
- }
- dh.ExecuteSql("update stencil set st_usestatus= '出库' where st_code='" + toolingVal.Text + "'", "update");
- dt = (DataTable)dh.ExecuteSql($"select ma_prodcode from make where ma_code='{ma_code.Text}'", "select");
- dh.ExecuteSql($@"INSERT INTO stenciluse (su_id,su_stcode,su_stid,
- su_usemacode,su_useprodcode,su_linecode,su_table,su_useman,su_usedate,su_status)
- SELECT stenciluse_seq.NEXTVAL,'{toolingVal.Text.Trim()}',st_id,
- '{ma_code.Text}','{dt.Rows[0]["ma_prodcode"].ToString()}','{li_code.Text}','{sideVal.Text}','{empVal.Text}',sysdate, '领用'
- FROM stencil WHERE st_code = '{toolingVal.Text.Trim()}'", "insert");
- ma_code.Text = "";
- sideVal.SelectedIndex = -1;
- empVal.Text = "";
- ShowMsg(MsgBox, 1, $"OK,{typeVal.Text}编号:{toolingVal.Text},已领用成功");
- }
- private void Return_Click(object sender, EventArgs e)
- {
- if (string.IsNullOrEmpty(empVal1.Text))
- {
- ShowMsg(MsgBox, 0, "NG,请填写归还人员");
- empVal1.Focus();
- empVal1.SelectAll();
- return;
- }
- dt = (DataTable)dh.ExecuteSql($@"SELECT st_usestatus,st_usecount
- FROM stencil WHERE st_code = '{toolingVal.Text.Trim()}'", "select");
- string status = dt.Rows[0]["st_usestatus"].ToString();
- if (status == "在库" || status == "报废")
- {
- ShowMsg(MsgBox, 0, $"NG,无需归还,{typeVal.Text}:{toolingVal.Text}为{status}状态");
- return;
- }
- if(typeVal.Text == "钢网")
- {
- if (IsClean.Checked) {
- dh.ExecuteSql($@"UPDATE stencil SET st_cleannums = nvl(st_cleannums, 0) + 1,
- st_ensiona = '{stA.Text.Trim()}',st_ensionb = '{stB.Text.Trim()}',
- st_ensionc = '{stC.Text.Trim()}',st_ensiond = '{stD.Text.Trim()}',st_ensione = '{stE.Text.Trim()}',
- st_usecount = '',st_usestatus = '在库'
- WHERE st_code = '{toolingVal.Text.Trim()}'", "update");
- }
- else
- {
- dh.ExecuteSql($@"UPDATE stencil SET st_ensiona = '{stA.Text.Trim()}',st_ensionb = '{stB.Text.Trim()}',
- st_ensionc = '{stC.Text.Trim()}',st_ensiond = '{stD.Text.Trim()}',st_ensione = '{stE.Text.Trim()}',
- st_usecount = '',st_usestatus = '在库'
- WHERE st_code = '{toolingVal.Text.Trim()}'", "update");
- }
- dh.ExecuteSql($@"INSERT INTO stenciluse (su_id,su_stcode,su_stid,
- su_usemacode,su_useprodcode,su_linecode,su_table,
- su_useman,su_usedate,su_status,
- su_ensiona,su_ensionb,su_ensionc,su_ensiond,su_ensione)
- SELECT stenciluse_seq.NEXTVAL,'{toolingVal.Text.Trim()}',st_id,
- su_usemacode,su_useprodcode,su_linecode,su_table,
- '{empVal1.Text}',sysdate,'归还',
- st_ensiona,st_ensionb,st_ensionc,st_ensiond,st_ensione
- FROM stencil,stenciluse WHERE st_code = '{toolingVal.Text.Trim()}'
- AND st_line = su_linecode", "insert");
- }
- else if(typeVal.Text == "刮刀")
- {
- if (IsClean.Checked)
- {
- dh.ExecuteSql($@"UPDATE stencil SET st_cleannums = nvl(st_cleannums, 0) + 1,st_usecount = '',
- st_usestatus = '在库' WHERE st_code = '{toolingVal.Text.Trim()}'", "update");
- }
- else
- {
- dh.ExecuteSql($@"UPDATE stencil SET st_usecount = '',st_usestatus = '在库'
- WHERE st_code = '{toolingVal.Text.Trim()}'", "update");
- }
- dh.ExecuteSql($@"INSERT INTO stenciluse (su_id,su_stcode,su_stid,
- su_usemacode,su_useprodcode,su_linecode,su_table,
- su_useman,su_usedate,su_status,)
- SELECT stenciluse_seq.NEXTVAL,'{toolingVal.Text.Trim()}',st_id,
- su_usemacode,su_useprodcode,su_linecode,su_table,
- '{empVal1.Text}',sysdate,'归还',
- FROM stencil,stenciluse WHERE st_code = '{toolingVal.Text.Trim()}'
- AND st_line = su_linecode", "insert");
- }
- stA.Text = "";
- stB.Text = "";
- stC.Text = "";
- stD.Text = "";
- stE.Text = "";
- empVal1.Text = "";
- IsClean.Checked = false;
- ShowMsg(MsgBox, 1, $"OK,{typeVal.Text}编号:{toolingVal.Text},已归还成功");
- }
- private void Scrap_Click(object sender, EventArgs e)
- {
- }
- }
- }
|