AddZac.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. using Servise.Classes;
  2. using System;
  3. using System.Data;
  4. using System.Data.SqlClient;
  5. using System.Windows.Forms;
  6. namespace Servise.Forms
  7. {
  8. public partial class AddZac : Form
  9. {
  10. string tp = "";
  11. string ie = "";
  12. string ic = "";
  13. DataBase conect = new DataBase();
  14. public AddZac()
  15. {
  16. InitializeComponent();
  17. }
  18. private void button1_Click(object sender, EventArgs e)
  19. {
  20. if (0 >= Convert.ToInt32(textColvo.Text))
  21. {
  22. MessageBox.Show("Попытка добавить пустое значение");
  23. return;
  24. }
  25. if (tp != "" && ie != "" && ic != "")
  26. {
  27. conect.openConect();
  28. SqlCommand sql = new SqlCommand("Select quantity From repository_spare where id_spare =" + comboShare.SelectedValue.ToString() + " ", conect.getConect());
  29. int i1 = Convert.ToInt32(sql.ExecuteScalar().ToString());
  30. if (i1 >= Convert.ToInt32(textColvo.Text))
  31. {
  32. string nb = textColvo.Text;
  33. string nm = comboShare.SelectedValue.ToString();
  34. sql = new SqlCommand("Select id_poch From poch where id_employ='" + ie + "' and id_client = '" + ic + "' and time_poch = '" + tp + "'", conect.getConect());
  35. string nm2 = sql.ExecuteScalar().ToString();
  36. var indert = "INSERT INTO zakaz (stoim,col_vo, id_spare,id_poch) VALUES (" + Math.Round(podschet(Convert.ToInt32(comboShare.SelectedValue.ToString()), Convert.ToInt32(textColvo.Text)), 3) + "," + nb + "," + nm + "," + nm2 + ");";
  37. conect.openConect();
  38. var command = new SqlCommand(indert, conect.getConect());
  39. command.ExecuteNonQuery();
  40. indert = "update repository_spare set quantity = quantity - " + nb + " where id_spare =" + nm + " ";
  41. command = new SqlCommand(indert, conect.getConect());
  42. command.ExecuteNonQuery();
  43. }
  44. else
  45. {
  46. MessageBox.Show("На складе недостаточно запчастей");
  47. }
  48. conect.closeConect();
  49. }
  50. else
  51. {
  52. MessageBox.Show("Починка еще не задана");
  53. }
  54. }
  55. private void AddZac_Load(object sender, EventArgs e)
  56. {
  57. Main.upd("SELECT id_spare as 'Код детали',name_spare as 'Название детали',name_type_spare as 'Тип детали',name_brand + ' ' + name_model + ' ' + year_of_release as 'Автомобиль' FROM spare,type_spare,brand where spare.id_brand =brand.id_brand and type_spare.id_type_spare = spare.id_type_spare", dataShare, "");
  58. Main.addVariant(Client, "client", "name_client + ' ' + phone_client", "id_client");
  59. Main.addVariant(comboShare, "spare", "name_spare", "id_spare");
  60. }
  61. public double podschet(int c, int col)
  62. {
  63. conect.openConect();
  64. SqlCommand sql = new SqlCommand("Select cost From repository_spare where id_spare =" + c + " ", conect.getConect());
  65. double i1 = Convert.ToDouble(sql.ExecuteScalar().ToString());
  66. conect.closeConect();
  67. return (i1 * col);
  68. }
  69. private void textColvo_Leave(object sender, EventArgs e)
  70. {
  71. if (textColvo.Text != "")
  72. {
  73. textBox1.Text = Convert.ToString(podschet(Convert.ToInt32(comboShare.SelectedValue.ToString()), Convert.ToInt32(textColvo.Text)));
  74. }
  75. }
  76. private void button2_Click(object sender, EventArgs e)
  77. {
  78. conect.openConect();
  79. SqlCommand sql = new SqlCommand("Select id_employee From employees where login='" + UserInform.Login + "'", conect.getConect());
  80. ic = Client.SelectedValue.ToString();
  81. ie = sql.ExecuteScalar().ToString();
  82. tp = DateTime.Now.ToString();
  83. var indert = "INSERT INTO poch (id_employ,id_client,time_poch) VALUES (" + ie + "," + ic + ",'" + tp + "');";
  84. var command = new SqlCommand(indert, conect.getConect());
  85. command.ExecuteNonQuery();
  86. conect.closeConect();
  87. }
  88. private void button3_Click(object sender, EventArgs e)
  89. {
  90. this.Hide();
  91. Users goUser = new Users();
  92. goUser.Show();
  93. }
  94. private void label15_Click(object sender, EventArgs e)
  95. {
  96. }
  97. private void dataShare_CellContentClick(object sender, DataGridViewCellEventArgs e)
  98. {
  99. }
  100. }
  101. }