90 lines
3.4 KiB
C#
90 lines
3.4 KiB
C#
using DigitalData.Modules.Database;
|
|
using DigitalData.Modules.Interfaces;
|
|
using DigitalData.Modules.Config;
|
|
using Microsoft.Extensions.Configuration;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using DigitalData.Modules.Logging;
|
|
using System;
|
|
|
|
namespace ZUGFeRDRESTService
|
|
{
|
|
public class Database: IDatabase
|
|
{
|
|
private DigitalData.Modules.Logging.Logger _Logger = null;
|
|
private string _gdPictureKey = null;
|
|
private List<XmlItemProperty> _propertyMapList = null;
|
|
|
|
private LogConfig _logConfig = null;
|
|
private string _connString;
|
|
private string _GDPictureVersion;
|
|
|
|
|
|
private const string QUERY_GET_GDPICTURE_KEY = "SELECT LICENSE FROM TBDD_3RD_PARTY_MODULES WHERE NAME = 'GDPICTURE'";
|
|
private const string QUERY_GET_PROPERTY_MAP = "SELECT * FROM TBDD_ZUGFERD_XML_ITEMS WHERE ACTIVE = 1 ORDER BY XML_PATH";
|
|
|
|
public MSSQLServer MSSQL { get; set; }
|
|
|
|
public Database(ILogging Logging, IConfiguration Config)
|
|
{
|
|
_logConfig = Logging.LogConfig;
|
|
var oLogger = Logging.LogConfig.GetLogger();
|
|
var oAppConfig = Config.GetSection("Config");
|
|
_connString = oAppConfig["MSSQLConnectionString"];
|
|
_GDPictureVersion = oAppConfig["GDPictureVersion"];
|
|
|
|
oLogger.Debug("Establishing MSSQL Database connection..");
|
|
MSSQL = new MSSQLServer(_logConfig, _connString);
|
|
|
|
oLogger.Debug("MSSQL Connection: [{0}]", MSSQL.CurrentConnectionString);
|
|
|
|
_Logger = oLogger;
|
|
}
|
|
|
|
public string GetGDPictureKey()
|
|
{
|
|
_gdPictureKey = ConfigDbFunct.GetProductLicense("GDPICTURE", _GDPictureVersion, _logConfig, _connString);
|
|
|
|
return _gdPictureKey;
|
|
}
|
|
|
|
public List<XmlItemProperty> GetPropertyMapList()
|
|
{
|
|
if (_propertyMapList == null)
|
|
{
|
|
_Logger.Debug("Property map list does not exist, creating.");
|
|
|
|
_propertyMapList = new List<XmlItemProperty>();
|
|
var oDatatable = MSSQL.GetDatatable(QUERY_GET_PROPERTY_MAP);
|
|
|
|
_Logger.Debug("Datatable Rows: [{0}]", oDatatable.Rows);
|
|
|
|
foreach (DataRow oRow in oDatatable.Rows)
|
|
{
|
|
_propertyMapList.Add(new XmlItemProperty()
|
|
{
|
|
XMLPath = oRow["XML_PATH"].ToString(),
|
|
Description = oRow["DESCRIPTION"].ToString(),
|
|
TableName = oRow["TABLE_NAME"].ToString(),
|
|
TableColumn = oRow["TABLE_COLUMN"].ToString(),
|
|
GroupScope = oRow["GROUP_SCOPE"].ToString(),
|
|
IsRequired = (bool)oRow["IS_REQUIRED"],
|
|
IsGrouped = (bool)oRow["IS_GROUPED"],
|
|
Specification = oRow["SPECIFICATION"].ToString(),
|
|
ItemType = oRow["ITEM_TYPE"] != null ? Convert.ToInt32(oRow["ITEM_TYPE"]) : 0,
|
|
EN16931_ID = oRow["EN16931_ID"] != null ? oRow["EN16931_ID"].ToString() : "-"
|
|
});
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_Logger.Debug("Property map list already exists, returning.");
|
|
}
|
|
|
|
_Logger.Debug("Returning Property Map list with [{0}] entries.", _propertyMapList.Count);
|
|
|
|
return _propertyMapList;
|
|
}
|
|
}
|
|
}
|