コード例 #1
0
        private void Theme1_Zadachi_Load(object sender, EventArgs e)
        {
            XmlSerializer formater = new XmlSerializer(typeof(List <Mission>));

            using (FileStream fs = new FileStream("listmission.xml", FileMode.OpenOrCreate))
            {
                list = (List <Mission>)formater.Deserialize(fs);
            }
            forRandom = new int [list.Count];
            List <Mission> any = new List <Mission>();

            label1.Text = list[0].Theme;
            using (FileStream fs = new FileStream("listmission.xml", FileMode.OpenOrCreate))
            {
                any = (List <Mission>)formater.Deserialize(fs);
            }
            int ind = 0;

            while (any.Count > 0)
            {
                Random  r           = new Random();
                int     RandomIndex = r.Next(any.Count);
                Mission a           = any[RandomIndex];
                for (int kol = 0; kol < list.Count; kol++)
                {
                    if (list[kol].question == a.question)
                    {
                        bool k = false;
                        for (int pr = 0; pr < a.answers.Count; pr++)
                        {
                            if (a.answers[pr].First != list[kol].answers[pr].First || a.answers[pr].Second != list[kol].answers[pr].Second)
                            {
                                k = true;
                            }
                        }
                        if (k == false)
                        {
                            forRandom[ind] = kol;
                        }
                    }
                }

                ind++;

                panel[PanelConstanta]               = new Panel();
                panel[PanelConstanta].Width         = panel1.Width;
                panel[PanelConstanta].Height        = 0;
                panel[PanelConstanta].Location      = new Point(0, panelLokation);
                textTask[currentIndexTextTask]      = new Label();
                textTask[currentIndexTextTask].Text = any[RandomIndex].question;
                int n = textTask[currentIndexTextTask].Text.Count(c => c == '\n') + 1;
                textTask[currentIndexTextTask].Width       = this.Width;
                textTask[currentIndexTextTask].Height      = n * 25;
                textTask[currentIndexTextTask].Font        = new System.Drawing.Font("Times New Roman", 14);
                textTask[currentIndexTextTask].UseMnemonic = false;
                textTask[currentIndexTextTask].BackColor   = Color.SkyBlue;
                panel[PanelConstanta].Height += textTask[currentIndexTextTask].Height;
                panel[PanelConstanta].Controls.Add(textTask[currentIndexTextTask]);
                localHeight += textTask[currentIndexTextTask].Height;


                for (int i = 0; i < any[RandomIndex].answers.Count; i++)
                {
                    radio[currentRadioButton]             = new RadioButton();
                    radio[currentRadioButton].Width       = this.Width;
                    radio[currentRadioButton].Height      = 25;
                    radio[currentRadioButton].Location    = new Point(0, localHeight);
                    radio[currentRadioButton].BackColor   = Color.Honeydew;
                    radio[currentRadioButton].Font        = new System.Drawing.Font("Times New Roman", 14);
                    radio[currentRadioButton].Text        = any[RandomIndex].answers[i].First;
                    radio[currentRadioButton].UseMnemonic = false;
                    panel[PanelConstanta].Height         += radio[currentRadioButton].Height;
                    panel[PanelConstanta].Controls.Add(radio[currentRadioButton]);
                    localHeight += radio[currentRadioButton].Height;
                    currentRadioButton++;
                }
                this.Controls.Add(panel[PanelConstanta]);
                localHeight += 5;
                PanelConstanta++;
                currentIndexTextTask++;
                panelLokation += localHeight;
                localHeight    = 0;
                any.RemoveAt(RandomIndex);
            }
        }
コード例 #2
0
        private void DopolniteTheme1_Click(object sender, EventArgs e)
        {
            bool fal1            = false;
            bool fal2            = false;
            bool fal3            = false;
            bool fal4            = false;
            int  countRadioCheck = 0;

            if (PanelConstanta == 0)
            {
                fal3 = true;
            }
            for (int j = 0; j < currentIndexRadio; j++)
            {
                if (radio[j].Checked)
                {
                    countRadioCheck++;
                }
            }
            if (countRadioCheck != CountNans.Count)
            {
                fal4 = true;
            }
            for (int j = 0; j < currentIndexRadio; j++)
            {
                if (radio[j].Text == "")
                {
                    fal1 = true;
                    break;
                }
            }
            for (int j = 0; j < currentIndexTextTask; j++)
            {
                if (textTask[j].Text == "")
                {
                    fal2 = true;
                    break;
                }
            }
            if (fal1 || fal2 || fal3 || fal4)
            {
                MessageBox.Show("Некорректные введенные данные");
            }
            else
            {
                int           ind   = 0;
                int           i     = 0;
                XmlSerializer diser = new XmlSerializer(typeof(List <Mission>));
                if (File.Exists("bank.xml"))
                {
                    using (FileStream fs = new FileStream("bank.xml", FileMode.OpenOrCreate))
                    {
                        any = (List <Mission>)diser.Deserialize(fs);
                    }
                }
                while (i < radio.Length && ind < CountNans.Count)
                {
                    Mission mr = new Mission();

                    int n = CountNans[ind];
                    for (int j = 0; j < n; j++)
                    {
                        Pair <string, bool> v = new Pair <string, bool>();
                        v.First  = radio[i].Text;
                        v.Second = radio[i].Checked;
                        mr.answers.Add(v);
                        i++;
                    }
                    mr.Theme    = label1.Text;
                    mr.question = textTask[ind].Text;
                    any.Add(mr);
                    ind++;
                }
                XmlSerializer ser = new XmlSerializer(typeof(List <Mission>));
                if (File.Exists("bank.xml"))
                {
                    File.Delete("bank.xml");
                }
                using (FileStream fs = new FileStream("bank.xml", FileMode.OpenOrCreate))
                {
                    ser.Serialize(fs, any);
                }
                ChooseAction menu = new ChooseAction();
                menu.LabelTheme.Text = label1.Text;
                menu.Show();
                this.Close();
            }
        }