using System; using System.Collections.Generic; using System.Data; using System.Drawing; 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.OQC { public partial class OQC_PlanMaintain : Form { AutoSizeFormClass asc = new AutoSizeFormClass(); LogStringBuilder sql = new LogStringBuilder(); DataTable dt; DataHelper dh; string ErrorMessage = ""; DataTable Dbfind; public OQC_PlanMaintain() { InitializeComponent(); } private void 抽样计划维护_Load(object sender, EventArgs e) { asc.controllInitializeSize(this); dh = SystemInf.dh; pr_code.TableName = "QUA_Project"; pr_code.SelectField = "pr_code # 方案编号,pr_name # 方案名称,pr_class # 检验单类型,pr_standard # 方案标准,pr_startdate # 生效日期,pr_enddate #失效日期 ,pr_status # 状态"; pr_code.SetValueField = new string[] { "pr_code" }; pr_code.FormName = Name; pr_code.DbChange += Pr_code_DbChange; al_code.TableName = "QUA_AQL"; al_code.DBTitle = "抽样标准查询"; al_code.SelectField = "al_code # 流水编号,AL_NAME # 检验标准名称"; al_code.SetValueField = new string[] { "al_code" }; al_code.FormName = Name; al_code.Condition = "al_statuscode='AUDITED'"; al_code.DbChange += Al_code_DbChange; ChooseAll.ChooseAll(CheckTypeDGV); } private void Al_code_DbChange(object sender, EventArgs e) { Dbfind = al_code.ReturnData; BaseUtil.SetFormValue(this.Controls, Dbfind); } private void Pr_code_DbChange(object sender, EventArgs e) { Dbfind = pr_code.ReturnData; BaseUtil.SetFormValue(this.Controls, Dbfind); } private void 抽样计划维护_SizeChanged(object sender, EventArgs e) { asc.controlAutoSize(this); } /// /// 获取批次点击按钮 /// /// /// private void GetBatch_Click(object sender, EventArgs e) { if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage)) { DataTable temp = dh.getFieldsDatasByCondition("makeserial", new string[] { "nvl(ms_ifrework,0)ms_ifrework", "ms_reworkcheckno" }, "(ms_sncode)='" + ms_sncode.Text.ToUpper() + "' order by ms_id desc"); if (temp.Rows.Count > 0) { if (temp.Rows[0]["ms_ifrework"].ToString() != "0") { ob_checkno.Text = temp.Rows[0]["ms_reworkcheckno"].ToString(); } } DataTable[] dt = LogicHandler.GetOQCBatch(ms_sncode.Text, obd_outboxcode.Text, ob_checkno.Text, "OQCPlanMaintain", out ErrorMessage); if (dt != null) { if (ErrorMessage == "") { ob_sampleqty.Text = ""; ob_maxngacceptqty.Text = ""; BaseUtil.SetFormValue(Controls, dt[0]); BaseUtil.FillDgvWithDataTable(CheckTypeDGV, dt[1]); al_code.Text = ""; al_code.Text = dt[0].Rows[0]["ob_aqlcode"].ToString(); } else { BaseUtil.CleanForm(this); OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red); ErrorMessage = ""; } } else { BaseUtil.CleanForm(this); OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red); } } else { OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red); } } private void SaveConfiguration_Click(object sender, EventArgs e) { if (ob_status.Text == "待检验") { sql.Clear(); sql.Append("select wm_concat(ms_sncode) sn from oqcbatch left join oqcbatchdetail on ob_id=obd_obid left join makeserial "); sql.Append("on ms_sncode=obd_sncode and obd_makecode=ms_makecode where ob_checkno='" + ob_checkno.Text + "' and ms_downstatus<>0"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); if (dt.Rows[0]["sn"].ToString() != "") { OperateResult.AppendText(">>批次含有序列号" + dt.Rows[0]["sn"].ToString() + "处于下地状态,不允许保存抽样计划\n", Color.Red); return; } if (ob_source.Text == "返工" && ob_reworkcode.Text != "") { dt = (DataTable)dh.ExecuteSql("select re_id from rework where re_code='" + ob_reworkcode.Text + "' and nvl(re_nullngfinsh,0)=0", "select"); if (dt.Rows.Count > 0) { sql.Clear(); sql.Append("select count(1),wm_concat(obd_sncode) sn from oqcbatchdetail left join makeserial "); sql.Append("on ms_sncode=obd_sncode and ms_reworkcheckno=obd_checkno where obd_checkno"); sql.Append("='" + ob_checkno.Text + "'and ms_nextstepcode<>'" + User.CurrentStepCode + "' and rownum<20"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); if (dt.Rows[0]["sn"].ToString() != "") { OperateResult.AppendText(">>序列号" + dt.Rows[0]["sn"].ToString() + "下一道不是OQC工序\n", Color.Red); return; } } } //新增的数据 List oi_id = new List(); List ci_kind = new List(); List oi_sampleqty = new List(); //更新的数据 List ci_kind_update = new List(); List oi_sampleqty_update = new List(); int ChooseCount = 0; for (int i = 0; i < CheckTypeDGV.Rows.Count; i++) { //用户勾选的数据才进行操作 if (CheckTypeDGV.Rows[i].Cells["Choose"].FormattedValue.ToString() == "True") { ChooseCount = ChooseCount + 1; if (int.Parse(CheckTypeDGV.Rows[i].Cells["oi_sampleqty"].Value.ToString()) > 0) { if (!(int.Parse(CheckTypeDGV.Rows[i].Cells["oi_sampleqty"].Value.ToString()) > int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text))) { oi_id.Add(CheckTypeDGV.Rows[i].Cells["oi_id"].Value.ToString()); ci_kind.Add(CheckTypeDGV.Rows[i].Cells["ci_kind"].Value.ToString()); oi_sampleqty.Add(CheckTypeDGV.Rows[i].Cells["oi_sampleqty"].Value.ToString()); } else { OperateResult.AppendText(">>第" + (i + 1) + "行的数量大于送检批数量\n", Color.Red); return; } } else { OperateResult.AppendText(">>第" + (i + 1) + "行的抽样数量必需大于0\n", Color.Red); return; } } } if (ChooseCount == 0) { OperateResult.AppendText(">>请勾选检验项目\n", Color.Red); return; } //如果ID为0的数组存在内容则进行插入操作 dh.ExecuteSql("delete from oqcitems where oi_checkno='" + ob_checkno.Text + "'", "delete"); if (oi_id.Count > 0) { sql.Clear(); sql.Append("insert into OQCItems(oi_id,oi_checkno, oi_projectcode,oi_batchqty ,oi_checkkind,oi_sampleqty,oi_itemcode) select "); sql.Append("OQCItems_seq.nextval,'" + ob_checkno.Text + "','" + pr_code.Text + "','" + ob_nowcheckqty.Text + "',:ci_kind,"); sql.Append(":oi_sampleqty,ci_code from QUA_PROJECT left join QUA_PROJECTDETAIL on pd_prid=pr_id "); sql.Append("LEFT JOIN QUA_CHECKITEM ON PD_CIID=CI_ID where pr_code='" + pr_code.Text + "' and ci_kind=:ci_kind1"); dh.BatchInsert(sql.GetString(), new string[] { "ci_kind", "oi_sampleqty", "ci_kind1" }, ci_kind.ToArray(), oi_sampleqty.ToArray(), ci_kind.ToArray()); //更新物料资料的抽检方案未当前选取的 dh.UpdateByCondition("product", "pr_qualmethod='" + pr_code.Text + "'", "pr_code='" + ob_prodcode.Text + "'"); LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, "", User.UserLineCode, User.UserSourceCode, "OQC抽样计划采集保存抽样计划", "成功", ms_sncode.Text, ob_checkno.Text); } OperateResult.AppendText(">>批次" + ob_checkno.Text + "保存抽样计划成功\n", Color.Green); } else OperateResult.AppendText(">>送检批次必须为待检验状态\n", Color.Red); } private void Save_Click(object sender, EventArgs e) { if (al_code.Text != "" || ob_maxngacceptqty.Text != "") { if (dh.getFieldDataByCondition("oqcbatch", "ob_status", "ob_checkno='" + ob_checkno.Text + "'").ToString() == "UNCHECK") { if (Checkob_maxngacceptqty()) { SaveConfiguration_Click(sender, e); } } else OperateResult.AppendText(">>送检批次必须为待检验状态\n", Color.Red); } else OperateResult.AppendText(">>AQL和最大不合格允许通过数至少填写一个\n", Color.Red); } //对于最大不合格允通过数的校验 private bool Checkob_maxngacceptqty() { if (int.Parse(ob_maxngacceptqty.Text == "" ? "0" : ob_maxngacceptqty.Text) < 0) { OperateResult.AppendText(">>最大不合格允通过数必须大于等于0\n", Color.Red); ob_maxngacceptqty.Text = null; return false; } else { if (ob_maxngacceptqty.Text == "") { ob_maxngacceptqty.Text = dh.getFieldDataByCondition("QUA_Aql left join qua_aqldetail on ad_alid=al_id", "nvl(ad_maxngacceptqty,0)", "al_code='" + al_code.Text + "' and ad_minqty<='" + ob_nowcheckqty.Text + "' and ad_maxqty>='" + ob_nowcheckqty.Text + "'").ToString(); } if (int.Parse(ob_maxngacceptqty.Text == "" ? "0" : ob_maxngacceptqty.Text) > int.Parse(ob_sampleqty.Text == "" ? "0" : ob_sampleqty.Text)) { OperateResult.AppendText(">>最大不合格通过数不允许大于抽检数\n", Color.Red); return false; } int result = (int)dh.ExecuteSql("update OQCBatch set ob_projectcode='" + pr_code.Text + "',ob_remark = '" + ob_remark.Text + "',ob_aqlcode='" + al_code.Text + "',ob_maxngacceptqty='" + ob_maxngacceptqty.Text + "',ob_actsampleqty='" + ob_sampleqty.Text + "' where ob_checkno='" + ob_checkno.Text + "' ", "update"); return result > 0; } } private void Clean_Click(object sender, EventArgs e) { OperateResult.Clear(); } private void ob_checkno_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 obd_outboxcode_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) GetBatch.PerformClick(); } private void ob_aqlcode_UserControlTextChanged(object sender, EventArgs e) { if (al_code.Text != "") { sql.Clear(); sql.Append("select nvl(ad_minqty,0)ad_minqty,nvl(ad_maxqty,0)ad_maxqty,nvl(ad_maxngacceptqty,0)ad_maxngacceptqty,ad_qty from QUA_Aql "); sql.Append("left join qua_aqldetail on ad_alid=al_id where al_code='" + al_code.Text + "' and ad_minqty<='" + ob_nowcheckqty.Text + "' and ad_maxqty>='" + ob_nowcheckqty.Text + "'"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); if (dt.Rows.Count > 0) { ob_maxngacceptqty.Text = dt.Rows[0]["ad_maxngacceptqty"].ToString(); ob_sampleqty.Text = dt.Rows[0]["ad_qty"].ToString(); } else { ob_maxngacceptqty.Text = ""; ob_sampleqty.Text = ""; } } } private void ad_qty_TextChanged_1(object sender, EventArgs e) { for (int i = 0; i < CheckTypeDGV.Rows.Count; i++) { CheckTypeDGV.Rows[i].Cells["oi_sampleqty"].Value = ob_sampleqty.Text; } } private void ob_projectcode_UserControlTextChanged(object sender, EventArgs e) { sql.Clear(); sql.Append("select nvl(max(oi_id),0)oi_id,ci_kind,nvl(max(oi_sampleqty),0) oi_sampleqty from QUA_PROJECT left join "); sql.Append(" QUA_ProjectDetail on pd_prid=pr_id left join QUA_CheckItem on pd_ciid=ci_id "); sql.Append("left join OQCITEMS on oi_checkno ='" + ob_checkno.Text + "' and oi_projectcode='" + pr_code.Text + "' "); sql.Append("and oi_projectcode = pr_code and oi_checkkind = ci_kind where pr_code='" + pr_code.Text + "' group by ci_kind"); DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); BaseUtil.FillDgvWithDataTable(CheckTypeDGV, dt); } private void OQC_PlanMaintain_FormClosing(object sender, FormClosingEventArgs e) { dh.Dispose(); } private void CheckTypeDGV_DataSourceChanged(object sender, EventArgs e) { //更换抽检方案后保持抽选状态和检验数量 for (int i = 0; i < CheckTypeDGV.Rows.Count; i++) { CheckTypeDGV.Rows[i].Cells["Choose"].Value = true; CheckTypeDGV.Rows[i].Cells["oi_sampleqty"].Value = ob_sampleqty.Text; } } private void normalButton1_Click(object sender, EventArgs e) { ob_checkno.Clear(); ms_sncode.Focus(); ms_sncode.SelectAll(); } } }