Example #1
0
        private List <RetencionPercepcionResguardos> ObtenerRetenciones()
        {
            List <RetencionPercepcionResguardos> retorno = new List <RetencionPercepcionResguardos>();

            foreach (GridViewRow gvr in gridViewRetenciones.Rows)
            {
                RetencionPercepcionResguardos detalle = new RetencionPercepcionResguardos();
                Label id    = gvr.FindControl("lblIdCodigoRetencionPercepcion") as Label;
                Label tasa  = gvr.FindControl("lblTasa") as Label;
                Label monto = gvr.FindControl("lblMonto") as Label;
                Label valor = gvr.FindControl("lblValor") as Label;

                if (id != null && !string.IsNullOrEmpty(id.Text))
                {
                    int idCodigo = Int32.Parse(id.Text);
                    CodigoRetencionPercepcion codigoRet = Sistema.GetInstancia().BuscarCodigoRetencionPercepcionId(idCodigo);
                    detalle.CodigoPercepcionRetencion   = codigoRet;
                    detalle.IdCodigoPercepcionRetencion = idCodigo;
                }


                if (tasa != null)
                {
                    if (!String.IsNullOrEmpty(tasa.Text))
                    {
                        detalle.tasa = decimal.Parse(tasa.Text);
                    }
                }
                if (monto != null)
                {
                    if (!String.IsNullOrEmpty(monto.Text))
                    {
                        detalle.monto = decimal.Parse(monto.Text);
                    }
                }
                if (valor != null)
                {
                    if (!String.IsNullOrEmpty(valor.Text))
                    {
                        detalle.valor = decimal.Parse(valor.Text);
                    }
                }
                retorno.Add(detalle);
            }
            return(retorno);
        }
Example #2
0
        protected void btnAgregar_Click(object sender, EventArgs e)
        {
            if (ddlRetencionPercepcion.SelectedValue != null && !ddlRetencionPercepcion.SelectedValue.Equals(""))
            {
                try
                {
                    int idCodigo = Int32.Parse(ddlRetencionPercepcion.SelectedValue);
                    CodigoRetencionPercepcion codigo = Sistema.GetInstancia().BuscarCodigoRetencionPercepcionId(idCodigo);
                    if (codigo != null)
                    {
                        LineaRetencion        linea  = new LineaRetencion();
                        List <LineaRetencion> lineas = new List <LineaRetencion>();
                        DataTable             dt     = ObtenerDataTable();
                        DataRow dr;
                        int     cont = -1;
                        linea.CodigoRetencion   = codigo.Descripcion;
                        linea.IdCodigoRetencion = codigo.IdCodigoRetencionPercepcion;


                        foreach (GridViewRow gvr in gridViewRetenciones.Rows)
                        {
                            dr = dt.NewRow();

                            Label idCod = gvr.FindControl("lblIdCodigoRetencionPercepcion") as Label;
                            Label cod   = gvr.FindControl("lblCodigoPercepcionRetencion") as Label;
                            Label tasa  = gvr.FindControl("lblTasa") as Label;
                            Label monto = gvr.FindControl("lblMonto") as Label;
                            Label valor = gvr.FindControl("lblValor") as Label;

                            if (idCod != null)
                            {
                                dr[0] = idCod.Text;
                            }
                            if (cod != null)
                            {
                                dr[1] = cod.Text;
                            }
                            if (tasa != null)
                            {
                                dr[2] = tasa.Text;
                            }
                            if (monto != null)
                            {
                                dr[3] = monto.Text;
                            }
                            if (valor != null)
                            {
                                dr[4] = valor.Text;
                            }

                            dt.Rows.Add(dr);
                            cont++;
                            LineaRetencion nueva = new LineaRetencion();
                            if (!String.IsNullOrEmpty(tasa.Text))
                            {
                                nueva.tasa = decimal.Parse(tasa.Text);
                            }
                            if (!String.IsNullOrEmpty(monto.Text))
                            {
                                nueva.monto = decimal.Parse(monto.Text);
                            }
                            if (!String.IsNullOrEmpty(valor.Text))
                            {
                                nueva.valor = Int32.Parse(valor.Text);
                            }

                            nueva.IdCodigoRetencion = Int32.Parse(idCod.Text);
                            nueva.CodigoRetencion   = cod.Text;

                            lineas.Add(nueva);
                        }
                        if (lineas.Contains(linea))
                        {
                            string script = @"<script type='text/javascript'> alert('" + "El código se encuentra seleccionado" + "');</script>";
                            ScriptManager.RegisterStartupScript(this, typeof(Page), "alerta", script, false);
                        }
                        else
                        {
                            dr    = dt.NewRow();
                            dr[0] = codigo.IdCodigoRetencionPercepcion;
                            dr[1] = codigo.Descripcion;

                            dt.Rows.Add(dr);
                            cont++;
                            gridViewRetenciones.EditIndex  = cont;
                            gridViewRetenciones.DataSource = dt;
                            gridViewRetenciones.DataBind();
                        }
                    }
                }
                catch { }
            }
            else
            {
                string script = @"<script type='text/javascript'> alert('" + "Debe seleccionar un código" + "');</script>";
                ScriptManager.RegisterStartupScript(this, typeof(Page), "alerta", script, false);
            }
        }