using System using System Collections Generic using System ComponentMo

  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
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;
using System.Data.SqlClient;
using MySql.Data.MySqlClient;
namespace LAb_MySql
{
public partial class User_Form : Form
{
private string connection;
private My_Sql mysql;
public User_Form()
{
#region подключение к базе данных
InitializeComponent();
connection = "datasource=localhost;" + "database=Module;" + "username=root;" + "password=World12q";
mysql = new My_Sql(connection);
#endregion
#region значения по умолчанию для панелей выбора
имя_фамилия_panel1.Enabled = false;
столик_panel1.Enabled = false;
время_panel1.Enabled = false;
#endregion
#region настройки comboBox
// фамилия
string фамилия = "select DISTINCT O as Фамилия from employess;";
Фамилия_comboBox1.DataSource = mysql.get_Table(фамилия);
Фамилия_comboBox1.DisplayMember = "Фамилия";
Фамилия_comboBox1.SelectedIndex = -1;
// имя
string имя = "select DISTINCT N as Имя from employess;";
имя_comboBox2.DataSource = mysql.get_Table(имя);
имя_comboBox2.DisplayMember = "Имя";
имя_comboBox2.SelectedIndex = -1;
// столик
string столик = "select DISTINCT description as Столик from tables;";
столик_comboBox3.DataSource = mysql.get_Table(столик);
столик_comboBox3.DisplayMember = "Столик";
столик_comboBox3.SelectedIndex = -1;
#endregion
#region установка значения только для чтения для comboBox
Фамилия_comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
имя_comboBox2.DropDownStyle = ComboBoxStyle.DropDownList;
столик_comboBox3.DropDownStyle = ComboBoxStyle.DropDownList;
#endregion
/// <summary>
//
foreach(var the_value in name_panel1.Controls.OfType<ComboBox>())
{
the_value.SelectedIndexChanged += combobox_zakaz;
}
/// <summary>
//
}
#region User_Form_FormClosed
private void User_Form_FormClosed(object sender, FormClosedEventArgs e)
{
Application.Exit();
}
#endregion
#region сменитьУровеньДоступа
private void сменитьУровеньДоступаToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
var account_form = new Account_Form();
if (!account_form.Created)
{
account_form = new Account_Form();
}
account_form.Show();
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
this.Hide();
}
}
#endregion
//фамилия
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (Фамилия_comboBox1.SelectedIndex != -1 && имя_comboBox2.SelectedIndex != -1)
{
dataGridView1.DataSource = mysql.get_Table("select employess.N as 'Имя', employess.O as 'Отчество',tables.description as 'Столик',data as 'Дата заказа', time as 'Время заказа', made as 'Выполнен (YES) / Не выполнен (NO)',order_amount as 'Сумма заказа'from orders, `tables`,employess where orders.`table` = tables.code_table and employess.id_employess = orders.the_waiter and employess.O = '" + Фамилия_comboBox1.Text + "'and employess.N ='" + имя_comboBox2.Text +"';");
}
else
{
dataGridView1.DataSource = mysql.get_Table("select employess.N as 'Имя', employess.O as 'Отчество',tables.description as 'Столик',data as 'Дата заказа', time as 'Время заказа', made as 'Выполнен (YES) / Не выполнен (NO)',order_amount as 'Сумма заказа'from orders, `tables`,employess where orders.`table` = tables.code_table and employess.id_employess = orders.the_waiter and employess.O = '" + Фамилия_comboBox1.Text + "';");
}
if (имя_comboBox2.SelectedIndex != -1 && Фамилия_comboBox1.SelectedIndex != -1)
{
столик_comboBox3.Enabled = true;
}
}
// имя
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
if(имя_comboBox2.SelectedIndex != -1 && Фамилия_comboBox1.SelectedIndex != -1)
{
dataGridView1.DataSource = mysql.get_Table("select employess.N as 'Имя', employess.O as 'Отчество',tables.description as 'Столик',data as 'Дата заказа', time as 'Время заказа', made as 'Выполнен (YES) / Не выполнен (NO)',order_amount as 'Сумма заказа'from orders, `tables`,employess where orders.`table` = tables.code_table and employess.id_employess = orders.the_waiter and employess.N = '" + имя_comboBox2.Text + "'and employess.O = '" +Фамилия_comboBox1.Text + "';");
}
else
{
dataGridView1.DataSource = mysql.get_Table("select employess.N as 'Имя', employess.O as 'Отчество',tables.description as 'Столик',data as 'Дата заказа', time as 'Время заказа', made as 'Выполнен (YES) / Не выполнен (NO)',order_amount as 'Сумма заказа'from orders, `tables`,employess where orders.`table` = tables.code_table and employess.id_employess = orders.the_waiter and employess.N = '" + имя_comboBox2.Text + "';");
}
if (имя_comboBox2.SelectedIndex != -1 && Фамилия_comboBox1.SelectedIndex != -1)
{
столик_comboBox3.Enabled = true;
}
}
// столик
private void comboBox1_SelectedIndexChanged_1(object sender, EventArgs e)
{
if (столик_comboBox3.SelectedIndex != -1 && имя_comboBox2.SelectedIndex != -1 && Фамилия_comboBox1.SelectedIndex != -1)
{
dataGridView1.DataSource = mysql.get_Table("select employess.N as 'Имя', employess.O as 'Отчество',tables.description as 'Столик',data as 'Дата заказа', time as 'Время заказа', made as 'Выполнен (YES) / Не выполнен (NO)',order_amount as 'Сумма заказа'from orders, `tables`,employess where orders.`table` = tables.code_table and employess.id_employess = orders.the_waiter and description = '" + столик_comboBox3.Text + "'and employess.N ='" + имя_comboBox2.Text + "'and employess.O = '" + Фамилия_comboBox1.Text + "';");
}
}
//дата
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
if (dateTimePicker1.Checked)
{
string time = dateTimePicker1.Value.Date.ToString("yyyy-MM-dd");
dataGridView1.DataSource = mysql.get_Table("select employess.N as 'Имя',employess.O as 'Отчество', tables.description as 'Столик',data as 'Дата заказа', time as 'Время заказа', made as 'Выполнен (YES) / Не выполнен (NO)',order_amount as 'Сумма заказа'from orders, `tables`,employess where orders.`table` = tables.code_table and employess.id_employess = orders.the_waiter and data = '" + time + "';");
имя_фамилия_panel1.Enabled = false;
столик_panel1.Enabled = false;
}
}
/// <summary>
private void combobox_zakaz(object sender, EventArgs e)
{
try
{
List<string> m = new List<string>();
foreach( var com_box in name_panel1.Controls.OfType<ComboBox>())
{
m.Add(com_box.Text);
}
m[0] = m[0] != "" ? " and employess.N = '" + m[0] + "'" : m[0];
dataGridView1.DataSource = mysql.get_Table("select employess.N as 'Имя', employess.O as 'Отчество',tables.description as 'Столик',data as 'Дата заказа', time as 'Время заказа', made as 'Выполнен (YES) / Не выполнен (NO)',order_amount as 'Сумма заказа'from orders, `tables`,employess where orders.`table` = tables.code_table and employess.id_employess = orders.the_waiter" + m[0] + ";"); /*and employess.N = '" + имя_comboBox2.Text + "'and employess.O = '" + Фамилия_comboBox1.Text + "';");*/
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
/// <summary>
///
// вывод таблицы заказы
private void таблицаЗаказовToolStripMenuItem_Click(object sender, EventArgs e)
{
string table_1 = "select employess.N as 'Имя',employess.O as 'Отчество', tables.description as 'Столик',data as 'Дата заказа', time as 'Время заказа', made as 'Выполнен (YES) / Не выполнен (NO)',order_amount as 'Сумма заказа'from orders, `tables`,employess where orders.`table` = tables.code_table and employess.id_employess = orders.the_waiter;";
dataGridView1.DataSource = mysql.get_Table(table_1);
имя_фамилия_panel1.Enabled = true;
столик_panel1.Enabled = true;
столик_comboBox3.Enabled = false;
время_panel1.Enabled = true;
/// <summary>
///
string имя = "select DISTINCT N as Имя from employess;";
имя_comboBox2.DataSource = mysql.get_Table(имя);
имя_comboBox2.DisplayMember = "Имя";
имя_comboBox2.SelectedIndex = -1;
/// <summary>
///
}
#region очистка Панели бд
private void сборосToolStripMenuItem_Click(object sender, EventArgs e)
{
dataGridView1.DataSource = null;
имя_фамилия_panel1.Enabled = false;
столик_panel1.Enabled = false;
Фамилия_comboBox1.SelectedIndex = -1;
имя_comboBox2.SelectedIndex = -1;
}
#endregion
#region сброс
// имя фамилия
private void label3_Click(object sender, EventArgs e)
{
Фамилия_comboBox1.SelectedIndex = -1;
имя_comboBox2.SelectedIndex = -1;
столик_comboBox3.Enabled = false;
столик_comboBox3.SelectedIndex = -1;
}
private void label7_Click(object sender, EventArgs e)
{
столик_comboBox3.SelectedIndex = -1;
столик_comboBox3.Enabled = false;
}
private void label8_Click(object sender, EventArgs e)
{
имя_фамилия_panel1.Enabled = true;
столик_comboBox3.SelectedIndex = -1;
имя_comboBox2.SelectedIndex = -1;
Фамилия_comboBox1.SelectedIndex = -1;
}
#endregion
}
}