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); }
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()); }
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()); }
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); }
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); }
public static void AddChoice(PollChoiceInfo choice) { IPoll dal = Factory<IPoll>.Create("Poll"); dal.AddChoice(choice); }
public static void UpdatePollAnswer(PollChoiceInfo choice) { IPoll dal = Factory<IPoll>.Create("Poll"); dal.UpdateChoice(choice); }
public void UpdateChoice(PollChoiceInfo pollChoice) { string strSql = "UPDATE " + Config.ForumTablePrefix + "POLLANSWERS SET PollID = @PollId,DisplayText = @Answer,SortOrder = @Order WHERE PollAnswerID=@Id"; 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}, new OleDbParameter("@Id", OleDbType.Numeric) {Value = pollChoice.Id} }; SqlHelper.ExecuteNonQuery(SqlHelper.ConnString, CommandType.Text, strSql, parms.ToArray()); }
public void Update(PollInfo poll) { string pollSql = "UPDATE " + Config.ForumTablePrefix + "POLLS SET DisplayText=@Question WHERE PollId=@PollId"; List<OleDbParameter> parms = new List<OleDbParameter> { new OleDbParameter("@PollId", OleDbType.Numeric) {Value = poll.Id}, new OleDbParameter("@Question", OleDbType.VarChar) {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); } } }
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 (OleDbDataReader rdr = SqlHelper.ExecuteReader(SqlHelper.ConnString, CommandType.Text, strSql, new OleDbParameter("@PollID", OleDbType.Numeric) { 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; }
public void AddChoice(PollChoiceInfo choiceInfo) { choiceInfo.PollInfo = this; Choices.Add(choiceInfo); }