【修】上传接口模板

This commit is contained in:
14278/caihao 2024-01-22 11:17:12 +08:00
parent 8263c18f38
commit 60bb545b1d
3 changed files with 358 additions and 0 deletions

View File

@ -71,6 +71,10 @@
<HintPath>..\..\..\MES_S_DLL\iMESConst.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="kcEQP, Version=6.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\MES_S_DLL\kcEQP.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="iMESCIO, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3ad2cfbf6a289680, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>

View File

@ -4,6 +4,8 @@ using iMESCore.Settings;
using System.Collections;
using System.Collections.Generic;
using static iMESCore.Base.iMESConst;
using System.Xml;
using Microsoft.VisualBasic.CompilerServices;
namespace EAIws_C
{
@ -115,6 +117,339 @@ namespace EAIws_C
}
public static string funCreateEquipment(string InXml)
{
string funCreateEquipmentRet = default(string);
var xmlDoc = new XmlDocument(); // 用以讀取Xml字串
string OutXml = null;
string strIdentity = string.Empty; // Identity XML字串
string strResult = "fail"; // Result XML字串
var strException = new List<ArrayList>(); // Exception XML字串
var strMessage = new List<ArrayList>(); // Message XML字串
string strKeyValue = string.Empty; // TransactionLot KeyValue
string strMode = string.Empty; // Mode
try
{
try
{
// 讀取InXml字串
xmlDoc.LoadXml(InXml);
}
catch (Exception ex)
{
combineException(ref strException, sysmsg: ex.Message, mesmsg: "[%InXmlError%]", stack: ex.StackTrace);
goto exitFun;
}
// 組Identity字串
try
{
strIdentity = modWS.CombineXMLIdentity(xmlDoc);
}
catch (Exception ex)
{
combineException(ref strException, sysmsg: ex.Message, mesmsg: "[%IndentityError%]", stack: ex.StackTrace);
goto exitFun;
}
// 2019/06/14 Shih Kai, Mantis:0058578, 修正ERP設備整合,若ERP有傳值才進行更新
// 調整初始值,配合後端改用defString,defInteger, 在修改時才不會異動到已經維護的欄位資料
// 若ERP未傳入,在新增資料時判斷若未傳入才帶入預設值
string EquipmentNo = string.Empty;
string EquipmentName = defString;
string EquipmentType = defString;
string VendorNo = defString; // Defautl N/A
int Capacity = defInteger; // Defautl -1
string ModelNo = defString;
string Description = defString;
string Creator = "TP"; // Defautl TP
var CreateDate = DateTime.Now; // Default Today
string EngineerGroupNo = defString; // Defautl N/A"
string AssetNo = defString;
string EquipmentClass = defString;
int LoadPort = defInteger; // Defautl 0
int AutoFlag = defInteger; // Defautl 0
string EAController = defString; // Defautl N/A
int EQPRecipe = defInteger; // Defautl 0
string QCListNo = defString;
// EquipmentNo
if (xmlDoc.DocumentElement.GetElementsByTagName("equipmentno").Count > 0 && xmlDoc.GetElementsByTagName("equipmentno").Item(0).SelectNodes("value").Count > 0)
{
string argstrInput = xmlDoc.DocumentElement.GetElementsByTagName("equipmentno").Item(0).SelectNodes("value").Item(0).InnerText;
EquipmentNo = modWS.CInput_Singlequotation(argstrInput);
xmlDoc.DocumentElement.GetElementsByTagName("equipmentno").Item(0).SelectNodes("value").Item(0).InnerText = argstrInput;
}
// EquipmentName
if (xmlDoc.DocumentElement.GetElementsByTagName("equipmentname").Count > 0 && xmlDoc.GetElementsByTagName("equipmentname").Item(0).SelectNodes("value").Count > 0)
{
string argstrInput1 = xmlDoc.DocumentElement.GetElementsByTagName("equipmentname").Item(0).SelectNodes("value").Item(0).InnerText;
EquipmentName = modWS.CInput_Singlequotation(argstrInput1);
xmlDoc.DocumentElement.GetElementsByTagName("equipmentname").Item(0).SelectNodes("value").Item(0).InnerText = argstrInput1;
}
// EquipmentType
if (xmlDoc.DocumentElement.GetElementsByTagName("equipmenttype").Count > 0 && xmlDoc.GetElementsByTagName("equipmenttype").Item(0).SelectNodes("value").Count > 0)
{
string argstrInput2 = xmlDoc.DocumentElement.GetElementsByTagName("equipmenttype").Item(0).SelectNodes("value").Item(0).InnerText;
EquipmentType = modWS.CInput_Singlequotation(argstrInput2);
xmlDoc.DocumentElement.GetElementsByTagName("equipmenttype").Item(0).SelectNodes("value").Item(0).InnerText = argstrInput2;
}
// VendorNo
if (xmlDoc.DocumentElement.GetElementsByTagName("vendorno").Count > 0 && xmlDoc.GetElementsByTagName("vendorno").Item(0).SelectNodes("value").Count > 0)
{
string argstrInput3 = xmlDoc.DocumentElement.GetElementsByTagName("vendorno").Item(0).SelectNodes("value").Item(0).InnerText;
VendorNo = modWS.CInput_Singlequotation(argstrInput3);
xmlDoc.DocumentElement.GetElementsByTagName("vendorno").Item(0).SelectNodes("value").Item(0).InnerText = argstrInput3;
}
// Capacity
if (xmlDoc.DocumentElement.GetElementsByTagName("capacity").Count > 0 && xmlDoc.GetElementsByTagName("capacity").Item(0).SelectNodes("value").Count > 0)
Capacity = Conversions.ToInteger(xmlDoc.DocumentElement.GetElementsByTagName("capacity").Item(0).SelectNodes("value").Item(0).InnerText);
// ModelNo
if (xmlDoc.DocumentElement.GetElementsByTagName("modelno").Count > 0 && xmlDoc.GetElementsByTagName("modelno").Item(0).SelectNodes("value").Count > 0)
{
string argstrInput4 = xmlDoc.DocumentElement.GetElementsByTagName("modelno").Item(0).SelectNodes("value").Item(0).InnerText;
ModelNo = modWS.CInput_Singlequotation(argstrInput4);
xmlDoc.DocumentElement.GetElementsByTagName("modelno").Item(0).SelectNodes("value").Item(0).InnerText = argstrInput4;
}
// Description
if (xmlDoc.DocumentElement.GetElementsByTagName("description").Count > 0 && xmlDoc.GetElementsByTagName("description").Item(0).SelectNodes("value").Count > 0)
{
string argstrInput5 = xmlDoc.DocumentElement.GetElementsByTagName("description").Item(0).SelectNodes("value").Item(0).InnerText;
Description = modWS.CInput_Singlequotation(argstrInput5);
xmlDoc.DocumentElement.GetElementsByTagName("description").Item(0).SelectNodes("value").Item(0).InnerText = argstrInput5;
}
// EngineerGroupNo
if (xmlDoc.DocumentElement.GetElementsByTagName("engineergroupno").Count > 0 && xmlDoc.GetElementsByTagName("engineergroupno").Item(0).SelectNodes("value").Count > 0)
{
string argstrInput6 = xmlDoc.DocumentElement.GetElementsByTagName("engineergroupno").Item(0).SelectNodes("value").Item(0).InnerText;
EngineerGroupNo = modWS.CInput_Singlequotation(argstrInput6);
xmlDoc.DocumentElement.GetElementsByTagName("engineergroupno").Item(0).SelectNodes("value").Item(0).InnerText = argstrInput6;
}
// AssetNo
if (xmlDoc.DocumentElement.GetElementsByTagName("assetno").Count > 0 && xmlDoc.GetElementsByTagName("assetno").Item(0).SelectNodes("value").Count > 0)
{
string argstrInput7 = xmlDoc.DocumentElement.GetElementsByTagName("assetno").Item(0).SelectNodes("value").Item(0).InnerText;
AssetNo = modWS.CInput_Singlequotation(argstrInput7);
xmlDoc.DocumentElement.GetElementsByTagName("assetno").Item(0).SelectNodes("value").Item(0).InnerText = argstrInput7;
}
// EquipmentClass
if (xmlDoc.DocumentElement.GetElementsByTagName("equipmentclass").Count > 0 && xmlDoc.GetElementsByTagName("equipmentclass").Item(0).SelectNodes("value").Count > 0)
{
string argstrInput8 = xmlDoc.DocumentElement.GetElementsByTagName("equipmentclass").Item(0).SelectNodes("value").Item(0).InnerText;
EquipmentClass = modWS.CInput_Singlequotation(argstrInput8);
xmlDoc.DocumentElement.GetElementsByTagName("equipmentclass").Item(0).SelectNodes("value").Item(0).InnerText = argstrInput8;
}
// LoadPort
if (xmlDoc.DocumentElement.GetElementsByTagName("loadpart").Count > 0 && xmlDoc.GetElementsByTagName("loadpart").Item(0).SelectNodes("value").Count > 0)
LoadPort = Conversions.ToInteger(xmlDoc.DocumentElement.GetElementsByTagName("loadpart").Item(0).SelectNodes("value").Item(0).InnerText);
// AutoFlag
if (xmlDoc.DocumentElement.GetElementsByTagName("autoflag").Count > 0 && xmlDoc.GetElementsByTagName("autoflag").Item(0).SelectNodes("value").Count > 0)
AutoFlag = Conversions.ToInteger(xmlDoc.DocumentElement.GetElementsByTagName("autoflag").Item(0).SelectNodes("value").Item(0).InnerText);
// EAController
if (xmlDoc.DocumentElement.GetElementsByTagName("eacontroller").Count > 0 && xmlDoc.GetElementsByTagName("eacontroller").Item(0).SelectNodes("value").Count > 0)
{
string argstrInput9 = xmlDoc.DocumentElement.GetElementsByTagName("eacontroller").Item(0).SelectNodes("value").Item(0).InnerText;
EAController = modWS.CInput_Singlequotation(argstrInput9);
xmlDoc.DocumentElement.GetElementsByTagName("eacontroller").Item(0).SelectNodes("value").Item(0).InnerText = argstrInput9;
}
// EQPRecipe
if (xmlDoc.DocumentElement.GetElementsByTagName("eqprecipe").Count > 0 && xmlDoc.GetElementsByTagName("eqprecipe").Item(0).SelectNodes("value").Count > 0)
EQPRecipe = Conversions.ToInteger(xmlDoc.DocumentElement.GetElementsByTagName("eqprecipe").Item(0).SelectNodes("value").Item(0).InnerText);
// QCListNo
if (xmlDoc.DocumentElement.GetElementsByTagName("qclistno").Count > 0 && xmlDoc.GetElementsByTagName("qclistno").Item(0).SelectNodes("value").Count > 0)
{
string argstrInput10 = xmlDoc.DocumentElement.GetElementsByTagName("qclistno").Item(0).SelectNodes("value").Item(0).InnerText;
QCListNo = modWS.CInput_Singlequotation(argstrInput10);
xmlDoc.DocumentElement.GetElementsByTagName("qclistno").Item(0).SelectNodes("value").Item(0).InnerText = argstrInput10;
}
// Creator
Creator = modWS.GetXMLIdentityNode(xmlDoc, "curuserno");
// 檢查必要性欄位
if (string.IsNullOrEmpty(EquipmentNo))
combineException(ref strException, mesmsg: "[%EquipmentNoEmpty%]");
if ((EquipmentType ?? "") == defString)
combineException(ref strException, mesmsg: "[%EquipmentTypeEmpty%]");
if ((VendorNo ?? "") == defString)
combineException(ref strException, mesmsg: "[%VendorNoEmpty%]");
// KeyValue
strKeyValue = EquipmentNo;
// ----- 判斷設備是否存在 -----
using (var objEQP = new kcEQP.clsEQPBasis())
{
var dr = objEQP.GetEquipmentBasis(EquipmentNo.ToUpper());
if (dr["EquipmentNo"] is DBNull == false)
{
// EquipmentNo已存在--Edit
// 2019/06/14 Shih Kai, Mantis:0058578, 因設備類別EquipmentType為ERP必傳入欄位,必定會有值
// 故EquipmentType重新給於defString, 修改時不調整設備類別
EquipmentType = defString;
// '呼叫Dll執行
strMode = "Edit";
//clsEQP.editEquipment(EquipmentNo, EquipmentType, VendorNo, Capacity, ModelNo, Description, Creator, CreateDate, EngineerGroupNo, AssetNo, EquipmentClass, LoadPort, AutoFlag, EAController, EQPRecipe, QCListNo, strMessage, strException, EquipmentName);
}
else
{
// 2019/06/14 Shih Kai, Mantis:0058578, 修正ERP設備整合,若ERP未傳入才給予預設值
if ((VendorNo ?? "") == defString)
VendorNo = "N/A"; // Defautl N/A
if (Capacity == defInteger)
Capacity = -1; // Defautl -1
if ((EngineerGroupNo ?? "") == defString)
EngineerGroupNo = "N/A"; // Defautl N/A
if (LoadPort == defInteger)
LoadPort = 0; // Defautl 0
if (AutoFlag == defInteger)
AutoFlag = 0; // Defautl 0
if ((EAController ?? "") == defString)
EAController = "N/A"; // Defautl N/A
if (EQPRecipe == defInteger)
EQPRecipe = 0; // Defautl 0
// '呼叫Dll執行
strMode = "Add";
clsEQP.addEquipment(EquipmentNo, EquipmentType, VendorNo, Capacity, ModelNo, Description, Creator, CreateDate, EngineerGroupNo, AssetNo, EquipmentClass, LoadPort, AutoFlag, EAController, EQPRecipe, QCListNo, strMessage: strMessage, strException: strException, EquipmentName: EquipmentName);
}
}
// 判斷成功與否
if (strException.Count > 0)
goto exitFun;
strResult = "success";
exitFun:
;
}
catch (Exception ex)
{
combineException(ref strException, sysmsg: ex.Message, mesmsg: "[%CreateEquipmentFail%]", stack: ex.StackTrace);
}
finally
{
// 將各部份之XML字串組起來並傳出
string argReturnValue = null;
OutXml = modWS.CombineXMLResponse(strIdentity, argReturnValue, strException, strResult, strMessage);
// 紀錄Transaction Log
//addTransactionLog_ErrorCode(modWS.GetXMLIdentityNode(xmlDoc, "transactionid"), modWS.GetXMLIdentityNode(xmlDoc, "moduleid"), modWS.GetXMLIdentityNode(xmlDoc, "functionid"), modWS.GetXMLIdentityNode(xmlDoc, "computername"), modWS.GetXMLIdentityNode(xmlDoc, "curuserno"), modWS.GetXMLIdentityNode(xmlDoc, "sendtime"), strResult, strKeyValue, strMessage, strException, InXml, OutXml, "CreateEquipment(" + strMode + ")", Conversions.ToInteger(AppSettings["keepLog"]), Conversions.ToInteger(AppSettings["keepXML"]), LogClass: "ERP");
funCreateEquipmentRet = OutXml;
}
return funCreateEquipmentRet;
}
#region --- Combine (Exception, Message) ---
public static bool combineException(ref List<ArrayList> strException, string code = null, string sysmsg = null, string mesmsg = null, string stack = null)
{
bool result = false;
try
{
var al = new ArrayList();
al.Add(code);
al.Add(sysmsg);
al.Add(mesmsg);
al.Add(stack);
strException.Add(al);
result = true;
}
catch (Exception ex)
{
result = false;
}
return default(bool);
}
public static bool combineMessage(ref List<ArrayList> strMessage, string mcode = null, string mtype = null, string mmsg = null)
{
bool result = false;
try
{
var al = new ArrayList();
al.Add(mcode);
al.Add(mtype);
al.Add(mmsg);
strMessage.Add(al);
result = true;
}
catch (Exception ex)
{
result = false;
}
return default(bool);
}
public static bool combineFileMessage(ref List<ArrayList> aryFileMessage, string mmsg)
{
bool result = false;
try
{
var al = new ArrayList();
al.Add(mmsg);
aryFileMessage.Add(al);
result = true;
}
catch (Exception ex)
{
result = false;
}
return result;
}
#endregion
}
}

View File

@ -1468,6 +1468,25 @@ namespace EAIws_C
}
#endregion
public static string CInput_Singlequotation(string strInput)
{
string CInput_SinglequotationRet = strInput;
// 若為空字串導致傳入資料變為Nothing
if (string.IsNullOrEmpty(strInput))
return CInput_SinglequotationRet;
// 將傳入值內的單引號轉換為可存入資料庫的格式
// 傳入值: strInput包含特殊字元的字串
// 傳回值: 將特殊字元變更為代替符號的字串
// 轉換 ' 為 '' (單引號轉為兩個單引號)
CInput_SinglequotationRet = Strings.Replace(strInput, "'", "''");
return CInput_SinglequotationRet;
// 17046 20230110 因EAI等接口已接收InXML字串做 xmlDoc.LoadXml(InXml)解析通過因此不需再各function做CInput會將轉換後特殊字又處理一次造成寫入後端錯誤
// 增加一支轉換函式CInput_Singlequotation僅做單引號轉換EAI接口中原本呼叫CInput的地方取代為CInput_Singlequotation
}
}
}