85 lines
3.1 KiB
C#
85 lines
3.1 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;
|
|
|
|
namespace ZUGFeRDRESTService
|
|
{
|
|
public class Database: IDatabase
|
|
{
|
|
private DigitalData.Modules.Logging.Logger _Logger = null;
|
|
private string _gdPictureKey = null;
|
|
private Dictionary<string, XmlItemProperty> _propertyMap = 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 Dictionary<string, XmlItemProperty> GetPropertyMap()
|
|
{
|
|
if (_propertyMap == null)
|
|
{
|
|
_Logger.Debug("Property map does not exist, creating.");
|
|
|
|
_propertyMap = new Dictionary<string, XmlItemProperty>();
|
|
var oDatatable = MSSQL.GetDatatable(QUERY_GET_PROPERTY_MAP);
|
|
|
|
_Logger.Debug("Datatable Rows: [{0}]", oDatatable.Rows);
|
|
|
|
foreach (DataRow oRow in oDatatable.Rows)
|
|
{
|
|
_propertyMap.Add(oRow["XML_PATH"].ToString(), new XmlItemProperty()
|
|
{
|
|
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()
|
|
});
|
|
}
|
|
} else
|
|
{
|
|
_Logger.Debug("Property map already exists, returning.");
|
|
}
|
|
|
|
_Logger.Debug("Returning Property Map with [{0}] entries.", _propertyMap.Count);
|
|
|
|
return _propertyMap;
|
|
}
|
|
}
|
|
}
|