Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using MySql.Data.MySqlClient;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace SAQ
- {
- public partial class ResultsForm : Form
- {
- public ResultsForm(string username, int awardedPoints, string bottleName)
- {
- InitializeComponent();
- lblUsername.Text = username;
- InvLblMultiplier.Text = awardedPoints.ToString();
- lblBottleName.Text = bottleName;
- }
- private void ResultsForm_Load(object sender, EventArgs e)
- {
- //------------------------------------------------------------------------------------- Loading player previous stats
- int Multiplier = Int32.Parse(InvLblMultiplier.Text);
- double previousElo = 0;
- double newElo = 0;
- int success_count = 0;
- int failure_count = 0;
- int half_success_count = 0;
- try
- {
- string MyConnection2 = "datasource=192.168.0.193;port=3306;username=haidson;password=password";
- string Query = "SELECT * FROM saq.users WHERE username='" + lblUsername.Text + "';";
- MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
- MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
- MySqlDataReader MyReader2;
- MyConn2.Open();
- MyReader2 = MyCommand2.ExecuteReader();
- while (MyReader2.Read())
- {
- lblPreviousELO.Text = MyReader2["elo"] + "";
- previousElo = Int32.Parse(MyReader2["elo"] + "");
- success_count = Int32.Parse(MyReader2["success_count"] + "");
- failure_count = Int32.Parse(MyReader2["failure_count"] + "");
- half_success_count = Int32.Parse(MyReader2["half_success_count"] + "");
- }
- MyConn2.Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- //-------------------------------------------------------------------------------------
- double bottlePreviousElo = 0;
- double bottleNewElo = 0;
- int bottleSuccessCount = 0;
- int bottleFailureCount = 0;
- try
- {
- string MyConnection2 = "datasource=192.168.0.193;port=3306;username=haidson;password=password";
- string Query = "SELECT * FROM saq.vins WHERE nom='" + lblBottleName.Text + "';";
- MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
- MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
- MySqlDataReader MyReader2;
- MyConn2.Open();
- MyReader2 = MyCommand2.ExecuteReader();
- while (MyReader2.Read())
- {
- bottlePreviousElo = Int32.Parse(MyReader2["wine_elo"] + "");
- bottleSuccessCount = Int32.Parse(MyReader2["success_count"] + "");
- bottleFailureCount = Int32.Parse(MyReader2["failure_count"] + "");
- }
- MyConn2.Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- //-------------------------------------------------------------------------------------
- if (success_count + failure_count < 10) { //User is still in placement games
- lblPreviousELO.Text = "In placements";
- lblNewELO.Text = "In placements";
- }
- if (Multiplier == 2)
- {
- try
- {
- string MyConnection2 = "datasource=192.168.0.193;port=3306;username=haidson;password=password";
- string Query = "UPDATE saq.users SET success_count= success_count + 1 WHERE username='" + lblUsername.Text + "';";
- MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
- MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
- MySqlDataReader MyReader2;
- MyConn2.Open();
- MyReader2 = MyCommand2.ExecuteReader();
- while (MyReader2.Read())
- {
- }
- MyConn2.Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- //-------------------------------------------------------------------------------------
- try
- {
- string MyConnection2 = "datasource=192.168.0.193;port=3306;username=haidson;password=password";
- string Query = "UPDATE saq.vins SET failure_count= failure_count + 1 WHERE nom='" + lblBottleName.Text + "';";
- MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
- MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
- MySqlDataReader MyReader2;
- MyConn2.Open();
- MyReader2 = MyCommand2.ExecuteReader();
- while (MyReader2.Read())
- {
- }
- MyConn2.Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- else if (Multiplier == 1)
- {
- try
- {
- string MyConnection2 = "datasource=192.168.0.193;port=3306;username=haidson;password=password";
- string Query = "UPDATE saq.users SET half_success_count= half_success_count + 1 WHERE username='" + lblUsername.Text + "';";
- MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
- MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
- MySqlDataReader MyReader2;
- MyConn2.Open();
- MyReader2 = MyCommand2.ExecuteReader();
- while (MyReader2.Read())
- {
- }
- MyConn2.Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- //-------------------------------------------------------------------------------------
- try
- {
- string MyConnection2 = "datasource=192.168.0.193;port=3306;username=haidson;password=password";
- string Query = "UPDATE saq.vins SET failure_count= failure_count + 1 WHERE nom='" + lblBottleName.Text + "';";
- MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
- MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
- MySqlDataReader MyReader2;
- MyConn2.Open();
- MyReader2 = MyCommand2.ExecuteReader();
- while (MyReader2.Read())
- {
- }
- MyConn2.Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- else if (Multiplier == 0)
- {
- try
- {
- string MyConnection2 = "datasource=192.168.0.193;port=3306;username=haidson;password=password";
- string Query = "UPDATE saq.users SET failure_count= failure_count + 1 WHERE username='" + lblUsername.Text + "';";
- MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
- MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
- MySqlDataReader MyReader2;
- MyConn2.Open();
- MyReader2 = MyCommand2.ExecuteReader();
- while (MyReader2.Read())
- {
- }
- MyConn2.Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- //-------------------------------------------------------------------------------------
- try
- {
- string MyConnection2 = "datasource=192.168.0.193;port=3306;username=haidson;password=password";
- string Query = "UPDATE saq.vins SET success_count= success_count + 1 WHERE nom='" + lblBottleName.Text + "';";
- MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
- MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
- MySqlDataReader MyReader2;
- MyConn2.Open();
- MyReader2 = MyCommand2.ExecuteReader();
- while (MyReader2.Read())
- {
- }
- MyConn2.Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- //-------------------------------------------------------------------------------------
- if (bottleFailureCount + bottleSuccessCount == 10) { //Determine the bottle's starting ELO
- bottleNewElo = bottleSuccessCount * 300;
- try
- {
- string MyConnection2 = "datasource=192.168.0.193;port=3306;username=haidson;password=password";
- string Query = "UPDATE saq.vins SET wine_elo=" + bottleNewElo + " WHERE nom='" + lblBottleName.Text + "';";
- MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
- MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
- MySqlDataReader MyReader2;
- MyConn2.Open();
- MyReader2 = MyCommand2.ExecuteReader();
- while (MyReader2.Read())
- {
- }
- MyConn2.Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- if (half_success_count + success_count + failure_count == 10)
- { //Determine the user's starting ELO
- newElo = (success_count * 300) + (half_success_count * 100);
- try
- {
- string MyConnection2 = "datasource=192.168.0.193;port=3306;username=haidson;password=password";
- string Query = "UPDATE saq.users SET elo= " + newElo + " WHERE username='" + lblUsername.Text + "';";
- MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
- MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
- MySqlDataReader MyReader2;
- MyConn2.Open();
- MyReader2 = MyCommand2.ExecuteReader();
- while (MyReader2.Read())
- {
- }
- MyConn2.Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- if (half_success_count + success_count + failure_count > 10) {
- if (bottlePreviousElo == 0 ) { //If the bottle is still under placements
- if (bottleSuccessCount < bottleFailureCount)
- {
- bottlePreviousElo = previousElo + 100;
- }
- else {
- bottlePreviousElo = previousElo - 20;
- }
- }
- double exa = (1 / (1 + Math.Pow(10, ((bottlePreviousElo - previousElo) / 400)))); //Expected outcome victory for user A
- if (Multiplier == 2)
- {
- newElo = previousElo + (25 * (2 - exa));
- int intNewElo = Convert.ToInt32(newElo);
- try
- {
- string MyConnection2 = "datasource=192.168.0.193;port=3306;username=haidson;password=password";
- string Query = "UPDATE saq.users SET elo= " + intNewElo + " WHERE username='" + lblUsername.Text + "';";
- MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
- MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
- MySqlDataReader MyReader2;
- MyConn2.Open();
- MyReader2 = MyCommand2.ExecuteReader();
- while (MyReader2.Read())
- {
- }
- MyConn2.Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- else if (Multiplier == 1)
- {
- newElo = previousElo + (7 * (2 - exa));
- int intNewElo = Convert.ToInt32(newElo);
- try
- {
- string MyConnection2 = "datasource=192.168.0.193;port=3306;username=haidson;password=password";
- string Query = "UPDATE saq.users SET elo= " + intNewElo + " WHERE username='" + lblUsername.Text + "';";
- MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
- MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
- MySqlDataReader MyReader2;
- MyConn2.Open();
- MyReader2 = MyCommand2.ExecuteReader();
- while (MyReader2.Read())
- {
- }
- MyConn2.Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- else if (Multiplier == 0) {
- newElo = previousElo - (25 * (2 - exa));
- int intNewElo = Convert.ToInt32(newElo);
- try
- {
- string MyConnection2 = "datasource=192.168.0.193;port=3306;username=haidson;password=password";
- string Query = "UPDATE saq.users SET elo= " + intNewElo + " WHERE username='" + lblUsername.Text + "';";
- MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
- MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
- MySqlDataReader MyReader2;
- MyConn2.Open();
- MyReader2 = MyCommand2.ExecuteReader();
- while (MyReader2.Read())
- {
- }
- MyConn2.Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- lblNewELO.Text = newElo.ToString();
- lblOddsToKnowBottle.Text = (Convert.ToInt32(exa) * 100) + "%";
- }
- if (bottleSuccessCount + bottleFailureCount > 10) {
- if (bottlePreviousElo == 0)
- { //If the user is still under placements
- if (success_count + half_success_count < failure_count)
- {
- previousElo = bottlePreviousElo + 100;
- }
- else
- {
- previousElo = bottlePreviousElo - 20;
- }
- }
- double exb = (1 / (1 + Math.Pow(10, ((previousElo - bottlePreviousElo) / 400)))); //Expected outcome victory for the bottle
- if (Multiplier == 2)
- {
- bottleNewElo = bottlePreviousElo - (25 * (2 - exb));
- int intbottleNewElo = Convert.ToInt32(bottleNewElo);
- try
- {
- string MyConnection2 = "datasource=192.168.0.193;port=3306;username=haidson;password=password";
- string Query = "UPDATE saq.vins SET wine_elo=" + intbottleNewElo + " WHERE nom='" + lblBottleName.Text + "';";
- MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
- MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
- MySqlDataReader MyReader2;
- MyConn2.Open();
- MyReader2 = MyCommand2.ExecuteReader();
- while (MyReader2.Read())
- {
- }
- MyConn2.Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- else if (Multiplier == 1)
- {
- bottleNewElo = bottlePreviousElo - (7 * (2 - exb));
- int intbottleNewElo = Convert.ToInt32(bottleNewElo);
- try
- {
- string MyConnection2 = "datasource=192.168.0.193;port=3306;username=haidson;password=password";
- string Query = "UPDATE saq.vins SET wine_elo=" + intbottleNewElo + " WHERE nom='" + lblBottleName.Text + "';";
- MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
- MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
- MySqlDataReader MyReader2;
- MyConn2.Open();
- MyReader2 = MyCommand2.ExecuteReader();
- while (MyReader2.Read())
- {
- }
- MyConn2.Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- else if (Multiplier == 0)
- {
- bottleNewElo = bottlePreviousElo + (25 * (2 - exb));
- int intbottleNewElo = Convert.ToInt32(bottleNewElo);
- try
- {
- string MyConnection2 = "datasource=192.168.0.193;port=3306;username=haidson;password=password";
- string Query = "UPDATE saq.vins SET wine_elo=" + intbottleNewElo + " WHERE nom='" + lblBottleName.Text + "';";
- MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
- MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
- MySqlDataReader MyReader2;
- MyConn2.Open();
- MyReader2 = MyCommand2.ExecuteReader();
- while (MyReader2.Read())
- {
- }
- MyConn2.Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- }
- }
- private void btnNewGame_Click(object sender, EventArgs e)
- {
- string username = lblUsername.Text;
- Form1 m = new Form1(username);
- m.Show();
- this.Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement