Beispiel #1
0
        public static List <Person> getPersons()
        {
            List <Person> persons = new List <Person>();

            foreach (DataRow row in Databas.getData("SELECT person_id_pk, fornamn, efternamn FROM person WHERE person.roll_id_fk = 1", null).Rows)
            {
                persons.Add(new Person()
                {
                    personID = Convert.ToInt16(row["person_id_pk"]), firstName = row["fornamn"].ToString(), lastName = row["efternamn"].ToString()
                });
            }


            foreach (Test test in Test.getTests())
            {
                foreach (Person person in persons)
                {
                    if (person.personID == test.personFK)
                    {
                        person.tests.Add(test);
                    }
                }
            }

            return(persons);
        }
Beispiel #2
0
        public static List <Test> getTests()
        {
            List <Test> tests = new List <Test>();

            foreach (DataRow row in Databas.getData("SELECT prov_id_pk, person_id_fk, xmlstring, datum, godkand, provtyp FROM prov", null).Rows)
            {
                tests.Add(new Test()
                {
                    provID    = Convert.ToInt16(row["prov_id_pk"]),
                    personFK  = Convert.ToInt16(row["person_id_fk"]),
                    xmlString = row["xmlstring"].ToString(),
                    time      = Convert.ToDateTime(row["datum"]),
                    passed    = Convert.ToBoolean(row["godkand"]),
                    testtyp   = row["provtyp"].ToString()
                });
            }

            return(tests);
        }
Beispiel #3
0
        public static string whichTest(int id)
        {
            bool licensieringtestPassed = false;
            bool åkutestPassed          = false;

            foreach (DataRow row in Databas.getData("SELECT provtyp, godkand FROM prov INNER JOIN person ON person_id_pk = prov.person_id_fk WHERE person.person_id_pk = @add", new List <SqlParameter>()
            {
                new SqlParameter("@add", id)
            }).Rows)
            {
                if (row["provtyp"].ToString() == "Licensieringtest" && Convert.ToBoolean(row["godkand"]) == true)
                {
                    licensieringtestPassed = true;
                }

                else if (row["provtyp"].ToString() == "ÅKU" && Convert.ToBoolean(row["godkand"]) == true)
                {
                    åkutestPassed = true;
                }
            }

            if (licensieringtestPassed && åkutestPassed)
            {
                return("Du har klarat ÅKU provet så återkom om ett år");
            }

            foreach (DataRow row in Databas.getData("SELECT provtyp, godkand FROM prov INNER JOIN person ON person_id_pk = prov.person_id_fk WHERE person.person_id_pk = @add", new List <SqlParameter>()
            {
                new SqlParameter("@add", id)
            }).Rows)
            {
                if (row["provtyp"].ToString() == "Licensieringtest" && Convert.ToBoolean(row["godkand"]) == true)
                {
                    return("ÅKU");
                }
            }
            return("Licensieringtest");
        }
