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 btnVastaa_Click(object sender, EventArgs e)
    {
        btnVastaa.Visible  = false;
        answerview.Visible = false;
        lblInfo.Text       = "Kiitos vastauksistasi!";

        AnswerList    a        = new AnswerList();
        Answer        b        = new Answer();
        List <string> answers  = new List <string>();
        List <int>    selected = new List <int>();
        string        question = "";
        int           j        = 0;
        int           i        = 0;

        foreach (Control item in studentPane.Controls)
        {
            if (item is TextBox)
            {
                if (i > 0)
                {
                    b.question = question;
                    b.answers  = answers;
                    b.selected = selected;
                    a.vastaukset.Add(b);

                    b = new Answer();
                }

                TextBox txtInstance = (TextBox)item;
                question = txtInstance.Text;

                i++;
            }
            if (item is CheckBox)
            {
                CheckBox chkInstance = (CheckBox)item;
                if (chkInstance.Checked)
                {
                    selected.Add(j);
                }
                j++;
            }
            if (item is Label)
            {
                Label lblInstance = (Label)item;
                answers.Add(lblInstance.Text);
            }
        }

        b.question = question;
        b.answers  = answers;
        b.selected = selected;
        a.vastaukset.Add(b);

        Serialisointi.SerialisoiXmlVastaukset(HttpContext.Current.Server.MapPath("~/App_Data/SavesAnswers.xml"), a);
    }
Esempio n. 5
0
    public static void VieAutot(List <Auto> autoLista)
    {
        AutoLista autot = new AutoLista();

        foreach (Auto item in autoLista)
        {
            autot.Autot.Add(item);
        }

        Serialisointi.SerialisoiXml(HttpContext.Current.Server.MapPath("~/App_Data/WanhatAutot.xml"), autot);
    }
