/Source/ProjetoFIM/WinForm/EsqueciMinhaSenha.cs

# · C# · 119 lines · 84 code · 20 blank · 15 comment · 8 complexity · 5c8e30b221640c6ff80a9e64150240c9 MD5 · raw file

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Text.RegularExpressions;
  10. using System.Net.Mail;
  11. using ProjetoFIM.LogicaNegocio;
  12. namespace WinForm
  13. {
  14. public partial class EsqueciMinhaSenha : Form
  15. {
  16. #region Métodos
  17. public EsqueciMinhaSenha()
  18. {
  19. IniciarTela();
  20. }
  21. private void IniciarTela()
  22. {
  23. InitializeComponent();
  24. }
  25. private string RetornarNovaSenha()
  26. {
  27. string novaSenha = string.Empty;
  28. Random rd = new Random();
  29. novaSenha += rd.Next(5).ToString();
  30. return novaSenha;
  31. }
  32. public void EnviarEmail()
  33. {
  34. try
  35. {
  36. #warning Verificar qual e-mail iremos usar!!!
  37. //string senha = RetornarNovaSenha();
  38. //SmtpClient enviar = new SmtpClient();
  39. //MailMessage msg = new MailMessage();
  40. ////enviar.Host = "servidor";
  41. ////enviar.Port = porta;
  42. //msg.To.Add("");
  43. //msg.From = new MailAddress(txtEmail.Text.Trim());
  44. //msg.IsBodyHtml = true;
  45. //msg.Subject = "SIGRE - Nova senha";
  46. //msg.Body = string.Format("Sua nova senha é: {0}", senha);
  47. ////enviar.Credentials = new System.Net.NetworkCredential(username, password);
  48. //enviar.Send(msg);
  49. ////Altera senha no Banco de Dados
  50. //LN_Usuario objUsuarioLN = new LN_Usuario();
  51. //objUsuarioLN.AlterarSenha(txtEmail.Text.Trim(), senha);
  52. }
  53. catch (Exception ex)
  54. {
  55. MessageBox.Show(ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
  56. }
  57. }
  58. private bool ValidarCampos()
  59. {
  60. 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})(\]?)$");
  61. LN_Usuario objUsuarioLN = new LN_Usuario();
  62. if (string.IsNullOrEmpty(txtUsuario.Text.Trim()))
  63. {
  64. MessageBox.Show("Informe o usuário.", "Preenchimento obrigatório", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  65. txtUsuario.Focus();
  66. return false;
  67. }
  68. else if (string.IsNullOrEmpty(txtEmail.Text.Trim()))
  69. {
  70. MessageBox.Show("Informe o e-mail.", "Preenchimento obrigatório", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  71. txtEmail.Focus();
  72. return false;
  73. }
  74. else if (!regexEmail.IsMatch(txtEmail.Text.Trim()))
  75. {
  76. MessageBox.Show("Informe um e-mail válido.", "Preenchimento obrigatório", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  77. txtEmail.Focus();
  78. return false;
  79. }
  80. else if (!objUsuarioLN.ExisteEmail(txtEmail.Text.Trim()))
  81. {
  82. MessageBox.Show("E-mail năo cadastrado.", "Preenchimento obrigatório", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  83. txtEmail.Focus();
  84. return false;
  85. }
  86. return true;
  87. }
  88. #endregion
  89. #region Eventos
  90. private void btnOk_Click(object sender, EventArgs e)
  91. {
  92. if (ValidarCampos())
  93. {
  94. EnviarEmail();
  95. }
  96. }
  97. #endregion
  98. }
  99. }