Value Mapping mit Excel getestet und einige Fehler korrigiert. Funktioniert soweit.
This commit is contained in:
parent
939b7fd23e
commit
a89ef42258
@ -82,6 +82,9 @@ namespace ENI2
|
|||||||
LADG.CargoCodesNST = LocalizedLookup.getCargoCodesNST();
|
LADG.CargoCodesNST = LocalizedLookup.getCargoCodesNST();
|
||||||
LADG.CargoCodesNST3 = LocalizedLookup.getCargoCodesNST3();
|
LADG.CargoCodesNST3 = LocalizedLookup.getCargoCodesNST3();
|
||||||
|
|
||||||
|
// Load import value mappings
|
||||||
|
ValueMapping.LoadDicts();
|
||||||
|
|
||||||
// Preload validation fields
|
// Preload validation fields
|
||||||
List<ValidationField> vFields = bsmd.database.ValidationRule.ValidationFields;
|
List<ValidationField> vFields = bsmd.database.ValidationRule.ValidationFields;
|
||||||
RuleEngine.RegisterLocodeChecker(Util.GlobalStructures.IsValidLocode);
|
RuleEngine.RegisterLocodeChecker(Util.GlobalStructures.IsValidLocode);
|
||||||
|
|||||||
@ -48,7 +48,7 @@ namespace ENI2.Controls
|
|||||||
|
|
||||||
MenuItem delItem = new MenuItem
|
MenuItem delItem = new MenuItem
|
||||||
{
|
{
|
||||||
Header = Properties.Resources.textAdd,
|
Header = Properties.Resources.textDelete,
|
||||||
Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/Resources/delete.png")) }
|
Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/Resources/delete.png")) }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -15,17 +15,18 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace ENI2.Excel
|
namespace ENI2.Excel
|
||||||
{
|
{
|
||||||
public static class ExcelUtil
|
public static class ExcelUtil
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#region fields
|
||||||
|
|
||||||
private static readonly ILog _log = LogManager.GetLogger(typeof(ExcelUtil));
|
private static readonly ILog _log = LogManager.GetLogger(typeof(ExcelUtil));
|
||||||
|
|
||||||
private static readonly Dictionary<string, string> _countryImportDict = new Dictionary<string, string>();
|
#endregion
|
||||||
private static readonly Dictionary<string, string> _genderImportDict = new Dictionary<string, string>();
|
|
||||||
private static readonly Dictionary<string, string> _documentTypeImportDict = new Dictionary<string, string>();
|
|
||||||
private static readonly Dictionary<string, string> _locodeImportDict = new Dictionary<string, string>();
|
|
||||||
|
|
||||||
#region Process Sheet (normal BSMD sheet import)
|
#region Process Sheet (normal BSMD sheet import)
|
||||||
|
|
||||||
@ -1340,8 +1341,7 @@ namespace ENI2.Excel
|
|||||||
wr.WasteCode.Equals("204") || wr.WasteCode.Equals("510") || wr.WasteCode.Equals("511"))
|
wr.WasteCode.Equals("204") || wr.WasteCode.Equals("510") || wr.WasteCode.Equals("511"))
|
||||||
wr.WasteDescription = "-";
|
wr.WasteDescription = "-";
|
||||||
}
|
}
|
||||||
wr.AmountWasteReceived_MTQ = reader.ReadNumber(wAmount);
|
wr.AmountWasteReceived_MTQ = reader.ReadNumber(wAmount) ?? (double?)0; // Default ist 0, nicht nix ;-)
|
||||||
if (!wr.AmountWasteReceived_MTQ.HasValue) wr.AmountWasteReceived_MTQ = 0; // Default ist 0, nicht nix ;-)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// only add message when an identification number was given
|
// only add message when an identification number was given
|
||||||
@ -2226,9 +2226,7 @@ namespace ENI2.Excel
|
|||||||
if (canceled) return true;
|
if (canceled) return true;
|
||||||
if (crewd.CrewMemberIdentityDocumentIssuingState.IsNullOrEmpty())
|
if (crewd.CrewMemberIdentityDocumentIssuingState.IsNullOrEmpty())
|
||||||
crewd.CrewMemberIdentityDocumentIssuingState = "XX";
|
crewd.CrewMemberIdentityDocumentIssuingState = "XX";
|
||||||
crewd.CrewMemberIdentityDocumentExpiryDate = reader.ReadCellAsDateTime(sheetTitle, string.Format("N{0}", i + 18));
|
crewd.CrewMemberIdentityDocumentExpiryDate = reader.ReadCellAsDateTime(sheetTitle, string.Format("N{0}", i + 18)) ?? (DateTime?)new DateTime(2100, 12, 31);
|
||||||
if (!crewd.CrewMemberIdentityDocumentExpiryDate.HasValue)
|
|
||||||
crewd.CrewMemberIdentityDocumentExpiryDate = new DateTime(2100, 12, 31);
|
|
||||||
|
|
||||||
crewd.Effects = reader.ReadCellAsText("2. PORT", string.Format("C{0}", i + 142));
|
crewd.Effects = reader.ReadCellAsText("2. PORT", string.Format("C{0}", i + 142));
|
||||||
|
|
||||||
@ -2333,7 +2331,7 @@ namespace ENI2.Excel
|
|||||||
pas.PassengerInTransit = reader.ReadCellAsBool(sheetTitle, string.Format("H{0}", i + 17));
|
pas.PassengerInTransit = reader.ReadCellAsBool(sheetTitle, string.Format("H{0}", i + 17));
|
||||||
|
|
||||||
pas.PassengerPlaceOfBirth = reader.ReadCellAsText(sheetTitle, string.Format("J{0}", i + 17));
|
pas.PassengerPlaceOfBirth = reader.ReadCellAsText(sheetTitle, string.Format("J{0}", i + 17));
|
||||||
pas.PassengerCountryOfBirth = reader.ReadCellAsText(sheetTitle, string.Format("K{0}", i + 17));
|
pas.PassengerCountryOfBirth = ReadNationality(reader.ReadCellAsText(sheetTitle, string.Format("K{0}", i + 17)), out canceled);
|
||||||
|
|
||||||
if (canceled) return true;
|
if (canceled) return true;
|
||||||
DateTime? dateOfBirth = reader.ReadCellAsDateTime(sheetTitle, string.Format("L{0}", i + 17));
|
DateTime? dateOfBirth = reader.ReadCellAsDateTime(sheetTitle, string.Format("L{0}", i + 17));
|
||||||
@ -2343,9 +2341,7 @@ namespace ENI2.Excel
|
|||||||
if (canceled) return true;
|
if (canceled) return true;
|
||||||
pas.PassengerIdentityDocumentId = reader.ReadCellAsText(sheetTitle, string.Format("N{0}", i + 17));
|
pas.PassengerIdentityDocumentId = reader.ReadCellAsText(sheetTitle, string.Format("N{0}", i + 17));
|
||||||
|
|
||||||
pas.PassengerIdentityDocumentExpiryDate = reader.ReadCellAsDateTime(sheetTitle, string.Format("P{0}", i + 17));
|
pas.PassengerIdentityDocumentExpiryDate = reader.ReadCellAsDateTime(sheetTitle, string.Format("P{0}", i + 17)) ?? (DateTime?)new DateTime(2100, 12, 31);
|
||||||
if (!pas.PassengerIdentityDocumentExpiryDate.HasValue)
|
|
||||||
pas.PassengerIdentityDocumentExpiryDate = new DateTime(2100, 12, 31);
|
|
||||||
|
|
||||||
pas.PassengerVisaNumber = reader.ReadCellAsText(sheetTitle, string.Format("Q{0}", i + 17));
|
pas.PassengerVisaNumber = reader.ReadCellAsText(sheetTitle, string.Format("Q{0}", i + 17));
|
||||||
pas.EmergencyCare = reader.ReadCellAsText(sheetTitle, string.Format("R{0}", i + 17));
|
pas.EmergencyCare = reader.ReadCellAsText(sheetTitle, string.Format("R{0}", i + 17));
|
||||||
@ -2475,9 +2471,7 @@ namespace ENI2.Excel
|
|||||||
pas.PassengerIdentityDocumentId = reader.ReadText(pasIdentDocId);
|
pas.PassengerIdentityDocumentId = reader.ReadText(pasIdentDocId);
|
||||||
pas.PassengerVisaNumber = reader.ReadText(pasVisaNo);
|
pas.PassengerVisaNumber = reader.ReadText(pasVisaNo);
|
||||||
pas.PassengerIdentityDocumentIssuingState = reader.ReadNationality(pasIssuing);
|
pas.PassengerIdentityDocumentIssuingState = reader.ReadNationality(pasIssuing);
|
||||||
pas.PassengerIdentityDocumentExpiryDate = reader.ReadDate(pasExpiryDate);
|
pas.PassengerIdentityDocumentExpiryDate = reader.ReadDate(pasExpiryDate) ?? (DateTime?)new DateTime(2100, 12, 31);
|
||||||
if (!pas.PassengerIdentityDocumentExpiryDate.HasValue)
|
|
||||||
pas.PassengerIdentityDocumentExpiryDate = new DateTime(2100, 12, 31);
|
|
||||||
pas.PassengerCountryOfBirth = reader.ReadNationality(pasCountryOfBirth);
|
pas.PassengerCountryOfBirth = reader.ReadNationality(pasCountryOfBirth);
|
||||||
pas.EmergencyCare = reader.ReadText(pasEmergencyCare);
|
pas.EmergencyCare = reader.ReadText(pasEmergencyCare);
|
||||||
pas.EmergencyContactNumber = reader.ReadText(pasEmergencyContact);
|
pas.EmergencyContactNumber = reader.ReadText(pasEmergencyContact);
|
||||||
@ -2590,8 +2584,6 @@ namespace ENI2.Excel
|
|||||||
|
|
||||||
#endregion LookupMessageCore
|
#endregion LookupMessageCore
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#region GetMessageWithType
|
#region GetMessageWithType
|
||||||
|
|
||||||
private static Message GetMessageWithType(List<Message> messages, MessageCore core, Message.NotificationClass type)
|
private static Message GetMessageWithType(List<Message> messages, MessageCore core, Message.NotificationClass type)
|
||||||
@ -2623,9 +2615,9 @@ namespace ENI2.Excel
|
|||||||
if (!gender.IsNullOrEmpty() && !result.HasValue)
|
if (!gender.IsNullOrEmpty() && !result.HasValue)
|
||||||
{
|
{
|
||||||
// special treatment / callback
|
// special treatment / callback
|
||||||
if (_genderImportDict.ContainsKey(gender))
|
if (ValueMapping.Dicts[ValueMapping.MappingType.GENDER].ContainsKey(gender))
|
||||||
{
|
{
|
||||||
result = byte.Parse(_genderImportDict[gender]); // we have mapped this before
|
result = byte.Parse(ValueMapping.Dicts[ValueMapping.MappingType.GENDER][gender].Value); // we have mapped this before
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -2637,8 +2629,14 @@ namespace ENI2.Excel
|
|||||||
{
|
{
|
||||||
if (!fid.SelectedValue.IsNullOrEmpty())
|
if (!fid.SelectedValue.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
_genderImportDict[gender] = fid.SelectedValue;
|
if (!ValueMapping.InvalidKeys[ValueMapping.MappingType.GENDER].Contains(gender))
|
||||||
result = byte.Parse(_genderImportDict[gender]);
|
{
|
||||||
|
string selectedValue = fid.SelectedValue;
|
||||||
|
Task<bool> createResult = Task.Run(async () => await ValueMapping.Create(ValueMapping.MappingType.GENDER, gender, selectedValue));
|
||||||
|
if (!createResult.Result)
|
||||||
|
_log.WarnFormat("Error saving gender value mapping {0} -> {1}", gender, selectedValue);
|
||||||
|
}
|
||||||
|
result = byte.Parse(fid.SelectedValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -2669,9 +2667,9 @@ namespace ENI2.Excel
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// special treatment / callback
|
// special treatment / callback
|
||||||
if (_documentTypeImportDict.ContainsKey(documentType))
|
if (ValueMapping.Dicts[ValueMapping.MappingType.DOCUMENT_TYPE].ContainsKey(documentType))
|
||||||
{
|
{
|
||||||
result = byte.Parse(_documentTypeImportDict[documentType]); // we have mapped this before
|
result = byte.Parse(ValueMapping.Dicts[ValueMapping.MappingType.DOCUMENT_TYPE][documentType].Value); // we have mapped this before
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -2683,8 +2681,14 @@ namespace ENI2.Excel
|
|||||||
{
|
{
|
||||||
if (!fid.SelectedValue.IsNullOrEmpty())
|
if (!fid.SelectedValue.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
_documentTypeImportDict[documentType] = fid.SelectedValue;
|
if(!ValueMapping.InvalidKeys[ValueMapping.MappingType.DOCUMENT_TYPE].Contains(documentType))
|
||||||
result = byte.Parse(_documentTypeImportDict[documentType]);
|
{
|
||||||
|
string selectedValue = fid.SelectedValue;
|
||||||
|
Task<bool> createResult = Task.Run<bool>(async () => await ValueMapping.Create(ValueMapping.MappingType.DOCUMENT_TYPE, documentType, selectedValue));
|
||||||
|
if (!createResult.Result)
|
||||||
|
_log.WarnFormat("Error saving document type value mapping {0} -> {1}", documentType, selectedValue);
|
||||||
|
}
|
||||||
|
result = byte.Parse(fid.SelectedValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -2715,9 +2719,9 @@ namespace ENI2.Excel
|
|||||||
{
|
{
|
||||||
result = CREW.NationalityDict.FirstOrDefault(x => x.Value.Substring(3).Equals(nationality, StringComparison.OrdinalIgnoreCase)).Key;
|
result = CREW.NationalityDict.FirstOrDefault(x => x.Value.Substring(3).Equals(nationality, StringComparison.OrdinalIgnoreCase)).Key;
|
||||||
}
|
}
|
||||||
else if (_countryImportDict.ContainsKey(nationality))
|
else if (ValueMapping.Dicts[ValueMapping.MappingType.COUNTRY].ContainsKey(nationality))
|
||||||
{
|
{
|
||||||
result = _countryImportDict[nationality];
|
result = ValueMapping.Dicts[ValueMapping.MappingType.COUNTRY][nationality].Value;
|
||||||
}
|
}
|
||||||
else // we cannot find whatever this is..
|
else // we cannot find whatever this is..
|
||||||
{
|
{
|
||||||
@ -2729,7 +2733,13 @@ namespace ENI2.Excel
|
|||||||
{
|
{
|
||||||
if (!fid.SelectedValue.IsNullOrEmpty())
|
if (!fid.SelectedValue.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
_countryImportDict[nationality] = fid.SelectedValue;
|
if(!ValueMapping.InvalidKeys[ValueMapping.MappingType.COUNTRY].Contains(nationality))
|
||||||
|
{
|
||||||
|
string selectedValue = fid.SelectedValue;
|
||||||
|
Task<bool> createResult = Task.Run<bool>(async () => await ValueMapping.Create(ValueMapping.MappingType.COUNTRY, nationality, selectedValue));
|
||||||
|
if(!createResult.Result)
|
||||||
|
_log.WarnFormat("Error saving nationality value mapping {0} -> {1}", nationality, selectedValue);
|
||||||
|
}
|
||||||
result = fid.SelectedValue.Substring(0, 2); // attention manual entry
|
result = fid.SelectedValue.Substring(0, 2); // attention manual entry
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2762,7 +2772,7 @@ namespace ENI2.Excel
|
|||||||
|
|
||||||
if (possibleLocodes.Count > 1)
|
if (possibleLocodes.Count > 1)
|
||||||
{
|
{
|
||||||
if (!_locodeImportDict.ContainsKey(val))
|
if (!ValueMapping.Dicts[ValueMapping.MappingType.LOCODE].ContainsKey(val))
|
||||||
{
|
{
|
||||||
FixImportDialog fid = new FixImportDialog();
|
FixImportDialog fid = new FixImportDialog();
|
||||||
fid.Value = val;
|
fid.Value = val;
|
||||||
@ -2773,15 +2783,20 @@ namespace ENI2.Excel
|
|||||||
fid.SelectionValues = ld;
|
fid.SelectionValues = ld;
|
||||||
if (fid.ShowDialog() ?? false)
|
if (fid.ShowDialog() ?? false)
|
||||||
{
|
{
|
||||||
_locodeImportDict[val] = fid.SelectedValue;
|
string selectedValue = fid.SelectedValue;
|
||||||
|
if (!ValueMapping.InvalidKeys[ValueMapping.MappingType.LOCODE].Contains(selectedValue)) {
|
||||||
|
Task<bool> createResult = Task.Run<bool>(async () => await ValueMapping.Create(ValueMapping.MappingType.LOCODE, val, selectedValue));
|
||||||
|
if (!createResult.Result)
|
||||||
|
_log.WarnFormat("Error saving locode value mapping {0} -> {1}", val, selectedValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
canceled = true;
|
canceled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (_locodeImportDict.ContainsKey(val))
|
if (ValueMapping.Dicts[ValueMapping.MappingType.LOCODE].ContainsKey(val))
|
||||||
result = _locodeImportDict[val];
|
result = ValueMapping.Dicts[ValueMapping.MappingType.LOCODE][val].Value;
|
||||||
}
|
}
|
||||||
else if (possibleLocodes.Count == 1)
|
else if (possibleLocodes.Count == 1)
|
||||||
{
|
{
|
||||||
@ -2789,7 +2804,7 @@ namespace ENI2.Excel
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!_locodeImportDict.ContainsKey(val))
|
if (!ValueMapping.Dicts[ValueMapping.MappingType.LOCODE].ContainsKey(val))
|
||||||
{
|
{
|
||||||
// nothing found, let the user pick a locode by himself
|
// nothing found, let the user pick a locode by himself
|
||||||
FixImportDialog fid = new FixImportDialog();
|
FixImportDialog fid = new FixImportDialog();
|
||||||
@ -2798,11 +2813,17 @@ namespace ENI2.Excel
|
|||||||
fid.LocodeMode = true;
|
fid.LocodeMode = true;
|
||||||
if (fid.ShowDialog() ?? false)
|
if (fid.ShowDialog() ?? false)
|
||||||
{
|
{
|
||||||
_locodeImportDict[val] = fid.SelectedValue;
|
if (!ValueMapping.InvalidKeys[ValueMapping.MappingType.LOCODE].Contains(fid.SelectedValue))
|
||||||
|
{
|
||||||
|
string selectedValue = fid.SelectedValue;
|
||||||
|
Task<bool> createResult = Task.Run(async () => await ValueMapping.Create(ValueMapping.MappingType.LOCODE, val, selectedValue));
|
||||||
|
if (!createResult.Result)
|
||||||
|
_log.WarnFormat("Error saving locode value mapping {0} -> {1}", val, selectedValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (_locodeImportDict.ContainsKey(val))
|
if (ValueMapping.Dicts[ValueMapping.MappingType.LOCODE].ContainsKey(val))
|
||||||
result = _locodeImportDict[val];
|
result = ValueMapping.Dicts[ValueMapping.MappingType.LOCODE][val].Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@ -37,8 +37,8 @@ namespace bsmd.database
|
|||||||
|
|
||||||
#region Fields
|
#region Fields
|
||||||
|
|
||||||
private static readonly Dictionary<MappingType, Dictionary<string, ValueMapping>> _dicts = new Dictionary<MappingType, Dictionary<string, ValueMapping>>();
|
private static Dictionary<MappingType, Dictionary<string, ValueMapping>> _dicts;
|
||||||
private static Dictionary<MappingType, List<string>> _invalidKeys = null;
|
private static Dictionary<MappingType, List<string>> _invalidKeys;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -46,7 +46,16 @@ namespace bsmd.database
|
|||||||
|
|
||||||
public static Dictionary<MappingType, Dictionary<string, ValueMapping>> Dicts
|
public static Dictionary<MappingType, Dictionary<string, ValueMapping>> Dicts
|
||||||
{
|
{
|
||||||
get { return _dicts; }
|
get
|
||||||
|
{
|
||||||
|
if (_dicts == null)
|
||||||
|
{
|
||||||
|
_dicts = new Dictionary<MappingType, Dictionary<string, ValueMapping>>();
|
||||||
|
foreach (MappingType type in Enum.GetValues(typeof(MappingType)))
|
||||||
|
_dicts[type] = new Dictionary<string, ValueMapping>();
|
||||||
|
}
|
||||||
|
return _dicts;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Dictionary<MappingType, List<string>> InvalidKeys
|
public static Dictionary<MappingType, List<string>> InvalidKeys
|
||||||
@ -59,7 +68,7 @@ namespace bsmd.database
|
|||||||
// get the keys initialized that cannot be assigned
|
// get the keys initialized that cannot be assigned
|
||||||
foreach (MappingType type in Enum.GetValues(typeof(MappingType)))
|
foreach (MappingType type in Enum.GetValues(typeof(MappingType)))
|
||||||
_invalidKeys[type] = new List<string>();
|
_invalidKeys[type] = new List<string>();
|
||||||
_invalidKeys[MappingType.COUNTRY].Add("UK");
|
_invalidKeys[MappingType.COUNTRY].Add("UK"); // can be mapped to GB and to UA .. we don't know what they want
|
||||||
}
|
}
|
||||||
return _invalidKeys;
|
return _invalidKeys;
|
||||||
}
|
}
|
||||||
@ -85,10 +94,7 @@ namespace bsmd.database
|
|||||||
/// <returns>true if entry was actually created, false if already present</returns>
|
/// <returns>true if entry was actually created, false if already present</returns>
|
||||||
public static async Task<bool> Create(MappingType type, string key, string value)
|
public static async Task<bool> Create(MappingType type, string key, string value)
|
||||||
{
|
{
|
||||||
if (!_dicts.ContainsKey(type))
|
if (!Dicts[type].ContainsKey(key))
|
||||||
_dicts[type] = new Dictionary<string, ValueMapping>();
|
|
||||||
|
|
||||||
if (!_dicts[type].ContainsKey(key))
|
|
||||||
{
|
{
|
||||||
ValueMapping vm = new ValueMapping()
|
ValueMapping vm = new ValueMapping()
|
||||||
{
|
{
|
||||||
@ -96,7 +102,7 @@ namespace bsmd.database
|
|||||||
Key = key,
|
Key = key,
|
||||||
Value = value
|
Value = value
|
||||||
};
|
};
|
||||||
_dicts[type][key] = vm;
|
Dicts[type][key] = vm;
|
||||||
return await DBManagerAsync.SaveAsync(vm) == 1;
|
return await DBManagerAsync.SaveAsync(vm) == 1;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -108,10 +114,10 @@ namespace bsmd.database
|
|||||||
/// <returns>true if successful, false if value was not found</returns>
|
/// <returns>true if successful, false if value was not found</returns>
|
||||||
public static async Task<bool> Delete(MappingType type, string key)
|
public static async Task<bool> Delete(MappingType type, string key)
|
||||||
{
|
{
|
||||||
if (!_dicts.ContainsKey(type)) return false;
|
if (!Dicts.ContainsKey(type)) return false;
|
||||||
if (!_dicts[type].ContainsKey(key)) return false;
|
if (!Dicts[type].ContainsKey(key)) return false;
|
||||||
ValueMapping vm = _dicts[type][key];
|
ValueMapping vm = Dicts[type][key];
|
||||||
_dicts[type].Remove(key);
|
Dicts[type].Remove(key);
|
||||||
return await DBManagerAsync.DeleteAsync(vm) == 1;
|
return await DBManagerAsync.DeleteAsync(vm) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,6 +131,20 @@ namespace bsmd.database
|
|||||||
return await DBManagerAsync.SaveAsync(this) == 1;
|
return await DBManagerAsync.SaveAsync(this) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// (re-)loads all value mapping dictionaries
|
||||||
|
/// </summary>
|
||||||
|
public static async void LoadDicts()
|
||||||
|
{
|
||||||
|
foreach(MappingType type in Enum.GetValues(typeof(MappingType)))
|
||||||
|
{
|
||||||
|
Dicts[type].Clear();
|
||||||
|
List<ValueMapping> mappings = await DBManagerAsync.LoadValuesForType(type);
|
||||||
|
foreach (ValueMapping mapping in mappings)
|
||||||
|
Dicts[type][mapping.Key] = mapping;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region DatabaseEntity implementation
|
#region DatabaseEntity implementation
|
||||||
|
|||||||
@ -96,7 +96,7 @@ namespace bsmd.database
|
|||||||
|
|
||||||
wdsp.id = reader.GetGuid(0);
|
wdsp.id = reader.GetGuid(0);
|
||||||
if (!reader.IsDBNull(1)) wdsp.WasteDisposalServiceProviderName = reader.GetString(1);
|
if (!reader.IsDBNull(1)) wdsp.WasteDisposalServiceProviderName = reader.GetString(1);
|
||||||
if (!reader.IsDBNull(3)) wdsp.Identifier = reader.GetString(2);
|
if (!reader.IsDBNull(2)) wdsp.Identifier = reader.GetString(2);
|
||||||
result.Add(wdsp);
|
result.Add(wdsp);
|
||||||
}
|
}
|
||||||
reader.Close();
|
reader.Close();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user