Form1.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Data.SqlClient;
  11. namespace KokursTest2
  12. {
  13. public partial class Form1 : Form
  14. {
  15. public Form1()
  16. {
  17. InitializeComponent();
  18. }
  19. private void Form1_Load(object sender, EventArgs e)
  20. {
  21. }
  22. private void textBox1_TextChanged(object sender, EventArgs e)
  23. {
  24. }
  25. private void button1_Click(object sender, EventArgs e)
  26. {
  27. String connstring = "Data Source=DESKTOP-Q8BTJMH;Initial Catalog=konkurs;Integrated Security=True";
  28. SqlConnection conn = new SqlConnection(connstring);
  29. conn.Open();
  30. SqlCommand command = new SqlCommand("Select * From users WHERE login = @login AND password = @password", conn);
  31. command.Parameters.Add("@login",textBox1.Text);
  32. command.Parameters.Add("@password", textBox2.Text);
  33. SqlDataReader reader = null;
  34. try{
  35. reader = command.ExecuteReader();
  36. if (reader.HasRows)
  37. {
  38. reader.Read();
  39. if (reader["admin"].ToString() == "1")
  40. {
  41. Form2 fr2 = new Form2();
  42. fr2.Show();
  43. this.Hide();
  44. }
  45. if (reader["manager"].ToString() == "1")
  46. {
  47. Form3 fr3 = new Form3();
  48. fr3.Show();
  49. this.Hide();
  50. }
  51. }
  52. else{
  53. MessageBox.Show("парроль введен неверно", "авторизация", MessageBoxButtons.OK, MessageBoxIcon.Error);
  54. }
  55. }
  56. catch(Exception ex)
  57. {
  58. MessageBox.Show(ex.Message.ToString(), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
  59. }
  60. finally
  61. {
  62. }
  63. }
  64. private void textBox2_Enter(object sender, EventArgs e)
  65. {
  66. if(textBox2.Text == "Введите пароль")
  67. {
  68. textBox2.Text = "";
  69. }
  70. }
  71. private void textBox2_Leave(object sender, EventArgs e)
  72. {
  73. if (textBox2.Text == "")
  74. {
  75. textBox2.Text = "Введите пароль";
  76. }
  77. }
  78. private void textBox1_Enter(object sender, EventArgs e)
  79. {
  80. if (textBox1.Text == "Введите логин")
  81. {
  82. textBox1.Text = "";
  83. }
  84. }
  85. private void textBox1_Leave(object sender, EventArgs e)
  86. {
  87. if (textBox1.Text == "")
  88. {
  89. textBox1.Text = "Введите логин";
  90. }
  91. }
  92. private void textBox2_TextChanged(object sender, EventArgs e)
  93. {
  94. }
  95. }
  96. }