コード例 #1
0
        private void Nazad1_Click(object sender, EventArgs e)
        {
            MenuWithThemes        form       = new MenuWithThemes();
            List <Nazvanie_Theme> listThemes = new List <Nazvanie_Theme>();

            formater = new XmlSerializer(typeof(List <Nazvanie_Theme>));
            using (FileStream fs = new FileStream("theme.xml", FileMode.OpenOrCreate))
            {
                listThemes = (List <Nazvanie_Theme>)formater.Deserialize(fs);
            }
            for (int i = 0; i < listThemes.Count; i++)
            {
                switch (i)
                {
                case 0:
                {
                    form.labelTheme1.Text = listThemes[0].Name;
                    break;
                }

                case 1:
                {
                    form.labelTheme2.Text = listThemes[1].Name;
                    break;
                }

                case 2:
                {
                    form.labelTheme3.Text = listThemes[2].Name;
                    break;
                }

                case 3:
                {
                    form.labelTheme4.Text = listThemes[3].Name;
                    break;
                }

                case 4:
                {
                    form.labelTheme5.Text = listThemes[4].Name;
                    break;
                }

                case 5:
                {
                    form.labelTheme6.Text = listThemes[5].Name;
                    break;
                }

                case 6:
                {
                    form.labelTheme7.Text = listThemes[6].Name;
                    break;
                }

                case 7:
                {
                    form.labelTheme8.Text = listThemes[7].Name;
                    break;
                }

                case 8:
                {
                    form.labelTheme9.Text = listThemes[8].Name;
                    break;
                }

                case 9:
                {
                    form.labelTheme10.Text = listThemes[9].Name;
                    break;
                }
                }
            }
            form.Show();
            this.Close();
        }
コード例 #2
0
ファイル: Tasks1.cs プロジェクト: romstein/OurProject
        private void CreateTheme1_Click(object sender, EventArgs e)
        {
            bool fal1            = false;
            bool fal2            = false;
            bool fal3            = false;
            bool fal4            = false;
            bool fal5            = false;
            int  countRadioCheck = 0;

            if (PanelConstanta == 0)
            {
                fal5 = true;
            }
            for (int j = 0; j < currentIndexRadio; j++)
            {
                if (radio[j].Checked)
                {
                    countRadioCheck++;
                }
            }
            if (countRadioCheck != CountNans.Count)
            {
                fal4 = true;
            }
            if (ThemeZagolovok.Text == "Введите название темы" || ThemeZagolovok.Text == "")
            {
                fal3 = 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 || fal5)
            {
                MessageBox.Show("Некорректные введенные данные");
            }
            else
            {
                int ind = 0;
                int i   = 0;
                StrokaTheme = ThemeZagolovok.Text;
                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    = StrokaTheme;
                    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);
                }


                Nazvanie_Theme theme      = new Nazvanie_Theme(StrokaTheme);
                XmlSerializer  deformater = new XmlSerializer(typeof(List <Nazvanie_Theme>));
                if (File.Exists("theme.xml"))
                {
                    using (FileStream fs = new FileStream("theme.xml", FileMode.OpenOrCreate))
                    {
                        themes = (List <Nazvanie_Theme>)deformater.Deserialize(fs);
                    }
                    File.Delete("theme.xml");
                }
                themes.Add(theme);
                XmlSerializer formater = new XmlSerializer(typeof(List <Nazvanie_Theme>));
                using (FileStream fs = new FileStream("theme.xml", FileMode.OpenOrCreate))
                {
                    formater.Serialize(fs, themes);
                }
                MenuWithThemes menu = new MenuWithThemes();

                // Допустим у нас есть несколько созданных тем
                // Далее мы создаем новую тему
                // Когда создали и жмем на кнопку ,,создать тему,,
                // нужно при загрузке формы с темами для учителя вывести все имеющиеся темы в хранилище ,,theme.xml,,
                // Я это сделал сразу в логике кнопки ,,создать тему,,
                //
                for (int j = 0; j < themes.Count; j++)
                {
                    switch (j)
                    {
                    case 0:
                    {
                        menu.labelTheme1.Text = themes[0].Name;
                        break;
                    }

                    case 1:
                    {
                        menu.labelTheme2.Text = themes[1].Name;
                        break;
                    }

                    case 2:
                    {
                        menu.labelTheme3.Text = themes[2].Name;
                        break;
                    }

                    case 3:
                    {
                        menu.labelTheme4.Text = themes[3].Name;
                        break;
                    }

                    case 4:
                    {
                        menu.labelTheme5.Text = themes[4].Name;
                        break;
                    }

                    case 5:
                    {
                        menu.labelTheme6.Text = themes[5].Name;
                        break;
                    }

                    case 6:
                    {
                        menu.labelTheme7.Text = themes[6].Name;
                        break;
                    }

                    case 7:
                    {
                        menu.labelTheme8.Text = themes[7].Name;
                        break;
                    }

                    case 8:
                    {
                        menu.labelTheme9.Text = themes[8].Name;
                        break;
                    }

                    case 9:
                    {
                        menu.labelTheme10.Text = themes[9].Name;
                        break;
                    }
                    }
                }

                //menu.labelTheme1.Text = StrokaTheme;
                menu.Show();
                this.Close();
            }
        }
