protected void Page_Load(object sender, EventArgs e)
        {
            Session["OMITE_VALIDACION"] = false;
            Session["TITULO"]           = "Conciliación de documentos";
            if (!this.Page.IsPostBack)
            {
                Parametros parametros = bd.Parametros.First(cond => cond.codigo == "DOC_CONC");

                Session["ID_DOC_CONCILIACION"] = int.Parse(parametros.valor);
                int docu  = int.Parse(parametros.valor);
                int grupo = bd.GruposDocumentos.First(w => w.DocId == docu).GDocId;
                Session["ID_SUBDOC_CONCILIACION"] = grupo;

                this.CargarDocumentos((Clientes)this.Session["CLIENTE"]);
                Documentos D = new Documentos();
                //Parametros param1 = bd.Parametros.First(c => c.codigo == "DOC_CONC");
                //int num5 = this.bCap.ObtenerSiguienteDocumento((Captura)this.Session["NEGOCIO"], (Clientes)this.Session["CLIENTE"]);
                //int num5 = Int32.Parse(param1.valor.ToString());
                D.DocId = (int)Session["ID_DOC_CONCILIACION"];
                this.CargarGruposDocs(D);
                P_Etapas etapas = new P_Etapas();
                etapas.IdEtapa        = 70;
                this.Session["ETAPA"] = etapas;
                //if (base.Request.QueryString["CAPTURA"].ToString() == "1")
                //{
                //    etapas.IdEtapa = 30;
                //    this.Session["ETAPA"] = etapas;
                //}
                //else if (base.Request.QueryString["CAPTURA"].ToString() == "2")
                //{
                //    etapas.IdEtapa = 40;
                //    this.Session["ETAPA"] = etapas;
                //}
                //else if (base.Request.QueryString["CAPTURA"].ToString() == "3")
                //{
                //    etapas.IdEtapa = 50;
                //    this.Session["ETAPA"] = etapas;
                //}
                this.bCap = new GestorDocumental.Controllers.CapturaController();
                Captura c = new Captura();
                if (this.bAsig.ObtenerNegociosXEntrada((Usuarios)this.Session["USUARIO"], etapas) == 0M)
                {
                    c.NegId = 0M;
                    this.Session["NEGOCIO"]    = c;
                    this.lstDocumentos.Enabled = false;
                    this.lstGrupos.Enabled     = false;
                    this.lblError.Text         = "No existen negocios disponibles para esta etapa";
                    this.UpdatePanel2.Update();
                }
                else
                {
                    int num5;
                    int num6;
                    c.NegId                 = this.bAsig.ObtenerNegociosXEntrada((Usuarios)this.Session["USUARIO"], etapas);
                    c.NumCaptura            = int.Parse(base.Request.QueryString["CAPTURA"].ToString());
                    this.Session["NEGOCIO"] = c;
                    AsignacionTareas a = new AsignacionTareas
                    {
                        IdEtapa    = ((P_Etapas)this.Session["ETAPA"]).IdEtapa,
                        NegId      = ((Captura)this.Session["NEGOCIO"]).NegId,
                        Usuario    = ((Usuarios)this.Session["USUARIO"]).IdUsuario,
                        IdEstado   = 10,
                        HoraInicio = DateTime.Now
                    };
                    if (!this.bAsig.ExisteEtapa(a))
                    {
                        this.bAsig.insertarAsignacion(a);
                    }
                    //int num = this.bCap.ObtenerDocumentoActual(c, (Clientes)this.Session["CLIENTE"]);

                    int        num = (int)Session["ID_DOC_CONCILIACION"];
                    Documentos d   = new Documentos
                    {
                        DocId = num
                    };
                    //int num2 = this.bCap.ObtenerGrupoActual(c, d);
                    //int num3 = this.bCap.ObtenerUltimoGrupo(d);



                    int num2 = (int)Session["ID_SUBDOC_CONCILIACION"];
                    int num3 = (int)Session["ID_SUBDOC_CONCILIACION"];

                    this.lstDocumentos.SelectedIndex = this.lstDocumentos.Items.IndexOf(this.lstDocumentos.Items.FindByValue(num.ToString()));
                    this.lstGrupos.SelectedIndex     = this.lstGrupos.Items.IndexOf(this.lstGrupos.Items.FindByValue(num3.ToString()));

                    //if (num2 == num3)
                    //{
                    //    int num4 = this.bCap.ObtenerSiguienteDocumento(c, (Clientes)this.Session["CLIENTE"]);
                    //    d.DocId = num4;
                    //    this.lstDocumentos.SelectedIndex = this.lstDocumentos.Items.IndexOf(this.lstDocumentos.Items.FindByValue(num4.ToString()));
                    //    this.CargarGruposDocs(d);
                    //    num5 = this.bCap.ObtenerSiguienteGrupo(c, d);
                    //    this.lstGrupos.SelectedIndex = this.lstGrupos.Items.IndexOf(this.lstGrupos.Items.FindByValue(num5.ToString()));
                    //    num6 = this.bCap.obtenerUltimoDocumento((Clientes)this.Session["CLIENTE"]);
                    //}
                    //else
                    //{
                    //    d.DocId = num;
                    //    this.lstDocumentos.SelectedIndex = this.lstDocumentos.Items.IndexOf(this.lstDocumentos.Items.FindByValue(num.ToString()));
                    //    this.CargarGruposDocs(d);
                    //    num5 = this.bCap.ObtenerSiguienteGrupo(c, d);
                    //    this.lstGrupos.SelectedIndex = this.lstGrupos.Items.IndexOf(this.lstGrupos.Items.FindByValue(num5.ToString()));
                    //    num6 = this.bCap.obtenerUltimoDocumento((Clientes)this.Session["CLIENTE"]);
                    //}
                    this.CargarCampos();
                    ((Label)base.Master.FindControl("lblNegocio")).Text = "Negocio:" + c.NegId.ToString();
                }
            }
            else
            {
                this.CargarCampos();
            }
            this.Page.ClientScript.RegisterClientScriptBlock(base.GetType(), "FileLoad", "neg = '" + ConfigurationManager.AppSettings["ClientFiles"] + "/" + ((Captura)this.Session["NEGOCIO"]).NegId.ToString() + "/" + ((Captura)this.Session["NEGOCIO"]).NegId.ToString() + ".TIF';", true);
            if (((Captura)this.Session["NEGOCIO"]).NegId != 0M)
            {
                Documentos documentos2 = new Documentos
                {
                    DocId = int.Parse(this.lstDocumentos.SelectedValue)
                };
                this.bdoc            = new GestorDocumental.Controllers.DocumentosController();
                this.NumPagina.Value = this.bdoc.ObtenrPaginaDocumento(documentos2, (Captura)this.Session["NEGOCIO"]).ToString();
            }
            this.lstDocumentos.Attributes.Add("onChange", "CargarPaginaDigitada();");
        }
        //CAPTURA DE DATOS E INSERCION EN LA TABLA
        protected void Button1_Click1(object sender, EventArgs e)
        {
            try
            {
                this.bCap = new GestorDocumental.Controllers.CapturaController();

                List <Captura> lstCaptura = new List <Captura>();
                this.InsertarCampos(this.pControls, lstCaptura);
                bool resultado = false;

                bool validacion = (bool)Session["OMITE_VALIDACION"];

                //OMITO LA VALIDACION ?
                if (!validacion)
                {
                    //VALIDO CONTRA LA CONCILIACION DEL ARCHIVO CAPTURADA EN RECEPCION
                    resultado = this.bCap.ValidaConciliacion(lstCaptura, (int)((Captura)this.Session["NEGOCIO"]).NegId, (int)Session["ID_SUBDOC_CONCILIACION"], (int)Session["SW_CONCILIACION"]);

                    if (resultado)
                    {
                        Session["SW_CONCILIACION"] = 0;
                    }
                    else
                    {
                        Session["SW_CONCILIACION"] = 1;
                    }
                }
                else
                {
                    Session["SW_CONCILIACION"] = 0;
                    resultado = true;
                }

                //SI LA VALIDACION CONTRA EL ARCHIVO FUE CORRECTA SIGUE EL PROCESO
                if (resultado)
                {
                    this.bCap.InsertarCaptura(lstCaptura);
                    //int num = this.bCap.obtenerUltimoDocumento((Clientes)this.Session["CLIENTE"]);
                    int        num = (int)Session["ID_DOC_CONCILIACION"];
                    Documentos d   = new Documentos
                    {
                        //DocId = this.bCap.ObtenerDocumentoActual((Captura)this.Session["NEGOCIO"], (Clientes)this.Session["CLIENTE"])
                        DocId = (int)Session["ID_DOC_CONCILIACION"]
                    };
                    Documentos documentos2 = new Documentos
                    {
                        //DocId = this.bCap.ObtenerSiguienteDocumento((Captura)this.Session["NEGOCIO"], (Clientes)this.Session["CLIENTE"])
                        DocId = (int)Session["ID_DOC_CONCILIACION"]
                    };
                    int num2 = 0;
                    if ((d.DocId == num) | (documentos2.DocId == num))
                    {
                        AsignacionTareas a = new AsignacionTareas
                        {
                            IdEstado        = 30,
                            HoraTerminacion = new DateTime?(DateTime.Now),
                            NegId           = ((Captura)this.Session["NEGOCIO"]).NegId,
                            IdEtapa         = ((P_Etapas)this.Session["ETAPA"]).IdEtapa
                        };
                        this.bAsig.insertarAsignacion(a);
                        num2 = 1;
                    }
                    else
                    {
                        int num6;
                        int num3 = this.bCap.ObtenerGrupoActual((Captura)this.Session["NEGOCIO"], d);
                        int num4 = this.bCap.ObtenerUltimoGrupo(d);
                        if (num3 == num4)
                        {
                            //Parametros param1 = bd.Parametros.First(c => c.codigo == "DOC_CONC");
                            //int num5 = this.bCap.ObtenerSiguienteDocumento((Captura)this.Session["NEGOCIO"], (Clientes)this.Session["CLIENTE"]);
                            int num5 = (int)Session["ID_DOC_CONCILIACION"];
                            this.lstDocumentos.SelectedIndex = this.lstDocumentos.Items.IndexOf(this.lstDocumentos.Items.FindByValue(num5.ToString()));
                            Documentos documentos3 = new Documentos
                            {
                                DocId = num5
                            };
                            this.CargarGruposDocs(documentos3);
                            num6 = (int)Session["ID_SUBDOC_CONCILIACION"];
                            //num6 = 6;
                            this.lstGrupos.SelectedIndex = this.lstGrupos.Items.IndexOf(this.lstGrupos.Items.FindByValue(num6.ToString()));
                        }
                        else
                        {
                            //Obtenemos el grupo asociado al negocio en proceso
                            int negID   = Convert.ToInt32(Session["NEGOCIO"].ToString());
                            int idGrupo = bCap.obtenerSubGrupo(negID);

                            Documentos documentos4 = new Documentos
                            {
                                DocId = this.bCap.ObtenerDocumentoActual((Captura)this.Session["NEGOCIO"], (Clientes)this.Session["CLIENTE"], idGrupo)
                            };
                            num6 = this.bCap.ObtenerSiguienteGrupo((Captura)this.Session["NEGOCIO"], documentos4);
                            this.lstGrupos.SelectedIndex = this.lstGrupos.Items.IndexOf(this.lstGrupos.Items.FindByValue(num6.ToString()));
                        }
                    }
                    this.UpdatePanel1.Update();
                    this.pControls.Controls.Clear();
                    this.CargarCampos();
                    this.UpdatePanel2.Update();
                    Documentos documentos5 = new Documentos
                    {
                        DocId = int.Parse(this.lstDocumentos.SelectedValue)
                    };
                    this.bdoc            = new GestorDocumental.Controllers.DocumentosController();
                    this.NumPagina.Value = this.bdoc.ObtenrPaginaDocumento(documentos5, (Captura)this.Session["NEGOCIO"]).ToString();
                    if (num2 == 1)
                    {
                        base.Response.Redirect("Conciliar.aspx?Captura=" + base.Request.QueryString["Captura"].ToString());
                    }
                }
                else
                {
                    this.lblError.Text = "Documento no conciliado verifique nuevamente";
                    this.btn_omiteConciliacion.Visible = true;
                    this.UpdatePanel1.Update();
                }
            }
            catch (Exception exception)
            {
                this.lblError.Text = exception.Message;
                this.UpdatePanel1.Update();
            }
        }