FormNewOrder.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace СУБД_Швейная_фабрика
  12. {
  13. public partial class FormNewOrder : Form
  14. {
  15. public FormNewOrder()
  16. {
  17. InitializeComponent();
  18. }
  19. private void FormNewOrder_Load(object sender, EventArgs e)
  20. {
  21. // TODO: This line of code loads data into the 'fabrikaLDADataSet.Cloth' table. You can move, or remove it, as needed.
  22. this.clothTableAdapter.Fill(this.fabrikaLDADataSet.Cloth);
  23. // TODO: This line of code loads data into the 'fabrikaLDADataSet.Furnitura' table. You can move, or remove it, as needed.
  24. this.furnituraTableAdapter.Fill(this.fabrikaLDADataSet.Furnitura);
  25. // TODO: This line of code loads data into the 'fabrikaLDADataSet.Products' table. You can move, or remove it, as needed.
  26. this.productsTableAdapter.Fill(this.fabrikaLDADataSet.Products);
  27. }
  28. private void btnNewOrder_Click(object sender, EventArgs e)
  29. {
  30. string IdManager = "";
  31. if (tbxCountProducts.Text.Trim() =="" || int.Parse(tbxCountProducts.Text) <= 0)
  32. {
  33. MessageBox.Show("Кол-во изделий должно быть больше 0", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Error);
  34. return;
  35. }
  36. if (tbxCountFur.Text.Trim() == "" || int.Parse(tbxCountFur.Text) <= 0)
  37. {
  38. MessageBox.Show("Кол-во фурнитуры должно быть больше 0", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Error);
  39. return;
  40. }
  41. if (tbxWight.Text.Trim() == "" || int.Parse(tbxWight.Text) <= 0 || tbxLenght.Text.Trim() == "" || int.Parse(tbxLenght.Text) <= 0)
  42. {
  43. MessageBox.Show("Длина и ширина должны быть больше 0", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Error);
  44. return;
  45. }
  46. SqlConnection con = new SqlConnection(FormAuthorization.StrCon);
  47. con.Open();
  48. SqlCommand cmdManager = new SqlCommand($@"select Count(IdProduct) as CountProduct,IdManager,Users.Role from Orders join Users on users.IdUser = Orders.IdManager
  49. group by Orders.IdManager,Users.Role
  50. order by CountProduct", con);
  51. SqlDataReader res = cmdManager.ExecuteReader();
  52. res.Read();
  53. IdManager = res["IdManager"].ToString();
  54. res.Close();
  55. try
  56. {
  57. SqlCommand cmd = new SqlCommand($@"INSERT INTO Orders
  58. (IdProduct, IdManager, IdClient, IdCloth, IdFur, CountFurnitura, CountProduct)
  59. VALUES ({cmbProduct.SelectedIndex + 1},{IdManager},{FormAuthorization.IdUser},{cmbCloth.SelectedIndex + 1},{cmbFur.SelectedIndex + 1},{tbxCountFur.Text},{tbxCountProducts.Text})", con);
  60. cmd.ExecuteNonQuery();
  61. }
  62. catch
  63. {
  64. MessageBox.Show("Ошибка создания заказа", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Error);
  65. return;
  66. }
  67. con.Close();
  68. MessageBox.Show("Заказ создан","Внимание!",MessageBoxButtons.OK,MessageBoxIcon.Information);
  69. this.Close();
  70. }
  71. }
  72. }