Ejemplo n.º 1
0
        private void butConfirmar_Click(object sender, System.EventArgs e)
        {
            usuario = (IUsuarios)Session["usuario"];

            bool            ok        = true;
            Hashtable       hGuiasNR  = new Hashtable(); // Guías que no están en condiciones de ser recibidas
            DsGuiaColectora dsGuiasNR = new DsGuiaColectora();

            string CBIngresados = txtCodigosBarraIngresado.Text.Split('-')[0];

            // Obtengo el listado de códigos ingresados
            string[] codigosIngresados = CBIngresados.Split('@');

            int cant = Utiles.Validaciones.obtieneEntero(this.txtGuiaIndex.Text);
            DsDetalleHojaRutaRepartidor dsDetalle = new DsDetalleHojaRutaRepartidor();

            for (int i = 0; i < codigosIngresados.Length - 1; i++)
            {
                int guiaID = Utiles.Validaciones.obtieneEntero(codigosIngresados[i]);

                // si la guía existe en el sistema, la ingreso a la HRR
                if (guiaID > 0)
                {
                    ds = (DsHojaRutaRepartidor)Session["HojaRutaRepartidorColectora"];
                    // Reviso si la guía puede ser incluida en la HRRepartidor. Busco en el Ds que se cargo al principio
                    if (ds.Guias.Select("GuiaID = " + guiaID).Length > 0)
                    {
                        DsDetalleHojaRutaRepartidor.DatosRow drDetalle = (DsDetalleHojaRutaRepartidor.DatosRow)dsDetalle.Datos.NewRow();
                        drDetalle.AgenciaID = AgenciaConectadaID;
                        drDetalle.EstadoGuiaHojaRutaRepartidor = 1;
                        drDetalle.GuiaID               = guiaID;
                        drDetalle.Prioridad            = 0;
                        drDetalle.GenerarFacturaRemito = false;
                        dsDetalle.Datos.AddDatosRow(drDetalle);
                    } // fin if EsRecepcionable
                    else
                    // La guia no puede ser incluida. Consulto el motivo. Guardo el nro y el motivo por el cual no puede ser incluida
                    {
                        // acá debería guardar las que no se pueden recibir y luego mostrarlas en un alert...
                        IGuia oGuia = GuiaFactory.GetGuia();
                        oGuia.GuiaID = guiaID;
                        oGuia.ConsultarGuiaColectora();
                        oGuia.UnidadNegocioID = this.UnidadNegocioID;
                        oGuia.UsuarioID       = usuario.UsuarioID;

                        string guia = oGuia.NroSucursalGuia + "-" + oGuia.NroGuia + "-" + oGuia.TipoGuia;
                        //if (hGuiasNR.ContainsKey(guia) == false)
                        //{
                        //    hGuiasNR.Add(guia, oGuia.MotivoNoRecepcionable);
                        //}
                        ok = false;

                        if (dsGuiasNR.Datos.FindByGuiaID(oGuia.GuiaID) == null)
                        {
                            dsGuiasNR.Datos.AddDatosRow(oGuia.GuiaID, "", 0, 0, 0, 0, 0, 0, DateTime.Now, 0, 0, 0, "", DateTime.Now, "", DateTime.Now, "", "", 0, 0, 0, "", DateTime.Now, 0, "", false, 0, false, false, 0, 0, 0, 0, oGuia.MotivoNoRecepcionable, "", "", "", "", 0, 0, false, false, guia);
                        }
                    }
                }
            } // fin for
            this.txtSeGuardo.Text           = "0";
            this.txtSeGuardoSinErrores.Text = "0";

            // Si hay guias que guardar, genero la Hoja de Ruta del Repartidor
            if (dsDetalle.Datos.Count > 0)
            {
                IHojaRutaRepartidor hojaRutaRepartidor = HojaRutaRepartidorFactory.GetHojaRutaRepartidor();
                hojaRutaRepartidor.DsDetalle = dsDetalle;
                hojaRutaRepartidor.Fecha     = DateTime.Now;
                hojaRutaRepartidor.EstadoHojaRutaRepartidor = (int)NegociosSisPackInterface.SisPack.EstadoHojaRutaRepartidor.GeneradaporColectoradeDatos; //Generada por Colectora de Datos
                hojaRutaRepartidor.UsuarioID = usuario.UsuarioID;
                hojaRutaRepartidor.AgenciaID = this.AgenciaConectadaID;
                hojaRutaRepartidor.Generar();
                hojaRutaRepartidor.Consultar();
                lblGuia.Text    = string.Empty;
                lblCliente.Text = string.Empty;
                lblDestino.Text = string.Empty;
                lblBultos.Text  = string.Empty;
                txtNroHojaRutaRepartidor.Text = hojaRutaRepartidor.NroHojaRutaRepartidor.ToString();
                //uppnlDatosGuias.Update();
                this.txtSeGuardo.Text = "1";
            }

            Session["GuiasNRHojaRutaRepartidor"] = hGuiasNR;
            if (ok)
            {
                Session["GuiasNRHojaRutaRepartidor"]   = null;
                Session["DsGuiasNRHojaRutaRepartidor"] = null;
                this.txtSeGuardoSinErrores.Text        = "1";
            }
            else
            {
                Session["GuiasNRHojaRutaRepartidor"]   = hGuiasNR;
                Session["DsGuiasNRHojaRutaRepartidor"] = dsGuiasNR;
                if (Session["DsGuiasNRHojaRutaRepartidor"] != null)
                {
                    dsGuiasNR = (DsGuiaColectora)Session["DsGuiasNRHojaRutaRepartidor"];

                    if (dsGuiasNR.Datos.Count > 0)
                    {
                        MostrarGuiasNoRecepcionables(dsGuiasNR);
                    }
                }
                //Response.Redirect("HojaRutaRepartidor.aspx?d=1");
            }


            string txtSeGuardo = this.txtSeGuardo.ClientID;
            string txtNroHojaRutaRepartidor1 = this.txtNroHojaRutaRepartidor.ClientID;
            string txtSeGuardoSinErrores     = this.txtSeGuardoSinErrores.ClientID;

            System.Text.StringBuilder scriptString = new System.Text.StringBuilder();
            scriptString.Append("<script language='javascript'>function MjeError(){\n");
            scriptString.Append("if (window.document.getElementById('" + txtSeGuardo + "').value == '0'){\n");
            scriptString.Append("	alert('No se genero Hoja de Ruta. Sin datos que guardar.');\n");
            scriptString.Append("if (window.document.getElementById('" + txtSeGuardoSinErrores + "').value == '0'){\n");
            scriptString.Append("		window.document.getElementById('tblGuias').style.display = 'none';\n");
            scriptString.Append("		window.document.getElementById('tblBotones').style.display = 'none';\n");
            scriptString.Append("		window.document.getElementById('tblDatos').style.display = 'none';\n");
            scriptString.Append("}\n");
            scriptString.Append("	} else {\n");
            scriptString.Append("	alert('Datos Guardados. Se generó la Hoja de Ruta de Reparto: Nº ' + window.document.getElementById('"+ txtNroHojaRutaRepartidor1 + "').value);\n");

            scriptString.Append("if (window.document.getElementById('" + txtSeGuardoSinErrores + "').value == '1'){\n");
            scriptString.Append("window.location = 'HojaRutaRepartidor.aspx';\n");
            scriptString.Append("}else{\n");
            scriptString.Append("		window.document.getElementById('tblGuias').style.display = 'none';\n");
            scriptString.Append("		window.document.getElementById('tblBotones').style.display = 'none';\n");
            scriptString.Append("		window.document.getElementById('tblDatos').style.display = 'none';\n");
            scriptString.Append("}\n");
            scriptString.Append("}\n");
            scriptString.Append("}\n</script>");

            Page.RegisterClientScriptBlock("MjeError", scriptString.ToString());

            //ScriptManager.RegisterClientScriptBlock(this.uppnlBotones,
            //                                                uppnlBotones.GetType(),
            //                                                "MjeError",
            //                                                script,
            //                                                true);
        }