コード例 #3
0
        private void Delete1_Click(object sender, EventArgs e)
        {
            if (Delete1.BackColor == Color.Red && Delete1.BackColor2 == Color.Red && localLIST != null)
            {
                List <Mission> any   = new List <Mission>();
                XmlSerializer  diser = new XmlSerializer(typeof(List <Mission>));
                using (FileStream fs = new FileStream("bank.xml", FileMode.OpenOrCreate))
                {
                    any = (List <Mission>)diser.Deserialize(fs);
                }
                string TemaEbat = localLIST[0].Theme;
                for (int i = 0; i < checks.Length; i++)
                {
                    if (checks[i].Checked)
                    {
                        foreach (var item in localLIST)
                        {
                            if (item.Theme == TemaEbat && item.question == checks[i].Text)
                            {
                                localLIST.Remove(item);
                                break;
                            }
                        }
                        foreach (var item in any)
                        {
                            if (item.Theme == TemaEbat && item.question == checks[i].Text)
                            {
                                any.Remove(item);
                                break;
                            }
                        }
                        // Если этот checkBox помечен, то мы удаляем этот вопрос из localLIST
                        // Затем эти изменения должны быть применены к общему хранилищу, т. е. bank.xml
                        //
                    }
                }
                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);
                }

                if (localLIST.Count != 0)
                {
                    ChooseAction form = new ChooseAction();
                    form.LabelTheme.Text = label1.Text;
                    form.Show();
                    this.Close();
                }
                else
                {
                    // Нужно удалить тему, если удалены все вопросы по этой теме

                    Nazvanie_Theme        theme      = new Nazvanie_Theme(label1.Text);
                    List <Nazvanie_Theme> themes     = new List <Nazvanie_Theme>();
                    XmlSerializer         deformater = new XmlSerializer(typeof(List <Nazvanie_Theme>));
                    if (File.Exists("theme.xml"))
                    {
                        using (FileStream fs = new FileStream("theme.xml", FileMode.OpenOrCreate))
                        {
                            themes = (List <Nazvanie_Theme>)deformater.Deserialize(fs);
                        }
                        File.Delete("theme.xml");
                    }
                    themes.Remove(theme);
                    XmlSerializer formater = new XmlSerializer(typeof(List <Nazvanie_Theme>));
                    using (FileStream fs = new FileStream("theme.xml", FileMode.OpenOrCreate))
                    {
                        formater.Serialize(fs, themes);
                    }
                    MenuWithThemes menu = new MenuWithThemes();


                    for (int j = 0; j < themes.Count; j++)
                    {
                        switch (j)
                        {
                        case 0:
                        {
                            menu.labelTheme1.Text = themes[0].Name;
                            break;
                        }

                        case 1:
                        {
                            menu.labelTheme2.Text = themes[1].Name;
                            break;
                        }

                        case 2:
                        {
                            menu.labelTheme3.Text = themes[2].Name;
                            break;
                        }

                        case 3:
                        {
                            menu.labelTheme4.Text = themes[3].Name;
                            break;
                        }

                        case 4:
                        {
                            menu.labelTheme5.Text = themes[4].Name;
                            break;
                        }

                        case 5:
                        {
                            menu.labelTheme6.Text = themes[5].Name;
                            break;
                        }

                        case 6:
                        {
                            menu.labelTheme7.Text = themes[6].Name;
                            break;
                        }

                        case 7:
                        {
                            menu.labelTheme8.Text = themes[7].Name;
                            break;
                        }

                        case 8:
                        {
                            menu.labelTheme9.Text = themes[8].Name;
                            break;
                        }

                        case 9:
                        {
                            menu.labelTheme10.Text = themes[9].Name;
                            break;
                        }
                        }
                    }
                    menu.Show();
                    this.Close();
                }
            }
        }