private void CreateNewDrug(object sender, EventArgs e) { Messages msg = new Messages(); if (TextNameMedicine.Text == "") { msg.DataError("Введите название!"); TextNameMedicine.Focus(); } else if (CBSetCategory.Text == "") { msg.DataError("Выберите категорию!"); CBSetCategory.Focus(); } else if (CBSetGroup.Text == "") { msg.DataError("Выберите группу!"); CBSetGroup.Focus(); } else if (CBSetType.Text == "") { msg.DataError("Выберите тип!"); CBSetType.Focus(); } else { conn.Open(); sql = "SELECT COUNT(*) FROM DRUG WHERE DRUG_NAME = '" + TextNameMedicine.Text + "'"; MySqlCommand check = new MySqlCommand(sql, conn); COUNT = Convert.ToInt32(check.ExecuteScalar()); if (COUNT == 0) { sql = "SELECT ID_GROUP FROM DRUG_GROUP WHERE GROUP_NAME = '" + CBSetGroup.Text + "'"; MySqlCommand grid = new MySqlCommand(sql, conn); groupid = Convert.ToInt32(grid.ExecuteScalar()); sql = "SELECT ID_TYPE FROM DRUG_TYPE WHERE TYPE_NAME = '" + CBSetType.Text + "'"; MySqlCommand tyid = new MySqlCommand(sql, conn); typeid = Convert.ToInt32(tyid.ExecuteScalar()); sql = "INSERT INTO DRUG (DRUG_NAME, " + "DRUG_TYPE_ID_TYPE, " + "DRUG_GROUP_ID_GROUP) " + "VALUES ('" + TextNameMedicine.Text + "'," + "" + typeid + ", " + "" + groupid + ")"; MySqlCommand medins = new MySqlCommand(sql, conn); if (medins.ExecuteNonQuery() == 1) { msg.WriteSuccess(); this.Close(); AdminMainForm amf = new AdminMainForm(); amf.Show(); conn.Close(); } else { msg.WriteError(); conn.Close(); } } else { msg.DataError("Препарат уже существует в базе!"); conn.Close(); } } }
private void SetMedicineToPerson(object sender, EventArgs e) { iin = TextIIN.Text; Messages msg = new Messages(); if (CBSetType.Text == "") { msg.DataError("Выберите тип препарата!"); CBSetType.Focus(); } else if (TextIIN.Text.Length != 12) { msg.DataError("Введите корректный ИИН!"); TextIIN.Focus(); } else if (CBSetCategory.Text == "") { msg.DataError("Выберите категорию препарата!"); CBSetCategory.Focus(); } else if (CBSetGroup.Text == "") { msg.DataError("Выберите группу препарата!"); CBSetGroup.Focus(); } else if (CBSetName.Text == "") { msg.DataError("Выберите название препарата!"); CBSetName.Focus(); } else { conn.Open(); sql = "SELECT COUNT(*) " + "FROM PERSON_HAS_DOCTOR " + "WHERE PERSON_HAS_DOCTOR.PERSON_PERSON_IIN = '" + iin + "' " + "AND PERSON_HAS_DOCTOR.DOCTOR_ID_DOCTOR = " + did + ""; MySqlCommand checkperson = new MySqlCommand(sql, conn); COUNT = Convert.ToInt32(checkperson.ExecuteScalar()); if (COUNT == 0) { msg.DataError("Невозможно назначить препарат!"); conn.Close(); } else { sql = "SELECT ID_MEDICINE FROM DRUG WHERE DRUG_NAME = '" + CBSetName.Text + "' "; MySqlCommand medicineid = new MySqlCommand(sql, conn); mid = Convert.ToInt32(medicineid.ExecuteScalar()); switch (CBSetType.SelectedIndex) { case 0: sql = "SELECT COUNT(*) FROM FORBIDDEN_DRUG WHERE MEDICINE_ID_MEDICINE = " + mid + ""; MySqlCommand recmed = new MySqlCommand(sql, conn); COUNT = Convert.ToInt32(recmed.ExecuteScalar()); if (COUNT == 0) { sql = "SELECT COUNT(*) FROM RECOMMENDED_DRUG " + "WHERE MEDICINE_ID_MEDICINE = " + mid + " AND PERSON_PERSON_IIN = " + iin + ""; MySqlCommand checkmed = new MySqlCommand(sql, conn); COUNT = Convert.ToInt32(checkmed.ExecuteScalar()); if (COUNT == 0) { sql = "INSERT INTO RECOMMENDED_DRUG ( PERSON_PERSON_IIN, MEDICINE_ID_MEDICINE) " + "VALUES ('" + iin + "', " + mid + ")"; MySqlCommand insrecmed = new MySqlCommand(sql, conn); if (insrecmed.ExecuteNonQuery() == 1) { msg.WriteSuccess(); this.Close(); DoctorMode doctorMode = new DoctorMode(did); doctorMode.Show(); conn.Close(); } else { msg.WriteError(); conn.Close(); } } else { msg.DataError("Запись уже существует!"); conn.Close(); } } else { msg.DataError("Ошибка совместимости!"); conn.Close(); } break; case 1: sql = "SELECT COUNT(*) FROM RECOMMENDED_DRUG WHERE MEDICINE_ID_MEDICINE = " + mid + ""; MySqlCommand formed = new MySqlCommand(sql, conn); COUNT = Convert.ToInt32(formed.ExecuteScalar()); if (COUNT == 0) { sql = "SELECT COUNT(*) FROM FORBIDDEN_DRUG " + "WHERE MEDICINE_ID_MEDICINE = " + mid + " AND PERSON_PERSON_IIN = " + iin + ""; MySqlCommand checkmed = new MySqlCommand(sql, conn); COUNT = Convert.ToInt32(checkmed.ExecuteScalar()); if (COUNT == 0) { sql = "INSERT INTO FORBIDDEN_DRUG (MEDICINE_ID_MEDICINE, PERSON_PERSON_IIN) " + "VALUES (" + mid + ",'" + iin + "')"; MySqlCommand insrformed = new MySqlCommand(sql, conn); if (insrformed.ExecuteNonQuery() == 1) { msg.WriteSuccess(); this.Close(); DoctorMode doctorMode = new DoctorMode(did); doctorMode.Show(); } else { msg.WriteError(); conn.Close(); } } else { msg.DataError("Запись уже существует!"); conn.Close(); } } else { msg.DataError("Ошибка совместимости!"); conn.Close(); } break; } } } }