Ejemplo n.º 1
0
        private void btnAceptar_Click(object sender, EventArgs e)
        {
            this.btnAceptar.Visible  = false;
            this.btnCancelar.Visible = false;
            this.btnBuscar.Enabled   = true;
            if (Operacion == 1)  // Buscar
            {
                cbxEspecialidad.DataSource = null;
                cbxEspecialidad.Text       = "";
                tbxCosto.Text = "0";

                if (!ValidarNumero(this.txbDni.Text.ToString(), "Documento"))
                {
                    this.btnAceptar.Visible  = true;
                    this.btnCancelar.Visible = true;
                    this.btnBuscar.Enabled   = false;
                    return;
                }
                this.medico = new Medico();
                MedicoNegocio mediconegocio = new MedicoNegocio();
                mediconegocio.Leer(this.txbDni.Text.Trim(), ref medico);
                if (medico.matricula == 0)
                {
                    MessageBox.Show("Profesional NO Registrado");
                    this.medico              = null;
                    this.btnAceptar.Visible  = true;
                    this.btnCancelar.Visible = true;
                    return;
                }
                this.groupBox1.Enabled = true;
                if (id == 2)
                {
                    this.btnModificar.Enabled           = true;
                    this.llbAgregarEspecialidad.Enabled = true;
                    this.lklActualizarHorarios.Enabled  = true;
                    this.btnAgregar.Enabled             = true;
                }
                this.tbxCosto.Enabled   = false;
                this.chbBajaEsp.Enabled = false;
                this.txbDni.Enabled     = false;

                CargarPantalla(medico);
                CargarEspecialidad(ref medico);
            }
            if (Operacion == 2) //Modificar
            {
                MedicoNegocio medicoNegocio;
                int           auxiliar;
                if (!ValidarCampos())
                {
                    CargarPantalla(medico);
                    Deshabilitar_Campos();
                    this.lklActualizarHorarios.Enabled  = true;
                    this.llbAgregarEspecialidad.Enabled = true;
                    this.btnAgregar.Enabled             = true;
                    this.btnModificar.Enabled           = true;
                    this.groupBox1.Enabled  = true;
                    this.tbxCosto.Enabled   = false;
                    this.chbBajaEsp.Enabled = false;
                    return;
                }
                else
                {
                    medico     = new Medico();
                    medico.dni = this.txbDni.Text.ToString();
                    int.TryParse(this.txbMatricula.Text.ToString(), out auxiliar);
                    medico.matricula = auxiliar;
                    medico.nombre    = this.txbNombre.Text.ToUpper();
                    medico.apellido  = this.txbApellido.Text.ToUpper();
                    medico.telefono  = this.txbTelefono.Text.ToUpper();
                    medico.mail      = this.txbMail.Text.ToUpper();
                    if (this.rbnFem.Checked == true)
                    {
                        medico.sexo = 'F';
                    }
                    if (this.rbnMasc.Checked == true)
                    {
                        medico.sexo = 'M';
                    }
                    if (this.rbnOtros.Checked == true)
                    {
                        medico.sexo = 'O';
                    }

                    medico.desde = this.dtpBaja.Value;
                    medico.hasta = this.dtpReinc.Value;
                    if (this.chbBajaDef.Checked == true)
                    {
                        medico.estado = 0;
                    }
                    else
                    {
                        medico.estado = 1;
                    }

                    medicoNegocio = new MedicoNegocio();
                    if (medicoNegocio.Escribir(medico) == false)
                    {
                        MessageBox.Show("Error al Modificar");
                    }
                    Deshabilitar_Campos();
                    this.groupBox1.Enabled             = true;
                    this.tbxCosto.Enabled              = false;
                    this.chbBajaEsp.Enabled            = false;
                    this.btnModificar.Enabled          = true;
                    this.btnAgregar.Enabled            = true;
                    this.lklActualizarHorarios.Enabled = true;
                }
            }
            if (Operacion == 3) //Agregar
            {
                MedicoNegocio medicoNegocio;
                int           auxiliar;

                if (!ValidarCampos())
                {
                    this.btnModificar.Enabled = false;
                    this.btnBuscar.Enabled    = false;
                    this.btnAgregar.Enabled   = false;
                    this.btnAceptar.Visible   = true;
                    this.btnCancelar.Visible  = true;
                    return;
                }
                else
                {
                    medico     = new Medico();
                    medico.dni = this.txbDni.Text.ToString();
                    int.TryParse(this.txbMatricula.Text.ToString(), out auxiliar);
                    medico.matricula = auxiliar;
                    medico.nombre    = this.txbNombre.Text.ToUpper();
                    medico.apellido  = this.txbApellido.Text.ToUpper();
                    medico.telefono  = this.txbTelefono.Text.ToUpper();
                    medico.mail      = this.txbMail.Text.ToUpper();

                    if (this.rbnFem.Checked == true)
                    {
                        medico.sexo = 'F';
                    }
                    if (this.rbnMasc.Checked == true)
                    {
                        medico.sexo = 'M';
                    }
                    if (this.rbnOtros.Checked == true)
                    {
                        medico.sexo = 'O';
                    }

                    medico.desde = this.dtpBaja.Value;
                    medico.hasta = this.dtpReinc.Value;

                    medicoNegocio = new MedicoNegocio();
                    if (medicoNegocio.Agregar(medico) == false)
                    {
                        MessageBox.Show("El Médico ya Existe");
                        Limpiar_Campos();
                        this.btnModificar.Enabled    = false;
                        this.cbxEspecialidad.Enabled = false;
                    }
                    Deshabilitar_Campos();
                    this.btnAceptar.Visible            = false;
                    this.btnCancelar.Visible           = false;
                    this.lklActualizarHorarios.Enabled = false;
                    this.tbxCosto.Enabled               = false;
                    this.chbBajaEsp.Enabled             = false;
                    this.linkLabel1.Enabled             = false;
                    this.linkLabel2.Enabled             = false;
                    this.llbAgregarEspecialidad.Enabled = true;
                    this.btnAgregar.Enabled             = true;
                    this.btnModificar.Enabled           = true;
                }
            }
        }