-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOperatorForm.cs
115 lines (103 loc) · 3.87 KB
/
OperatorForm.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
using Microsoft.Toolkit.Uwp.Notifications;
using MySql.Data.MySqlClient;
using System;
using System.IO;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using MySQLData;
using System.Threading.Tasks;
namespace jsu1xd
{
public partial class OperatorForm : Form
{
string strPath = System.Environment.GetEnvironmentVariable("TEMP");
public int CountMessages { get; set; }
public int UserId { get; set; }
public void CheckStatus()
{
var dbCon = DBConnection.Instance();
while (true)
{
if (dbCon.IsConnect())
{
try
{
var connection = dbCon.openConnect();
string query = $"SELECT COUNT(*) FROM requests WHERE status='WAIT'";
var cmd = new MySqlCommand(query, connection);
int counter = Convert.ToInt32(cmd.ExecuteScalar());
if (counter > CountMessages)
{
new ToastContentBuilder()
.AddText("Новое обращение")
.AddText("Было получено новое общращение, посмотреть его можно во вкладке 'Запросы пользователей'")
.Show();
}
CountMessages = counter;
string path = Path.Combine(strPath, "jsu1xdmessageoperator.tmp");
using (FileStream fs = File.Create(path))
{
byte[] info = new UTF8Encoding(true).GetBytes(CountMessages.ToString());
fs.Write(info, 0, info.Length);
connection.Close();
}
}
catch (Exception ex)
{
dbCon.Close();
Console.WriteLine(ex.ToString());
Thread.Sleep(5000);
}
}
Thread.Sleep(1000);
}
}
public OperatorForm()
{
InitializeComponent();
string path = Path.Combine(strPath, "jsu1xd.tmp");
using (var sr = new StreamReader(path))
{
UserId = Convert.ToInt32(sr.ReadToEnd());
}
var dbCon = DBConnection.Instance();
if (dbCon.IsConnect()) { }
string query = $"SELECT fio FROM operators WHERE id={UserId}";
var cmd = new MySqlCommand(query, dbCon.Connection);
var result = cmd.ExecuteReader();
while (result.Read())
{
guna2HtmlLabel2.Text = $"{result.GetString(0)}";
}
dbCon.Close();
try
{
path = Path.Combine(strPath, "jsu1xdmessageoperator.tmp");
using (var sr = new StreamReader(path))
{
CountMessages = Convert.ToInt32(sr.ReadToEnd());
}
}
catch (FileNotFoundException) { }
}
private void guna2Button1_Click(object sender, EventArgs e)
{
Form AddContactForm = new AddContactForm();
AddContactForm.ShowDialog();
}
private void OperatorForm_FormClosing(object sender, FormClosingEventArgs e)
{
Application.Exit();
}
private async void OperatorForm_Load(object sender, EventArgs e)
{
await Task.Run(() => CheckStatus());
}
private void guna2Button2_Click(object sender, EventArgs e)
{
Form requestsForm = new OperatorRequestForm();
requestsForm.ShowDialog();
}
}
}