-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
133 lines (123 loc) · 5.93 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
using Microsoft.Extensions.FileProviders;
using Practic_3_curs.Models;
using Practic_3_curs.Views;
using System;
using System.IO;
using System.Windows.Forms;
using System.Xml;
namespace Practic_3_curs
{
static class Program
{
public static string StoragePath = Directory.GetCurrentDirectory() + "/Settings";
public const string LogFilePath = "Errors.log";
public const string MailFilePath = "Mail.xml";
public const string DBSettingFilePath = "Connect.txt";
public static string DB_Connect_Setting;
public static CMailData MailData;
public static IManifestFinder ManifestFinder;
public static ICarrierManager CarriersManager;
public static IClientManager ClientManager;
public static IWaybillManager WaybillManager;
public static ICargoTypeManager CargoTypeManager;
public static IAirportManager AirportManager;
public static IManifestManager ManifestManager;
public static void Log(string msg)
{
StreamWriter writer = new StreamWriter(path: StoragePath + "/" + LogFilePath, append: true);
writer.WriteLine(DateTime.Now + ": " + msg);
writer.Close();
}
static void ReadMailData()
{
MailData = new CMailData();
PhysicalFileProvider provider = new PhysicalFileProvider(StoragePath);
if (provider.GetFileInfo(MailFilePath).Exists)
{
XmlDocument document = new XmlDocument();
document.Load(StoragePath + "/" + MailFilePath);
XmlNode root = document.DocumentElement;
foreach (XmlNode node in root.ChildNodes)
switch (node.Name.ToLower())
{
case "ëîãèí":
MailData.Login = node.InnerText;
break;
case "ïàðîëü":
MailData.Password = node.InnerText;
break;
case "õîñò":
MailData.Host = node.InnerText;
break;
case "ïîðò":
try
{
MailData.Port = int.Parse(node.InnerText);
}
catch
{
string err_msg = "Íåïðàâèëüíî óñòàíîâëåí ïàðàìåòð \"ïîðò\" â ôàéëå ñ äàííûìè äëÿ îòïðàâêè ïî÷òû (\"" + MailFilePath + "\").";
Log(err_msg);
MessageBox.Show(err_msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
}
break;
}
}
else
{
string err_msg = "Íå íàéäåí ôàéë ñ äàííûìè äëÿ îòïðàâêè ïî÷òû (\"" + MailFilePath + "\").";
Log(err_msg);
MessageBox.Show(err_msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
}
}
static void ReadDBSettings()
{
DB_Connect_Setting = "";
PhysicalFileProvider provider = new PhysicalFileProvider(StoragePath);
if (provider.GetFileInfo(DBSettingFilePath).Exists)
{
StreamReader Inp = new StreamReader(StoragePath + "/" + DBSettingFilePath);
while (!Inp.EndOfStream)
DB_Connect_Setting += " " + Inp.ReadLine();
Inp.Close();
}
else
{
string err_msg = "Íå íàéäåí ôàéë ñ äàííûìè ïîäêëþ÷åíèÿ ê áàçå äàííûõ (\"" + DBSettingFilePath + "\").";
Log(err_msg);
MessageBox.Show(err_msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
}
}
[STAThread]
static void Main()
{
try
{
ReadDBSettings();
ReadMailData();
ManifestFinder = new PGDBManifestFinder(DB_Connect_Setting);
CarriersManager = new PGDBCarrierManager(DB_Connect_Setting);
ClientManager = new PGDBClientManager(DB_Connect_Setting);
WaybillManager = new PGDBWaybillManager(DB_Connect_Setting);
CargoTypeManager = new PGDBCargoTypeManager(DB_Connect_Setting);
AirportManager = new PGDBAirportManager(DB_Connect_Setting);
ManifestManager = new PGDBManifestManager(DB_Connect_Setting);
if (!ManifestFinder.Ping())
{
string err_msg = "Íå óäàëîñü ïîëó÷èòü äîñòóï ê áàçå äàííûõ.";
Log(err_msg);
MessageBox.Show(err_msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
}
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainContainer());
}
catch (Exception except)
{
try { Log(except.Message); } catch { }
MessageBox.Show("Ïðîèçîøëà íåïðåäâèäåííàÿ îøèáêà. Âûïîëíåíèå ïðîãðàììû ïðåðâàíî", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
}
}
}
}