Ejemplo n.º 1
0
        public void UpdateChoice(PollChoiceInfo pollChoice)
        {
            string strSql             = "UPDATE " + Config.ForumTablePrefix + "POLLANSWERS SET PollID = @PollId,DisplayText = @Answer,SortOrder = @Order WHERE PollAnswerID=@Id";
            List <SqlParameter> parms = new List <SqlParameter>
            {
                new SqlParameter("@PollID", SqlDbType.Int)
                {
                    Value = pollChoice.PollId
                },
                new SqlParameter("@Order", SqlDbType.Int)
                {
                    Value = pollChoice.Order
                },
                new SqlParameter("@Answer", SqlDbType.NVarChar)
                {
                    Value = pollChoice.DisplayText
                },
                new SqlParameter("@Id", SqlDbType.Int)
                {
                    Value = pollChoice.Id
                }
            };

            SqlHelper.ExecuteNonQuery(SqlHelper.ConnString, CommandType.Text, strSql, parms.ToArray());
        }
Ejemplo n.º 2
0
        public void Update(PollInfo poll)
        {
            string pollSql            = "UPDATE " + Config.ForumTablePrefix + "POLLS SET DisplayText=@Question WHERE PollId=@PollId;";
            List <SqlParameter> parms = new List <SqlParameter>
            {
                new SqlParameter("@PollId", SqlDbType.Int)
                {
                    Value = poll.Id
                },
                new SqlParameter("@Question", SqlDbType.NVarChar)
                {
                    Value = poll.DisplayText
                }
            };

            SqlHelper.ExecuteNonQuery(SqlHelper.ConnString, CommandType.Text, pollSql, parms.ToArray());
            if (poll.Choices == null)
            {
                return;
            }
            var choices            = GetPollChoices(poll.Id).ToArray();
            int currentchoicecount = choices.Length;
            int newchoicecount     = poll.Choices.Count;

            for (int ch = 0; ch < choices.Count(); ch++)
            {
                if (ch < newchoicecount)
                {
                    choices[ch].DisplayText = poll.Choices[ch].DisplayText;
                    choices[ch].Order       = poll.Choices[ch].Order;
                    UpdateChoice(choices[ch]);
                }
                else
                {
                    break;
                }
            }
            if (newchoicecount > currentchoicecount)
            {
                for (int i = currentchoicecount; i < newchoicecount; i++)
                {
                    PollChoiceInfo choice = new PollChoiceInfo
                    {
                        DisplayText = poll.Choices[i].DisplayText,
                        PollId      = poll.Id,
                        Order       = poll.Choices[i].Order
                    };
                    AddChoice(choice);
                }
            }
            else if (newchoicecount < currentchoicecount)
            {
                for (int i = newchoicecount; i < currentchoicecount; i++)
                {
                    DeleteChoice(choices[i].Id);
                }
            }
        }
Ejemplo n.º 3
0
        protected void PollAnswerInsert_ItemInserting(object sender, DetailsViewInsertEventArgs e)
        {
            PollChoiceInfo choice = new PollChoiceInfo {
                PollId = Convert.ToInt32(Request.QueryString["pid"])
            };
            TextBox text  = (TextBox)PollAnswerInsert.FindControl("NewPollAnswerDisplayText");
            TextBox order = (TextBox)PollAnswerInsert.FindControl("NewPollAnswerSortOrder");

            choice.DisplayText = text.Text;
            choice.Order       = Convert.ToInt32(order.Text);
            Snitz.BLL.Polls.AddChoice(choice);

            Response.Redirect(Request.RawUrl);
        }
Ejemplo n.º 4
0
        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            int    choiceid    = GridView1.GetNewValue <int>(e.RowIndex, 1);
            int    pollid      = Convert.ToInt32(Request.QueryString["pid"]);
            string displayText = GridView1.GetNewValue <string>(e.RowIndex, 2);
            int    order       = GridView1.GetNewValue <int>(e.RowIndex, 3);

            PollChoiceInfo choice = new PollChoiceInfo
            {
                Id          = choiceid,
                DisplayText = displayText,
                PollId      = pollid,
                Order       = order
            };

            Snitz.BLL.Polls.UpdatePollAnswer(choice);
        }
