Browse Source

货柜接口增加错误日志保存

master
陆晔 2 years ago
parent
commit
a4780f6f67
  1. 98
      ICSSoft.WMS.WebAPI/ICSSoft.Common/DBHelper.cs
  2. 7
      ICSSoft.WMS.WebAPI/ICSSoft.DataProject/ICSSoft.DataProject.csproj
  3. 10
      ICSSoft.WMS.WebAPI/ICSSoft.DataProject/ICSSubmitService.cs
  4. 2
      ICSSoft.WMS.WebAPI/ICSSoft.WMS.WebAPI/Controllers/WMSBarCoreController.cs

98
ICSSoft.WMS.WebAPI/ICSSoft.Common/DBHelper.cs

@ -3896,7 +3896,105 @@ VALUES (33, '{0}') END ";
string c = year + "-" + month + "-" + day;
return c;
}
}
public static int ExecuteNonQuery(string connectionString, CommandType commandType, string commandText)
{
// Pass through the call providing null for the set of SqlParameters
return ExecuteNonQuery(connectionString, commandType, commandText, (SqlParameter[])null);
}
public static int ExecuteNonQuery(string connectionString, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
{
if (connectionString == null || connectionString.Length == 0) throw new ArgumentNullException("connectionString");
// Create & open a SqlConnection, and dispose of it after we are done
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
// Call the overload that takes a connection in place of the connection string
return ExecuteNonQuery(connection, commandType, commandText, commandParameters);
}
}
public static int ExecuteNonQuery(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
{
if (connection == null) throw new ArgumentNullException("connection");
// Create a command and prepare it for execution
SqlCommand cmd = new SqlCommand();
bool mustCloseConnection = false;
PrepareCommand(cmd, connection, (SqlTransaction)null, commandType, commandText, commandParameters, out mustCloseConnection);
// Finally, execute the command
int retval = cmd.ExecuteNonQuery();
// Detach the SqlParameters from the command object, so they can be used again
cmd.Parameters.Clear();
if (mustCloseConnection)
connection.Close();
return retval;
}
private static void PrepareCommand(SqlCommand command, SqlConnection connection, SqlTransaction transaction, CommandType commandType, string commandText, SqlParameter[] commandParameters, out bool mustCloseConnection)
{
if (command == null) throw new ArgumentNullException("command");
if (commandText == null || commandText.Length == 0) throw new ArgumentNullException("commandText");
// If the provided connection is not open, we will open it
if (connection.State != ConnectionState.Open)
{
mustCloseConnection = true;
connection.Open();
}
else
{
mustCloseConnection = false;
}
// Associate the connection with the command
command.Connection = connection;
// Set the command text (stored procedure name or SQL statement)
command.CommandText = commandText;
// If we were provided a transaction, assign it
if (transaction != null)
{
if (transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction");
command.Transaction = transaction;
}
// Set the command type
command.CommandType = commandType;
// Attach the command parameters if they are provided
if (commandParameters != null)
{
AttachParameters(command, commandParameters);
}
return;
}
private static void AttachParameters(SqlCommand command, SqlParameter[] commandParameters)
{
if (command == null) throw new ArgumentNullException("command");
if (commandParameters != null)
{
foreach (SqlParameter p in commandParameters)
{
if (p != null)
{
// Check for derived output value with no value assigned
if ((p.Direction == ParameterDirection.InputOutput ||
p.Direction == ParameterDirection.Input) &&
(p.Value == null))
{
p.Value = DBNull.Value;
}
command.Parameters.Add(p);
}
}
}
}
}
}

7
ICSSoft.WMS.WebAPI/ICSSoft.DataProject/ICSSoft.DataProject.csproj

@ -40,6 +40,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="ICSSoft.Common">
<HintPath>..\ICSSoft.Common\bin\ICSSoft.Common.dll</HintPath>
</Reference>
<Reference Include="log4net, Version=2.0.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.13\lib\net45\log4net.dll</HintPath>
</Reference>
@ -98,10 +101,6 @@
</Compile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ICSSoft.Common\ICSSoft.Common.csproj">
<Project>{ee45f7a5-17ee-4707-a617-8c00dd36fc01}</Project>
<Name>ICSSoft.Common</Name>
</ProjectReference>
<ProjectReference Include="..\ICSSoft.Entity\ICSSoft.Entity.csproj">
<Project>{834E9A76-1D9E-4EBD-9321-0B362A06A367}</Project>
<Name>ICSSoft.Entity</Name>

10
ICSSoft.WMS.WebAPI/ICSSoft.DataProject/ICSSubmitService.cs

@ -3323,7 +3323,7 @@ namespace ICSSoft.DataProject
/// </summary>
/// <param name="JsonData"></param>
/// <returns></returns>
public static DataTable LOTStockDownHGCreate(LOTStockDownHGModel JsonData)
public static DataTable LOTStockDownHGCreate(LOTStockDownHGModel JsonData, object InputJson)
{
String PrintEnable = "";
var language = LanguageHelper.GetName("WMSAPIInfo");
@ -3459,6 +3459,14 @@ namespace ICSSoft.DataProject
if (cmd.Transaction != null)
cmd.Transaction.Rollback();
log.Error(ex.Message);
#region 保存传入JSON及报错信息
string errorsql = @"Insert into ICSHG_WMSEorrorLog
Values
(NEWID(),'{0}','{1}','{2}','{3}',GETDATE(),'{4}','{4}','{5}','','','')";
errorsql = string.Format(errorsql, JsonData.DATA.EXP_ORDINI[0].ORD_ORDINE, JsonData.DATA.EXP_ORDINI[0].ORD_DES, InputJson
, ex.Message, JsonData.DATA.EXP_ORDINI_RIGHE_STO[0].STO_EXE_OPERATORE, JsonData.DATA.EXP_ORDINI[0].ORD_CLIENTE);
DBHelper.ExecuteNonQuery(connString, CommandType.Text, errorsql);
#endregion
throw new Exception(ex.Message);
}
finally

2
ICSSoft.WMS.WebAPI/ICSSoft.WMS.WebAPI/Controllers/WMSBarCoreController.cs

@ -1040,7 +1040,7 @@ namespace ICSSoft.WebAPI.Controllers
model = JsonConvert.DeserializeObject<LOTStockDownHGModel>(JsonData.ToString());
//WMSBarCoreService action = new WMSBarCoreService();
//var resultStr = action.LOTStockDownCreate(model);
var resultStr = ICSSubmitService.LOTStockDownHGCreate(model);
var resultStr = ICSSubmitService.LOTStockDownHGCreate(model, JsonData);
res.Success = true;
//res.PrintStr = DBHelper.ReadFileStream();
if (resultStr.Columns.Contains("OLDLotNo"))

Loading…
Cancel
Save