Exemple #1
0
        /// <summary>
        /// Gets the current poll data for the given category and returns it in a <see cref="PollDataSet"/>.
        /// </summary>
        /// <returns>A <see cref="PollDataSet"/> containing the current poll in the given category.</returns>
        protected internal override PollDataSet GetCurrentPoll(String pollCategory)
        {
            if (pollCategory == null)
            {
                pollCategory = "";
            }

            PollDataSet poll = new PollDataSet();

            using (OleDbConnection cn = this.CreateConnection())
            {
                OleDbDataAdapter da = new OleDbDataAdapter("Select Top 1 * From " + PollsTable + " Where StartDate <= ? And Enabled = ? And Category = ? Order By StartDate desc", cn);
                da.SelectCommand.Parameters.Add("@StartDate", OleDbType.Date).Value    = DateTime.Now;
                da.SelectCommand.Parameters.Add("@Enabled", OleDbType.Boolean).Value   = true;
                da.SelectCommand.Parameters.Add("@Category", OleDbType.VarWChar).Value = pollCategory;
                da.TableMappings.Add(PollsTable, poll.Polls.TableName);
                da.Fill(poll.Polls);
            }

            if (poll.Polls.Count == 1)
            {
                this.GetResults(poll);
            }
            return(poll);
        }
Exemple #2
0
        /// <summary>
        /// Gets a <see cref="PollDataSet"/> containg all the polls with the given filter.
        /// </summary>
        protected internal override PollDataSet GetPollsByFilter(PollSelectionFilter filter)
        {
            PollDataSet polls = new PollDataSet();

            using (OleDbConnection cn = this.CreateConnection())
            {
                OleDbDataAdapter da = null;

                da = new OleDbDataAdapter();
                da.SelectCommand            = CreateSelectionCommand("*", filter);
                da.SelectCommand.Connection = cn;
                da.TableMappings.Add(PollsTable, polls.Polls.TableName);
                da.Fill(polls.Polls);

                da = new OleDbDataAdapter();
                da.SelectCommand             = CreateSelectionCommand("PollID", filter);
                da.SelectCommand.CommandText = "Select * From " + OptionsView + " Where PollID In ( " + da.SelectCommand.CommandText + " )";
                da.SelectCommand.Connection  = cn;
                da.TableMappings.Add(OptionsView, polls.Options.TableName);
                da.Fill(polls.Options);

                da = new OleDbDataAdapter();
                da.SelectCommand             = CreateSelectionCommand("PollID", filter);
                da.SelectCommand.CommandText = "Select * From " + VotesTable + " Where PollID In ( " + da.SelectCommand.CommandText + " )";
                da.SelectCommand.Connection  = cn;
                da.TableMappings.Add(VotesTable, polls.Votes.TableName);
                da.Fill(polls.Votes);
            }

            return(polls);
        }
Exemple #3
0
        /// <summary>
        /// Gets a <see cref="PollDataSet"/> containg all the polls.
        /// </summary>
        protected internal override PollDataSet GetAllPolls()
        {
            PollDataSet value = new PollDataSet();

            using (SqlConnection cn = this.CreateConnection())
            {
                SqlDataAdapter da;

                value.EnforceConstraints = false;

                da = new SqlDataAdapter("Select * From " + PollsTable, cn);
                da.TableMappings.Add(PollsTable, value.Polls.TableName);
                da.Fill(value.Polls);

                da = new SqlDataAdapter("Select * From " + OptionsView, cn);
                da.TableMappings.Add(OptionsView, value.Options.TableName);
                da.Fill(value.Options);

                da = new SqlDataAdapter("Select * From " + VotesTable, cn);
                da.TableMappings.Add(VotesTable, value.Votes.TableName);
                da.Fill(value.Votes);

                value.EnforceConstraints = true;
            }

            return(value);
        }
