Advertisement
Guest User

Untitled

a guest
Jan 9th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.54 KB | None | 0 0
  1. using MySql.Data.MySqlClient;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11.  
  12. namespace SAQ
  13. {
  14. public partial class ResultsForm : Form
  15. {
  16. public ResultsForm(string username, int awardedPoints, string bottleName)
  17. {
  18. InitializeComponent();
  19. lblUsername.Text = username;
  20. InvLblMultiplier.Text = awardedPoints.ToString();
  21. lblBottleName.Text = bottleName;
  22. }
  23.  
  24. private void ResultsForm_Load(object sender, EventArgs e)
  25. {
  26. //------------------------------------------------------------------------------------- Loading player previous stats
  27. int Multiplier = Int32.Parse(InvLblMultiplier.Text);
  28. double previousElo = 0;
  29. double newElo = 0;
  30. int success_count = 0;
  31. int failure_count = 0;
  32. int half_success_count = 0;
  33.  
  34. try
  35. {
  36. string MyConnection2 = "datasource=192.168.0.193;port=3306;username=haidson;password=password";
  37. string Query = "SELECT * FROM saq.users WHERE username='" + lblUsername.Text + "';";
  38. MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
  39. MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
  40. MySqlDataReader MyReader2;
  41. MyConn2.Open();
  42. MyReader2 = MyCommand2.ExecuteReader();
  43. while (MyReader2.Read())
  44. {
  45. lblPreviousELO.Text = MyReader2["elo"] + "";
  46. previousElo = Int32.Parse(MyReader2["elo"] + "");
  47. success_count = Int32.Parse(MyReader2["success_count"] + "");
  48. failure_count = Int32.Parse(MyReader2["failure_count"] + "");
  49. half_success_count = Int32.Parse(MyReader2["half_success_count"] + "");
  50.  
  51. }
  52. MyConn2.Close();
  53. }
  54. catch (Exception ex)
  55. {
  56. MessageBox.Show(ex.Message);
  57. }
  58.  
  59. //-------------------------------------------------------------------------------------
  60. double bottlePreviousElo = 0;
  61. double bottleNewElo = 0;
  62. int bottleSuccessCount = 0;
  63. int bottleFailureCount = 0;
  64. try
  65. {
  66. string MyConnection2 = "datasource=192.168.0.193;port=3306;username=haidson;password=password";
  67. string Query = "SELECT * FROM saq.vins WHERE nom='" + lblBottleName.Text + "';";
  68. MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
  69. MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
  70. MySqlDataReader MyReader2;
  71. MyConn2.Open();
  72. MyReader2 = MyCommand2.ExecuteReader();
  73. while (MyReader2.Read())
  74. {
  75. bottlePreviousElo = Int32.Parse(MyReader2["wine_elo"] + "");
  76. bottleSuccessCount = Int32.Parse(MyReader2["success_count"] + "");
  77. bottleFailureCount = Int32.Parse(MyReader2["failure_count"] + "");
  78.  
  79. }
  80. MyConn2.Close();
  81. }
  82. catch (Exception ex)
  83. {
  84. MessageBox.Show(ex.Message);
  85. }
  86.  
  87.  
  88.  
  89. //-------------------------------------------------------------------------------------
  90.  
  91. if (success_count + failure_count < 10) { //User is still in placement games
  92. lblPreviousELO.Text = "In placements";
  93. lblNewELO.Text = "In placements";
  94. }
  95.  
  96. if (Multiplier == 2)
  97. {
  98. try
  99. {
  100. string MyConnection2 = "datasource=192.168.0.193;port=3306;username=haidson;password=password";
  101. string Query = "UPDATE saq.users SET success_count= success_count + 1 WHERE username='" + lblUsername.Text + "';";
  102. MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
  103. MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
  104. MySqlDataReader MyReader2;
  105. MyConn2.Open();
  106. MyReader2 = MyCommand2.ExecuteReader();
  107. while (MyReader2.Read())
  108. {
  109. }
  110. MyConn2.Close();
  111. }
  112. catch (Exception ex)
  113. {
  114. MessageBox.Show(ex.Message);
  115. }
  116.  
  117. //-------------------------------------------------------------------------------------
  118.  
  119. try
  120. {
  121. string MyConnection2 = "datasource=192.168.0.193;port=3306;username=haidson;password=password";
  122. string Query = "UPDATE saq.vins SET failure_count= failure_count + 1 WHERE nom='" + lblBottleName.Text + "';";
  123. MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
  124. MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
  125. MySqlDataReader MyReader2;
  126. MyConn2.Open();
  127. MyReader2 = MyCommand2.ExecuteReader();
  128. while (MyReader2.Read())
  129. {
  130. }
  131. MyConn2.Close();
  132. }
  133. catch (Exception ex)
  134. {
  135. MessageBox.Show(ex.Message);
  136. }
  137. }
  138.  
  139. else if (Multiplier == 1)
  140. {
  141. try
  142. {
  143. string MyConnection2 = "datasource=192.168.0.193;port=3306;username=haidson;password=password";
  144. string Query = "UPDATE saq.users SET half_success_count= half_success_count + 1 WHERE username='" + lblUsername.Text + "';";
  145. MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
  146. MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
  147. MySqlDataReader MyReader2;
  148. MyConn2.Open();
  149. MyReader2 = MyCommand2.ExecuteReader();
  150. while (MyReader2.Read())
  151. {
  152. }
  153. MyConn2.Close();
  154. }
  155. catch (Exception ex)
  156. {
  157. MessageBox.Show(ex.Message);
  158. }
  159.  
  160. //-------------------------------------------------------------------------------------
  161.  
  162. try
  163. {
  164. string MyConnection2 = "datasource=192.168.0.193;port=3306;username=haidson;password=password";
  165. string Query = "UPDATE saq.vins SET failure_count= failure_count + 1 WHERE nom='" + lblBottleName.Text + "';";
  166. MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
  167. MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
  168. MySqlDataReader MyReader2;
  169. MyConn2.Open();
  170. MyReader2 = MyCommand2.ExecuteReader();
  171. while (MyReader2.Read())
  172. {
  173. }
  174. MyConn2.Close();
  175. }
  176. catch (Exception ex)
  177. {
  178. MessageBox.Show(ex.Message);
  179. }
  180. }
  181.  
  182. else if (Multiplier == 0)
  183. {
  184. try
  185. {
  186. string MyConnection2 = "datasource=192.168.0.193;port=3306;username=haidson;password=password";
  187. string Query = "UPDATE saq.users SET failure_count= failure_count + 1 WHERE username='" + lblUsername.Text + "';";
  188. MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
  189. MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
  190. MySqlDataReader MyReader2;
  191. MyConn2.Open();
  192. MyReader2 = MyCommand2.ExecuteReader();
  193. while (MyReader2.Read())
  194. {
  195. }
  196. MyConn2.Close();
  197. }
  198. catch (Exception ex)
  199. {
  200. MessageBox.Show(ex.Message);
  201. }
  202.  
  203. //-------------------------------------------------------------------------------------
  204.  
  205. try
  206. {
  207. string MyConnection2 = "datasource=192.168.0.193;port=3306;username=haidson;password=password";
  208. string Query = "UPDATE saq.vins SET success_count= success_count + 1 WHERE nom='" + lblBottleName.Text + "';";
  209. MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
  210. MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
  211. MySqlDataReader MyReader2;
  212. MyConn2.Open();
  213. MyReader2 = MyCommand2.ExecuteReader();
  214. while (MyReader2.Read())
  215. {
  216. }
  217. MyConn2.Close();
  218. }
  219. catch (Exception ex)
  220. {
  221. MessageBox.Show(ex.Message);
  222. }
  223. }
  224.  
  225.  
  226. //-------------------------------------------------------------------------------------
  227.  
  228. if (bottleFailureCount + bottleSuccessCount == 10) { //Determine the bottle's starting ELO
  229. bottleNewElo = bottleSuccessCount * 300;
  230. try
  231. {
  232. string MyConnection2 = "datasource=192.168.0.193;port=3306;username=haidson;password=password";
  233. string Query = "UPDATE saq.vins SET wine_elo=" + bottleNewElo + " WHERE nom='" + lblBottleName.Text + "';";
  234. MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
  235. MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
  236. MySqlDataReader MyReader2;
  237. MyConn2.Open();
  238. MyReader2 = MyCommand2.ExecuteReader();
  239. while (MyReader2.Read())
  240. {
  241. }
  242. MyConn2.Close();
  243. }
  244. catch (Exception ex)
  245. {
  246. MessageBox.Show(ex.Message);
  247. }
  248. }
  249.  
  250. if (half_success_count + success_count + failure_count == 10)
  251. { //Determine the user's starting ELO
  252. newElo = (success_count * 300) + (half_success_count * 100);
  253. try
  254. {
  255. string MyConnection2 = "datasource=192.168.0.193;port=3306;username=haidson;password=password";
  256. string Query = "UPDATE saq.users SET elo= " + newElo + " WHERE username='" + lblUsername.Text + "';";
  257. MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
  258. MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
  259. MySqlDataReader MyReader2;
  260. MyConn2.Open();
  261. MyReader2 = MyCommand2.ExecuteReader();
  262. while (MyReader2.Read())
  263. {
  264. }
  265. MyConn2.Close();
  266. }
  267. catch (Exception ex)
  268. {
  269. MessageBox.Show(ex.Message);
  270. }
  271. }
  272.  
  273. if (half_success_count + success_count + failure_count > 10) {
  274. if (bottlePreviousElo == 0 ) { //If the bottle is still under placements
  275. if (bottleSuccessCount < bottleFailureCount)
  276. {
  277. bottlePreviousElo = previousElo + 100;
  278. }
  279. else {
  280. bottlePreviousElo = previousElo - 20;
  281. }
  282. }
  283.  
  284.  
  285.  
  286. double exa = (1 / (1 + Math.Pow(10, ((bottlePreviousElo - previousElo) / 400)))); //Expected outcome victory for user A
  287. if (Multiplier == 2)
  288. {
  289. newElo = previousElo + (25 * (2 - exa));
  290. int intNewElo = Convert.ToInt32(newElo);
  291. try
  292. {
  293. string MyConnection2 = "datasource=192.168.0.193;port=3306;username=haidson;password=password";
  294. string Query = "UPDATE saq.users SET elo= " + intNewElo + " WHERE username='" + lblUsername.Text + "';";
  295. MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
  296. MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
  297. MySqlDataReader MyReader2;
  298. MyConn2.Open();
  299. MyReader2 = MyCommand2.ExecuteReader();
  300. while (MyReader2.Read())
  301. {
  302. }
  303. MyConn2.Close();
  304. }
  305. catch (Exception ex)
  306. {
  307. MessageBox.Show(ex.Message);
  308. }
  309. }
  310. else if (Multiplier == 1)
  311. {
  312. newElo = previousElo + (7 * (2 - exa));
  313. int intNewElo = Convert.ToInt32(newElo);
  314. try
  315. {
  316. string MyConnection2 = "datasource=192.168.0.193;port=3306;username=haidson;password=password";
  317. string Query = "UPDATE saq.users SET elo= " + intNewElo + " WHERE username='" + lblUsername.Text + "';";
  318. MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
  319. MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
  320. MySqlDataReader MyReader2;
  321. MyConn2.Open();
  322. MyReader2 = MyCommand2.ExecuteReader();
  323. while (MyReader2.Read())
  324. {
  325. }
  326. MyConn2.Close();
  327. }
  328. catch (Exception ex)
  329. {
  330. MessageBox.Show(ex.Message);
  331. }
  332. }
  333. else if (Multiplier == 0) {
  334. newElo = previousElo - (25 * (2 - exa));
  335. int intNewElo = Convert.ToInt32(newElo);
  336. try
  337. {
  338. string MyConnection2 = "datasource=192.168.0.193;port=3306;username=haidson;password=password";
  339. string Query = "UPDATE saq.users SET elo= " + intNewElo + " WHERE username='" + lblUsername.Text + "';";
  340. MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
  341. MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
  342. MySqlDataReader MyReader2;
  343. MyConn2.Open();
  344. MyReader2 = MyCommand2.ExecuteReader();
  345. while (MyReader2.Read())
  346. {
  347. }
  348. MyConn2.Close();
  349. }
  350. catch (Exception ex)
  351. {
  352. MessageBox.Show(ex.Message);
  353. }
  354. }
  355. lblNewELO.Text = newElo.ToString();
  356. lblOddsToKnowBottle.Text = (Convert.ToInt32(exa) * 100) + "%";
  357. }
  358.  
  359. if (bottleSuccessCount + bottleFailureCount > 10) {
  360. if (bottlePreviousElo == 0)
  361. { //If the user is still under placements
  362. if (success_count + half_success_count < failure_count)
  363. {
  364. previousElo = bottlePreviousElo + 100;
  365. }
  366. else
  367. {
  368. previousElo = bottlePreviousElo - 20;
  369. }
  370. }
  371.  
  372.  
  373.  
  374.  
  375. double exb = (1 / (1 + Math.Pow(10, ((previousElo - bottlePreviousElo) / 400)))); //Expected outcome victory for the bottle
  376. if (Multiplier == 2)
  377. {
  378. bottleNewElo = bottlePreviousElo - (25 * (2 - exb));
  379. int intbottleNewElo = Convert.ToInt32(bottleNewElo);
  380. try
  381. {
  382. string MyConnection2 = "datasource=192.168.0.193;port=3306;username=haidson;password=password";
  383. string Query = "UPDATE saq.vins SET wine_elo=" + intbottleNewElo + " WHERE nom='" + lblBottleName.Text + "';";
  384. MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
  385. MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
  386. MySqlDataReader MyReader2;
  387. MyConn2.Open();
  388. MyReader2 = MyCommand2.ExecuteReader();
  389. while (MyReader2.Read())
  390. {
  391. }
  392. MyConn2.Close();
  393. }
  394. catch (Exception ex)
  395. {
  396. MessageBox.Show(ex.Message);
  397. }
  398.  
  399. }
  400. else if (Multiplier == 1)
  401. {
  402. bottleNewElo = bottlePreviousElo - (7 * (2 - exb));
  403. int intbottleNewElo = Convert.ToInt32(bottleNewElo);
  404. try
  405. {
  406. string MyConnection2 = "datasource=192.168.0.193;port=3306;username=haidson;password=password";
  407. string Query = "UPDATE saq.vins SET wine_elo=" + intbottleNewElo + " WHERE nom='" + lblBottleName.Text + "';";
  408. MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
  409. MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
  410. MySqlDataReader MyReader2;
  411. MyConn2.Open();
  412. MyReader2 = MyCommand2.ExecuteReader();
  413. while (MyReader2.Read())
  414. {
  415. }
  416. MyConn2.Close();
  417. }
  418. catch (Exception ex)
  419. {
  420. MessageBox.Show(ex.Message);
  421. }
  422. }
  423. else if (Multiplier == 0)
  424. {
  425. bottleNewElo = bottlePreviousElo + (25 * (2 - exb));
  426. int intbottleNewElo = Convert.ToInt32(bottleNewElo);
  427. try
  428. {
  429. string MyConnection2 = "datasource=192.168.0.193;port=3306;username=haidson;password=password";
  430. string Query = "UPDATE saq.vins SET wine_elo=" + intbottleNewElo + " WHERE nom='" + lblBottleName.Text + "';";
  431. MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
  432. MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
  433. MySqlDataReader MyReader2;
  434. MyConn2.Open();
  435. MyReader2 = MyCommand2.ExecuteReader();
  436. while (MyReader2.Read())
  437. {
  438. }
  439. MyConn2.Close();
  440. }
  441. catch (Exception ex)
  442. {
  443. MessageBox.Show(ex.Message);
  444. }
  445. }
  446. }
  447.  
  448. }
  449.  
  450. private void btnNewGame_Click(object sender, EventArgs e)
  451. {
  452. string username = lblUsername.Text;
  453. Form1 m = new Form1(username);
  454. m.Show();
  455. this.Close();
  456. }
  457. }
  458. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement