private void CheckUser(object sender, EventArgs e) { Messages msg = new Messages(); if (TextIIN.Text == "") { msg.DataError("Введите ИИН!"); TextIIN.Focus(); } conn.Open(); switch (sw) { case 0: sql = "SELECT COUNT(*) FROM PERSON WHERE PERSON_IIN = '" + TextIIN.Text + "'"; MySqlCommand checkp = new MySqlCommand(sql, conn); COUNT = Convert.ToInt32(checkp.ExecuteScalar()); break; case 1: sql = "SELECT COUNT(*) FROM DOCTOR WHERE DOC_IIN = '" + TextIIN.Text + "'"; MySqlCommand checkd = new MySqlCommand(sql, conn); COUNT = Convert.ToInt32(checkd.ExecuteScalar()); break; } if (COUNT == 1) { PanelClinic.Visible = true; } 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; } } } }
private void CreateNewDoctor(object sender, EventArgs e) { Messages msg = new Messages(); if (TextLastName.Text == "") { msg.DataError("Введите фамилию!"); TextLastName.Focus(); } else if (TextFirstName.Text == "") { msg.DataError("Введите имя!"); TextFirstName.Focus(); } else if (TextIIN.Text.Length != 12) { msg.DataError("Введите корректный ИИН!"); TextIIN.Focus(); } else if (TextEmail.Text == "") { msg.DataError("Введите адрес электронной почты!"); TextEmail.Focus(); } else if (TextPhone.Text == "") { msg.DataError("Введите номер телефона!"); TextPhone.Focus(); } else if (TextPassword.Text == "") { msg.DataError("Введите пароль!"); TextPassword.Focus(); } else if (TextPassword.Text != TextRepPassword.Text) { msg.DataError("Пароли не совпадают!"); TextPassword.Focus(); } else if (CBSetSpec.Text == "") { msg.DataError("Выберите специализацию!"); CBSetSpec.Focus(); } else { conn.Open(); sql = "SELECT COUNT(*) FROM DOCTOR WHERE DOC_EMAIL = '" + TextEmail.Text + "'"; MySqlCommand checkEmail = new MySqlCommand(sql, conn); COUNT = Convert.ToInt32(checkEmail.ExecuteScalar()); if (COUNT == 0) { sql = "SELECT COUNT(*) FROM DOCTOR WHERE DOC_IIN = '" + TextIIN.Text + "'"; MySqlCommand checkIIN = new MySqlCommand(sql, conn); COUNT = Convert.ToInt32(checkIIN.ExecuteScalar()); if (COUNT == 0) { sql = "INSERT INTO DOCTOR (DOC_LASTNAME, " + "DOC_FIRSTNAME, " + "DOC_PATRONYMIC, " + "DOC_IIN, " + "DOC_EMAIL, " + "DOC_PHONE, " + "DOC_PASSWORD, " + "SPECIALISATION_ID_SPEC) " + "VALUES ('" + TextLastName.Text + "', " + "'" + TextFirstName.Text + "', " + "'" + TextPatronymic.Text + "', " + "'" + TextIIN.Text + "', " + "'" + TextEmail.Text + "', " + "'" + TextPhone.Text + "', " + "'" + TextPassword.Text + "', " + "" + idspec + ")"; MySqlCommand insdoc = new MySqlCommand(sql, conn); if (insdoc.ExecuteNonQuery() == 1) { msg.WriteSuccess(); this.Close(); AdminMainForm amf = new AdminMainForm(); amf.Show(); conn.Close(); } else { msg.WriteError(); conn.Close(); } } else { msg.DataError("ИИН уже существует в системе!"); conn.Close(); } } else { msg.DataError("Электронный адрес уже существует в системе!"); conn.Close(); } } }
private void AddNewRecord(object sender, EventArgs e) { Messages msg = new Messages(); if (CBSetClinic.Text == "") { msg.DataError("Выберите поликлинику!"); CBSetClinic.Focus(); } else if (TextIIN.Text == "") { msg.DataError("Введите ИИН!"); TextIIN.Focus(); } else { conn.Open(); sql = "SELECT COUNT(*) " + "FROM PERSON WHERE PERSON_IIN = '" + TextIIN.Text + "' "; MySqlCommand check = new MySqlCommand(sql, conn); COUNT = Convert.ToInt32(check.ExecuteScalar()); if (COUNT == 0) { msg.DataError("Пациент не найден в базе данных!"); conn.Close(); } else { sql = "SELECT COUNT(*) " + "FROM PERSON_HAS_DOCTOR " + "WHERE PERSON_PERSON_IIN = '" + TextIIN.Text + "' " + "AND CLINIC_ID_CLINIC = " + cid + " " + "AND DOCTOR_ID_DOCTOR = " + did + ""; MySqlCommand checkpc = new MySqlCommand(sql, conn); COUNT = Convert.ToInt32(checkpc.ExecuteScalar()); if (COUNT == 0) { sql = "INSERT INTO PERSON_HAS_DOCTOR (PERSON_PERSON_IIN, CLINIC_ID_CLINIC, DOCTOR_ID_DOCTOR) " + "VALUES ('" + TextIIN.Text + "'," + cid + ", " + did + ")"; MySqlCommand ins = new MySqlCommand(sql, conn); if (ins.ExecuteNonQuery() == 1) { msg.WriteSuccess(); this.Close(); conn.Close(); DoctorMode doctorMode = new DoctorMode(did); doctorMode.Show(); } else { msg.WriteError(); conn.Close(); } } else { msg.DataError("Запись уже существует в базе данных!"); conn.Close(); } } } }
private void CreateNewPerson(object sender, EventArgs e) { Messages msg = new Messages(); if (TextLastName.Text == "") { msg.DataError("Введите фамилию!"); TextLastName.Focus(); } else if (TextFirstName.Text == "") { msg.DataError("Введите имя!"); TextFirstName.Focus(); } else if (SexSet.Text == "") { msg.DataError("Выберите пол!"); SexSet.Focus(); } else if (TextIIN.Text.Length != 12) { msg.DataError("Введите корректный ИИН!"); TextIIN.Focus(); } else if (TextEmail.Text == "") { msg.DataError("Введите адрес электронной почты!"); TextEmail.Focus(); } else if (TextPhone.Text == "") { msg.DataError("Введите номер телефона!"); TextPhone.Focus(); } else if (TextPassword.Text == "") { msg.DataError("Введите пароль!"); TextPassword.Focus(); } else if (TextPassword.Text != TextRepPassword.Text) { msg.DataError("Пароли не совпадают!"); TextPassword.Focus(); } else { conn.Open(); sqlins = "INSERT INTO PERSON (PERSON_LASTNAME, " + "PERSON_FIRSTNAME, " + "PERSON_PATRONYMIC, " + "PERSON_BIRTHDAY, " + "PERSON_IIN, " + "PERSON_PASSWORD, " + "PERSON_EMAIL, " + "PERSON_SEX, " + "PERSON_PHONE) " + "VALUES ('" + TextLastName.Text + "', " + "'" + TextFirstName.Text + "', " + "'" + TextPatronymic.Text + "', " + "'" + this.BirthdaySet.Text + "', " + "'" + TextIIN.Text + "', " + "'" + TextPassword.Text + "', " + "'" + TextEmail.Text + "', " + "'" + SexSet.Text + "'," + "'" + TextPhone.Text + "')"; sql = "SELECT COUNT(*) FROM PERSON WHERE PERSON_EMAIL = '" + TextEmail.Text + "'"; MySqlCommand checkEmail = new MySqlCommand(sql, conn); COUNT = Convert.ToInt32(checkEmail.ExecuteScalar()); if (COUNT == 0) { sql = "SELECT COUNT(*) FROM PERSON WHERE PERSON_IIN = '" + TextIIN.Text + "'"; MySqlCommand checkIIN = new MySqlCommand(sql, conn); COUNT = Convert.ToInt32(checkIIN.ExecuteScalar()); if (COUNT == 0) { MySqlCommand cmd = new MySqlCommand(sqlins, conn); if (cmd.ExecuteNonQuery() == 1) { msg.WriteSuccess(); this.Close(); AdminMainForm amf = new AdminMainForm(); amf.Show(); conn.Close(); } else { msg.WriteError(); conn.Close(); } } else { msg.DataError("Номер документа уже существует в системе!"); conn.Close(); COUNT = 0; } } } }