using log4net; using Microsoft.Office.Interop.Excel; using System.Runtime.InteropServices; using System; using System.Drawing; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace bsmd.ExcelReadService { /// /// Kapselt die Implementierung / Schreiben des Bestätigungs-Sheets. Bisher wurde das Highlighting direkt in das ursprüngl. Sheet /// übernommen. Da die Bestätigung aber anders aussieht und aus mehreren Sheets bestehen kann ist das jetzt abgetrennt in einer /// eignenen Klasse. Der Pfad zu den Templates ist in den Settings hinterlegt, die Klasse wird mit der entspr. Collection aufgerufen /// Das wiederum ergibt sich aus dem Zielhafen in PoC. /// internal class Confirmation : IDisposable { private 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 private int failColor = ColorTranslator.ToOle(Color.FromArgb(255, 150, 150)); // light red private int whiteColor = ColorTranslator.ToOle(Color.White); private List workbooks = new List(); private List> nameDicts = new List>(); private List templateNames = new List(); #region Construction public Confirmation(System.Collections.Specialized.StringCollection sheetCollection, Application excelInstance) { foreach(string template in sheetCollection) { try { // 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); Dictionary nameDict = new Dictionary(); foreach (Name name in aWorkbook.Names) { nameDict[name.Name] = name; } workbooks.Add(aWorkbook); nameDicts.Add(nameDict); templateNames.Add(Path.GetFileNameWithoutExtension(template)); } catch(Exception ex) { _log.ErrorFormat("Failure creating sheet from template {0}:{1}", template, ex.Message); } } } #endregion #region public public void ConfirmText(string lookup, string value, ExcelReader.ReadState state) { this.ConfirmValue(lookup, value, state); } public void ConfirmNumber(string lookup, double? value, ExcelReader.ReadState state) { this.ConfirmValue(lookup, value, state); } public void ConfirmDate(string lookup, DateTime? value, ExcelReader.ReadState state) { this.ConfirmValue(lookup, value, state); } public void ConfirmTime(string lookup, DateTime? value, ExcelReader.ReadState state) { this.ConfirmValue(lookup, value, state); } public List SaveConfirmationSheets(string receivedFileName) { List result = new List(); for(int i=0;i