113
|
|
114
| if (sqlRead != null)
|
115
| sqlRead.Close();//проверка на откратасть
|
116
| }
|
117
| catch (Exception ex)//обработка исключений
|
118
| {
|
119
| MessageBox.Show(ex.Message.ToString(), ex.Source.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
|
120
| }
|
121
| finally
|
122
| {
|
123
| if (sqlRead != null)
|
124
| sqlRead.Close();//проверка на откратасть
|
125
|
|
126
| }
|
127
| }
|
128
|
|
129
| private void listView1_SelectedIndexChanged(object sender, EventArgs e)
|
130
| {
|
131
| CheckBtnActivity1();
|
132
| }
|
133
|
|
134
| private void CheckBtnActivity1()
|
135
| {
|
136
| ybrati1.Enabled = listView1.SelectedItems.Count > 0;
|
137
| update_task.Enabled = listView1.SelectedItems.Count > 0;
|
138
| view_task.Enabled = listView1.SelectedItems.Count > 0;
|
139
|
|
140
| }
|
141
|
|
142
| private void ybrati1_Click(object sender, EventArgs e)
|
143
| {
|
144
| SqlCommand comend = new SqlCommand("DELETE FROM [tasks] " +
|
145
| "WHERE [id] = @id", sqlConn);//перемеена для хранение запроса
|
146
|
|
147
| comend.Parameters.AddWithValue("@id", listView1.SelectedItems[0].SubItems[0].Text);
|
148
| try
|
149
| {
|
150
| SqlDataReader sqlDataReader = comend.ExecuteReader();//создаем запросif (sqlDataReader != null)
|
151
| sqlDataReader.Close();//проверка на откратасть
|
152
| R_update_tasks();
|
153
|
|
154
| }
|
155
| catch (Exception ex)//обработка исключений
|
156
| {
|
157
| MessageBox.Show(ex.Message.ToString(), ex.Source.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
|
158
| }
|
159
| }
|
160
|
|
161
| private void add_task_Click(object sender, EventArgs e)
|
162
| {
|
163
| Form_add_tasks f = new Form_add_tasks(sqlConn);
|
164
|
|
165
| f.Show();
|
166
|
|
167
|
|
168
| }
|
169
|
|
170
| private void view_task_Click(object sender, EventArgs e)
|
171
| {
|
172
| Form_view_tasks f = new Form_view_tasks(sqlConn,
|
173
| listView1.SelectedItems[0].SubItems[3].Text);
|
174
|
|
175
| f.Show();
|
176
| }
|
177
|
|
178
| private void update_task_Click(object sender, EventArgs e)
|
179
| {
|
180
| Form_update_task f = new Form_update_task(sqlConn,
|
181
| listView1.SelectedItems[0].SubItems[3].Text);
|
182
|
|
183
| f.Show();
|
184
| }
|
185
|
|
186
|
|
187
| //employee
|
188
|
|
189
| public void R_update_employee()
|
190
| {
|
191
| listView2.Items.Clear();//очишаем таблицу
|
192
| byte[] data = new byte[1000000000];
|
193
|
|
194
|
|
195
| SqlDataReader sqlRead = null;//перемеена для хранение вывода запроса
|
196
|
|
197
| SqlCommand comend = new SqlCommand();//перемеена для хранение запроса
|
198
|
|
199
| string comond = "SELECT [surname], [employee].[name] AS name_em, [patronymic], [specialty], [employee].[id] AS id_em, [brigade].[name] AS name_br, [vin], [image]" +
|
200
| "FROM [employee], [brigade]" +
|
201
| "WHERE [employee].[brigade] = [brigade].[id]";
|
202
|
|
203
| if (!dostoop)
|
204
| comond += "AND [employee].[brigade] = @brigade";
|
205
|
|
206
|
|
207
| comend = new SqlCommand(comond, sqlConn);
|
208
|
|
209
| if (!dostoop)
|
210
| comend.Parameters.AddWithValue("@brigade", brigade);
|
211
|
|
212
| if (sqlRead != null)
|
213
| sqlRead.Close();//проверка на откратасть
|
214
| string str = "";
|
215
| try
|
216
| {
|
217
| sqlRead = comend.ExecuteReader();//создаем запрос
|
218
|
|
219
|
|
220
| int c = 0;
|
221
| ImageList ImageList1 = new ImageList();
|
222
| ImageList1.ImageSize = new Size(50, 50);
|
223
|
|
224
| List ListViewItem1 = new List();
|
225
|
|
226
| while (sqlRead.Read())
|
227
| {
|
228
|
|
229
| ListViewItem1.Add(new ListViewItem(new string[]
|
230
| {
|
231
| "",
|
232
| Convert.ToString(sqlRead["surname"]),
|
233
| Convert.ToString(sqlRead["name_em"]),
|
234
| Convert.ToString(sqlRead["patronymic"]),
|
235
| Convert.ToString(sqlRead["specialty"]),
|
236
| Convert.ToString(sqlRead["id_em"]),
|
237
| Convert.ToString(sqlRead["name_br"]),
|
238
| Convert.ToString(sqlRead["vin"])
|
239
| }));
|
240
|
|
241
| try
|
242
| {
|
243
| // ImageList1.Images.Add
|
244
| // (new Bitmap(
|
245
| // Image.FromFile(Convert.ToString(sqlRead["photo"]))));
|
246
|
|
247
| data = (byte[])sqlRead["image"];
|
248
| System.IO.MemoryStream ms = new System.IO.MemoryStream(data);
|
249
| Image img = System.Drawing.Image.FromStream(ms);
|
250
| ImageList1.Images.Add(new Bitmap(img, new Size(100, 100)));
|
251
| c++;
|
252
| }
|
253
| catch (Exception ex)//обработка исключений
|
254
| {
|
255
| ImageList1.Images.Add
|
256
| (new Bitmap(50, 50));
|
257
|
|
258
| c++;
|
259
| }
|
260
| }
|
261
|
|
262
| listView2.SmallImageList = ImageList1;
|
263
|
|
264
| for (int i = 0; i < c; i++)
|
265
| {
|
266
| ListViewItem1[i].ImageIndex = i;
|
267
|
|
268
| listView2.Items.Add(ListViewItem1[i]);
|
269
| }
|
270
| if (sqlRead != null)
|
271
| sqlRead.Close();//проверка на откратасть
|
272
| }
|
273
| catch (Exception ex)//обработка исключений
|
274
| {
|
275
| MessageBox.Show(ex.Message.ToString(), ex.Source.ToString() + str, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
276
| }
|
277
| finally
|
278
| {
|
279
| if (sqlRead != null)
|
280
| sqlRead.Close();//проверка на откратасть
|
281
|
|
282
| }
|
283
| }
|
284
|
|
285
| private void listView2_SelectedIndexChanged(object sender, EventArgs e)
|
286
| {
|
287
| CheckBtnActivity2();
|
288
| }
|
289
|
|
290
| private void CheckBtnActivity2()
|
291
| {
|
292
| ybrati2.Enabled = listView2.SelectedItems.Count > 0;
|
293
| update_employee.Enabled = listView2.SelectedItems.Count > 0;
|
294
| view_employee.Enabled = listView2.SelectedItems.Count > 0;
|
295
| }
|
296
|
|
297
| private void ybrati2_Click(object sender, EventArgs e)
|
298
| {
|
299
| SqlCommand comend = new SqlCommand("DELETE FROM [employee] " +
|
300
| "WHERE [id] = @id", sqlConn);//перемеена для хранение запроса
|
301
|
|
302
| comend.Parameters.AddWithValue("@id", listView2.SelectedItems[0].SubItems[5].Text);
|
303
| try
|
304
| {
|
305
| SqlDataReader sqlDataReader = comend.ExecuteReader();//создаем запросif (sqlDataReader != null)
|
306
| sqlDataReader.Close();//проверка на откратасть
|
307
| R_update_employee();
|
308
| }
|
309
| catch (Exception ex)//обработка исключений
|
310
| {
|
311
| MessageBox.Show(ex.Message.ToString(), ex.Source.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
|
312
| }
|
313
|
|
314
| }
|
315
|
|
316
| private void add_employee_Click(object sender, EventArgs e)
|
317
| {
|
318
| Form_add_employee f = new Form_add_employee(sqlConn);
|
319
|
|
320
| f.Show();
|
321
| }
|
322
|
|
323
| private void view_employee_Click(object sender, EventArgs e)
|
324
| {
|
325
| Form_view_employee f = new Form_view_employee(sqlConn,
|
326
| listView2.SelectedItems[0].SubItems[5].Text);
|
327
|
|
328
| f.Show();
|
329
| }
|
330
|
|
331
| private void update_employee_Click(object sender, EventArgs e)
|
332
| {
|
333
| Form_update_employee f = new Form_update_employee(sqlConn,
|
334
| listView2.SelectedItems[0].SubItems[5].Text);
|
335
|
|
336
| f.Show();
|
337
| }
|
338
|
|
339
|
|
340
| //menuStrip
|
341
| private void обновитьToolStripMenuItem_Click(object sender, EventArgs e)
|
342
| {
|
343
| R_update_tasks();
|
344
| R_update_employee();
|
345
| }
|
346
|
|
347
| private void инфVINToolStripMenuItem_Click(object sender, EventArgs e)//вывод собщения о годе
|
348
| {
|
349
| MessageBox.Show(VIN.rdrev.GET_year(listView2.SelectedItems[0].SubItems[7].Text, sqlConn),//текст из функции dll
|
350
| "year",//заголовок
|
351
| MessageBoxButtons.OK,
|
352
| MessageBoxIcon.Question);//тип поля
|
353
| }
|
354
|
|
355
| private void инфЗаводVINToolStripMenuItem_Click(object sender, EventArgs e)//вывод собщения о заводе
|
356
| {
|
357
| MessageBox.Show(VIN.rdrev.GET_factory(listView2.SelectedItems[0].SubItems[7].Text, sqlConn),//текст из функции dll
|
358
| "factory",//заголовок
|
359
| MessageBoxButtons.OK,
|
360
| MessageBoxIcon.Question);//тип поля
|
361
| }
|
362
| }
|
363
| }
|