Beispiel #1
0
        protected void gridSolicitudes_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType != DataControlRowType.DataRow)
            {
                return;
            }
            //HyperLink link = (HyperLink)e.Row.FindControl("HyperLink1");
//             if (link != null)
//             {
//                 link.Text = "Abrir";
//                 String sQuery = "idtomodify=" + this.gridSolicitudes.DataKeys[e.Row.RowIndex]["solicitudID"].ToString();
//                 sQuery = Utils.GetEncriptedQueryString(sQuery);
//                 String strRedirect = "~/frmAddSolicitud.aspx";
//                 strRedirect += sQuery;
//                 link.NavigateUrl = strRedirect;
//             }

            HyperLink link = (HyperLink)e.Row.FindControl("lnkSolicitud2010");

            if (link != null)
            {
                String sQuery = "SolID=" + this.gridSolicitudes.DataKeys[e.Row.RowIndex]["solicitudID"].ToString();
                sQuery = Utils.GetEncriptedQueryString(sQuery);
                String strRedirect = "~/frmAddSolicitud2010.aspx";
                strRedirect     += sQuery;
                link.NavigateUrl = strRedirect;
                link.Text        = "Abrir";
            }

//             LinkButton LB = (LinkButton)e.Row.FindControl("LBPrintSolicitud");
//             if(LB!=null)
//             {
//                 string sFileName = "SOLICITUD.pdf";
//                 sFileName = sFileName.Replace(" ", "_");
//                 String sURL = "frmDescargaTmpFile.aspx";
//                 string datosaencriptar;
//                 datosaencriptar = "filename=" + sFileName + "&ContentType=application/pdf&";
//                 datosaencriptar = datosaencriptar + "solID=" + this.gridSolicitudes.DataKeys[e.Row.RowIndex]["solicitudID"].ToString() + "&";
//                 datosaencriptar += "impsol=1&";
//                 String URLcomplete = sURL + "?data=";
//                 URLcomplete += Utils.encriptacadena(datosaencriptar);
//                 //LinkButton l = new LinkButton();
//                 JSUtils.OpenNewWindowOnClick(ref LB,URLcomplete, "Solicitud ", true);
//                 LB.Text = "SOLICITUD";
//             }
            LinkButton LB = (LinkButton)e.Row.FindControl("LBPrintContrato");

            if (LB != null)
            {
                string sFileName = "CONTRATO.pdf";
                sFileName = sFileName.Replace(" ", "_");
                string sURL            = "frmDescargaTmpFile.aspx";
                string datosaencriptar = "filename=" + sFileName + "&ContentType=application/pdf&";
                datosaencriptar  = datosaencriptar + "solID=" + this.gridSolicitudes.DataKeys[e.Row.RowIndex]["solicitudID"].ToString() + "&";
                datosaencriptar += "impcont=1&";
                string URLcomplete = sURL + "?data=";
                URLcomplete += Utils.encriptacadena(datosaencriptar);
                JSUtils.OpenNewWindowOnClick(ref LB, URLcomplete, "Contrato", true);
                LB.Text = "CONTRATO";
            }
//             LB = (LinkButton)e.Row.FindControl("LBPrintCaratula");
//             if(LB!=null)
//             {
//                 string sFileName = "CARATULA_ANEXA.pdf";
//                 sFileName = sFileName.Replace(" ", "_");
//                 string sURL = "frmDescargaTmpFile.aspx";
//                 string datosaencriptar = "filename=" + sFileName + "&ContentType=application/pdf&";
//                 datosaencriptar = datosaencriptar + "solID=" + this.gridSolicitudes.DataKeys[e.Row.RowIndex]["solicitudID"].ToString() + "&";
//                 datosaencriptar += "impcar=1&";
//                 string URLcomplete = sURL + "?data=";
//                 URLcomplete += Utils.encriptacadena(datosaencriptar);
//                 LB.Text = "CARATULA ANEXA";
//                 JSUtils.OpenNewWindowOnClick(ref LB, URLcomplete, "Caratula_Anexa", true);
//             }

