public static void WriteInformationLog(string strMessage) { bool bolCreateEventLog = ISConvert.ToBoolean(ISConfiguration.GetConfigurationParameter("Exception", "_appErro_CreateEventLog")); bool bolCreateFileLog = ISConvert.ToBoolean(ISConfiguration.GetConfigurationParameter("Exception", "_appErro_CreateFileLog")); if (bolCreateEventLog || bolCreateFileLog) { var sbLogMessage = new StringBuilder(""); sbLogMessage.Append("Date: ").Append(DateTime.Now.ToString("dd-MM-yyyy")).Append('\t'); sbLogMessage.Append("Time: ").Append(DateTime.Now.ToString("HH:mm:ss.fff")).Append("\r\n"); sbLogMessage.Append(strMessage).Append("\r\n"); if (bolCreateFileLog) { if (!writeFileLog(sbLogMessage.ToString())) { bolCreateEventLog = true; } } if (bolCreateEventLog) { writeEventLog(sbLogMessage.ToString(), EventLogEntryType.Information); } } }
protected void btnEmitir_Click(object sender, EventArgs e) { try { if (Page.IsValid) { DateTime desde = ISConvert.ToDateTime(txtDesde.Text); DateTime hasta = ISConvert.ToDateTime(txtHasta.Text); int? IdCliente = null; if (!string.IsNullOrEmpty(ddlClientes.SelectedValue)) { IdCliente = int.Parse(ddlClientes.SelectedValue); } int tipo = int.Parse(ddlNotaCobro.SelectedValue); TrxFACTURACION _TrxFACTURACION = new TrxFACTURACION(); _TrxFACTURACION.EmitirNotasCobros(desde, hasta, tipo, IdCliente); Response.Redirect("MensajeExito.aspx?t=Emisión de Notas de Cobros&m=Se han emitidos los documentos correspondientes", false); } } catch (Exception ex) { ISException.RegisterExcepcion(ex); panelMensaje.CssClass = "MostrarMensaje"; lblMensaje.Text = ex.Message; return; } }
private void getFacturas() { DateTime FechaDesde = ISConvert.ToDateTime(txtFechaEmisionDesde.Text); DateTime FechaHasta = ISConvert.ToDateTime(txtFechaEmisionHasta.Text); var facturacion = new TrxFACTURACION(); grdFacturas.DataSource = facturacion.GetResumenFacturacion(FechaDesde, FechaHasta); grdFacturas.DataBind(); }
public static void RegisterExcepcion(Exception objException) { bool bolCreateEventLog = ISConvert.ToBoolean(ISConfiguration.GetConfigurationParameter("Exception", "_appErro_CreateEventLog")); bool bolCreateFileLog = ISConvert.ToBoolean(ISConfiguration.GetConfigurationParameter("Exception", "_appErro_CreateFileLog")); bool bolSendMailOnError = ISConvert.ToBoolean(ISConfiguration.GetConfigurationParameter("Exception", "_appErro_SendMailOnError")); if (bolCreateEventLog || bolCreateFileLog) { var objStackTrace = new StackTrace(); string strClassName; string strMethodName; var sbLogMessage = new StringBuilder(""); strClassName = objStackTrace.GetFrame(1).GetMethod().DeclaringType.Name; strMethodName = objStackTrace.GetFrame(1).GetMethod().Name; sbLogMessage.Append("Date: ").Append(DateTime.Now.ToString("dd-MM-yyyy")).Append('\t'); sbLogMessage.Append("Time: ").Append(DateTime.Now.ToString("HH:mm:ss.fff")).Append("\r\n"); sbLogMessage.Append("Object Class: ").Append(strClassName).Append('\t'); sbLogMessage.Append("Object Method: ").Append(strMethodName).Append("\r\n"); sbLogMessage.Append("Object Exception: ").Append(objException.Message).Append("\r\n"); if (objException.GetType().FullName.Equals("System.Data.SqlClient.SqlException")) { var objSqlException = (SqlException)objException; sbLogMessage.Append("DB Procedure: ").Append(objSqlException.Procedure).Append("\r\n"); sbLogMessage.Append("DB Line: ").Append(objSqlException.LineNumber).Append("\r\n"); sbLogMessage.Append("DB Message: ").Append(objSqlException.Message).Append("\r\n"); } else if (objException.GetType().FullName.Equals("System.Data.OracleClient.OracleException")) { var objOracleException = (OracleException)objException; sbLogMessage.Append("DB Procedure: ").Append(objOracleException.Source).Append("\r\n"); sbLogMessage.Append("DB Line: ").Append(objOracleException.TargetSite).Append("\r\n"); sbLogMessage.Append("DB Message: ").Append(objOracleException.Message).Append("\r\n"); } if (objException.StackTrace != null) { // STACK TRACE: sbLogMessage.Append("StackTrace: ").Append("\r\n"); sbLogMessage.Append(objException.StackTrace).Append("\r\n"); } if (objException.InnerException != null && objException.InnerException.Message != null) { sbLogMessage.Append(objException.InnerException.Message).Append("\r\n"); if (objException.InnerException.StackTrace != null) { // STACK TRACE INNER EXCEPTION: sbLogMessage.Append("StackTrace InnerException: ").Append("\r\n"); sbLogMessage.Append(objException.InnerException.StackTrace).Append("\r\n"); } } if (bolCreateFileLog) { if (!writeFileLog(sbLogMessage.ToString())) { bolCreateEventLog = true; } } if (bolCreateEventLog) { if (!writeEventLog(sbLogMessage.ToString(), EventLogEntryType.Error)) { bolSendMailOnError = true; } } if (bolSendMailOnError) { string strAdminEmail = ISConvert.ToString(ISConfiguration.GetConfigurationParameter("Exception", "_appErro_AdminEmail")); string strSubject = ISConvert.ToString(ISConfiguration.GetConfigurationParameter("Exception", "_appErro_Subject")); string strError; var objISEmail = new ISEmail(); objISEmail.SendMailAsync(strAdminEmail, strSubject, sbLogMessage.ToString(), false, out strError); } } //throw objException; }
/// <summary> /// Envio de email con varios adjuntos. /// </summary> /// <param name="to"></param> /// <param name="subject"></param> /// <param name="body"></param> /// <param name="isHtmlBody"></param> /// <param name="attachments"></param> /// <param name="resultMessage"></param> /// <returns></returns> public static bool SendMailWithAttachment(string to, string subject, string body, bool isHtmlBody, IList <Adjunto> attachments, out string resultMessage) { //SE VALIDA CONFIGURACION DE CORREO if (string.IsNullOrEmpty(ISConfiguration.GetConfigurationParameter("Email", "_appMail_FromAddress"))) { resultMessage = "Invalid configuration value: FromAddress"; ISException.RegisterExcepcion(resultMessage); return(false); } try { using (var mailMessage = new MailMessage { From = new MailAddress(ISConfiguration.GetConfigurationParameter("Email", "_appMail_FromAddress")), Subject = subject, Body = body, IsBodyHtml = isHtmlBody, }) { mailMessage.To.Add(to); //SE AGREGAN LOS ADJUNTOS if (attachments != null && attachments.Count > 0) { for (int i = 0; i < attachments.Count; i++) { if (!string.IsNullOrEmpty(attachments[i].Contenido) && !string.IsNullOrEmpty(attachments[i].Nombre)) { //SE CARGA EL ADJUNTO AL MENSAJE byte[] filebytes = Convert.FromBase64String(attachments[i].Contenido); Stream stream = new MemoryStream(filebytes); mailMessage.Attachments.Add(new Attachment(stream, attachments[i].Nombre)); } } } //SE CREA EL CLIENTE SMTP var smtpClient = new SmtpClient { Host = ISConfiguration.GetConfigurationParameter("Email", "_appMail_SmtpServer"), Port = ISConvert.ToInteger(ISConfiguration.GetConfigurationParameter("Email", "_appMail_SmtpPort")), Credentials = new NetworkCredential( ISConfiguration.GetConfigurationParameter("Email", "_appMail_User"), ISConfiguration.GetConfigurationParameter("Email", "_appMail_Password"), ISConfiguration.GetConfigurationParameter("Email", "_appMail_Domain")), EnableSsl = ISConvert.ToBoolean(ISConfiguration.GetConfigurationParameter("Email", "_appMail_AuthenticationRequired")) }; //SE ENVIA EL MAIL //smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; smtpClient.Send(mailMessage); } resultMessage = string.Empty; return(true); } catch (FormatException ex) { resultMessage = ex.Message; ISException.RegisterExcepcion(ex); return(false); } catch (SmtpException ex) { resultMessage = ex.Message; ISException.RegisterExcepcion(ex); return(false); } catch (Exception ex) { resultMessage = ex.Message; ISException.RegisterExcepcion(ex); return(false); } }
public bool SendMail(string[] strListTo, string[] strListCc, string strSubject, string strBody, bool blnIsBodyHtml, bool blnAsyncMethod, object objState, out string _strResultMessage) { if (string.IsNullOrEmpty(ISConfiguration.GetConfigurationParameter("Email", "_appMail_FromAddress"))) { _strResultMessage = "Invalid configuration value: FromAddress"; ISException.RegisterExcepcion(_strResultMessage); return(false); } try { var objMailMessage = new MailMessage(); objMailMessage.From = new MailAddress(ISConfiguration.GetConfigurationParameter("Email", "_appMail_FromAddress")); for (int index = 0; index < strListTo.Length; index++) { objMailMessage.To.Add(strListTo[index]); } for (int index = 0; index < strListCc.Length; index++) { objMailMessage.CC.Add(strListCc[index]); } objMailMessage.Subject = strSubject; objMailMessage.Body = strBody; objMailMessage.IsBodyHtml = blnIsBodyHtml; var objSmtpClient = new SmtpClient(); objSmtpClient.Host = ISConfiguration.GetConfigurationParameter("Email", "_appMail_SmtpServer"); objSmtpClient.Port = ISConvert.ToInteger(ISConfiguration.GetConfigurationParameter("Email", "_appMail_SmtpPort")); ; objSmtpClient.Credentials = new NetworkCredential(ISConfiguration.GetConfigurationParameter("Email", "_appMail_User"), ISConfiguration.GetConfigurationParameter("Email", "_appMail_Password"), ISConfiguration.GetConfigurationParameter("Email", "_appMail_Domain")); objSmtpClient.EnableSsl = ISConvert.ToBoolean(ISConfiguration.GetConfigurationParameter("Email", "_appMail_AuthenticationRequired")); if (blnAsyncMethod) { objSmtpClient.SendCompleted += objSmtpClient_SendCompleted; objSmtpClient.SendAsync(objMailMessage, objState); _strResultMessage = string.Empty; return(true); } objSmtpClient.Send(objMailMessage); _strResultMessage = string.Empty; return(true); } catch (FormatException ex) { _strResultMessage = ex.Message; ISException.RegisterExcepcion(ex); return(false); } catch (SmtpException ex) { _strResultMessage = ex.Message; ISException.RegisterExcepcion(ex); return(false); } catch (Exception ex) { _strResultMessage = ex.Message; ISException.RegisterExcepcion(ex); return(false); } }