Version 3.3.1 Funktioniert leider noch nicht richtig, einige Zellen werden einfach nicht geschrieben.

This commit is contained in:
Daniel Schick 2017-01-01 18:19:00 +00:00
parent a9ce7aacb2
commit 6525178314
8 changed files with 142 additions and 31 deletions

Binary file not shown.

View File

@ -1,13 +1,11 @@
using log4net; using log4net;
using Microsoft.Office.Interop.Excel; using Microsoft.Office.Interop.Excel;
using System.Runtime.InteropServices;
using System; using System;
using System.Drawing; using System.Reflection;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing;
using System.IO; using System.IO;
using System.Linq; using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace bsmd.ExcelReadService namespace bsmd.ExcelReadService
{ {
@ -19,7 +17,7 @@ namespace bsmd.ExcelReadService
/// </summary> /// </summary>
internal class Confirmation : IDisposable 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 okColor = ColorTranslator.ToOle(Color.FromArgb(200, 255, 200)); // light green
private int warnColor = ColorTranslator.ToOle(Color.FromArgb(255, 255, 200)); // yellow private int warnColor = ColorTranslator.ToOle(Color.FromArgb(255, 255, 200)); // yellow
@ -28,23 +26,54 @@ namespace bsmd.ExcelReadService
private List<Workbook> workbooks = new List<Workbook>(); private List<Workbook> workbooks = new List<Workbook>();
private List<Dictionary<string, Name>> nameDicts = new List<Dictionary<string, Name>>(); private List<Dictionary<string, Name>> nameDicts = new List<Dictionary<string, Name>>();
private List<string> templateNames = new List<string>(); private List<string> templateNames = new List<string>();
private List<Dictionary<string, string>> actualNameDict = null;
#region Construction #region Construction
public Confirmation(System.Collections.Specialized.StringCollection sheetCollection, Application excelInstance) public Confirmation(System.Collections.Specialized.StringCollection sheetCollection, Application excelInstance)
{ {
foreach(string template in sheetCollection) string nameDictKey = "";
foreach (string template in sheetCollection)
{ {
try try
{ {
nameDictKey += template;
// die Templates sollten echte Excel Templates (.xlst) sein // 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); 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<string, Name> nameDict = new Dictionary<string, Name>(); Dictionary<string, Name> nameDict = new Dictionary<string, Name>();
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); workbooks.Add(aWorkbook);
nameDicts.Add(nameDict); nameDicts.Add(nameDict);
templateNames.Add(Path.GetFileNameWithoutExtension(template)); templateNames.Add(Path.GetFileNameWithoutExtension(template));
@ -54,6 +83,8 @@ namespace bsmd.ExcelReadService
_log.ErrorFormat("Failure creating sheet from template {0}:{1}", template, ex.Message); _log.ErrorFormat("Failure creating sheet from template {0}:{1}", template, ex.Message);
} }
} }
} }
#endregion #endregion
@ -90,9 +121,9 @@ namespace bsmd.ExcelReadService
// construct file path // construct file path
string fileNameWithPath = Path.Combine(Path.GetDirectoryName(receivedFileName), string fileNameWithPath = Path.Combine(Path.GetDirectoryName(receivedFileName),
string.Format("{0}_{1}.xlsx", this.templateNames[i], Path.GetFileNameWithoutExtension(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, XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing); Type.Missing, Type.Missing);
this.workbooks[i].Saved = true; this.workbooks[i].Saved = true;
result.Add(fileNameWithPath); result.Add(fileNameWithPath);
this.workbooks[i].Close(); this.workbooks[i].Close();
@ -115,18 +146,33 @@ namespace bsmd.ExcelReadService
#region private #region private
private void ConfirmValue(string lookup, object value, ExcelReader.ReadState state) private void ConfirmValue(string lookup, object value, ExcelReader.ReadState state)
{ {
for (int i = 0; i < this.nameDicts.Count; i++) for(int i=0;i<this.workbooks.Count;i++)
{ {
if (this.nameDicts[i].ContainsKey(lookup)) Workbook workbook = this.workbooks[i];
Dictionary<string, Name> nameDict = this.nameDicts[i];
Name someName = null;
if(nameDict.ContainsKey(lookup))
{ {
Range range = this.nameDicts[i][lookup].RefersToRange; try
if (range != null)
{ {
range.Interior.Color = this.ColorForState(state); someName = nameDict[lookup];
range.Value = value;
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; return this.whiteColor;
} }
#endregion #endregion
} }

View File

@ -33,7 +33,8 @@ namespace bsmd.ExcelReadService
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly(); System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location); FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
string version = fvi.FileVersion; 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(); this.DoOnce();
} }

View File

@ -18,6 +18,7 @@ namespace bsmd.ExcelReadService
if (Debugger.IsAttached) if (Debugger.IsAttached)
{ {
// Confirmation.InitDictionaries();
((ExcelReadService)ServicesToRun[0]).DoOnce(); ((ExcelReadService)ServicesToRun[0]).DoOnce();
} }
else else

View File

@ -1184,37 +1184,82 @@ namespace bsmd.ExcelReadService
{ {
DateTime? sheetValue = reader.ReadDate(lookupNameAttribute.LookupName); DateTime? sheetValue = reader.ReadDate(lookupNameAttribute.LookupName);
if (sheetValue != null) if (sheetValue != null)
{
property.SetValue(dbEntity, sheetValue); 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?)) else if (property.PropertyType == typeof(double?))
{ {
double? sheetValue = reader.ReadNumber(lookupNameAttribute.LookupName); double? sheetValue = reader.ReadNumber(lookupNameAttribute.LookupName);
if (sheetValue != null) if (sheetValue != null)
{
property.SetValue(dbEntity, sheetValue); 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)) else if (property.PropertyType == typeof(string))
{ {
string sheetValue = reader.ReadText(lookupNameAttribute.LookupName); string sheetValue = reader.ReadText(lookupNameAttribute.LookupName);
if (sheetValue != null) if (sheetValue != null)
{
property.SetValue(dbEntity, sheetValue); 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); double? sheetValue = reader.ReadNumber(lookupNameAttribute.LookupName);
if (sheetValue.HasValue) if (sheetValue.HasValue)
{
property.SetValue(dbEntity, (int)sheetValue.Value); 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); double? sheetValue = reader.ReadNumber(lookupNameAttribute.LookupName);
if (sheetValue.HasValue) if (sheetValue.HasValue)
{
property.SetValue(dbEntity, (byte)sheetValue.Value); 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); bool? sheetValue = reader.ReadBoolean(lookupNameAttribute.LookupName);
if (sheetValue.HasValue) string boolStringValue = reader.ReadText(lookupNameAttribute.LookupName);
if (sheetValue.HasValue) {
property.SetValue(dbEntity, sheetValue); 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 else
{ {
@ -1298,6 +1343,24 @@ namespace bsmd.ExcelReadService
// somehow lookup LOCODE from the port's name! // somehow lookup LOCODE from the port's name!
poc = LocodeDB.LocodeGERFromCity(aGermanPortName); 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<string> locodes = LocodeDB.AllLocodesForCityName(aGermanPortName);
if (locodes.Count > 0)
poc = locodes[0];
}
} }
if (poc != null) if (poc != null)

View File

@ -2,6 +2,6 @@
[assembly: AssemblyCompany("Informatikbüro Daniel Schick")] [assembly: AssemblyCompany("Informatikbüro Daniel Schick")]
[assembly: AssemblyProduct("BSMD NSW interface")] [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: AssemblyCopyright("Copyright © 2014-2016 Informatikbüro Daniel Schick. All rights reserved.")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]

View File

@ -1,4 +1,4 @@
using System.Reflection; using System.Reflection;
[assembly: AssemblyVersion("3.3.0.*")] [assembly: AssemblyVersion("3.3.1.*")]

View File

@ -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 - 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. 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. mit BSMD\daniel.schick# hat es dann geklappt.
Anschließend kann man in "Dienste" die Anmeldeinformationen wieder auf das normale Systemkonto setzen.