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 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
/// </summary>
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
@ -29,22 +27,53 @@ namespace bsmd.ExcelReadService
private List<Workbook> workbooks = new List<Workbook>();
private List<Dictionary<string, Name>> nameDicts = new List<Dictionary<string, Name>>();
private List<string> templateNames = new List<string>();
private List<Dictionary<string, string>> actualNameDict = null;
#region Construction
public Confirmation(System.Collections.Specialized.StringCollection sheetCollection, Application excelInstance)
{
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<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);
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,7 +121,7 @@ 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);
this.workbooks[i].Saved = true;
@ -116,17 +147,32 @@ namespace bsmd.ExcelReadService
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
{
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);
}
}
}
}
@ -148,7 +194,6 @@ namespace bsmd.ExcelReadService
return this.whiteColor;
}
#endregion
}

View File

@ -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();
}

View File

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

View File

@ -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?))
{
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?))
{
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?))
{
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<string> locodes = LocodeDB.AllLocodesForCityName(aGermanPortName);
if (locodes.Count > 0)
poc = locodes[0];
}
}
if (poc != null)

View File

@ -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("")]

View File

@ -1,4 +1,4 @@
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
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.