using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Data.SqlClient; namespace hospital { public partial class insertMedCard : Form { SqlConnection sqlConnection = null; SqlDataReader reader = null; SqlCommand a = null; public insertMedCard() { InitializeComponent(); } private void insertMedCard_Load(object sender, EventArgs e) { try { FormCreating.openConnection(ref sqlConnection); disabilityCB.Items.Add("Нет"); disabilityCB.Items.Add("Да"); disabilityCB.SelectedIndex = 0; a = new SqlCommand($"select name_blood from blood_type", sqlConnection); reader = a.ExecuteReader(); while (reader.Read()) { bloodCB.Items.Add($"{reader.GetString(0)}"); } reader.Close(); bloodCB.SelectedIndex = 0; a = new SqlCommand($"select name_factor from rh_factor", sqlConnection); reader = a.ExecuteReader(); while (reader.Read()) { rhFactorCB.Items.Add($"{reader.GetString(0)}"); } reader.Close(); rhFactorCB.SelectedIndex = 0; } catch { MessageBox.Show("Произошла непредвиденная ошибка", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); debugAndTrace.writeInFile("ERROR"); } } private void disabilityCB_SelectedIndexChanged(object sender, EventArgs e) { try { if (disabilityCB.SelectedItem.Equals("Да")) { descriptionDisabilityRTB.Visible = true; } else { descriptionDisabilityRTB.Visible = false; } } catch { MessageBox.Show("Произошла непредвиденная ошибка", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); debugAndTrace.writeInFile("ERROR"); } } private void add_Click(object sender, EventArgs e) { try { bool checkTB = false, checkMTB = false; foreach (TextBox textBox in this.Controls.OfType()) { if (String.IsNullOrEmpty(textBox.Text) && textBox.Visible == true) { checkTB = true; break; } } foreach (MaskedTextBox maskedTextBox in this.Controls.OfType()) { if (!maskedTextBox.MaskCompleted) { checkMTB = true; break; } } if (!checkMTB && !checkTB) { DateTime date1 = DateTime.Parse(birthDateDTP.Text); DateTime date2 = DateTime.Parse(passportDateDTP.Text); SqlCommand bloodIndex = new SqlCommand($"select id_blood from blood_type where name_blood like N'{bloodCB.SelectedItem}'", sqlConnection); SqlCommand factorIndex = new SqlCommand($"select id_factor from rh_factor where name_factor like N'{rhFactorCB.SelectedItem}'", sqlConnection); a = new SqlCommand($"insert into [medical_cards] ([Surname_Patient], [Name_Patient], [Midname_Patient], [Date_Birthday_Patient], [Telephone_Patient], [IIAN_Patient], [Passport_Number_Patient], [Passport_Date_Patient], [Passport_Place_Patient], [Passport_Code_Patient], [Number_Policy_Patient], [Disability_Patient], [Description_Disability], [ID_Blood], [ID_Factor], [WorkStudy_Place], [isIll]) values (@Surname_Patient, @Name_Patient, @Midname_Patient, @Date_Birthday_Patient, @Telephone_Patient, @IIAN_Patient, @Passport_Number_Patient, @Passport_Date_Patient, @Passport_Place_Patient, @Passport_Code_Patient, @Number_Policy_Patient, @Disability_Patient, @Description_Disability, @ID_Blood, @ID_Factor, @WorkStudy_Place, @isIll)", sqlConnection); a.Parameters.AddWithValue("Surname_Patient", surnameTB.Text); a.Parameters.AddWithValue("Name_Patient", nameTB.Text); a.Parameters.AddWithValue("Midname_Patient", midnameTB.Text); a.Parameters.AddWithValue("Date_Birthday_Patient", $"{date1.Day}/{date1.Month}/{date1.Year}"); a.Parameters.AddWithValue("Telephone_Patient", telephoneMTB.Text); a.Parameters.AddWithValue("IIAN_Patient", iianMTB.Text); a.Parameters.AddWithValue("Passport_Number_Patient", passportNumberMTB.Text); a.Parameters.AddWithValue("Passport_Date_Patient", $"{date2.Day}/{date2.Month}/{date2.Year}"); a.Parameters.AddWithValue("Passport_Place_Patient", passpordPlaceTB.Text); a.Parameters.AddWithValue("Passport_Code_Patient", passportCodeMTB.Text); a.Parameters.AddWithValue("Number_Policy_Patient", policyNumberMTB.Text); a.Parameters.AddWithValue("Disability_Patient", disabilityCB.SelectedItem); a.Parameters.AddWithValue("Description_Disability", descriptionDisabilityRTB.Text); a.Parameters.AddWithValue("ID_Blood", bloodIndex.ExecuteScalar().ToString()); a.Parameters.AddWithValue("ID_Factor", factorIndex.ExecuteScalar().ToString()); a.Parameters.AddWithValue("WorkStudy_Place", workStudyPlaceRTB.Text); a.Parameters.AddWithValue("isIll", 0); Array.Resize(ref auth.data, 16); auth.data[0] = $"Фамилия: {surnameTB.Text}"; auth.data[1] = $"Имя: {nameTB.Text}"; auth.data[2] = $"Отчество: {midnameTB.Text}"; auth.data[3] = $"Дата рождения: {date1.Day}/{date1.Month}/{date1.Year}"; auth.data[4] = $"Телефон: {telephoneMTB.Text}"; auth.data[5] = $"СНИЛС: {iianMTB.Text}"; auth.data[6] = $"Серия и номер паспорта: {passportNumberMTB.Text}"; auth.data[7] = $"Дата выдачи паспорта: {date2.Day}/{date2.Month}/{date2.Year}"; auth.data[8] = $"Кем выдан: {passpordPlaceTB.Text}"; auth.data[9] = $"Код подразделения: {passportCodeMTB.Text}"; auth.data[10] = $"Номер страхового полиса: {policyNumberMTB.Text}"; auth.data[11] = $"Инвалидность: {disabilityCB.SelectedIndex}"; auth.data[12] = $"Описание инвалидности(если есть): {descriptionDisabilityRTB.Text}"; auth.data[13] = $"Группа крови: {bloodCB.SelectedItem}"; auth.data[14] = $"Резус фактор: {rhFactorCB.SelectedItem}"; auth.data[15] = $"Описание трудовой деятельности: {workStudyPlaceRTB.Text}"; if (a.ExecuteNonQuery() == 1) { MessageBox.Show("Добавление данных произошло успешно", "Уведомление", MessageBoxButtons.OK, MessageBoxIcon.Information); debugAndTrace.writeInFile("Добавление медицинской карты", auth.data); debugAndTrace.writeInFile("Переход на главную форму"); this.Close(); } else { MessageBox.Show("Произошла ошибка", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); debugAndTrace.writeInFile("Ошибка добавления данных медицинской карты", auth.data); } } else { MessageBox.Show("Заполнены не все поля", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); debugAndTrace.writeInFile("Error, заполнены не все поля"); } } catch { MessageBox.Show("Произошла непредвиденная ошибка", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); debugAndTrace.writeInFile("ERROR"); } } private void backBTN_Click(object sender, EventArgs e) { try { var res = MessageBox.Show("Уверены, что хотите отменить добавление медицинской карты?", "Предупреждение", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (res == DialogResult.Yes) { debugAndTrace.writeInFile("Отмена добавления медицинской карты"); this.Close(); } else { MessageBox.Show("Действие отменено", "Уведомление", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch { MessageBox.Show("Произошла непредвиденная ошибка", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); debugAndTrace.writeInFile("ERROR"); } } private void label15_Click(object sender, EventArgs e) { } private void workStudyPlaceRTB_TextChanged(object sender, EventArgs e) { } } }