Form1.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace ad
  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=CLASS3108;Initial Catalog=konkurstest;Integrated Security=True");
  22. SqlCommand command = new SqlCommand("SELECT * FROM users WHERE password=@password AND login =@login ", connection);
  23. command.Parameters.Add("@password", textBox1.Text);
  24. command.Parameters.Add("@login", textBox2.Text);
  25. SqlDataReader read = null;
  26. connection.Open();
  27. try
  28. {
  29. read = command.ExecuteReader();
  30. read.Read();
  31. if (read["admin"].ToString() == "1")
  32. {
  33. Form2 f2 = new Form2();
  34. f2.Show();
  35. this.Hide();
  36. }
  37. if (read["manager"].ToString() == "1")
  38. {
  39. Form3 f3 = new Form3();
  40. f3.Show();
  41. this.Hide();
  42. }
  43. }
  44. catch(Exception ex)
  45. {
  46. MessageBox.Show(ex.Message.ToString(), "",MessageBoxButtons.OK, MessageBoxIcon.Error);
  47. }
  48. }
  49. }
  50. }