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