Esempio n. 6
0
 private void btnSerializeBin_Click(object sender, RoutedEventArgs e)
 {
     // Kutsutaan serialisointia binääri-muotoon
     try
     {
         Serialisointi.Serialisoi(txtFileName.Text, mitatut);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Esempio n. 7
0
 private void btnDeserialize_Click(object sender, RoutedEventArgs e)
 {
     // Kutsutaan deserialisointia
     try
     {
         mitatut = Serialisointi.DeSerialisoiXml(txtFileName.Text);
         ApplyChanges();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Esempio n. 8
0
 private void btnSerializeBin_Click(object sender, RoutedEventArgs e)
 {
     // Kutsutaan serialisointia binäärimuotoon
     try
     {
         Serialisointi.Serialisoi(txtFileName.Text, mittaukset);
         MessageBox.Show("Binäärimuotoinen serialisointi onnistui tiedostoon " + txtFileName.Text);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Esempio n. 9
0
    public static List <Auto> HaeAutot()
    {
        AutoLista   autot     = new AutoLista();
        List <Auto> autoLista = new List <Auto>();

        Serialisointi.DeSerialisoiXml(HttpContext.Current.Server.MapPath("~/App_Data/WanhatAutot.xml"), ref autot);

        for (int i = 0; i < autot.Autot.Count; i++)
        {
            autoLista.Add(autot.Autot[i]);
        }
        return(autoLista);
    }
Esempio n. 10
0
 private void btnSerialize_Click(object sender, RoutedEventArgs e)
 {
     // Kutsutaan serialisointia
     try
     {
         Serialisointi.SerialisoiXml(txtFileName.Text, mittaukset);
         MessageBox.Show("Serialisoitu onnistuneesti tiedostoon " + txtFileName.Text);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Esempio n. 11
0
    private void populatePane()
    {
        AnswerList a = new AnswerList();

        Serialisointi.DeSerialisoiVastauksetXml(HttpContext.Current.Server.MapPath("~/App_Data/SavedQuestions.xml"), ref a);

        pane.Controls.Add(new LiteralControl("<br/>"));

        Label lbl = new Label();

        lbl.Text = "Vastauksia tuli yhteensä: " + a.vastaukset.Count().ToString();

        pane.Controls.Add(new Label());
    }
Esempio n. 12
0
 private void btnDeserialize_Click(object sender, RoutedEventArgs e)
 {
     // Kutsutaan deserialisointia
     try
     {
         mittaukset = Serialisointi.DeSerialisoiXml(txtFileName.Text);
         ApplyChanges();
         MessageBox.Show("Deserialisoitu onnistuneesti tiedostosta " + txtFileName.Text);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Esempio n. 13
0
 private void initStuff()
 {
     try
     {
         Records records = new Records();
         Serialisointi.DeSerialisoiXml(Server.MapPath("~/App_Data/records.xml"), ref records);
         Albums = records.genre.Records;
         ViewState["Records"] = Albums;
         loadListWiew(Albums);
     }
     catch (Exception ex)
     {
         er.InnerText = ex.Message;
     }
 }
Esempio n. 14
0
        private void btnDeserializeBin_Click(object sender, RoutedEventArgs e)
        {
            // Kutsutaan deserialisointia binääri-muotoon, palauttaa viittauksen objektiin
            object obj = new object();

            try
            {
                Serialisointi.DeSerialisoi(txtFileName.Text, ref obj);
                // Castataan obj MittausData-oliolistaksi
                mitatut = (List <MittausData>)obj;
                ApplyChanges();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 15
0
        private void btnDeserializeBin_Click(object sender, RoutedEventArgs e)
        {
            // Kutsutaan deserialisointia
            object obj = new object();

            try
            {
                Serialisointi.DeSerialisoi(txtFileName.Text, ref obj);
                // Ja nyt koetaan astata object-tyyppinen olio listaksi mittausdataan
                mittaukset = (List <MittausData>)obj;
                ApplyChanges();
                MessageBox.Show("Binäärimuotoinen deserialisointi onnistui tiedostosta " + txtFileName.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 16
0
    private void initMyStuff()
    {
        try
        {
            AutoLista autot = new AutoLista();
            Serialisointi.DeSerialisoiXml(Server.MapPath("~/App_Data/WanhatAutot.xml"), ref autot);
            Random      random = new Random();
            List <Auto> nelja  = new List <Auto>();

            while (nelja.Count < 4)
            {
                int luku = random.Next(0, autot.Autot.Count - 1);
                if (!nelja.Contains(autot.Autot.ElementAt(luku)))
                {
                    nelja.Add(autot.Autot.ElementAt(luku));
                }
            }
            Autot = autot.Autot;
            ViewState["AutotLista"] = Autot;
            List <string> merkit = new List <string>();
            merkit.Add("Kaikki");

            foreach (Auto auto in autot.Autot)
            {
                string merkki = auto.Merkki;

                if (!merkit.Contains(merkki))
                {
                    merkit.Add(merkki);
                }
            }

            ListBox1.DataSource = merkit;
            ListBox1.DataBind();
            ListBox1.Height = 150;
            SortExpression  = "DESC";
            loadListWiew(nelja);
        }
        catch (Exception ex)
        {
            er.InnerText = ex.Message;
        }
    }
Esempio n. 17
0
    public static bool authenticateUser(string userName, string passWord)
    {
        Users kayttajat = new Users();

        Serialisointi.deSerialisoiKayttajat(HttpContext.Current.Server.MapPath("~/App_Data/Kayttajat.xml"), ref kayttajat);

        byte[] saltBytes = new byte[] { 12, 254, 62, 6, 7, 42, 2, 96 };
        byte[] saltedHashBytesUserName = new HMACMD5(saltBytes).ComputeHash(Encoding.UTF8.GetBytes(userName));
        byte[] saltedHashBytesPassword = new HMACMD5(saltBytes).ComputeHash(Encoding.UTF8.GetBytes(passWord));

        string saltedHashStringUserName = Convert.ToBase64String(saltedHashBytesUserName);
        string saltedHashStringPassword = Convert.ToBase64String(saltedHashBytesPassword);

        for (int i = 0; i < kayttajat.kayttajat.Count; i++)
        {
            if (saltedHashStringUserName == kayttajat.kayttajat[i].UserName && saltedHashStringPassword == kayttajat.kayttajat[i].Password)
            {
                return(true);
            }
        }
        return(false);
    }
Esempio n. 18
0
 public static void TallennaAutot(AutoLista autot)
 {
     Serialisointi.SerialisoiXml(HttpContext.Current.Server.MapPath("~/App_Data/WanhatAutot.xml"), autot);
 }
Esempio n. 19
0
    protected void btnEmpty_Click(object sender, EventArgs e)
    {
        AnswerList a = new AnswerList();

        Serialisointi.SerialisoiXmlVastaukset(HttpContext.Current.Server.MapPath("~/App_Data/SavedQuestions.xml"), a);
    }