/Source/ProjetoFIM/WinForm/EsqueciMinhaSenha.cs
# · C# · 119 lines · 84 code · 20 blank · 15 comment · 8 complexity · 5c8e30b221640c6ff80a9e64150240c9 MD5 · raw file
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Text.RegularExpressions;
- using System.Net.Mail;
- using ProjetoFIM.LogicaNegocio;
-
- namespace WinForm
- {
- public partial class EsqueciMinhaSenha : Form
- {
- #region Métodos
-
- public EsqueciMinhaSenha()
- {
- IniciarTela();
- }
-
- private void IniciarTela()
- {
- InitializeComponent();
- }
-
- private string RetornarNovaSenha()
- {
- string novaSenha = string.Empty;
-
- Random rd = new Random();
-
- novaSenha += rd.Next(5).ToString();
-
- return novaSenha;
- }
-
- public void EnviarEmail()
- {
- try
- {
- #warning Verificar qual e-mail iremos usar!!!
- //string senha = RetornarNovaSenha();
-
- //SmtpClient enviar = new SmtpClient();
- //MailMessage msg = new MailMessage();
- ////enviar.Host = "servidor";
- ////enviar.Port = porta;
- //msg.To.Add("");
- //msg.From = new MailAddress(txtEmail.Text.Trim());
- //msg.IsBodyHtml = true;
- //msg.Subject = "SIGRE - Nova senha";
- //msg.Body = string.Format("Sua nova senha é: {0}", senha);
-
- ////enviar.Credentials = new System.Net.NetworkCredential(username, password);
-
- //enviar.Send(msg);
-
- ////Altera senha no Banco de Dados
- //LN_Usuario objUsuarioLN = new LN_Usuario();
- //objUsuarioLN.AlterarSenha(txtEmail.Text.Trim(), senha);
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
-
- private bool ValidarCampos()
- {
- Regex regexEmail = new Regex(@"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");
-
- LN_Usuario objUsuarioLN = new LN_Usuario();
-
- if (string.IsNullOrEmpty(txtUsuario.Text.Trim()))
- {
- MessageBox.Show("Informe o usuário.", "Preenchimento obrigatório", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- txtUsuario.Focus();
- return false;
- }
- else if (string.IsNullOrEmpty(txtEmail.Text.Trim()))
- {
- MessageBox.Show("Informe o e-mail.", "Preenchimento obrigatório", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- txtEmail.Focus();
- return false;
- }
- else if (!regexEmail.IsMatch(txtEmail.Text.Trim()))
- {
- MessageBox.Show("Informe um e-mail válido.", "Preenchimento obrigatório", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- txtEmail.Focus();
- return false;
- }
- else if (!objUsuarioLN.ExisteEmail(txtEmail.Text.Trim()))
- {
- MessageBox.Show("E-mail năo cadastrado.", "Preenchimento obrigatório", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- txtEmail.Focus();
- return false;
- }
-
- return true;
- }
-
- #endregion
-
- #region Eventos
-
- private void btnOk_Click(object sender, EventArgs e)
- {
- if (ValidarCampos())
- {
- EnviarEmail();
- }
- }
-
- #endregion
- }
- }