Form1.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using Npgsql;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace TestsManipulate
  12. {
  13. public partial class Form1 : Form
  14. {
  15. public Form1()
  16. {
  17. InitializeComponent();
  18. }
  19. private void Login(object sender, EventArgs e)
  20. {
  21. var conn = new NpgsqlConnection(Program.connString);
  22. conn.Close();
  23. try
  24. {
  25. conn.Open();
  26. }
  27. catch
  28. {
  29. MessageBox.Show("Ошибка", "Ошибка");
  30. return;
  31. }
  32. using (var cmd = new NpgsqlCommand("SELECT login, password, role_id, id FROM users WHERE login = @login", conn))
  33. {
  34. cmd.Parameters.AddWithValue("login", textBox1.Text);
  35. using (var reader = cmd.ExecuteReader())
  36. {
  37. if (reader.Read())
  38. {
  39. Program.login = textBox1.Text;
  40. string dbPassword = reader.GetString(1);
  41. Program.role_id = reader.GetInt16(2);
  42. Program.user_id = reader.GetInt32(3);
  43. if (dbPassword == textBox2.Text)
  44. {
  45. MainPage mainPage = new MainPage();
  46. this.Hide();
  47. mainPage.Show();
  48. }
  49. else
  50. {
  51. MessageBox.Show("Неверный пароль!", "Ошибка");
  52. }
  53. }
  54. else
  55. {
  56. MessageBox.Show("Пользователь не найден!", "Ошибка");
  57. }
  58. }
  59. }
  60. }
  61. }
  62. }