300 lines
15 KiB
C#
300 lines
15 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.OleDb;
|
|
using System.Linq;
|
|
using System.Data.SqlClient;
|
|
using System.Xml;
|
|
using DTS.Common.Enums.DBExport;
|
|
using DTS.Common.Storage;
|
|
using DTS.Common.Utilities.Logging;
|
|
|
|
namespace DTS.Common.ISO
|
|
{
|
|
public class MMEPhysicalDimensions : AbstractOLEDbWrapper
|
|
{
|
|
public string S_GUID { get; }
|
|
|
|
public string Physical_Dimension { get; }
|
|
|
|
public string Text_L1 { get; }
|
|
|
|
public string Text_L2 { get; }
|
|
|
|
public string Default_Unit { get; }
|
|
|
|
public long Length_EXP { get; }
|
|
|
|
public long Time_EXP { get; }
|
|
|
|
public long Mass_EXP { get; }
|
|
|
|
public long Electric_Current_EXP { get; }
|
|
|
|
public long Temperature_EXP { get; }
|
|
|
|
public long Luminous_Intensity_Exp { get; }
|
|
|
|
public long Amount_Of_Substance_EXP { 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;
|
|
|
|
/// <summary>
|
|
/// imports a singular physical dimension
|
|
/// </summary>
|
|
/// <param name="node"></param>
|
|
/// <param name="setStatus"></param>
|
|
/// <param name="page"></param>
|
|
public static MMEPhysicalDimensions ReadXML(XmlElement node)
|
|
{
|
|
var fields = Enum.GetValues(typeof(PhysicalDimensionFields)).Cast<PhysicalDimensionFields>().ToArray();
|
|
|
|
string sGUID = "", physicalDimension = "", textL1 = "", textL2 = "", defaultUnit = "", remarks = "", sortKey = "", lastChangeText = "", history = "";
|
|
long lengthExp = 0, timeExp = 0, massExp = 0, currentExp = 0, temperatureExp = 0, luminiousExp = 0, amountExp = 0, version = 0;
|
|
var expired = false;
|
|
DateTime date = DateTime.Now, lastChange = DateTime.Now;
|
|
|
|
foreach (var field in fields)
|
|
{
|
|
switch (field)
|
|
{
|
|
case PhysicalDimensionFields.Amount_Of_Substance_EXP:
|
|
amountExp = long.Parse(node.GetAttribute(field.ToString()), System.Globalization.CultureInfo.InvariantCulture);
|
|
break;
|
|
case PhysicalDimensionFields.Date:
|
|
date = DateTime.Parse(node.GetAttribute(field.ToString()), System.Globalization.CultureInfo.InvariantCulture);
|
|
break;
|
|
case PhysicalDimensionFields.Default_Unit:
|
|
defaultUnit = node.GetAttribute(field.ToString());
|
|
break;
|
|
case PhysicalDimensionFields.Electric_Current_EXP:
|
|
currentExp = long.Parse(node.GetAttribute(field.ToString()), System.Globalization.CultureInfo.InvariantCulture);
|
|
break;
|
|
case PhysicalDimensionFields.Expired:
|
|
expired = Convert.ToBoolean(node.GetAttribute(field.ToString()));
|
|
break;
|
|
case PhysicalDimensionFields.History:
|
|
history = node.GetAttribute(field.ToString());
|
|
break;
|
|
case PhysicalDimensionFields.Last_Change:
|
|
lastChange = DateTime.Parse(node.GetAttribute(field.ToString()), System.Globalization.CultureInfo.InvariantCulture);
|
|
break;
|
|
case PhysicalDimensionFields.Last_Change_Text:
|
|
lastChangeText = node.GetAttribute(field.ToString());
|
|
break;
|
|
case PhysicalDimensionFields.Length_EXP:
|
|
lengthExp = long.Parse(node.GetAttribute(field.ToString()), System.Globalization.CultureInfo.InvariantCulture);
|
|
break;
|
|
case PhysicalDimensionFields.Luminous_Intensity_Exp:
|
|
luminiousExp = long.Parse(node.GetAttribute(field.ToString()), System.Globalization.CultureInfo.InvariantCulture);
|
|
break;
|
|
case PhysicalDimensionFields.Mass_EXP:
|
|
massExp = long.Parse(node.GetAttribute(field.ToString()), System.Globalization.CultureInfo.InvariantCulture);
|
|
break;
|
|
case PhysicalDimensionFields.Physical_Dimension:
|
|
physicalDimension = node.GetAttribute(field.ToString());
|
|
break;
|
|
case PhysicalDimensionFields.RecordType:
|
|
break;
|
|
case PhysicalDimensionFields.Remarks:
|
|
remarks = node.GetAttribute(field.ToString());
|
|
break;
|
|
case PhysicalDimensionFields.S_GUID:
|
|
sGUID = node.GetAttribute(field.ToString());
|
|
break;
|
|
case PhysicalDimensionFields.SortKey:
|
|
sortKey = node.GetAttribute(field.ToString());
|
|
break;
|
|
case PhysicalDimensionFields.Temperature_EXP:
|
|
temperatureExp = long.Parse(node.GetAttribute(field.ToString()), System.Globalization.CultureInfo.InvariantCulture);
|
|
break;
|
|
case PhysicalDimensionFields.Text_L1:
|
|
textL1 = node.GetAttribute(field.ToString());
|
|
break;
|
|
case PhysicalDimensionFields.Text_L2:
|
|
textL2 = node.GetAttribute(field.ToString());
|
|
break;
|
|
case PhysicalDimensionFields.Time_EXP:
|
|
timeExp = long.Parse(node.GetAttribute(field.ToString()), System.Globalization.CultureInfo.InvariantCulture);
|
|
break;
|
|
case PhysicalDimensionFields.Version:
|
|
version = long.Parse(node.GetAttribute(field.ToString()), System.Globalization.CultureInfo.InvariantCulture);
|
|
break;
|
|
default:
|
|
throw new NotSupportedException("ImportTestSetup::ImportCustomPhysicalDimension unsupported field: " + field.ToString());
|
|
}
|
|
}
|
|
|
|
return new MMEPhysicalDimensions(sGUID, physicalDimension, textL1, textL2, defaultUnit, lengthExp, timeExp, massExp, currentExp, temperatureExp, luminiousExp, amountExp, version, date, remarks, expired, sortKey, lastChange, lastChangeText, history, MMEPossibleChannels.MMEChannelTypes.SQL);
|
|
}
|
|
|
|
public MMEPhysicalDimensions(string sGUID, string physicalDimension, string textL1, string textL2, string defaultUnit,
|
|
long lengthExp, long timeExp, long massExp, long currentExp, long temperatureExp, long luminiousExp, long amountExp,
|
|
long version, DateTime date, string remarks, bool expired, string sortKey, DateTime lastChange, string lastChangeText,
|
|
string history, MMEPossibleChannels.MMEChannelTypes type)
|
|
{
|
|
RecordType = type;
|
|
S_GUID = sGUID;
|
|
Physical_Dimension = physicalDimension;
|
|
Text_L1 = textL1;
|
|
Text_L2 = textL2;
|
|
Default_Unit = defaultUnit;
|
|
Length_EXP = lengthExp;
|
|
Time_EXP = timeExp;
|
|
Mass_EXP = massExp;
|
|
Electric_Current_EXP = currentExp;
|
|
Temperature_EXP = temperatureExp;
|
|
Luminous_Intensity_Exp = luminiousExp;
|
|
Amount_Of_Substance_EXP = amountExp;
|
|
Version = version;
|
|
Date = date;
|
|
Remarks = remarks;
|
|
Expired = expired;
|
|
SortKey = sortKey;
|
|
Last_Change = lastChange;
|
|
Last_Change_Text = lastChangeText;
|
|
History = history;
|
|
}
|
|
|
|
public static MMEPhysicalDimensions[] GetPhysicalDimensions()
|
|
{
|
|
var physicalDimensions = new List<MMEPhysicalDimensions>();
|
|
|
|
using (var cmd = DbOperations.GetISOCommand())
|
|
{
|
|
cmd.CommandType = CommandType.Text;
|
|
cmd.CommandText = "SELECT * FROM MMEPhysicalDimensions";
|
|
try
|
|
{
|
|
using (var ISOReader = cmd.ExecuteReader())
|
|
{
|
|
while (ISOReader.Read())
|
|
{
|
|
try
|
|
{
|
|
string sGuid = ISOReader["s_GUID"].ToString();
|
|
string physicalDimension = ISOReader["PHYSICAL_DIMENSION"].ToString();
|
|
string textL1 = ISOReader["TEXT_L1"].ToString();
|
|
string textL2 = ISOReader["TEXT_L2"].ToString();
|
|
string defaultUnit = ISOReader["DEFAULT_UNIT"].ToString();
|
|
long lengthExp = GetLong(ISOReader, "LENGTH_EXP");
|
|
long timeExp = GetLong(ISOReader, "TIME_EXP");
|
|
long massExp = GetLong(ISOReader, "MASS_EXP");
|
|
long electricCurrentExp = GetLong(ISOReader, "ELECTRIC_CURRENT_EXP");
|
|
long temperatureExp = GetLong(ISOReader, "TEMPERATURE_EXP");
|
|
long luminiousExp = GetLong(ISOReader, "LUMINOUS_INTENSITY_EXP");
|
|
long amountExp = GetLong(ISOReader, "AMOUNT_OF_SUBSTANCE_EXP");
|
|
long version = GetLong(ISOReader, "VERSION");
|
|
DateTime date = (DateTime)ISOReader["DATE"];
|
|
string remarks = ISOReader["REMARKS"].ToString();
|
|
bool expired = (bool)ISOReader["EXPIRED"];
|
|
string sortkey = ISOReader["SORTKEY"].ToString();
|
|
DateTime lastChange = GetDate(ISOReader, "LAST_CHANGE");
|
|
string lastChangeText = ISOReader["LAST_CHANGE_TEXT"].ToString();
|
|
string history = ISOReader["HISTORY"].ToString();
|
|
|
|
physicalDimensions.Add(new MMEPhysicalDimensions(sGuid, physicalDimension, textL1,
|
|
textL2, defaultUnit, lengthExp,
|
|
timeExp, massExp, electricCurrentExp, temperatureExp, luminiousExp, amountExp,
|
|
version, date, remarks, expired, sortkey, lastChange, lastChangeText, history,
|
|
MMEPossibleChannels.MMEChannelTypes.ISO13499_106));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
APILogger.Log("Failed to process dimension", ex);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
cmd.Connection.Dispose();
|
|
}
|
|
}
|
|
|
|
return physicalDimensions.ToArray();
|
|
}
|
|
|
|
public void Commit()
|
|
{
|
|
using (var cmd = DbOperations.GetSQLCommand(true))
|
|
{
|
|
try
|
|
{
|
|
cmd.CommandType = CommandType.StoredProcedure;
|
|
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_MMEPhysicalDimensionsUpdateInsert.ToString();
|
|
|
|
#region params
|
|
|
|
cmd.Parameters.Add(
|
|
new SqlParameter("@s_GUID", SqlDbType.UniqueIdentifier) { Value = Guid.Parse(S_GUID) });
|
|
cmd.Parameters.Add(
|
|
new SqlParameter("@PHYSICAL_DIMENSION", SqlDbType.NVarChar, 50) { Value = Physical_Dimension });
|
|
cmd.Parameters.Add(new SqlParameter("@TEXT_L1", SqlDbType.NVarChar, 50) { Value = Text_L1 });
|
|
cmd.Parameters.Add(new SqlParameter("@TEXT_L2", SqlDbType.NVarChar, 50) { Value = Text_L2 });
|
|
cmd.Parameters.Add(
|
|
new SqlParameter("@DEFAULT_UNIT", SqlDbType.NVarChar, 50) { Value = Default_Unit });
|
|
cmd.Parameters.Add(new SqlParameter("@LENGTH_EXP", SqlDbType.Int) { Value = Length_EXP });
|
|
cmd.Parameters.Add(new SqlParameter("@TIME_EXP", SqlDbType.Int) { Value = Time_EXP });
|
|
cmd.Parameters.Add(new SqlParameter("@MASS_EXP", SqlDbType.Int) { Value = Mass_EXP });
|
|
cmd.Parameters.Add(
|
|
new SqlParameter("@ELECTRIC_CURRENT_EXP", SqlDbType.Int) { Value = Electric_Current_EXP });
|
|
cmd.Parameters.Add(new SqlParameter("@TEMPERATURE_EXP", SqlDbType.Int) { Value = Temperature_EXP });
|
|
cmd.Parameters.Add(
|
|
new SqlParameter("@LUMINOUS_INTENSITY_EXP", SqlDbType.Int) { Value = Luminous_Intensity_Exp });
|
|
cmd.Parameters.Add(
|
|
new SqlParameter("@AMOUNT_OFSUBSTANCE_EXP", SqlDbType.Int) { Value = Amount_Of_Substance_EXP });
|
|
cmd.Parameters.Add(new SqlParameter("@VERSION", SqlDbType.Int) { Value = Version });
|
|
cmd.Parameters.Add(new SqlParameter("@DATE", SqlDbType.DateTime) { Value = Date });
|
|
cmd.Parameters.Add(new SqlParameter("@REMARKS", SqlDbType.NVarChar, 50) { Value = Remarks });
|
|
cmd.Parameters.Add(new SqlParameter("@EXPIRED", SqlDbType.Bit) { Value = Expired });
|
|
cmd.Parameters.Add(new SqlParameter("@SORTKEY", SqlDbType.NVarChar, 50) { Value = SortKey });
|
|
cmd.Parameters.Add(new SqlParameter("@LAST_CHANGE", SqlDbType.DateTime) { Value = Last_Change });
|
|
cmd.Parameters.Add(
|
|
new SqlParameter("@LAST_CHANGE_TEXT", SqlDbType.NVarChar, 50) { Value = Last_Change_Text });
|
|
cmd.Parameters.Add(new SqlParameter("@HISTORY", SqlDbType.NVarChar, 50) { Value = History });
|
|
var newIdParam = new SqlParameter("@new_id", SqlDbType.Int) { Direction = ParameterDirection.Output };
|
|
cmd.Parameters.Add(newIdParam);
|
|
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);
|
|
|
|
#endregion params
|
|
|
|
cmd.ExecuteNonQuery();
|
|
if (int.Parse(errorNumberParam.Value.ToString()) != 0)
|
|
{
|
|
//errorMessageParam.Value
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
cmd.Connection.Dispose();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|