【打印COA界面】DataTable数据获取与更新
using System;using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using MESCore;
using TRSCore;
using QCMCore.Reports;
using QCMCore.Inquiry;
namespace QCMCore
{
public partial class frmQCMTranGenCOA : BaseFormWIP, IBaseFormFunc
{
public frmQCMTranGenCOA()
{
InitializeComponent();
}
public frmQCMTranGenCOA(string sCoaId)
{
InitializeComponent();
paraCoaId = sCoaId;
}
#region Variable
private bool mbLoadFlag = false;
private string[] saTableKeys;
private string sPoId = "";
private string paraCoaId = "";
#endregion
#region Function
private bool CheckCondition(string FuncName, char ProcStep)
{
try
{
switch (CommonFunction.Trim(FuncName))
{
case "Create_COA":
if (gluCOATemplate.Text == "")
{
CommonFunction.ShowMsgBox(CommonFunction.GetMessage(108));
gluCOATemplate.Focus();
return false;
}
switch (CommonFunction.ToChar(CommonFunction.Trim(ProcStep)))
{
case GlobalConstant.SYS_STEP_CREATE:
case GlobalConstant.SYS_STEP_UPDATE:
break;
case GlobalConstant.SYS_STEP_DELETE:
return true;
}
break;
case "Update_Item_List":
DataTable dt = (DataTable)gdcCOAItem.DataSource;
if (dt != null)
{
foreach (DataRow dr in dt.Rows)
{
if (dr.RowState != DataRowState.Deleted)
{
if (dr["TESTING_RESULT"].ToString().Trim() == "")
{
CommonFunction.ShowMsgBox(CommonFunction.GetMessage(108));
return false;
}
}
//if (dr.RowState != DataRowState.Deleted)
//{
// if (dr["ITEM_SEQ"].ToString().Trim() == "")
// {
// CommonFunction.ShowMsgBox(CommonFunction.GetMessage(108));
// return false;
// }
//}
}
}
break;
}
return true;
}
catch (Exception ex)
{
CommonFunction.ShowMsgBox(ex.Message);
return false;
}
}
public void InitgdvCoaItem()
{
DataTable dtResult = new DataTable();
dtResult.Columns.Add("ITEM_SEQ");
dtResult.Columns.Add("TESTING_ITEM");
dtResult.Columns.Add("TESTING_RESULT");
dtResult.Columns.Add("TESTING_SPECIFICATION");
dtResult.Columns.Add("DIMENS");
dtResult.Columns.Add("TESTING_METHOD");
DevGridControlHelper.BindData(gdcCOAItem, dtResult, new int[] { 1, 1, 1, 1, 1, 1 });
return;
}
private bool BindGV(string sCoaId)
{
DataTable dt = QCMLIST.ViewQcmCoaItem(sCoaId);
if (dt != null)
{
DevGridControlHelper.BindData(gdcCOAItem, dt, new int[] { -1, 1, 1, 1, 1, 1 });
return true;
}
else
{
DataTable dtResult = new DataTable();
dtResult.Columns.Add("ITEM_SEQ");
dtResult.Columns.Add("TESTING_ITEM");
dtResult.Columns.Add("TESTING_RESULT");
dtResult.Columns.Add("TESTING_SPECIFICATION");
dtResult.Columns.Add("DIMENS");
dtResult.Columns.Add("TESTING_METHOD");
DevGridControlHelper.BindData(gdcCOAItem, dtResult, new int[] { -1, 1, 1, 1, 1, 1 });
return false;
}
}
private void View_Coa_Template_List()
{
DataTable dt = QCMLIST.ViewQcmCoaTemplateList();
if (dt != null)
{
DevGridLookupHelper.AddEmptyRow(this.gluCOATemplate, true);
DevGridLookupHelper.InitPopup(this.gluCOATemplate, new string[] { "COA模板" }, dt);
}
}
private void View_Pkg_Notice_No_List()
{
if (sPoId == "")
{
return;
}
DataTable dt = QCMLIST.ViewQCMPkgNoticeNoListByPo(sPoId);
if (dt != null)
{
DevGridLookupHelper.AddEmptyRow(this.gluPkgID, true);
DevGridLookupHelper.InitPopup(this.gluPkgID, new string[] {"ID", "包装单号" }, dt, 1, 1);
}
}
private TRSNode FillUpdateRecords(TRSNode in_node, DataTable dtDataEdited, bool bOriginal, char cStep)
{
TRSNode node;
for (int i = 0; i < dtDataEdited.Rows.Count; i++)
{
node = in_node.AddNode("COA_LIST");
node.ProcStep = cStep;
if (bOriginal)
{
node.AddInt("ITEM_SEQ", dtDataEdited.Rows[i]["ITEM_SEQ", DataRowVersion.Original]);
node.AddDouble("TESTING_RESULT", dtDataEdited.Rows[i]["TESTING_RESULT", DataRowVersion.Original]);
node.AddString("TESTING_ITEM", dtDataEdited.Rows[i]["TESTING_ITEM", DataRowVersion.Original]);
node.AddString("TESTING_SPECIFICATION", dtDataEdited.Rows[i]["TESTING_SPECIFICATION", DataRowVersion.Original]);
node.AddString("DIMENS", dtDataEdited.Rows[i]["DIMENS", DataRowVersion.Original]);
node.AddString("TESTING_METHOD", dtDataEdited.Rows[i]["TESTING_METHOD", DataRowVersion.Original]);
}
else
{
node.AddInt("ITEM_SEQ", dtDataEdited.Rows[i]["ITEM_SEQ"]);//根据i行及列名获取值并存入node中
node.AddDouble("TESTING_RESULT", dtDataEdited.Rows[i]["TESTING_RESULT"]);
node.AddString("TESTING_ITEM", dtDataEdited.Rows[i]["TESTING_ITEM"]);
node.AddString("TESTING_SPECIFICATION", dtDataEdited.Rows[i]["TESTING_SPECIFICATION"]);
node.AddString("DIMENS", dtDataEdited.Rows[i]["DIMENS"]);
node.AddString("TESTING_METHOD", dtDataEdited.Rows[i]["TESTING_METHOD"]);
}
}
return in_node;
}
private bool Update_COA(char ProcStep)
{
TRSNode in_node = new TRSNode("UPDATE_COA_TEMPLATE_IN");
TRSNode out_node = new TRSNode("CMN_OUT");
try
{
CommonRoutine.SetInMsg(in_node);
string sCoaTempId = gluCOATemplate.Text;
string sTempDesc = txtDesc.Text;
string sBatchId = txtLotID.Text;
string sCoaDate = deCoaDate.Text;
DataRowView dr = (DataRowView)gluPkgID.GetSelectedDataRow();
in_node.AddString("COA_ID", sCoaTempId);
if (dr != null)
{
in_node.AddInt("PKG_ID", dr["PKG_NOTICE_ID"]);
}
else
{
in_node.AddInt("PKG_ID", 0);
}
in_node.AddString("PKG_NO", gluPkgID.Text);
in_node.AddString("COA_DESC", sTempDesc);
in_node.AddString("BATCH_ID", sBatchId);
in_node.AddString("COA_DATE", sCoaDate);
in_node.ProcStep = ProcStep;
if (CommonRoutine.CallService("QCM", "QCM_Update_COA", in_node, ref out_node) == false)
{
return false;
}
return true;
}
catch (Exception ex)
{
CommonFunction.ShowMsgBox(ex.Message);
return false;
}
}
private bool Update_COA_Detail_Item_List()
{
try
{
if (gdcCOAItem.DataSource == null)//无数据,直接返回true,避免调用时return,不给保存成功的提示
{
return false;
}
TRSNode in_node = new TRSNode("UPDATE_COA_TEMPLATE_IN");
TRSNode out_node = new TRSNode("UPDATE_COA_TEMPLATE_OUT");
if(gluCOATemplate.Text=="")
{
CommonFunction.ShowMsgBox("请选择模板ID");
gluCOATemplate.Focus();
return false;
}
if (txtLotID.Text == "")
{
CommonFunction.ShowMsgBox("检查批号不能为空");
txtLotID.Focus();
return false;
}
if (gluPkgID.Text == "")
{
CommonFunction.ShowMsgBox("包装单号不能为空");
gluPkgID.Focus();
return false;
}
in_node.AddString("COA_ID", CommonFunction.Trim(gluCOATemplate.Text));
in_node.AddString("BATCH_ID", CommonFunction.Trim(txtLotID.Text));
in_node.AddString("COA_DESC", CommonFunction.Trim(txtDesc.Text));
in_node.AddString("COA_DATE", CommonFunction.Trim(deCoaDate.Text));
in_node.AddString("PKG_NO", CommonFunction.Trim(gluPkgID.Text));
CommonRoutine.SetInMsg(in_node);
DataTable dtDataEdited = (DataTable)gdcCOAItem.DataSource;//简单粗暴,全删全加
//if (dtDataEdited != null) //不访问已删除了的,直接后台删除pkgId关联的再全加
//{
// in_node = FillUpdateRecords(in_node, dtDataEdited, false, GlobalConstant.SYS_STEP_DELETE);
//}
//dtDataEdited = null;
//dtDataEdited = (DataTable)gdcCOAItem.DataSource;//简单粗暴,全删全加
if (dtDataEdited != null)
{
in_node = FillUpdateRecords(in_node, dtDataEdited, false, "A");
}
if (CommonRoutine.CallService("QCM", "QCM_Update_COA_Item", in_node, ref out_node) == false)
{
return false;
}
//CommonRoutine.ShowSuccessMsg(out_node);
return true;
}
catch (Exception ex)
{
CommonFunction.ShowMsgBox(ex.Message);
return false;
}
}
private bool View_Batch_Info(string sBatchID = " ")
{
TRSNode in_node = new TRSNode("VIEW_BATCH_INFO_IN");
TRSNode out_node = new TRSNode("VIEW_BATCH_INFO_OUT");
try
{
if (sBatchID != null)
{
CommonRoutine.SetInMsg(in_node);
in_node.ProcStep = "1";
in_node.AddString("BATCH_ID", sBatchID);
if (CommonRoutine.CallService("QCM", "QCM_Custom_View_Batch_Info", in_node, ref out_node) == false)
{
return false;
}
//this.txtBatchID.Text = CommonFunction.Trim(out_node.GetString("BATCH_ID"));
this.txtDesc.Text = CommonFunction.Trim(out_node.GetString("DESCRIPTION"));
sPoId = CommonFunction.Trim(out_node.GetString("PO"));
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
CommonFunction.ShowMsgBox(ex.Message);
return false;
}
}
#endregion
#region Control Event
private void frmQCMTranGenCOA_Load(object sender, EventArgs e)
{
try
{
View_Coa_Template_List();
if (mbLoadFlag == false)
{
mbLoadFlag = true;
}
}
catch (Exception ex)
{
CommonFunction.ShowMsgBox(ex.Message);
}
}
private void btnProcess_Click(object sender, EventArgs e)
{
//Create
try
{
//保存编辑框中做的更新
gdvCOAItem.PostEditor();
gdvCOAItem.UpdateCurrentRow();
string sBatchID = txtLotID.Text;
string sTemplateID = gluCOATemplate.Text;
if (txtLotID.Text == "")
{
CommonFunction.ShowMsgBox("检查批号不能为空");
txtLotID.Focus();
return;
}
if (gluCOATemplate.Text == "")
{
CommonFunction.ShowMsgBox("请选择模板ID");
gluCOATemplate.Focus();
return;
}
if (gluPkgID.EditValue == null || gluPkgID.Text == "")
{
CommonFunction.ShowMsgBox("请选择包装单号!");
gluPkgID.Focus();
return;
}
//Update Data List
//int ActiveRow = 0;//更新后继续focus在原先focus的行
if (CheckCondition("Update_Item_List", GlobalConstant.SYS_STEP_CREATE) == false) //CheckDataCondition不分SYS_STEP_UPDATE还是SYS_STEP_DELETE
{
return;
}
if (Update_COA("A") == false)
{
return;
}
if (Update_COA_Detail_Item_List() == false)
{
return;
}
string sPkgID = gluPkgID.Text;
if (QCMLIST.PrintQcmCoa(sPkgID) == null)
{
return;
}
DataTable dt = (DataTable)gdcCOAItem.DataSource;
if (dt != null)
{
foreach (DataRow dr in dt.Rows)
{
if (dr.RowState != DataRowState.Deleted)
{
if (dr["TESTING_RESULT"].ToString().Trim() == "")
{
CommonFunction.ShowMsgBox(CommonFunction.GetMessage(108));
return ;
}
}
}
}
rptQCMCOACard QCMCOACard = new rptQCMCOACard(dt,sBatchID,sTemplateID);
DevExpress.XtraReports.UI.ReportPrintTool printTool = new DevExpress.XtraReports.UI.ReportPrintTool(QCMCOACard);
printTool.ShowPreviewDialog();
printTool.Dispose();
QCMCOACard.Dispose();
}
catch (Exception ex)
{
CommonFunction.ShowMsgBox(ex.Message);
}
}
protected override void txtLotID_KeyPress(object sender, KeyPressEventArgs e)
{
try
{
if (e.KeyChar == (char)13 && txtLotID.Text.Trim() != "")
{
View_Batch_Info(txtLotID.Text);
View_Pkg_Notice_No_List();
}
}
catch (Exception ex)
{
CommonFunction.ShowMsgBox(ex.Message);
}
//try
//{
// string sCoaId = gluCOATemplate.Text;
// string sBacthId = txtLotID.Text;
// if (e.KeyChar == (char)13)
// {
// if (txtLotID.Text != "" && sCoaId != "")
// {
// DataTable dt = new DataTable();
// dt = QCMLIST.QCM_View_COA_Detail(sCoaId, sBacthId);
// if (dt != null)
// {
// DevGridControlHelper.BindData(gdcCOAItem, dt);
// DevGridControlHelper.BindData(gdcCOAItem, dt, new int[] { 1, 1, 1, 1, 1, 1 });
// }
// }
// return;
// }
//}
//catch (Exception ex)
//{
// CommonFunction.ShowMsgBox(ex.Message);
// return;
//}
}
private void gluCOATemplate_EditValueChanged(object sender, EventArgs e)
{
try
{
if (gluCOATemplate.Text != "")
{
string sCoaId = gluCOATemplate.Text;
string sBacthId = txtLotID.Text;
if (txtLotID.Text == "")
{
CommonFunction.ShowMsgBox("检查批号不能为空");
InitgdvCoaItem();
gluCOATemplate.Text = "";
txtLotID.Focus();
return;
}
if (gluCOATemplate.Text == "")
{
CommonFunction.ShowMsgBox("请选择模板ID");
gluCOATemplate.Focus();
return;
}
if (txtLotID.Text != "" && sCoaId != "")
{
DataTable dt = new DataTable();
dt = QCMLIST.QCM_View_COA_Detail(sCoaId, sBacthId);
if (dt != null)
{
udcGVNewDelCtrl1.RecordCount = dt.Rows.Count;
DevGridControlHelper.BindData(gdcCOAItem, dt, new int[] { -1, 1, 1, 1, 1, 1 });
gdvCOAItem.Columns[0].OptionsColumn.AllowEdit = false;
}
else
{
InitgdvCoaItem();
}
}
}
else
{
InitgdvCoaItem();
}
}
catch (Exception ex)
{
CommonFunction.ShowMsgBox(ex.Message);
return;
}
}
//private void gluPkgID_EditValueChanged(object sender, EventArgs e)
//{
// string sCoaId = gluPkgID.Text;
// if (sCoaId != "选择包装单号")
// {
// BindGV(sCoaId);
// }
//}
#endregion
}
}
以上是 【打印COA界面】DataTable数据获取与更新 的全部内容, 来源链接: utcz.com/z/510311.html