예제 #1
0
        private static void SetzeSystemzeit(DateTime NeueZeit) //Fehlernummern siehe Log.cs 1201ZZ
        {
            NeueZeit = NeueZeit.ToUniversalTime();

            str_Zeit Zeit = new str_Zeit
            {
                Jahr          = (short)NeueZeit.Year,
                Monat         = (short)NeueZeit.Month,
                TagInDerWoche = (short)NeueZeit.DayOfWeek,
                Tag           = (short)NeueZeit.Day,
                Stunde        = (short)NeueZeit.Hour,
                Minute        = (short)NeueZeit.Minute,
                Sekunde       = (short)NeueZeit.Second,
                Millisekunde  = (short)NeueZeit.Millisecond
            };

            bool result = SetSystemTime(ref Zeit);

            //If the function succeeds, the return value is nonzero.
            if (result)
            {
                Log.Write(Log.Cat.Scheduler, Log.Prio.Error, 120102,
                          "Der Benutzer >" + InTouch.ReadTag("$Operator") + "< hat die Systemzeit nach >" + NeueZeit.ToLocalTime() + "< (" + NeueZeit + " UTC) umgestellt.");
            }
            else
            {
                Log.Write(Log.Cat.Scheduler, Log.Prio.Error, 120103,
                          "Der Benutzer >" + InTouch.ReadTag("$Operator") + "< konnte die Systemzeit nicht nach >" + NeueZeit + "< umstellen. Fehler aus kernel32.dll");
            }
        }
