CountryUpd.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 proba
  12. {
  13. public partial class CountryUpd : Form
  14. {
  15. string id_country;
  16. public int razmer = 0;
  17. public static string[] update_country = new string[1];
  18. DataBase dataBase = new DataBase();
  19. public CountryUpd(string id_country, string country)
  20. {
  21. InitializeComponent();
  22. textBox1.Text = country;
  23. this.id_country = id_country;
  24. }
  25. public void global_FormClosed(object sender, EventArgs e)
  26. {
  27. Application.Exit();
  28. }
  29. private void button_save_Click(object sender, EventArgs e)
  30. {
  31. if (textBox1.Text.Replace(" ", "") == "") MessageBox.Show("Поле страна не может быть пустым");
  32. else
  33. {
  34. dataBase.openConnection();
  35. var addQuery = $"update Country set country = '{textBox1.Text}' where id_country = '{id_country}'";
  36. var command = new SqlCommand(addQuery, dataBase.GetConnection());
  37. command.ExecuteNonQuery();
  38. MessageBox.Show("Запись успешно изменена");
  39. update_country[razmer] = textBox1.Text;
  40. Array.Resize(ref update_country, update_country.Length + 1);
  41. razmer++;
  42. dataBase.closeConnection();
  43. this.Hide();
  44. Country vidNomenkatury = new Country();
  45. vidNomenkatury.ShowDialog();
  46. }
  47. }
  48. private void button_back_Click(object sender, EventArgs e)
  49. {
  50. this.Hide();
  51. Country country = new Country();
  52. country.ShowDialog();
  53. }
  54. }
  55. }