Exemple #4
0
        /// <summary>
        /// Gets the current poll data for the given category and returns it in a <see cref="PollDataSet"/>.
        /// </summary>
        /// <returns>A <see cref="PollDataSet"/> containing the current poll in the given category.</returns>
        protected internal override PollDataSet GetCurrentPoll(String pollCategory)
        {
            if (pollCategory == null)
            {
                pollCategory = "";
            }

            PollDataSet value = new PollDataSet();

            using (SqlConnection cn = this.CreateConnection())
            {
                SqlDataAdapter a = new SqlDataAdapter("Select Top 1 * From " + PollsTable + " Where StartDate <= @StartDate And Enabled = 1 And Category = @Category Order By StartDate desc", cn);
                a.SelectCommand.Parameters.Add("@StartDate", SqlDbType.DateTime).Value = DateTime.Now;
                a.SelectCommand.Parameters.Add("@Category", SqlDbType.NVarChar).Value  = pollCategory;
                a.TableMappings.Add(PollsTable, value.Polls.TableName);

                a.Fill(value.Polls);
            }

            if (value.Polls.Count == 1)
            {
                this.GetResults(value);
            }
            return(value);
        }
Exemple #5
0
        internal static PollDataSet CreatePlaceholderPoll()
        {
            if (fake == null)
            {
                fake = new PollDataSet();
                fake.Polls.AddPollsRow("Example Question", DateTime.Now, VoteSelectionMode.Single.ToString(), true, false, "");
                fake.Options.AddOptionsRow(fake.Polls[0], "Example Answer 1", 0, 1);
                fake.Options.AddOptionsRow(fake.Polls[0], "Example Answer 2", 1, 3);
                fake.Options.AddOptionsRow(fake.Polls[0], "Example Answer 3", 2, 2);
                fake.Votes.AddVotesRow(Guid.NewGuid(), "PlaceHolder", fake.Polls[0], fake.Options[0], null, DateTime.Now, 1, "127.0.0.1");
                fake.Votes.AddVotesRow(Guid.NewGuid(), "PlaceHolder", fake.Polls[0], fake.Options[1], null, DateTime.Now, 1, "127.0.0.1");
                fake.Votes.AddVotesRow(Guid.NewGuid(), "PlaceHolder", fake.Polls[0], fake.Options[1], null, DateTime.Now, 1, "127.0.0.1");
                fake.Votes.AddVotesRow(Guid.NewGuid(), "PlaceHolder", fake.Polls[0], fake.Options[1], null, DateTime.Now, 1, "127.0.0.1");
                fake.Votes.AddVotesRow(Guid.NewGuid(), "PlaceHolder", fake.Polls[0], fake.Options[2], null, DateTime.Now, 1, "127.0.0.1");
                fake.Votes.AddVotesRow(Guid.NewGuid(), "PlaceHolder", fake.Polls[0], fake.Options[2], null, DateTime.Now, 1, "127.0.0.1");

                PollDataSet.VotesRow writeInVote = fake.Votes.NewVotesRow();
                writeInVote.VoteID      = Guid.NewGuid();
                writeInVote.Member      = "PlaceHolder";
                writeInVote.PollsRow    = fake.Polls[0];
                writeInVote.WriteInText = "Write In Vote 1";
                writeInVote.VoteRating  = 1;
                writeInVote.DateVoted   = DateTime.Now;
                writeInVote.IPAddress   = "127.0.0.1";
                fake.Votes.AddVotesRow(writeInVote);

                fake.Polls.AddPollsRow("Quesion2", DateTime.Now, VoteSelectionMode.Multiple.ToString(), true, false, "");
                fake.Options.AddOptionsRow(fake.Polls[1], "Option1", 0, 0);
                fake.Options.AddOptionsRow(fake.Polls[1], "Option2", 1, 0);
                fake.Options.AddOptionsRow(fake.Polls[1], "Option3", 2, 0);
            }

            return(fake);
        }
