Form1.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. if (read["manager"].ToString() == "1")
  39. {
  40. Form3 f3 = new Form3();
  41. f3.Show();
  42. this.Hide();
  43. }
  44. }
  45. }
  46. catch(Exception ex)
  47. {
  48. MessageBox.Show(ex.Message.ToString(),"", MessageBoxButtons.OK, MessageBoxIcon.Error );
  49. }
  50. }
  51. }
  52. }