Example #1
0
        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();
                }
            }
        }