protected void btnUpdateQuestion_Click(object sender, EventArgs e) { classes.Question thisQuestion = new classes.Question(); thisQuestion.QuestionID = new Guid(txtQuestionID.Text); thisQuestion.QuestionText = txtQuestionText.Text; thisQuestion.QuestionTypeID = new Guid(ddlQuestionType.SelectedValue.ToString()); classes.SQLCode mySQL = new classes.SQLCode(); ListItem li = ddlQuestionType.SelectedItem; string QuestionType = li.Text; theseAnswers = DeserializeAnswers(); //when you add a free text question there is only one answer, which = the text of the question. Since the answer editor controls are //disabled for free text questions this won't allow a user to create an answer, therefore: on create answer list is null and uneditable. if (QuestionType == "Free Text" && theseAnswers.Count < 1) { classes.Answer thisAnswer = new classes.Answer(); Guid g = Guid.NewGuid(); thisAnswer.AnswerID = g; thisAnswer.QuestionID = thisQuestion.QuestionID; thisAnswer.AnswerText = thisQuestion.QuestionText; thisAnswer.SortOrder = 1; theseAnswers.Add(thisAnswer); } else if (QuestionType == "Free Text" && theseAnswers.Count > 0) { theseAnswers[0].AnswerText = txtQuestionText.Text; theseAnswers[0].SortOrder = 1; } mySQL.PostQuestion(thisQuestion, theseAnswers); LoadQuestions(); Response.Write("Question added"); }
protected void lbAnswers_SelectedIndexChanged(object sender, EventArgs e) { theseAnswers = DeserializeAnswers(); classes.Answer foundAnswer = theseAnswers.Find(delegate(classes.Answer myAnswer) { return(myAnswer.AnswerID == new Guid(lbAnswers.SelectedValue.ToString())); }); if (foundAnswer != null) { txtAnswerText.Text = foundAnswer.AnswerText; txtSortOrder.Text = foundAnswer.SortOrder.ToString(); txtAnswerID.Text = foundAnswer.AnswerID.ToString(); } }
protected void btnAddUpdateAnswer_Click(object sender, EventArgs e) { theseAnswers = DeserializeAnswers(); Guid g = Guid.NewGuid(); classes.Answer foundAnswer = theseAnswers.Find(delegate(classes.Answer myAnswer) { return(myAnswer.AnswerID == new Guid(txtAnswerID.Text)); }); if (foundAnswer != null) { foundAnswer.AnswerText = txtAnswerText.Text; foundAnswer.SortOrder = Convert.ToInt32(txtSortOrder.Text); foundAnswer.AnswerID = new Guid(txtAnswerID.Text); } else { classes.Answer thisAnswer = new classes.Answer(); thisAnswer.AnswerText = txtAnswerText.Text; if (string.IsNullOrEmpty(txtQuestionID.Text)) { txtQuestionID.Text = g.ToString(); } g = Guid.NewGuid(); thisAnswer.AnswerID = new Guid("00000000-0000-0000-0000-000000000000"); //txtAnswerID.Text = thisAnswer.AnswerID.ToString(); thisAnswer.QuestionID = new Guid(txtQuestionID.Text); thisAnswer.SortOrder = Convert.ToInt32(txtSortOrder.Text); theseAnswers.Add(thisAnswer); } theseAnswers = theseAnswers.OrderBy(a => a.SortOrder).ToList(); SerializeAnswers(theseAnswers); lbAnswers.DataSource = theseAnswers; lbAnswers.DataTextField = "AnswerText"; lbAnswers.DataValueField = "AnswerID"; lbAnswers.DataBind(); /* * ddlAnswers.Items.Clear(); * ListItem li = new ListItem(); * li.Text = "New Answer"; * li.Value = new Guid("00000000-0000-0000-0000-000000000000").ToString(); * foreach (classes.Answer thisAnswer in theseAnswers) * { * li = new ListItem(); * li.Text = thisAnswer.AnswerText; * li.Value = thisAnswer.AnswerID.ToString(); * ddlAnswers.Items.Add(li); * } * */ }
protected void btnUpdateAnswer_Click(object sender, EventArgs e) { theseAnswers = DeserializeAnswers(); Guid g = Guid.NewGuid(); classes.Answer foundAnswer = theseAnswers.Find(delegate(classes.Answer myAnswer) { return(myAnswer.AnswerID == new Guid(txtAnswerID.Text)); }); if (foundAnswer == null) { Response.Write("Couldn't update answer, no answer selected"); return; } foundAnswer.AnswerText = txtAnswerText.Text; foundAnswer.SortOrder = Convert.ToInt32(txtSortOrder.Text); foundAnswer.Status = "KEEP"; theseAnswers = theseAnswers.OrderBy(a => a.SortOrder).ToList(); SerializeAnswers(theseAnswers); lbAnswers.DataSource = theseAnswers; lbAnswers.DataTextField = "AnswerText"; lbAnswers.DataValueField = "AnswerID"; lbAnswers.DataBind(); }
protected void btnAddAnswer_Click(object sender, EventArgs e) { theseAnswers = DeserializeAnswers(); Guid g = Guid.NewGuid(); //check for valid number in sort order int numVal; bool result = Int32.TryParse(txtSortOrder.Text, out numVal); if (!result) { txtSortOrder.BackColor = System.Drawing.Color.Red; txtSortOrder.Text = "Enter a valid number"; return; } else { txtSortOrder.BackColor = System.Drawing.Color.White; } classes.Answer thisAnswer = new classes.Answer(); thisAnswer.AnswerText = txtAnswerText.Text; if (string.IsNullOrEmpty(txtQuestionID.Text)) { txtQuestionID.Text = g.ToString(); } g = Guid.NewGuid(); thisAnswer.AnswerID = g; thisAnswer.QuestionID = new Guid(txtQuestionID.Text); thisAnswer.SortOrder = numVal; thisAnswer.Status = "KEEP"; theseAnswers.Add(thisAnswer); theseAnswers = theseAnswers.OrderBy(a => a.SortOrder).ToList(); SerializeAnswers(theseAnswers); lbAnswers.DataSource = theseAnswers; lbAnswers.DataTextField = "AnswerText"; lbAnswers.DataValueField = "AnswerID"; lbAnswers.DataBind(); }
protected void btnRemoveAnswer_Click(object sender, EventArgs e) { theseAnswers = DeserializeAnswers(); Guid g = Guid.NewGuid(); classes.Answer foundAnswer = theseAnswers.Find(delegate(classes.Answer myAnswer) { return(myAnswer.AnswerID == new Guid(txtAnswerID.Text)); }); if (foundAnswer != null) { foundAnswer.Status = "REMOVE"; foundAnswer.AnswerText += " REMOVED"; } else { Response.Write("Couldn't find answer to remove"); return; } theseAnswers = theseAnswers.OrderBy(a => a.SortOrder).ToList(); SerializeAnswers(theseAnswers); lbAnswers.DataSource = theseAnswers; lbAnswers.DataTextField = "AnswerText"; lbAnswers.DataValueField = "AnswerID"; lbAnswers.DataBind(); }
private void LayoutPage() { theseQuestions = DeserialzeQuestions(); theseQuestionTypes = DeserialzeQuestionTypes(); theseAnswers = DeserializeAnswers(); foreach (classes.Question thisQuestion in theseQuestions) { classes.QuestionType foundType = theseQuestionTypes.Find(delegate(classes.QuestionType myType) { return(myType.QuestionTypeID == thisQuestion.QuestionTypeID); }); if (foundType == null) { Response.Write("No type, ending"); return; } pnlQuestions.Controls.Add(new LiteralControl("<div id=\"q" + thisQuestion.QuestionNumber + "\"><div class=\"qText\"><label class=\"qNum\">" + thisQuestion.QuestionNumber.ToString() + "</label> " + "<label class=\"questionTextLabel\">" + thisQuestion.QuestionText + "</label></div>")); string qType = foundType.QuestionTypeName; if (qType == "Calendar") { classes.Answer foundAnswer = theseAnswers.Find(delegate(classes.Answer myAnswer) { return(myAnswer.QuestionID == thisQuestion.QuestionID); }); if (foundAnswer == null) { Response.Write("Couldn't find answer, ending"); return; } Calendar c = new Calendar(); c.SelectedDate = DateTime.Now; c.ID = foundAnswer.AnswerID.ToString(); pnlQuestions.Controls.Add(new LiteralControl("<div class=\"outer\">")); pnlQuestions.Controls.Add(new LiteralControl("<div class=\"inner\">")); pnlQuestions.Controls.Add(c); pnlQuestions.Controls.Add(new LiteralControl("</div>")); pnlQuestions.Controls.Add(new LiteralControl("</div>")); } if (qType == "Free Text") { classes.Answer foundAnswer = theseAnswers.Find(delegate(classes.Answer myAnswer){ return(myAnswer.QuestionID == thisQuestion.QuestionID); }); if (foundAnswer == null) { Response.Write("Couldn't find answer, ending"); return; } TextBox qBox = new TextBox(); qBox.TextMode = TextBoxMode.MultiLine; qBox.Rows = 4; qBox.CssClass = "surveyTextBox"; qBox.ID = foundAnswer.AnswerID.ToString(); pnlQuestions.Controls.Add(new LiteralControl("<div class=\"outer\">")); pnlQuestions.Controls.Add(new LiteralControl("<div class=\"inner\">")); pnlQuestions.Controls.Add(qBox); pnlQuestions.Controls.Add(new LiteralControl("</div>")); pnlQuestions.Controls.Add(new LiteralControl("</div>")); } if (qType == "Multi Select") { List <classes.Answer> qAnswers = new List <classes.Answer>(); foreach (classes.Answer thisAnswer in theseAnswers) { if (thisAnswer.QuestionID == thisQuestion.QuestionID) { qAnswers.Add(thisAnswer); } } qAnswers = qAnswers.OrderBy(a => a.SortOrder).ToList(); pnlQuestions.Controls.Add(new LiteralControl("<div class=\"outer\">")); pnlQuestions.Controls.Add(new LiteralControl("<div class=\"inner\">")); //CheckBoxList cbl = new CheckBoxList(); ListBox cbl = new ListBox(); cbl.SelectionMode = ListSelectionMode.Multiple; cbl.ID = thisQuestion.QuestionID.ToString(); pnlQuestions.Controls.Add(new LiteralControl("<div class=\"scrollList\">")); pnlQuestions.Controls.Add(new LiteralControl("<div><label class=\"italicLabel\">Select All That Apply (hold Ctrl to multi-select)</label></div>")); foreach (classes.Answer thisAnswer in qAnswers) { ListItem li = new ListItem(); li.Text = thisAnswer.AnswerText; li.Value = thisAnswer.AnswerID.ToString(); cbl.Items.Add(li); /* * CheckBox qCB = new CheckBox(); * qCB.ID = thisAnswer.AnswerID.ToString(); * qCB.Text = thisAnswer.AnswerText; * pnlQuestions.Controls.Add(qCB); * */ } pnlQuestions.Controls.Add(cbl); pnlQuestions.Controls.Add(new LiteralControl("</div>")); //End scrollList pnlQuestions.Controls.Add(new LiteralControl("</div>")); //End inner pnlQuestions.Controls.Add(new LiteralControl("</div>")); //End Outer } if (qType == "Single Select") { List <classes.Answer> qAnswers = new List <classes.Answer>(); foreach (classes.Answer thisAnswer in theseAnswers) { if (thisAnswer.QuestionID == thisQuestion.QuestionID) { qAnswers.Add(thisAnswer); } } qAnswers = qAnswers.OrderBy(a => a.SortOrder).ToList(); pnlQuestions.Controls.Add(new LiteralControl("<div class=\"outer\">")); pnlQuestions.Controls.Add(new LiteralControl("<div class=\"inner\">")); //RadioButtonList rbl = new RadioButtonList(); DropDownList rbl = new DropDownList(); rbl.ID = thisQuestion.QuestionID.ToString(); pnlQuestions.Controls.Add(new LiteralControl("<div class=\"scrollList\">")); pnlQuestions.Controls.Add(new LiteralControl("<div><label class=\"italicLabel\">Select One</label></div>")); foreach (classes.Answer thisAnswer in qAnswers) { ListItem li = new ListItem(); li.Value = thisAnswer.AnswerID.ToString(); li.Text = thisAnswer.AnswerText; rbl.Items.Add(li); /* * RadioButton rb = new RadioButton(); * rb.ID = thisAnswer.AnswerID.ToString(); * rb.Text = thisAnswer.AnswerText; * rb.GroupName = thisQuestion.QuestionID.ToString(); * pnlQuestions.Controls.Add(rb); * */ } pnlQuestions.Controls.Add(rbl); pnlQuestions.Controls.Add(new LiteralControl("</div>")); //End scrollList pnlQuestions.Controls.Add(new LiteralControl("</div>")); //End inner pnlQuestions.Controls.Add(new LiteralControl("</div>")); //End outer } pnlQuestions.Controls.Add(new LiteralControl("</div>")); } }