using System; using System.Collections.Generic; using System.Data; using System.Text; using System.Drawing; using System.Windows.Forms; using UAS_MES_NEW.CustomControl.DataGrid_View; using UAS_MES_NEW.DataOperate; using UAS_MES_NEW.Entity; using UAS_MES_NEW.PublicMethod; namespace UAS_MES_NEW.OQC { public partial class OQC_Inspection : Form { AutoSizeFormClass asc = new AutoSizeFormClass(); DataHelper dh; LogStringBuilder sql = new LogStringBuilder(); DataTable dt; //用来存放已打开过的行 List dgvr = new List(); string ErrorMessage = ""; public OQC_Inspection() { InitializeComponent(); } private void 生成送检批_Load(object sender, EventArgs e) { asc.controllInitializeSize(this); dh = SystemInf.dh; //工单号放大镜配置 ma_code.TableName = "make"; ma_code.SelectField = "ma_code # 工单号,ma_prodcode # 产品编号"; ma_code.FormName = Name; ma_code.SetValueField = new string[] { "ma_code", "ma_prodcode" }; ma_code.Condition = "ma_statuscode='STARTED'"; } private void Clean_Click(object sender, EventArgs e) { OperateResult.Clear(); } private void NewBatch_Click(object sender, EventArgs e) { if (CheckStep()) { string ob_id = dh.GetSEQ("OQCBatch_SEQ"); string checkno = ""; LogicHandler.GetSerialNumByCaller("Make!CheckQC", out checkno); sql.Clear(); sql.Append("insert into OQCBatch (ob_id, ob_checkno ,ob_status, ob_source,ob_indate,ob_checkman) "); sql.Append("values( '" + ob_id + "','" + checkno + "', 'ENTERING', '新增', sysdate, '" + User.UserName + "')"); dh.ExecuteSql(sql.GetString(), "insert"); LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "生成新品", "生成新批次成功", "", ob_checkno.Text); //生成成功,将批次号,以及批次状态写入页面 BaseUtil.SetFormValue(Controls, dh.getFieldsDataByCondition("OQCBatch", new string[] { "ob_checkno", "ob_status" }, "ob_id='" + ob_id + "'")); } } private void 生成送检批_SizeChanged(object sender, EventArgs e) { asc.controlAutoSize(this); } private void bi_outboxcode_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { //只允许用户操作在录入状态的箱号 if (ob_status.Text == "在录入") { //如果勾选了撤销 if (WithDraw.Checked) { dt = (DataTable)dh.ExecuteSql("select obd_obid from OQCBatchDetail where obd_outboxcode='" + pa_outboxcode.Text + "'", "select"); if (dt.Rows.Count > 0) { dh.ExecuteSql("delete from OQCBatchDetail where obd_outboxcode='" + pa_outboxcode.Text + "'", "delete"); dh.UpdateByCondition("OQCBatch", "ob_batchqty =(select count(1) from OQCBatchDetail where obd_checkno='" + ob_checkno.Text + "')", "ob_checkno='" + ob_checkno.Text + "'"); dh.UpdateByCondition("OQCBatch", "ob_prodcode=''", "ob_batchqty=0"); GetBatch.PerformClick(); OperateResult.AppendText(">>箱号已从送检批中移除\n", Color.Green); } else OperateResult.AppendText(">>箱号不在抽检明细中\n", Color.Red); } //未勾选撤销 else { dt = (DataTable)dh.ExecuteSql("select pa_prodcode,pa_makecode from package where pa_outboxcode='" + pa_outboxcode.Text + "'", "select"); if (dt.Rows.Count > 0) { string pa_prodcode = dt.Rows[0]["pa_prodcode"].ToString(); string pa_makecode = dt.Rows[0]["pa_makecode"].ToString(); if (dt.Rows[0]["pa_prodcode"].ToString() == ma_prodcode.Text || ma_prodcode.Text == "") { dt = dh.getFieldsDataByCondition("OQCBatchDetail", new string[] { "obd_checkno" }, "obd_outboxcode='" + pa_outboxcode.Text + "'"); //如果不存在送检批中 if (dt.Rows.Count == 0) { if (ma_prodcode.Text == "") { dh.UpdateByCondition("Oqcbatch", "ob_prodcode='" + pa_prodcode + "'", "ob_checkno='" + ob_checkno.Text + "'"); } if (pa_makecode == "") { string macode = dh.getFieldDataByCondition("packagedetail", "pd_makecode", "pd_outboxcode='" + pa_outboxcode.Text + "'").ToString(); dh.UpdateByCondition("Oqcbatch", "ob_makecode='" + pa_makecode + "'", "ob_checkno='" + ob_checkno.Text + "'"); } sql.Clear(); sql.Append("insert into OQCBatchDetail (obd_id,obd_obid,obd_checkno, obd_sncode,obd_outboxcode,"); sql.Append("obd_makecode, obd_builddate) select OQCBatchDetail_seq.nextval,(select ob_id from OQCBatch where ob_checkno='" + ob_checkno.Text + "'),'" + ob_checkno.Text + "',v_barcode"); sql.Append(",v_outboxcode,v_makecode,sysdate from MES_PACKAGE_VIEW where v_outboxcode='" + pa_outboxcode.Text + "'"); dh.ExecuteSql(sql.GetString(), "insert"); string obd_id = dh.getFieldDataByCondition("OQCBatchDetail", "obd_id", "obd_outboxcode='" + pa_outboxcode.Text + "'").ToString(); dh.UpdateByCondition("OQCBatch", "ob_nowcheckqty =(select count(1) from OQCBatchDetail where obd_checkno='" + ob_checkno.Text + "')", "ob_checkno='" + ob_checkno.Text + "'"); dh.UpdateByCondition("makeserial", "ms_checkno='" + ob_checkno.Text + "'", "ms_outboxcode='" + pa_outboxcode.Text + "'"); GetBatch.PerformClick(); LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "生成新品", pa_outboxcode.Text + "成功维护到送检批", "", ob_checkno.Text); OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "成功维护到送检批\n", Color.Green, pa_outboxcode); } //存在则进行提示 else OperateResult.AppendText(">>箱号已存在送检批" + dt.Rows[0]["obd_checkno"] + "中\n", Color.Red, pa_outboxcode); } else OperateResult.AppendText(">>箱内产品与抽检批次产品不一致\n", Color.Red, pa_outboxcode); } else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "不存在\n", Color.Red, pa_outboxcode); } } else OperateResult.AppendText(">>只允许在录入状态的抽检批才允许操作\n", Color.Red, pa_outboxcode); } } private void GetBatch_Click(object sender, EventArgs e) { if (CheckStep()) { DataTable[] dt = LogicHandler.GetOQCBatch(ms_sncode.Text, obd_outboxcode.Text, ob_checkno.Text, "OQCSendCheck", out ErrorMessage); if (ErrorMessage == "") { BaseUtil.SetFormValue(Controls, dt[0]); BaseUtil.FillDgvWithDataTable(CheckBatchDGV, dt[1]); } else { BaseUtil.CleanForm(this); OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red); } } } private void dataGridViewExpand1_DataError(object sender, DataGridViewDataErrorEventArgs e) { } private bool CheckStep() { if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage)) { return true; } else { OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red); return false; } } /// /// 全选Grid中的数据,对展开时包含明细也进行了判断 /// /// /// private void ChooseAll_Click(object sender, EventArgs e) { if (!CheckNoSourceCheck()) { OperateResult.AppendText(">>自动生成的批次只允许点击送检\n", Color.Red); return; } for (int i = 0; i < CheckBatchDGV.Rows.Count; i++) { if (CheckBatchDGV.Rows[i].Cells[0] is DataGridViewCheckBoxCell) { if (CheckBatchDGV.Rows[i].Cells[0].Value == null || (bool)CheckBatchDGV.Rows[i].Cells[0].Value == false) { CheckBatchDGV.Rows[i].Cells[0].Value = true; } else { CheckBatchDGV.Rows[i].Cells[0].Value = false; } } } } private void RemoveAll_Click(object sender, EventArgs e) { if (!CheckNoSourceCheck()) { OperateResult.AppendText(">>自动生成的批次只允许点击送检\n", Color.Red); return; } if (CheckBatchDGV.Rows.Count > 0) { if (MessageBox.Show(this.ParentForm, "确认移除全部箱号?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString() == "Yes") { DataTable dt = (DataTable)dh.ExecuteSql("select ob_status,ob_source from OQCBatch where ob_checkno='" + ob_checkno.Text + "'", "select"); if (dt.Rows.Count > 0) { if (dt.Rows[0]["ob_status"].ToString() == "ENTERING") { List DeleteID = new List(); //判断有多少勾选了 for (int i = 0; i < CheckBatchDGV.Rows.Count; i++) DeleteID.Add(CheckBatchDGV.Rows[i].Cells["obd_id"].Value.ToString()); if (DeleteID.Count > 0) { //删除全部明细 dh.DeleteDataByID("OQCBatchDetail", "obd_id", DeleteID.ToArray()); dh.UpdateByCondition("OQCBatch", "ob_nowcheckqty=0,ob_prodcode=''", "ob_checkno='" + ob_checkno.Text + "'"); GetBatch.PerformClick(); BaseUtil.CleanControlsText(ob_batchqty, obd_outboxcode); OperateResult.AppendText(">>批次" + ob_checkno.Text + "已全部移除\n", Color.Green); } } else OperateResult.AppendText(">>只允许移除在录入状态的抽检品的箱号\n", Color.Red); } else OperateResult.AppendText(">>抽检批次号不存在\n", Color.Red); } } } /// /// 删除当前的单据 /// /// /// private void Delete_Click(object sender, EventArgs e) { if (!CheckNoSourceCheck()) { OperateResult.AppendText(">>自动生成的批次只允许点击送检\n", Color.Red); return; } if (dh.CheckExist("OQCBatch", "ob_checkno='" + ob_checkno.Text + "'") && ob_status.Text == "在录入") { dh.ExecuteSql("delete from OQCBatch where ob_checkno='" + ob_checkno.Text + "'", "delete"); dh.ExecuteSql("delete from OQCBatchDetail where obd_checkno='" + ob_checkno.Text + "'", "delete"); OperateResult.AppendText(">>抽检批次" + ob_checkno.Text + "已删除\n", Color.Green); BaseUtil.CleanForm(this); } else OperateResult.AppendText(">>抽检批次不存在或者单据状态不是在录入\n", Color.Red); } /// /// 送检按钮 /// /// /// private void SendOQC_Click(object sender, EventArgs e) { if (dh.CheckExist("OQCBatch", "ob_checkno='" + ob_checkno.Text + "'") && ob_status.Text == "在录入") { dh.UpdateByCondition("OQCBatch", "ob_status='UNCHECK'", "ob_checkno='" + ob_checkno.Text + "'"); OperateResult.AppendText(">>抽检批次" + ob_checkno.Text + "已送检\n", Color.Green); } else { BaseUtil.CleanForm(this); OperateResult.AppendText(">>抽检批次不存在或者单据状态不是在录入\n", Color.Red); } } private void ob_checkno_TextChanged(object sender, EventArgs e) { if (ob_checkno.Text != "") SendOQC.Enabled = true; else SendOQC.Enabled = false; } private void ob_checkno_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) GetBatch.PerformClick(); } private void obd_outboxcode_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) GetBatch.PerformClick(); } private void ms_sncode_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) GetBatch.PerformClick(); } private void OQC_Inspection_FormClosing(object sender, FormClosingEventArgs e) { dh.Dispose(); } private bool CheckNoSourceCheck() { if (ob_source.Text != "") { if (ob_source.Text == "工序") { return false; } } return true; } } }