FormAddOrder.cs 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 FormAddOrder : Form
  14. {
  15. public FormAddOrder()
  16. {
  17. InitializeComponent();
  18. }
  19. SqlConnection Con = new SqlConnection(FormMain.txtCon);
  20. private void FormAddOrder_Load(object sender, EventArgs e)
  21. {
  22. // TODO: This line of code loads data into the 'sewingFactoryMURDataSet1.Furnitura' table. You can move, or remove it, as needed.
  23. this.furnituraTableAdapter.Fill(this.sewingFactoryMURDataSet1.Furnitura);
  24. // TODO: This line of code loads data into the 'sewingFactoryMURDataSet1.Cloth' table. You can move, or remove it, as needed.
  25. this.clothTableAdapter.Fill(this.sewingFactoryMURDataSet1.Cloth);
  26. // TODO: This line of code loads data into the 'sewingFactoryMURDataSet1.Izdelia' table. You can move, or remove it, as needed.
  27. this.izdeliaTableAdapter.Fill(this.sewingFactoryMURDataSet1.Izdelia);
  28. // TODO: This line of code loads data into the 'sewingFactoryMURDataSet1.Orders' table. You can move, or remove it, as needed.
  29. this.ordersTableAdapter.Fill(this.sewingFactoryMURDataSet1.Orders);
  30. BsZak.AddNew();
  31. BsZak.Position = BsZak.Count - 1;
  32. CbxCloth.SelectedIndex = 0;
  33. CbxFurn.SelectedIndex = 0;
  34. CbxIzd.SelectedIndex = 0;
  35. LblCountFur.Hide();
  36. LblCountIzd.Hide();
  37. LblIDMen.Hide();
  38. LblIDZak.Hide();
  39. }
  40. private void BtnCreateOrder_Click(object sender, EventArgs e)
  41. {
  42. int f, i;
  43. if(TbxCountFur.Text == "" || TbxCountIzd.Text == "")
  44. {
  45. MessageBox.Show("Не все данные заполнены", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Information);
  46. return;
  47. }
  48. try
  49. {
  50. f = int.Parse(TbxCountFur.Text);
  51. i = int.Parse(TbxCountIzd.Text);
  52. }
  53. catch
  54. {
  55. MessageBox.Show("Данные по количеству введены неверно", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Information);
  56. return;
  57. }
  58. LblCountFur.Text = TbxCountFur.Text;
  59. LblCountIzd.Text = TbxCountIzd.Text;
  60. LblIDZak.Text = FormMain.IDUser;
  61. string txtQuery = $@"select IDUser from Users where Role = 2 and IDUser not in (select IDMen from Orders)";
  62. Con.Open();
  63. SqlCommand query = new SqlCommand(txtQuery, Con);
  64. SqlDataReader res = query.ExecuteReader();
  65. if (res.Read())
  66. {
  67. LblIDMen.Text = res["User"].ToString();
  68. Con.Close();
  69. }
  70. else
  71. {
  72. Con.Close();
  73. txtQuery = $@"select IDMen, (select COUNT(*) from Orders where IDMen = o.IDMen) as co from Orders o group by IDMen order by co";
  74. Con.Open();
  75. query = new SqlCommand(txtQuery, Con);
  76. res = query.ExecuteReader();
  77. res.Read();
  78. LblIDMen.Text = res["IDMen"].ToString();
  79. Con.Close();
  80. }
  81. BsZak.EndEdit();
  82. this.ordersTableAdapter.Update(this.sewingFactoryMURDataSet1.Orders);
  83. this.ordersTableAdapter.Fill(this.sewingFactoryMURDataSet1.Orders);
  84. Close();
  85. }
  86. }
  87. }