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(); }
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) { 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}' точка!"); } }); }); }
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); } }