Beispiel #1
0
        public void Add(CP entity)
        {
            _databaseStub.Add(entity);

            using (var _connection = new SQLiteConnection(connectionString))
                using (var cmd = new SQLiteCommand(_connection))
                {
                    _connection.Open();

                    foreach (var item in _databaseStub)
                    {
                        cmd.Parameters.AddWithValue("@Name", item.Name);
                        cmd.Parameters.AddWithValue("@TermId", WorkWithDB.GetIdTermForCp(item.TermName));
                        cmd.Parameters.AddWithValue("@WeightKT", item.WeightKT);
                        cmd.Parameters.AddWithValue("@WeightLab", item.WeightLab);
                        cmd.Parameters.AddWithValue("@WeightLek", item.WeightLek);
                        cmd.Parameters.AddWithValue("@WeightPrac", item.WeightPrac);
                        cmd.Parameters.AddWithValue("@WeightMore", item.WeightMore);
                        cmd.Parameters.AddWithValue("@GroupId", this.GetIdGroupForCP(item.GroupName));
                        cmd.Parameters.AddWithValue("@CountLek", entity.CountLek);
                        cmd.Parameters.AddWithValue("@CountLab", entity.CountLab);
                        cmd.Parameters.AddWithValue("@CountPrac", entity.CountPrac);
                        cmd.Parameters.AddWithValue("@IdDiscipline", WorkWithDB.GetDisciplineId(entity.NameDiscipline));

                        cmd.CommandText = "insert or replace into CP (name,  " +
                                          "term_id, weight_lab, weight_lek, weight_prac, weight_more, weight_kt, group_id, countLek, countLab, countPrac, discipline_id) VALUES" +
                                          " (@Name, @TermId, @WeightLab, @WeightLek, @WeightPrac, @WeightMore, @WeightKT, @GroupId, @CountLek, @CountLab, @CountPrac, @IdDiscipline)";
                        cmd.ExecuteNonQuery();
                    }
                }
            _databaseStub.Clear();
        }
Beispiel #2
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);
        }
        private async void Button3_Click(object sender, EventArgs e)
        {
            _logger.Info("Нажата кнопка '{0}'", button3.Text);
            try
            {
                await Task.Factory.StartNew(() =>
                {
                    InvokeUI(() =>
                    {
                        listStatementLine.Clear();

                        var reposStudent = RepositoryFactory <Student> .Create();

                        this.comboBoxListGroups.SelectedIndexChanged += new EventHandler(ComboboxListGroup_SelectedIndexChanged);

                        var _idGroup = reposStudent.GetIdGroupForStudent(GroupName);
                        var _idCp    = WorkWithDB.GetIdCp(CpName, _idGroup, DisciplineName, TermName);

                        var _cp = reposCP.Get(_idCp);

                        if (_idCp != 0 && _cp.DisciplineId == WorkWithDB.GetDisciplineId(DisciplineName))
                        {
                            foreach (var item in StatementLine.GetListStatementLine(_idCp, WorkWithDB.GetDisciplineId(DisciplineName),
                                                                                    Convert.ToInt32(reposGroup.GetIdGroupDisciplineGroup(GroupName)), WorkWithDB.GetIdTermForCp(TermName)).AsParallel())
                            {
                                listStatementLine.Add(item);
                            }
                            var repCp = reposCP.Get(_idCp);

                            tbCountLek.Text  = Convert.ToString(repCp.CountLek);
                            tbCountLab.Text  = Convert.ToString(repCp.CountLab);
                            tbCountPrac.Text = Convert.ToString(repCp.CountPrac);

                            ShowInformationAboutCp(_idCp);
                            _logger.Info("Информация загружена.");
                        }
                        else if (_idCp == 0)
                        {
                            _logger.Debug("Не удалось получить id контрольной точки!");
                        }
                        else
                        {
                            MessageBox.Show($"Для данной группы отсутствует '{CpName}' точка!");
                            _logger.Info("Данные не были загружены, так как у группы {0} отсутствует {1} точка по дисциплине {2} в семестре {3}",
                                         GroupName, CpName, DisciplineName, TermName);
                        }
                    });
                });
            }
            catch (Exception ex)
            {
                _logger.Error("Произошла ошибка ({0}) при загрузке записей", ex.Message);
            }
        }
