Form1.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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 Blanki_ekzamena
  12. {
  13. public partial class Form1 : Form
  14. {
  15. public Form1()
  16. {
  17. InitializeComponent();
  18. }
  19. public DataTable Select(string selectSQL)
  20. {
  21. DataTable dataTable = new DataTable("dataBase");
  22. SqlConnection sqlConnection = new SqlConnection("server=ngknn.ru;Trusted_Connection=No;DataBase=31P_Trifonova_PP;User ID=31П;PWD=12357");
  23. sqlConnection.Open();
  24. SqlCommand sqlCommand = sqlConnection.CreateCommand();
  25. sqlCommand.CommandText = selectSQL;
  26. SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand);
  27. sqlDataAdapter.Fill(dataTable);
  28. sqlConnection.Close();
  29. return dataTable;
  30. }
  31. private void btn_sotr_Click(object sender, EventArgs e)
  32. {
  33. if (textBox2.UseSystemPasswordChar == true)
  34. {
  35. textBox2.UseSystemPasswordChar = false;
  36. }
  37. else
  38. {
  39. textBox2.UseSystemPasswordChar = true;
  40. }
  41. }
  42. public bool isFormVaid(string a, string b)
  43. {
  44. if (a.ToString().Trim() == String.Empty || b.ToString().Trim() == String.Empty)
  45. {
  46. MessageBox.Show("Обезательные поля пустые", "Пожалуйста, заполните обязательные поля", MessageBoxButtons.OK, MessageBoxIcon.Error);
  47. return false;
  48. }
  49. else
  50. {
  51. return true;
  52. }
  53. }
  54. private bool checkAdmin(string login_sotrd, string password)
  55. {
  56. const string sql = "Select * from Sotrudnik WHERE Login = @log AND [Password] = @pass and [Dolgnost]='Администратор'";
  57. DataTable table = new DataTable();
  58. SqlCommand cmd = new SqlCommand(sql, DataBase.connect());
  59. SqlDataAdapter adapter = new SqlDataAdapter();
  60. cmd.Parameters.Add(new SqlParameter("@log", SqlDbType.NVarChar, 50));
  61. cmd.Parameters["@log"].Value = login_sotrd;
  62. cmd.Parameters.Add(new SqlParameter("@pass", SqlDbType.NVarChar, 50));
  63. cmd.Parameters["@pass"].Value = password;
  64. adapter.SelectCommand = cmd;
  65. adapter.Fill(table);
  66. if (table.Rows.Count == 1)
  67. {
  68. DebugAndTrace hy = new DebugAndTrace();
  69. string[] opisanie = new string[4];
  70. using (SqlConnection connection = new SqlConnection("server=ngknn.ru;Trusted_Connection=No;DataBase=31P_Trifonova_PP;User ID=31П;PWD=12357"))
  71. {
  72. connection.Open();
  73. SqlCommand command3 = new SqlCommand("Select [Familia] From [dbo].[Sotrudnik] where [Login] ='" + textBox1.Text + "' and [Password] ='" + textBox2.Text + "'", connection);
  74. opisanie[0] = command3.ExecuteScalar().ToString();
  75. DebugAndTrace.fio = $"{opisanie[0]}";
  76. SqlCommand command4 = new SqlCommand("Select [Ima] From [dbo].[Sotrudnik] where [Login] ='" + textBox1.Text + "' and [Password] ='" + textBox2.Text + "'", connection);
  77. opisanie[1] = command4.ExecuteScalar().ToString();
  78. DebugAndTrace.ima = $"{opisanie[1]}";
  79. SqlCommand command5 = new SqlCommand("Select [Otchestvo] From [dbo].[Sotrudnik] where [Login] ='" + textBox1.Text + "' and [Password] ='" + textBox2.Text + "'", connection);
  80. opisanie[2] = command5.ExecuteScalar().ToString();
  81. DebugAndTrace.oth = $"{opisanie[2]}";
  82. SqlCommand command6 = new SqlCommand("Select [Dolgnost] From [dbo].[Sotrudnik] where [Login] ='" + textBox1.Text + "' and [Password] ='" + textBox2.Text + "'", connection);
  83. opisanie[3] = command6.ExecuteScalar().ToString();
  84. DebugAndTrace.dol = $"{opisanie[3]}";
  85. }
  86. DebugAndTrace.login(textBox1.Text);
  87. return true;
  88. }
  89. else
  90. {
  91. return false;
  92. }
  93. }
  94. private bool checkOperator(string login_sotrd, string password)
  95. {
  96. const string sql = "Select * from Sotrudnik WHERE Login = @log AND [Password] = @pass and [Dolgnost]='Оператор'";
  97. DataTable table = new DataTable();
  98. SqlCommand cmd = new SqlCommand(sql, DataBase.connect());
  99. SqlDataAdapter adapter = new SqlDataAdapter();
  100. cmd.Parameters.Add(new SqlParameter("@log", SqlDbType.NVarChar, 50));
  101. cmd.Parameters["@log"].Value = login_sotrd;
  102. cmd.Parameters.Add(new SqlParameter("@pass", SqlDbType.NVarChar, 50));
  103. cmd.Parameters["@pass"].Value = password;
  104. adapter.SelectCommand = cmd;
  105. adapter.Fill(table);
  106. if (table.Rows.Count == 1)
  107. {
  108. DebugAndTrace hy = new DebugAndTrace();
  109. string[] opisanie = new string[4];
  110. using (SqlConnection connection = new SqlConnection("server=ngknn.ru;Trusted_Connection=No;DataBase=31P_Trifonova_PP;User ID=31П;PWD=12357"))
  111. {
  112. connection.Open();
  113. SqlCommand command3 = new SqlCommand("Select [Familia] From [dbo].[Sotrudnik] where [Login] ='" + textBox1.Text + "' and [Password] ='" + textBox2.Text + "'", connection);
  114. opisanie[0] = command3.ExecuteScalar().ToString();
  115. DebugAndTrace.fio = $"{opisanie[0]}";
  116. SqlCommand command4 = new SqlCommand("Select [Ima] From [dbo].[Sotrudnik] where [Login] ='" + textBox1.Text + "' and [Password] ='" + textBox2.Text + "'", connection);
  117. opisanie[1] = command4.ExecuteScalar().ToString();
  118. DebugAndTrace.ima = $"{opisanie[1]}";
  119. SqlCommand command5 = new SqlCommand("Select [Otchestvo] From [dbo].[Sotrudnik] where [Login] ='" + textBox1.Text + "' and [Password] ='" + textBox2.Text + "'", connection);
  120. opisanie[2] = command5.ExecuteScalar().ToString();
  121. DebugAndTrace.oth = $"{opisanie[2]}";
  122. SqlCommand command6 = new SqlCommand("Select [Dolgnost] From [dbo].[Sotrudnik] where [Login] ='" + textBox1.Text + "' and [Password] ='" + textBox2.Text + "'", connection);
  123. opisanie[3] = command6.ExecuteScalar().ToString();
  124. DebugAndTrace.dol = $"{opisanie[3]}";
  125. }
  126. DebugAndTrace.login(textBox1.Text);
  127. return true;
  128. }
  129. else
  130. {
  131. return false;
  132. }
  133. }
  134. private bool checkSotr(string login_sotrd, string password)
  135. {
  136. const string sql = "Select * from Sotrudnik WHERE Login = @log AND [Password] = @pass and [Dolgnost]='Сотрудник'";
  137. DataTable table = new DataTable();
  138. SqlCommand cmd = new SqlCommand(sql, DataBase.connect());
  139. SqlDataAdapter adapter = new SqlDataAdapter();
  140. cmd.Parameters.Add(new SqlParameter("@log", SqlDbType.NVarChar, 50));
  141. cmd.Parameters["@log"].Value = login_sotrd;
  142. cmd.Parameters.Add(new SqlParameter("@pass", SqlDbType.NVarChar, 50));
  143. cmd.Parameters["@pass"].Value = password;
  144. adapter.SelectCommand = cmd;
  145. adapter.Fill(table);
  146. if (table.Rows.Count == 1)
  147. {
  148. DebugAndTrace hy = new DebugAndTrace();
  149. string[] opisanie = new string[4];
  150. using (SqlConnection connection = new SqlConnection("server=ngknn.ru;Trusted_Connection=No;DataBase=31P_Trifonova_PP;User ID=31П;PWD=12357"))
  151. {
  152. connection.Open();
  153. SqlCommand command3 = new SqlCommand("Select [Familia] From [dbo].[Sotrudnik] where [Login] ='" + textBox1.Text + "' and [Password] ='" + textBox2.Text + "'", connection);
  154. opisanie[0] = command3.ExecuteScalar().ToString();
  155. DebugAndTrace.fio = $"{opisanie[0]}";
  156. SqlCommand command4 = new SqlCommand("Select [Ima] From [dbo].[Sotrudnik] where [Login] ='" + textBox1.Text + "' and [Password] ='" + textBox2.Text + "'", connection);
  157. opisanie[1] = command4.ExecuteScalar().ToString();
  158. DebugAndTrace.ima = $"{opisanie[1]}";
  159. SqlCommand command5 = new SqlCommand("Select [Otchestvo] From [dbo].[Sotrudnik] where [Login] ='" + textBox1.Text + "' and [Password] ='" + textBox2.Text + "'", connection);
  160. opisanie[2] = command5.ExecuteScalar().ToString();
  161. DebugAndTrace.oth = $"{opisanie[2]}";
  162. SqlCommand command6 = new SqlCommand("Select [Dolgnost] From [dbo].[Sotrudnik] where [Login] ='" + textBox1.Text + "' and [Password] ='" + textBox2.Text + "'", connection);
  163. opisanie[3] = command6.ExecuteScalar().ToString();
  164. DebugAndTrace.dol = $"{opisanie[3]}";
  165. }
  166. DebugAndTrace.login(textBox1.Text);
  167. return true;
  168. }
  169. else
  170. {
  171. MessageBox.Show("Неправильный логин или пароль! Повторите ввод!");
  172. return false;
  173. }
  174. }
  175. private void btn_reg_Click(object sender, EventArgs e)
  176. {
  177. if (isFormVaid(textBox1.Text, textBox2.Text))
  178. {
  179. if (checkAdmin(textBox1.Text, textBox2.Text))
  180. {
  181. Admin nh = new Admin();
  182. string[] opisanie = new string[3];
  183. using (SqlConnection connection = new SqlConnection("server=ngknn.ru;Trusted_Connection=No;DataBase=31P_Trifonova_PP;User ID=31П;PWD=12357"))
  184. {
  185. connection.Open();
  186. SqlCommand command = new SqlCommand("Select [Familia] From [dbo].[Sotrudnik] where [Login] ='" + textBox1.Text + "' and [Password] ='" + textBox2.Text + "'and [Dolgnost]='Администратор'", connection);
  187. opisanie[0] = command.ExecuteScalar().ToString();
  188. Admin.familia = $"{opisanie[0]}";
  189. SqlCommand command1 = new SqlCommand("Select [Ima] From [dbo].[Sotrudnik] where [Login] ='" + textBox1.Text + "' and [Password] ='" + textBox2.Text + "'and [Dolgnost]='Администратор'", connection);
  190. opisanie[1] = command1.ExecuteScalar().ToString();
  191. Admin.ima = $"{opisanie[1]}";
  192. SqlCommand command2 = new SqlCommand("Select [Otchestvo] From [dbo].[Sotrudnik] where [Login] ='" + textBox1.Text + "' and [Password] ='" + textBox2.Text + "'and [Dolgnost]='Администратор'", connection);
  193. opisanie[2] = command2.ExecuteScalar().ToString();
  194. Admin.othestvo = $"{opisanie[2]}";
  195. }
  196. using (Admin fd = new Admin())
  197. {
  198. this.Hide();
  199. fd.ShowDialog();
  200. this.Close();
  201. }
  202. }
  203. if (checkOperator(textBox1.Text, textBox2.Text))
  204. {
  205. Operator nh = new Operator();
  206. string[] opisanie = new string[3];
  207. using (SqlConnection connection = new SqlConnection("server=ngknn.ru;Trusted_Connection=No;DataBase=31P_Trifonova_PP;User ID=31П;PWD=12357"))
  208. {
  209. connection.Open();
  210. SqlCommand command = new SqlCommand("Select [Familia] From [dbo].[Sotrudnik] where [Login] ='" + textBox1.Text + "' and [Password] ='" + textBox2.Text + "'", connection);
  211. opisanie[0] = command.ExecuteScalar().ToString();
  212. Operator.familia = $"{opisanie[0]}";
  213. SqlCommand command1 = new SqlCommand("Select [Ima] From [dbo].[Sotrudnik] where [Login] ='" + textBox1.Text + "' and [Password] ='" + textBox2.Text + "'", connection);
  214. opisanie[1] = command1.ExecuteScalar().ToString();
  215. Operator.ima = $"{opisanie[1]}";
  216. SqlCommand command2 = new SqlCommand("Select [Otchestvo] From [dbo].[Sotrudnik] where [Login] ='" + textBox1.Text + "' and [Password] ='" + textBox2.Text + "'", connection);
  217. opisanie[2] = command2.ExecuteScalar().ToString();
  218. Operator.othestvo = $"{opisanie[2]}";
  219. }
  220. using (Operator fd = new Operator())
  221. {
  222. this.Hide();
  223. fd.ShowDialog();
  224. this.Close();
  225. }
  226. }
  227. if (checkSotr(textBox1.Text, textBox2.Text))
  228. {
  229. Zakaz nd = new Zakaz();
  230. string[] opisanie = new string[7];
  231. using (SqlConnection connection = new SqlConnection("server=ngknn.ru;Trusted_Connection=No;DataBase=31P_Trifonova_PP;User ID=31П;PWD=12357"))
  232. {
  233. connection.Open();
  234. SqlCommand command = new SqlCommand("Select [Familia] From [dbo].[Sotrudnik] where [Login] ='" + textBox1.Text + "' and [Password] ='" + textBox2.Text + "'", connection);
  235. opisanie[0] = command.ExecuteScalar().ToString();
  236. Zakaz.familia = $"{opisanie[0]}";
  237. SqlCommand command1 = new SqlCommand("Select [Ima] From [dbo].[Sotrudnik] where [Login] ='" + textBox1.Text + "' and [Password] ='" + textBox2.Text + "'", connection);
  238. opisanie[1] = command1.ExecuteScalar().ToString();
  239. Zakaz.ima = $"{opisanie[1]}";
  240. SqlCommand command2 = new SqlCommand("Select [Otchestvo] From [dbo].[Sotrudnik] where [Login] ='" + textBox1.Text + "' and [Password] ='" + textBox2.Text + "'", connection);
  241. opisanie[2] = command2.ExecuteScalar().ToString();
  242. Zakaz.othestvo = $"{opisanie[2]}";
  243. }
  244. using (Zakaz fd = new Zakaz())
  245. {
  246. this.Hide();
  247. fd.ShowDialog();
  248. this.Close();
  249. }
  250. }
  251. }
  252. }
  253. }
  254. }