Ejemplo n.º 1
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;
            }
        }
Ejemplo n.º 2
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("Недостаточно данных!");
            }
        }