Files
2026-04-17 14:55:32 -04:00

238 lines
11 KiB
C#

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
namespace DatabaseImport
{
public class MMEDirections //: AbstractOLEDbWrapper
{
public string S_GUID { get; }
public string Direction { get; }
public string Text_L1 { get; }
public string Text_L2 { get; }
public DateTime Date { get; }
public long Version { get; }
public bool Expired { get; }
public string Remarks { get; }
public DateTime Last_Change { get; }
public string Last_Change_Text { get; }
public string History { get; }
public string SortKey { get; }
public MMEPossibleChannels.MMEChannelTypes RecordType { get; }
public MMEDirections(string sGuid, string direction, string textL1, string textL2, DateTime date, long version,
bool bExpired, string remarks, DateTime lastChange, string lastChangeText, string history, string sortkey,
MMEPossibleChannels.MMEChannelTypes type)
{
RecordType = type;
S_GUID = sGuid;
Direction = direction;
Text_L1 = textL1;
Text_L2 = textL2;
Date = date;
Version = version;
Expired = bExpired;
Remarks = remarks;
Last_Change = lastChange;
Last_Change_Text = lastChangeText;
History = history;
SortKey = sortkey;
}
public static MMEDirections[] GetDirections()
{
var directions = new List<MMEDirections>();
SqlDataReader reader = null;
try
{
using (var cmd = DbOperations.GetSQLCommand(true))
{
try
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_MMEDirectionsGet.ToString();
cmd.Parameters.Add(new SqlParameter("@s_GUID", SqlDbType.UniqueIdentifier) { Value = null });
reader = cmd.ExecuteReader();
while (reader.Read())
{
try
{
var version =
Convert.ToInt32(
reader[DbOperations.MMETables.MMEDirectionsFields.VERSION.ToString()]);
var text2 = Convert.ToString(
reader[DbOperations.MMETables.MMEDirectionsFields.TEXT_L2.ToString()]);
var text1 = Convert.ToString(
reader[DbOperations.MMETables.MMEDirectionsFields.TEXT_L1.ToString()]);
var sortKey =
Convert.ToString(
reader[DbOperations.MMETables.MMEDirectionsFields.SORTKEY.ToString()]);
var sGuid = Convert.ToString(
reader[DbOperations.MMETables.MMEDirectionsFields.s_GUID.ToString()]);
var remarks =
Convert.ToString(
reader[DbOperations.MMETables.MMEDirectionsFields.REMARKS.ToString()]);
var lastChangeText =
Convert.ToString(
reader[DbOperations.MMETables.MMEDirectionsFields.LAST_CHANGE_TEXT.ToString()]);
var lastChange =
Convert.ToDateTime(
reader[DbOperations.MMETables.MMEDirectionsFields.LAST_CHANGE.ToString()]);
var history =
Convert.ToString(
reader[DbOperations.MMETables.MMEDirectionsFields.HISTORY.ToString()]);
var expired =
Convert.ToBoolean(
reader[DbOperations.MMETables.MMEDirectionsFields.EXPIRED.ToString()]);
var direction =
Convert.ToString(
reader[DbOperations.MMETables.MMEDirectionsFields.DIRECTION.ToString()]);
var date = Convert.ToDateTime(
reader[DbOperations.MMETables.MMEDirectionsFields.DATE.ToString()]);
var mmedirection = new MMEDirections(sGuid, direction, text1, text2, date,
Convert.ToInt64(version),
expired, remarks, lastChange, lastChangeText, history, sortKey,
MMEPossibleChannels.MMEChannelTypes.ISO13499_106);
directions.Add(mmedirection);
}
catch (Exception)
{
//APILogger.Log("failed to load direction", ex);
}
}
reader.Close();
}
finally { cmd.Connection.Dispose(); }
}
}
catch (Exception)
{
//APILogger.Log("failed to load sql portion of iso.mmedirections, ", ex);
}
try
{
using (var cmd = DbOperations.GetSQLCommand(true))
{
try
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_MMEDirectionsGetCustom.ToString();
cmd.Parameters.Add(new SqlParameter("@s_GUID", SqlDbType.UniqueIdentifier) { Value = null });
reader = cmd.ExecuteReader();
while (reader.Read())
{
try
{
var version =
Convert.ToInt32(
reader[DbOperations.MMETables.MMEDirectionsFields.VERSION.ToString()]);
var text2 = Convert.ToString(
reader[DbOperations.MMETables.MMEDirectionsFields.TEXT_L2.ToString()]);
var text1 = Convert.ToString(
reader[DbOperations.MMETables.MMEDirectionsFields.TEXT_L1.ToString()]);
var sortKey =
Convert.ToString(
reader[DbOperations.MMETables.MMEDirectionsFields.SORTKEY.ToString()]);
var sGuid = Convert.ToString(
reader[DbOperations.MMETables.MMEDirectionsFields.s_GUID.ToString()]);
var remarks =
Convert.ToString(
reader[DbOperations.MMETables.MMEDirectionsFields.REMARKS.ToString()]);
var lastChangeText =
Convert.ToString(
reader[DbOperations.MMETables.MMEDirectionsFields.LAST_CHANGE_TEXT.ToString()]);
var lastChange =
Convert.ToDateTime(
reader[DbOperations.MMETables.MMEDirectionsFields.LAST_CHANGE.ToString()]);
var history =
Convert.ToString(
reader[DbOperations.MMETables.MMEDirectionsFields.HISTORY.ToString()]);
var expired =
Convert.ToBoolean(
reader[DbOperations.MMETables.MMEDirectionsFields.EXPIRED.ToString()]);
var direction =
Convert.ToString(
reader[DbOperations.MMETables.MMEDirectionsFields.DIRECTION.ToString()]);
var date = Convert.ToDateTime(
reader[DbOperations.MMETables.MMEDirectionsFields.DATE.ToString()]);
var mmedirection = new MMEDirections(sGuid, direction, text1, text2, date,
Convert.ToInt64(version),
expired, remarks, lastChange, lastChangeText, history, sortKey,
MMEPossibleChannels.MMEChannelTypes.SQL);
directions.Add(mmedirection);
}
catch (Exception)
{
//APILogger.Log("failed to load custom direction", ex);
}
}
reader.Close();
}
finally { cmd.Connection.Dispose(); }
}
}
catch (Exception)
{
//APILogger.Log("failed to load sql portion of custom mmedirections, ", ex);
}
finally
{
reader?.Close();
}
return directions.ToArray();
}
public static void DeleteDirections()
{
try
{
using (var cmd = DbOperations.GetSQLCommand(true))
{
try
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_MMEDirectionsDelete.ToString();
cmd.Parameters.Add(new SqlParameter("@s_GUID", SqlDbType.UniqueIdentifier) { Value = null });
var errorNumberParam =
new SqlParameter("@errorNumber", SqlDbType.Int) { Direction = ParameterDirection.Output };
cmd.Parameters.Add(errorNumberParam);
var errorMessageParam =
new SqlParameter("@errorMessage", SqlDbType.NVarChar, 250)
{
Direction = ParameterDirection.Output
};
cmd.Parameters.Add(errorMessageParam);
cmd.ExecuteNonQuery();
if (int.Parse(errorNumberParam.Value.ToString()) != 0)
{
//errorMessageParam.Value
}
}
finally
{
cmd.Connection.Dispose();
}
}
}
catch (Exception) { /*APILogger.Log("failed to delete sql portion of iso.mmedirections, ", ex); */}
}
}
}