Admin.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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.Windows.Forms;
  9. using System.Data.SqlClient;
  10. namespace Perevozki
  11. {
  12. public partial class Admin : Form
  13. {
  14. public Admin()
  15. {
  16. InitializeComponent();
  17. StartPosition = FormStartPosition.CenterScreen;
  18. }
  19. private void button1_Click(object sender, EventArgs e)
  20. {
  21. DB dataBase = new DB();
  22. var log = textBox1.Text;
  23. var pass = textBox2.Text;
  24. string querystring = $"insert into Polzovateli (Login, Password) values('{log}', '{pass}')";
  25. SqlCommand command = new SqlCommand(querystring, dataBase.GetConnection());
  26. dataBase.OpenConnection();
  27. if(command.ExecuteNonQuery() ==1 )
  28. {
  29. MessageBox.Show("Пользователь добавлен!");
  30. }
  31. }
  32. private void button2_Click(object sender, EventArgs e)
  33. {
  34. DB dataBase = new DB();
  35. var ID = textBox3.Text;
  36. string querystring = $"DELETE FROM Polzovateli WHERE IDUser = {ID}";
  37. SqlCommand command = new SqlCommand(querystring, dataBase.GetConnection());
  38. dataBase.OpenConnection();
  39. if (command.ExecuteNonQuery() == 1)
  40. {
  41. MessageBox.Show("Пользователь удален!");
  42. }
  43. else
  44. {
  45. MessageBox.Show("Такого пользователя нету");
  46. }
  47. }
  48. private void button3_Click(object sender, EventArgs e)
  49. {
  50. }
  51. private void button3_Click_1(object sender, EventArgs e)
  52. {
  53. DB dataBase = new DB();
  54. var log = textBox1.Text;
  55. var pass = textBox2.Text;
  56. var ID = textBox3.Text;
  57. string changeQuery = $"UPDATE Polzovateli SET Login = '{log}' , Password = '{pass}' where IDUser = '{ID}'";
  58. SqlCommand command = new SqlCommand(changeQuery, dataBase.GetConnection());
  59. dataBase.OpenConnection();
  60. if (command.ExecuteNonQuery() == 1)
  61. {
  62. MessageBox.Show("Данные изменены");
  63. }
  64. }
  65. private void button4_Click(object sender, EventArgs e)
  66. {
  67. Menu f4 = new Menu();
  68. f4.Show();
  69. Hide();
  70. }
  71. }
  72. }