protected void admin_knapp3_Click(object sender, EventArgs e) { GridView.DataSource = null; DataTable table = new DataTable(); table.Columns.Add("Förnamn"); table.Columns.Add("Efternamn"); table.Columns.Add("Provresultat"); table.Columns.Add("Etik"); table.Columns.Add("Ekonomi"); table.Columns.Add("Produkter"); table.Columns.Add("Provtyp"); List <Person> persons = Person.getPersons(); bool run1 = false; bool run2 = false; foreach (Person person in persons) { run1 = false; run2 = false; foreach (Test test in person.tests) { if (test.testtyp == "Licensieringtest") { if (!run1) { Test temptest = person.tests.OrderByDescending(x => x.time).Where(y => y.testtyp == "Licensieringtest").First(); table.Rows.Add(persons.Where(x => x.personID == temptest.personFK).Select(x => x.firstName).Single(), persons.Where(x => x.personID == temptest.personFK).Select(x => x.lastName).Single(), XElement.Parse(temptest.xmlString).Attribute("totalpoäng").Value + "/" + Quiz.getQuestions(temptest.testtyp).Count, XElement.Parse(temptest.xmlString).Attribute("poängetik").Value + "/" + Quiz.getQuestions(temptest.testtyp).Where(x => x.Subject == "Etik och regelverk").Count(), XElement.Parse(temptest.xmlString).Attribute("poängekonomi").Value + "/" + Quiz.getQuestions(temptest.testtyp).Where(x => x.Subject == "Ekonomi").Count(), XElement.Parse(temptest.xmlString).Attribute("poängprodukter").Value + "/" + Quiz.getQuestions(temptest.testtyp).Where(x => x.Subject == "Produkter").Count(), temptest.testtyp); run1 = true; } } else if (test.testtyp == "ÅKU") { if (!run2) { Test temptest = person.tests.OrderByDescending(x => x.time).Where(y => y.testtyp == "ÅKU").First(); table.Rows.Add(persons.Where(x => x.personID == temptest.personFK).Select(x => x.firstName).Single(), persons.Where(x => x.personID == temptest.personFK).Select(x => x.lastName).Single(), XElement.Parse(temptest.xmlString).Attribute("totalpoäng").Value + "/" + Quiz.getQuestions(temptest.testtyp).Count, XElement.Parse(temptest.xmlString).Attribute("poängetik").Value + "/" + Quiz.getQuestions(temptest.testtyp).Where(x => x.Subject == "Etik och regelverk").Count(), XElement.Parse(temptest.xmlString).Attribute("poängekonomi").Value + "/" + Quiz.getQuestions(temptest.testtyp).Where(x => x.Subject == "Ekonomi").Count(), XElement.Parse(temptest.xmlString).Attribute("poängprodukter").Value + "/" + Quiz.getQuestions(temptest.testtyp).Where(x => x.Subject == "Produkter").Count(), temptest.testtyp); run2 = true; } } } } GridView.DataSource = table; GridView.DataBind(); }
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); }