Example #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                isGood = true;
                di     = new Discipline()
                {
                    name             = textBox1.Text,
                    semester         = Convert.ToInt32(textBox2.Text),
                    kyrs             = trackBar1.Value,
                    specialization   = textBox4.Text,
                    numberOfLections = Convert.ToInt32(textBox5.Text),
                    numberOflabs     = Convert.ToInt32(textBox6.Text),
                    typeOfControls   = textBox9.Text,
                    numberOfStudents = Convert.ToInt32(textBox8.Text),

                    lector = new lector()
                    {
                        kafedra  = textBox7.Text,
                        FullName = textBox11.Text,
                        clas     = Convert.ToInt32(textBox10.Text),
                    },
                    litlist = new litlist()
                    {
                        name   = textBox12.Text,
                        author = textBox14.Text,
                        year   = Convert.ToInt32(numericUpDown1.Value),
                    }
                };
                var result  = new List <ValidationResult>();
                var context = new ValidationContext(di);
                if (!Validator.TryValidateObject(di, context, result, true))
                {
                    foreach (var error in result)
                    {
                        throw new Exception(error.ErrorMessage);
                    }
                }

                mylist.Add(di);
                richTextBox1.Text = di.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                isGood = true;
                di     = new Discipline()
                {
                    name             = textBox1.Text,
                    semester         = Convert.ToInt32(textBox2.Text),
                    kyrs             = trackBar1.Value,
                    specialization   = textBox4.Text,
                    numberOfLections = Convert.ToInt32(textBox5.Text),
                    numberOflabs     = Convert.ToInt32(textBox6.Text),
                    typeOfControls   = textBox9.Text,
                    numberOfStudents = Convert.ToInt32(textBox8.Text),

                    lector = new lector()
                    {
                        kafedra  = textBox7.Text,
                        FullName = textBox11.Text,
                        clas     = Convert.ToInt32(textBox10.Text),
                    },
                    litlist = new litlist()
                    {
                        name   = textBox12.Text,
                        author = textBox14.Text,
                        year   = Convert.ToInt32(numericUpDown1.Value),
                    }
                };

                mylist.Add(di);
                richTextBox1.Text = di.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }