protected void delete_Click(object sender, EventArgs e)
 {
     if (edit.Visible)
     {
         List <Pytanie> pyt     = Login.admin.przedmioty.Find(p => p.nazwa == przedmiot).pytania;
         int            id      = lista.SelectedIndex;
         Pytanie        pytanie = pyt[id];
         Login.admin.przedmioty.Find(p => p.nazwa == przedmiot).pytania.Remove(pytanie);
         lista.Items.RemoveAt(lista.SelectedIndex);
     }
     else
     {
         String  stu      = lista.SelectedItem.ToString();
         String  imie     = stu.Remove(stu.IndexOf(" "));
         String  nazwisko = stu.Remove(0, stu.IndexOf(" ") + 1);
         Student student  = null;
         foreach (Student st in Startup.students)
         {
             if (st.oceny.Exists(o => (o.przedmiot.nazwa == przedmiot)) && st.imie == imie && st.nazwisko == nazwisko)
             {
                 student = st;
             }
         }
         lista.Items.RemoveAt(lista.SelectedIndex);
         student.oceny.Remove(student.oceny.Find(p => p.przedmiot.nazwa == przedmiot));
     }
 }
        protected void Nbutton_Click(object sender, EventArgs e)
        {
            Pytanie pyt = Student1.ocena.przedmiot.pytania[questionId];

            if (pyt.GetMaxPoints() > 1)
            {
                for (int i = 0; i < pyt.pytania.Count; i++)
                {
                    CheckBox checkBox = (CheckBox)Main.FindControl("d_check_" + i.ToString());
                    if (checkBox.Checked && pyt.odp[i])
                    {
                        Student1.ocena.points++;
                    }
                }
            }
            else
            {
                for (int i = 0; i < pyt.pytania.Count; i++)
                {
                    RadioButton checkBox = (RadioButton)Main.FindControl("d_check_" + i.ToString());
                    if (checkBox.Checked && pyt.odp[i])
                    {
                        Student1.ocena.points++;
                    }
                }
            }
            maxPyt++;
            if (maxPyt >= Student1.ocena.przedmiot.pytania.Count)
            {
                finish = true;
            }
            Response.Redirect("Pytanie.aspx");
        }
        public void GenerujPytanie()
        {
            Main.Controls.Clear();
            questionId = random.Next(Student1.ocena.przedmiot.pytania.Count);
            Pytanie pyt = Student1.ocena.przedmiot.pytania[questionId];

            Main.Controls.Add(new LiteralControl("<h2>" + pyt.tytul + "</h2>"));
            Main.Controls.Add(new LiteralControl("<br>"));
            if (pyt.GetMaxPoints() > 1)
            {
                for (int i = 0; i < pyt.pytania.Count; i++)
                {
                    CheckBox ncheckbox = new CheckBox();
                    ncheckbox.ID   = "d_check_" + i.ToString();
                    ncheckbox.Text = pyt.pytania[i];
                    Main.Controls.Add(ncheckbox);
                    Main.Controls.Add(new LiteralControl("<br>"));
                }
            }
            else
            {
                for (int i = 0; i < pyt.pytania.Count; i++)
                {
                    RadioButton ncheckbox = new RadioButton();
                    ncheckbox.ID        = "d_check_" + i.ToString();
                    ncheckbox.Text      = pyt.pytania[i];
                    ncheckbox.GroupName = "d_group_" + questionId.ToString();
                    Main.Controls.Add(ncheckbox);
                    Main.Controls.Add(new LiteralControl("<br>"));
                }
            }
            Button nbutton = new Button();

            nbutton.ID = "d_apply_" + questionId.ToString();
            if (maxPyt < Student1.ocena.przedmiot.pytania.Count)
            {
                nbutton.Text = "Następne pytanie";
            }
            else
            {
                nbutton.Text = "Sprawdź test";
            }
            nbutton.Click += new System.EventHandler(Nbutton_Click);
            Main.Controls.Add(nbutton);
        }
Exemple #4
0
        public Przedmiot()
        {
            pytania = new List <Pytanie>();

            Pytanie pyt = new Pytanie("Zaznacz odp1:");

            pyt.AddPytanie("Zla", false);
            pyt.AddPytanie("Dobra", true);
            pyt.AddPytanie("Zła nr 2", false);
            pytania.Add(pyt);
            pyt = new Pytanie("Zaznacz odp2:");
            pyt.AddPytanie("Tak", true);
            pyt.AddPytanie("Dobra", true);
            pyt.AddPytanie("Zła nr 2", false);
            pytania.Add(pyt);
            pyt = new Pytanie("Zaznacz odp3:");
            pyt.AddPytanie("Nie", false);
            pyt.AddPytanie("Tak", true);
            pyt.AddPytanie("Nie nr 2", false);
            pytania.Add(pyt);
        }