Exemple #6
0
        /// <summary>
        /// Gets the poll data specified by the pollID, and returns it in a <see cref="PollDataSet"/>.
        /// </summary>
        /// <param name="pollID">The ID of the poll to retrieve.</param>
        /// <returns>A <see cref="PollDataSet"/> containing the specified poll data.</returns>
        public static PollDataSet GetPoll(Int32 pollID)
        {
            PollDataSet p = null;

            HttpContext context = HttpContext.Current;

            if (context == null)
            {
                p = Polling.Provider.GetPoll(pollID);
            }
            else
            {
                lock ( cacheSyncObject )
                {
                    String cacheKey = "MetaBuilders Polling Current PollDataSet By ID " + pollID.ToString(System.Globalization.CultureInfo.InvariantCulture);
                    p = Polling.GetPollFromCache(cacheKey);
                    if (p == null)
                    {
                        p = Polling.Provider.GetPoll(pollID);
                        Polling.InsertPollIntoCache(cacheKey, p);
                    }
                }
            }

            return(p ?? new PollDataSet());
        }
Exemple #7
0
        /// <summary>
        /// Gets the current poll data and returns it in a <see cref="PollDataSet"/>.
        /// </summary>
        /// <remarks>
        /// <p>Which poll is deemed "current" is up to the provider, but the built in providers use the current date and given category as the determining factor.</p>
        /// </remarks>
        /// <returns>A <see cref="PollDataSet"/> containing the current poll.</returns>
        public static PollDataSet GetCurrentPoll(String pollCategory)
        {
            if (pollCategory == null)
            {
                pollCategory = "";
            }

            PollDataSet p = null;

            HttpContext context = HttpContext.Current;

            if (context == null)
            {
                p = Polling.Provider.GetCurrentPoll(pollCategory);
            }
            else
            {
                lock ( cacheSyncObject )
                {
                    String cacheKey = "MetaBuilders Polling Current PollDataSet By Category " + pollCategory;
                    p = Polling.GetPollFromCache(cacheKey);
                    if (p == null)
                    {
                        p = Polling.Provider.GetCurrentPoll(pollCategory);
                        Polling.InsertPollIntoCache(cacheKey, p);
                    }
                }
            }

            return(p ?? new PollDataSet());
        }
Exemple #8
0
        private static void InsertPollIntoCache(String key, PollDataSet poll)
        {
            Initialize();

            HttpContext.Current.Cache.Insert(key, poll, null, DateTime.MaxValue, TimeSpan.FromMinutes(1));
            if (!cacheItems.Contains(key))
            {
                cacheItems.Add(key);
            }
        }
Exemple #9
0
        /// <summary>
        /// Gets the poll data specified by the pollID, and returns it in a <see cref="PollDataSet"/>.
        /// </summary>
        /// <param name="pollID">The ID of the poll to retrieve.</param>
        /// <returns>A <see cref="PollDataSet"/> containing the specified poll data.</returns>
        protected internal override PollDataSet GetPoll(Int32 pollID)
        {
            PollDataSet value = new PollDataSet();

            using (SqlConnection cn = this.CreateConnection())
            {
                SqlDataAdapter a = new SqlDataAdapter("Select * From " + PollsTable + " Where PollID = @PollID", cn);
                a.SelectCommand.Parameters.Add("@PollID", SqlDbType.Int).Value = pollID;
                a.TableMappings.Add(PollsTable, value.Polls.TableName);
                a.Fill(value.Polls);
            }

            if (value.Polls.Count == 1)
            {
                this.GetResults(value);
            }
            return(value);
        }
Exemple #10
0
        /// <summary>
        /// Gets the poll data specified by the pollID, and returns it in a <see cref="PollDataSet"/>.
        /// </summary>
        /// <param name="pollID">The ID of the poll to retrieve.</param>
        /// <returns>A <see cref="PollDataSet"/> containing the specified poll data.</returns>
        protected internal override PollDataSet GetPoll(Int32 pollID)
        {
            PollDataSet poll = new PollDataSet();

            using (OleDbConnection cn = this.CreateConnection())
            {
                OleDbDataAdapter da = new OleDbDataAdapter("Select * From " + PollsTable + " Where PollID = ?", cn);
                da.SelectCommand.Parameters.Add("@PollID", OleDbType.Integer).Value = pollID;
                da.TableMappings.Add(PollsTable, poll.Polls.TableName);
                da.Fill(poll.Polls);
            }

            if (poll.Polls.Count == 1)
            {
                this.GetResults(poll);
            }

            return(poll);
        }
