Genre_update.cs 1.9 KB

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