Form1.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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.Data.SqlClient;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace WindowsFormsApp1
  12. {
  13. public partial class Form1 : Form
  14. {
  15. public Form1()
  16. {
  17. InitializeComponent();
  18. }
  19. private void button1_Click(object sender, EventArgs e)
  20. {
  21. SqlConnection connection = new SqlConnection("Data Source=CLASS3109;Initial Catalog=hotel;Integrated Security=True");
  22. connection.Open();
  23. SqlCommand Command = new SqlCommand("select * from users where login=@login AND password=@password", connection);
  24. Command.Parameters.Add("@login" ,textBox1.Text);
  25. Command.Parameters.Add("@password", textBox2.Text);
  26. SqlDataReader read = null;
  27. try
  28. {
  29. read = Command.ExecuteReader();
  30. if(read.HasRows){
  31. read.Read();
  32. if (read["admin"].ToString() == "1")
  33. {
  34. Form2 f2 = new Form2();
  35. f2.Show();
  36. this.Hide();
  37. }
  38. }
  39. }
  40. catch(Exception ex)
  41. {
  42. MessageBox.Show(ex.Message.ToString(),"", MessageBoxButtons.OK, MessageBoxIcon.Error );
  43. }
  44. }
  45. }
  46. }