CountryAdd.cs 1.7 KB

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