Performer_add.cs 1.8 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 Performer_add : Form
  14. {
  15. public int razmer = 0;
  16. public static string[] add_performer = new string[1];
  17. DataBase dataBase = new DataBase();
  18. public Performer_add()
  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 performer = textBox1.Text;
  29. var addQuery = $"insert into [Performer] (performer) values (N'{performer}')";
  30. var command = new SqlCommand(addQuery, dataBase.GetConnection());
  31. command.ExecuteNonQuery();
  32. MessageBox.Show("Запись успешно добавлена в таблицу");
  33. add_performer[razmer] = textBox1.Text;
  34. Array.Resize(ref add_performer, add_performer.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. Performer performer = new Performer();
  47. performer.ShowDialog();
  48. }
  49. private void Performer_add_Load(object sender, EventArgs e)
  50. {
  51. }
  52. }
  53. }