/// <summary> /// Email /// </summary> /// <param name="emailRemitenteRFC"></param> /// <param name="serverSMTP"></param> /// <param name="usuarioSMTP"></param> /// <param name="pswSMTP"></param> /// <param name="port"></param> /// <param name="enableSSL"></param> public HelperEmail(string emailRemitenteRFC, string serverSMTP, string usuarioSMTP, string pswSMTP, int?port = null, bool?enableSSL = null) { try { if (HelperValidate.IsEmpty(emailRemitenteRFC)) { throw new ArgumentNullException("No se ha indicado el email del remitente (FactoryMail: Email"); } if (HelperValidate.IsEmpty(serverSMTP)) { throw new ArgumentNullException("No se ha indicado el servidor SMTP (FactoryMail: Email"); } if (HelperValidate.IsEmpty(emailRemitenteRFC)) { throw new ArgumentNullException("No se ha indicado el usuario del servidor SMTP (FactoryMail: Email"); } if (HelperValidate.IsEmpty(emailRemitenteRFC)) { throw new ArgumentNullException("No se ha indicado la contraseña del usuario del servidor SMTP (FactoryMail: Email"); } this.Correo = new MailMessage( ) { HeadersEncoding = System.Text.Encoding.UTF8, SubjectEncoding = System.Text.Encoding.UTF8, BodyEncoding = System.Text.Encoding.UTF8 }; this.Correo.From = new MailAddress(emailRemitenteRFC); this.Correo.IsBodyHtml = true; this.Correo.Priority = MailPriority.Normal; // Server SMTP this.Smtp = new SmtpClient(serverSMTP); this.Smtp.UseDefaultCredentials = false; if (port.HasValue) { this.Smtp.Port = port.Value; } if (enableSSL.HasValue) { this.Smtp.EnableSsl = enableSSL.Value; } // User SMTP if (!HelperValidate.IsEmpty(usuarioSMTP) && !HelperValidate.IsEmpty(pswSMTP)) { this.Smtp.Credentials = new System.Net.NetworkCredential(usuarioSMTP, pswSMTP); } } catch (Exception ex) { throw new Exception("Imposible crear email (FactoryMail: Email) " + ex.Message, ex); } }
/// <summary> /// Añade un valor (string)/ clave (int) al combo /// </summary> /// <param name="ddl"></param> /// <param name="key"></param> /// <exception cref="ex"></exception> /// <param name="value"></param> public static void AddKeyValue(DropDownList ddl, string key, string value) { if (HelperValidate.IsEmpty(key)) { throw new ArgumentNullException("No se ha indicado la clave donde insertar (WFCombobox: AddKeyValue)"); } ddl.Items.Add(new ListItem(value, key)); }
/// <summary> /// Añade un emaail al CCO. Lanza excepción sino es un email /// </summary> /// <param name="email"></param> /// <exception cref="ex">Exception</exception> public void AddCCO(string email) { if (!HelperValidate.IsEmail(email)) { throw new Exception("La dirección de correo CCO no es un email válido (AtxMail: AddCCO)"); } this.Correo.Bcc.Add(new MailAddress(email)); }
/// <summary> /// Añade un email y descripción al To. Lanza excepción sino es un email /// </summary> /// <param name="email"></param> /// <param name="displayName"></param> public void AddTo(string email, string displayName) { if (!HelperValidate.IsEmail(email)) { throw new Exception("La dirección de correo TO no es un email válido (FactoryMail: AddTo)"); } this.Correo.To.Add(new MailAddress(email, displayName, System.Text.Encoding.Default)); }
/// <summary> /// Añade un email al To. Lanza excepción sino es un email /// </summary> /// <param name="email"></param> /// <exception cref="ex">Exception</exception> public void AddTo(string email) { if (!HelperValidate.IsEmail(email)) { throw new Exception("La dirección de correo TO no es un email válido (FactoryMail: AddTo)"); } this.Correo.To.Add(new MailAddress(email)); }
/// <summary> /// Añade al final una clave(string)/valor(int) al ListBox /// </summary> /// <param name="ddl">Listbox</param> /// <param name="key">string</param> /// <param name="value">int</param> public static void AddKeyValue(ListBox ddl, string key, int value) { if (HelperValidate.IsEmpty(key)) { throw new ArgumentNullException("No se ha indicado la clave donde insertar (AtxListBox: AddKeyValue)"); } ddl.Items.Add(new ListItem(value.ToString(), key)); }
/// <summary> /// Inserta un clave(string)/valor(int) al combo en una posicion determinada. /// </summary> /// <param name="ddl">DropDownList</param> /// <param name="Pos">int</param> /// <param name="key">string</param> /// <param name="value">int</param> /// <exception cref="ex">Exception</exception> public static void InsertKeyValue(DropDownList ddl, int Pos, string key, int value) { if (Pos < 0) { throw new ArgumentOutOfRangeException("La posición donde insertar no puede ser menor de 0 (WFCombobox InsertKeyValue)"); } if (HelperValidate.IsEmpty(key)) { throw new ArgumentNullException("No se ha indicado la clave donde insertar (WFCombobox: InsertKeyValue)"); } ddl.Items.Insert(Pos, new ListItem(value.ToString(), key)); }
/// <summary> /// Asigna un valor string a una variable guardada en la sesion /// </summary> /// <param name="key"></param> /// <param name="value"></param> public static void SetValue(string key, string value) { if (HelperValidate.IsEmpty(key)) { throw new NullReferenceException("Clave no especificada (FactortWebSession: SetValue)"); } if (null == HttpContext.Current || null == HttpContext.Current.Session) { throw new Exception("No existe HttpContext (FactoryWebSession: SetValue)"); } HttpContext.Current.Session[key] = value; }
/// <summary> /// Inserta una clave(string)/valor(string) al ListBox en una posicion determinada. /// 0 es la primera /// </summary> /// <param name="ddl">Listbox</param> /// <param name="Pos">int</param> /// <param name="key">string</param> /// <param name="value">string</param> public static void InsertKeyValue(ListBox ddl, int Pos, string key, string value) { if (Pos < 0) { throw new ArgumentOutOfRangeException("La posición donde insertar no puede ser menor de 0 (AtxListbix InsertKeyValue)"); } if (HelperValidate.IsEmpty(key)) { throw new ArgumentNullException("No se ha indicado la clave donde insertar (AtxListBox: InsertKeyValue)"); } ddl.Items.Insert(Pos, new ListItem(value, key)); }
/// <summary> /// Devuelve un valor (short) de una propiedad guardada en al session /// </summary> /// <param name="key"></param> /// <exception cref="ex"></exception> /// <returns></returns> protected static byte GetValueByte(string key) { if (HelperValidate.IsEmpty(key)) { throw new NullReferenceException("Clave no especificada (FactortWebSession: GetValue)"); } if (null == HttpContext.Current || null == HttpContext.Current.Session || null == HttpContext.Current.Session[key]) { throw new Exception("No existe valor Byte de (" + key + ") en la session"); } return(HelperString.ToByte(Convert.ToString(HttpContext.Current.Session[key]))); }
/// <summary> /// Elimina una clave determinada (string) del ListBox /// </summary> /// <param name="ddl">ListBox</param> /// <param name="Key">string</param> public static void RemoveKey(ListBox ddl, string Key) { if (HelperValidate.IsEmpty(Key)) { throw new ArgumentNullException("No se ha indicado la clave a eliminar (AtxListBox: RemoveKey)"); } ListItem item = ddl.Items.FindByValue(Key); if (null != item) { ddl.Items.Remove(item); } }
/// <summary> /// Asigna una colección de objeto a un CheckList. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="elem"></param> /// <param name="lst"></param> /// <param name="Key">Nombre del campo del obleto que se usa para la clave</param> /// <param name="Text">Nombre del campo del obleto que se usa para el texto</param> public static void DataBind <T>(CheckBoxList elem, IEnumerable <T> lst, string FieldNameKey, string FieldNameText) { if (HelperValidate.IsEmpty(FieldNameKey)) { throw new ArgumentNullException("No se ha indicado la clave (WFCheckboxList: DataBind)"); } if (HelperValidate.IsEmpty(FieldNameText)) { throw new ArgumentNullException("No se ha indicado el texto (WFCheckboxList: DataBind)"); } elem.DataSource = lst; elem.DataTextField = FieldNameText; elem.DataValueField = FieldNameKey; elem.DataBind( ); }
/// <summary> /// Elimina una clave (string) determinada del combo, devuelve true si la ha elimiando o false so no la ha eliminado (no existe) /// </summary> /// <param name="ddl">DropDownList </param> /// <param name="Key">string</param> /// <returns>bool</returns> public static bool RemoveKey(DropDownList ddl, string Key) { if (HelperValidate.IsEmpty(Key)) { throw new ArgumentNullException("No se ha indicado la clave donde insertar (WFCombobox: AddKeyValue)"); } ListItem item = ddl.Items.FindByValue(Key); if (null != item) { ddl.Items.Remove(item); return(true); } return(false); }
/// <summary> /// Guarda una variable en la session /// </summary> /// <typeparam name="T"></typeparam> /// <param name="key"></param> /// <param name="value"></param> /// <exception cref="ex">Exception</exception> public static void Set <T>(string key, T value) { if (HelperValidate.IsEmpty(key)) { throw new ArgumentNullException("No se ha indicado clave (" + key + ") en la sesión (FactoryWebSession: Set)"); } if (null == value) { // El valor puede ser "" throw new ArgumentNullException("No se puede guardar un valor null en la sesion: (" + key + ") (FactoryWebSession: Set)"); } if (null == HttpContext.Current || null == HttpContext.Current.Session) { throw new Exception("No existe HttpContext (FactoryWebSession: Set)"); } HttpContext.Current.Session.Add(key, value); }
/// <summary> /// Devuelve un valor (short) de una propiedad guardada en al session /// </summary> /// <param name="key"></param> /// <exception cref="ex"></exception> /// <returns></returns> protected static DateTime GetValueDateTime(string key) { if (HelperValidate.IsEmpty(key)) { throw new NullReferenceException("Clave no especificada (FactortWebSession: GetValue)"); } if (null == HttpContext.Current || null == HttpContext.Current.Session || null == HttpContext.Current.Session[key]) { throw new Exception("No existe valor DateTime de (" + key + ") en la session"); } string sDate = Convert.ToString(HttpContext.Current.Session[key]); DateTime dt; if (System.DateTime.TryParse(sDate, out dt)) { return(dt); } throw new Exception("Valor DateTime erróneo en la session"); }