Form1.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 konkurs
  12. {
  13. public partial class Form1 : Form
  14. {
  15. public Form1()
  16. {
  17. InitializeComponent();
  18. }
  19. private void button3_Click(object sender, EventArgs e)
  20. {
  21. }
  22. public string constring = "Data Source=CLASS3108;Initial Catalog=konkurs;Integrated Security=True";
  23. private void button2_Click(object sender, EventArgs e)
  24. {
  25. SqlConnection con = new SqlConnection(constring);
  26. SqlDataReader sqlReader = null;
  27. con.Open();
  28. SqlCommand command = new SqlCommand("Select * FROM [dbo].[Users] WHERE login = @login AND password = @password", con);
  29. command.Parameters.Add("@login", textBox1.Text);
  30. command.Parameters.Add("@password", textBox2.Text);
  31. try
  32. {
  33. sqlReader = command.ExecuteReader();
  34. if (!sqlReader.HasRows)
  35. {
  36. string message = "пароль введен не верно";
  37. string caption = "Form close";
  38. MessageBox.Show(message,caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
  39. }
  40. while (sqlReader.Read())
  41. {
  42. if(sqlReader["Admin"].ToString() == "1")
  43. {
  44. Form2 fr2 = new Form2();
  45. fr2.Show();
  46. this.Hide();
  47. }
  48. if (sqlReader["manager"].ToString() == "1")
  49. {
  50. Form3 fr3 = new Form3();
  51. fr3.Show();
  52. this.Hide();
  53. }
  54. }
  55. }
  56. catch (Exception ex)
  57. {
  58. MessageBox.Show(ex.Message.ToString(), ex.Source.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
  59. }
  60. finally
  61. {
  62. if (sqlReader != null)
  63. sqlReader.Close();
  64. }
  65. }
  66. private void textBox1_TextChanged(object sender, EventArgs e)
  67. {
  68. }
  69. private void textBox1_Enter(object sender, EventArgs e)
  70. {
  71. if(textBox1.Text == "введите логин")
  72. {
  73. textBox1.Text = "";
  74. }
  75. }
  76. private void textBox1_Leave(object sender, EventArgs e)
  77. {
  78. if (textBox1.Text == "")
  79. {
  80. textBox1.Text = "введите логин";
  81. }
  82. }
  83. private void textBox2_Enter(object sender, EventArgs e)
  84. {
  85. if (textBox2.Text == "введите пароль")
  86. {
  87. textBox2.Text = "";
  88. }
  89. }
  90. private void textBox2_Leave(object sender, EventArgs e)
  91. {
  92. if (textBox2.Text == "")
  93. {
  94. textBox2.Text = "введите пароль";
  95. }
  96. }
  97. }
  98. }