diff --git a/Stundensheet.xlsx b/Stundensheet.xlsx index 2926e12d..e9fb3843 100644 Binary files a/Stundensheet.xlsx and b/Stundensheet.xlsx differ diff --git a/nsw/Source/bsmd.ExcelReadService/Confirmation.cs b/nsw/Source/bsmd.ExcelReadService/Confirmation.cs index 13e629b3..233071ce 100644 --- a/nsw/Source/bsmd.ExcelReadService/Confirmation.cs +++ b/nsw/Source/bsmd.ExcelReadService/Confirmation.cs @@ -1,13 +1,11 @@ using log4net; using Microsoft.Office.Interop.Excel; -using System.Runtime.InteropServices; using System; -using System.Drawing; +using System.Reflection; using System.Collections.Generic; +using System.Drawing; using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Runtime.InteropServices; namespace bsmd.ExcelReadService { @@ -19,7 +17,7 @@ namespace bsmd.ExcelReadService /// internal class Confirmation : IDisposable { - private ILog _log = LogManager.GetLogger(typeof(Confirmation)); + private static ILog _log = LogManager.GetLogger(typeof(Confirmation)); private int okColor = ColorTranslator.ToOle(Color.FromArgb(200, 255, 200)); // light green private int warnColor = ColorTranslator.ToOle(Color.FromArgb(255, 255, 200)); // yellow @@ -28,23 +26,54 @@ namespace bsmd.ExcelReadService private List workbooks = new List(); private List> nameDicts = new List>(); - private List templateNames = new List(); + private List templateNames = new List(); + private List> actualNameDict = null; #region Construction public Confirmation(System.Collections.Specialized.StringCollection sheetCollection, Application excelInstance) { - foreach(string template in sheetCollection) + string nameDictKey = ""; + + foreach (string template in sheetCollection) { try { + nameDictKey += template; // die Templates sollten echte Excel Templates (.xlst) sein Workbook aWorkbook = excelInstance.Workbooks.Open(template, 0, false, 5, "", "", false, XlPlatform.xlWindows, "", true, false, 0, false, false, false); + + + /* + if (aWorkbook == excelInstance.ActiveWorkbook) + _log.Info("aWorkbook is active workbook"); + else + aWorkbook.Activate(); + + */ + Dictionary nameDict = new Dictionary(); - foreach (Name name in aWorkbook.Names) + + + // hier müsste etwas hin das nur aus der eben geladenen Vorlage die Namen rauszieht.. + // eben nicht aus *allen* Vorlagen. Das funktioniert auch nur liefern einige der Names keine Ranges.. + + foreach(Name workbookName in aWorkbook.Names) { - nameDict[name.Name] = name; - } + _log.Info(workbookName.Name); + if (workbookName.Name.Contains("!")) + { + continue; + } + else + { + nameDict[workbookName.Name] = workbookName; + } + + } + + + workbooks.Add(aWorkbook); nameDicts.Add(nameDict); templateNames.Add(Path.GetFileNameWithoutExtension(template)); @@ -54,6 +83,8 @@ namespace bsmd.ExcelReadService _log.ErrorFormat("Failure creating sheet from template {0}:{1}", template, ex.Message); } } + + } #endregion @@ -90,9 +121,9 @@ namespace bsmd.ExcelReadService // construct file path string fileNameWithPath = Path.Combine(Path.GetDirectoryName(receivedFileName), string.Format("{0}_{1}.xlsx", this.templateNames[i], Path.GetFileNameWithoutExtension(receivedFileName))); - this.workbooks[i].SaveAs(fileNameWithPath, Type.Missing, Type.Missing, Type.Missing, Type.Missing, + this.workbooks[i].SaveAs(fileNameWithPath, XlFileFormat.xlOpenXMLWorkbook, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, - Type.Missing, Type.Missing); + Type.Missing, Type.Missing); this.workbooks[i].Saved = true; result.Add(fileNameWithPath); this.workbooks[i].Close(); @@ -115,18 +146,33 @@ namespace bsmd.ExcelReadService #region private private void ConfirmValue(string lookup, object value, ExcelReader.ReadState state) - { - for (int i = 0; i < this.nameDicts.Count; i++) + { + for(int i=0;i nameDict = this.nameDicts[i]; + + Name someName = null; + if(nameDict.ContainsKey(lookup)) { - Range range = this.nameDicts[i][lookup].RefersToRange; - if (range != null) + try { - range.Interior.Color = this.ColorForState(state); - range.Value = value; + someName = nameDict[lookup]; + + Range range = someName.RefersToRange; + if (range != null) + { + range.Interior.Color = this.ColorForState(state); + range.Value = value; + } + Marshal.ReleaseComObject(range); + _log.InfoFormat("Value {0} for lookup {1} OK", value, lookup); + } + catch(Exception ex) + { + _log.WarnFormat("cannot set value {0} for lookup {1}: {2}", + value, lookup, ex.Message); } - Marshal.ReleaseComObject(range); } } } @@ -148,7 +194,6 @@ namespace bsmd.ExcelReadService return this.whiteColor; } - #endregion } diff --git a/nsw/Source/bsmd.ExcelReadService/ExcelReadService.cs b/nsw/Source/bsmd.ExcelReadService/ExcelReadService.cs index c858f9ed..ae54290a 100644 --- a/nsw/Source/bsmd.ExcelReadService/ExcelReadService.cs +++ b/nsw/Source/bsmd.ExcelReadService/ExcelReadService.cs @@ -33,7 +33,8 @@ namespace bsmd.ExcelReadService System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly(); FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location); string version = fvi.FileVersion; - this._log.InfoFormat("Starting NSW Excel Read Service. v.{0} -------------- ", version); + _log.InfoFormat("Starting NSW Excel Read Service. v.{0} -------------- ", version); + //Confirmation.InitDictionaries(); this.DoOnce(); } diff --git a/nsw/Source/bsmd.ExcelReadService/Program.cs b/nsw/Source/bsmd.ExcelReadService/Program.cs index fbddd2c1..1987eeb5 100644 --- a/nsw/Source/bsmd.ExcelReadService/Program.cs +++ b/nsw/Source/bsmd.ExcelReadService/Program.cs @@ -18,6 +18,7 @@ namespace bsmd.ExcelReadService if (Debugger.IsAttached) { + // Confirmation.InitDictionaries(); ((ExcelReadService)ServicesToRun[0]).DoOnce(); } else diff --git a/nsw/Source/bsmd.ExcelReadService/Util.cs b/nsw/Source/bsmd.ExcelReadService/Util.cs index 4412198e..dbfdbc91 100644 --- a/nsw/Source/bsmd.ExcelReadService/Util.cs +++ b/nsw/Source/bsmd.ExcelReadService/Util.cs @@ -1184,37 +1184,82 @@ namespace bsmd.ExcelReadService { DateTime? sheetValue = reader.ReadDate(lookupNameAttribute.LookupName); if (sheetValue != null) + { property.SetValue(dbEntity, sheetValue); - } + reader.Conf.ConfirmDate(lookupNameAttribute.LookupName, sheetValue, ExcelReader.ReadState.OK); + } + else + { + reader.Conf.ConfirmDate(lookupNameAttribute.LookupName, sheetValue, ExcelReader.ReadState.WARN); + } + + } else if (property.PropertyType == typeof(double?)) { double? sheetValue = reader.ReadNumber(lookupNameAttribute.LookupName); if (sheetValue != null) + { property.SetValue(dbEntity, sheetValue); - } + reader.Conf.ConfirmNumber(lookupNameAttribute.LookupName, sheetValue, ExcelReader.ReadState.OK); + } + else + { + reader.Conf.ConfirmNumber(lookupNameAttribute.LookupName, sheetValue, ExcelReader.ReadState.WARN); + } + } else if (property.PropertyType == typeof(string)) { string sheetValue = reader.ReadText(lookupNameAttribute.LookupName); if (sheetValue != null) + { property.SetValue(dbEntity, sheetValue); + reader.Conf.ConfirmText(lookupNameAttribute.LookupName, sheetValue, ExcelReader.ReadState.OK); + } + else + { + reader.Conf.ConfirmText(lookupNameAttribute.LookupName, sheetValue, ExcelReader.ReadState.WARN); + } } - else if(property.PropertyType == typeof(int?)) + else if (property.PropertyType == typeof(int?)) { double? sheetValue = reader.ReadNumber(lookupNameAttribute.LookupName); if (sheetValue.HasValue) + { property.SetValue(dbEntity, (int)sheetValue.Value); + reader.Conf.ConfirmNumber(lookupNameAttribute.LookupName, sheetValue, ExcelReader.ReadState.OK); + } + else + { + reader.Conf.ConfirmNumber(lookupNameAttribute.LookupName, sheetValue, ExcelReader.ReadState.WARN); + } } - else if(property.PropertyType == typeof(byte?)) + else if (property.PropertyType == typeof(byte?)) { double? sheetValue = reader.ReadNumber(lookupNameAttribute.LookupName); if (sheetValue.HasValue) + { property.SetValue(dbEntity, (byte)sheetValue.Value); + reader.Conf.ConfirmNumber(lookupNameAttribute.LookupName, sheetValue, ExcelReader.ReadState.OK); + } + else + { + reader.Conf.ConfirmNumber(lookupNameAttribute.LookupName, sheetValue, ExcelReader.ReadState.WARN); + } + } - else if(property.PropertyType == typeof(Boolean?)) + else if (property.PropertyType == typeof(Boolean?)) { bool? sheetValue = reader.ReadBoolean(lookupNameAttribute.LookupName); - if (sheetValue.HasValue) + string boolStringValue = reader.ReadText(lookupNameAttribute.LookupName); + if (sheetValue.HasValue) { property.SetValue(dbEntity, sheetValue); + reader.Conf.ConfirmText(lookupNameAttribute.LookupName, sheetValue.Value ? "Y" : "N", + ExcelReader.ReadState.OK); + } + else + { + reader.Conf.ConfirmText(lookupNameAttribute.LookupName, boolStringValue, ExcelReader.ReadState.WARN); + } } else { @@ -1298,6 +1343,24 @@ namespace bsmd.ExcelReadService // somehow lookup LOCODE from the port's name! poc = LocodeDB.LocodeGERFromCity(aGermanPortName); } + + // okay, könnte DK Locode etc sein.. + if(poc == null) + { + if((aGermanPortName != null) && (aGermanPortName.Length == 5)) // possible locode? + { + if (LocodeDB.PortNameFromLocode(aGermanPortName) != null) + poc = aGermanPortName; + } + } + + if(poc == null) + { + List locodes = LocodeDB.AllLocodesForCityName(aGermanPortName); + if (locodes.Count > 0) + poc = locodes[0]; + } + } if (poc != null) diff --git a/nsw/Source/bsmd.database/Properties/AssemblyProductInfo.cs b/nsw/Source/bsmd.database/Properties/AssemblyProductInfo.cs index 4a2be253..a6c6dca6 100644 --- a/nsw/Source/bsmd.database/Properties/AssemblyProductInfo.cs +++ b/nsw/Source/bsmd.database/Properties/AssemblyProductInfo.cs @@ -2,6 +2,6 @@ [assembly: AssemblyCompany("Informatikbüro Daniel Schick")] [assembly: AssemblyProduct("BSMD NSW interface")] -[assembly: AssemblyInformationalVersion("3.3.0")] +[assembly: AssemblyInformationalVersion("3.3.1")] [assembly: AssemblyCopyright("Copyright © 2014-2016 Informatikbüro Daniel Schick. All rights reserved.")] [assembly: AssemblyTrademark("")] \ No newline at end of file diff --git a/nsw/Source/bsmd.database/Properties/AssemblyProjectInfo.cs b/nsw/Source/bsmd.database/Properties/AssemblyProjectInfo.cs index 72cc0f52..cb5009fe 100644 --- a/nsw/Source/bsmd.database/Properties/AssemblyProjectInfo.cs +++ b/nsw/Source/bsmd.database/Properties/AssemblyProjectInfo.cs @@ -1,4 +1,4 @@ using System.Reflection; -[assembly: AssemblyVersion("3.3.0.*")] +[assembly: AssemblyVersion("3.3.1.*")] diff --git a/nsw/Source/misc/info_service_installation.txt b/nsw/Source/misc/info_service_installation.txt index 7fe79e69..7af2dd32 100644 --- a/nsw/Source/misc/info_service_installation.txt +++ b/nsw/Source/misc/info_service_installation.txt @@ -7,3 +7,4 @@ So hat es dann geklappt: - Dann erscheint ein Dialog, in dem man Username + Passwort für den Service angeben muss. Das hat nicht funktioniert für den Admin, auch nicht für meinen User ohne die Domäne vorne dran. mit BSMD\daniel.schick# hat es dann geklappt. +Anschließend kann man in "Dienste" die Anmeldeinformationen wieder auf das normale Systemkonto setzen.