Beispiel #1
0
        private void frmLogin_Load(object sender, EventArgs e)
        {
            // Collects predictions from database and displays them.

            string queryCount = "SELECT COUNT(Game_id) FROM TblGames";
            string countId    = "SELECT COUNT(id) FROM TblPredictions";
            string querymin   = "SELECT MIN(id) FROM TblPredictions";

            int countGame = dbh.DTInt(queryCount);
            int countPred = dbh.DTInt(countId);
            int minPred   = dbh.DTInt(querymin);

            int[] arrayCountGame  = new int[countGame * 4];
            int[] arrayCountGame1 = new int[countGame * 4];

            for (int i = 0; i < countGame; i++)
            {
                string querySelectHome = "SELECT HomeTeamScore FROM TblGames WHERE Game_id = '" + i + "'";
                string querySelectAway = "SELECT AwayTeamScore FROM TblGames WHERE Game_id = '" + i + "'";

                int HomeTeamScore = dbh.DTInt(querySelectHome);
                int AwayTeamScore = dbh.DTInt(querySelectAway);

                int trueId = i + minPred;

                string querySelect = "SELECT User_id FROM TblPredictions WHERE id = '" + trueId + "' and PredictedAwayScore = '" + AwayTeamScore + "' or PredictedHomeScore = '" + HomeTeamScore + "'";

                arrayCountGame[i] = dbh.DTInt(querySelect);

                string queryScore = "SELECT Score FROM TblUsers WHERE id = '" + arrayCountGame[i] + "'";

                arrayCountGame1[i] = dbh.DTInt(queryScore) + 2;

                string queryUpdate = "UPDATE TblUsers SET Score = '" + arrayCountGame[i] + "' WHERE id = '" + arrayCountGame[i] + "'";

                dbh.Execute(queryUpdate);
            }
        }
Beispiel #2
0
        public frmPlayer(Form frm, string un)
        {
            // This is letting the user to see the preditions, result and scorecard. We need an dbh to excute sqls.

            int amount = dbh.DTInt("SELECT COUNT(*) FROM TblGames");

            rowLeft  = new NumericUpDown[amount];
            rowRight = new NumericUpDown[amount];

            this.ControlBox = false;

            frmRanking = frm;

            this.counter--;

            dbh = new DatabaseHandler();

            InitializeComponent();

            // Disables buttons if its passed it expire date.

            if (DisableEditButton())
            {
                btnClearPrediction.Enabled = false;
                btnSaveButton.Enabled      = false;
            }

            this.Text = un;

            // Checks if some preditions already has been saved.

            DataTable tblUsers = dbh.FillDT("SELECT * FROM TblUsers WHERE (Username='******')");

            dbh.TestConnection();
            dbh.OpenConnectionToDB();

            using (SqlCommand cmd = new SqlCommand("SELECT id FROM TblUsers WHERE Username =  @Username", dbh.GetCon()))
            {
                cmd.Parameters.AddWithValue("Username", this.Text);

                string sql = Convert.ToString(cmd.ExecuteScalar());

                int.TryParse(sql, out this.resultId);
            }

            int userId = resultId;

            using (SqlCommand cmd = new SqlCommand("SELECT COUNT(*) FROM [tblPredictions] WHERE User_id = @User_id AND Saved = 1", dbh.GetCon()))
            {
                cmd.Parameters.AddWithValue("User_id", userId);
                saved = (int)cmd.ExecuteScalar() > 0;
            }

            dbh.CloseConnectionToDB();

            if (saved)
            {
                btnSaveButton.Enabled = false;
            }
            else
            {
                btnClearPrediction.Enabled = false;
            }

            ShowResults();
            ShowScoreCard();
            ShowPredictions(userId);
        }