Advertisement
MarkDev

Untitled

Dec 22nd, 2022
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.97 KB | None | 0 0
  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. using как_хочешь.Classes;
  12. using как_хочешь.Forms;
  13.  
  14. namespace как_хочешь
  15. {
  16. public partial class Avtorization : Form
  17. {
  18. public Avtorization()
  19. {
  20. InitializeComponent();
  21. }
  22. SqlClass sql = new SqlClass();
  23. GlobalParam param = new GlobalParam();
  24. int cheack_login = 0;
  25.  
  26. private void Avtorization_Load(object sender, EventArgs e)
  27. {
  28. sql.OpenConnection();
  29. }
  30.  
  31. private void Avtorization_FormClosed(object sender, FormClosedEventArgs e)
  32. {
  33. sql.CloseConnection();
  34. }
  35.  
  36. private void button1_Click(object sender, EventArgs e)
  37. {
  38. try
  39. {
  40. if (textBox1.Text != "" && textBox1.Text != "")
  41. {
  42. SqlCommand command = new SqlCommand($"SELECT COUNT(*) from [dbo].[users] WHERE login = '{textBox1.Text}' AND pass = '{textBox2.Text}'", sql.connestion);
  43. SqlDataReader reader = command.ExecuteReader();
  44.  
  45. while (reader.Read())
  46. {
  47. cheack_login = Convert.ToInt32(reader[0]);
  48.  
  49.  
  50. }
  51. reader.Close();
  52.  
  53. if(cheack_login == 1)
  54. {
  55. SqlCommand command_user = new SqlCommand($"SELECT * from [dbo].[users] WHERE login = '{textBox1.Text}' AND pass = '{textBox2.Text}'", sql.connestion);
  56. SqlDataReader reader_user = command_user.ExecuteReader();
  57.  
  58. while (reader_user.Read())
  59. {
  60. param.user_surname = Convert.ToString(reader_user[1]);
  61. param.user_patronymic = Convert.ToString(reader_user[3]);
  62. param.user_name = Convert.ToString(reader_user[2]);
  63. param.user_role = Convert.ToInt32(reader_user[6]);
  64.  
  65. }
  66. reader_user.Close();
  67.  
  68. MessageBox.Show("Добро пожаловать!!!!!!!!!");
  69. this.Hide();
  70. MainPanel mp = new MainPanel();
  71. mp.Show();
  72.  
  73. }
  74. else if (cheack_login == 0)
  75. {
  76. MessageBox.Show("Введите данные", "Ошибка");
  77. }
  78. }
  79. else
  80. {
  81. MessageBox.Show("Пошёл нахуй");
  82. }
  83. }
  84. catch (Exception ex)
  85. {
  86. MessageBox.Show(ex.Message);
  87. }
  88. }
  89. }
  90. }
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105. using System;
  106. using System.Collections.Generic;
  107. using System.Linq;
  108. using System.Text;
  109. using System.Threading.Tasks;
  110.  
  111. namespace как_хочешь.Classes
  112. {
  113. public class GlobalParam
  114. {
  115. public string user_surname = "";
  116. public string user_patronymic = "";
  117. public string user_name = "";
  118. public int user_role = 0;
  119. }
  120. }
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133. using System;
  134. using System.Collections.Generic;
  135. using System.Data.SqlClient;
  136. using System.Linq;
  137. using System.Text;
  138. using System.Threading.Tasks;
  139.  
  140. namespace как_хочешь.Classes
  141. {
  142. public class SqlClass
  143. {
  144. public SqlConnection connestion = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;Initial Catalog=sobaka;Integrated Security=True");
  145.  
  146. public void OpenConnection()
  147. {
  148. connestion.Open();
  149. }
  150.  
  151. public void CloseConnection()
  152. {
  153. connestion.Close();
  154. }
  155. }
  156. }
  157.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement