前几天和SAP集成,实现报工,取消报工接口,发现线上可参照资源很少,联调之后特此分享
1.界面
2.业务逻辑
业务逻辑很简单,点击SAP界面,选中并提交报工信息,将信息保存在固定格式XML中,调取SAP接口,将数据传出,成功之后SAP回传XML,在集成方面,重要的是双方要在XML格式上保持一致,互相配合保证联调成功。
3.报工按钮代码,生成XML,将数据插入XML中
/// <summary>
/// ERP报工
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnERPStart_Click(object sender, EventArgs e)
{
try
{//yehy 20180918 增加
#region SAP 报工
if (m_strSAP != "")
{
this.ProductorderReportbindingSource.EndEdit();
this.gridView2.PostEditor();
DataRow[] drOrdersSAP = dstFinishReport1.ERP_PRODUCTORDERREPORT.Select("SelectRow=True");
if (drOrdersSAP.Length > 0)
{
string strResult = "";
foreach (DataRow drOrder in drOrdersSAP)
{
#region 组织报工数据
//MemoryStream swbizData = new MemoryStream();
//XmlWriterSettings setting = new XmlWriterSettings();
//setting.Encoding = new UTF8Encoding(false);
//setting.Indent = true;
//XmlWriter xtw = XmlWriter.Create(swbizData, setting);
StringWriter swbizData = new StringWriter();
XmlTextWriter xtw = new XmlTextWriter(swbizData);
xtw.WriteStartDocument();
xtw.WriteStartElement("ROOT");
xtw.WriteStartElement("ITEM");
//xtw.WriteStartElement("INSDATA");
//操作完成的确认编号:报工时不需反馈到ERP,报工后ERP反馈该值到MES,用于取消报工
xtw.WriteStartElement("RUECK");
xtw.WriteString("");
xtw.WriteEndElement();
//订单号
xtw.WriteStartElement("AUFNR");
xtw.WriteString(drOrder["VBILLCODE"].ToString());
xtw.WriteEndElement();
//活动编号:订单工序中的活动编号,与工作中心一一对应
xtw.WriteStartElement("VORNR");
xtw.WriteString(drOrder["VORNR"].ToString());
xtw.WriteEndElement();
//已确认的总计产量(报工数量)
xtw.WriteStartElement("LMNGA");
x