Ejemplo n.º 5
0
        public static void AddTopicPoll(int postid, string question, SortedList <int, string> choices)
        {
            IPoll dal = Factory <IPoll> .Create("Poll");

            PollInfo poll = new PollInfo {
                TopicId = postid, DisplayText = question
            };

            foreach (var choice in choices)
            {
                PollChoiceInfo pollchoice = new PollChoiceInfo {
                    DisplayText = choice.Value, Order = choice.Key
                };
                poll.AddChoice(pollchoice);
            }
            dal.Add(poll);
        }
Ejemplo n.º 6
0
        public void AddChoice(PollChoiceInfo pollChoice)
        {
            string strSql             = "INSERT INTO " + Config.ForumTablePrefix + "POLLANSWERS (PollID,DisplayText,SortOrder) VALUES (@PollId,@Answer,@Order); SELECT SCOPE_IDENTITY();";
            List <SqlParameter> parms = new List <SqlParameter>
            {
                new SqlParameter("@PollID", SqlDbType.Int)
                {
                    Value = pollChoice.PollId
                },
                new SqlParameter("@Order", SqlDbType.Int)
                {
                    Value = pollChoice.Order
                },
                new SqlParameter("@Answer", SqlDbType.NVarChar)
                {
                    Value = pollChoice.DisplayText
                }
            };

            SqlHelper.ExecuteNonQuery(SqlHelper.ConnString, CommandType.Text, strSql, parms.ToArray());
        }
Ejemplo n.º 7
0
        public void AddChoice(PollChoiceInfo pollChoice)
        {
            string strSql = "INSERT INTO " + Config.ForumTablePrefix + "POLLANSWERS (PollID,DisplayText,SortOrder) VALUES (@PollId,@Answer,@Order)";
            List <OleDbParameter> parms = new List <OleDbParameter>
            {
                new OleDbParameter("@PollID", OleDbType.Numeric)
                {
                    Value = pollChoice.PollId
                },
                new OleDbParameter("@Order", OleDbType.Numeric)
                {
                    Value = pollChoice.Order
                },
                new OleDbParameter("@Answer", OleDbType.VarChar)
                {
                    Value = pollChoice.DisplayText
                }
            };

            SqlHelper.ExecuteInsertQuery(SqlHelper.ConnString, CommandType.Text, strSql, parms.ToArray());
        }
Ejemplo n.º 8
0
        public IEnumerable <PollChoiceInfo> GetPollChoices(int pollId)
        {
            string strSql = "SELECT PollAnswerId,DisplayText,SortOrder FROM " + Config.ForumTablePrefix + "POLLANSWERS WHERE PollId=@PollId ORDER BY SortOrder";
            List <PollChoiceInfo> answers = new List <PollChoiceInfo>();

            using (SqlDataReader rdr = SqlHelper.ExecuteReader(SqlHelper.ConnString, CommandType.Text, strSql, new SqlParameter("@PollID", SqlDbType.Int)
            {
                Value = pollId
            }))
            {
                while (rdr.Read())
                {
                    PollChoiceInfo answer = new PollChoiceInfo
                    {
                        Id          = rdr.GetInt32(0),
                        DisplayText = rdr.SafeGetString(1),
                        Order       = rdr.GetInt32(2),
                        PollId      = pollId
                    };
                    answers.Add(answer);
                }
            }
            return(answers);
        }
Ejemplo n.º 9
0
        public static void UpdatePollAnswer(PollChoiceInfo choice)
        {
            IPoll dal = Factory <IPoll> .Create("Poll");

            dal.UpdateChoice(choice);
        }
Ejemplo n.º 10
0
        public static void AddChoice(PollChoiceInfo choice)
        {
            IPoll dal = Factory <IPoll> .Create("Poll");

            dal.AddChoice(choice);
        }