private void btDelete_Click(object sender, EventArgs e) { if ((dgvDirections.SelectedRows.Count == 0) || (dgvDirections.SelectedRows[0].Cells[dgvDirections_Type.Index].Value.ToString() == "Н")) { MessageBox.Show("Выберите профиль"); } else if (SharedClasses.Utility.ShowChoiceMessageBox("Удалить выбранный профиль?", "Удаление профиля")) { try { _DB_Connection.Delete(DB_Table.PROFILES, new Dictionary <string, object> { { "faculty_short_name", dgvDirections.SelectedRows[0].Cells[dgvDirections_FacultyName.Index].Value }, { "direction_id", dgvDirections.SelectedRows[0].Cells[dgvDirections_ID.Index].Value }, { "short_name", dgvDirections.SelectedRows[0].Cells[dgvDirections_ShortName.Index].Value } }); UpdateTable(); } catch (MySqlException ex) { if (ex.Number == 1217 || ex.Number == 1451) { List <object[]> appEntrances = _DB_Connection.Select(DB_Table.APPLICATIONS_ENTRANCES, new string[] { "application_id" }, new List <Tuple <string, Relation, object> > { new Tuple <string, Relation, object>("faculty_short_name", Relation.EQUAL, dgvDirections.SelectedRows[0].Cells[dgvDirections_FacultyName.Index].Value), new Tuple <string, Relation, object>("direction_id", Relation.EQUAL, dgvDirections.SelectedRows[0].Cells[dgvDirections_ID.Index].Value), new Tuple <string, Relation, object>("profile_short_name", Relation.EQUAL, dgvDirections.SelectedRows[0].Cells[dgvDirections_ShortName.Index].Value) }); if (appEntrances.Count > 0) { MessageBox.Show("На данный профиль подано заявление. Удаление невозможно."); } else if (SharedClasses.Utility.ShowChoiceMessageWithConfirmation("Профиль включен в кампанию. Выполнить удаление?", "Связь с кампанией")) { using (MySql.Data.MySqlClient.MySqlTransaction transaction = _DB_Connection.BeginTransaction()) { _DB_Connection.Delete(DB_Table.CAMPAIGNS_PROFILES_DATA, new Dictionary <string, object> { { "profiles_direction_faculty", dgvDirections.SelectedRows[0].Cells[dgvDirections_FacultyName.Index].Value }, { "profiles_direction_id", dgvDirections.SelectedRows[0].Cells[dgvDirections_ID.Index].Value }, { "profiles_short_name", dgvDirections.SelectedRows[0].Cells[dgvDirections_ShortName.Index].Value } }, transaction); _DB_Connection.Delete(DB_Table.PROFILES, new Dictionary <string, object> { { "faculty_short_name", dgvDirections.SelectedRows[0].Cells[dgvDirections_FacultyName.Index].Value }, { "direction_id", dgvDirections.SelectedRows[0].Cells[dgvDirections_ID.Index].Value }, { "short_name", dgvDirections.SelectedRows[0].Cells[dgvDirections_ShortName.Index].Value } }, transaction); transaction.Commit(); } UpdateTable(); } } } } }
private void toolStrip_Delete_Click(object sender, EventArgs e) { if (SharedClasses.Utility.ShowUnrevertableActionMessageBox()) { _DB_Connection.Delete(DB_Table.ORDERS, new Dictionary <string, object> { { "number", SelectedOrderNumber } }); UpdateTable(); } }
private void btDelete_Click(object sender, EventArgs e) { if (dgvTargetOrganizations.SelectedRows.Count == 0) { MessageBox.Show("Выберите строку"); } else if (SharedClasses.Utility.ShowChoiceMessageBox("Удалить выбранную организацию?", "Удаление организации")) { try { _DB_Connection.Delete(DB_Table.TARGET_ORGANIZATIONS, new Dictionary <string, object> { { "id", dgvTargetOrganizations.SelectedRows[0].Cells[0].Value }, { "name", dgvTargetOrganizations.SelectedRows[0].Cells[1].Value } }); UpdateTable(); } catch (MySql.Data.MySqlClient.MySqlException ex) { if (ex.Number == 1217 || ex.Number == 1451) { List <object[]> appEntrances = _DB_Connection.Select(DB_Table.APPLICATIONS_ENTRANCES, new string[] { "application_id" }, new List <Tuple <string, Relation, object> > { new Tuple <string, Relation, object>("target_organization_id", Relation.EQUAL, dgvTargetOrganizations.SelectedRows[0].Cells[0].Value) }); if (appEntrances.Count > 0) { MessageBox.Show("С данной целевой организацией связано заявление. Удаление невозможно."); } else if (SharedClasses.Utility.ShowChoiceMessageWithConfirmation("Целевая организация включена в кампанию. Выполнить удаление?", "Связь с кампанией")) { using (MySql.Data.MySqlClient.MySqlTransaction transaction = _DB_Connection.BeginTransaction()) { _DB_Connection.Delete(DB_Table.CAMPAIGNS_DIRECTIONS_TARGET_ORGANIZATIONS_DATA, new Dictionary <string, object> { { "target_organization_id", dgvTargetOrganizations.SelectedRows[0].Cells[0].Value } }, transaction); _DB_Connection.Delete(DB_Table.TARGET_ORGANIZATIONS, new Dictionary <string, object> { { "id", dgvTargetOrganizations.SelectedRows[0].Cells[0].Value } }, transaction); transaction.Commit(); } UpdateTable(); } } } } }
private void dataGridView_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) { if (DB_Queries.ExaminationHasMarks(_DB_Connection, (uint)e.Row.Cells[dataGridView_ID.Index].Value)) { MessageBox.Show("Невозможно удалить экзамен с распределёнными абитуриентами. Сначала очистите список оценок.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning); e.Cancel = true; } else if (SharedClasses.Utility.ShowUnrevertableActionMessageBox()) { _DB_Connection.Delete(DB_Table.EXAMINATIONS, new Dictionary <string, object> { { "id", e.Row.Cells[dataGridView_ID.Index].Value } }); } else { e.Cancel = true; } }
private void toolStrip_Clear_Click(object sender, EventArgs e) { if (!TryApplyCellChanges()) { return; } if (SharedClasses.Utility.ShowUnrevertableActionMessageBox()) { _DB_Connection.Delete(DB_Table.ENTRANTS_EXAMINATIONS_MARKS, new Dictionary <string, object> { { "examination_id", _ExaminationID } }); dataGridView.Rows.Clear(); } }
private void UpdateDocuments(MySql.Data.MySqlClient.MySqlTransaction transaction) { List <object[]> appDocumentsLinks = _DB_Connection.Select(DB_Table._APPLICATIONS_HAS_DOCUMENTS, new string[] { "documents_id" }, new List <Tuple <string, Relation, object> > { new Tuple <string, Relation, object>("applications_id", Relation.EQUAL, _ApplicationID) }); bool certificateFound = false; bool photosFound = false; if (appDocumentsLinks.Count > 0) { List <object[]> appDocuments = new List <object[]>(); foreach (var documentID in appDocumentsLinks) { appDocuments.Add(_DB_Connection.Select(DB_Table.DOCUMENTS, new string[] { "id", "type", "series", "number", "date", "organization", "original_recieved_date" }, new List <Tuple <string, Relation, object> > { new Tuple <string, Relation, object>("id", Relation.EQUAL, (uint)documentID[0]) })[0]); } foreach (object[] document in appDocuments) { if (document[1].ToString() == "identity") { _DB_Connection.Update(DB_Table.DOCUMENTS, new Dictionary <string, object> { { "series", tbIDDocSeries.Text }, { "number", tbIDDocNumber.Text }, { "date", dtpIDDocDate.Value }, { "organization", tbIssuedBy.Text } }, new Dictionary <string, object> { { "id", (uint)document[0] } }, transaction); _DB_Connection.Update(DB_Table.IDENTITY_DOCS_ADDITIONAL_DATA, new Dictionary <string, object> { { "last_name", tbLastName.Text }, { "first_name", tbFirstName.Text }, { "middle_name", tbMiddleName.Text }, { "gender_dict_id", (uint)FIS_Dictionary.GENDER }, { "gender_id", _DB_Helper.GetDictionaryItemID(FIS_Dictionary.GENDER, cbSex.SelectedItem.ToString()) }, { "subdivision_code", mtbSubdivisionCode.MaskFull? mtbSubdivisionCode.Text: null }, { "type_dict_id", (uint)FIS_Dictionary.IDENTITY_DOC_TYPE }, { "type_id", _DB_Helper.GetDictionaryItemID(FIS_Dictionary.IDENTITY_DOC_TYPE, cbIDDocType.SelectedItem.ToString()) }, { "nationality_dict_id", (uint)FIS_Dictionary.COUNTRY }, { "nationality_id", _DB_Helper.GetDictionaryItemID(FIS_Dictionary.COUNTRY, cbNationality.SelectedItem.ToString()) }, { "birth_date", dtpDateOfBirth.Value }, { "birth_place", tbPlaceOfBirth.Text }, { "reg_region", cbRegion.Text }, { "reg_district", cbDistrict.Text }, { "reg_town", cbTown.Text }, { "reg_street", cbStreet.Text }, { "reg_house", cbHouse.Text }, { "reg_flat", tbAppartment.Text }, { "reg_index", tbPostcode.Text } }, new Dictionary <string, object> { { "document_id", (uint)document[0] } }, transaction); } else if (document[1].ToString() == "school_certificate" || document[1].ToString() == "middle_edu_diploma" || document[1].ToString() == "high_edu_diploma") { string eduDocType = _InstitutionTypes.First(s => s[0] == cbInstitutionType.SelectedItem.ToString())[1]; if ((document[6] as DateTime?) != null && (cbOriginal.Checked)) { _DB_Connection.Update(DB_Table.DOCUMENTS, new Dictionary <string, object> { { "series", tbEduDocSeries.Text }, { "type", eduDocType }, { "number", tbEduDocNumber.Text }, { "organization", cbInstitutionType.SelectedItem.ToString() + "|" + tbInstitutionNumber.Text + "|" + tbInstitutionLocation.Text } }, new Dictionary <string, object> { { "id", (uint)document[0] } }, transaction); } else if ((document[6] as DateTime?) != null && (!cbOriginal.Checked)) { _DB_Connection.Update(DB_Table.DOCUMENTS, new Dictionary <string, object> { { "series", tbEduDocSeries.Text }, { "original_recieved_date", null }, { "type", eduDocType }, { "number", tbEduDocNumber.Text }, { "organization", cbInstitutionType.SelectedItem.ToString() + "|" + tbInstitutionNumber.Text + "|" + tbInstitutionLocation.Text } }, new Dictionary <string, object> { { "id", (uint)document[0] } }, transaction); } else if ((document[6] as DateTime?) == null && (cbOriginal.Checked)) { _DB_Connection.Update(DB_Table.DOCUMENTS, new Dictionary <string, object> { { "series", tbEduDocSeries.Text }, { "original_recieved_date", DateTime.Now }, { "type", eduDocType }, { "number", tbEduDocNumber.Text }, { "organization", cbInstitutionType.SelectedItem.ToString() + "|" + tbInstitutionNumber.Text + "|" + tbInstitutionLocation.Text } }, new Dictionary <string, object> { { "id", (uint)document[0] } }, transaction); } else { _DB_Connection.Update(DB_Table.DOCUMENTS, new Dictionary <string, object> { { "series", tbEduDocSeries.Text }, { "type", eduDocType }, { "number", tbEduDocNumber.Text }, { "organization", cbInstitutionType.SelectedItem.ToString() + "|" + tbInstitutionNumber.Text + "|" + tbInstitutionLocation.Text } }, new Dictionary <string, object> { { "id", (uint)document[0] } }, transaction); } _DB_Connection.Update(DB_Table.OTHER_DOCS_ADDITIONAL_DATA, new Dictionary <string, object> { { "year", cbGraduationYear.SelectedItem } }, new Dictionary <string, object> { { "document_id", (uint)document[0] } }, transaction); } else if (document[1].ToString() == "medical") { List <object[]> spravkaData = _DB_Connection.Select(DB_Table.OTHER_DOCS_ADDITIONAL_DATA, new string[] { "name" }, new List <Tuple <string, Relation, object> > { new Tuple <string, Relation, object>("document_id", Relation.EQUAL, (uint)document[0]) }); if (spravkaData.Count > 0 && spravkaData[0][0].ToString() == DB_Helper.MedCertificate) { certificateFound = true; if (!cbMedCertificate.Checked) { _DB_Connection.Delete(DB_Table.DOCUMENTS, new Dictionary <string, object> { { "id", (uint)document[0] } }, transaction); } } } else if (document[1].ToString() == "photos") { photosFound = true; if (!cbPhotos.Checked) { _DB_Connection.Delete(DB_Table.DOCUMENTS, new Dictionary <string, object> { { "id", (uint)document[0] } }, transaction); } } } if (cbMedCertificate.Checked && !certificateFound) { SaveCertificate(_ApplicationID.Value, transaction); } if (cbPhotos.Checked && !photosFound) { _DB_Connection.Insert( DB_Table._APPLICATIONS_HAS_DOCUMENTS, new Dictionary <string, object> { { "applications_id", _ApplicationID }, { "documents_id", _DB_Connection.Insert(DB_Table.DOCUMENTS, new Dictionary <string, object> { { "type", "photos" } }, transaction) } }, transaction); } } }
private void btSave_Click(object sender, EventArgs e) { List <object[]> select = _DB_Connection.Select(DB_Table.DIRECTIONS, "faculty_short_name", "direction_id"); bool stop = false; foreach (DataGridViewRow r in dgvDirections_.Rows) { bool found = false; if (((bool)r.Cells[1].Value) && ((r.Cells[5].Value == null) || (r.Cells[5].Value.ToString() == ""))) { MessageBox.Show("Не указано сокразение для направления " + r.Cells[3].Value + " \"" + r.Cells[2].Value + "\"."); stop = true; } else if ((select.Count == 0) && ((bool)r.Cells[1].Value)) { _DB_Connection.Insert(DB_Table.DIRECTIONS, new Dictionary <string, object> { { "faculty_short_name", _FacultyShortName }, { "direction_id", r.Cells[0].Value }, { "short_name", r.Cells[5].Value.ToString() } }); } else { found = select.Exists(x => (x[0].ToString() == _FacultyShortName) && (x[1].ToString() == r.Cells[0].Value.ToString())); if (((bool)r.Cells[1].Value) && (!found)) { _DB_Connection.Insert(DB_Table.DIRECTIONS, new Dictionary <string, object> { { "faculty_short_name", _FacultyShortName }, { "direction_id", r.Cells[0].Value }, { "short_name", r.Cells[5].Value.ToString() } }); } else if ((!(bool)r.Cells[1].Value) && (found)) { try { _DB_Connection.Delete(DB_Table.DIRECTIONS, new Dictionary <string, object> { { "faculty_short_name", _FacultyShortName }, { "direction_id", r.Cells[0].Value } }); } catch (MySql.Data.MySqlClient.MySqlException ex) { if (ex.Number == 1217 || ex.Number == 1451) { List <object[]> appEntrances = _DB_Connection.Select(DB_Table.APPLICATIONS_ENTRANCES, new string[] { "application_id" }, new List <Tuple <string, Relation, object> > { new Tuple <string, Relation, object>("faculty_short_name", Relation.EQUAL, _FacultyShortName), new Tuple <string, Relation, object>("direction_id", Relation.EQUAL, r.Cells[0].Value) }); if (appEntrances.Count > 0) { MessageBox.Show("На направление \"" + r.Cells[dgvDirections_Name.Index].Value + "\" подано заявление. Удаление невозможно."); stop = true; } else if (SharedClasses.Utility.ShowChoiceMessageWithConfirmation("Направление имеет профиль или включено в кампанию. Выполнить удаление направления и связанных профилей?", "Связь с кампанией")) { using (MySql.Data.MySqlClient.MySqlTransaction transaction = _DB_Connection.BeginTransaction()) { _DB_Connection.Delete(DB_Table.CAMPAIGNS_PROFILES_DATA, new Dictionary <string, object> { { "profiles_direction_faculty", _FacultyShortName }, { "profiles_direction_id", r.Cells[0].Value } }, transaction); _DB_Connection.Delete(DB_Table.PROFILES, new Dictionary <string, object> { { "faculty_short_name", _FacultyShortName }, { "direction_id", r.Cells[0].Value } }, transaction); _DB_Connection.Delete(DB_Table.CAMPAIGNS_DIRECTIONS_DATA, new Dictionary <string, object> { { "direction_faculty", _FacultyShortName }, { "direction_id", r.Cells[0].Value } }, transaction); _DB_Connection.Delete(DB_Table.DIRECTIONS, new Dictionary <string, object> { { "faculty_short_name", _FacultyShortName }, { "direction_id", r.Cells[0].Value } }, transaction); transaction.Commit(); } } } } } } } if (!stop) { DialogResult = DialogResult.OK; } }
private void UpdateData(DB_Table table, List <object[]> oldList, List <object[]> newList, bool autoGeneratedKey, int keysCount, string[] fieldNames) { using (MySql.Data.MySqlClient.MySqlTransaction transaction = _DB_Connection.BeginTransaction()) { foreach (var oldItem in oldList) { if (newList.Count == 0) { Dictionary <string, object> keyAndValues = new Dictionary <string, object>(); for (int i = 0; i < keysCount; i++) { keyAndValues.Add(fieldNames[i], oldItem[i]); } _DB_Connection.Delete(table, keyAndValues, transaction); } else { bool keysMatch = true; bool valuesMatch = true; int index = -1; do { index++; object[] newItem = newList[index]; for (int i = 0; i < fieldNames.Length; i++) { if (i < keysCount) { if ((keysMatch) && (newItem[i].ToString() != oldItem[i].ToString())) { keysMatch = false; } } else if ((valuesMatch) && (newItem[i].ToString() != oldItem[i].ToString())) { valuesMatch = false; } } }while ((index < newList.Count - 1) && (!((keysMatch) && (index == keysCount - 1)))); if (keysMatch && valuesMatch) { newList.RemoveAt(index); } else if (keysMatch && !valuesMatch) { Dictionary <string, object> columnsAndValues = new Dictionary <string, object>(); for (int i = keysCount; i < fieldNames.Length; i++) { columnsAndValues.Add(fieldNames[i], newList[index][i]); } Dictionary <string, object> keyAndValues = new Dictionary <string, object>(); for (int i = 0; i < keysCount; i++) { keyAndValues.Add(fieldNames[i], newList[index][i]); } _DB_Connection.Update(table, columnsAndValues, keyAndValues, transaction); newList.RemoveAt(index); } else { Dictionary <string, object> keyAndValues = new Dictionary <string, object>(); for (int i = 0; i < keysCount; i++) { keyAndValues.Add(fieldNames[i], oldItem[i]); } _DB_Connection.Delete(table, keyAndValues, transaction); } } } if (newList.Count != 0) { foreach (var newItem in newList) { Dictionary <string, object> columnsAndValues = new Dictionary <string, object>(); if (autoGeneratedKey) { for (int i = keysCount; i < fieldNames.Length; i++) { columnsAndValues.Add(fieldNames[i], newItem[i]); } } else { for (int i = 0; i < keysCount; i++) { columnsAndValues.Add(fieldNames[i], newItem[i]); } for (int i = keysCount; i < fieldNames.Length; i++) { columnsAndValues.Add(fieldNames[i], newItem[i]); } } _DB_Connection.Insert(table, columnsAndValues, transaction); } } transaction.Commit(); } }