Exemplo n.º 1
0
        //Guardar
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            var dgv = dgvPropiedades;

            if (validarCamposPropiedad())
            {
                //Datos Propiedad
                if (modificar == false) //Si es una propiedad nueva
                {
                    p.pDni     = Convert.ToInt32(txtDniBuscar.Text);
                    p.pTipoDNI = Convert.ToInt32(cboTipoBuscar.SelectedValue);
                }
                else //Si la propiedad existe en BD
                {
                    p.pDni     = Convert.ToInt32(dgv.CurrentRow.Cells[1].Value);
                    p.pTipoDNI = Convert.ToInt32(dgv.CurrentRow.Cells[2].Value);
                }
                p.pCalle        = txtDireccionProp.Text;
                p.pNumeroCalle  = Convert.ToInt32(txtNro.Text);
                p.pBarrio       = Convert.ToInt32(cboBarrio.SelectedValue);
                p.pCiudad       = Convert.ToInt32(cboCiudad.SelectedValue);
                p.pDepartamento = Convert.ToInt32(cboDepto.SelectedValue);
                p.pProvincia    = Convert.ToInt32(cboProvincia.SelectedValue);
                p.pDescripcion  = rtxtObservaciones.Text;

                p.TipoPropiedad = Convert.ToInt32(cboTipoProp.SelectedValue);

                if (txtPiso.Text == "")
                {
                    p.pPiso = 0;
                }
                else
                {
                    p.pPiso = Convert.ToInt32(txtPiso.Text);
                }


                if (txtDpto.Text == "")
                {
                    p.pDpto = "";
                }
                else
                {
                    p.pDpto = txtDpto.Text;
                }


                //Características Propiedad
                p.agregarCaracteristica(new CaracteristicaPropiedad(1, Convert.ToInt32(txtSupCub.Text)));

                p.agregarCaracteristica(new CaracteristicaPropiedad(2, Convert.ToInt32(txtHabitaciones.Text)));

                p.agregarCaracteristica(new CaracteristicaPropiedad(3, Convert.ToInt32(txtLivingComedor.Text)));

                p.agregarCaracteristica(new CaracteristicaPropiedad(4, Convert.ToInt32(txtCocina.Text)));

                p.agregarCaracteristica(new CaracteristicaPropiedad(5, Convert.ToInt32(txtBaño.Text)));

                p.agregarCaracteristica(new CaracteristicaPropiedad(6, Convert.ToInt32(txtPatio.Text)));


                //Si guardamos una propiedad nueva
                if (modificar == false && pAd.VerificarPropiedad(p.pCalle, p.pNumeroCalle, p.pPiso, p.pDpto, p.pCiudad) == false)
                {
                    pAd.InsertarPropiedad(p);

                    int idProp = pAd.BuscarIdPropiedad(0); //Busca el ID de la última Propiedad Registrada

                    foreach (var item in p.Caracteristicas)
                    {
                        pAd.InsertarCaracteristicas(item, idProp);
                    }

                    //INSERTA LAS FOTOS UNA POR UNA
                    if (p.ListaFotos != null)
                    {
                        foreach (var item in p.ListaFotos)
                        {
                            pAd.guardarFoto(item.pFotoBinaria, idProp);
                        }
                        p.ListaFotos.Clear();
                    }

                    p.Caracteristicas.Clear();
                    limpiarCampos();
                    limpiarCamposNuevaProp(0);
                    limpiarCuadros();
                    deshabilitarCampos();
                    registroGuardado();
                }

                //Si la propiedad existe, actualizamos
                else
                {
                    p.pId_propiedad = Convert.ToInt32(dgv.CurrentRow.Cells[0].Value);
                    pAd.ModificarPropiedad(p);

                    foreach (var item in p.Caracteristicas)
                    {
                        pAd.InsertarCaracteristicas(item, p.pId_propiedad);
                    }

                    if (p.ListaFotos != null)
                    {
                        foreach (var item in p.ListaFotos)
                        {
                            pAd.guardarFoto(item.pFotoBinaria, p.pId_propiedad);
                        }
                        p.ListaFotos.Clear();
                    }

                    p.Caracteristicas.Clear(); //Se limpia la lista de características
                    limpiarCampos();
                    limpiarCamposNuevaProp(0);
                    limpiarCuadros();
                    deshabilitarCampos();
                    registroGuardado();
                }

                if (NuevoContrato == true)
                {
                    NuevoContrato nc = new NuevoContrato();
                    nc.cargarCamposLocador(locador);
                    nc.cargarPropiedad(locador);
                    NuevoContrato = false;
                    abrirVentana <NuevoContrato>(nc);
                }
            }
            cargarPropiedades();
            pnlNuevaProp.Visible = false;
            grpPropiedad.BringToFront();
        }
