OrganizationsADD.cs 1.7 KB

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