123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321 |
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Text;
- using System.Drawing;
- using System.Windows.Forms;
- using UAS_MES.CustomControl.DataGrid_View;
- using UAS_MES.DataOperate;
- using UAS_MES.Entity;
- using UAS_MES.PublicMethod;
- namespace UAS_MES.OQC
- {
- public partial class OQC_Inspection : Form
- {
- AutoSizeFormClass asc = new AutoSizeFormClass();
- DataHelper dh;
- LogStringBuilder sql = new LogStringBuilder();
- DataTable dt;
- //用来存放已打开过的行
- List<DataGridViewRow> dgvr = new List<DataGridViewRow>();
- 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, "生成新品", "生成新批次成功", "", checkno);
- //生成成功,将批次号,以及批次状态写入页面
- 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;
- }
- }
- /// <summary>
- /// 全选Grid中的数据,对展开时包含明细也进行了判断
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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<string> DeleteID = new List<string>();
- //判断有多少勾选了
- 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);
- }
- }
- }
- /// <summary>
- /// 删除当前的单据
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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);
- }
- /// <summary>
- /// 送检按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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_breakingdate=sysdate", "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;
- }
- }
- }
|