207 lines
11 KiB
C#
207 lines
11 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Data;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Data.SqlClient;
|
|||
|
|
|
|||
|
|
namespace DatabaseImport
|
|||
|
|
{
|
|||
|
|
public class MMEPositions //: AbstractOLEDbWrapper
|
|||
|
|
{
|
|||
|
|
public string S_GUID { get; }
|
|||
|
|
|
|||
|
|
public string Position { get; }
|
|||
|
|
|
|||
|
|
public string Text_L1 { get; }
|
|||
|
|
|
|||
|
|
public string Text_L2 { get; }
|
|||
|
|
|
|||
|
|
public long Version { get; }
|
|||
|
|
|
|||
|
|
public DateTime Date { get; }
|
|||
|
|
|
|||
|
|
public string Remarks { get; }
|
|||
|
|
|
|||
|
|
public bool Expired { get; }
|
|||
|
|
|
|||
|
|
public string SortKey { get; }
|
|||
|
|
|
|||
|
|
public DateTime Last_Change { get; }
|
|||
|
|
|
|||
|
|
public string Last_Change_Text { get; }
|
|||
|
|
|
|||
|
|
public string History { get; }
|
|||
|
|
|
|||
|
|
public MMEPossibleChannels.MMEChannelTypes RecordType { get; } = MMEPossibleChannels.MMEChannelTypes.ISO13499_106;
|
|||
|
|
public MMEPositions(string sGuid, string position, string textL1, string textL2, long version,
|
|||
|
|
DateTime date, string remarks, bool expired, string sortKey, DateTime lastChange, string lastChangeText,
|
|||
|
|
string history, MMEPossibleChannels.MMEChannelTypes type)
|
|||
|
|
{
|
|||
|
|
RecordType = type;
|
|||
|
|
S_GUID = sGuid;
|
|||
|
|
Position = position;
|
|||
|
|
Text_L1 = textL1;
|
|||
|
|
Text_L2 = textL2;
|
|||
|
|
Version = version;
|
|||
|
|
Date = date;
|
|||
|
|
Remarks = remarks;
|
|||
|
|
Expired = expired;
|
|||
|
|
SortKey = sortKey;
|
|||
|
|
Last_Change = lastChange;
|
|||
|
|
Last_Change_Text = lastChangeText;
|
|||
|
|
History = history;
|
|||
|
|
}
|
|||
|
|
public static void DeletePositions()
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
using (var cmd = DbOperations.GetSQLCommand(true))
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
cmd.CommandType = CommandType.StoredProcedure;
|
|||
|
|
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_MMEPositionsDelete.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 positions, ", ex);*/ }
|
|||
|
|
}
|
|||
|
|
public static MMEPositions[] GetPositions()
|
|||
|
|
{
|
|||
|
|
var positions = new List<MMEPositions>();
|
|||
|
|
|
|||
|
|
using (var cmd = DbOperations.GetSQLCommand(true))
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
cmd.CommandType = CommandType.StoredProcedure;
|
|||
|
|
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_MMEPositionsGet.ToString();
|
|||
|
|
cmd.Parameters.Add(new SqlParameter("@s_GUID", SqlDbType.NVarChar) { Value = null });
|
|||
|
|
using (var ds = DbOperations.Connection.QueryDataSet(cmd))
|
|||
|
|
{
|
|||
|
|
if (ds.Tables.Count <= 0 || ds.Tables[0].Rows.Count <= 0) return positions.ToArray();
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
positions.AddRange(from DataRow dr in ds.Tables[0].Rows
|
|||
|
|
let date = Convert.ToDateTime(
|
|||
|
|
dr[DbOperations.MMETables.MMEPositionsFields.DATE.ToString()])
|
|||
|
|
let expired =
|
|||
|
|
Convert.ToBoolean(dr[DbOperations.MMETables.MMEPositionsFields.EXPIRED.ToString()])
|
|||
|
|
let history =
|
|||
|
|
Convert.ToString(dr[DbOperations.MMETables.MMEPositionsFields.HISTORY.ToString()])
|
|||
|
|
let lastChange =
|
|||
|
|
Convert.ToDateTime(
|
|||
|
|
dr[DbOperations.MMETables.MMEPositionsFields.LAST_CHANGE.ToString()])
|
|||
|
|
let lastChangeText =
|
|||
|
|
Convert.ToString(
|
|||
|
|
dr[DbOperations.MMETables.MMEPositionsFields.LAST_CHANGE_TEXT.ToString()])
|
|||
|
|
let position =
|
|||
|
|
Convert.ToString(dr[DbOperations.MMETables.MMEPositionsFields.POSITION.ToString()])
|
|||
|
|
let remarks =
|
|||
|
|
Convert.ToString(dr[DbOperations.MMETables.MMEPositionsFields.REMARKS.ToString()])
|
|||
|
|
let sGuid = Convert.ToString(
|
|||
|
|
dr[DbOperations.MMETables.MMEPositionsFields.s_GUID.ToString()])
|
|||
|
|
let sortKey =
|
|||
|
|
Convert.ToString(dr[DbOperations.MMETables.MMEPositionsFields.SORTKEY.ToString()])
|
|||
|
|
let text1 = Convert.ToString(
|
|||
|
|
dr[DbOperations.MMETables.MMEPositionsFields.TEXT_L1.ToString()])
|
|||
|
|
let text2 = Convert.ToString(
|
|||
|
|
dr[DbOperations.MMETables.MMEPositionsFields.TEXT_L2.ToString()])
|
|||
|
|
let version =
|
|||
|
|
Convert.ToInt32(dr[DbOperations.MMETables.MMEPositionsFields.VERSION.ToString()])
|
|||
|
|
select new MMEPositions(sGuid, position, text1, text2, Convert.ToInt64(version), date,
|
|||
|
|
remarks, expired, sortKey, lastChange, lastChangeText, history,
|
|||
|
|
MMEPossibleChannels.MMEChannelTypes.ISO13499_106));
|
|||
|
|
}
|
|||
|
|
catch (Exception)
|
|||
|
|
{
|
|||
|
|
//APILogger.Log("Failed to get positions", ex);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
finally
|
|||
|
|
{
|
|||
|
|
cmd.Connection.Dispose();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
using (var cmd = DbOperations.GetSQLCommand(true))
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
cmd.CommandType = CommandType.StoredProcedure;
|
|||
|
|
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_MMEPositionsGetCustom.ToString();
|
|||
|
|
cmd.Parameters.Add(new SqlParameter("@s_GUID", SqlDbType.NVarChar) { Value = null });
|
|||
|
|
using (var ds = DbOperations.Connection.QueryDataSet(cmd))
|
|||
|
|
{
|
|||
|
|
if (ds.Tables.Count <= 0 || ds.Tables[0].Rows.Count <= 0) return positions.ToArray();
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
positions.AddRange(from DataRow dr in ds.Tables[0].Rows
|
|||
|
|
let date = Convert.ToDateTime(
|
|||
|
|
dr[DbOperations.MMETables.MMEPositionsFields.DATE.ToString()])
|
|||
|
|
let expired =
|
|||
|
|
Convert.ToBoolean(dr[DbOperations.MMETables.MMEPositionsFields.EXPIRED.ToString()])
|
|||
|
|
let history =
|
|||
|
|
Convert.ToString(dr[DbOperations.MMETables.MMEPositionsFields.HISTORY.ToString()])
|
|||
|
|
let lastChange =
|
|||
|
|
Convert.ToDateTime(
|
|||
|
|
dr[DbOperations.MMETables.MMEPositionsFields.LAST_CHANGE.ToString()])
|
|||
|
|
let lastChangeText =
|
|||
|
|
Convert.ToString(
|
|||
|
|
dr[DbOperations.MMETables.MMEPositionsFields.LAST_CHANGE_TEXT.ToString()])
|
|||
|
|
let position =
|
|||
|
|
Convert.ToString(dr[DbOperations.MMETables.MMEPositionsFields.POSITION.ToString()])
|
|||
|
|
let remarks =
|
|||
|
|
Convert.ToString(dr[DbOperations.MMETables.MMEPositionsFields.REMARKS.ToString()])
|
|||
|
|
let sGuid = Convert.ToString(
|
|||
|
|
dr[DbOperations.MMETables.MMEPositionsFields.s_GUID.ToString()])
|
|||
|
|
let sortKey =
|
|||
|
|
Convert.ToString(dr[DbOperations.MMETables.MMEPositionsFields.SORTKEY.ToString()])
|
|||
|
|
let text1 = Convert.ToString(
|
|||
|
|
dr[DbOperations.MMETables.MMEPositionsFields.TEXT_L1.ToString()])
|
|||
|
|
let text2 = Convert.ToString(
|
|||
|
|
dr[DbOperations.MMETables.MMEPositionsFields.TEXT_L2.ToString()])
|
|||
|
|
let version =
|
|||
|
|
Convert.ToInt32(dr[DbOperations.MMETables.MMEPositionsFields.VERSION.ToString()])
|
|||
|
|
select new MMEPositions(sGuid, position, text1, text2, Convert.ToInt64(version), date,
|
|||
|
|
remarks, expired, sortKey, lastChange, lastChangeText, history,
|
|||
|
|
MMEPossibleChannels.MMEChannelTypes.SQL));
|
|||
|
|
}
|
|||
|
|
catch (Exception)
|
|||
|
|
{
|
|||
|
|
//APILogger.Log("Failed to get custom positions", ex);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
finally
|
|||
|
|
{
|
|||
|
|
cmd.Connection.Dispose();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return positions.ToArray();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|