using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace СУБД_Швейная_фабрика { public partial class FormNewOrder : Form { public FormNewOrder() { InitializeComponent(); } private void FormNewOrder_Load(object sender, EventArgs e) { // TODO: This line of code loads data into the 'fabrikaLDADataSet.Cloth' table. You can move, or remove it, as needed. this.clothTableAdapter.Fill(this.fabrikaLDADataSet.Cloth); // TODO: This line of code loads data into the 'fabrikaLDADataSet.Furnitura' table. You can move, or remove it, as needed. this.furnituraTableAdapter.Fill(this.fabrikaLDADataSet.Furnitura); // TODO: This line of code loads data into the 'fabrikaLDADataSet.Products' table. You can move, or remove it, as needed. this.productsTableAdapter.Fill(this.fabrikaLDADataSet.Products); } private void btnNewOrder_Click(object sender, EventArgs e) { string IdManager = ""; if (tbxCountProducts.Text.Trim() =="" || int.Parse(tbxCountProducts.Text) <= 0) { MessageBox.Show("Кол-во изделий должно быть больше 0", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (tbxCountFur.Text.Trim() == "" || int.Parse(tbxCountFur.Text) <= 0) { MessageBox.Show("Кол-во фурнитуры должно быть больше 0", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (tbxWight.Text.Trim() == "" || int.Parse(tbxWight.Text) <= 0 || tbxLenght.Text.Trim() == "" || int.Parse(tbxLenght.Text) <= 0) { MessageBox.Show("Длина и ширина должны быть больше 0", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } SqlConnection con = new SqlConnection(FormAuthorization.StrCon); con.Open(); SqlCommand cmdManager = new SqlCommand($@"select Count(IdProduct) as CountProduct,IdManager,Users.Role from Orders join Users on users.IdUser = Orders.IdManager group by Orders.IdManager,Users.Role order by CountProduct", con); SqlDataReader res = cmdManager.ExecuteReader(); res.Read(); IdManager = res["IdManager"].ToString(); res.Close(); try { SqlCommand cmd = new SqlCommand($@"INSERT INTO Orders (IdProduct, IdManager, IdClient, IdCloth, IdFur, CountFurnitura, CountProduct) VALUES ({cmbProduct.SelectedIndex + 1},{IdManager},{FormAuthorization.IdUser},{cmbCloth.SelectedIndex + 1},{cmbFur.SelectedIndex + 1},{tbxCountFur.Text},{tbxCountProducts.Text})", con); cmd.ExecuteNonQuery(); } catch { MessageBox.Show("Ошибка создания заказа", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } con.Close(); MessageBox.Show("Заказ создан","Внимание!",MessageBoxButtons.OK,MessageBoxIcon.Information); this.Close(); } } }