InternetADD.cs 2.3 KB

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