OrganizationsUPD.cs 2.0 KB

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