diff --git a/bsmd.database/DBManagerAsync.cs b/bsmd.database/DBManagerAsync.cs index a459dd55..8e0eb454 100644 --- a/bsmd.database/DBManagerAsync.cs +++ b/bsmd.database/DBManagerAsync.cs @@ -1,7 +1,5 @@ -// Copyright (c) 2020-present schick Informatik -// Description: The new and mighty DB manager that uses async methods and -// connection pooling.. will try it out in Maersk/PO numbers and expand over the whole -// app later +// Copyright (c) 2023-present schick Informatik +// Description: Variant of DBManager that uses async calls using log4net; using System; @@ -81,6 +79,14 @@ namespace bsmd.database return result; } + public static async Task> LoadValuesForType(ValueMapping.MappingType mappingType) + { + SqlCommand cmd = new SqlCommand(); + ValueMapping vm = new ValueMapping(); + vm.PrepareLoadCommand(cmd, Message.LoadFilter.BY_TYPE, mappingType); + SqlDataReader reader = await PerformCommandAsync(cmd); + return await vm.LoadListAsync(reader); + } #endregion diff --git a/bsmd.database/DatabaseEntityAsync.cs b/bsmd.database/DatabaseEntityAsync.cs new file mode 100644 index 00000000..a5571d5d --- /dev/null +++ b/bsmd.database/DatabaseEntityAsync.cs @@ -0,0 +1,33 @@ +// Copyright (c) 2023-present schick Informatik +// Description: Async variant of DatabaseEntity + +using System; +using System.Collections.Generic; +using System.Data; +using System.Data.SqlClient; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace bsmd.database +{ + public abstract class DatabaseEntityAsync : DatabaseEntity + { + protected abstract DatabaseEntityAsync ReadRowFromReader(IDataReader reader); + + public async Task> LoadListAsync(SqlDataReader reader) + { + List result = new List(); + if (reader != null) + { + while (await reader.ReadAsync()) + { + result.Add(ReadRowFromReader(reader)); + } + reader.Close(); + } + return result; + } + + } +} diff --git a/bsmd.database/Message.cs b/bsmd.database/Message.cs index 27ec8ed4..b10c5b8f 100644 --- a/bsmd.database/Message.cs +++ b/bsmd.database/Message.cs @@ -143,7 +143,8 @@ namespace bsmd.database BY_CORE_AND_CLASS, BY_AGE, WASRCPT_ID, - BY_FILE_SEQ_NUM + BY_FILE_SEQ_NUM, + BY_TYPE } /// diff --git a/bsmd.database/ValueMapping.cs b/bsmd.database/ValueMapping.cs new file mode 100644 index 00000000..47b36129 --- /dev/null +++ b/bsmd.database/ValueMapping.cs @@ -0,0 +1,125 @@ +// Copyright (c) 2023-present schick Informatik +// Description: Container class for self-learning, volatile information that +// is added by parsing Excel sheets. Here common wrong/misspelled data fields +// are mapped to valid ones. + +using System; +using System.Collections.Generic; +using System.Data.SqlClient; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace bsmd.database +{ + public class ValueMapping : DatabaseEntityAsync + { + + #region enums + + public enum MappingType + { + UNKNOWN, + COUNTRY, + GENDER, + DOCUMENT_TYPE, + LOCODE, + INVALID + }; + + #endregion + + #region Fields + + private static Dictionary> _dicts = new Dictionary>(); + + #endregion + + #region Properties + + public static Dictionary> Dicts + { + get { return _dicts; } + } + + public MappingType EntryType { get; private set; } + + public string Key { get; private set; } + + public string Value { get; private set; } + + #endregion + + #region public funcs + + /// + /// creates and saves a new entry and adds it to the internal dictionaries + /// + /// true if entry was actually created, false if already present + public static bool Create(MappingType type, string key, string value) + { + + return false; + } + + /// + /// deletes an entry and removes it from the database + /// + /// true if successful, false if value was not found + public static bool Delete(MappingType type, string key) + { + + return false; + } + + /// + /// updates an existing value and saves it + /// + /// true if successful + public bool Update(string newValue) + { + + return false; + } + + #endregion + + #region DatabaseEntity implementation + + public override void PrepareSave(System.Data.IDbCommand cmd) + { + throw new NotImplementedException(); + } + + public override void PrepareLoadCommand(System.Data.IDbCommand cmd, Message.LoadFilter filter, params object[] criteria) + { + throw new NotImplementedException(); + } + + public override List LoadList(System.Data.IDataReader reader) + { + throw new NotImplementedException(); + } + + protected override DatabaseEntityAsync ReadRowFromReader(System.Data.IDataReader reader) + { + ValueMapping vm = null; + if (reader != null) + { + vm = new ValueMapping(); + + vm.id = reader.GetGuid(0); + + //if (!reader.IsDBNull(1)) md.MessageCoreId = reader.GetGuid(1); + //if (!reader.IsDBNull(2)) md.ColA = reader.GetString(2); + + + + } + return vm; + } + + #endregion + + } +} diff --git a/bsmd.database/bsmd.database.licenseheader b/bsmd.database/bsmd.database.licenseheader index 4b92e20b..47a9d64d 100644 --- a/bsmd.database/bsmd.database.licenseheader +++ b/bsmd.database/bsmd.database.licenseheader @@ -1,11 +1,11 @@ extensions: designer.cs generated.cs extensions: .cs .cpp .h -// Copyright (c) 2020-present schick Informatik +// Copyright (c) 2023-present schick Informatik // Description: extensions: .aspx .ascx <%-- -Copyright (c) 2020-present schick Informatik +Copyright (c) 2023-present schick Informatik --%> extensions: .vb 'Sample license text.