Exemple #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (NombreReporte != null && NombreReporte != "")
     {
         string[] arrayReporte = NombreReporte.Split('-');
         try
         {
             string tipoDocumento = DBFunctions.SingleData("SELECT TDOC_TIPODOCU FROM PDOCUMENTO WHERE PDOC_CODIGO = '" + arrayReporte[1] + "'");
             if (tipoDocumento == "CV")
             {
                 tbMail.Text = DBFunctions.SingleData("SELECT DVIS_EMAIL FROM DVISITADIARIACLIENTES WHERE PDOC_CODIGO = '" + arrayReporte[1] + "' AND DVIS_NUMEVISI = '" + arrayReporte[2] + "';");
             }
             else if (tipoDocumento == "RC")
             {
                 tbMail.Text = DBFunctions.SingleData("SELECT MNIT_EMAIL FROM MCAJA MC, MNIT M WHERE M.MNIT_NIT = MC.MNIT_NIT AND PDOC_CODIGO = '" + arrayReporte[1] + "' AND MCAJ_NUMERO = '" + arrayReporte[2] + "';");
             }
             else if (tipoDocumento == "FC")
             {
                 tbMail.Text = DBFunctions.SingleData("SELECT MNIT_EMAIL FROM MFACTURACLIENTE MF, MNIT M WHERE M.MNIT_NIT = MF.MNIT_NIT AND PDOC_CODIGO = '" + arrayReporte[1] + "' AND MFAC_NUMEDOCU = '" + arrayReporte[2] + "';");
             }
             else if (tipoDocumento == "FP")
             {
                 tbMail.Text = DBFunctions.SingleData("SELECT MNIT_EMAIL FROM MFACTURAPROVEEDOR MFP, MNIT M WHERE M.MNIT_NIT = MFP.MNIT_NIT AND PDOC_CODIORDEPAGO = '" + arrayReporte[1] + "' AND MFAC_NUMEORDEPAGO = '" + arrayReporte[2] + "';");
             }
             else if (tipoDocumento == "OT")
             {
                 tbMail.Text = DBFunctions.SingleData("SELECT MNIT_EMAIL FROM MORDEN MO, MNIT M WHERE M.MNIT_NIT = MO.MNIT_NIT AND PDOC_CODIGO = '" + arrayReporte[1] + "' AND MORD_NUMEORDE = '" + arrayReporte[2] + "';");
             }
         }
         catch (Exception err) { }
     }
 }
