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 CoreFS.CA06;
using Pur.Entity;
using System.Collections;
using Core.Mes.Client.Comm.Tool;
using Pur.Entity.configureEntity;
using Core.Mes.Client.Comm.Control;
using com.hnshituo.pur.vo;
using Pur.Entity.ck;
using Infragistics.Win;
using Pur.require_plan;
namespace Pur.ck
{
public partial class frmCheckItem : FrmPmsBase
{
public frmCheckItem()
{
InitializeComponent();
}
//菜单按钮事件
public override void ToolBar_Click(object sender, string ToolbarKey)
{
switch (ToolbarKey)
{
case "Query":
GetCkInBill();
break;
case "RecReceiveAll"://全部接收
RecReceiveAll();
break;
case "RecReceivePortion"://部分接收
RecReceivePortion();
break;
case "RecReceiveBack"://让步接收
RecReceiveBack();
break;
case "RecReturn"://拒收
RecReturn();
break;
}
}
///
/// 全部接收
///
private void RecReceiveAll()
{ checkRec("1"); }
///
/// 部分接收
///
private void RecReceivePortion()
{ checkRec("2"); }
///
/// 让步接收
///
private void RecReceiveBack()
{ checkRec("3"); }
///
/// 拒收
///
private void RecReturn()
{ checkRec("4"); }
///
/// 查询
///
private void GetCkInBill()
{
PurCkRecBillEntity pcibEntity = new PurCkRecBillEntity();
pcibEntity.Status = "2";//只查询已初检的收货单
DataTable dt = this.execute("com.hnshituo.pur.ck.service.CkRecBillService", "GetCkRecBill", new object[] { pcibEntity });
//按创建时间降序
if (dt.Rows.Count != 0)
{
dt.DefaultView.Sort = "CREATETIME DESC";
dt = dt.DefaultView.ToTable();
}
GridHelper.CopyDataToDatatable(dt, dataTable1, true);
}
///
/// 查询
///
private void GetPUR_CK_STORAGE()
{
CkStorage CkSto = new CkStorage();
CkSto.OrderId = txt_ORDER_ID.Text;
CkSto.RefeId = txt_RefeId.Text;
CkSto.RefType = "3";
if (!string.IsNullOrEmpty(txt_createTimeS.Text) && !string.IsNullOrEmpty(txt_createTimeE.Text))
{
CkSto.CreateTime = Convert.ToDateTime(txt_createTimeS.Text);
CkSto.UpdateTime = Convert.ToDateTime(txt_createTimeE.Text).AddDays(1);
}
DataTable dt = this.execute("com.hnshituo.pur.ck.service.CkStorageService", "find_Storage", new object[] { CkSto });
GridHelper.CopyDataToDatatable(dt, dataTable7, true);
}
///
/// 获取质检头信息
///
private void getCkLimsM()
{
PurCkLimsMEntity CkLimsMEntity = new PurCkLimsMEntity();
CkLimsMEntity.InspectCode = txt_INSPECT_CODE_Query.Text;
CkLimsMEntity.BatchNo = txt_BATCH_NO_Query.Text;
DataTable dt = this.execute("com.hnshituo.pur.ck.service.CkLimsMService", "getCkLimsM", new object[] { CkLimsMEntity});
GridHelper.CopyDataToDatatable(dt, dataTable8, true);
}
///
/// 获取质检行信息
///
private void getCkLimsC(string strInspectCode)
{
PurCkLimsCEntity CkLimsCEntity = new PurCkLimsCEntity();
CkLimsCEntity.InspectCode = strInspectCode;
CkLimsCEntity.Validflag = "1";
DataTable dt = this.execute("com.hnshituo.pur.ck.service.CkLimsCService", "find", new object[] { CkLimsCEntity, 0, 0 });
GridHelper.CopyDataToDatatable(dt, dataTable3, true);
}
///
/// 开始初检
///
private void checkRec(string strRecieveMode)
{
//ultraGrid1.UpdateData();
ArrayList alCkRecBillEntity = new ArrayList();
// for (int i = 0; i < ultraGrid1.Rows.Count; i++)
//{
PurCkRecBillEntity CkRecBillEntity = new PurCkRecBillEntity();
//CkRecBillEntity.RecId = ultraGrid1.Rows[i].Cells["RecId"].Value.ToString();
CkRecBillEntity.RecCls = strRecieveMode;//接收方式
CkRecBillEntity.Status = "3";
alCkRecBillEntity.Add(CkRecBillEntity);
// }
CoreResult crt = this.execute("com.hnshituo.pur.ck.service.CkRecBillService", "checkRec", new object[] { alCkRecBillEntity });
if (crt.Resultcode != 0)
{
MessageUtil.ShowTips("操作失败 " + crt.Resultmsg);
return;
}
MessageUtil.ShowTips("操作成功");
}
///
/// 生成检验委托单
///
private void AddCheckDelegateId()
{
if (ultraGrid6.ActiveRow == null)
{ return; }
try
{
DateTime? dtnull = null;
PurCkLimsMEntity CkLimsMEntity = new PurCkLimsMEntity();
String strInspectCode = this.execute("com.hnshituo.pur.utils.service.UtilsService", "getOddNumber_yymm", new object[] { "PUR_CK_LIMS_M", "INSPECT_CODE", "ZJDH-", "3" });
String strBatchNo = this.execute("com.hnshituo.pur.utils.service.UtilsService", "getOddNumber_yymm", new object[] { "PUR_CK_LIMS_M", "INSPECT_SNQ", "JYP-", "3" });
CkLimsMEntity.InspectCode = strInspectCode;//质检单号
CkLimsMEntity.RecId = ultraGrid6.ActiveRow.Cells["INSTOCKNO"].Value.ToString();//收货单号
CkLimsMEntity.BatchNo = ultraGrid6.ActiveRow.Cells["BATCHNO"].Value.ToString();//入场批号
CkLimsMEntity.InspectSnq = strBatchNo;//检验批号
CkLimsMEntity.InspectDate = txt_INSPECT_DATE.Value == null ? dtnull : (DateTime)txt_INSPECT_DATE.Value;//检验日期(判定日期)
CkLimsMEntity.Remark = txt_REMARK.Text;//备注
CkLimsMEntity.Paihao = txt_PAIHAO.Text;//牌号
CkLimsMEntity.InspectUserName = txt_INSPECT_USER_NAME.Text;//质检人姓名
CkLimsMEntity.OrderLineSqe = txt_ORDER_LINE_SQE.Text;//合同行号
CkLimsMEntity.Qty = txt_QTY.Text.Trim() == "" ? 0 : double.Parse(txt_QTY.Text);//验收量
CkLimsMEntity.InspectStandCode = txt_INSPECT_STAND_CODE.Text;//质检标准编号
CkLimsMEntity.ItemName = txt_ITEM_NAME.Text;//物料名称
CkLimsMEntity.ItemCode = ultraGrid6.ActiveRow.Cells["ITEMCODE"].Value.ToString();//物料编码
CkLimsMEntity.ItemStandardsCode = txt_ITEM_STANDARDS_CODE.Text;//标准编号
CkLimsMEntity.CheckItems = txt_CHECK_ITEMS.Text;// 检测项目
CkLimsMEntity.Validflag = "1";
CkLimsMEntity.CreateName = UserInfo.GetUserName();
CkLimsMEntity.CreateUserid = UserInfo.GetUserID();
CkLimsMEntity.CreateTime = System.DateTime.Now;
CoreResult crt = this.execute("com.hnshituo.pur.ck.service.CkLimsMService", "doInsert", new object[] { CkLimsMEntity });//添加操作
CkStorage CkSto = new CkStorage();
CkSto.InvId = ultraGrid6.ActiveRow.Cells["InvId"].Value.ToString();
CkSto.BatchNo = strBatchNo;
CoreResult crt1 = this.execute("com.hnshituo.pur.ck.service.CkStorageService", "doUpdate", new object[] { CkSto });//修改库存检验批号
if (crt.Resultcode != 0 || crt1.Resultcode != 0)
{
MessageUtil.ShowTips("生成失败: " + crt.Resultmsg);
return;
}
MessageUtil.ShowTips("成功生成检验委托单:" + strBatchNo);
getCkLimsM();
comm.doActiveSelRow(ultraGrid1, "INSPECTCODE", strInspectCode);
GetPUR_CK_STORAGE();
comm.doActiveSelRow(ultraGrid6, "INSTOCKNO", CkLimsMEntity.RecId);
}
catch (Exception e){
MessageUtil.ShowTips("生成失败: " + e.Message);
return;
}
}
///
/// 增加质检行信息
///
private void AddCkLims()
{
if (ultraGrid1.ActiveRow == null)
{
MessageUtil.ShowTips("请选择质检委托单");
return;
}
ultraGrid5.UpdateData();
//更新检验单检验结果
PurCkLimsMEntity CkLimsMEntity = new PurCkLimsMEntity();
CkLimsMEntity.InspectCode = ultraGrid1.ActiveRow.Cells["InspectCode"].Value.ToString();
CkLimsMEntity.Result = cmbCheck.Value.ToString();
CkLimsMEntity.Remark = txt_REMARK1.Text;
if (txt_ITEM_UOM_CONEFFICIENT.Text != "")
{
CkLimsMEntity.ItemUomConefficient = double.Parse(txt_ITEM_UOM_CONEFFICIENT.Text);
}
//插入检验详细信息
ArrayList alCkLims = new ArrayList();
for (int i = 0; i < ultraGrid5.Rows.Count; i++)
{
PurCkLimsCEntity CkLimsCEntity = new PurCkLimsCEntity();
CkLimsCEntity.InspectCode = ultraGrid1.ActiveRow.Cells["InspectCode"].Value.ToString();
CkLimsCEntity.ChemCode = ultraGrid5.Rows[i].Cells["ChemCode"].Value.ToString();//质检项
CkLimsCEntity.ChemValue1 = ultraGrid5.Rows[i].Cells["ChemValue1"].Value.ToString();//质检结果
CkLimsCEntity.ChemValue2 = ultraGrid5.Rows[i].Cells["ChemValue2"].Value.ToString();//单位
CkLimsCEntity.SeqNo = i;
CkLimsCEntity.Validflag = "1";
CkLimsCEntity.CreateName = UserInfo.GetUserName();
CkLimsCEntity.CreateUserid = UserInfo.GetUserID();
CkLimsCEntity.CreateTime = System.DateTime.Now;
alCkLims.Add(CkLimsCEntity);
}
//更新库存收货单的状态
CkStorage ckEntity =new CkStorage();
ckEntity.InStockNo = ultraGrid1.ActiveRow.Cells["RECID"].Value.ToString();
CoreResult crt = this.execute("com.hnshituo.pur.ck.service.CkLimsCService", "AddCkLims", new object[] { alCkLims, CkLimsMEntity, ckEntity });//添加操作
if (crt.Resultcode != 0)
{
MessageUtil.ShowTips("判定结果失败");
return;
}
MessageUtil.ShowTips("已生成判定结果:"+cmbCheck.Text);
getCkLimsM();
comm.doActiveSelRow(ultraGrid1, "INSPECTCODE", CkLimsMEntity.InspectCode);
string strINSTOCKNO = ultraGrid6.ActiveRow.Cells["INSTOCKNO"].Value.ToString();
GetPUR_CK_STORAGE();
comm.doActiveSelRow(ultraGrid6, "INSTOCKNO", strINSTOCKNO);
}
///
/// 获取检验委托信息
///
private void getCheckDelegate()
{
txt_ORDER_LINE_SQE.Text = ultraGrid6.ActiveRow.Cells["ORDERLINESQE"].Value.ToString();//合同行号
txt_SUPP_NAME.Text = ultraGrid6.ActiveRow.Cells["SUPPNAME"].Value.ToString();//供应商名称
txt_CHK_BATCH_NO.Text = ultraGrid6.ActiveRow.Cells["CHKBATCHNO"].Value.ToString();//检验批
txt_ITEM_NAME.Text = ultraGrid6.ActiveRow.Cells["ITEMNAME"].Value.ToString();//物料名称
txt_ITEM_STANDARDS_CODE.Text = ultraGrid6.ActiveRow.Cells["ITEMSTANDARDSCODE"].Value.ToString();//标准编号
txt_RECQTY.Text = ultraGrid6.ActiveRow.Cells["INVQTY"].Value.ToString();//收货数量、供货数量
}
///
/// 激活收货单号,查询 相应的质检信息
///
///
///
private void ultraGrid1_AfterRowActivate(object sender, EventArgs e)
{
getCkLimsC(ultraGrid1.ActiveRow.Cells["INSPECTCODE"].Value.ToString());
if (ultraGrid1.ActiveRow.Cells["RESULT"].Value.ToString() == "合格")
{
cmbCheck.Value = 1;
}
else
{
cmbCheck.Value = 0;
}
txt_ITEM_UOM_CONEFFICIENT.Text = ultraGrid1.ActiveRow.Cells["ITEMUOMCONEFFICIENT"].Value.ToString();
}
///
/// 质检信息激活事件,查询质检明细单
///
///
///
private void ultraGrid2_AfterRowActivate(object sender, EventArgs e)
{
PurCkLimsCEntity CkLimsCEntity = new PurCkLimsCEntity();
//CkLimsCEntity.InspectCode = ultraGrid2.ActiveRow.Cells["INSPECTCODE"].Value.ToString();
DataTable dt = this.execute("com.hnshituo.pur.ck.service.CkLimsCService", "find", new object[] { CkLimsCEntity, 0, 0 });
GridHelper.CopyDataToDatatable(dt, dataTable3, true);
}
///
/// 生成检验委托单
///
///
///
private void btnChkDelegate_Click(object sender, EventArgs e)
{
AddCheckDelegateId();
}
///
/// 查询库存
///
///
///
private void btnQuery_Click(object sender, EventArgs e)
{
GetPUR_CK_STORAGE();
}
///
/// 查询质检头信息
///
///
///
private void btnQueryCLM_Click(object sender, EventArgs e)
{
getCkLimsM();
}
///
/// 确定质检判定结果信息
///
///
///
private void btnConform_Click(object sender, EventArgs e)
{
AddCkLims();
}
private void ultraGrid6_AfterRowActivate(object sender, EventArgs e)
{
getCheckDelegate();
}
///
/// 界面加载
///
///
///
private void frmCheckItem_Load(object sender, EventArgs e)
{
cmbCheck.SelectedIndex = 0;
txt_createTimeS.Value = DateTime.Now.AddMonths(-1);
}
}
}