ServUPD.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 ServUPD : Form
  14. {
  15. public int razmer = 0;
  16. public static string[] upd_add = new string[1];
  17. string id_serv;
  18. DataBase dataBase = new DataBase();
  19. public ServUPD(string id_serv, string name, string cost)
  20. {
  21. InitializeComponent();
  22. dataBase.openConnection();
  23. this.id_serv = id_serv;
  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. SADD IDD = new SADD();
  32. IDD.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 ServicesADD set Name = '{textBox1.Text}', Cost = '{textBox2.Text}' where ServicesADD_code = '{id_serv}'";
  42. var command = new SqlCommand(addQuery, dataBase.GetConnection());
  43. command.ExecuteNonQuery();
  44. MessageBox.Show("Запись успешно изменена");
  45. upd_add[razmer] = textBox1.Text;
  46. Array.Resize(ref upd_add, upd_add.Length + 1);
  47. razmer++;
  48. dataBase.closeConnection();
  49. this.Hide();
  50. SADD IF = new SADD();
  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. }