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