Ejemplo n.º 1
0
        private void CreateNewRecord(object sender, EventArgs e)
        {
            Messages      msg = new Messages();
            AdminMainForm amf = new AdminMainForm();

            if (CBCity.Text == "")
            {
                msg.DataError("Выберите город!");
                CBCity.Focus();
            }
            else if (CBCountry.Text == "")
            {
                msg.DataError("Выберите страну!");
                CBCountry.Focus();
            }
            else if (CBRegion.Text == "")
            {
                msg.DataError("Выберите регион!");
                CBRegion.Focus();
            }
            else if (CBSetClinic.Text == "")
            {
                msg.DataError("Выберите поликлинику!");
                CBSetClinic.Focus();
            }
            else
            {
                conn.Open();
                sql = "SELECT ID_CLINIC FROM CLINIC WHERE CLINIC_NAME = '" + CBSetClinic.Text + "'";
                MySqlCommand clinicid = new MySqlCommand(sql, conn);
                cid = Convert.ToInt32(clinicid.ExecuteScalar());
                switch (sw)
                {
                case 0:
                    sql = "SELECT COUNT(*) " +
                          "FROM CLINIC_HAS_PERSON " +
                          "WHERE PERSON_PERSON_IIN = '" + TextIIN.Text + "' AND " +
                          "CLINIC_ID_CLINIC = " + cid + "";
                    MySqlCommand pcheck = new MySqlCommand(sql, conn);
                    COUNT = Convert.ToInt32(pcheck.ExecuteScalar());
                    if (COUNT == 0)
                    {
                        sql = "INSERT INTO CLINIC_HAS_PERSON " +
                              "(PERSON_PERSON_IIN, CLINIC_ID_CLINIC) " +
                              "VALUES ('" + TextIIN.Text + "'," + cid + ")";
                        MySqlCommand pins = new MySqlCommand(sql, conn);
                        if (pins.ExecuteNonQuery() == 1)
                        {
                            msg.WriteSuccess();
                            this.Close();
                            amf.Show();
                            conn.Close();
                        }
                        else
                        {
                            msg.WriteError();
                            conn.Close();
                        }
                    }
                    else
                    {
                        msg.DataError("Запись уже существует в базе данных!");
                        conn.Close();
                    }
                    break;

                case 1:
                    sql = "SELECT ID_DOCTOR FROM DOCTOR WHERE DOC_IIN = '" + TextIIN.Text + "'";
                    MySqlCommand dociin = new MySqlCommand(sql, conn);
                    did = Convert.ToInt32(dociin.ExecuteScalar());

                    sql = "SELECT COUNT(*) " +
                          "FROM CLINIC_HAS_DOCTOR " +
                          "WHERE DOCTOR_ID_DOCTOR = " + did + " AND " +
                          "CLINIC_ID_CLINIC = " + cid + "";
                    MySqlCommand dcheck = new MySqlCommand(sql, conn);
                    COUNT = Convert.ToInt32(dcheck.ExecuteScalar());
                    if (COUNT == 0)
                    {
                        sql = "INSERT INTO CLINIC_HAS_DOCTOR " +
                              "(DOCTOR_ID_DOCTOR, CLINIC_ID_CLINIC) " +
                              "VALUES (" + did + " ," + cid + ")";
                        MySqlCommand dins = new MySqlCommand(sql, conn);
                        if (dins.ExecuteNonQuery() == 1)
                        {
                            msg.WriteSuccess();
                            this.Close();
                            amf.Show();
                            conn.Close();
                        }
                        else
                        {
                            msg.WriteError();
                            conn.Close();
                        }
                    }
                    else
                    {
                        msg.DataError("Запись уже существует в базе данных!");
                        conn.Close();
                    }
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        private void CreateNewClinic(object sender, EventArgs e)
        {
            Messages msg = new Messages();

            if (TextNameClPh.Text == "")
            {
                msg.DataError("Введите название!");
                TextNameClPh.Focus();
            }
            else if (TextZipClPh.Text == "")
            {
                msg.DataError("Введите почтовый индекс!");
                TextZipClPh.Focus();
            }
            else if (CBCity.Text == "")
            {
                msg.DataError("Выберите город!");
                CBCity.Focus();
            }
            else if (CBCountry.Text == "")
            {
                msg.DataError("Выберите страну!");
                CBCountry.Focus();
            }
            else if (CBRegion.Text == "")
            {
                msg.DataError("Выберите регион!");
                CBRegion.Focus();
            }
            else if (TextStreetClPh.Text == "")
            {
                msg.DataError("Введите улицу!");
                TextStreetClPh.Focus();
            }
            else if (TextBuildingClPh.Text == "")
            {
                msg.DataError("Введите номер строения!");
                TextBuildingClPh.Focus();
            }
            else if (TextPhoneClPh.Text == "")
            {
                msg.DataError("Введите номер телефона!");
                TextPhoneClPh.Focus();
            }
            else
            {
                conn.Open();
                sql = "SELECT ID_CITY FROM CITY WHERE CITY ='" + CBCity.Text + "'";
                MySqlCommand cid = new MySqlCommand(sql, conn);
                cityid = Convert.ToInt32(cid.ExecuteScalar());
            }
            sql = "SELECT COUNT(*) FROM CLINIC WHERE CLINIC_NAME = '" + TextNameClPh.Text + "'";
            MySqlCommand querycheckcl = new MySqlCommand(sql, conn);

            COUNT = Convert.ToInt32(querycheckcl.ExecuteScalar());
            if (COUNT == 0)
            {
                sql = "INSERT INTO CLINIC (CLINIC_NAME, " +
                      "CITY_ID_CITY, " +
                      "CLINIC_ZIP_CODE, " +
                      "CLINIC_STREET, " +
                      "CLINIC_BUILDING) " +
                      "VALUES ('" + TextNameClPh.Text + "', " +
                      "" + cityid + "," +
                      " '" + TextZipClPh.Text + "'," +
                      " '" + TextStreetClPh.Text + "'," +
                      " '" + TextBuildingClPh.Text + "')";
                MySqlCommand cmdcl = new MySqlCommand(sql, conn);
                if (cmdcl.ExecuteNonQuery() == 1)
                {
                    sql = "SELECT ID_CLINIC FROM CLINIC WHERE CLINIC_NAME = '" + TextNameClPh.Text + "'";
                    MySqlCommand clquery = new MySqlCommand(sql, conn);
                    id  = (int)clquery.ExecuteScalar();
                    sql = "INSERT INTO CLINIC_PHONE (CLINIC_PHONE, CLINIC_ID_CLINIC) VALUES ('" + TextPhoneClPh.Text + "', " + id + ")";
                    MySqlCommand clphone = new MySqlCommand(sql, conn);
                    if (clphone.ExecuteNonQuery() == 1)
                    {
                        msg.WriteSuccess();
                        this.Close();
                        AdminMainForm amf = new AdminMainForm();
                        amf.Show();
                        conn.Close();
                    }
                    else
                    {
                        msg.WriteError();
                        conn.Close();
                    }
                }
                else
                {
                    msg.WriteError();
                    conn.Close();
                }
            }
            else
            {
                msg.DataError("Такое медицинское учреждение уже существует!");
                conn.Close();
            }
        }