Exemple #2
0
        public void ImageButton1_Click(Object Sender, EventArgs e)
        {
            AMS.CriptoServiceProvider.Crypto miCripto = new Crypto(AMS.CriptoServiceProvider.Crypto.CryptoProvider.TripleDES);
            miCripto.IV  = ConfigurationManager.AppSettings["VectorInicialEncriptacion"];
            miCripto.Key = ConfigurationManager.AppSettings["ValorConcatClavePrivada"];
            string password = ConfigurationManager.AppSettings["PasswordEMail"];
            string empresa  = DBFunctions.SingleDataGlobal("select gemp_descripcion from gempresa where gemp_nombre='" + GlobalData.getEMPRESA() + "';");

            if (rutaImagen != null)
            {
                if (rutaArchivo == "")
                {
                    return;
                }
                try
                {
                    //string newPwd=miCripto.DescifrarCadena(password);
                    string newPwd = password;

                    string[] arrayReporte = NombreReporte.Split('.');
                    string   nReporte     = arrayReporte[arrayReporte.Length - 1];
                    //string rutaArchivo = ConfigurationManager.AppSettings["PathToReports"] + NombreReporte + "_" + HttpContext.Current.User.Identity.Name.ToLower() + "." ;
                    string urlImagen = "http://ecas.co/images/" + GlobalData.getEMPRESA() + ".png";

                    string mensaje =
                        @"<div style='position: absolute; background-color:#EEEFD9;width: 35%;border-radius: 10px;margin: auto;padding: 20px;box-shadow: 1px 7px 9px #888888;'>
	                        <img style='width: 20%; position: absolute; right: 2%;' src='"         + urlImagen + @"' /><br><br>
		                    <b><font size='5'>Reporte Generado:</font></b>
		                    <br>"         + nReporte +
                        @"<br><br>
		                    <b>Reciba un cordial saludo</b>, <br>
		                    Ha recibido un reporte usando el Sistema Ecas <br>
                            Dicho reporte se encuentra disponible como archivo <br>
                            adjunto en este correo.
		                    <br><br>
	                        <b>Gracias por su atención.</b>
		                    <br>
		                    <i>eCAS-AMS.</i>
	                    </div>
                        <br><br>";
                    if (rutaArchivo != null && rutaArchivo != "")
                    {
                        enviarMail(tbMail.Text, "Ha recibido un reporte de " + empresa + ": " + NombreReporte, mensaje, TipoCorreo.HTML, rutaArchivo);
                    }
                    else if (rutaImagen != null && rutaImagen != "")
                    {
                        enviarMail(tbMail.Text, "Ha recibido un reporte de " + empresa + ": " + NombreReporte, mensaje, TipoCorreo.HTML, rutaImagen);
                    }

                    Utils.MostrarAlerta(Response, "Email con Reporte ha sido enviado correctamente a: " + tbMail.Text);
                }
                catch (Exception er)
                {
                    lb.Text = "El Servidor de correos no ha sido configurado. Contactar Administrador de sistemas.";
                }
            }
            else if (dsExcel != null)
            {
                ds = dsExcel;
                Random num    = new Random();
                string nombre = "" + DBFunctions.SingleData("SELECT REMARKS FROM sysibm.SYSTABLES WHERE name='" + ds.DataSetName + "' ORDER BY NAME ASC;");
                if (nombre == "")
                {
                    nombre = ds.DataSetName + "_" + num.Next(0, 9999);
                }
                else
                {
                    nombre += "_" + num.Next(0, 9999);
                }

                string urlImagen = "http://ecas.co/images/" + GlobalData.getEMPRESA() + ".png";

                string mensajeExcel =
                    @"<div style='position: absolute; background-color:#EEEFD9;width: 35%;border-radius: 10px;margin: auto;padding: 20px;box-shadow: 1px 7px 9px #888888;'>
	                        <img style='width: 20%; position: absolute; right: 2%;' src='"         + urlImagen + @"' /><br><br>
		                    <b><font size='5'>Excel Generado:</font></b>
		                    <br>"         + nombre.Split('_')[0] +
                    @"<br><br>
		                    <b>Reciba un cordial saludo</b>, <br>
		                    Ha recibido un Excel usando el Sistema Ecas <br>
                            Dicho Excel se encuentra disponible como archivo <br>
                            adjunto en este correo.
		                    <br><br>
	                        <b>Gracias por su atención.</b>
		                    <br>
		                    <i>eCAS-AMS.</i>
	                    </div>
                        <br><br>";

                DataTable dt = dsExcel.Tables[0];
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    string nom = dt.DataSet.Tables[0].Columns[i].ColumnName;

                    string columnName = "" + DBFunctions.SingleData("SELECT REMARKS FROM SYSIBM.SYSCOLUMNS WHERE TBname='" + ds.DataSetName + "' AND NAME = '" + nom + "';");

                    if (columnName == "")
                    {
                        dt.Columns[i].ColumnName = nom;
                    }
                    else
                    {
                        dt.Columns[i].ColumnName = columnName;
                    }
                }
                //Set DataTable Name which will be the name of Excel Sheet.

                dt.TableName = ds.DataSetName;
                //Create a New Workbook.

                XLWorkbook wb = new XLWorkbook();

                //Add the DataTable as Excel Worksheet.

                wb.Worksheets.Add(dt);



                MemoryStream memoryStream = new MemoryStream();

                //Save the Excel Workbook to MemoryStream.

                wb.SaveAs(memoryStream);



                //Convert MemoryStream to Byte array.

                byte[] bytes = memoryStream.ToArray();

                memoryStream.Close();
                try
                {
                    if (correo != "" && correo != null)
                    {
                        enviarMail(correo, "Ha recibido un Reporte Excel de " + empresa, mensajeExcel, TipoCorreo.HTML, bytes);
                        Utils.MostrarAlerta(Response, "Email enviado satisfactoriamente a: " + correo);
                    }
                    else
                    {
                        enviarMail(tbMail.Text, "Ha recibido un Reporte Excel de " + empresa, mensajeExcel, TipoCorreo.HTML, bytes);
                        Utils.MostrarAlerta(Response, "Email enviado satisfactoriamente a: " + tbMail.Text);
                    }

                    //Response.Redirect(indexPage + "?process=DBManager.Selects&table=" + ds.DataSetName);
                }
                catch (Exception z)
                {
                    lblResult.Text = z.Message;
                }
            }
        }