Exemple #1
0
        private List <UI.Documento> ListarDocumentos()
        {
            var lstDocumentoUi = new List <UI.Documento>();

            try
            {
                using (DemoContext db = new DemoContext())
                {
                    List <Documento> lstDocumentoBe = db.Documentos.Where(x => x.Activo == true).ToList();

                    foreach (Documento documentoBe in lstDocumentoBe)
                    {
                        var documentoIdentidadUi = new UI.Documento();

                        documentoIdentidadUi.Id          = documentoBe.Id;
                        documentoIdentidadUi.Nombre      = documentoBe.Nombre;
                        documentoIdentidadUi.Descripcion = documentoBe.Descripcion;
                        documentoIdentidadUi.Activo      = documentoBe.Activo == true ? UI.ActivoEnum.Si : UI.ActivoEnum.No;

                        lstDocumentoUi.Add(documentoIdentidadUi);
                    }
                }

                return(lstDocumentoUi);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #2
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            try
            {
                #region Validaciones del formulario

                if (this.txtCodigo.Text.Trim().Length == 0)
                {
                    this.txtCodigo.Focus();
                    throw new Exception("Ingrese el codigo del Cliente");
                }

                if (this.txtNombres.Text.Trim().Length == 0)
                {
                    this.txtNombres.Focus();
                    throw new Exception("Ingrese los nombres del Cliente");
                }

                if (this.txtApellidos.Text.Trim().Length == 0)
                {
                    this.txtApellidos.Focus();
                    throw new Exception("Ingrese los apellidos del Cliente");
                }

                if (this.cboDocumento.SelectedIndex == 0)
                {
                    this.cboDocumento.Focus();
                    throw new Exception("Seleccione el documento del Cliente");
                }

                if (this.txtNroDocumento.Text.Trim().Length == 0)
                {
                    this.txtNroDocumento.Focus();
                    throw new Exception("Ingrese el numero de documento del Cliente");
                }

                if (this.cboSexo.SelectedIndex == 0)
                {
                    this.cboSexo.Focus();
                    throw new Exception("Seleccione el sexo del Cliente");
                }

                #endregion

                #region Guardar

                this.clienteUi.Codigo    = this.txtCodigo.Text.Trim();
                this.clienteUi.Nombres   = this.txtNombres.Text.Trim();
                this.clienteUi.Apellidos = this.txtApellidos.Text.Trim();

                UI.Documento documentoUi = (UI.Documento) this.cboDocumento.SelectedItem;
                this.clienteUi.DocumentoId     = documentoUi.Id;
                this.clienteUi.DocumentoNombre = documentoUi.Nombre;

                this.clienteUi.NroDocumento = this.txtNroDocumento.Text.Trim();
                this.clienteUi.Activo       = this.chkActivo.Checked == true ? UI.ActivoEnum.Si : UI.ActivoEnum.No;

                this.clienteUi.FechaNacimiento = this.dtpFechaNacimiento.Value;
                UI.SexoEnum sexo;
                if (Enum.TryParse <UI.SexoEnum>(this.cboSexo.SelectedValue.ToString(), out sexo))
                {
                    this.clienteUi.Sexo = sexo;
                }

                bool   rpta = false;
                string msg  = "";

                if (this.clienteUi.ID == 0) //Nuevo
                {
                    rpta = Insertar(ref this.clienteUi);
                    if (rpta)
                    {
                        msg = "Se registro una nuevo Cliente";
                    }
                }
                else  //Actualizar
                {
                    rpta = Actualizar(this.clienteUi);
                    if (rpta)
                    {
                        msg = "Se actualizo la Cliente";
                    }
                }

                if (rpta == true)
                {
                    General.InformationMessage(msg);
                    this.frmList.CargarListadoClientes();
                    this.Close();
                }

                #endregion
            }
            catch (Exception ex)
            {
                General.ErrorMessage(ex.Message);
            }
        }