addZakPredstavitel.cs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Data.SqlClient;
  11. namespace Дол_Восток
  12. {
  13. public partial class addZakPredstavitel : Form
  14. {
  15. SqlCommand query = null;
  16. public addZakPredstavitel()
  17. {
  18. InitializeComponent();
  19. }
  20. private void tb_add_Click(object sender, EventArgs e)
  21. {
  22. try
  23. {
  24. DateTime date1 = DateTime.Parse(dtp_dateBirthZP.Text);
  25. query = new SqlCommand($"insert into passport (kem_vudan, date_vudach, seria, nomer) values (@kem_vudan, @date_vudach, @seria, @nomer)", db_helper.sqlConnection);
  26. query.Parameters.AddWithValue("kem_vudan", tb_kemVudanZP.Text);
  27. query.Parameters.AddWithValue("date_vudach", $"{date1.Day}.{date1.Month}.{date1.Year}");
  28. query.Parameters.AddWithValue("seria", mtb_seriaZP.Text);
  29. query.Parameters.AddWithValue("nomer", mtb_nomerZP.Text);
  30. query.ExecuteNonQuery();
  31. query = new SqlCommand($"select kod_passport from passport where kem_vudan like '{tb_kemVudanZP.Text}' and date_vudach like '{date1.Day}.{date1.Month}.{date1.Year}' and seria like '{mtb_seriaZP.Text}' and nomer like '{mtb_nomerZP.Text}'", db_helper.sqlConnection);
  32. string kodPassport = query.ExecuteScalar().ToString();
  33. date1 = DateTime.Parse(dtp_dateBirthZP.Text);
  34. query = new SqlCommand($"insert into zakon_predstavitel (surname, [name], patronymic, date_birth, adress, kod_passport, inn, snils, telephone, work_place) values (@surname, @name, @patronymic, @date_birth, @adress, @kod_passport, @inn, @snils, @telephone, @work_place)", db_helper.sqlConnection);
  35. query.Parameters.AddWithValue("surname", tb_surnameZP.Text);
  36. query.Parameters.AddWithValue("name", tb_nameZP.Text);
  37. query.Parameters.AddWithValue("patronymic", tb_patronymicZP.Text);
  38. query.Parameters.AddWithValue("date_birth", $"{date1.Day}.{date1.Month}.{date1.Year}");
  39. query.Parameters.AddWithValue("adress", tb_adressZP.Text);
  40. query.Parameters.AddWithValue("kod_passport", kodPassport);
  41. query.Parameters.AddWithValue("inn", mtb_innZP.Text);
  42. query.Parameters.AddWithValue("snils", mtb_snilsZP.Text);
  43. query.Parameters.AddWithValue("telephone", mtb_telephoneZP.Text);
  44. query.Parameters.AddWithValue("work_place", tb_workPlaceZP.Text);
  45. if (query.ExecuteNonQuery().ToString().Equals("1"))
  46. {
  47. MessageBox.Show("Добавление данных прошло успешно!", "Уведомление", MessageBoxButtons.OK, MessageBoxIcon.Information);
  48. this.Close();
  49. }
  50. }
  51. catch
  52. {
  53. MessageBox.Show("Произошла непредвиденная ошибка!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  54. }
  55. }
  56. private void addZakPredstavitel_Load(object sender, EventArgs e)
  57. {
  58. }
  59. }
  60. }