Exemple #11
0
        private void GetResults(PollDataSet polls)
        {
            polls.EnforceConstraints = false;

            using (OleDbConnection cn = this.CreateConnection())
            {
                foreach (PollDataSet.PollsRow pollRow in polls.Polls)
                {
                    OleDbDataAdapter answersAdapter = new OleDbDataAdapter("Select * From " + OptionsView + " Where PollID = ?", cn);
                    answersAdapter.SelectCommand.Parameters.Add("@PollID", OleDbType.Integer, 4, "PollID").Value = pollRow.PollID;
                    answersAdapter.TableMappings.Add(OptionsView, polls.Options.TableName);
                    answersAdapter.Fill(polls.Options);

                    OleDbDataAdapter writeInsAdapter = new OleDbDataAdapter("Select * From " + VotesTable + " Where PollID = ?", cn);
                    writeInsAdapter.SelectCommand.Parameters.Add("@PollID", OleDbType.Integer, 4, "PollID").Value = pollRow.PollID;
                    writeInsAdapter.TableMappings.Add(VotesTable, polls.Votes.TableName);
                    writeInsAdapter.Fill(polls.Votes);
                }
            }

            try
            {
                polls.EnforceConstraints = true;
            }
            catch (System.Data.ConstraintException)
            {
                foreach (DataTable table in polls.Tables)
                {
                    if (table.HasErrors)
                    {
                        foreach (DataRow row in table.GetErrors())
                        {
                            System.Diagnostics.Debug.WriteLine(row.RowError);
                        }
                    }
                }
                throw;
            }
        }
Exemple #12
0
        /// <summary>
        /// Gets a <see cref="PollDataSet"/> containg all the polls.
        /// </summary>
        protected internal override PollDataSet GetAllPolls()
        {
            PollDataSet polls = new PollDataSet();

            using (OleDbConnection cn = this.CreateConnection())
            {
                OleDbDataAdapter da;

                da = new OleDbDataAdapter("Select * From " + PollsTable, cn);
                da.TableMappings.Add(PollsTable, polls.Polls.TableName);
                da.Fill(polls.Polls);

                da = new OleDbDataAdapter("Select * From " + OptionsView, cn);
                da.TableMappings.Add(OptionsView, polls.Options.TableName);
                da.Fill(polls.Options);

                da = new OleDbDataAdapter("Select * From " + VotesTable, cn);
                da.TableMappings.Add(VotesTable, polls.Votes.TableName);
                da.Fill(polls.Votes);
            }

            return(polls);
        }
Exemple #13
0
        private void GetResults(PollDataSet poll)
        {
            poll.EnforceConstraints = false;

            using (SqlConnection cn = this.CreateConnection())
            {
                foreach (PollDataSet.PollsRow pollRow in poll.Polls)
                {
                    SqlDataAdapter a = new SqlDataAdapter("Select * From " + OptionsView + " Where PollID = @PollID", cn);
                    a.SelectCommand.Parameters.Add("@PollID", SqlDbType.Int, 4, "PollID").Value = pollRow.PollID;
                    a.TableMappings.Add(OptionsView, poll.Options.TableName);
                    a.Fill(poll.Options);


                    a = new SqlDataAdapter("Select * From " + VotesTable + " Where PollID = @PollID", cn);
                    a.SelectCommand.Parameters.Add("@PollID", SqlDbType.Int, 4, "PollID").Value = pollRow.PollID;
                    a.TableMappings.Add(VotesTable, poll.Votes.TableName);
                    a.Fill(poll.Votes);
                }
            }

            poll.EnforceConstraints = true;
        }
Exemple #14
0
 internal void SetPollData(PollDataSet pollData)
 {
     _pollData = pollData;
 }
Exemple #15
0
        /// <summary>
        /// Gets a <see cref="PollDataSet"/> containg all the polls with the given filter.
        /// </summary>
        public static PollDataSet GetPollsByFilter(PollSelectionFilter filter)
        {
            PollDataSet p = Polling.Provider.GetPollsByFilter(filter);

            return(p ?? new PollDataSet());
        }
Exemple #16
0
        public static PollDataSet GetAllPolls()
        {
            PollDataSet p = Polling.Provider.GetAllPolls();

            return(p ?? new PollDataSet());
        }