using System;
using System.Data;
using System.Windows.Forms;
using System.Drawing;
using UAS_MES_NEW.PublicMethod;
using UAS_MES_NEW.DataOperate;
using System.Text;
using UAS_MES_NEW.Entity;
using System.Collections.Generic;
namespace UAS_MES_NEW.OQC
{
public partial class OQC_BatchResultJudge : Form
{
AutoSizeFormClass asc = new AutoSizeFormClass();
DataHelper dh;
LogStringBuilder sql = new LogStringBuilder();
DataTable dt;
string ErrorMessage = "";
///
/// 是否通过资源验证
///
bool PassCheckStep = false;
public OQC_BatchResultJudge()
{
InitializeComponent();
}
private void 抽检批维护_Load(object sender, EventArgs e)
{
dh = SystemInf.dh;
ob_checkno.Focus();
asc.controllInitializeSize(this);
}
private void GetBatch_Click(object sender, EventArgs e)
{
if (CheckStep())
{
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();
}
}
PassCheckStep = true;
string ErrorMessage = "";
DataTable[] dt = LogicHandler.GetOQCBatch(ms_sncode.Text, obd_outboxcode.Text, ob_checkno.Text, "OQCResultDetermine", out ErrorMessage);
if (ErrorMessage == "")
{
BaseUtil.SetFormValue(Controls, dt[0]);
switch (ob_result.Text)
{
case "OK":
BatchPass.Enabled = false;
BatchRejection.Enabled = false;
ForcePass.Enabled = false;
ForceRejection.Enabled = false;
WithdrawPass.Enabled = true;
WithdrawRejection.Enabled = false;
break;
case "FOK":
BatchPass.Enabled = false;
BatchRejection.Enabled = false;
ForcePass.Enabled = false;
ForceRejection.Enabled = false;
WithdrawPass.Enabled = true;
WithdrawRejection.Enabled = false;
break;
case "NG":
BatchPass.Enabled = false;
BatchRejection.Enabled = false;
ForcePass.Enabled = false;
ForceRejection.Enabled = false;
WithdrawPass.Enabled = false;
WithdrawRejection.Enabled = true;
break;
case "FNG":
BatchPass.Enabled = false;
BatchRejection.Enabled = false;
ForcePass.Enabled = false;
ForceRejection.Enabled = false;
WithdrawPass.Enabled = false;
WithdrawRejection.Enabled = true;
break;
case "":
if (ob_checkno.Text != "")
{
BatchPass.Enabled = true;
BatchRejection.Enabled = true;
ForcePass.Enabled = true;
ForceRejection.Enabled = true;
WithdrawPass.Enabled = true;
WithdrawRejection.Enabled = true;
}
break;
default:
break;
}
}
else
{
BaseUtil.CleanForm(this);
BatchPass.Enabled = false;
BatchRejection.Enabled = false;
ForcePass.Enabled = false;
ForceRejection.Enabled = false;
WithdrawPass.Enabled = false;
WithdrawRejection.Enabled = false;
OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
}
}
else
{
PassCheckStep = false;
}
}
private void BatchPass_Click(object sender, EventArgs e)
{
string ReworkCode = "";
if (CheckBefore() && PassCheckStep)
{
if (int.Parse(ob_ngqty.Text == "" ? "0" : ob_ngqty.Text) <= int.Parse(ob_maxngacceptqty.Text == "" ? "0" : ob_maxngacceptqty.Text))
{
if (LogicHandler.OQCBatchJudge(ob_checkno.Text, User.UserSourceCode, "OK", "", User.UserCode, Remark.Text, out ReworkCode, out ErrorMessage))
{
LogicHandler.DoCommandLog(Tag.ToString(),User.UserCode,"",User.UserLineCode,User.UserSourceCode,"通过批", "抽检批: "+ ob_checkno.Text+"通过","",ob_checkno.Text);
OperateResult.AppendText(">>通过批成功\n", Color.Green);
GetBatch.PerformClick();
}
else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
}
else
OperateResult.AppendText(">>当前批次不合格数为" + ob_ngqty.Text + ",大于最大不合格允通过数" + ob_maxngacceptqty.Text + "\n", Color.Red);
}
}
private void BatchRejection_Click(object sender, EventArgs e)
{
string ReworkCode = "";
if (CheckBefore() && PassCheckStep)
{
if (LogicHandler.OQCBatchJudge(ob_checkno.Text, User.UserSourceCode, "NG", ReworkRequire.Checked ? "Y" : "N", User.UserCode, Remark.Text, out ReworkCode, out ErrorMessage))
{
OperateResult.AppendText(">>判退批成功\n", Color.Green);
LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, "", User.UserLineCode, User.UserSourceCode, "判退批", "抽检批: " + ob_checkno.Text + "判退", "", ob_checkno.Text);
if (ReworkRequire.Checked)
{
dh.UpdateByCondition("oqcbatch", "ob_reworkcode='" + ReworkCode + "'", "ob_checkno='" + ob_checkno.Text + "'");
OperateResult.AppendText(">>生成返工需求单" + ReworkCode + "\n", Color.Green);
}
GetBatch.PerformClick();
}
else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
}
}
private void ForcePass_Click(object sender, EventArgs e)
{
string ReworkCode = "";
if (PassCheckStep)
{
if (LogicHandler.OQCBatchJudge(ob_checkno.Text, User.UserSourceCode, "FOK", "", User.UserCode, Remark.Text, out ReworkCode, out ErrorMessage))
{
LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, "", User.UserLineCode, User.UserSourceCode, "强制通过批", "抽检批: " + ob_checkno.Text + "强制通过", "", ob_checkno.Text);
OperateResult.AppendText(">>强制通过批" + ob_checkno.Text + "成功\n", Color.Green);
GetBatch.PerformClick();
}
else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
}
}
private void ForceRejection_Click(object sender, EventArgs e)
{
string ReworkCode = "";
if (PassCheckStep)
{
if (LogicHandler.OQCBatchJudge(ob_checkno.Text, User.UserSourceCode, "FNG", ReworkRequire.Checked ? "Y" : "N", User.UserCode, Remark.Text, out ReworkCode, out ErrorMessage))
{
OperateResult.AppendText(">>强制退批" + ob_checkno.Text + "成功\n", Color.Green);
LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, "", User.UserLineCode, User.UserSourceCode, "强制退批", "抽检批: " + ob_checkno.Text + "强制退批", "", ob_checkno.Text);
if (ReworkRequire.Checked)
{
dh.UpdateByCondition("oqcbatch", "ob_reworkcode='" + ReworkCode + "'", "ob_checkno='" + ob_checkno.Text + "'");
OperateResult.AppendText(">>生成返工需求单" + ReworkCode + "\n", Color.Green);
}
GetBatch.PerformClick();
}
else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
}
}
private void WithdrawPass_Click(object sender, EventArgs e)
{
string ReworkCode = "";
if (PassCheckStep)
{
if (ob_result.Text == "OK" || ob_result.Text == "FOK")
{
if (LogicHandler.OQCBatchJudge(ob_checkno.Text, User.UserSourceCode, "REOK", "", User.UserCode, Remark.Text, out ReworkCode, out ErrorMessage))
{
LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, "", User.UserLineCode, User.UserSourceCode, "撤销通过批", "抽检批: " + ob_checkno.Text + "撤销通过", "", ob_checkno.Text);
OperateResult.AppendText(">>撤销通过批" + ob_checkno.Text + "成功\n", Color.Green);
GetBatch.PerformClick();
}
else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
}
else OperateResult.AppendText(">>该抽检批次未通过,无需撤销通过\n", Color.Red);
}
}
private void WithdrawRejection_Click(object sender, EventArgs e)
{
string ReworkCode = "";
if (PassCheckStep)
{
if (ob_result.Text == "NG" || ob_result.Text == "FNG")
{
dt = (DataTable)dh.ExecuteSql("select re_statuscode from rework where re_checkno='" + ob_checkno.Text + "'", "select");
if (dt.Rows.Count > 0)
{
if (dt.Rows[0]["re_statuscode"].ToString() == "AUDITED")
{
OperateResult.AppendText(">>该批次存在已审核的返修工单,不允许撤销\n", Color.Red);
return;
}
else
{
string logout_confirm = MessageBox.Show("已存在返修工单,撤销会删除该工单,是否继续", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
if (logout_confirm == "Yes")
{
if (LogicHandler.OQCBatchJudge(ob_checkno.Text, User.UserSourceCode, "RENG", "", User.UserCode, Remark.Text, out ReworkCode, out ErrorMessage))
{
LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, "", User.UserLineCode, User.UserSourceCode, "撤销判退", "抽检批: " + ob_checkno.Text + "撤销判退", "", ob_checkno.Text);
OperateResult.AppendText(">>撤销判退成功\n", Color.Green);
ob_result.Text = "";
GetBatch.PerformClick();
}
else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
}
else return;
}
}
else
{
if (LogicHandler.OQCBatchJudge(ob_checkno.Text, User.UserSourceCode, "RENG", "", User.UserCode, Remark.Text, out ReworkCode, out ErrorMessage))
{
OperateResult.AppendText(">>撤销判退成功\n", Color.Green);
ob_result.Text = "";
GetBatch.PerformClick();
}
else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
}
}
else OperateResult.AppendText(">>该抽检批次未判退,无需撤销判退\n", Color.Red);
}
}
private void Clean_Click(object sender, EventArgs e)
{
OperateResult.Clear();
}
///
/// 操作之前通用的验证逻辑
///
///
private bool CheckBefore()
{
if (ob_status.Text == "检验中")
{
if (ob_maxngacceptqty.Text == "")
{
if (ob_aqlcode.Text == "")
OperateResult.AppendText(">>AQL标准为空的时候必须填写最大不合格允许通过数\n", Color.Red);
else
{
sql.Clear();
sql.Append("select nvl(ad_minqty,0)ad_minqty,nvl(ad_maxqty,0)ad_maxqty,nvl(ad_maxngacceptqty,0) ");
sql.Append("ad_maxngacceptqty from QUA_Aql left join qua_aqldetail on ad_alid=al_id where ");
sql.Append("al_code='" + ob_aqlcode.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();
return true;
}
}
}
else
{
return true;
}
}
else OperateResult.AppendText(">>状态未在检验中的批次不允许进行判断\n", Color.Red);
return false;
}
private bool CheckStep()
{
if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
{
return true;
}
else
{
OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
return false;
}
}
private void 抽检批维护_SizeChanged(object sender, EventArgs e)
{
asc.controlAutoSize(this);
}
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)
{
//因为通过序列号获取的时候会带出送检批次,获取数据的方法根据送检批次为主
//所以在通过序列号获取的时候要清除界面数据
string sncode = ms_sncode.Text;
BaseUtil.CleanForm(this);
ms_sncode.Text = sncode;
GetBatch.PerformClick();
}
}
private void obd_outboxcode_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
GetBatch.PerformClick();
}
private void OQC_BatchResultJudge_FormClosing(object sender, FormClosingEventArgs e)
{
dh.Dispose();
}
private void normalButton1_Click(object sender, EventArgs e)
{
if (ob_checkno.Text != "")
{
dh.UpdateByCondition("oqcbatch", "ob_remark = '" + Remark.Text + "'", "ob_checkno = '" + ob_checkno.Text + "'");
OperateResult.AppendText(">>抽检批" + ob_checkno.Text + "备注维护完成\n", Color.Green);
}
else
{
OperateResult.AppendText(">>抽检批号不可为空\n", Color.Red);
}
}
}
}