changeZakPredstavitel.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 changeZakPredstavitel : Form
  14. {
  15. SqlCommand query = null;
  16. public changeZakPredstavitel()
  17. {
  18. InitializeComponent();
  19. }
  20. private void changeZakPredstavitel_Load(object sender, EventArgs e)
  21. {
  22. try
  23. {
  24. query = new SqlCommand($"select surname from zakon_predstavitel where kod_zakon_predstavitel like '{changeChild.row}'", db_helper.sqlConnection);
  25. tb_surnameZP.Text = query.ExecuteScalar().ToString();
  26. query = new SqlCommand($"select [name] from zakon_predstavitel where kod_zakon_predstavitel like '{changeChild.row}'", db_helper.sqlConnection);
  27. tb_nameZP.Text = query.ExecuteScalar().ToString();
  28. query = new SqlCommand($"select patronymic from zakon_predstavitel where kod_zakon_predstavitel like '{changeChild.row}'", db_helper.sqlConnection);
  29. tb_patronymicZP.Text = query.ExecuteScalar().ToString();
  30. query = new SqlCommand($"select date_birth from zakon_predstavitel where kod_zakon_predstavitel like '{changeChild.row}'", db_helper.sqlConnection);
  31. dtp_dateBirthZP.Text = query.ExecuteScalar().ToString();
  32. query = new SqlCommand($"select adress from zakon_predstavitel where kod_zakon_predstavitel like '{changeChild.row}'", db_helper.sqlConnection);
  33. tb_adressZP.Text = query.ExecuteScalar().ToString();
  34. query = new SqlCommand($"select kem_vudan from zakon_predstavitel z join passport p on p.kod_passport = z.kod_passport where kod_zakon_predstavitel like '{changeChild.row}'", db_helper.sqlConnection);
  35. tb_kemVudanZP.Text = query.ExecuteScalar().ToString();
  36. query = new SqlCommand($"select date_vudach from zakon_predstavitel z join passport p on p.kod_passport = z.kod_passport where kod_zakon_predstavitel like '{changeChild.row}'", db_helper.sqlConnection);
  37. dtp_dateVudachZP.Text = query.ExecuteScalar().ToString();
  38. query = new SqlCommand($"select seria from zakon_predstavitel z join passport p on p.kod_passport = z.kod_passport where kod_zakon_predstavitel like '{changeChild.row}'", db_helper.sqlConnection);
  39. mtb_seriaZP.Text = query.ExecuteScalar().ToString();
  40. query = new SqlCommand($"select nomer from zakon_predstavitel z join passport p on p.kod_passport = z.kod_passport where kod_zakon_predstavitel like '{changeChild.row}'", db_helper.sqlConnection);
  41. mtb_nomerZP.Text = query.ExecuteScalar().ToString();
  42. query = new SqlCommand($"select inn from zakon_predstavitel where kod_zakon_predstavitel like '{changeChild.row}'", db_helper.sqlConnection);
  43. mtb_innZP.Text = query.ExecuteScalar().ToString();
  44. query = new SqlCommand($"select snils from zakon_predstavitel where kod_zakon_predstavitel like '{changeChild.row}'", db_helper.sqlConnection);
  45. mtb_snilsZP.Text = query.ExecuteScalar().ToString();
  46. query = new SqlCommand($"select telephone from zakon_predstavitel where kod_zakon_predstavitel like '{changeChild.row}'", db_helper.sqlConnection);
  47. mtb_telephoneZP.Text = query.ExecuteScalar().ToString();
  48. query = new SqlCommand($"select work_place from zakon_predstavitel where kod_zakon_predstavitel like '{changeChild.row}'", db_helper.sqlConnection);
  49. tb_workPlaceZP.Text = query.ExecuteScalar().ToString();
  50. }
  51. catch
  52. {
  53. MessageBox.Show("Произошла непредвиденная ошибка!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  54. }
  55. }
  56. private void bt_change_Click(object sender, EventArgs e)
  57. {
  58. try
  59. {
  60. query = new SqlCommand($"select kod_passport from zakon_predstavitel where kod_zakon_predstavitel like '{changeChild.row}'", db_helper.sqlConnection);
  61. string kodPassport = query.ExecuteScalar().ToString();
  62. DateTime date1 = DateTime.Parse(dtp_dateVudachZP.Text);
  63. query = new SqlCommand($"update passport set kem_vudan = @kem_vudan, date_vudach = @date_vudach, seria = @seria, nomer = @nomer where kod_passport like (select kod_passport from zakon_predstavitel where kod_zakon_predstavitel like '{changeChild.row}')", db_helper.sqlConnection);
  64. query.Parameters.AddWithValue("kem_vudan", tb_kemVudanZP.Text);
  65. query.Parameters.AddWithValue("date_vudach", $"{date1.Day}.{date1.Month}.{date1.Year}");
  66. query.Parameters.AddWithValue("seria", mtb_seriaZP.Text);
  67. query.Parameters.AddWithValue("nomer", mtb_nomerZP.Text);
  68. query.ExecuteNonQuery();
  69. date1 = DateTime.Parse(dtp_dateBirthZP.Text);
  70. query = new SqlCommand($"update zakon_predstavitel set surname = @surname, [name] = @name, patronymic = @patronymic, date_birth = @date_birth, adress = @adress, inn = @inn, snils = @snils, telephone = @telephone, work_place = @work_place where kod_zakon_predstavitel like '{changeChild.row}'", db_helper.sqlConnection);
  71. query.Parameters.AddWithValue("surname", tb_surnameZP.Text);
  72. query.Parameters.AddWithValue("name", tb_nameZP.Text);
  73. query.Parameters.AddWithValue("patronymic", tb_patronymicZP.Text);
  74. query.Parameters.AddWithValue("date_birth", $"{date1.Day}.{date1.Month}.{date1.Year}");
  75. query.Parameters.AddWithValue("adress", tb_adressZP.Text);
  76. query.Parameters.AddWithValue("inn", mtb_innZP.Text);
  77. query.Parameters.AddWithValue("snils", mtb_snilsZP.Text);
  78. query.Parameters.AddWithValue("telephone", mtb_telephoneZP.Text);
  79. query.Parameters.AddWithValue("work_place", tb_workPlaceZP.Text);
  80. if (query.ExecuteNonQuery().ToString().Equals("1"))
  81. {
  82. MessageBox.Show("Данные успешно изменены!", "Уведомление", MessageBoxButtons.OK, MessageBoxIcon.Information);
  83. this.Close();
  84. }
  85. }
  86. catch
  87. {
  88. MessageBox.Show("Произошла непредвиденная ошибка!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  89. }
  90. }
  91. private void label3_Click(object sender, EventArgs e)
  92. {
  93. }
  94. }
  95. }