예제 #2
0
        private static void SetzeSystemzeit2(DateTime NeueZeit)
        {
            string powerShellCommand = String.Format("Set-Date -Date {0}", NeueZeit);

            System.Diagnostics.ProcessStartInfo start = new System.Diagnostics.ProcessStartInfo
            {
                FileName               = "powershell", // Specify exe name.
                UseShellExecute        = false,
                CreateNoWindow         = true,
                WindowStyle            = System.Diagnostics.ProcessWindowStyle.Hidden,
                RedirectStandardOutput = true,
                RedirectStandardError  = true,
                Arguments              = powerShellCommand
            };

            using (System.Diagnostics.Process process = System.Diagnostics.Process.Start(start))
            {
                // Read the error stream first and then wait.
                string error = process.StandardError.ReadToEnd();
                process.WaitForExit();

                //Check for an error
                if (!String.IsNullOrEmpty(error))
                {
                    Log.Write(Log.Cat.Scheduler, Log.Prio.Error, 120105,
                              "Der Benutzer >" + InTouch.ReadTag("$Operator") + "< konnte die Systemzeit nicht nach >" + NeueZeit + "< umstellen. Fehler aus PowerShell");
                }
                else
                {
                    Log.Write(Log.Cat.Scheduler, Log.Prio.Error, 120106,
                              "Der Benutzer >" + InTouch.ReadTag("$Operator") + "< hat die Systemzeit per PowerShell nach >" + NeueZeit + "< umgestellt.");
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Erzeugt die Sql-Abfrage Zeichenfolge
        /// </summary>
        /// <returns>Sql-Abfrage Zeichenfolge</returns>
        private static string SqlQueryString() //Fehlernummern siehe Log.cs 1102ZZ
        {
            Log.Write(Log.Cat.MethodCall, Log.Prio.Info, 110201, string.Format("SqlQueryString()"));
            //ToDo: Testen; Was, wenn InTouchTagName nicht existiert?

            try
            {
                DBGruppe = (string)InTouch.ReadTag("DBGruppe");
                if (DBGruppe.Trim().Length < 1)
                {
                    DBGruppe = "A00_General";
                }
                DBGruppeComment = (string)InTouch.ReadTag(DBGruppe + ".Comment");
                DBStartTime     = (string)InTouch.ReadTag("DBStartTime");
                DBEndTime       = (string)InTouch.ReadTag("DBEndTime");
                DBvonPrio       = (int)InTouch.ReadTag("DBvonPrio");
                DBbisPrio       = (int)InTouch.ReadTag("DBbisPrio");

                Log.Write(Log.Cat.SqlQuery, Log.Prio.Info, 110202, string.Format("SQL-Abfrage mit: DBGruppe {0}\r\n\t\t\t\t, DBGruppeComment {1}\r\n\t\t\t\t, DBStartTime {2}\r\n\t\t\t\t, DBEndTime {3}\r\n\t\t\t\t, DBvonPrio {4}\r\n\t\t\t\t, DBbisPrio {5}\r\n\t\t\t\t", DBGruppe, DBGruppeComment, DBStartTime, DBEndTime, DBvonPrio, DBbisPrio));

                // GROUP BY - string
                string grptxt = GetGrpString();

                //Fehler, wenn GetGrpString() einen Leerstring erzeugt.
                if (grptxt.Length < 3)
                {
                    grptxt = "1=1";
                }

                string usCulture = "en-US";
                bool   time_ok   = false;

                time_ok = DateTime.TryParse(DBStartTime, System.Globalization.CultureInfo.GetCultureInfo(usCulture), System.Globalization.DateTimeStyles.None, out StartTime);
                if (!time_ok)
                {
                    StartTime = DateTime.Now.AddMonths(-1);
                }

                time_ok = DateTime.TryParse(DBEndTime, System.Globalization.CultureInfo.GetCultureInfo(usCulture), System.Globalization.DateTimeStyles.None, out EndTime);
                if (!time_ok)
                {
                    EndTime = DateTime.Now;
                }

                // TEST Prüfe eingelesenen Werte
                //Log.Write(Log.Category.SqlQuery, 1903141202, "\r\nConString: " + ConnString + "\r\nDBGruppe: " + DBGruppe + "\r\nDBGruppeComment: " + DBGruppeComment + "\r\nDBStartTime: " + DBStartTime + "\t" + StartTime.ToString("g") + "\r\nDBStartTime: " + DBEndTime + "\t" + EndTime.ToString("g") + "\r\n DBvonPrio: " + DBvonPrio + "\r\n DBbisPrio: " + DBbisPrio + "\r\n");

                //# TT.MM..YYYY HH:mm
                string vonzeittxt = " AND v_AE.EventStamp > '" + StartTime.ToString("s") + "'";
                string biszeittxt = " AND v_AE.EventStamp < '" + EndTime.ToString("s") + "'";

                string SQLString = "SELECT " +
                                   // "v_AE.EventStamp AS 'Datum'," +
                                   "v_AE.EventStamp AS 'Zeit'," +
                                   "v_AE.Priority AS 'Prio', " +
                                   "v_AE.Operator AS 'Benutzer', " +
                                   "v_AE.Description AS 'Beschreibung', " +
                                   "v_AE.Value AS 'Wert', " +
                                   "v_AE.CheckValue AS 'Alt Wert', " +
                                   "v_AE.AlarmState AS 'Zustand'," +
                                   "v_AE.Area AS 'Gruppe' " +
                                   "FROM WWALMDB.dbo.v_AlarmEventHistory v_AE WHERE " +
                                   grptxt + vonzeittxt + biszeittxt +
                                   " AND (v_AE.Priority >= " + DBvonPrio +
                                   " AND v_AE.Priority <= " + DBbisPrio + ") " +
                                   "ORDER BY v_AE.EventStamp DESC";

                Log.Write(Log.Cat.SqlQuery, Log.Prio.Info, 110204, "SQL-Abfrage:\r\n" + SQLString);

                return(SQLString);
            }
            catch (Exception ex)
            {
                Log.Write(Log.Cat.SqlQuery, Log.Prio.Error, 110203, string.Format("Fehler beim Zusammenstellen der AlmDatenbank-Abfrage: \r\n\t\t Typ: {0} \r\n\t\t Fehlertext: {1}  \r\n\t\t InnerException: {2}  \r\n\t\t StackTrace: {3}", ex.GetType().ToString(), ex.Message, ex.InnerException, ex.StackTrace));
                Program.AppErrorOccured = true;
                return(string.Empty);
            }
        }
예제 #4
0
        /// <summary>
        /// Füllt die VorlageDatei xlFilePath mit der DataTable aus der SQL-Abfrage
        /// </summary>
        /// <param name="xlFilePath"></param>
        /// <param name="dt">DataTable aus SQL-Abfrage SqlQuery()</param>
        private static void FillAlmListFile(string xlFilePath, DataTable dt) // //Fehlernummern siehe Log.cs 1106ZZ
        {
            if (!File.Exists(xlFilePath))
            {
                Log.Write(Log.Cat.FileSystem, Log.Prio.Error, 110602, string.Format("Die Datei {0} für AlmDruck existiert nicht.", xlFilePath));
                return;
            }

            FileInfo file = new FileInfo(xlFilePath);

            try
            {
                using (ExcelPackage excelPackage = new ExcelPackage(file))
                {
                    //Kommentare
                    ExcelWorksheet worksheet = excelPackage.Workbook.Worksheets["AlmDruck"];

                    worksheet.Cells[1, 1].AddComment("von " + StartTime.ToString("g"), (string)InTouch.ReadTag("$Operator"));
                    worksheet.Cells[1, 2].AddComment(" bis " + EndTime.ToString("g"), (string)InTouch.ReadTag("$Operator"));
                    worksheet.Cells[1, 8].AddComment(DBGruppe, (string)InTouch.ReadTag("$Operator"));
                    //worksheet.Cells[1, 1].AddComment(DBGruppe + " (" + DBGruppeComment + ") von " + StartTime.ToString("g") + " bis " + EndTime.ToString("g"), (string)InTouch.ReadTag("$Operator"));

                    //Überschriften
                    worksheet.Cells[1, 1].Value = dt.Columns[0].Caption;
                    worksheet.Cells[1, 2].Value = dt.Columns[1].Caption;
                    worksheet.Cells[1, 3].Value = dt.Columns[2].Caption;
                    worksheet.Cells[1, 4].Value = dt.Columns[3].Caption;
                    worksheet.Cells[1, 5].Value = dt.Columns[4].Caption;
                    worksheet.Cells[1, 6].Value = dt.Columns[5].Caption;
                    worksheet.Cells[1, 7].Value = dt.Columns[6].Caption;
                    worksheet.Cells[1, 8].Value = dt.Columns[7].Caption;
                    worksheet.Cells[1, 1, 1, 8].Style.Font.Bold = true;

                    //Werte
                    int   row      = 1;
                    Color almColor = Color.Black;

                    foreach (DataRow dataRow in dt.Rows)
                    {
                        row++;
                        object[] array = dataRow.ItemArray;

                        string zustand = array[dt.Columns["Zustand"].Ordinal].ToString();
                        string gruppe  = array[dt.Columns["Gruppe"].Ordinal].ToString();

                        almColor = SetFontColor(zustand, gruppe[0]);

                        for (int col = 0; col < array.Length; col++)
                        {
                            worksheet.Cells[row, col + 1].Value = array[col];
                            worksheet.Cells[row, col + 1].Style.Font.Color.SetColor(almColor);
                            worksheet.Cells.Style.Border.Bottom.Style = ExcelBorderStyle.Hair;
                        }
                    }

                    string description = "&8&\"Arial\" Obergruppe: " + DBGruppeComment + " von " + StartTime.ToString("g") + " bis " + EndTime.ToString("g") + ", Priorität " + DBvonPrio.ToString() + " bis " + DBbisPrio.ToString();
                    worksheet.HeaderFooter.FirstFooter.LeftAlignedText = description;
                    worksheet.HeaderFooter.EvenFooter.LeftAlignedText  = description;
                    worksheet.HeaderFooter.OddFooter.LeftAlignedText   = description;

                    string pageNo = string.Format("{0} / {1}", ExcelHeaderFooter.PageNumber, ExcelHeaderFooter.NumberOfPages);
                    worksheet.HeaderFooter.FirstFooter.RightAlignedText = pageNo;
                    worksheet.HeaderFooter.EvenFooter.RightAlignedText  = pageNo;
                    worksheet.HeaderFooter.OddFooter.RightAlignedText   = pageNo;

                    excelPackage.Workbook.Calculate();
                    excelPackage.Save();
                }
            }
            catch (Exception ex)
            {
                Log.Write(Log.Cat.ExcelWrite, Log.Prio.Error, 110503, string.Format("In die Datei für Alarmausdruck konnte nicht geschrieben werden: {0}\r\n\t\t Typ: {1} \r\n\t\t Fehlertext: {2}  \r\n\t\t InnerException: {3}  \r\n\t\t StackTrace: {4}", xlFilePath, ex.GetType().ToString(), ex.Message, ex.InnerException, ex.StackTrace));
            }
        }
예제 #5
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
        }