Beispiel #1
0
    protected void Poll1_SecurityChecking(object sender, PollSecurityCheckingEventArgs e)
    {
        OleDbConnection conn = new OleDbConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PollConnectionString"].ConnectionString);

        conn.Open();

        string checkVotingAllowedQuery = "SELECT COUNT(*) FROM UserVotes UV";

        checkVotingAllowedQuery += " INNER JOIN Answers A ON UV.AnswerID = A.AnswerID WHERE UV.UserID = @UserID AND A.PollID = 3";

        OleDbCommand checkVotingAllowedCommand = new OleDbCommand(checkVotingAllowedQuery, conn);

        checkVotingAllowedCommand.Parameters.AddWithValue("@UserID", UserID.ToString());

        object numberOfVotes = checkVotingAllowedCommand.ExecuteScalar();

        conn.Close();

        if (int.Parse(numberOfVotes.ToString()) >= Poll1.AllowedVotesPerUser)
        {
            e.AllowVoting = false;
        }
        else
        {
            e.AllowVoting = true;
        }
    }
    protected void Poll1_SecurityChecking(object sender, PollSecurityCheckingEventArgs e)
    {
        OleDbConnection conn = new OleDbConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PollConnectionString"].ConnectionString);

        conn.Open();

        string checkVotingAllowedQuery = "SELECT COUNT(*) FROM UserVotes UV";
        checkVotingAllowedQuery += " INNER JOIN Answers A ON UV.AnswerID = A.AnswerID WHERE UV.UserID = @UserID AND A.PollID = 3";

        OleDbCommand checkVotingAllowedCommand = new OleDbCommand(checkVotingAllowedQuery, conn);
        checkVotingAllowedCommand.Parameters.AddWithValue("@UserID", UserID.ToString());

        object numberOfVotes = checkVotingAllowedCommand.ExecuteScalar();

        conn.Close();

        if (int.Parse(numberOfVotes.ToString()) >= Poll1.AllowedVotesPerUser)
        {
            e.AllowVoting = false;
        }
        else
        {
            e.AllowVoting = true;
        }        
    }