private bool Save() { string[] columns; object[] paramValue; string name = textBoxName.Text.Trim(); string kod = textBoxKod.Text.Trim(); if (id_specialization == -1) { columns = new string[] { "Name", "KOD", "ID_SPECIALTY" }; paramValue = new object[] { name, kod, kodSpecialty }; } else { columns = new string[] { "Name", "KOD", "ID_SPECIALTY", "ID_SPECIALIZATION" }; paramValue = new object[] { name, kod, kodSpecialty, id_specialization }; } int rowid = SQLiteManager.InsertValue("COMPETENCE", columns, paramValue); if (rowid == -1) { return(false); } parentForm.AddCompetenceInDataGrid(name, kod, rowid, kodSpecialty, id_specialization); return(true); }
/// <summary> /// Функция сохранения всей информации в БД. /// </summary> private bool SaveData() { try { // Добавляем новых пользователей в БД и записываем их ID в Таг строки for (int i = 0; i < dataGrid.Rows.Count; i++) { if (Convert.ToInt64(dataGrid.Rows[i].Tag) == -1) { int rowid = SQLiteManager.InsertValue("Student", new string[] { "FIO", "ID_group" }, new object[] { dataGrid[0, i].Value.ToString().Trim(), id_group }); dataGrid.Rows[i].Tag = rowid; } } // Проходим по каждому пользователю и добавляем в БД новую запись об оценке за семестер по каждой дисциплине SQLiteConnection connection = SQLiteManager.CreateConnection(); string sqlInsert = "INSERT INTO Assessment_Discipline(Assessment, ID_student, ID_discipline, Semester) VALUES(@ass, @id_stud, @id_disp, @sem)"; SQLiteCommand command = new SQLiteCommand(sqlInsert, connection); command.Parameters.Add(new SQLiteParameter("@ass", DbType.Int64)); command.Parameters.Add(new SQLiteParameter("@id_stud", DbType.Int64)); command.Parameters.Add(new SQLiteParameter("@id_disp", DbType.Int64)); command.Parameters.AddWithValue("@sem", semester); for (int i = 0; i < dataGrid.Rows.Count; i++) { long id_student = Convert.ToInt64(dataGrid.Rows[i].Tag); if (id_student == -1) { continue; } for (int j = 1; j < dataGrid.Columns.Count; j++) { long id_disp = Convert.ToInt64(dataGrid.Columns[j].Tag); if (id_disp == -1) { continue; } int assessment; if (dataGrid[j, i].Value == null) { assessment = 0; } else { assessment = getValueAssessment(dataGrid[j, i].Value.ToString()); } command.Parameters[0].Value = assessment; command.Parameters[1].Value = id_student; command.Parameters[2].Value = id_disp; command.ExecuteNonQuery(); } } connection.Close(); return(true); } catch (Exception e) { MessageBox.Show("В процессе сохранения произошла ошибка.\n" + e.Message, "Ошибка"); return(false); } }
private void buttonSave_Click(object sender, EventArgs e) { if (String.IsNullOrWhiteSpace(textBox1.Text)) { MessageBox.Show("Сначала введите ФИО", "Уведомление"); return; } int rowid = SQLiteManager.InsertValue("Student", new string[] { "FIO", "ID_group" }, new object[] { textBox1.Text.Trim(), id_group }); SQLiteConnection connection = SQLiteManager.CreateConnection(); SQLiteCommand command = new SQLiteCommand("SELECT ID, Semester FROM WorkProgramm WHERE ID_specialization = @id_spec", connection); command.Parameters.AddWithValue("@id_spec", id_specialization); List <long> IDdiscipline = new List <long>(); ArrayList listSemesterDiscipline = new ArrayList(); SQLiteDataReader reader = command.ExecuteReader(); while (reader.Read()) { string[] sem = reader[1].ToString().Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (sem == null || sem.Length == 0) { continue; } IDdiscipline.Add(Convert.ToInt64(reader[0])); int[] temp = new int[sem.Length]; for (int i = 0; i < sem.Length; i++) { temp[i] = Convert.ToInt32(sem[i]); } listSemesterDiscipline.Add(temp); } reader.Close(); if (listSemesterDiscipline.Count != 0) { command.Parameters.Clear(); command.CommandText = "INSERT INTO Assessment_Discipline(ID_student, ID_discipline, Semester) VALUES(@id_stud, @id_disp, @sem)"; command.Parameters.AddWithValue("@id_stud", rowid); command.Parameters.Add(new SQLiteParameter("@id_disp", DbType.Int64)); command.Parameters.Add(new SQLiteParameter("@sem", DbType.Int32)); for (int i = 0; i < listSemesterDiscipline.Count; i++) { int[] sem = (int[])listSemesterDiscipline[i]; command.Parameters[1].Value = IDdiscipline[i]; for (int j = 0; j < sem.Length; j++) { if (sem[j] <= semester) { command.Parameters[2].Value = sem[j]; command.ExecuteNonQuery(); } } } } parentForm.AddNewStudent(rowid, id_group, textBox1.Text.Trim()); connection.Close(); Close(); }
public void AddNewGroup(long id_specialization, string numGroup, long kurs) { int rowid = SQLiteManager.InsertValue("StudyGroup", new string[] { "ID_specialization", "NumGroup", "Kurs" }, new object[] { id_specialization, numGroup, kurs }); BindingSource bind = (BindingSource)dataGridViewGroup.DataSource; DataTable table = (DataTable)bind.DataSource; DataRow row = table.NewRow(); row["ID"] = Convert.ToInt64(rowid); row["ID_specialization"] = id_specialization; row["NumGroup"] = numGroup; row["Kurs"] = kurs; table.Rows.Add(row); row.AcceptChanges(); dataGridViewGroup.Refresh(); }
private bool Save() { string semester = ""; foreach (int index in checkedListBox1.CheckedIndices) { semester += (index + 1).ToString() + ";"; } int rowid = SQLiteManager.InsertValue("WorkProgramm", new string[] { "NameDiscipline", "ID_specialization", "Semester" }, new object[] { textBoxDiscipline.Text, id_specialization, semester }); if (rowid == -1) { return(false); } parentForm.AddDisciplineInDataGrid(textBoxDiscipline.Text, rowid, id_specialization, semester); return(true); }
private bool SaveSpecialization() { int rowid = SQLiteManager.InsertValue("Specialization", new string[] { "Number", "Name", "specialty_fk" }, new string[] { numericUpDown1.Value.ToString(), textBox2.Text, kodParentSpec }); if (rowid == -1) { return(false); } DataGridView d = (DataGridView)parentForm.Controls["dataGridViewSpecialization"]; BindingSource bind = (BindingSource)d.DataSource; DataTable table = (DataTable)bind.DataSource; DataRow row = table.NewRow(); row["Number"] = numericUpDown1.Value.ToString(); row["Name"] = textBox2.Text; row["ID"] = rowid; row["specialty_fk"] = kodParentSpec; table.Rows.Add(row); row.AcceptChanges(); d.Refresh(); return(true); }
public void AddCompetenceChosenDiscipline(System.Collections.ArrayList ListDataGridRow) { if (ListDataGridRow == null || ListDataGridRow.Count == 0) { return; } BindingSource bind = (BindingSource)dataGridCompChosenDiscip.DataSource; DataTable table = (DataTable)bind.DataSource; for (int i = 0; i < ListDataGridRow.Count; i++) { bool flag_add = true; DataGridViewRow rowAdd = (DataGridViewRow)ListDataGridRow[i]; foreach (DataGridViewRow rowCurrent in dataGridCompChosenDiscip.Rows) { if (Convert.ToInt64(rowCurrent.Cells["ID"].Value) == Convert.ToInt64(rowAdd.Cells["ID"].Value)) { flag_add = false; break; } } if (flag_add) { // добавляем компетенцию в дата грид DataRow row = table.NewRow(); row["ID"] = rowAdd.Cells["ID"].Value; row["KOD"] = rowAdd.Cells["KOD"].Value; row["NAME"] = rowAdd.Cells["NAME"].Value; table.Rows.Add(row); row.AcceptChanges(); dataGridCompChosenDiscip.Refresh(); // теперь сохраним в базу новую связь дисциплина-компетенция SQLiteManager.InsertValue("Competence_Discipline", new string[] { "ID_competence", "ID_discipline" }, new object[] { rowAdd.Cells["ID"].Value, dataGridCompChosenDiscip.Tag }); } } }
private bool SaveSpec() { if (SQLiteManager.IsExistValue("SPECIALTY", "KOD", textBox1.Text)) { return(false); } int rowid = SQLiteManager.InsertValue("SPECIALTY", new string[] { "KOD", "Name" }, new string[] { textBox1.Text, textBox2.Text }); if (rowid == -1) { return(false); } DataGridView d = (DataGridView)parentForm.Controls["dataGridViewSpecialty"]; BindingSource bind = (BindingSource)d.DataSource; DataTable table = (DataTable)bind.DataSource; DataRow row = table.NewRow(); row[0] = textBox1.Text; row[1] = textBox2.Text; table.Rows.Add(row); row.AcceptChanges(); d.Refresh(); return(true); }