Exemplo n.º 1
0
        private void OpenSpisokClick(object sender, EventArgs e)
        {
            if (need_updated == true)
            {
                DialogResult result = WantSaveList();
                if (result == DialogResult.Yes)
                {
                    SaveSpisokClick(sender, e);
                }
                else if (result == DialogResult.Cancel)
                {
                    return;
                }
            }
            dlg_open.InitialDirectory = Directory.GetCurrentDirectory();
            if (dlg_open.ShowDialog() == DialogResult.OK)
            {
                file_name = dlg_open.FileName;
                DirectoryInfo info = new DirectoryInfo(file_name);
                if (info.Extension != ".xml")
                {
                    toolStripLabelnfo.Text = "Файл имеет неверное расширение";
                    return;
                }
                toolStripLabelnfo.Text = "Файл открыт: " + info.Name;

                XmlSerializer formatter = new XmlSerializer(typeof(List <Student>));

                using FileStream fs = new FileStream(file_name, FileMode.OpenOrCreate);
                try
                {
                    students     = new StudentsCollection((List <Student>)formatter.Deserialize(fs));
                    need_updated = false;
                    SetButtonEnable(TypeAction.Prev, false);
                    deleteStudent.Enabled = true;

                    if (students.students_list.Count == 0)
                    {
                        deleteStudent.Enabled = false;
                        SetButtonEnable(TypeAction.Next, false);
                    }
                    else
                    {
                        button_update.Enabled = true;
                        deleteStudent.Enabled = true;
                        SetButtonEnable(TypeAction.Next, true);
                    }
                    if (students.GetEnumerator().MoveFirst())
                    {
                        FirstNameTextBox.Text  = students.Current.FirstName;
                        SecondNameTextBox.Text = students.Current.SecondName;
                        FacultyTextBox.Text    = students.Current.Faculty;
                    }
                }
                catch
                {
                    toolStripLabelnfo.Text = "Файл пустой";
                }
            }
        }
Exemplo n.º 2
0
 private void Previous_Click(object sender, EventArgs e)     //кнопка предыдущий на форме
 {
     button_update.Enabled = true;
     SetButtonEnable(TypeAction.Next, true);
     if (students.GetEnumerator().MovePrev())
     {
         FirstNameTextBox.Text  = students.Current.FirstName;
         SecondNameTextBox.Text = students.Current.SecondName;
         FacultyTextBox.Text    = students.Current.Faculty;
         if (students.GetEnumerator().IsFirst())
         {
             SetButtonEnable(TypeAction.Prev, false);
         }
     }
     else
     {
         SetButtonEnable(TypeAction.Prev, false);
     }
 }