root/branches/ReklamaReorganizacja/BazaReklam/Program.cs @ 670

Wersja 601, 2.4 KB (wprowadzona przez marek, 17 years temu)

re #165 - merged with latest trunk

Line 
1using System;
2using System.Text;
3using System.Threading;
4using System.Windows.Forms;
5using Baza_Reklam.Classes;
6
7namespace Baza_Reklam
8{
9    static class Program
10    {
11        /// <summary>
12        /// The main entry point for the application.
13        /// </summary>
14        [STAThread]
15        static void Main()
16        {
17            CustomExceptionHandler exceptionHandler = new CustomExceptionHandler();
18
19            Application.ThreadException += exceptionHandler.OnThreadException;
20
21
22            Application.EnableVisualStyles();
23            Application.SetCompatibleTextRenderingDefault(false);
24
25            Logowanie logowanie = new Logowanie();
26
27            if (logowanie.ShowDialog() == DialogResult.OK)
28            {
29                Application.Run(new MDIBazaReklam());
30            }
31        }
32
33    }
34
35    // Creates a class to handle the exception event.
36    internal class CustomExceptionHandler
37    {
38
39        // Handles the exception event.
40        public void OnThreadException(object sender, ThreadExceptionEventArgs t)
41        {
42            try
43            {
44                ShowThreadExceptionDialog(t.Exception);
45            }
46            catch
47            {
48                try
49                {
50                    MessageBox.Show("Fatal Error - aplikacja zostanie zamknięta", "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
51                }
52                finally
53                {
54                    Application.Exit();
55                }
56            }   
57        }
58
59        // Creates the error message and displays it.
60        private static void ShowThreadExceptionDialog(Exception exception)
61        {
62            string userName = User.Instance().Login;
63            if (string.IsNullOrEmpty(userName)) userName = "[not_found]";
64
65            Logger.LogException(exception, userName, DateTime.Now);
66            StringBuilder sb = new StringBuilder();
67            sb.AppendLine("Wystąpił nieoczekiwany wyjątek.");
68            sb.AppendLine(string.Empty);
69            sb.AppendLine("Informacje dotyczące tego błędu zostały automatycznie przekazane programiście.");
70            sb.AppendLine(string.Empty);
71            sb.AppendLine("Data i czas: " + DateTime.Now);
72            sb.AppendLine("Użytkownik: " + userName);
73            MessageBox.Show(sb.ToString(), "Błąd w aplikacji Baza Reklam", MessageBoxButtons.OK, MessageBoxIcon.Stop);
74        }
75    }
76}
Notatka: Zobacz TracBrowser aby uzyskać więcej informacji.