Esempio n. 1
0
        /// <summary>
        /// Erzeugt eine SQL-Abfrage der Alarmdatenbank und speichert das Ergebnis in einer Excel-Tabelle.
        /// Die Excel-Tabelle wird in ein PDF gewandelt. keepExcelFile bestimmt, ob die Excel-Datei gelöscht wird.
        /// </summary>
        /// <param name="keepExcelFile">true = erzeugt Exceldatei und PDF; false = nur PDF.</param>
        internal static void AlmListToExcel(bool keepExcelFile) //Fehlernummern siehe Log.cs 1101ZZ
        {
            Log.Write(Log.Cat.MethodCall, Log.Prio.Info, 110101, string.Format("AlmListToExcel({0})", keepExcelFile));

            try
            {
                string sqlQuery = SqlQueryString();
                if (sqlQuery.Length < 1)
                {
                    return;
                }

                DataTable dt = SqlQyery(SqlConnString, sqlQuery);

                string almPrintFilePath = Path.Combine(Excel.XlArchiveDir, "Listen");
                Directory.CreateDirectory(almPrintFilePath);
                almPrintFilePath = Path.Combine(almPrintFilePath, string.Format("AlmDruck_{0:yyyy-MM-dd_HH-mm-ss}.xlsx", EndTime));

                TryCreateNewExcelAlmFile(almPrintFilePath);

                FillAlmListFile(almPrintFilePath, dt);

                Tools.Wait(1);

                Pdf.CreatePdf(almPrintFilePath);

                if (!keepExcelFile)
                {
                    File.Delete(almPrintFilePath);
                }
            }
            catch (SqlException sql_ex)
            {
                Log.Write(Log.Cat.SqlQuery, Log.Prio.Error, 110102, string.Format("Fehler in SQL-Syntax: \r\n\t\t\t{0}:\r\n\t\t\t{1}\r\n\t\t\t{2}\r\n", DataSource, SqlQueryString(), sql_ex.Message));
                Program.AppErrorOccured = true;
            }
            catch (Exception ex)
            {
                Log.Write(Log.Cat.SqlQuery, Log.Prio.Error, 110103, string.Format("Fehler beim Auslesen der AlmDatenbank: Typ: {0} \r\n\t\t\t\tFehlertext: {1}  \r\n\t\t\t\tInnerException: {2}  \r\n\t\t\t\tStackTrace: {3}\r\n\r\n\r\n CONSTRING: {4}", ex.GetType().ToString(), ex.Message, ex.InnerException, ex.StackTrace, SqlConnString));
                Program.AppErrorOccured = true;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// direkte PDF-Erzeugen aus InTouch z.B. aus PDF-Betrachter.
        /// </summary>
        public static void CreatePdfFromCmd() //Fehlernummern siehe Log.cs 0804ZZ
        {
            Log.Write(Log.Cat.MethodCall, Log.Prio.Info, 080401, string.Format("CreatePdfFromCmd()"));

            if (Program.CmdArgs.Length > 1)
            {
                string xlFilePath = Program.CmdArgs[1];
                if (File.Exists(xlFilePath))
                {
                    Log.Write(Log.Cat.PdfWrite, Log.Prio.Info, 080402, "Erzeuge PDF-Datei aus " + xlFilePath);
                    Pdf.CreatePdf(xlFilePath);
                }
                else
                {
                    Log.Write(Log.Cat.FileSystem, Log.Prio.Error, 080403, "Es konnte keine PDF-Datei erstellt werden. Ungültige Quelldatei: " + xlFilePath);
                    //Program.AppErrorOccured = true;
                }
            }
            else
            {
                Log.Write(Log.Cat.PdfWrite, Log.Prio.Error, 080404, "Es konnte keine PDF-Datei erstellt werden. Fehlendes 2. Argument für Quellpfad (xslx)");
                //Program.AppErrorOccured = true;
            }
        }
Esempio n. 3
0
        internal static string InTouchDIntErrorNumber             = "XlLogErrorNumber";    //An InTouch weiterzugebene Fehlernummer
        #endregion

        #endregion

        static void Main(string[] args) //Fehlernummern siehe Log.cs 0101ZZ
        {
            #region Vorbereitende Abfragen
            try
            {
                CmdArgs = args;

                if (CmdArgs.Length < 1)
                {
                    AppStartedBy = Environment.UserName;
                }
                else
                {
                    AppStartedBy = CmdArgs[0].Remove(0, 1);
                }
                Config.LoadConfig();

                Log.Write(Log.Cat.OnStart, Log.Prio.LogAlways, 010101, string.Format("Gestartet durch {0}, Debug {1}, V{2}", AppStartedBy, Log.DebugWord, System.Reflection.Assembly.GetExecutingAssembly().GetName().Version));

                #region PDF erstellen per Drag&Drop
                try
                {
                    if (CmdArgs.Length > 0)
                    {
                        if (File.Exists(CmdArgs[0]) && Path.GetExtension(CmdArgs[0]) == ".xlsx")
                        {
                            //Wenn der Pfad zu einer Excel-Dateie übergebenen wurde, diese in PDF umwandeln, danach beenden
                            Console.WriteLine("Wandle Excel-Dateie in PDF " + CmdArgs[0]);
                            Log.Write(Log.Cat.PdfWrite, Log.Prio.LogAlways, 010100, "Wandle Excel-Datei in PDF " + CmdArgs[0]);
                            Pdf.CreatePdf(CmdArgs[0]);
                            Console.WriteLine("Exel-Datei " + CmdArgs[0] + " umgewandelt in PDF.\r\nBeliebige Taste drücken zum Beenden...");
                            Console.ReadKey();
                            return;
                        }
                        else if (!File.Exists(CmdArgs[0]) && Directory.Exists(CmdArgs[0]))
                        {
                            //Alle Excel-Dateien im übergebenen Ordner in PDF umwandeln, danach beenden
                            Console.WriteLine("Wandle alle Excel-Dateien in PDF im Ordner " + CmdArgs[0]);
                            Log.Write(Log.Cat.PdfWrite, Log.Prio.LogAlways, 010100, "Wandle alle Excel-Dateien in PDF im Ordner " + CmdArgs[0]);
                            Pdf.CreatePdf4AllXlsxInDir(CmdArgs[0], false);
                            Console.WriteLine("Exel-Dateien umgewandelt in " + CmdArgs[0] + "\r\nBeliebige Taste drücken zum Beenden...");
                            Console.ReadKey();
                            return;
                        }
                    }
                }
                catch
                {
                    Log.Write(Log.Cat.PdfWrite, Log.Prio.Error, 010118, string.Format("Fehler beim Erstellen von PDF durch Drag'n'Drop. Aufrufargumente prüfen."));
                }
                #endregion

                EmbededDLL.LoadDlls();

                bool makerIsRunning = Process.GetProcessesByName("wm").Length != 0;
                if (makerIsRunning)
                {
                    Log.Write(Log.Cat.OnStart, Log.Prio.Error, 010102, "Das Programm kann nicht zusammen mit dem InTouch WindowMaker / Manager ausgeführt werden und wird deshalb beendet.");
                    Console.WriteLine("ACHTUNG: Das Programm kann nicht zusammen mit dem InTouch WindowMaker / Manager ausgeführt werden und wird deshalb beendet.");
                    Tools.Wait(10);
                    return;
                }


                bool viewerIsRunning = Process.GetProcessesByName("view").Length != 0;

                if (!viewerIsRunning)
                {
                    Log.Write(Log.Cat.OnStart, Log.Prio.Error, 010103, "Das Programm kann nicht ohne den InTouch Viewer ausgeführt werden und wird deshalb beendet.");
                    Console.WriteLine("ACHTUNG: Das Programm kann nicht ohne den InTouch Viewer ausgeführt werden und wird deshalb beendet.");
                    Tools.Wait(10);
                    return;
                }

                if (!File.Exists(NativeMethods.PtaccPath))
                {
                    Log.Write(Log.Cat.InTouchDB, Log.Prio.Info, 010104, string.Format("Datei für 64bit-OS nicht gefunden: " + NativeMethods.PtaccPath));

                    if (!File.Exists(NativeMethods32.PtaccPath))
                    {
                        Log.Write(Log.Cat.InTouchDB, Log.Prio.Error, 010104, string.Format("Datei für 64bit oder 32bit-OS nicht gefunden: \r\n" +
                                                                                           NativeMethods.PtaccPath + "\r\n" +
                                                                                           NativeMethods32.PtaccPath + "\r\n"));
                        Console.WriteLine("ACHTUNG: Das Programm kann nicht ohne die Datei " + Path.GetFileName(NativeMethods32.PtaccPath) + " ausgeführt werden und wird deshalb beendet. Beachte Log-Datei.");
                        Tools.Wait(10);
                        return;
                    }
                    else
                    {
                        InTouch.Is32BitSystem = true;
                    }
                }
                else
                {
                    InTouch.Is32BitSystem = false;
                }

                if (!File.Exists(NativeMethods.WwheapPath))
                {
                    Log.Write(Log.Cat.InTouchDB, Log.Prio.Info, 010104, string.Format("Datei für 64bit-OS nicht gefunden: " + NativeMethods.WwheapPath));

                    if (!File.Exists(NativeMethods32.WwheapPath))
                    {
                        Log.Write(Log.Cat.InTouchDB, Log.Prio.Error, 010104, string.Format("Datei für 64bit oder 32bit-OS nicht gefunden: \r\n" +
                                                                                           NativeMethods.WwheapPath + "\r\n" +
                                                                                           NativeMethods32.WwheapPath + "\r\n"));
                        Console.WriteLine("ACHTUNG: Das Programm kann nicht ohne die Datei " + Path.GetFileName(NativeMethods32.WwheapPath) + " ausgeführt werden und wird deshalb beendet. Beachte Log-Datei.");
                        Tools.Wait(10);
                        return;
                    }
                    else
                    {
                        InTouch.Is32BitSystem = true;
                    }
                }
                else
                {
                    InTouch.Is32BitSystem = false;
                }



                //if (!File.Exists(NativeMethods.WwheapPath))
                //{
                //    Log.Write(Log.Cat.InTouchDB, Log.Prio.Error, 010107, string.Format("Datei nicht gefunden: " + NativeMethods.WwheapPath));
                //    Console.WriteLine("ACHTUNG: Das Programm kann nicht ohne die Datei " + NativeMethods.WwheapPath + " ausgeführt werden und wird deshalb beendet. Beachte Log-Datei.");

                //    if (Path.GetDirectoryName(NativeMethods.WwheapPath).Contains(" (x86)"))
                //    {
                //        Log.Write(Log.Cat.InTouchDB, Log.Prio.Error, 010108, string.Format("Dieses Programm ist für ein 64-Bit Betriebssystem ausgelegt."));
                //    }
                //    else if (Path.GetDirectoryName(NativeMethods.PtaccPath).StartsWith(@"C:\Program Files\"))
                //    {
                //        Log.Write(Log.Cat.InTouchDB, Log.Prio.Error, 010109, string.Format("Dieses Programm ist für ein 32-Bit Betriebssystem ausgelegt."));
                //    }

                //    Tools.Wait(10);
                //    return;
                //}

                if (!File.Exists(Excel.XlTemplateDayFilePath))
                {
                    Log.Write(Log.Cat.InTouchDB, Log.Prio.Error, 010110, string.Format("Vorlage für Tagesdatei nicht gefunden unter: " + Excel.XlTemplateDayFilePath));
                    //AppErrorOccured = true;
                }

                if (!File.Exists(Excel.XlTemplateMonthFilePath))
                {
                    Log.Write(Log.Cat.ExcelRead, Log.Prio.Warning, 010111, string.Format("Keine Vorlage für Monatsdatei gefunden."));
                    //kein Fehler
                }

                if ((bool)InTouch.ReadTag(InTouchDiscXlLogFlag) != true)
                {
                    Log.Write(Log.Cat.InTouchVar, Log.Prio.Error, 010112, "Freigabe-Flag >" + InTouchDiscXlLogFlag + "< wurde nicht in InTouch gesetzt. Das Programm wird beendet.");
                    //AppErrorOccured = true;
                    return;
                }

                string Operator = (string)InTouch.ReadTag("$Operator");
                Log.Write(Log.Cat.Info, Log.Prio.Info, 010113, "Angemeldet in InTouch: >" + Operator + "<");

                Scheduler.CeckOrCreateTaskScheduler();

                if (!Directory.Exists(Excel.XlArchiveDir))
                {
                    try
                    {
                        Directory.CreateDirectory(Excel.XlArchiveDir);
                    }
                    catch (Exception ex)
                    {
                        Log.Write(Log.Cat.FileSystem, Log.Prio.Error, 010114, string.Format("Archivordner konnte nicht gefunden oder erstellt werden: {0}\r\n\t\t Typ: {1} \r\n\t\t Fehlertext: {2}  \r\n\t\t InnerException: {3}", Excel.XlArchiveDir, ex.GetType().ToString(), ex.Message, ex.InnerException));
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Write(Log.Cat.OnStart, Log.Prio.Error, 010115, string.Format("Fehler beim initialisieren der Anwendung: Typ: {0} \r\n\t\t Fehlertext: {1}  \r\n\t\t InnerException: {2}", ex.GetType().ToString(), ex.Message, ex.InnerException));
                return;
            }
            #endregion

            Excel.XlFillWorkbook();

            Print.PrintRoutine();

            #region Diese *.exe beenden
            InTouch.SetExcelAliveBit(Program.AppErrorOccured);

            if (AppErrorOccured)
            {
                Log.Write(Log.Cat.OnStart, Log.Prio.Error, 010116, "XlLog.exe beendet. Es ist ein Fehler aufgetreten.\r\n\r\n");
            }
            else
            {
                Log.Write(Log.Cat.OnStart, Log.Prio.Info, 010117, "XlLog.exe ohne Fehler beendet.\r\n");
            }

            // Bei manuellem Start Fenster kurz offen halten.
            if (AppStartedBy == Environment.UserName)
            {
                Tools.Wait(Tools.WaitToClose);
            }
            #endregion
        }