Пример #1
0
        private void btnAddCp_Click(object sender, EventArgs e)
        {
            int sum = 0;

            try
            {
                sum = Convert.ToInt32(tbWeghtMore.Text) + Convert.ToInt32(tbWeightLab.Text) +
                      Convert.ToInt32(tbWeightLek.Text) + Convert.ToInt32(tbWeightPrac.Text);
            }
            catch { }

            var listTextBoxes = new List <TextBox> {
                tbCountLab, tbCountLek, tbCountPrac
            };

            var emptyIsListTextBoxes = listTextBoxes.AsParallel().Any(t => t.Text == String.Empty);

            var listCpForGroup = from cp in reposCP.GetAll()
                                 where cp.DisciplineId == WorkWithDB.GetDisciplineId(DisciplineName)
                                 where cp.GroupId == WorkWithDB.GetIdGroupDisciplineGroup(reposGroup, GroupName)
                                 where cp.TermId == WorkWithDB.GetIdTermForCp(TermName)
                                 select cp;

            var sumCp = listCpForGroup.ToList().Sum(t => t.WeightKT);

            if (emptyIsListTextBoxes || sum > 100 || sum <= 0 || sum < 100 || sumCp + Convert.ToInt32(tbWeightPoint.Text) > 100)
            {
                MessageBox.Show("Проверьте введенные данные.");
                tbCountLek.BackColor   = Color.Red;
                tbCountLab.BackColor   = Color.Red;
                tbCountPrac.BackColor  = Color.Red;
                tbWeightLek.BackColor  = Color.Red;
                tbWeightLab.BackColor  = Color.Red;
                tbWeightPrac.BackColor = Color.Red;
                tbWeghtMore.BackColor  = Color.Red;
            }
            else
            {
                try
                {
                    //var _idTerm = WorkWithDB.GetIdTermForCp(TermName);
                    reposCP.Add(new CP(CpName, TermName, GroupName, Convert.ToInt32(tbWeightPoint.Text),
                                       Convert.ToInt32(tbWeightLab.Text), Convert.ToInt32(tbWeightLek.Text), Convert.ToInt32(tbWeightPrac.Text),
                                       Convert.ToInt32(tbWeghtMore.Text), Convert.ToInt32(tbCountLek.Text),
                                       Convert.ToInt32(tbCountLab.Text), Convert.ToInt32(tbCountPrac.Text), DisciplineName));
                    MessageBox.Show("Точка успешно добавлена");
                    lstBCp.DataSource = listCpForGroupAndDiscipline;
                }
                catch
                {
                    MessageBox.Show("Ошибка при добавлении контрольной точки!\nПроверьте введенные данные!");
                }
            }

            listCpForGroup = null;
            sumCp          = default(int);
            sum            = default(int);
        }