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_BurnInfo : Form { public Make_BurnInfo() { InitializeComponent(); } LogStringBuilder sql = new LogStringBuilder(); DataTable Dbfind; DataHelper dh; DataTable dt; string remainQty; DateTime callTime = DateTime.Now; private void Make_BurnInfo_Load(object sender, EventArgs e) { //设置锁定工单 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 # 工单号,pr_code # 产品编号,pr_detail # 产品名称"; ma_code.FormName = Name; ma_code.SetValueField = new string[] { "ma_code", "pr_code", "pr_detail" }; ma_code.Condition = "ma_statuscode='STARTED'"; ma_code.DbChange += Ma_code_DbChange; dh = SystemInf.dh; dt = (DataTable)dh.ExecuteSql("SELECT * FROM line WHERE li_wcname = 'SMT' ORDER BY li_auditdate", "select"); if (dt.Rows.Count > 0) { foreach (DataRow item in dt.Rows) { LineVal.Items.Add(item["li_code"].ToString()); } } } private void Ma_code_DbChange(object sender, EventArgs e) { Dbfind = ma_code.ReturnData; BaseUtil.SetFormValue(this.Controls, Dbfind); //获取工单的其他信息 sql.Clear(); sql.Append("select ma_code,nvl(mcd_okqty,0) mcd_okqty,ma_prodcode as pr_code ,pr_detail,"); sql.Append("pr_spec,ma_qty - nvl(mcd_inqty, 0) mcd_remainqty,ma_qty from make left join makecraftdetail on "); sql.Append("mcd_maid=ma_id left join product on pr_code=ma_prodcode where ma_code='" + ma_code.Text + "'"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); if (dt.Rows.Count > 0) { BaseUtil.SetFormValue(this.Controls, dt); } if ((DateTime.Now - callTime).TotalSeconds > 10) { callTime = DateTime.Now; dt = (DataTable)dh.ExecuteSql($"SELECT BURN_LOTNO,WORK_ORDER,LINE,BURN_SOFTWARE,CHECK_CODE,DOT_DETAIL,UPDATE_TIME,UPDATE_NAME,BURN_QTY,inspect_res,IC_DETAIL,burn_id,remark FROM burn_info LEFT JOIN burn_inspect ON burn_id = burnid WHERE work_order = '{ma_code.Text}'", "select"); DataBox.DataSource = dt; ShowMsg(1, $"工单: {ma_code.Text} 已找到{dt.Rows.Count}条烧录记录"); dt = (DataTable)dh.ExecuteSql($"select nvl(sum(burn_qty),0) allqty from burn_info where work_order = '{ma_code.Text}'", "select"); if (dt.Rows.Count > 0) { CurrQtyVal.Text = dt.Rows[0]["allqty"].ToString(); } if (BaseUtil.GetCacheData("BurnInfoWo").ToString() == ma_code.Text.Trim()) { BurnSwVal.Text = BaseUtil.GetCacheData("BurnInfo_BurnSwVal").ToString(); CheckCodeVal.Text = BaseUtil.GetCacheData("BurnInfo_CheckCodeVal").ToString(); DotVal.Text = BaseUtil.GetCacheData("BurnInfo_DotVal").ToString(); IcDetailVal.Text = BaseUtil.GetCacheData("BurnInfo_IcDetailVal").ToString(); } } if (!string.IsNullOrEmpty(ma_code.Text)) SaveCache.Enabled = true; else SaveCache.Enabled = false; } private void Confirm_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(ma_code.Text)) { ShowMsg(0, "请选择归属工单"); ma_code.Focus(); return; } /*if (string.IsNullOrEmpty(LineVal.Text)) { ShowMsg(0, "请选择线体"); LineVal.Focus(); LineVal.SelectAll(); return; }*/ if (string.IsNullOrEmpty(BurnLotnoVal.Text)) { ShowMsg(0, "请扫描包批次号"); BurnLotnoVal.Focus(); BurnLotnoVal.SelectAll(); return; } dt = (DataTable)dh.ExecuteSql($@"select * from burn_info where burn_lotno = '{BurnLotnoVal.Text}'", "select"); if (dt.Rows.Count > 0) { ShowMsg(0, $"批号 {BurnLotnoVal.Text}已记录,请勿重复使用"); return; } dh.ExecuteSql($@"insert INTO burn_info (burn_id,burn_lotno,burn_software, check_code,dot_detail,line,burn_qty, update_name,update_time,work_order) VALUES (BURN_INFO_SEQ.nextval,'{BurnLotnoVal.Text.Trim()}','{BurnSwVal.Text.Trim()}', '{CheckCodeVal.Text.Trim()}','{DotVal.Text.Trim()}','{LineVal.Text.Trim()}','{remainQty}', '{User.UserName}',sysdate,'{ma_code.Text.Trim()}')", "insert"); BurnLotnoVal.Focus(); BurnLotnoVal.SelectAll(); BurnSwVal.Text = ""; CheckCodeVal.Text = ""; DotVal.Text = ""; ShowMsg(1, "添加烧录信息成功"); dt = (DataTable)dh.ExecuteSql($"SELECT BURN_LOTNO,WORK_ORDER,LINE,BURN_SOFTWARE,CHECK_CODE,DOT_DETAIL,UPDATE_TIME,UPDATE_NAME,BURN_QTY,inspect_res,IC_DETAIL,burn_id,remark FROM burn_info LEFT JOIN burn_inspect ON burn_id = burnid WHERE work_order = '{ma_code.Text}'", "select"); DataBox.DataSource = dt; dt = (DataTable)dh.ExecuteSql($"select nvl(sum(burn_qty),0) allqty from burn_info where work_order = '{ma_code.Text}'", "select"); if (dt.Rows.Count > 0) { CurrQtyVal.Text = dt.Rows[0]["allqty"].ToString(); } } private void ShowMsg(int type, string msg) { string fullDateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); if (type == 0) { OperateResult.AppendText($"{fullDateTime}: {msg}\n", Color.Red); } else if (type == 1) { OperateResult.AppendText($"{fullDateTime}: {msg}\n", Color.Green); } } private void BurnLotnoVal_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode != Keys.Enter) return; BurnLotnoVal.Text = BurnLotnoVal.Text.Trim(); if (!string.IsNullOrEmpty(BurnLotnoVal.Text)) { dt = (DataTable)dh.ExecuteSql($"select * from barcode where bar_code = '{BurnLotnoVal.Text}'", "select"); if (dt.Rows.Count == 0) { ShowMsg(0, $"条码:{BurnLotnoVal.Text} 不是MES系统中库存条码"); BurnLotnoVal.Text = ""; return; } remainQty = dt.Rows[0]["BAR_REMAIN"].ToString(); } if (string.IsNullOrEmpty(ma_code.Text)) { ShowMsg(0, "请选择归属工单"); ma_code.Focus(); return; } if(Convert.ToInt32(CurrQtyVal.Text) > Convert.ToInt32(ma_qty.Text)) { ShowMsg(0, "烧录数量已达标,超过工单批量"); ma_code.Focus(); return; } if (string.IsNullOrEmpty(EmployeeVal.Text)) { ShowMsg(0, "请输入操作人员"); ma_code.Focus(); return; } /*if (string.IsNullOrEmpty(LineVal.Text)) { ShowMsg(0, "请选择线体"); LineVal.Focus(); LineVal.SelectAll(); return; }*/ if (string.IsNullOrEmpty(BurnLotnoVal.Text)) { ShowMsg(0, "请扫描包批次号"); BurnLotnoVal.Focus(); BurnLotnoVal.SelectAll(); return; } dt = (DataTable)dh.ExecuteSql($@"select * from burn_info where burn_lotno = '{BurnLotnoVal.Text}'", "select"); if (dt.Rows.Count > 0) { ShowMsg(0, $"批号:{BurnLotnoVal.Text} 已记录,请勿重复使用"); return; } dh.ExecuteSql($@"insert INTO burn_info (burn_id,burn_lotno,burn_software, check_code,dot_detail,line,burn_qty, update_name,update_time,work_order,ic_detail,remark) VALUES (BURN_INFO_SEQ.nextval,'{BurnLotnoVal.Text.Trim()}','{BurnSwVal.Text.Trim()}', '{CheckCodeVal.Text.Trim()}','{DotVal.Text.Trim()}','{LineVal.Text.Trim()}','{remainQty}', '{EmployeeVal.Text}',sysdate,'{ma_code.Text.Trim()}','{IcDetailVal.Text.Trim()}','{RemarkVal.Text.Trim()}')", "insert"); BurnLotnoVal.Focus(); BurnLotnoVal.SelectAll(); BurnLotnoVal.Text = ""; /*BurnSwVal.Text = ""; CheckCodeVal.Text = ""; DotVal.Text = "";*/ ShowMsg(1, $"批号:{BurnLotnoVal.Text} 添加烧录信息成功"); dt = (DataTable)dh.ExecuteSql($"SELECT BURN_LOTNO,WORK_ORDER,LINE,BURN_SOFTWARE,CHECK_CODE,DOT_DETAIL,UPDATE_TIME,UPDATE_NAME,BURN_QTY,inspect_res,IC_DETAIL,burn_id,remark FROM burn_info LEFT JOIN burn_inspect ON burn_id = burnid WHERE work_order = '{ma_code.Text}'", "select"); DataBox.DataSource = dt; dt = (DataTable)dh.ExecuteSql($"select nvl(sum(burn_qty),0) allqty from burn_info where work_order = '{ma_code.Text}'", "select"); if (dt.Rows.Count > 0) { CurrQtyVal.Text = dt.Rows[0]["allqty"].ToString(); } } private void DeleteLog_Click(object sender, EventArgs e) { if (DataBox.SelectedRows.Count == 0) { ShowMsg(0, "请在列表选中需删除记录"); return; } string burn_id = DataBox.SelectedRows[0].Cells["burn_id"].Value?.ToString(); string burn_lotno = DataBox.SelectedRows[0].Cells["BURN_LOTNO"].Value?.ToString(); DialogResult res = MessageBox.Show($"确认删除烧录条码:{burn_lotno}","Warning",MessageBoxButtons.YesNo,MessageBoxIcon.Warning); if(res == DialogResult.Yes) { dh.ExecuteSql($"delete burn_info where burn_id = '{burn_id}'", "delete"); dt = (DataTable)dh.ExecuteSql($"SELECT BURN_LOTNO,WORK_ORDER,LINE,BURN_SOFTWARE,CHECK_CODE,DOT_DETAIL,UPDATE_TIME,UPDATE_NAME,BURN_QTY,inspect_res,IC_DETAIL,burn_id FROM burn_info LEFT JOIN burn_inspect ON burn_id = burnid WHERE work_order = '{ma_code.Text}'", "select"); DataBox.DataSource = dt; } } private void DataBox_SelectionChanged(object sender, EventArgs e) { if (DataBox.SelectedRows.Count > 0) { DeleteLog.Enabled = true; } else { DeleteLog.Enabled = false; } } private void SaveCache_Click(object sender, EventArgs e) { BaseUtil.SetCacheData("BurnInfoWo", ma_code.Text.Trim()); BaseUtil.SetCacheData("BurnInfo_BurnSwVal", BurnSwVal.Text.Trim()); BaseUtil.SetCacheData("BurnInfo_CheckCodeVal", CheckCodeVal.Text.Trim()); BaseUtil.SetCacheData("BurnInfo_DotVal", DotVal.Text.Trim()); BaseUtil.SetCacheData("BurnInfo_IcDetailVal", IcDetailVal.Text.Trim()); ShowMsg(1, $"已缓存工单: {ma_code.Text.Trim()} 输入信息"); } private void BurnSwVal_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode != Keys.Enter) return; CheckCodeVal.Focus(); CheckCodeVal.SelectAll(); } private void CheckCodeVal_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode != Keys.Enter) return; DotVal.Focus(); DotVal.SelectAll(); } private void DotVal_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode != Keys.Enter) return; Confirm.Focus(); } private void ClearMsg_Click(object sender, EventArgs e) { OperateResult.Clear(); } } }