//             LB = (LinkButton)e.Row.FindControl("LBPrintSeguro");
//             if(LB!=null){
//                     string sFileName = "CONTRATO_SEGURO.pdf";
//                     sFileName = sFileName.Replace(" ", "_");
//                     string sURL = "frmDescargaTmpFile.aspx";
//                     string datosaencriptar = "filename=" + sFileName + "&ContentType=application/pdf&";
//                     datosaencriptar = datosaencriptar + "solID=" + this.gridSolicitudes.DataKeys[e.Row.RowIndex]["solicitudID"].ToString() + "&";
//                     datosaencriptar += "impseg=1&";
//                     string URLcomplete = sURL + "?data=";
//                     URLcomplete += Utils.encriptacadena(datosaencriptar);
//                     JSUtils.OpenNewWindowOnClick(ref LB, URLcomplete, "Contrato Seguro", true);
//             }
            HyperLink lnk = (HyperLink)e.Row.FindControl("lnkPagare");

            if (lnk != null)
            {
                Solicitudes sol;
                if (this.IsSistemBanco)
                {
                    sol = SolicitudesSisBancos.Get(int.Parse(this.gridSolicitudes.DataKeys[e.Row.RowIndex]["solicitudID"].ToString()));
                }
                else
                {
                    sol = Solicitudes.Get(int.Parse(this.gridSolicitudes.DataKeys[e.Row.RowIndex]["solicitudID"].ToString()));
                }
                string sFileName = "PAGARE.pdf";
                sFileName = sFileName.Replace(" ", "_");
                string sURL            = "frmDescargaTmpFile.aspx";
                string datosaencriptar = "filename=" + sFileName + "&ContentType=application/pdf&";
                datosaencriptar  = datosaencriptar + "creditoID=" + sol.CreditoID.ToString() + "&";
                datosaencriptar += "solID=" + sol.SolicitudID.ToString() + "&";
                datosaencriptar += "impPagare=1&";
                string URLcomplete = sURL + "?data=";
                URLcomplete    += Utils.encriptacadena(datosaencriptar);
                lnk.NavigateUrl = this.Request.Url.ToString();
                lnk.Text        = "PAGARE";
                JSUtils.OpenNewWindowOnClick(ref lnk, URLcomplete, "Pagare", true);
            }
            LB = (LinkButton)e.Row.FindControl("LBTermsAndCon");
            if (LB != null)
            {
                string sFileName = "TERMINOS Y CONDICIONES.pdf";
                sFileName = sFileName.Replace(" ", "_");
                string sURL            = "frmDescargaTmpFile.aspx";
                string datosaencriptar = "filename=" + sFileName + "&ContentType=application/pdf&";
                datosaencriptar  = datosaencriptar + "solID=" + this.gridSolicitudes.DataKeys[e.Row.RowIndex]["solicitudID"].ToString() + "&";
                datosaencriptar += "imptermsandcond=1&";
                string URLcomplete = sURL + "?data=";
                URLcomplete += Utils.encriptacadena(datosaencriptar);
                LB.Text      = "TERMINOS Y CONDICIONES";
                JSUtils.OpenNewWindowOnClick(ref LB, URLcomplete, "Terminos y condiciones", true);
            }
            LB = (LinkButton)e.Row.FindControl("LBSolicitud2010");
            if (LB != null)
            {
                string sFileName = "SOLICITUD.pdf";
                sFileName = sFileName.Replace(" ", "_");
                string sURL            = "frmDescargaTmpFile.aspx";
                string datosaencriptar = "filename=" + sFileName + "&ContentType=application/pdf&";
                datosaencriptar  = datosaencriptar + "solID=" + this.gridSolicitudes.DataKeys[e.Row.RowIndex]["solicitudID"].ToString() + "&";
                datosaencriptar += "impSol2010=1&";
                string URLcomplete = sURL + "?data=";
                URLcomplete += Utils.encriptacadena(datosaencriptar);
                JSUtils.OpenNewWindowOnClick(ref LB, URLcomplete, "Solicitud", true);
                LB.Text = "SOLICITUD";
            }
            LB = (LinkButton)e.Row.FindControl("LBBuroCredito");
            if (LB != null)
            {
                string sFileName = "BUROCREDITO.pdf";
                sFileName = sFileName.Replace(" ", "_");
                string sURL            = "frmDescargaTmpFile.aspx";
                string datosaencriptar = "filename=" + sFileName + "&ContentType=application/pdf&";
                datosaencriptar  = datosaencriptar + "solID=" + this.gridSolicitudes.DataKeys[e.Row.RowIndex]["solicitudID"].ToString() + "&";
                datosaencriptar += "buroCredito=1&";
                string URLcomplete = sURL + "?data=";
                URLcomplete += Utils.encriptacadena(datosaencriptar);
                JSUtils.OpenNewWindowOnClick(ref LB, URLcomplete, "BuroCredito", true);
                LB.Text = "BURO";
            }
            LB = (LinkButton)e.Row.FindControl("LBCartaCompromiso");
            if (LB != null)
            {
                string sFileName = "CARTACOMPROMISO.pdf";
                sFileName = sFileName.Replace(" ", "_");
                string sURL            = "frmDescargaTmpFile.aspx";
                string datosaencriptar = "filename=" + sFileName + "&ContentType=application/pdf&";
                datosaencriptar  = datosaencriptar + "solID=" + this.gridSolicitudes.DataKeys[e.Row.RowIndex]["solicitudID"].ToString() + "&";
                datosaencriptar += "cartaCompromiso=1&";
                string URLcomplete = sURL + "?data=";
                URLcomplete += Utils.encriptacadena(datosaencriptar);
                JSUtils.OpenNewWindowOnClick(ref LB, URLcomplete, "CartaCompromiso", true);
                LB.Text = "CARTA COMPROMISO";
            }


            LB = (LinkButton)e.Row.FindControl("LBEvaluacion");
            if (LB != null)
            {
                string sFileName = "EVALUACION.pdf";
                sFileName = sFileName.Replace(" ", "_");
                string sURL            = "frmDescargaTmpFile.aspx";
                string datosaencriptar = "filename=" + sFileName + "&ContentType=application/pdf&";
                datosaencriptar  = datosaencriptar + "solID=" + this.gridSolicitudes.DataKeys[e.Row.RowIndex]["solicitudID"].ToString() + "&";
                datosaencriptar += "evaluacion=1&";
                string URLcomplete = sURL + "?data=";
                URLcomplete += Utils.encriptacadena(datosaencriptar);
                JSUtils.OpenNewWindowOnClick(ref LB, URLcomplete, "evaluacion", true);
                LB.Text = "EVALUACION";
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!this.IsPostBack)
                {
                    if (Request.QueryString["data"] != null)
                    {
                        if (this.loadqueryStrings(Request.QueryString["data"].ToString()))
                        {
                            string path  = "";
                            Byte[] bytes = null;
                            if (myQueryStrings["solID"] != null)
                            { // ES SOLICITUD
                                if (myQueryStrings["impsol"] != null)
                                {
                                    path = FormatosPdf.imprimeSolicitud(int.Parse(myQueryStrings["solID"].ToString()));
                                    Logger.Instance.LogUserSessionRecord(Logger.typeModulo.SOLICITUDES, Logger.typeUserActions.PRINT, this.UserID, "IMPRIMIO LA SOLICITUD: " + myQueryStrings["solID"].ToString());
                                }

                                if ((myQueryStrings["impSol2010"] != null))
                                {
                                    bytes = FormatosPdf.imprimeSolicitud2010(int.Parse(myQueryStrings["solID"].ToString()));
                                    Logger.Instance.LogUserSessionRecord(Logger.typeModulo.SOLICITUDES, Logger.typeUserActions.PRINT, this.UserID, "IMPRIMIO LA SOLICITUD: " + myQueryStrings["solID"].ToString());
                                }
                                if (myQueryStrings["impcont"] != null)
                                {
                                    bytes = FormatosPdf.imprimeContrato(int.Parse(myQueryStrings["solID"].ToString()), this.UserID);
                                    Logger.Instance.LogUserSessionRecord(Logger.typeModulo.SOLICITUDES, Logger.typeUserActions.PRINT, this.UserID, "IMPRIMIO EL CONTRATO DE LA SOLICITUD: " + myQueryStrings["solID"].ToString());
                                }
                                if (myQueryStrings["impcar"] != null)
                                {
                                    bytes = FormatosPdf.imprimeCaratulaAnexaSola(int.Parse(myQueryStrings["solID"].ToString()), this.UserID);
                                    Logger.Instance.LogUserSessionRecord(Logger.typeModulo.SOLICITUDES, Logger.typeUserActions.PRINT, this.UserID, "IMPRIMIO LA CARÁTULA DE LA SOLICITUD: " + myQueryStrings["solID"].ToString());
                                }
                                if (myQueryStrings["impPagare"] != null)
                                {
                                    /*
                                     * filename=" + sFileName + "&ContentType=application/pdf&";
                                     * datosaencriptar = datosaencriptar + "creditoID=" + actualRow.creditoID.ToString() +"&";
                                     * datosaencriptar += "impPagare=1&monto=" + actualRow.total.ToString() + "&";
                                     * string URLcomplete = sURL + "?data=";
                                     */
                                    int solicitud = -1;
                                    if (myQueryStrings["creditoID"] != null)
                                    {
                                        SqlCommand comm = new SqlCommand("SELECT solicitudID FROM Solicitudes WHERE (creditoID = @creditoID)");
                                        comm.CommandText = dbFunctions.UpdateSDSForSisBanco(comm.CommandText);
                                        comm.Parameters.Add("@creditoID", System.Data.SqlDbType.Int).Value = int.Parse(myQueryStrings["creditoID"].ToString());
                                        solicitud = dbFunctions.GetExecuteIntScalar(comm, -1);
                                        if (solicitud != -1)
                                        {
//                                            Solicitudes sol = Solicitudes.Get(solicitud);
                                            Solicitudes sol;
                                            if (this.IsSistemBanco)
                                            {
                                                sol = SolicitudesSisBancos.Get(solicitud);
                                            }
                                            else
                                            {
                                                sol = Solicitudes.Get(solicitud);
                                            }
                                            if (this.myQueryStrings["fecha"] == null)
                                            {
                                                this.myQueryStrings.Add("fecha", ((DateTime)sol.Fecha).ToString("yyyy/MM/dd"));
                                            }
                                            //else
                                            //  this.myQueryStrings["fecha"] = ((DateTime)sol.Fecha).ToString("yyyy/MM/dd");

                                            if (this.myQueryStrings["monto"] == null)
                                            {
                                                this.myQueryStrings.Add("monto", sol.Monto.ToString());
                                            }
                                            //else
                                            //    this.myQueryStrings["monto"] = sol.Monto.ToString();

                                            DateTime fecha;
                                            if (myQueryStrings["fecha"] != null && DateTime.TryParse(myQueryStrings["fecha"].ToString(), out fecha))
                                            {
                                                DateTime FechaPagare;
                                                if (myQueryStrings["fechaPagare"] != null && DateTime.TryParse(myQueryStrings["fechaPagare"].ToString(), out FechaPagare))
                                                {
                                                    bytes = FormatosPdf.imprimePagare(solicitud, this.UserID, double.Parse(myQueryStrings["monto"].ToString()), fecha, FechaPagare, true);
                                                }
                                                else
                                                {
                                                    bytes = FormatosPdf.imprimePagare(solicitud, this.UserID, double.Parse(myQueryStrings["monto"].ToString()), fecha);
                                                }
                                            }
                                            else
                                            {
                                                bytes = FormatosPdf.imprimePagare(solicitud, this.UserID, double.Parse(myQueryStrings["monto"].ToString()));
                                            }
                                        }
                                        else
                                        {
                                            if (int.TryParse(myQueryStrings["creditoID"].ToString(), out solicitud))
                                            {
                                                DateTime fecha;
                                                if (myQueryStrings["fecha"] != null && DateTime.TryParse(myQueryStrings["fecha"].ToString(), out fecha))
                                                {
                                                    DateTime FechaPagare;
                                                    if (myQueryStrings["fechaPagare"] != null && DateTime.TryParse(myQueryStrings["fechaPagare"].ToString(), out FechaPagare))
                                                    {
                                                        bytes = FormatosPdf.imprimePagareCredito(solicitud, this.UserID, double.Parse(myQueryStrings["monto"].ToString()), fecha, FechaPagare, true);
                                                    }
                                                    else
                                                    {
                                                        bytes = FormatosPdf.imprimePagareCredito(solicitud, this.UserID, double.Parse(myQueryStrings["monto"].ToString()), fecha);
                                                    }
                                                }
                                                else
                                                {
                                                    bytes = FormatosPdf.imprimePagareCredito(solicitud, this.UserID, double.Parse(myQueryStrings["monto"].ToString()));
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        solicitud = int.Parse(myQueryStrings["solID"].ToString());
                                        bytes     = FormatosPdf.imprimePagare(solicitud, this.UserID);
                                    }


                                    Logger.Instance.LogUserSessionRecord(Logger.typeModulo.SOLICITUDES, Logger.typeUserActions.PRINT, this.UserID, "IMPRIMIO LA CARÁTULA DE LA SOLICITUD: " + myQueryStrings["solID"].ToString());
                                }
                                if (myQueryStrings["impseg"] != null)
                                {
                                    string sError = "";

                                    FormatosPdf.imprimeReporteSeguro(int.Parse(myQueryStrings["solID"].ToString()), ref path, ref sError);
                                    Logger.Instance.LogUserSessionRecord(Logger.typeModulo.SOLICITUDES, Logger.typeUserActions.PRINT, this.UserID, "IMPRIMIO EL FORMATO DE SEGURO DE LA SOLICITUD: " + myQueryStrings["solID"].ToString());
                                }
                                if (myQueryStrings["imptermsandcond"] != null)
                                {
                                    bytes = FormatosPdf.imprimeTermsAndConditions(int.Parse(myQueryStrings["solID"].ToString()), UserID);
                                    Logger.Instance.LogUserSessionRecord(Logger.typeModulo.SOLICITUDES, Logger.typeUserActions.PRINT, this.UserID, "IMPRIMIO EL FORMATO DE TERMINOS Y CONDICIONES: " + myQueryStrings["solID"].ToString());
                                }
                                if (myQueryStrings["cartaCompromiso"] != null)
                                {
                                    bytes = FormatosPdf.imprimeCartaCompromiso(int.Parse(myQueryStrings["solID"].ToString()));
                                    Logger.Instance.LogUserSessionRecord(Logger.typeModulo.SOLICITUDES, Logger.typeUserActions.PRINT, this.UserID, "IMPRIMIO EL FORMATO DE CARTA COMPROMISO: " + myQueryStrings["solID"].ToString());
                                }

                                if (myQueryStrings["evaluacion"] != null)
                                {
                                    bytes = FormatosPdf.imprimeEvaluacion(int.Parse(myQueryStrings["solID"].ToString()));
                                    Logger.Instance.LogUserSessionRecord(Logger.typeModulo.SOLICITUDES, Logger.typeUserActions.PRINT, this.UserID, "IMPRIMIO EL FORMATO DE Evaluacion: " + myQueryStrings["solID"].ToString());
                                }


                                if (myQueryStrings["buroCredito"] != null)
                                {
                                    bytes = FormatosPdf.imprimeBuroCredito(int.Parse(myQueryStrings["solID"].ToString()));
                                    Logger.Instance.LogUserSessionRecord(Logger.typeModulo.SOLICITUDES, Logger.typeUserActions.PRINT, this.UserID, "IMPRIMIO EL FORMATO DE TERMINOS Y CONDICIONES: " + myQueryStrings["solID"].ToString());
                                }
                            }

                            if (myQueryStrings["NotaCompraFormato"] != null)
                            {
                                string sError = "";

                                FormatosPdf.imprimeOrdendeCompraFormato(int.Parse(myQueryStrings["NotaCompraFormato"].ToString()), ref path, ref sError);
                                Logger.Instance.LogUserSessionRecord(Logger.typeModulo.SOLICITUDES, Logger.typeUserActions.PRINT, this.UserID, "IMPRIMIO EL FORMATO DE SEGURO DE LA SOLICITUD: " + myQueryStrings["NotaCompraFormato"].ToString());
                            }
                            if (myQueryStrings["ordenDeCargaId"] != null)
                            {
                                string sError = "";

                                FormatosPdf.imprimeOrdendeCarga(int.Parse(myQueryStrings["ordenDeCargaId"].ToString()), ref path, ref sError);
                                Logger.Instance.LogUserSessionRecord(Logger.typeModulo.SOLICITUDES, Logger.typeUserActions.PRINT, this.UserID, "IMPRIMIO LA ORDEN DE CARGA: " + myQueryStrings["ordenDeCargaId"].ToString());
                            }

                            //printSeguro=1&solSeguroID="
                            if (myQueryStrings["printSeguro"] != null)
                            {
                                string sError = "";
                                bytes = FormatosPdf.imprimeSeguro(int.Parse(myQueryStrings["solSeguroID"].ToString()));
                                Logger.Instance.LogUserSessionRecord(Logger.typeModulo.SOLICITUDES, Logger.typeUserActions.PRINT, this.UserID, "IMPRIMIO EL SEGURO: " + myQueryStrings["solSeguroID"].ToString());
                            }
                            Response.ClearHeaders();
                            Response.Clear();

                            if (myQueryStrings["ContentType"] == null || myQueryStrings["ContentType"].ToString().Length <= 0)
                            {
                                Response.ContentType = "application/pdf";
                            }
                            else
                            {
                                Response.ContentType = myQueryStrings["ContentType"].ToString();//"application/pdf";
                            }

                            Response.AddHeader("Content-Disposition", "attachment;filename=" + myQueryStrings["filename"].ToString());
                            if (myQueryStrings["archivo"] != null)
                            {
                                path = myQueryStrings["archivo"].ToString();
                            }
                            if (bytes != null)
                            {
                                Response.BinaryWrite(bytes);
                            }
                            else
                            {
                                Response.WriteFile(path);
                                Response.Flush();
                                //try to delete the tmp file
                                try
                                {
                                    if (File.Exists(path))
                                    {
                                        File.Delete(path);
                                    }
                                }
                                catch {}
                            }
                            //Response.End();
                        }
                        else
                        {
                            myQueryStrings.Clear();
                            //Response.Redirect("~/frmAddModifyProductores.aspx", true);
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                Logger.Instance.LogException(Logger.typeUserActions.PRINT, "Error imprimiendo", ref ex);
            }
        }