Beispiel #4
0
        private void showPassedTests()
        {
            HtmlTableRow  tablerow = new HtmlTableRow();
            HtmlTableCell cell1    = new HtmlTableCell();
            HtmlTableCell cell2    = new HtmlTableCell();

            bool run = false;

            string[] sql = { "SELECT top 1 fornamn, efternamn, datum, xmlstring, provtyp, godkand FROM person INNER JOIN prov ON person.person_id_pk = prov.person_id_fk  WHERE provtyp = 'ÅKU' AND person_id_pk = @add AND godkand = 'true' ORDER BY datum desc", "SELECT top 1 fornamn, efternamn, datum, xmlstring, provtyp FROM person INNER JOIN prov ON person.person_id_pk = prov.person_id_fk  WHERE provtyp = 'Licensieringtest' AND person_id_pk = @add AND godkand = 'true' ORDER BY datum desc" };

            foreach (string sqlquery in sql)
            {
                foreach (DataRow row in Databas.getData(sqlquery, new List <SqlParameter>()
                {
                    new SqlParameter("@add", Convert.ToInt16(Session["user"]))
                }).Rows)
                {
                    if (!run)
                    {
                        run = true;
                        firstName.InnerText = row["fornamn"].ToString();
                        lastName.InnerText  = row["efternamn"].ToString();
                        time.InnerText      = Convert.ToDateTime(row["datum"]).ToShortDateString();
                        godkänd.InnerText   = "Godkänd";
                        try
                        {
                            totalPoäng.InnerText          = XElement.Parse(row["xmlstring"].ToString()).Attribute("totalpoäng").Value;
                            totalPoängEtik.InnerText      = XElement.Parse(row["xmlstring"].ToString()).Attribute("poängetik").Value;
                            totalPoängEkonomi.InnerText   = XElement.Parse(row["xmlstring"].ToString()).Attribute("poängekonomi").Value;
                            totalPoängProdukter.InnerText = XElement.Parse(row["xmlstring"].ToString()).Attribute("poängprodukter").Value;
                        }
                        catch (Exception ex)
                        {
                            if (Master.FindControl("error") as HtmlGenericControl != null)
                            {
                                HtmlGenericControl errormessage = Master.FindControl("error") as HtmlGenericControl;
                                errormessage.Visible   = true;
                                errormessage.InnerText = ex.Message;
                            }
                        }

                        provTyp.InnerText = row["provtyp"].ToString();

                        try
                        {
                            XDocument        xDoc      = XDocument.Parse(row["xmlstring"].ToString());
                            List <Questions> questions = new List <Questions>();

                            if (xDoc.Descendants("fraga").Count() == 15)
                            {
                                questions = Quiz.getQuestions("ÅKU");
                            }

                            else
                            {
                                questions = Quiz.getQuestions("Licensprov");
                            }

                            List <Anwer> anwers = Quiz.getAnwers(row["xmlstring"].ToString());

                            for (int i = 0; i < anwers.Count; i++)
                            {
                                if (questions[i].Type == "One")
                                {
                                    tidigare_prov_box.Controls.Add(new Label()
                                    {
                                        Text = "Fråga " + (i + 1).ToString() + ": " + anwers[i].Title, CssClass = "title"
                                    });
                                    tidigare_prov_box.Controls.Add(new Label()
                                    {
                                        Text = anwers[i].Subject, CssClass = "text"
                                    });

                                    bool runed = false;

                                    RadioButtonList radiolist = new RadioButtonList();
                                    radiolist.Attributes.Add("class", "background-color");
                                    radiolist.Enabled = false;
                                    tidigare_prov_box.Controls.Add(radiolist);
                                    radiolist.CssClass = "font";
                                    questions[i].Options.ForEach(x => radiolist.Items.Add(x.name));

                                    for (int j = 0; j < radiolist.Items.Count; j++)
                                    {
                                        if (radiolist.Items[j].Text == anwers[i].Anwers.Single())
                                        {
                                            radiolist.Items[j].Selected = true;
                                        }
                                    }

                                    foreach (var question in questions[i].Options)
                                    {
                                        if (question.name == anwers[i].Anwers.Single() && question.isture)
                                        {
                                            if (!runed)
                                            {
                                                Panel panel = new Panel();
                                                panel.Attributes.Add("class", "återkoppling-box");
                                                panel.Controls.Add(new Label()
                                                {
                                                    Text = "Rätt", CssClass = "passtext"
                                                });
                                                panel.Controls.Add(new Label()
                                                {
                                                    Text = "Korrekt svar", CssClass = "passtext"
                                                });
                                                panel.Controls.Add(new Label()
                                                {
                                                    Text = "* " + anwers[i].Anwers.Single(), CssClass = "passtext"
                                                });
                                                tidigare_prov_box.Controls.Add(panel);
                                                runed = true;
                                            }
                                        }
                                    }

                                    if (!runed)
                                    {
                                        Panel panel = new Panel();
                                        panel.Attributes.Add("class", "återkoppling-box");
                                        panel.Controls.Add(new Label()
                                        {
                                            Text = "Fel", CssClass = "passtext"
                                        });
                                        panel.Controls.Add(new Label()
                                        {
                                            Text = "Korrekt svar", CssClass = "passtext"
                                        });
                                        panel.Controls.Add(new Label()
                                        {
                                            Text = "* " + questions[i].Options.Where(x => x.isture == true).Single().name, CssClass = "passtext"
                                        });
                                        tidigare_prov_box.Controls.Add(panel);
                                        runed = true;
                                    }
                                }

                                else if (questions[i].Type == "Multi")
                                {
                                    CheckBoxList checkboxlist = new CheckBoxList();

                                    questions[i].Options.ForEach(x => checkboxlist.Items.Add(x.name));

                                    for (int j = 0; j < checkboxlist.Items.Count; j++)
                                    {
                                        if (anwers[i].Anwers.Exists(x => x == checkboxlist.Items[j].Text))
                                        {
                                            checkboxlist.Items[j].Selected = true;
                                        }
                                    }

                                    checkboxlist.Enabled = false;
                                    tidigare_prov_box.Controls.Add(new Label()
                                    {
                                        Text = "Fråga " + (i + 1).ToString() + ": " + anwers[i].Title, CssClass = "title"
                                    });
                                    tidigare_prov_box.Controls.Add(new Label()
                                    {
                                        Text = anwers[i].Subject, CssClass = "text"
                                    });
                                    tidigare_prov_box.Controls.Add(checkboxlist);

                                    int  counter = 0;
                                    bool wrong   = true;

                                    foreach (string anwer in anwers[i].Anwers)
                                    {
                                        foreach (var question in questions[i].Options)
                                        {
                                            if (question.name == anwer && question.isture)
                                            {
                                                counter++;
                                            }

                                            else if (question.name == anwer && question.isture == false)
                                            {
                                                wrong = false;
                                                break;
                                            }
                                        }
                                    }

                                    if (questions[i].Options.Count(x => x.isture == true) == counter && wrong)
                                    {
                                        Panel panel = new Panel();
                                        panel.Attributes.Add("class", "återkoppling-box");
                                        panel.Controls.Add(new Label()
                                        {
                                            Text = "Rätt", CssClass = "passtext"
                                        });
                                        panel.Controls.Add(new Label()
                                        {
                                            Text = "Korrekta svar", CssClass = "passtext"
                                        });

                                        foreach (Option option in questions[i].Options.Where(x => x.isture == true))
                                        {
                                            panel.Controls.Add(new Label()
                                            {
                                                Text = "* " + option.name, CssClass = "passtext"
                                            });
                                        }

                                        tidigare_prov_box.Controls.Add(panel);
                                    }

                                    else
                                    {
                                        Panel panel = new Panel();
                                        panel.Attributes.Add("class", "återkoppling-box");
                                        panel.Controls.Add(new Label()
                                        {
                                            Text = "Fel", CssClass = "passtext"
                                        });
                                        panel.Controls.Add(new Label()
                                        {
                                            Text = "Korrekta svar", CssClass = "passtext"
                                        });

                                        foreach (Option option in questions[i].Options.Where(x => x.isture == true))
                                        {
                                            panel.Controls.Add(new Label()
                                            {
                                                Text = "* " + option.name, CssClass = "passtext"
                                            });
                                        }

                                        tidigare_prov_box.Controls.Add(panel);
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            if (Master.FindControl("error") as HtmlGenericControl != null)
                            {
                                HtmlGenericControl errormessage = Master.FindControl("error") as HtmlGenericControl;
                                errormessage.Visible   = true;
                                errormessage.InnerText = ex.Message;
                            }
                        }

                        break;
                    }
                }
            }

            if (run == false)
            {
                tidigare_prov_text.InnerText = "Inga prov att visa";
                table.Visible = false;
            }
        }
Beispiel #5
0
        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);
        }