Exemplo n.º 2
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            if (validarCamposCliente())
            {
                dni           = pr.pDNI = Convert.ToInt32(txtDNI.Text);
                tipo          = pr.pTipoDNI = Convert.ToInt32(cboTipoDNI.SelectedValue);
                pr.pApellido  = txtApellido.Text;
                pr.pNombre    = txtNombre.Text;
                pr.pDireccion = txtDireccion.Text;
                pr.pAltura    = Convert.ToInt32(txtAltura.Text);
                if (txtPiso.Text == "")
                {
                    pr.pPiso = 0;
                }
                else
                {
                    pr.pPiso = Convert.ToInt32(txtPiso.Text);
                }
                if (txtDepto.Text == "")
                {
                    pr.pDepto = "";
                }
                else
                {
                    pr.pDepto = txtDepto.Text;
                }
                if (cboBarrio.SelectedIndex != -1)
                {
                    pr.pBarrio = Convert.ToInt32(cboBarrio.SelectedValue);
                }
                else
                {
                    MessageBox.Show("Debe ingresar un barrio");
                }

                pr.pciudad       = Convert.ToInt32(cboCiudad.SelectedValue);
                pr.pdepartamento = Convert.ToInt32(cboDepartamento.SelectedValue);
                pr.pProvincia    = Convert.ToInt32(cboProvincia.SelectedValue);
                pr.pMail         = txtMail.Text.Trim();

                //Si la persona No existe, INSERTAR
                if (cl.VerificarPersona(pr.pTipoDNI, pr.pDNI) == 0)
                {
                    cl.InsertarPersona(pr);                       //Primero se hace la inserción con los campos ingresados

                    pr.pTelefono = null;                          //Limpio la lista de teléfonos
                    pr.pTelefono = cl.buscarTelefonos(tipo, dni); //Se necesita buscar los teléfonos porque si no, no tienen el ID

                    if (locador == true)                          //Si se ingresa un nuevo Locador desde Nuevo Contrato
                    {
                        NuevoContrato nc = (NuevoContrato)this.ParentForm;
                        locador = false;            //Ponemos la bandera falso
                        abrirVentana <NuevoContrato>(nc);
                        nc.cargarCamposLocador(pr); //Cargamos los campos

                        this.Close();
                    }
                    else if (locatario == true)
                    {
                        NuevoContrato nc = (NuevoContrato)this.ParentForm;
                        locatario = false;
                        abrirVentana <NuevoContrato>(nc);
                        nc.cargarCamposLocatario(pr);

                        this.Close();
                    }
                    else if (garante == true)
                    {
                        NuevoContrato nc = (NuevoContrato)this.ParentForm;
                        garante = false;
                        abrirVentana <NuevoContrato>(nc);
                        nc.cargarCamposGarante(pr);

                        this.Close();
                    }
                    else if (comprobantes == true)
                    {
                        EstadoDeCuentas ec = (EstadoDeCuentas)this.ParentForm;
                        comprobantes = false;
                        abrirVentana <EstadoDeCuentas>(ec);
                        //FALTA CARGA DE DATOS EN LA VENTANA ESTADO DE CUENTAS

                        this.Close();
                    }
                    else if (nuevaPropiedad == true)
                    {
                        Propiedades prop = (Propiedades)this.ParentForm;
                        nuevaPropiedad = false;
                        abrirVentana <Propiedades>(prop);
                        prop.nuevoLocador(pr);

                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("Se ingresó correctamente el registro");
                        this.Close();
                    }
                }

                //Si la persona existe, ACTUALIZAR
                else
                {
                    cl.modificarPersona(pr);
                    foreach (var item in idTelefonoBorrar)
                    {
                        if (item != 0) //Si el valor es 0, es porque el teléfono se cargó y se borró en el momento por lo cual no está ingresado en BD y no hace falta borrarlo
                        {
                            cl.BorrarTelefono(item);
                        }
                    }
                    pr.pTelefono = null;                          //Limpio la lista de teléfonos
                    pr.pTelefono = cl.buscarTelefonos(tipo, dni); //Se necesita buscar los teléfonos porque si no, no tienen el ID

                    if (locador == true)
                    {
                        NuevoContrato nc = (NuevoContrato)this.ParentForm;

                        locador = false;
                        abrirVentana <NuevoContrato>(nc);
                        nc.cargarCamposLocador(pr);

                        this.Close();
                    }
                    else if (locatario == true)
                    {
                        NuevoContrato nc = (NuevoContrato)this.ParentForm;
                        locatario = false;
                        abrirVentana <NuevoContrato>(nc);
                        nc.cargarCamposLocatario(pr);

                        this.Close();
                    }
                    else if (garante == true)
                    {
                        NuevoContrato nc = (NuevoContrato)this.ParentForm;
                        garante = false;
                        abrirVentana <NuevoContrato>(nc);
                        nc.cargarCamposGarante(pr);

                        this.Close();
                    }
                    else if (comprobantes == true)
                    {
                        EstadoDeCuentas ec = (EstadoDeCuentas)this.ParentForm;
                        comprobantes = false;
                        abrirVentana <EstadoDeCuentas>(ec);

                        this.Close();
                        //FALTA CARGA DE DATOS EN LA VENTANA ESTADO DE CUENTAS
                    }
                    else
                    {
                        MessageBox.Show("Se modificó correctamente el registro");
                        this.Close();
                    }
                }
            }
        }