Repository navigation
Expand file tree
/
Copy pathAdminTable.cs
More file actions
246 lines (208 loc) · 9.04 KB
/
Copy pathAdminTable.cs
File metadata and controls
246 lines (208 loc) · 9.04 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ProjectAvtoMoika
{
public partial class AdminTable : Form
{
public AdminTable()
{
InitializeComponent();
TextUsluga.Text = "Введите наименование услуги: ";
TextCostUsluga.Text = "Введите стоимость услуги: ";
TextTimeUsluga.Text = "Введите время выполнения: ";
TextTipKuzov.Text = "Введите название кузова: ";
TextXCost.Text = "Введите множитель цены: ";
TextXTime.Text = "Введите множитель времени: ";
}
private void AddUslugi_Click(object sender, EventArgs e)
{
if (TextUsluga.Text == "Введите наименование услуги: ")
{
MessageBox.Show("Введите услугу!");
return;
}
if (TextCostUsluga.Text == "Введите стоимость услуги: ")
{
MessageBox.Show("Введите стоимость!");
return;
}
if (TextTimeUsluga.Text == "Введите время выполнения: ")
{
MessageBox.Show("Введите время!");
return;
}
bool UslugiExists = checkUslugi();
if (!UslugiExists)
{
MessageBox.Show("Такой тип услуги уже есть, но вы можете продолжить.");
return;
}
DB dB = new DB();
MySqlCommand command = new MySqlCommand("INSERT INTO `uslugi` (`Usluga`, `Cost`, `time`) VALUES (@usluga, @cost, @time);", dB.GetConnection());
command.Parameters.Add("@usluga", MySqlDbType.VarChar).Value = TextUsluga.Text;
command.Parameters.Add("@cost", MySqlDbType.Float).Value = float.Parse(TextCostUsluga.Text);
command.Parameters.Add("@time", MySqlDbType.Float).Value = float.Parse(TextTimeUsluga.Text);
try
{
dB.OpenCon();
command.ExecuteNonQuery();
MessageBox.Show("Услуга успешно добавлена!");
}
catch (Exception ex)
{
MessageBox.Show("Ошибка: " + ex.Message);
}
finally
{
dB.CloseCon();
}
}
public Boolean checkUslugi()
{
DB db = new DB();
DataTable dataTable = new DataTable();
MySqlDataAdapter adapter = new MySqlDataAdapter();
MySqlCommand cmd = new MySqlCommand("SELECT * FROM `uslugi` WHERE `Usluga` = @usl AND `Cost` = @cost AND `time` = @time ", db.GetConnection());
cmd.Parameters.Add("@usl", MySqlDbType.VarChar).Value = TextUsluga.Text;
cmd.Parameters.Add("@cost", MySqlDbType.Float).Value = float.Parse(TextCostUsluga.Text);
cmd.Parameters.Add("@time", MySqlDbType.Float).Value = float.Parse(TextTimeUsluga.Text);
adapter.SelectCommand = cmd;
adapter.Fill(dataTable);
if (dataTable.Rows.Count > 0)
{
MessageBox.Show($"Такой тип услуги уже есть, но вы можете продолжить.");
return false;
}
return true;
}
private void TextUsluga_Enter(object sender, EventArgs e)
{
if (TextUsluga.Text == "Введите наименование услуги: ")
TextUsluga.Text = "";
}
private void TextCostUsluga_Leave(object sender, EventArgs e)
{
if (TextCostUsluga.Text == "")
TextCostUsluga.Text = "Введите стоимость услуги: ";
}
private void TextUsluga_Leave(object sender, EventArgs e)
{
if (TextUsluga.Text == "")
TextUsluga.Text = "Введите наименование услуги: ";
}
private void TextCostUsluga_Enter(object sender, EventArgs e)
{
if (TextCostUsluga.Text == "Введите стоимость услуги: ")
TextCostUsluga.Text = "";
}
private void TextTimeUsluga_Enter(object sender, EventArgs e)
{
if (TextTimeUsluga.Text == "Введите время выполнения: ")
TextTimeUsluga.Text = "";
}
private void TextTimeUsluga_Leave(object sender, EventArgs e)
{
if (TextTimeUsluga.Text == "")
TextTimeUsluga.Text = "Введите время выполнения: ";
}
private void TextTipKuzov_Enter(object sender, EventArgs e)
{
if (TextTipKuzov.Text == "Введите название кузова: ")
TextTipKuzov.Text = "";
}
private void TextTipKuzov_Leave(object sender, EventArgs e)
{
if (TextTipKuzov.Text == "")
TextTipKuzov.Text = "Введите название кузова: ";
}
private void TextXCost_Enter(object sender, EventArgs e)
{
if (TextXCost.Text == "Введите множитель цены: ")
TextXCost.Text = "";
}
private void TextXCost_Leave(object sender, EventArgs e)
{
if (TextXCost.Text == "")
TextXCost.Text = "Введите множитель цены: ";
}
private void TextXTime_Enter(object sender, EventArgs e)
{
if (TextXTime.Text == "Введите множитель времени: ")
TextXTime.Text = "";
}
private void TextXTime_Leave(object sender, EventArgs e)
{
if (TextXTime.Text == "")
TextXTime.Text = "Введите множитель времени: ";
}
private void AddKuzova_Click(object sender, EventArgs e)
{
if (TextTipKuzov.Text == "Введите название кузова: ")
{
MessageBox.Show("Введите название кузова!");
return;
}
if (TextXCost.Text == "Введите множитель цены: ")
{
MessageBox.Show("Введите множитель цены!");
return;
}
if (TextXTime.Text == "Введите множитель времени: ")
{
MessageBox.Show("Введите множитель времени!");
return;
}
bool KuzovExists = checkKuzov();
if (!KuzovExists)
{
MessageBox.Show("Такой тип кузова уже есть, но вы можете продолжить.");
return;
}
DB dB = new DB();
MySqlCommand command = new MySqlCommand("INSERT INTO `kuzova` (`KuZOV`, `Xtime`, `XCost`) VALUES (@kuzov, @xcost, @xtime);", dB.GetConnection());
command.Parameters.Add("@kuzov", MySqlDbType.VarChar).Value = TextTipKuzov.Text;
command.Parameters.Add("@xcost", MySqlDbType.Float).Value = float.Parse(TextXCost.Text);
command.Parameters.Add("@xtime", MySqlDbType.Float).Value = float.Parse(TextXTime.Text);
try
{
dB.OpenCon();
command.ExecuteNonQuery();
MessageBox.Show("Кузов успешно добавлен!");
}
catch (Exception ex)
{
MessageBox.Show("Ошибка: " + ex.Message);
}
finally
{
dB.CloseCon();
}
}
public Boolean checkKuzov()
{
DB db = new DB();
DataTable dataTable = new DataTable();
MySqlDataAdapter adapter = new MySqlDataAdapter();
MySqlCommand cmd = new MySqlCommand("SELECT * FROM `kuzova` WHERE `KuZOV` = @kuz AND `XCost` = @xcost AND `Xtime` = @xtime ", db.GetConnection());
cmd.Parameters.Add("@kuz", MySqlDbType.VarChar).Value = TextTipKuzov.Text;
cmd.Parameters.Add("@xcost", MySqlDbType.Float).Value = float.Parse(TextXCost.Text);
cmd.Parameters.Add("@xtime", MySqlDbType.Float).Value = float.Parse(TextXTime.Text);
adapter.SelectCommand = cmd;
adapter.Fill(dataTable);
if (dataTable.Rows.Count > 0)
{
MessageBox.Show($"Такой тип кузова уже есть, но вы можете продолжить.");
return false;
}
return true;
}
}
}