From 4c74ec5d46f99c2b7ae873a3e1b05af6d3f1ece4 Mon Sep 17 00:00:00 2001 From: Antonio Gonzalez Date: Wed, 22 Jul 2020 19:47:27 -0700 Subject: [PATCH] =?UTF-8?q?notificac=C3=B3n=20por=20correo=20agregada?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App_Code/ClsOIEventos.vb | 20 +++++++++ OI/DocumentoDetalle.aspx | 2 +- OI/DocumentoDetalle.aspx.cs | 84 ++++++++++++++++++++++++++++++++----- OI/Documentos.aspx | 19 ++++----- OI/Documentos.aspx.cs | 2 +- 5 files changed, 103 insertions(+), 24 deletions(-) diff --git a/App_Code/ClsOIEventos.vb b/App_Code/ClsOIEventos.vb index 4e36ab9e0..6abe367d1 100644 --- a/App_Code/ClsOIEventos.vb +++ b/App_Code/ClsOIEventos.vb @@ -2922,6 +2922,26 @@ Public Class ClsOIEventos #End Region #Region "Documentos" + Public Function ListadoDocumentos(CveEmpresa As Integer) As Boolean + + Dim Retorno As Boolean = False + + DataAdapter("PA_OI_ListarDocumentos") + + With SqlAdapter.SelectCommand.Parameters + .Add("@CveEmpresa", SqlDbType.Int).Value = CveEmpresa + End With + + Try + SqlAdapter.Fill(Data) + Retorno = True + Catch ex As Exception + OnError("Ocurrió un error al obtener el listado de documento", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo()) + End Try + + Return Retorno + End Function + Public Function GetDocumento(CveDocumento As Integer, CveEmpresa As Integer) As Boolean Dim Retorno As Boolean = False diff --git a/OI/DocumentoDetalle.aspx b/OI/DocumentoDetalle.aspx index ad0062d3e..d5af82e6c 100644 --- a/OI/DocumentoDetalle.aspx +++ b/OI/DocumentoDetalle.aspx @@ -97,7 +97,7 @@ - diff --git a/OI/DocumentoDetalle.aspx.cs b/OI/DocumentoDetalle.aspx.cs index 23c3b49e7..6955095d9 100644 --- a/OI/DocumentoDetalle.aspx.cs +++ b/OI/DocumentoDetalle.aspx.cs @@ -7,6 +7,7 @@ using System.Web.UI.WebControls; using Extensiones; using System.Data; using System.IO; +using System.Text; public partial class OI_DocumentoDetalle : ClsPaginas { @@ -155,7 +156,7 @@ public partial class OI_DocumentoDetalle : ClsPaginas #endregion #region "GENERAR DOCUMENTO" - + protected void LblGuardar_Click(object sender, EventArgs e) { @@ -166,19 +167,24 @@ public partial class OI_DocumentoDetalle : ClsPaginas //Esta variable es requerida más adelante int CveDocumento = 0; string RutaArchivo = "-1"; + string CorreosNotificacion = ""; + byte[] ArchivoNotifiacion = null; CveDocumento = GuardarDocumento(ref ObjOI, ref TieneError);//Se crea el Documento if (!TieneError) { RutaArchivo = AsignarArchivoAlDocumento(CveDocumento, ref ObjOI, ref TieneError); }//Se guarda el archivo fisico y se asigna al Documento generado - if (!TieneError) { GuardarUsuariosQueAutorizan(CveDocumento, RutaArchivo, ref ObjOI, ref TieneError); }//asignamos a los usuarios que participaran en aprovar este documento - + if (!TieneError) { CorreosNotificacion = GuardarUsuariosQueAutorizan(CveDocumento, RutaArchivo, ref ObjOI, ref TieneError); }//asignamos a los usuarios que participaran en aprovar este documento + if (!TieneError) + { + ArchivoNotifiacion = GenerarArchivoByte(RutaArchivo); + NotificarPorCorreo(CorreosNotificacion, RutaArchivo, ArchivoNotifiacion); + } //Gestión de errores y resultados if (!TieneError) { ObjOI.Commit(); Alert("Documento guardado correctamente"); - //this.CveDocumento = CveDocumento; - Response.Redirect(string.Format("/OI/DocumentoDetalle.aspx?CveDocumento={0}",CveDocumento)); + Response.Redirect(string.Format("/OI/DocumentoDetalle.aspx?CveDocumento={0}", CveDocumento)); } else { @@ -215,7 +221,7 @@ public partial class OI_DocumentoDetalle : ClsPaginas this.ErrorMensaje = "Hubo un error al asignar el archivo"; } } - else if(RutaArchivo == "Error") + else if (RutaArchivo == "Error") { TieneError = true; this.ErrorMensaje = "Hubo un error al guardar el archivo"; @@ -223,8 +229,9 @@ public partial class OI_DocumentoDetalle : ClsPaginas return RutaArchivo; } - private void GuardarUsuariosQueAutorizan(int CveDocumento, string RutaArchivo, ref ClsOIEventos ObjOI, ref bool TieneError) + private string GuardarUsuariosQueAutorizan(int CveDocumento, string RutaArchivo, ref ClsOIEventos ObjOI, ref bool TieneError) { + StringBuilder CorreosReturn = new StringBuilder(""); GridViewRowCollection GridUsuarios = GvUsuarios.Rows; foreach (GridViewRow GvRow in GridUsuarios) { @@ -237,12 +244,19 @@ public partial class OI_DocumentoDetalle : ClsPaginas this.ErrorMensaje = "Hubo un error al asignar los usuarios a este documento"; break; } + else + { + CorreosReturn.AppendFormat("{0},", GvRow.DataKey("Correo")); + } } } + + return CorreosReturn.ToString(); } #endregion #region "ARCHIVO ADJUNTO" + private string GuardarArchivo(int CveDocumento) { string RutaArchivo = "-1"; @@ -278,9 +292,7 @@ public partial class OI_DocumentoDetalle : ClsPaginas return RutaArchivo; } - - - protected void LkbDescargarArchivo_Click(object sender,EventArgs e) + protected void LkbDescargarArchivo_Click(object sender, EventArgs e) { string Ruta = string.Format("{0}Empresas/{1}/DocumentosRepo/{2}", ModExtensiones.DirectorioBaseEmpresas, UsuarioActual.CveEmpresa, ArchivoAdjuntoNombre); byte[] archivoBytes = File.ReadAllBytes(Ruta); @@ -295,5 +307,57 @@ public partial class OI_DocumentoDetalle : ClsPaginas } #endregion + #region "NOTIFICACIONES CORREO" + private void NotificarPorCorreo(string Para, string NombreArchivo, byte[] Adjunto) + { + string Descripcion = TxtDescripcion.Text; + string Asunto = "Se le ha agregado como participante en el desarrollo de un Documento"; + string a = string.Format("{0} -- {1} --- {2}", Descripcion, Para, ""); + a.GuardaLog(); + + ClsSisMail Mail = new ClsSisMail(); + + if (Adjunto != null) + { + List LSRutasMail = new List(); + ClsSisMail.ArchivoMail itemMail = new ClsSisMail.ArchivoMail(); + + { + var withBlock = itemMail; + itemMail.ArchivoBinario = Adjunto; + itemMail.NombreArchivo = NombreArchivo; + } + + LSRutasMail.Add(itemMail); + + + Mail.SendMail(ClsPaginas.EmpresaNotificaciones, Para, Asunto, Descripcion, "", LSRutasMail); + Mail = null/* TODO Change to default(_) if this is not a reference type */; + } + else + { + Mail.SendMail(ClsPaginas.EmpresaNotificaciones, Para, Asunto, Descripcion, ""); + Mail = null/* TODO Change to default(_) if this is not a reference type */; + } + } + + private byte[] GenerarArchivoByte(string NombreArchivo) + { + string ArchivoEnviar = string.Format(@"{0}DocumentosRepo\{1}", UsuarioActual.Empresa.Ruta, NombreArchivo); + if (File.Exists(ArchivoEnviar)) + { + System.IO.FileStream fs = System.IO.File.Open(ArchivoEnviar, System.IO.FileMode.Open, System.IO.FileAccess.Read); + byte[] buff = new byte[fs.Length + 1]; + if (fs.Length > 0) + { + fs.Read(buff, 0, (fs.Length.ToString().ToEntero() - 1)); + fs.Close(); + } + return buff; + } + + return new byte[] { }; + } + #endregion } \ No newline at end of file diff --git a/OI/Documentos.aspx b/OI/Documentos.aspx index 724ec70d8..5a202ebaa 100644 --- a/OI/Documentos.aspx +++ b/OI/Documentos.aspx @@ -32,18 +32,13 @@ EmptyDataText="No se encontraron Documentos Registrados" ToolTip="Listado de Documentos" CssClass="table table-striped table-advance table-hover" Style="margin-top: -10px; text-align: center; width: 100%" GridLines="None"> - - - - - - - - - <%-- - --%> - - + + + + + + <%----%> + diff --git a/OI/Documentos.aspx.cs b/OI/Documentos.aspx.cs index e087c71c9..2f162df73 100644 --- a/OI/Documentos.aspx.cs +++ b/OI/Documentos.aspx.cs @@ -20,7 +20,7 @@ public partial class OI_Documentos : ClsPaginas private void CargaDatos() { ClsOIEventos ObjOI = new ClsOIEventos(); - if (ObjOI.GetDocumento(-1,UsuarioActual.CveEmpresa)) + if (ObjOI.ListadoDocumentos(UsuarioActual.CveEmpresa)) { GvDatos.DataSource = ObjOI.DtResultados; GvDatos.DataBind();