Beispiel #4
0
 private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
 {
     if (Convert.ToString(dataGridView1.Columns[dataGridView1.CurrentCell.ColumnIndex].HeaderText) == "ФИО")
     {
         var _idStudent = reposStud.GetIdStudent(Convert.ToString(dataGridView1.CurrentCell.Value));
         if (_idStudent == -1)
         {
             reposStud.Add(new Student(Convert.ToString(dataGridView1.CurrentCell.Value), GroupName,
                                       WorkWithDB.GetDisciplineId(GroupName)));
         }
         else
         {
             MessageBox.Show("Студент с таким именем уже существует!");
         }
     }
 }
Beispiel #5
0
        private async void button3_Click(object sender, EventArgs e)
        {
            await Task.Factory.StartNew(() =>
            {
                InvokeUI(() =>
                {
                    listStatementLine.Clear();

                    var reposStudent = RepositoryFactory <Student> .Create();

                    this.comboBoxListGroups.SelectedIndexChanged += new EventHandler(comboboxListGroup_SelectedIndexChanged);

                    var _idGroup = reposStudent.GetIdGroupForStudent(GroupName);
                    var _idCp    = WorkWithDB.GetIdCp(CpName, _idGroup, DisciplineName, TermName);

                    var _cp = reposCP.Get(_idCp);

                    if (_idCp != 0 && _cp.DisciplineId == WorkWithDB.GetDisciplineId(DisciplineName))
                    {
                        foreach (var item in StatementLine.GetListStatementLine(_idCp, WorkWithDB.GetDisciplineId(DisciplineName),
                                                                                Convert.ToInt32(reposGroup.GetIdGroupDisciplineGroup(GroupName)), WorkWithDB.GetIdTermForCp(TermName)).AsParallel())
                        {
                            listStatementLine.Add(item);
                        }
                        var repCp = reposCP.Get(_idCp);

                        tbCountLek.Text  = Convert.ToString(repCp.CountLek);
                        tbCountLab.Text  = Convert.ToString(repCp.CountLab);
                        tbCountPrac.Text = Convert.ToString(repCp.CountPrac);

                        ShowInformationAboutCp(_idCp);
                    }
                    else
                    {
                        MessageBox.Show($"Для данной группы отсутствует '{CpName}' точка!");
                    }
                });
            });
        }
Beispiel #6
0
        private async void btnCloseTurn_Click(object sender, EventArgs e)
        {
            try
            {
                await Task.Factory.StartNew(() =>
                {
                    InvokeUI(() =>
                    {
                        var nameTypeWorkCColumnIndex = dataGridView1.CurrentCell.ColumnIndex;

                        var nameStudent = dataGridView1.CurrentCell.RowIndex;

                        string typeWorkName = Convert.ToString(dataGridView1.Columns[nameTypeWorkCColumnIndex].HeaderText);

                        string columnName = Convert.ToString(dataGridView1.Columns[nameTypeWorkCColumnIndex].Name);

                        dataGridView2.Visible = false;
                        var idGroup           = reposStud.GetIdGroupForStudent(GroupName);
                        foreach (var item in listTurn.AsParallel())
                        {
                            if (item.Point != 0 && item.Name != String.Empty && item.NameStudent != String.Empty)
                            {
                                var _idTurn = WorkWithDB.GetIdTurn(new Turn(Convert.ToInt32(reposStud.GetIdStudent(item.NameStudent)),
                                                                            WorkWithDB.GetDisciplineId(DisciplineName),
                                                                            Convert.ToInt32(WorkWithDB.GetIdCp(CpName, idGroup, DisciplineName, TermName)),
                                                                            typeWorkName, item.Point, item.Name));
                                if (_idTurn == -1)
                                {
                                    reposTurn.Add(new Turn(Convert.ToInt32(reposStud.GetIdStudent(item.NameStudent)),
                                                           WorkWithDB.GetDisciplineId(DisciplineName),
                                                           Convert.ToInt32(WorkWithDB.GetIdCp(CpName, idGroup, DisciplineName, TermName)),
                                                           typeWorkName, item.Point, item.Name));
                                }
                                else
                                {
                                    reposTurn.Update(new Turn(Convert.ToInt32(reposStud.GetIdStudent(item.NameStudent)),
                                                              WorkWithDB.GetDisciplineId(DisciplineName),
                                                              Convert.ToInt32(WorkWithDB.GetIdCp(CpName, idGroup, DisciplineName, TermName)),
                                                              typeWorkName, item.Point, item.Name));
                                }
                            }
                        }

                        var listWork = new List <Work>();

                        foreach (var itemTurn in listTurn.AsParallel())
                        {
                            listWork.Add(new Work(itemTurn.Name, itemTurn.Point));
                        }

                        dataGridView1[columnName, nameStudent].Value = CalcPointForCp.CalcScoreLabOrPrac(listWork); // Считаем виды работ, в которых есть разворот
                        dataGridView1.ReadOnly = false;
                        calcul();
                        listWork.Clear();
                        listTurn.Clear();
                    });
                });
            }
            catch
            {
                dataGridView1.ReadOnly = false;
                dataGridView2.Visible  = false;
            }
        }
