public Discipline(string Name, string Spec, int Sem, int Kurs, int NumOfLec, int NumOfLab, string ControlType, Lector lector) { this.Name = Name; this.Spec = Spec; this.Sem = Sem; this.Kurs = Kurs; this.NumOfLec = NumOfLec; this.NumOfLab = NumOfLab; this.ControlType = ControlType; this.lector = lector; }
private void button1_Click(object sender, EventArgs e) { //string filename = @"F:\OOP\Discipline.xml"; Discipline discipline = new Discipline(); Lector lector = new Lector(); lector.Surname = FIO.Surname; lector.Name = FIO.Name; lector.Otch = FIO.Otch; discipline.Name = textBox2.Text; discipline.Pulpit = textBox3.Text; discipline.Spec = SpecStr; discipline.Sem = (int)numericUpDown1.Value; discipline.Kurs = (int)numericUpDown2.Value; discipline.NumOfLec = trackBar1.Value; discipline.NumOfLab = trackBar2.Value; discipline.ControlType = comboBox1.Text; discipline.lector = lector; discipline.lector.Name = FIO.Name; discipline.lector.Surname = FIO.Surname; discipline.lector.Otch = FIO.Otch; var results = new List <ValidationResult>(); var context = new ValidationContext(discipline); if (!Validator.TryValidateObject(discipline, context, results, true)) { foreach (var error in results) { MessageBox.Show(error.ErrorMessage); } } else { //clone listDisciplines.Add(discipline); Prototype clone = discipline.Clone(); listDisciplines.Add((Discipline)clone);//list State = "Добавление"; } }
private void toolStripLabel3_Click(object sender, EventArgs e) { string filename = @"F:\OOP\Discipline.xml"; Discipline discipline = new Discipline(); Lector lector = new Lector(); lector.Surname = FIO.Surname; lector.Name = FIO.Name; lector.Otch = FIO.Otch; discipline.Name = textBox2.Text; discipline.Pulpit = textBox3.Text; discipline.Spec = SpecStr; discipline.Sem = (int)numericUpDown1.Value; discipline.Kurs = (int)numericUpDown2.Value; discipline.NumOfLec = trackBar1.Value; discipline.NumOfLab = trackBar2.Value; discipline.ControlType = comboBox1.Text; discipline.lector = lector; discipline.lector.Name = FIO.Name; discipline.lector.Surname = FIO.Surname; discipline.lector.Otch = FIO.Otch; listDisciplines.Add(discipline); Prototype clone = discipline.Clone(); listDisciplines.Add((Discipline)clone); XmlSerializeWrapper.Serialize(listDisciplines, filename); MessageBox.Show("Информация добавлена в файл"); State = "Сохранение"; }