Ejemplo n.º 1
0
        bool isLabCreated = false; // создан ли тип работ для предмета

        #endregion Fields

        #region Constructors

        public FSubjectInfo(TSubject sub)
        {
            InitializeComponent();
            CurrentSubject = sub;
            InitData();
            InitWindow();
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Кнопка ОК
 /// </summary>
 private void OkExecute(object sender, EventArgs e)
 {
     if (textBox1.Text == "")
     {
         MessageBox.Show("Не введено название предмета!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     if (!radioButton1.Checked && !radioButton2.Checked)
     {
         MessageBox.Show("Не выбран метод создания работ для предмета!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     if (radioButton2.Checked && numericUpDown1.Value==0)
     {
         MessageBox.Show("Не задано количество работ!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     if (radioButton2.Checked && !isLabCreated)
     {
         MessageBox.Show("Не создана структура работы!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     // создание нового предмета
     subj = new TSubject(textBox1.Text);
     subj.AutoGenerateLabList((int)numericUpDown1.Value, ElementsIndexes);
     // закрытие окна
     this.DialogResult = DialogResult.OK;
     this.Close();
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Удаление предмета из списка по названию
 /// </summary>
 /// <param name="name">Название предмета</param>
 public void RemoveSubject(string name)
 {
     if (data.Length == 0)
         throw new Exception("Список задач пуст!");
     TSubject[] tmp = new TSubject[data.Length - 1];
     int k = 0;
     for (int i = 0; i < data.Length; i++)
         if (data[i].Name != name)
         {
             tmp[k] = data[i];
             k++;
         }
     data = tmp;
     isChange = true;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Загрузка данных из файла
        /// </summary>
        /// <param name="fname">Полный путь и имя файла для чтения</param>
        /// <returns>Возвращает список предметов с ихними работами</returns>
        public static TSubjectList LoadListFromFile(string fname)
        {
            XmlTextReader file = null;
            TSubjectList list = null;

            TSubject subj = null;
            TListItem item = null;

            try
            {
                // Load the reader with the data file and ignore all white space nodes.
                file = new XmlTextReader(fname);
                file.WhitespaceHandling = WhitespaceHandling.None;

                // Parse the file and display each of the nodes.
                while (file.Read())
                {
                    switch (file.NodeType)
                    {
                        case XmlNodeType.Element:
                            switch (file.Name) // проверяем элемент из XML файла
                            {
                                case "subjlist":
                                    // создание объекта списка
                                    list = new TSubjectList(file.GetAttribute("name"), file.GetAttribute("description"));
                                    break;
                                case "subject": // считываем описание предмета
                                    subj = new TSubject(file.GetAttribute("name"), (TStatus)Enum.Parse(typeof(TStatus), file.GetAttribute("status")));
                                    break;
                                case "lablist": // считываем описание списка работ
                                    if (subj != null)
                                        subj.List = new TLabList(file.GetAttribute("name"), file.GetAttribute("description"));
                                    break;
                                case "lab":
                                    item = new TListItem(file.GetAttribute("name"), file.GetAttribute("description"), (TStatus)Enum.Parse(typeof(TStatus), file.GetAttribute("status")));
                                    break;
                                case "element":
                                    if (item != null)
                                    {
                                        Element el = new Element();
                                        el.type = (ElementsTypes)Enum.Parse(typeof(ElementsTypes) ,file.GetAttribute("type"));
                                        el.isCompleted = bool.Parse(file.GetAttribute("iscompleted"));
                                        item.AddElement(el);
                                    }
                                    break;
                            }
                            break;
                        case XmlNodeType.EndElement:
                            switch (file.Name) // проверка на завершение блока элемента
                            {
                                case "lab": // добавление работы в список работ
                                    if (subj != null)
                                        subj.List.AddItem(item);
                                    break;
                                case "subject": // добавление предмета в список
                                    if (list != null)
                                        list.AddSubject(subj);
                                    break;
                            }
                            break;
                    }
                }
            }
            finally
            {
                if (file != null)
                    file.Close();
            }

            // возвращаем считанный список из файла
            return list;
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Добавление нового предмета в список
 /// </summary>
 /// <param name="subj">Новый предмет</param>
 /// <returns>Возвращает индекс добавленного предмета</returns>
 public int AddSubject(TSubject subj)
 {
     Array.Resize(ref data, data.Length + 1);
     data[data.Length - 1] = subj;
     isChange = true;
     return data.Length - 1;
 }