protected void populatePanel() { QuestionLista q = new QuestionLista(); Serialisointi.DeSerialisoiKysymyksetXml(HttpContext.Current.Server.MapPath("~/App_Data/SavedQuestions.xml"), ref q); btnVastaa.Visible = true; if (q.kysymykset.Count > 0) { foreach (Question item in q.kysymykset) { TextBox kysymys = new TextBox(); kysymys.Text = item.question; kysymys.Enabled = false; studentPane.Controls.Add(kysymys); studentPane.Controls.Add(new LiteralControl("<br />")); foreach (string item1 in item.answers) { Label ehto = new Label(); CheckBox vastaus = new CheckBox(); ehto.Text = item1; studentPane.Controls.Add(ehto); studentPane.Controls.Add(vastaus); studentPane.Controls.Add(new LiteralControl("<br />")); } } } }
protected void endSurvey(object sender, EventArgs e) { QuestionLista a = new QuestionLista(); Timer1.Enabled = false; Serialisointi.SerialisoiXmlKysymykset(HttpContext.Current.Server.MapPath("~/App_Data/SavedQuestions.xml"), a); showresults = true; }
protected void btnAddQuestion_Click(object sender, EventArgs e) { List <string> answers = new List <string>(); List <int> rightanswers = new List <int>(); QuestionLista q = new QuestionLista(); int j = 0; if (int.Parse(cmbNumberofAnswers.SelectedValue) > 2) { foreach (Control item in pane.Controls) { if (item is TextBox) { TextBox txtInstance = (TextBox)item; answers.Add(txtInstance.Text); } if (item is CheckBox) { CheckBox chkInstance = (CheckBox)item; if (chkInstance.Checked) { rightanswers.Add(j); } j++; } } Question o = new Question(); o.question = txtQuetion.Text; o.answers = answers; o.rightanswers = rightanswers; q.kysymykset.Add(o); } else { answers.Add("Kyllä"); answers.Add("Ei"); if (CheckBox1.Checked) { rightanswers.Add(0); } else { rightanswers.Add(1); } Question o = new Question(); o.question = txtQuetion.Text; o.answers = answers; o.rightanswers = rightanswers; q.kysymykset.Add(o); } Serialisointi.SerialisoiXmlKysymykset(HttpContext.Current.Server.MapPath("~/App_Data/SavedQuestions.xml"), q); lblInfo.Text = "Kysymys lisätty!"; }
protected void btnAddQuestion_Click(object sender, EventArgs e) { List<string> answers = new List<string>(); List<int> rightanswers = new List<int>(); QuestionLista q = new QuestionLista(); int j = 0; if (int.Parse(cmbNumberofAnswers.SelectedValue) > 2) { foreach (Control item in pane.Controls) { if (item is TextBox) { TextBox txtInstance = (TextBox)item; answers.Add(txtInstance.Text); } if (item is CheckBox) { CheckBox chkInstance = (CheckBox)item; if (chkInstance.Checked) { rightanswers.Add(j); } j++; } } Question o = new Question(); o.question = txtQuetion.Text; o.answers = answers; o.rightanswers = rightanswers; q.kysymykset.Add(o); } else { answers.Add("Kyllä"); answers.Add("Ei"); if (CheckBox1.Checked) { rightanswers.Add(0); } else { rightanswers.Add(1); } Question o = new Question(); o.question = txtQuetion.Text; o.answers = answers; o.rightanswers = rightanswers; q.kysymykset.Add(o); } Serialisointi.SerialisoiXmlKysymykset(HttpContext.Current.Server.MapPath("~/App_Data/SavedQuestions.xml"), q); lblInfo.Text = "Kysymys lisätty!"; }
public static void DeSerialisoiKysymyksetXml(string filePath, ref QuestionLista kysymykset) { XmlSerializer deserializer = new XmlSerializer(typeof(QuestionLista)); try { FileStream xmlFile = new FileStream(filePath, FileMode.Open); kysymykset = (QuestionLista)deserializer.Deserialize(xmlFile); xmlFile.Close(); } catch (Exception ex) { throw ex; } finally { } }
public static void SerialisoiXmlKysymykset(string tiedosto, QuestionLista kysymykset) { XmlSerializer xs = new XmlSerializer(kysymykset.GetType()); TextWriter tw = new StreamWriter(tiedosto); try { xs.Serialize(tw, kysymykset); } catch (Exception e) { throw e; } finally { tw.Close(); } }