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 FormAddOrder : Form { public FormAddOrder() { InitializeComponent(); } SqlConnection Con = new SqlConnection(FormMain.txtCon); private void FormAddOrder_Load(object sender, EventArgs e) { // TODO: This line of code loads data into the 'sewingFactoryMURDataSet1.Furnitura' table. You can move, or remove it, as needed. this.furnituraTableAdapter.Fill(this.sewingFactoryMURDataSet1.Furnitura); // TODO: This line of code loads data into the 'sewingFactoryMURDataSet1.Cloth' table. You can move, or remove it, as needed. this.clothTableAdapter.Fill(this.sewingFactoryMURDataSet1.Cloth); // TODO: This line of code loads data into the 'sewingFactoryMURDataSet1.Izdelia' table. You can move, or remove it, as needed. this.izdeliaTableAdapter.Fill(this.sewingFactoryMURDataSet1.Izdelia); // TODO: This line of code loads data into the 'sewingFactoryMURDataSet1.Orders' table. You can move, or remove it, as needed. this.ordersTableAdapter.Fill(this.sewingFactoryMURDataSet1.Orders); BsZak.AddNew(); BsZak.Position = BsZak.Count - 1; CbxCloth.SelectedIndex = 0; CbxFurn.SelectedIndex = 0; CbxIzd.SelectedIndex = 0; LblCountFur.Hide(); LblCountIzd.Hide(); LblIDMen.Hide(); LblIDZak.Hide(); } private void BtnCreateOrder_Click(object sender, EventArgs e) { int f, i; if(TbxCountFur.Text == "" || TbxCountIzd.Text == "") { MessageBox.Show("Не все данные заполнены", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } try { f = int.Parse(TbxCountFur.Text); i = int.Parse(TbxCountIzd.Text); } catch { MessageBox.Show("Данные по количеству введены неверно", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } LblCountFur.Text = TbxCountFur.Text; LblCountIzd.Text = TbxCountIzd.Text; LblIDZak.Text = FormMain.IDUser; string txtQuery = $@"select IDUser from Users where Role = 2 and IDUser not in (select IDMen from Orders)"; Con.Open(); SqlCommand query = new SqlCommand(txtQuery, Con); SqlDataReader res = query.ExecuteReader(); if (res.Read()) { LblIDMen.Text = res["User"].ToString(); Con.Close(); } else { Con.Close(); txtQuery = $@"select IDMen, (select COUNT(*) from Orders where IDMen = o.IDMen) as co from Orders o group by IDMen order by co"; Con.Open(); query = new SqlCommand(txtQuery, Con); res = query.ExecuteReader(); res.Read(); LblIDMen.Text = res["IDMen"].ToString(); Con.Close(); } BsZak.EndEdit(); this.ordersTableAdapter.Update(this.sewingFactoryMURDataSet1.Orders); this.ordersTableAdapter.Fill(this.sewingFactoryMURDataSet1.Orders); Close(); } } }