InernetUPD.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 InernetUPD : Form
  14. {
  15. public int razmer = 0;
  16. public static string[] upd_internet = new string[1];
  17. string id_internet;
  18. DataBase dataBase = new DataBase();
  19. public InernetUPD(string id_internet, string name, string cost)
  20. {
  21. InitializeComponent();
  22. dataBase.openConnection();
  23. this.id_internet = id_internet;
  24. textBox1.Text = name;
  25. textBox2.Text = cost;
  26. dataBase.closeConnection();
  27. }
  28. private void button_back_Click(object sender, EventArgs e)
  29. {
  30. this.Hide();
  31. InternetForm IF = new InternetForm();
  32. IF.ShowDialog();
  33. }
  34. private void Save_button_Click(object sender, EventArgs e)
  35. {
  36. if (textBox1.Text.Replace(" ", "") == "") MessageBox.Show("Поле интернет не может быть пустым");
  37. if (textBox2.Text.Replace(" ", "") == "") MessageBox.Show("Поле стоимость не может быть пустым");
  38. else
  39. {
  40. dataBase.openConnection();
  41. var addQuery = $"update Internet set Name = '{textBox1.Text}', Cost = '{textBox2.Text}' where Internet_code = '{id_internet}'";
  42. var command = new SqlCommand(addQuery, dataBase.GetConnection());
  43. command.ExecuteNonQuery();
  44. MessageBox.Show("Запись успешно изменена");
  45. upd_internet[razmer] = textBox1.Text;
  46. Array.Resize(ref upd_internet, upd_internet.Length + 1);
  47. razmer++;
  48. dataBase.closeConnection();
  49. this.Hide();
  50. InternetForm IF = new InternetForm();
  51. IF.ShowDialog();
  52. }
  53. }
  54. private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
  55. {
  56. char number = e.KeyChar;
  57. if ((e.KeyChar <= 47 || e.KeyChar >= 58) && number != 8 && number != 46) //цифры, клавиша BackSpace и запятая а ASCII
  58. {
  59. e.Handled = true;
  60. }
  61. }
  62. private void global_FormClosed(object sender, FormClosedEventArgs e)
  63. {
  64. Application.Exit();
  65. }
  66. }
  67. }