public static List <Anwer> getAnwers(string xmlstring) { try { XDocument xDoc = XDocument.Parse(xmlstring); List <Anwer> anwers = new List <Anwer>(); foreach (var node in xDoc.Descendants("fraga")) { Anwer anwer = new Anwer(); anwer.Title = node.Attribute("Title").Value; anwer.Subject = node.Attribute("Ämne").Value; anwer.Type = node.Attribute("Typ").Value; foreach (XElement val in xDoc.Descendants("fraga").Where(x => x.Attribute("Title").Value == anwer.Title).Elements("Val")) { anwer.Anwers.Add(val.Value); } anwers.Add(anwer); } return(anwers); } catch (Exception ex) { HtmlGenericControl errormessage = Databas.errorMessage; errormessage.Visible = true; errormessage.InnerText = ex.Message; } return(new List <Anwer>()); }
private static void categoryPoints(Anwer anwer) { if (anwer.Subject.Contains("Produkter")) { pointsProdukter++; } else if (anwer.Subject.Contains("Ekonomi")) { pointsEkonomi++; } else { pointsEtik++; } }
protected void submit_button_Click(object sender, EventArgs e) { if (Convert.ToBoolean(ViewState["clicked"])) { Response.Redirect("Default.aspx"); return; } else if (validation()) { info.Visible = true; return; } info.Visible = false; List <Anwer> anwers = new List <Anwer>(); int counter = 0; Anwer anwer = new Anwer(); foreach (Control control in Page.Controls) { foreach (Control childcontrol in prov_div.FindControl("section").Controls) { if (childcontrol is Panel) { foreach (var grandchildcontrol in (childcontrol).Controls) { if (3 == counter) { anwers.Add(anwer); anwer = new Anwer(); counter = 0; } if (anwer.Title == "") { anwer.Title = ((Label)grandchildcontrol).Text; counter++; } else if (anwer.Subject == "") { anwer.Subject = ((Label)grandchildcontrol).Text; counter++; } else if (grandchildcontrol is CheckBoxList) { anwer.Type = "Multi"; foreach (ListItem item in (((CheckBoxList)grandchildcontrol).Items)) { if (item.Selected) { anwer.Anwers.Add(item.Value); } } counter++; } else if (grandchildcontrol is RadioButtonList) { anwer.Type = "One"; anwer.Anwers.Add((((RadioButtonList)grandchildcontrol).SelectedValue)); counter++; } } } } } anwers.Add(anwer); clearForm(); ViewState["clicked"] = true; Feedback feedback = Quiz.correctTest(Session["test"].ToString(), anwers); Databas.dataToDB("INSERT INTO prov(person_id_fk, xmlstring, datum, godkand, provtyp) VALUES(@id, @xmlstring, @datum, @godkand, @provtyp);", new List <SqlParameter>() { new SqlParameter("@id", Convert.ToInt16(Session["user"])), new SqlParameter("@datum", DateTime.Now), new SqlParameter("@godkand", feedback.passed), new SqlParameter("@xmlstring", Quiz.createXmlString(anwers)), new SqlParameter("@provtyp", Session["test"].ToString()) }); Feedback(feedback); }