-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOperatorRequestForm.cs
144 lines (133 loc) · 5.4 KB
/
OperatorRequestForm.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
134
135
136
137
138
139
140
141
142
143
144
using System;
using MySQLData;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using Types;
using System.IO;
namespace jsu1xd
{
public partial class OperatorRequestForm : Form
{
string strPath = System.Environment.GetEnvironmentVariable("TEMP");
public int UserId { get; set; }
public OperatorRequestForm()
{
InitializeComponent();
string path = Path.Combine(strPath, "jsu1xd.tmp");
using (var sr = new StreamReader(path))
{
UserId = Convert.ToInt32(sr.ReadToEnd());
}
}
private void guna2Button2_Click(object sender, EventArgs e)
{
int requestId = Convert.ToInt32((guna2ComboBox1.SelectedItem as ComboboxItem).Value);
var dbCon = DBConnection.Instance();
if (dbCon.IsConnect())
{
string query = $"SELECT info, comment FROM requests WHERE id={requestId}";
var cmd = new MySqlCommand(query, dbCon.Connection);
var result = cmd.ExecuteReader();
while (result.Read())
{
MessageBox.Show($"Текст обращения: {result.GetString(0)}\nКомментарий: {result.GetString(1)}");
}
dbCon.Close();
}
else
{
MessageBox.Show("Проверьте подключение к сети");
}
}
private void OperatorRequestForm_Load(object sender, EventArgs e)
{
var dbCon = DBConnection.Instance();
if (dbCon.IsConnect())
{
string query = $"SELECT COUNT(*) FROM contacts";
var cmd = new MySqlCommand(query, dbCon.Connection);
int counter = Convert.ToInt32(cmd.ExecuteScalar());
if (counter == 0)
{
MessageBox.Show("Сначала требуется добавить контакты");
dbCon.Close();
this.BeginInvoke(new MethodInvoker(this.Close));
return;
}
query = $"SELECT COUNT(*) FROM requests WHERE status='WAIT'";
cmd = new MySqlCommand(query, dbCon.Connection);
counter = Convert.ToInt32(cmd.ExecuteScalar());
if (counter == 0)
{
MessageBox.Show("Простите, но нет заявок");
dbCon.Close();
this.BeginInvoke(new MethodInvoker(this.Close));
return;
}
query = $"SELECT id, info FROM requests WHERE status='WAIT'";
cmd = new MySqlCommand(query, dbCon.Connection);
var result = cmd.ExecuteReader();
int i = 0;
while (result.Read())
{
ComboboxItem item = new ComboboxItem();
item.Text = result.GetString(1);
item.Value = result.GetInt32(0);
guna2ComboBox1.Items.Add(item);
i++;
}
dbCon.Close();
}
}
private void guna2ComboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
var dbCon = DBConnection.Instance();
if (dbCon.IsConnect())
{
string query = $"SELECT COUNT(*) FROM contacts";
var cmd = new MySqlCommand(query, dbCon.Connection);
int counter = Convert.ToInt32(cmd.ExecuteScalar());
if (counter == 0)
{
MessageBox.Show("Простите, но нет контактов");
dbCon.Close();
this.Hide();
return;
}
query = $"SELECT id, fio FROM contacts";
cmd = new MySqlCommand(query, dbCon.Connection);
var result = cmd.ExecuteReader();
int i = 0;
while (result.Read())
{
Console.WriteLine(result.GetString(1));
ComboboxItem item = new ComboboxItem();
item.Text = result.GetString(1);
item.Value = result.GetInt32(0);
guna2ComboBox2.Items.Add(item);
i++;
}
dbCon.Close();
}
guna2Button1.Visible = true;
guna2Button2.Visible = true;
guna2ComboBox2.Visible = true;
guna2HtmlLabel2.Visible = true;
}
private void guna2Button1_Click(object sender, EventArgs e)
{
int requestId = Convert.ToInt32((guna2ComboBox1.SelectedItem as ComboboxItem).Value);
int contactId = Convert.ToInt32((guna2ComboBox2.SelectedItem as ComboboxItem).Value);
var dbCon = DBConnection.Instance();
if (dbCon.IsConnect())
{
string query = $"UPDATE requests SET contact={contactId}, operator={UserId}, status='RES' WHERE id={requestId}";
var cmd = new MySqlCommand(query, dbCon.Connection);
cmd.ExecuteNonQuery();
dbCon.Close();
MessageBox.Show("Данные были предоставлены");
this.Close();
}
}
}
}