Class1.cs 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Configuration;
  4. using System.Data.SqlClient;
  5. using System.Text.RegularExpressions;
  6. namespace PC_Build_Games_SQL
  7. {
  8. public class SQL
  9. {
  10. public string User;// пользователя, который вошел в аккаунт
  11. public SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQL"].ConnectionString);
  12. public bool ConnectivityCheck()
  13. {
  14. sqlConnection.Open();
  15. if (sqlConnection.State == System.Data.ConnectionState.Open)
  16. {
  17. Console.WriteLine("Подключение прошло успешно");
  18. return true;
  19. }
  20. sqlConnection.Close();
  21. return false;
  22. }
  23. public bool Login_verification(string nickname, string password)
  24. {
  25. sqlConnection.Open();
  26. string authenticationrequest = "SELECT * from User_Authorization";
  27. SqlCommand command = new SqlCommand(authenticationrequest, sqlConnection);
  28. SqlDataReader reader = command.ExecuteReader();
  29. bool flag = false;
  30. int i = 1;
  31. using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQL"].ConnectionString))
  32. {
  33. if (reader.HasRows)
  34. {
  35. while (reader.Read())
  36. {
  37. if (nickname == Convert.ToString(reader.GetValue(1)))
  38. {
  39. if (password == Convert.ToString(reader.GetValue(2)))
  40. {
  41. Console.WriteLine("Нашел");
  42. flag = true;
  43. User = Convert.ToString(reader.GetValue(1));
  44. }
  45. }
  46. i++;
  47. }
  48. }
  49. }
  50. reader.Close();
  51. sqlConnection.Close();
  52. return flag;
  53. }
  54. public int Registration(string name, string surname, string nickname, string email, string password)// Регистрация пользователя
  55. {
  56. if (name == "" || surname == "" || nickname == "" || email == "" || password == "")
  57. {
  58. return 1; // Поля должны быть заполнены
  59. }
  60. Regex regex = new Regex(@"^(?! )(?!.* $)(?!(?:.* ){2}).+$");
  61. Regex regexEmail = new Regex(@"^[_a-z0-9-\+-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$");
  62. Regex regexPassword = new Regex(@"([0-9,a-z,A-Z,~,!,@,#,$,%,^,&,*,(,),_]){6,}$");
  63. MatchCollection match = regex.Matches(name);
  64. if (regexEmail.IsMatch(email) == false)
  65. {
  66. return 5;// Такой почты не существует
  67. }
  68. if (regexPassword.IsMatch(password) == false)
  69. {
  70. return 6;// Пароль не соответствует требованиям
  71. }
  72. if (regex.IsMatch(name) == true && regex.IsMatch(surname) && regex.IsMatch(nickname))
  73. {
  74. sqlConnection.Open();
  75. string User_Authorization = "SELECT * from User_Authorization";
  76. string User = "select * from [User]";
  77. string Query_User_Authorization = String.Format($"INSERT INTO User_Authorization (Nickname, PASSWORD) VALUES ('{nickname}','{password}')");
  78. string Query_User = String.Format($"INSERT INTO [User] ([Name],Surname,EMAIL) VALUES ('{name}','{surname}','{email}')");
  79. SqlCommand User_Authorization_Table = new SqlCommand(User_Authorization, sqlConnection);
  80. SqlDataReader Reader_User_Authorization_Table = User_Authorization_Table.ExecuteReader();
  81. using (SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQL"].ConnectionString))
  82. {
  83. while (Reader_User_Authorization_Table.Read())
  84. {
  85. if (nickname == Convert.ToString(Reader_User_Authorization_Table.GetValue(1)))
  86. {
  87. return 2; // пользователь с таким ником уже существует
  88. }
  89. }
  90. }
  91. Reader_User_Authorization_Table.Close();
  92. SqlCommand User_Table = new SqlCommand(User, sqlConnection);
  93. SqlDataReader Reader_User_Table = User_Table.ExecuteReader();
  94. using (SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQL"].ConnectionString))
  95. {
  96. while (Reader_User_Table.Read())
  97. {
  98. if (email == Convert.ToString(Reader_User_Table.GetValue(3)))
  99. {
  100. return 3; // Пользователь с таким адрессом электронной почты уже существует
  101. }
  102. }
  103. }
  104. Reader_User_Table.Close();
  105. using (SqlCommand command = new SqlCommand(Query_User_Authorization, sqlConnection))
  106. {
  107. command.Parameters.AddWithValue("@Nickname", nickname);
  108. command.Parameters.AddWithValue("@PASSWORD", password);
  109. Console.WriteLine(command.ExecuteNonQuery());
  110. }
  111. using (SqlCommand command = new SqlCommand(Query_User, sqlConnection))
  112. {
  113. command.Parameters.AddWithValue("@Name", name);
  114. command.Parameters.AddWithValue("@Surname", surname);
  115. command.Parameters.AddWithValue("@EMAIL", email);
  116. Console.WriteLine(command.ExecuteNonQuery());
  117. }
  118. sqlConnection.Close();
  119. return 0; // Вы успешно зарегестрировались
  120. }
  121. else
  122. {
  123. return 4; // Имя не должно начинаться с пробелал, заканчиваться на пробел, иметь 2 пробела в тексте
  124. }
  125. }
  126. public void New_configuration(string Nickname, string Graphics_card_name, string CPUName, int RAM, string nameConfig)// Создание новой конфигурации
  127. {
  128. sqlConnection.Open();
  129. int IDUser = 0;
  130. string videoСardQuery = "Select * from VideoCard";
  131. int IDvideoCard = 0;
  132. int IDCPU = 0;
  133. string CPUQuery = "Select * from CPU";
  134. string UserQuery = "Select * from User_Authorization";
  135. string fillingoutTheConfiguration;
  136. SqlCommand User_Authorization = new SqlCommand(UserQuery, sqlConnection);
  137. SqlDataReader ReaderUserAuthorizationTable = User_Authorization.ExecuteReader();
  138. using (SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQL"].ConnectionString))
  139. {
  140. while (ReaderUserAuthorizationTable.Read())
  141. {
  142. if (Nickname == Convert.ToString(ReaderUserAuthorizationTable.GetValue(1)))
  143. {
  144. IDUser = Convert.ToInt32(ReaderUserAuthorizationTable.GetValue(0));
  145. break;
  146. }
  147. }
  148. }
  149. ReaderUserAuthorizationTable.Close();
  150. SqlCommand videoСardIDTable = new SqlCommand(videoСardQuery, sqlConnection);
  151. SqlDataReader Reader_User_Authorization_Table = videoСardIDTable.ExecuteReader();
  152. using (SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQL"].ConnectionString))
  153. {
  154. while (Reader_User_Authorization_Table.Read())
  155. {
  156. if (Graphics_card_name == Convert.ToString(Reader_User_Authorization_Table.GetValue(2)))
  157. {
  158. IDvideoCard = Convert.ToInt32(Reader_User_Authorization_Table.GetValue(0));
  159. Console.WriteLine(IDvideoCard);
  160. }
  161. }
  162. }
  163. Reader_User_Authorization_Table.Close();
  164. SqlCommand CPUTable = new SqlCommand(CPUQuery, sqlConnection);
  165. SqlDataReader readerCPUTable = CPUTable.ExecuteReader();
  166. using (SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQL"].ConnectionString))
  167. {
  168. while (readerCPUTable.Read())
  169. {
  170. if (CPUName == Convert.ToString(readerCPUTable.GetValue(2)))
  171. {
  172. IDCPU = Convert.ToInt32(readerCPUTable.GetValue(0));
  173. Console.WriteLine(IDCPU);
  174. }
  175. }
  176. }
  177. readerCPUTable.Close();
  178. fillingoutTheConfiguration = $"insert into Configuration ([name],ID_User,ID_VideoCard,ID_CPU, RAM) VALUES ('{nameConfig}','{IDUser}','{IDvideoCard}',{IDCPU},{RAM})";
  179. using (SqlCommand command = new SqlCommand(fillingoutTheConfiguration, sqlConnection))
  180. {
  181. Console.WriteLine(command.ExecuteNonQuery());
  182. }
  183. sqlConnection.Close();
  184. }
  185. public List<string> UserInformation(string Nickname)//Информация о пользователе
  186. {
  187. sqlConnection.Open();
  188. List<string> userInfo = new List<string>();
  189. string UserAuthorizationQuery = "Select * from User_Authorization";
  190. string UserQuery = "Select * from [User]";
  191. int UserID = 0;
  192. SqlCommand UserAuthorizationTable = new SqlCommand(UserAuthorizationQuery, sqlConnection);
  193. SqlDataReader readerUserAuthorizationTable = UserAuthorizationTable.ExecuteReader();
  194. using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQL"].ConnectionString))
  195. {
  196. while (readerUserAuthorizationTable.Read())
  197. {
  198. if (Nickname == Convert.ToString(readerUserAuthorizationTable.GetValue(1)))
  199. {
  200. UserID = Convert.ToInt32(readerUserAuthorizationTable.GetValue(0));
  201. break;
  202. }
  203. }
  204. }
  205. readerUserAuthorizationTable.Close();
  206. SqlCommand UserTable = new SqlCommand(UserQuery, sqlConnection);
  207. SqlDataReader readerUserTable = UserTable.ExecuteReader();
  208. using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQL"].ConnectionString))
  209. {
  210. while (readerUserTable.Read())
  211. {
  212. if (UserID == Convert.ToInt32(readerUserTable.GetValue(0)))
  213. {
  214. userInfo.Add(Convert.ToString(readerUserTable.GetValue(1)));
  215. Console.WriteLine(userInfo[0]);
  216. userInfo.Add(Convert.ToString(readerUserTable.GetValue(2)));
  217. Console.WriteLine(userInfo[1]);
  218. userInfo.Add(Convert.ToString(readerUserTable.GetValue(3)));
  219. Console.WriteLine(userInfo[2]);
  220. }
  221. }
  222. sqlConnection.Close();
  223. return userInfo;
  224. }
  225. }
  226. public List<string> CPUGPUList(string InfoReturn)//список видеокард и процессоров
  227. {
  228. sqlConnection.Open();
  229. List<string> userInfo = new List<string>();
  230. string GPUQuery = "select [Name] from VideoCard";
  231. string CPUQuery = "select [Name] from CPU";
  232. if (InfoReturn == "GPU")
  233. {
  234. SqlCommand GPUTable = new SqlCommand(GPUQuery, sqlConnection);
  235. SqlDataReader sqlDataReader = GPUTable.ExecuteReader();
  236. using (SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQL"].ConnectionString))
  237. {
  238. for (int i = 0; sqlDataReader.Read(); i++)
  239. {
  240. userInfo.Add(Convert.ToString(sqlDataReader.GetValue(0)));
  241. }
  242. }
  243. sqlDataReader.Close();
  244. }
  245. if (InfoReturn == "CPU")
  246. {
  247. SqlCommand CPUTable = new SqlCommand(CPUQuery, sqlConnection);
  248. SqlDataReader sqlDataReader = CPUTable.ExecuteReader();
  249. using (SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQL"].ConnectionString))
  250. {
  251. for (int i = 0; sqlDataReader.Read(); i++)
  252. {
  253. userInfo.Add(Convert.ToString(sqlDataReader.GetValue(0)));
  254. Console.WriteLine(userInfo);
  255. }
  256. }
  257. sqlDataReader.Close();
  258. }
  259. sqlConnection.Close();
  260. return userInfo;
  261. }
  262. public List<string> ListOfConfigurations(string Nickname)// список конфигурация пользователя
  263. {
  264. sqlConnection.Open();
  265. List<string> list = new List<string>();
  266. int IDUser = 0;
  267. string UserAuthorizationQuery = "Select * from User_Authorization";
  268. SqlCommand UserAuthorizationTable = new SqlCommand(UserAuthorizationQuery, sqlConnection);
  269. SqlDataReader ReaderUserAuthorizationTable = UserAuthorizationTable.ExecuteReader();
  270. using (SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQL"].ConnectionString))
  271. {
  272. while (ReaderUserAuthorizationTable.Read())
  273. {
  274. if (Nickname == Convert.ToString(ReaderUserAuthorizationTable.GetValue(1)))
  275. {
  276. IDUser = Convert.ToInt32(ReaderUserAuthorizationTable.GetValue(0));
  277. break;
  278. }
  279. }
  280. }
  281. ReaderUserAuthorizationTable.Close();
  282. string ConfigurationQuery = "Select [name],ID_User from Configuration ";
  283. SqlCommand ConfigurationTable = new SqlCommand(ConfigurationQuery, sqlConnection);
  284. SqlDataReader sqlDataReader = ConfigurationTable.ExecuteReader();
  285. using (SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQL"].ConnectionString))
  286. {
  287. while (sqlDataReader.Read())
  288. {
  289. if (Convert.ToInt32(sqlDataReader.GetValue(1)) == IDUser)
  290. {
  291. list.Add(Convert.ToString(sqlDataReader.GetValue(0)));
  292. }
  293. }
  294. }
  295. sqlDataReader.Close();
  296. sqlConnection.Close();
  297. return list;
  298. }
  299. public List<string> PartsList(string NameConfiguration)// информация о конфигурации
  300. {
  301. sqlConnection.Open();
  302. int IDGPU = 0;
  303. int IDCPU = 0;
  304. int RAM = 0;
  305. List<string> PartsList = new List<string>();
  306. string ConfigurationQuery = "Select [name],ID_VideoCard,ID_CPU,RAM from Configuration ";
  307. string GPUQuery = "Select ID_VideoCard, [Name] from VideoCard";
  308. string CPUQuery = "Select ID_CPU, [Name] from CPU";
  309. SqlCommand ConfigurationTable = new SqlCommand(ConfigurationQuery, sqlConnection);
  310. SqlDataReader sqlDataReader = ConfigurationTable.ExecuteReader();
  311. using (SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQL"].ConnectionString))
  312. {
  313. for (int i = 0; sqlDataReader.Read(); i++)
  314. {
  315. if (Convert.ToString(sqlDataReader.GetValue(0)) == NameConfiguration)
  316. {
  317. IDGPU = Convert.ToInt32(sqlDataReader.GetValue(1));
  318. IDCPU = Convert.ToInt32(sqlDataReader.GetValue(2));
  319. RAM = Convert.ToInt32(sqlDataReader.GetValue(3));
  320. }
  321. }
  322. }
  323. sqlDataReader.Close();
  324. SqlCommand GPUTable = new SqlCommand(GPUQuery, sqlConnection);
  325. SqlDataReader GPUReader = GPUTable.ExecuteReader();
  326. using (SqlConnection sqlConnection1 = new SqlConnection(ConfigurationManager.ConnectionStrings["SQL"].ConnectionString))
  327. {
  328. while (GPUReader.Read())
  329. {
  330. if (IDGPU == Convert.ToInt32(GPUReader.GetValue(0)))
  331. {
  332. PartsList.Add(Convert.ToString(GPUReader.GetValue(1)));
  333. }
  334. }
  335. }
  336. GPUReader.Close();
  337. SqlCommand CPUTable = new SqlCommand(CPUQuery, sqlConnection);
  338. SqlDataReader CPUReader = CPUTable.ExecuteReader();
  339. using (SqlConnection sqlConnection1 = new SqlConnection(ConfigurationManager.ConnectionStrings["SQL"].ConnectionString))
  340. {
  341. while (CPUReader.Read())
  342. {
  343. if (IDCPU == Convert.ToInt32(CPUReader.GetValue(0)))
  344. {
  345. PartsList.Add(Convert.ToString(CPUReader.GetValue(1)));
  346. PartsList.Add(Convert.ToString(RAM));
  347. }
  348. }
  349. }
  350. CPUReader.Close();
  351. sqlConnection.Close();
  352. return PartsList;
  353. }
  354. public string CompatibilityCheck(string NameConfigurathoin, string NameProgramm)// проверка совместимости(демо)
  355. {
  356. sqlConnection.Open();
  357. int[] minimumRequirements = new int[3];
  358. int[] RecRequirements = new int[3];
  359. int[] сomponentСonfigurations = new int[3];
  360. List<string> PartsList = new List<string>();
  361. string minimumRequirementsQuery = $"SELECT VideoCard.ID_VideoCard,CPU.ID_CPU,Minimum_Requirements.RAM FROM [Application] JOIN Minimum_Requirements ON Minimum_Requirements.ID_MIN=[Application].ID_REC JOIN VideoCard ON Minimum_Requirements.ID_VideoCard=VideoCard.ID_VideoCard JOIN CPU ON Minimum_Requirements.ID_CPU=CPU.ID_CPU WHERE [Application].Title='{NameProgramm}';";
  362. string RecomendedRequiremetsQuery = $"SELECT VideoCard.ID_VideoCard,CPU.ID_CPU,Recommended_Requirements.RAM FROM [Application] JOIN Recommended_Requirements ON Recommended_Requirements.ID_REC=[Application].ID_REC JOIN VideoCard ON Recommended_Requirements.ID_VideoCard=VideoCard.ID_VideoCard JOIN CPU ON Recommended_Requirements.ID_CPU=CPU.ID_CPU WHERE [Application].Title='{NameProgramm}';";
  363. string сomponentСonfigurationsQuery = $"select ID_VideoCard,ID_CPU,RAM from [Configuration] where [name] = '{NameConfigurathoin}'";
  364. SqlCommand MinimumRequirementsTable = new SqlCommand(minimumRequirementsQuery, sqlConnection);
  365. SqlDataReader MinimumRequirementsReader = MinimumRequirementsTable.ExecuteReader();
  366. using (SqlConnection sqlConnection1 = new SqlConnection(ConfigurationManager.ConnectionStrings["SQL"].ConnectionString))
  367. {
  368. while (MinimumRequirementsReader.Read())
  369. {
  370. minimumRequirements[0] = Convert.ToInt32(MinimumRequirementsReader.GetValue(0));
  371. minimumRequirements[1] = Convert.ToInt32(MinimumRequirementsReader.GetValue(1));
  372. minimumRequirements[2] = Convert.ToInt32(MinimumRequirementsReader.GetValue(2));
  373. }
  374. }
  375. MinimumRequirementsReader.Close();
  376. SqlCommand RecRequirementsTable = new SqlCommand(RecomendedRequiremetsQuery, sqlConnection);
  377. SqlDataReader RecRequirementsTableReader = RecRequirementsTable.ExecuteReader();
  378. using (SqlConnection sqlConnection1 = new SqlConnection(ConfigurationManager.ConnectionStrings["SQL"].ConnectionString))
  379. {
  380. while (RecRequirementsTableReader.Read())
  381. {
  382. RecRequirements[0] = Convert.ToInt32(RecRequirementsTableReader.GetValue(0));
  383. RecRequirements[1] = Convert.ToInt32(RecRequirementsTableReader.GetValue(1));
  384. RecRequirements[2] = Convert.ToInt32(RecRequirementsTableReader.GetValue(2));
  385. }
  386. }
  387. RecRequirementsTableReader.Close();
  388. SqlCommand сomponentСonfigurationsTable = new SqlCommand(сomponentСonfigurationsQuery, sqlConnection);
  389. SqlDataReader сomponentСonfigurationsTableReader = сomponentСonfigurationsTable.ExecuteReader();
  390. using (SqlConnection sqlConnection1 = new SqlConnection(ConfigurationManager.ConnectionStrings["SQL"].ConnectionString))
  391. {
  392. while (сomponentСonfigurationsTableReader.Read())
  393. {
  394. сomponentСonfigurations[0] = Convert.ToInt32(сomponentСonfigurationsTableReader.GetValue(0));
  395. сomponentСonfigurations[1] = Convert.ToInt32(сomponentСonfigurationsTableReader.GetValue(1));
  396. сomponentСonfigurations[2] = Convert.ToInt32(сomponentСonfigurationsTableReader.GetValue(2));
  397. }
  398. }
  399. сomponentСonfigurationsTableReader.Close();
  400. if ((сomponentСonfigurations[0] <= RecRequirements[0]) && (сomponentСonfigurations[1] <= RecRequirements[1]) && (сomponentСonfigurations[2] >= RecRequirements[2]))
  401. {
  402. sqlConnection.Close();
  403. return "Ваша конфигурация подходит для рекомендованных требований";
  404. }
  405. else if ((сomponentСonfigurations[0] <= minimumRequirements[0]) && (сomponentСonfigurations[1] <= minimumRequirements[1]) && (сomponentСonfigurations[2] >= minimumRequirements[2]))
  406. {
  407. sqlConnection.Close();
  408. return "Ваша конфигурация подходит для минимальных требований";
  409. }
  410. else
  411. {
  412. sqlConnection.Close();
  413. return gaga(NameConfigurathoin, NameProgramm);
  414. }
  415. }
  416. public string gaga(string NameConfigurathoin, string NameProgramm)// пока демо
  417. {
  418. sqlConnection.Open();
  419. int[] minimumRequirements = new int[3];
  420. int[] RecRequirements = new int[3];
  421. int[] сomponentСonfigurations = new int[3];
  422. string[] minimumRequirementsString = new string[3];
  423. string[] RecRequirementsString = new string[3];
  424. string returninfo;
  425. List<string> info = new List<string>();
  426. string minimumRequirementsQuery = $"SELECT VideoCard.ID_VideoCard,CPU.ID_CPU,Minimum_Requirements.RAM FROM [Application] JOIN Minimum_Requirements ON Minimum_Requirements.ID_MIN=[Application].ID_REC JOIN VideoCard ON Minimum_Requirements.ID_VideoCard=VideoCard.ID_VideoCard JOIN CPU ON Minimum_Requirements.ID_CPU=CPU.ID_CPU WHERE [Application].Title='{NameProgramm}';";
  427. string RecomendedRequiremetsQuery = $"SELECT VideoCard.ID_VideoCard,CPU.ID_CPU,Recommended_Requirements.RAM FROM [Application] JOIN Recommended_Requirements ON Recommended_Requirements.ID_REC=[Application].ID_REC JOIN VideoCard ON Recommended_Requirements.ID_VideoCard=VideoCard.ID_VideoCard JOIN CPU ON Recommended_Requirements.ID_CPU=CPU.ID_CPU WHERE [Application].Title='{NameProgramm}';";
  428. string сomponentСonfigurationsQuery = $"select ID_VideoCard,ID_CPU,RAM from [Configuration] where [name] = '{NameConfigurathoin}'";
  429. string minimumRequirementsQuerystring = $"SELECT VideoCard.[Name],CPU.[Name],Minimum_Requirements.RAM FROM [Application] JOIN Minimum_Requirements ON Minimum_Requirements.ID_MIN=[Application].ID_MIN JOIN VideoCard ON Minimum_Requirements.ID_VideoCard=VideoCard.ID_VideoCard JOIN CPU ON Minimum_Requirements.ID_CPU=CPU.ID_CPU WHERE [Application].Title='{NameProgramm}';";
  430. string RecomendedRequiremetsQuerystring = $"SELECT VideoCard.[Name],CPU.[Name],Recommended_Requirements.RAM FROM [Application] JOIN Recommended_Requirements ON Recommended_Requirements.ID_REC=[Application].ID_REC JOIN VideoCard ON Recommended_Requirements.ID_VideoCard=VideoCard.ID_VideoCard JOIN CPU ON Recommended_Requirements.ID_CPU=CPU.ID_CPU WHERE [Application].Title='{NameProgramm}'";
  431. SqlCommand MinimumRequirementsTable = new SqlCommand(minimumRequirementsQuery, sqlConnection);
  432. SqlDataReader MinimumRequirementsReader = MinimumRequirementsTable.ExecuteReader();
  433. using (SqlConnection sqlConnection1 = new SqlConnection(ConfigurationManager.ConnectionStrings["SQL"].ConnectionString))
  434. {
  435. while (MinimumRequirementsReader.Read())
  436. {
  437. minimumRequirements[0] = Convert.ToInt32(MinimumRequirementsReader.GetValue(0));
  438. minimumRequirements[1] = Convert.ToInt32(MinimumRequirementsReader.GetValue(1));
  439. minimumRequirements[2] = Convert.ToInt32(MinimumRequirementsReader.GetValue(2));
  440. }
  441. }
  442. MinimumRequirementsReader.Close();
  443. SqlCommand RecRequirementsTable = new SqlCommand(RecomendedRequiremetsQuery, sqlConnection);
  444. SqlDataReader RecRequirementsTableReader = RecRequirementsTable.ExecuteReader();
  445. using (SqlConnection sqlConnection1 = new SqlConnection(ConfigurationManager.ConnectionStrings["SQL"].ConnectionString))
  446. {
  447. while (RecRequirementsTableReader.Read())
  448. {
  449. RecRequirements[0] = Convert.ToInt32(RecRequirementsTableReader.GetValue(0));
  450. RecRequirements[1] = Convert.ToInt32(RecRequirementsTableReader.GetValue(1));
  451. RecRequirements[2] = Convert.ToInt32(RecRequirementsTableReader.GetValue(2));
  452. }
  453. }
  454. RecRequirementsTableReader.Close();
  455. SqlCommand сomponentСonfigurationsTable = new SqlCommand(сomponentСonfigurationsQuery, sqlConnection);
  456. SqlDataReader сomponentСonfigurationsTableReader = сomponentСonfigurationsTable.ExecuteReader();
  457. using (SqlConnection sqlConnection1 = new SqlConnection(ConfigurationManager.ConnectionStrings["SQL"].ConnectionString))
  458. {
  459. while (сomponentСonfigurationsTableReader.Read())
  460. {
  461. сomponentСonfigurations[0] = Convert.ToInt32(сomponentСonfigurationsTableReader.GetValue(0));
  462. сomponentСonfigurations[1] = Convert.ToInt32(сomponentСonfigurationsTableReader.GetValue(1));
  463. сomponentСonfigurations[2] = Convert.ToInt32(сomponentСonfigurationsTableReader.GetValue(2));
  464. }
  465. }
  466. сomponentСonfigurationsTableReader.Close();
  467. SqlCommand minimumRequirementsStringTable = new SqlCommand(minimumRequirementsQuerystring, sqlConnection);
  468. SqlDataReader minimumRequirementsStringTableReader = minimumRequirementsStringTable.ExecuteReader();
  469. using (SqlConnection sqlConnection1 = new SqlConnection(ConfigurationManager.ConnectionStrings["SQL"].ConnectionString))
  470. {
  471. while (minimumRequirementsStringTableReader.Read())
  472. {
  473. minimumRequirementsString[0] = Convert.ToString(minimumRequirementsStringTableReader.GetValue(0));
  474. minimumRequirementsString[1] = Convert.ToString(minimumRequirementsStringTableReader.GetValue(1));
  475. minimumRequirementsString[2] = Convert.ToString(minimumRequirementsStringTableReader.GetValue(2));
  476. }
  477. }
  478. minimumRequirementsStringTableReader.Close();
  479. SqlCommand RecRequirementsStringTable = new SqlCommand(RecomendedRequiremetsQuerystring, sqlConnection);
  480. SqlDataReader RecRequirementsStringTableReader = RecRequirementsStringTable.ExecuteReader();
  481. using (SqlConnection sqlConnection1 = new SqlConnection(ConfigurationManager.ConnectionStrings["SQL"].ConnectionString))
  482. {
  483. while (RecRequirementsStringTableReader.Read())
  484. {
  485. RecRequirementsString[0] = Convert.ToString(RecRequirementsStringTableReader.GetValue(0));
  486. RecRequirementsString[1] = Convert.ToString(RecRequirementsStringTableReader.GetValue(1));
  487. RecRequirementsString[2] = Convert.ToString(RecRequirementsStringTableReader.GetValue(2));
  488. }
  489. }
  490. RecRequirementsStringTableReader.Close();
  491. if (сomponentСonfigurations[2] > minimumRequirements[2])
  492. {
  493. returninfo = $"Для игры на минимальных настройках вам понадобиться Видеокарта - {minimumRequirementsString[0]}, процессор - {minimumRequirementsString[1]}\n";
  494. }
  495. else
  496. {
  497. returninfo = $"Для игры на минимальных настройках вам понадобиться Видеокарта - {minimumRequirementsString[0]}, процессор - {minimumRequirementsString[1]}, и добавить {minimumRequirements[2] - сomponentСonfigurations[2]}Гб оперативной памяти\n";
  498. }
  499. if (сomponentСonfigurations[2] > RecRequirements[2])
  500. {
  501. returninfo +=$"Для игры на рекомендованных настройках вам понадобиться Видеокарта - {RecRequirementsString[0]}, процессор - {RecRequirementsString[1]}\n";
  502. }
  503. else
  504. {
  505. returninfo += $"Для игры на рекомендованных настройках вам понадобиться Видеокарта - {RecRequirementsString[0]}, процессор - {RecRequirementsString[1]}, и добавить {RecRequirements[2] - сomponentСonfigurations[2]}Гб оперативной памяти\n";
  506. }
  507. return returninfo;
  508. }
  509. public List<string> Listofprograms() // список приложений
  510. {
  511. sqlConnection.Open();
  512. string ListofprogramsQuery = "select Title from Application";
  513. List<string> Listofprograms = new List<string>();
  514. SqlCommand ListofprogramsTable = new SqlCommand(ListofprogramsQuery, sqlConnection);
  515. SqlDataReader ListofprogramsReader = ListofprogramsTable.ExecuteReader();
  516. using (SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQL"].ConnectionString))
  517. {
  518. while (ListofprogramsReader.Read())
  519. {
  520. Listofprograms.Add(Convert.ToString(ListofprogramsReader.GetValue(0)));
  521. }
  522. }
  523. ListofprogramsReader.Close();
  524. sqlConnection.Close();
  525. return Listofprograms;
  526. }
  527. public string UserEditing(string Name, string Surname, string Email, string FormerNickname, string Nickname)// смена контактных данных
  528. {
  529. sqlConnection.Open();
  530. string userAuthorizationQuery = $" update User_Authorization set [Nickname] = '{FormerNickname}' where User_Authorization.ID_User = (select ID_User from User_Authorization where Nickname = '{Nickname}')";
  531. string userQuery = $" update[User] set[Name] = '{Name}',Surname = '{Surname}',EMAIL = '{Email}' where[User].ID_User = (select ID_User from User_Authorization where Nickname = '{Nickname}')";
  532. Regex regexEmail = new Regex(@"^[_a-zA-Z0-9-\+-]+(\.[_a-zA_Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,})$");
  533. string authenticationrequest = "SELECT * from User_Authorization";
  534. SqlCommand command = new SqlCommand(authenticationrequest, sqlConnection);
  535. SqlDataReader reader = command.ExecuteReader();
  536. using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQL"].ConnectionString))
  537. {
  538. if (reader.HasRows)
  539. {
  540. while (reader.Read())
  541. {
  542. if (FormerNickname == Convert.ToString(reader.GetValue(1)))
  543. {
  544. return "Такой никнейм уже существует";
  545. }
  546. }
  547. }
  548. }
  549. reader.Close();
  550. if (Nickname == FormerNickname)
  551. {
  552. return "Ваш новый никнейм совпадает с предыдущим";
  553. }
  554. if (regexEmail.IsMatch(Email) == false)
  555. {
  556. return "Почта имеет неправильный формат";
  557. }
  558. SqlCommand UserСhanges = new SqlCommand(userQuery, sqlConnection);
  559. SqlDataReader dataReader = UserСhanges.ExecuteReader();
  560. using (SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQL"].ConnectionString))
  561. {
  562. dataReader.Dispose();
  563. UserСhanges.ExecuteNonQuery();
  564. }
  565. dataReader.Close();
  566. SqlCommand userAuthorizationChanges = new SqlCommand(userAuthorizationQuery, sqlConnection);
  567. SqlDataReader sqlData = userAuthorizationChanges.ExecuteReader();
  568. using (SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQL"].ConnectionString))
  569. {
  570. sqlData.Dispose();
  571. userAuthorizationChanges.ExecuteNonQuery();
  572. }
  573. sqlData.Close();
  574. sqlConnection.Close();
  575. return "Профиль успешно обновлен";
  576. }
  577. public string UserEditing(string Nickname, string previousPassword, string NewPassword, string newPasswordRepeat)
  578. {
  579. sqlConnection.Open();
  580. string userPasswordUpdate = $"update User_Authorization set [PASSWORD] = '{NewPassword}' where User_Authorization.ID_User = (select ID_User from User_Authorization where Nickname = '{Nickname}')";
  581. string userPasswordOldQuery = $"select PASSWORD from User_Authorization where Nickname ='{Nickname}'";
  582. Regex regexPassword = new Regex(@"([0-9,a-z,A-Z,~,!,@,#,$,%,^,&,*,(,),_]){6,}$");
  583. string oldPassword = "s";
  584. if (regexPassword.IsMatch(NewPassword) == false)
  585. {
  586. return "Пароль не соответствует требованиям";
  587. }
  588. SqlCommand userPasswordOldTable = new SqlCommand(userPasswordOldQuery, sqlConnection);
  589. SqlDataReader userPasswordOldTableReader = userPasswordOldTable.ExecuteReader();
  590. using (SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQL"].ConnectionString))
  591. {
  592. while (userPasswordOldTableReader.Read())
  593. {
  594. oldPassword = Convert.ToString(userPasswordOldTableReader.GetValue(0));
  595. }
  596. }
  597. userPasswordOldTableReader.Close();
  598. if (previousPassword != oldPassword)
  599. {
  600. return "Неверный пароль";
  601. }
  602. if (NewPassword != newPasswordRepeat)
  603. {
  604. return "Введенные пароли не совпадают";
  605. }
  606. if(NewPassword == previousPassword)
  607. {
  608. return "Новый пароль совпадает с предыдущим";
  609. }
  610. SqlCommand userPasswordUpdateTable = new SqlCommand(userPasswordUpdate, sqlConnection);
  611. SqlDataReader userPasswordUpdateTableReader = userPasswordUpdateTable.ExecuteReader();
  612. using (SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQL"].ConnectionString))
  613. {
  614. userPasswordUpdateTableReader.Dispose();
  615. userPasswordUpdateTable.ExecuteNonQuery();
  616. }
  617. userPasswordUpdateTableReader.Close();
  618. sqlConnection.Close();
  619. return "Пароль успешно изменен";
  620. }
  621. }
  622. }