git_bsmd/ENI2/Report/LabelStorage.cs

81 lines
2.6 KiB
C#

// Copyright (c) 2015-2017 schick Informatik
// Zugriff auf SQLite Datenbank mit Report Überschriften
using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
namespace ENI2.Report
{
/// <summary>
/// Zugriff auf SQLite Datenbank mit Report Überschriften
/// </summary>
public class LabelStorage
{
private static readonly SQLiteConnection _con;
private const string _locode_DB_NAME = "report.db";
private static Dictionary<string, string> _collectionLabelDict = null;
private static Dictionary<string, string> _fieldLabelDict = null;
static LabelStorage()
{
_con = new SQLiteConnection(string.Format("data source={0}; Version=3;", _locode_DB_NAME));
_con.Open();
}
#region public static properties
public static Dictionary<string, string> CollectionLabelDict
{
get
{
if(_collectionLabelDict == null)
{
_collectionLabelDict = new Dictionary<string, string>();
string query = "SELECT Name, Value FROM CollectionLabel";
SQLiteCommand cmd = new SQLiteCommand(query, _con);
IDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
if (!reader.IsDBNull(0) && !reader.IsDBNull(1))
_collectionLabelDict[reader.GetString(0)] = reader.GetString(1);
}
reader.Close();
}
return _collectionLabelDict;
}
}
public static Dictionary<string, string> FieldLabelDict
{
get
{
if (_fieldLabelDict == null)
{
_fieldLabelDict = new Dictionary<string, string>();
string query = "SELECT Name, Value FROM FieldLabel";
SQLiteCommand cmd = new SQLiteCommand(query, _con);
IDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
if (!reader.IsDBNull(0) && !reader.IsDBNull(1))
_fieldLabelDict[reader.GetString(0)] = reader.GetString(1);
}
reader.Close();
}
return _fieldLabelDict;
}
}
public static void CloseDB()
{
_con.Close();
}
#endregion
}
}