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 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 bSave_Click(object sender, EventArgs e) { if (!AssureSave()) { return; } Cursor.Current = Cursors.WaitCursor; Dictionary <string, object> data = new Dictionary <string, object> { { "subject_dict_id", (uint)FIS_Dictionary.SUBJECTS }, { "subject_id", _DB_Helper.GetDictionaryItemID(FIS_Dictionary.SUBJECTS, cbSubject.Text) }, { "date", dtpDate.Value }, { "reg_start_date", dtpRegStartDate.Value }, { "reg_end_date", dtpRegEndDate.Value } }; using (MySql.Data.MySqlClient.MySqlTransaction transaction = _DB_Connection.BeginTransaction()) { uint id; if (_ID.HasValue) { _DB_Connection.Update(DB_Table.EXAMINATIONS, data, new Dictionary <string, object> { { "id", _ID } }, transaction); id = _ID.Value; } else { id = _DB_Connection.Insert(DB_Table.EXAMINATIONS, data, transaction); } string[] fields = { "examination_id", "number", "capacity", "priority" }; List <object[]> oldList = _DB_Connection.Select( DB_Table.EXAMINATIONS_AUDIENCES, fields, new List <Tuple <string, Relation, object> > { new Tuple <string, Relation, object>("examination_id", Relation.EQUAL, id) } ); List <object[]> newList = new List <object[]>(); foreach (DataGridViewRow row in dataGridView.Rows) { if (!row.IsNewRow) { newList.Add(new object[] { id, row.Cells[0].Value, row.Cells[1].Value, row.Index }); } } _DB_Helper.UpdateData(DB_Table.EXAMINATIONS_AUDIENCES, oldList, newList, fields, new string[] { "examination_id", "number" }, transaction); transaction.Commit(); } Cursor.Current = Cursors.Default; SharedClasses.Utility.ShowChangesSavedMessage(); DialogResult = DialogResult.OK; }
private void btSave_Click(object sender, EventArgs e) { if (cbIDDocType.SelectedItem.ToString() == DB_Helper.PassportName && (string.IsNullOrWhiteSpace(tbLastName.Text) || string.IsNullOrWhiteSpace(tbFirstName.Text) || string.IsNullOrWhiteSpace(tbIDDocSeries.Text) || string.IsNullOrWhiteSpace(tbIDDocNumber.Text) || string.IsNullOrWhiteSpace(tbPlaceOfBirth.Text) || string.IsNullOrWhiteSpace(cbRegion.Text) || string.IsNullOrWhiteSpace(tbPostcode.Text))) { MessageBox.Show("Обязательные поля в разделе \"Из паспорта\" не заполнены."); } else if (cbIDDocType.SelectedItem.ToString() == DB_Helper.PassportName && !mtbSubdivisionCode.MaskFull) { MessageBox.Show("Код подразделения в разделе \"Из паспорта\" не заполнен."); } else if ((rbDiploma.Checked || rbCertificate.Checked && (int)cbGraduationYear.SelectedItem < 2014) && (string.IsNullOrWhiteSpace(tbEduDocSeries.Text) || string.IsNullOrWhiteSpace(tbEduDocNumber.Text))) { MessageBox.Show("Обязательные поля в разделе \"Из аттестата\" не заполнены."); } else if ((int)cbGraduationYear.SelectedItem >= 2014 && rbCertificate.Checked && (!string.IsNullOrWhiteSpace(tbEduDocSeries.Text) || tbEduDocNumber.Text.Length != 14)) { MessageBox.Show("Неправильный формат серии и номера аттестата для этого года окончания."); } else if (!cbAppAdmission.Checked || !cbEduDoc.Checked || !cbPassportCopy.Checked) { MessageBox.Show("В разделе \"Забираемые документы\" не отмечены обязательные поля."); } else { bool dateOk = true; if ((dtpDateOfBirth.Tag.ToString() == "false" || dtpIDDocDate.Tag.ToString() == "false") && !SharedClasses.Utility.ShowChoiceMessageBox("Значения некоторых полей дат не были изменены. Продолжить?", "Даты не изменены")) { dateOk = false; } if (dateOk) { bool passportOK = true; List <object[]> passportFound = _DB_Connection.Select(DB_Table.DOCUMENTS, new string[] { "id" }, new List <Tuple <string, Relation, object> > { new Tuple <string, Relation, object>("type", Relation.EQUAL, "identity"), new Tuple <string, Relation, object>("series", Relation.EQUAL, tbIDDocSeries.Text), new Tuple <string, Relation, object>("number", Relation.EQUAL, tbIDDocNumber.Text) }); if (passportFound.Count > 0) { List <object[]> oldApplications = _DB_Connection.Select(DB_Table.APPLICATIONS, new string[] { "status", "campaign_id", "id" }, new List <Tuple <string, Relation, object> > { new Tuple <string, Relation, object>("id", Relation.EQUAL, (uint)_DB_Connection.Select(DB_Table._APPLICATIONS_HAS_DOCUMENTS, new string[] { "applications_id" }, new List <Tuple <string, Relation, object> > { new Tuple <string, Relation, object>("documents_id", Relation.EQUAL, (uint)passportFound[0][0]) })[0][0]) }); foreach (object[] app in oldApplications) { if ((uint)app[1] == _CurrCampainID && (uint)app[2] != _ApplicationID) { passportOK = false; if (app[0].ToString() != "withdrawn") { MessageBox.Show("В данной кампании уже существует действующее заявление на этот паспорт."); break; } else if (SharedClasses.Utility.ShowChoiceMessageBox("В данной кампании уже существует заявление на этот паспорт, по которому забрали документы. Создать новое заявление на этот паспорт?", "Паспорт уже существует")) { passportOK = true; } } } } if (passportOK) { Cursor.Current = Cursors.WaitCursor; using (MySql.Data.MySqlClient.MySqlTransaction transaction = _DB_Connection.BeginTransaction()) { uint applID; if (!_ApplicationID.HasValue) { applID = SaveApplication(transaction); } else { applID = _ApplicationID.Value; _EditingDateTime = DateTime.Now; UpdateApplication(transaction); } transaction.Commit(); _ApplicationID = applID; btPrint.Enabled = true; btWithdraw.Enabled = true; } Cursor.Current = Cursors.Default; } } } }
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(); } }
private void bOK_Click(object sender, EventArgs e) { if (tbNumber.Text == "") { MessageBox.Show("Не заполнен номер протокола.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } Cursor.Current = Cursors.WaitCursor; EducationLevel eduLevel = new DB_Helper(_DB_Connection).GetCampaignType(Classes.Settings.CurrentCampaignID) == DB_Helper.CampaignType.MASTER ? EducationLevel.MASTER : EducationLevel.BACHELOR; //TODO object[] buf = _DB_Connection.Select( DB_Table.ORDERS, new string[] { "type", "edu_form_id", "edu_source_id", "faculty_short_name" }, new List <Tuple <string, Relation, object> > { new Tuple <string, Relation, object>("number", Relation.EQUAL, _Number) } )[0]; string type = buf[0].ToString(); uint eduForm = (uint)buf[1]; bool paid = (uint)buf[2] == 15; //TODO string faculty = buf[3].ToString(); var applications = _DB_Connection.Select( DB_Table.ORDERS_HAS_APPLICATIONS, new string[] { "applications_id" }, new List <Tuple <string, Relation, object> > { new Tuple <string, Relation, object>("orders_number", Relation.EQUAL, _Number) } ).Join( _DB_Connection.Select(DB_Table.APPLICATIONS, "id", "status"), k1 => k1[0], k2 => k2[0], (s1, s2) => new { ID = (uint)s2[0], Status = s2[1].ToString() } ); using (MySql.Data.MySqlClient.MySqlTransaction transaction = _DB_Connection.BeginTransaction()) { if (type == "admission") { foreach (var appl in applications) { _DB_Connection.Update( DB_Table.ORDERS_HAS_APPLICATIONS, new Dictionary <string, object> { { "record_book_number", GetFreeRecordBookNumber(eduForm, paid, eduLevel) } }, new Dictionary <string, object> { { "orders_number", _Number }, { "applications_id", appl.ID } }, transaction ); _DB_Connection.Update( DB_Table.APPLICATIONS, new Dictionary <string, object> { { "status", _Statuses.Single(s1 => s1.Item2 == (_Statuses.Single(s2 => s2.Item1 == appl.Status).Item2 | (paid?ApplicationStatus.ADM_PAID:ApplicationStatus.ADM_BUDGET))).Item1 }//TODO !!! }, new Dictionary <string, object> { { "id", appl.ID } }, transaction ); } } else if (type == "exception") { foreach (var appl in applications) { _DB_Connection.Update( DB_Table.APPLICATIONS, new Dictionary <string, object> { { "status", _Statuses.Single(s1 => s1.Item2 == (_Statuses.Single(s2 => s2.Item1 == appl.Status).Item2 & ~(paid ? ApplicationStatus.ADM_PAID : ApplicationStatus.ADM_BUDGET))).Item1 } //TODO !!! }, new Dictionary <string, object> { { "id", appl.ID } }, transaction ); } } else { ushort places = (ushort)_DB_Connection.Select( DB_Table.CAMPAIGNS_FACULTIES_DATA, new string[] { "hostel_places" }, new List <Tuple <string, Relation, object> > { new Tuple <string, Relation, object>("campaign_id", Relation.EQUAL, Classes.Settings.CurrentCampaignID), new Tuple <string, Relation, object>("faculty_short_name", Relation.EQUAL, faculty) })[0][0]; ushort occupied = (ushort)(_DB_Connection.Select( DB_Table.ORDERS, new string[] { "number" }, new List <Tuple <string, Relation, object> > { new Tuple <string, Relation, object>("type", Relation.EQUAL, "hostel"), new Tuple <string, Relation, object>("campaign_id", Relation.EQUAL, Classes.Settings.CurrentCampaignID), new Tuple <string, Relation, object>("faculty_short_name", Relation.EQUAL, faculty), new Tuple <string, Relation, object>("protocol_number", Relation.NOT_EQUAL, null) }).Join( _DB_Connection.Select(DB_Table.ORDERS_HAS_APPLICATIONS), k1 => k1[0], k2 => k2[0], (s1, s2) => s2[1] ).Count() + applications.Count()); if (places < occupied && MessageBox.Show( "Число мест в общежитии, выделенных для факультета, меньше суммарного числа абитуриентов, назначенных на них по приказам. Продолжить регистрацию?", "Внимание", MessageBoxButtons.YesNo, MessageBoxIcon.Warning ) == DialogResult.No) { return; } } _DB_Connection.Update( DB_Table.ORDERS, new Dictionary <string, object> { { "protocol_number", ushort.Parse(tbNumber.Text) }, { "protocol_date", dtpDate.Value } }, new Dictionary <string, object> { { "number", _Number } }, transaction ); transaction.Commit(); } Cursor.Current = Cursors.Default; DialogResult = DialogResult.OK; }