Performer_update.cs 2.0 KB

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