123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- 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;
- namespace Дол_Восток
- {
- public partial class addOtryad : Form
- {
- SqlCommand query = null;
- public addOtryad()
- {
- InitializeComponent();
- }
- private void addOtryad_Load(object sender, EventArgs e)
- {
- try
- {
- query = new SqlCommand($"select surname + ' ' + [name] + ' ' + patronymic from sotrudnic", db_helper.sqlConnection);
- SqlDataReader reader = query.ExecuteReader();
- while (reader.Read())
- {
- cb_sotrudnic.Items.Add(reader.GetString(0));
- }
- reader.Close();
- query = new SqlCommand($"select korpus from korpus", db_helper.sqlConnection);
- reader = query.ExecuteReader();
- while (reader.Read())
- {
- cb_korpus.Items.Add(reader.GetString(0));
- }
- reader.Close();
- }
- catch
- {
- MessageBox.Show("Произошла непредвиденная ошибка!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- private void bt_add_Click(object sender, EventArgs e)
- {
- try
- {
- query = new SqlCommand($"select kod_sotrudnic from sotrudnic where (surname + ' ' + [name] + ' ' + patronymic) like '{cb_sotrudnic.SelectedItem}'", db_helper.sqlConnection);
- string kodSotrudnic = query.ExecuteScalar().ToString();
- query = new SqlCommand($"select kod_korpus from korpus where korpus like '{cb_korpus.SelectedItem}'", db_helper.sqlConnection);
- string kodKorpus = query.ExecuteScalar().ToString();
- query = new SqlCommand($"insert into otryad (kod_sotrudnic, kol_vo_children, kod_korpus) values (@kod_sotrudnic, @kol_vo_children, @kod_korpus)", db_helper.sqlConnection);
- query.Parameters.AddWithValue($"kod_sotrudnic", kodSotrudnic);
- query.Parameters.AddWithValue($"kol_vo_children", nud_kolChildren.Value);
- query.Parameters.AddWithValue($"kod_korpus", kodKorpus);
- if (query.ExecuteNonQuery().ToString().Equals("1"))
- {
- MessageBox.Show("Добавление прошло успешно!", "Уведомление", MessageBoxButtons.OK, MessageBoxIcon.Information);
- this.Close();
- }
- }
- catch
- {
- MessageBox.Show("Произошла непредвиденная ошибка!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }
- }
|