Beispiel #7
0
        private async void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                var sum = Convert.ToInt32(tbWeghtMore.Text) + Convert.ToInt32(tbWeightLab.Text) +
                          Convert.ToInt32(tbWeightLek.Text) + Convert.ToInt32(tbWeightPrac.Text);
                if (sum > 100)
                {
                    MessageBox.Show("Проверьте веса видов работ!");
                    tbWeightLek.BackColor  = Color.Red;
                    tbWeightLab.BackColor  = new Color(/* Color [Red] */);
                    tbWeightPrac.BackColor = Color.Red;
                    tbWeghtMore.BackColor  = Color.Red;
                }

                UpCp();
                await Task.Factory.StartNew(() =>
                {
                    InvokeUI(() =>
                    {
                        var reposCpDataGeneral = RepositoryFactory <CPDataGeneral> .Create();
                        var _listCpData        = reposCpDataGeneral.GetAll().AsParallel();
                        var reposStudent       = RepositoryFactory <Student> .Create();
                        var _listStudentFromDb = reposStudent.GetAllStudentForGroup(GroupName);
                        var _idGroup           = reposStudent.GetIdGroupForStudent(GroupName);
                        var _idCp = WorkWithDB.GetIdCp(CpName, _idGroup, DisciplineName, TermName);

                        List <CPDataGeneral> listDataGeneral = new List <CPDataGeneral>();
                        List <Student> listStudent           = new List <Student>();
                        List <Student> listStudentUpdate     = new List <Student>();

                        var IsBool = listStatementLine.AsParallel().Any(t => t.FIO == "");

                        if (IsBool == false)
                        {
                            foreach (var item in listStatementLine.AsParallel())
                            {
                                listDataGeneral.Add(new CPDataGeneral(item.PointGeneral, item.FIO, DisciplineName, _idCp, 3, item.PointForLab,
                                                                      Convert.ToInt32(item.PointForLek), item.PointForPrac, item.PointForMore));
                            }

                            foreach (var itemDataGeneral in listDataGeneral.AsParallel())
                            {
                                var bl = _listCpData.Any(t => t.StudentId == reposStudent.GetIdStudent(itemDataGeneral.StudentName) &&
                                                         t.DisciplineId == WorkWithDB.GetDisciplineId(DisciplineName) &&
                                                         t.CpId == WorkWithDB.GetIdCp(CpName, _idGroup, DisciplineName, TermName));
                                if (bl)
                                {
                                    reposCpDataGeneral.Update(itemDataGeneral);
                                    continue;
                                }
                                else
                                {
                                    reposCpDataGeneral.Add(itemDataGeneral);
                                    continue;
                                }
                            }
                            MessageBox.Show("Данные успешно сохранены!");
                            listDataGeneral.Clear();
                            _listCpData = null;
                        }
                        else
                        {
                            MessageBox.Show("Проверьте заполнение поля 'ФИО' в введенных записях!");
                        }
                    });
                });
            }
            catch
            {
                MessageBox.Show("Недостаточно данных!");
            }
        }
        private void Btn_AddStudents_Click(object sender, EventArgs e)
        {
            Form    formAddStudents = new Form();
            TextBox textBoxPathFile = new TextBox();

            Label labelHeaderText = new Label();
            Label labelFilePath   = new Label();

            //блок кода, для работы с формой
            formAddStudents.Width     = 600;
            formAddStudents.Height    = 400;
            formAddStudents.BackColor = Color.FromArgb(57, 230, 57);
            formAddStudents.Text      = "Добавить студентов";

            //блок формы для работы с текстБоксами
            textBoxPathFile.Location = new Point(300, 100);
            textBoxPathFile.Size     = new Size(200, 50);
            textBoxPathFile.Font     = new Font("Microsoft Sans Serif", 10, FontStyle.Regular);
            formAddStudents.Controls.Add(textBoxPathFile);


            //блок формы для работы с лэйблами
            labelHeaderText.Location = new Point(200, 0);
            labelHeaderText.Font     = new Font("Microsoft Sans Serif", 15, FontStyle.Bold);
            labelHeaderText.Size     = new Size(250, 50);
            labelHeaderText.Text     = "Введите данные:";

            labelFilePath.Location = new Point(100, 100);
            labelFilePath.Font     = new Font("Microsoft Sans Serif", 10, FontStyle.Bold);
            labelFilePath.Size     = new Size(200, 50);
            labelFilePath.Text     = "Путь к файлу: ";


            OpenFileDialog openFileDialog = new OpenFileDialog
            {
                Filter = "Файлы xlsx|*.xlsx"
            };

            //Блок кода, работающий с кнопками
            Button btnAddStudents = new Button
            {
                Location = new Point(200, 300),
                Font     = new Font("Microsoft Sans Serif", 10, FontStyle.Bold),
                Size     = new Size(200, 50),
                Text     = "Добавить студентов"
            };

            Button btnSearchFile = new Button
            {
                Location = new Point(200, 200),
                Font     = new Font("Microsoft Sans Serif", 10, FontStyle.Bold),
                Size     = new Size(200, 50),
                Text     = "Выбрать файл"
            };

            btnSearchFile.Click += (send, args) =>
            {
                OnBtnSearchFileClick?.Invoke(sender, EventArgs.Empty);
            };

            OnBtnSearchFileClick += (send, args) =>
            {
                try
                {
                    if (openFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        //MessageBox.Show(openFileDialog.FileName);
                        textBoxPathFile.Text = openFileDialog.FileName;
                    }
                }
                catch { }
            };

            btnAddStudents.MouseClick += (send, args) =>
            {
                OnBtnAddStudents?.Invoke(sender, EventArgs.Empty);
            }; // Кнопка в окне добавления группы



            OnBtnAddStudents += (send, args) =>
            {
                try
                {
                    var list  = Module1.ReadExcelFile(textBoxPathFile.Text);
                    var count = list.Count();

                    if (list != null)
                    {
                        for (int i = 0; i <= count - 1; i++)
                        {
                            var _idStudent = reposStud.GetIdStudent(list[i]);
                            if (_idStudent == -1)
                            {
                                reposStud.Add(new Student(list[i], GroupName, WorkWithDB.GetDisciplineId(GroupName)));
                            }
                            else
                            {
                                MessageBox.Show("Студент с таким именем уже существует!");
                            }
                        }
                    }
                    MessageBox.Show("Студенты добавлены!");
                    formAddStudents.Close();
                }
                catch
                {
                    MessageBox.Show("Что-то пошло не так!");
                }
            };

            formAddStudents.Controls.Add(btnAddStudents);
            formAddStudents.Controls.Add(labelHeaderText);
            formAddStudents.Controls.Add(labelFilePath);
            formAddStudents.Controls.Add(btnSearchFile);


            formAddStudents.Show();
        }