using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; 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_Aging : Form { DataHelper dh; AutoSizeFormClass asc = new AutoSizeFormClass(); LogStringBuilder sql = new LogStringBuilder(); DataTable dt; //当前序列号记录 string sn_code; //制造单号 string macode; //采集网标号 float net_code; //网标查询条件ms_id string oMsID; //打印计数 int printcount = 0; int ma_unlimitin; string ErrorMessage = ""; string LastSncode; public Make_Aging() { InitializeComponent(); } private void Make_CollectNetCode_Load(object sender, EventArgs e) { asc.controllInitializeSize(this); sncode.Focus(); dh = SystemInf.dh; } private void sncode_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { string ErrorMessage2; string oMakeCode; //采集序列号 if (sncode.Text == "") { OperateResult.AppendText(">>序列号不能为空\n", Color.Red); return; } if (!quxiao.Checked) { if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage2)) { //判断界面工单是否为空时的序列号是否自动归属工单 string oStatus = ""; if (!LogicHandler.GetMakeInfo(sncode.Text, out oMakeCode, out oStatus, out ErrorMessage2)) { if (ms_makecode.Text == "") { OperateResult.AppendText(">>" + ErrorMessage2 + "\n", Color.Red, sncode); return; } } //OperateResult.AppendText("<<" + sncode.Text + "\n", Color.Black); dt = (DataTable)dh.ExecuteSql("select ms_status,ms_id,ms_makecode,ms_nextstepcode,ms_craftcode,ms_prodcode from makeserial left join product on ms_prodcode = pr_code where ms_sncode ='" + sncode.Text + "' order by ms_id desc", "select"); if (dt.Rows.Count == 0) { OperateResult.AppendText(">>SN:" + sncode.Text + "不存在\n", Color.Red, sncode); return; } //判断工单工序 // 获取工单归属工单下一工序是否正确 if (LogicHandler.CheckStepSNAndMacode(ms_makecode.Text == "" ? oMakeCode : ms_makecode.Text, User.UserSourceCode, sncode.Text, User.UserCode, out oMakeCode, out oMsID, out ErrorMessage2) || (dt.Rows.Count > 0 && dt.Rows[0]["ms_status"].ToString() == "1")) { if (oMsID == "" || oMsID == "null" || oMsID == "0") { oMsID = dt.Rows[0]["ms_id"].ToString(); oMakeCode = dt.Rows[0]["ms_makecode"].ToString(); } sql.Clear(); sql.Append("select ms_makecode,ms_prodcode,pr_detail,ms_craftcode from makeserial left join product on "); sql.Append(" ms_prodcode = pr_code where ms_id = '" + oMsID + "'"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); BaseUtil.SetFormValue(this.Controls, dt); sn_code = sncode.Text; } else { OperateResult.AppendText(">>" + ErrorMessage2 + "\n", Color.Red, sncode); return; } if (agcode.Text == "") { if (checkBox1.Checked) { agcode.Text = LogicHandler.GetAGCode(); fildgv(); } else { DataTable dtc = (DataTable)dh.ExecuteSql("select ag_code,ag_status from ageingdetail left join ageing on agd_agid = ag_id where agd_sncode = '" + sncode.Text + "' order by agd_id desc", "select"); if (dtc.Rows.Count > 0) { if (dtc.Rows[0]["ag_status"].ToString().Contains("0")) { agcode.Text = dtc.Rows[0]["ag_code"].ToString(); fildgv(); sncode.Text = ""; return; } else if (dtc.Rows[0]["ag_status"].ToString().Contains("1")) { OperateResult.AppendText(">>SN:" + sncode.Text + "处于老化中老化批:" + dtc.Rows[0]["ag_code"].ToString() + "中,无法采集进新批\n", Color.Red, sncode); return; } else if (dtc.Rows[0]["ag_status"].ToString().Contains("2")) { OperateResult.AppendText(">>SN:" + sncode.Text + "处于老化结束批:" + dtc.Rows[0]["ag_code"].ToString() + "中,无法采集进新批\n", Color.Red, sncode); return; } } else { OperateResult.AppendText(">>SN:" + sncode.Text + "未采集老化,老化编号不可为空\n", Color.Red, sncode); return; } } } else { fildgv(); } DataTable dtB = (DataTable)dh.ExecuteSql("select ag_code from ageingdetail left join ageing on agd_agid = ag_id where agd_sncode = '" + sncode.Text + "' and ag_status <>2", "select"); if (dtB.Rows.Count > 0) { OperateResult.AppendText(">>SN:" + sncode.Text + "处于未结束老化批:" + dtB.Rows[0]["ag_code"].ToString() + "中,无法采集进新批\n", Color.Red, sncode); return; } if (dh.CheckExist("craft left join craftdetail on cr_id = cd_crid", "cr_code = '" + dt.Rows[0]["ms_craftcode"].ToString() + "' and cr_prodcode = '" + dt.Rows[0]["ms_prodcode"].ToString() + "' and cd_stepcode = 'Aging'")) { if (LogicHandler.CheckStepSNAndMacode(ms_makecode.Text == "" ? oMakeCode : ms_makecode.Text, User.UserSourceCode, sncode.Text, User.UserCode, out oMakeCode, out oMsID, out ErrorMessage2)) { //良品信息采集 if (LogicHandler.SetStepResult(ms_makecode.Text, User.UserSourceCode, sncode.Text, "老化采集", "采集成功", User.UserCode, out ErrorMessage)) { //提示正确返回时传递的信息 if (ErrorMessage.Contains("AFTERSUCCESS")) OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red); LastSncode = sncode.Text; } else { OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, sncode); return; } } else { OperateResult.AppendText(">>" + ErrorMessage2 + "\n", Color.Red, sncode); return; } } else { LastSncode = sncode.Text; } if (!dh.CheckExist("ageing", "ag_code = '" + agcode.Text + "'")) { dh.ExecuteSql("insert into ageing(ag_id,ag_code,ag_indate,ag_status) values(ageing_seq.nextval,'" + agcode.Text + "',sysdate,0)", "insert"); } dh.ExecuteSql("insert into ageingdetail(agd_id,agd_agid,agd_agcode,agd_makecode,agd_sncode,agd_indate) select ageingdetail_seq.nextval,ag_id,ag_code,'" + ms_makecode.Text + "','" + sncode.Text + "',sysdate from ageing where ag_code = '" + agcode.Text + "'", "insert"); LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, "老化采集" + agcode.Text, "采集成功", LastSncode, ""); OperateResult.AppendText(">>" + sncode.Text + "老化采集成功\n", Color.Green, sncode); fildgv(); } else OperateResult.AppendText(">>" + ErrorMessage2 + "\n", Color.Red, sncode); } else { if (agcode.Text == "") { OperateResult.AppendText(">>老化编号不可为空\n", Color.Red, sncode); return; } else { fildgv(); } DataTable dtB = (DataTable)dh.ExecuteSql("select ag_code from ageingdetail left join ageing on agd_agid = ag_id where agd_agcode = '"+agcode.Text+"' and agd_sncode = '" + sncode.Text + "' and ag_status =0", "select"); if (dtB.Rows.Count > 0) { dh.ExecuteSql("delete ageingdetail where agd_agcode = '" + agcode.Text + "' and agd_sncode = '" + sncode.Text + "' ", "delete"); LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, "取消老化采集" + agcode.Text, "取消采集成功", sncode.Text, ""); OperateResult.AppendText(">>SN:" + sncode.Text + "取消采集老化批:" + dtB.Rows[0]["ag_code"].ToString() + "成功\n", Color.Green, sncode); fildgv(); return; } else { OperateResult.AppendText(">>SN:" + sncode.Text + "未处于在录入老化批:" + agcode.Text + "中,无法取消采集\n", Color.Red, sncode); return; } } } } private void Make_CollectNetCode_SizeChanged(object sender, EventArgs e) { asc.controlAutoSize(this); } private void Make_CollectNetCode_Activated(object sender, EventArgs e) { sncode.Focus(); } private void deleteButton1_Click(object sender, EventArgs e) { string Seal = MessageBox.Show(this.ParentForm, "是否确认老化?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString(); if (Seal == "Yes") { fildgv(); if (agcode.Text != "") { dt = (DataTable)dh.ExecuteSql("select * from ageing where ag_code = '" + agcode.Text + "' and ag_status <>0 ", "select"); if (dt.Rows.Count > 0) { OperateResult.AppendText(">>老化编号" + agcode.Text + "已开始或结束老化\n", Color.Red, agcode); return; } else { dh.ExecuteSql("update ageing set ag_startdate = sysdate,ag_status = 1 where ag_code = '" + agcode.Text + "'", "update"); LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, "老化开始" + agcode.Text, "采集开始", agcode.Text, ""); OperateResult.AppendText(">>" + agcode.Text + "老化批次开始\n", Color.CornflowerBlue, agcode); BaseUtil.CleanControls(this.Controls); if (!checkBox1.Checked) { agcode.Focus(); } else { sncode.Focus(); } } } else { OperateResult.AppendText(">>老化编号" + agcode.Text + "不可为空\n", Color.Red, agcode); return; } } } private void checkBox1_CheckedChanged(object sender, EventArgs e) { } void fildgv() { DataTable dtc; if (agcode.Text != "") { dtc = (DataTable)dh.ExecuteSql("select * from ageingdetail left join ageing on agd_agid = ag_id where ag_code = '" + agcode.Text + "' and ag_status <>0 ", "select"); if (dtc.Rows.Count > 0) { OperateResult.AppendText(">>老化编号" + agcode.Text + "已开始或结束老化\n", Color.Red, agcode); return; } else { dtc = (DataTable)dh.ExecuteSql("select * from ageingdetail left join ageing on agd_agid = ag_id where ag_code = '" + agcode.Text + "' ", "select"); agsum.Text = dh.getFieldDataByCondition("ageingdetail", "count(1) cn"," agd_agcode = '"+ agcode.Text + "'").ToString(); } BaseUtil.FillDgvWithDataTable(LabelDataGridView, dtc); } } private void snCollectionBox1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { fildgv(); sncode.Focus(); sncode.SelectAll(); } } } }