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 proba { public partial class Postavshiki_update : Form { string id_supplier; public int razmer = 0; public static string[] update_supplier = new string[1]; DataBase dataBase = new DataBase(); public Postavshiki_update(string id_supplier, string name_organization,string surname, string name, string patronymic, string pol, string phone) { InitializeComponent(); text_id_view_tools.Text = pol; textBox2.Text = name_organization; text_price.Text = surname; text_data_manufacture.Text = name; textBox1.Text = patronymic; textBox3.Text = phone; this.id_supplier = id_supplier; } private void button_back_Click(object sender, EventArgs e) { this.Hide(); Postavshiki postavshiki = new Postavshiki(); postavshiki.ShowDialog(); } private void button_save_Click(object sender, EventArgs e) { if (textBox2.Text.Replace(" ", "") == "") MessageBox.Show("Поле название не может быть пустым"); else if (text_price.Text.Replace(" ", "") == "") MessageBox.Show("Поле фамилия не может быть пустым"); else if (text_data_manufacture.Text.Replace(" ", "") == "") MessageBox.Show("Поле имя поставки не может быть пустым"); else if (textBox1.Text.Replace(" ", "") == "") MessageBox.Show("Поле отчество поставки не может быть пустым"); else { dataBase.openConnection(); string pol; string sqlCommand_pol = $"SELECT id_pol From Pol WHERE pol = '{text_id_view_tools.Text}'"; SqlCommand sqlCommand2 = new SqlCommand(sqlCommand_pol, dataBase.GetConnection()); SqlDataAdapter sda = new SqlDataAdapter(sqlCommand_pol, dataBase.GetConnection()); DataTable dtbl = new DataTable(); sda.Fill(dtbl); if (dtbl.Rows.Count != 0) { pol = sqlCommand2.ExecuteScalar().ToString(); var addQuery = $"update Supplier set name_organization = '{textBox2.Text}', surname = '{text_price.Text}', name = '{text_data_manufacture.Text}', patronymic = '{textBox1.Text}', id_pol = '{pol}', phone = '{textBox3.Text}' where id_supplier = '{id_supplier}'"; var command = new SqlCommand(addQuery, dataBase.GetConnection()); command.ExecuteNonQuery(); MessageBox.Show("Запись успешно изменена"); update_supplier[razmer] = textBox2.Text; Array.Resize(ref update_supplier, update_supplier.Length + 1); razmer++; dataBase.closeConnection(); this.Hide(); Postavshiki postavshiki = new Postavshiki(); postavshiki.ShowDialog(); } else { MessageBox.Show("Поле пол должно быть выбрано из списка"); } dataBase.closeConnection(); } } public void global_FormClosed(object sender, EventArgs e) { Application.Exit(); } private void Postavshiki_update_Load(object sender, EventArgs e) { // TODO: данная строка кода позволяет загрузить данные в таблицу "vINILDataSet_Pol.Pol". При необходимости она может быть перемещена или удалена. this.polTableAdapter.Fill(this.vINILDataSet_Pol.Pol); } private void textBox3_KeyPress(object sender, KeyPressEventArgs e) { char number = e.KeyChar; if (!Char.IsDigit(number) && number != 8 && !(e.KeyChar == '+') && !(e.KeyChar == '(') && !(e.KeyChar == ')')) { e.Handled = true; } } } }