protected void cmdEnviar_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                try
                {
                    ProfessorDTO dto = new ProfessorDTO();
                    dto.nomeProfessor  = txtNome.Text;
                    dto.emailProfessor = txtEmail.Text;
                    dto.pwProfessor    = cript2.code.business.SimpleCripto.Encrypt(txtPW.Text + txtEmail.Text.Substring(0, 2), System.Configuration.ConfigurationManager.AppSettings["cript2Hash"].ToString());

                    ProfessorBRL brl = new ProfessorBRL();
                    if (brl.insertMaquina(dto))
                    {
                        lblResultado.Text = "Professor inserido com sucesso.";

                        txtEmail.Text = "";
                        txtNome.Text  = "";
                        txtPW.Text    = "";

                        //enviando e-mail de cadastro
                        enviadEmailAdministradores();
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
        private void preencherGrid()
        {
            ProfessorBRL brl = new ProfessorBRL();

            this.grdAluno.DataSource = brl.allProfessor();
            this.grdAluno.DataBind();
        }
        protected void lnkEsqueceuASenha_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                try
                {
                    if (!String.IsNullOrEmpty(txtUsuario.Text))
                    {
                        ProfessorDTO dto = new ProfessorDTO();
                        dto.emailProfessor = txtUsuario.Text;

                        ProfessorBRL brl     = new ProfessorBRL();
                        DataTable    dtEmail = brl.searchProfessorByEmail(dto);

                        if (dtEmail != null && dtEmail.Rows.Count > 0)
                        {
                            CriptQuery.SecureQueryString qs = new SecureQueryString();
                            qs["Email"] = txtUsuario.Text;
                            qs["Id"]    = dtEmail.Rows[0]["IdProfessor"].ToString();
                            //qs["Tipo"] = "Professor";


                            string[] emails = new string[1];
                            emails[0] = txtUsuario.Text;

                            //string _pw = cript2.code.business.SimpleCripto.Decrypt(dtEmail.Rows[0]["PWProfessor"].ToString(), System.Configuration.ConfigurationManager.AppSettings["cript2Hash"].ToString());

                            StringBuilder str = new StringBuilder();
                            str.Append(@" Segue o link abaixo para alterar a senha solicitada através do sistema BEPiD UCB. <br>
                                      Lembre-se de nunca passar a sua senha para ninguém, toda senha 
                                        é confidencial e intransferível. ");

                            str.Append(@" <Br><Br> Acesse o link ou copie cole no browser: http://admin.bepiducb.com.br/private/LoginAlterarSenha?e=" + qs.ToString() + " <br> e digite nova senha.");
                            str.Append(@" <Br><Br> Em caso de dúvidas, entre em contato conosco pelo menu Contato");

                            BEPiD.Business.Util.EmailEnvio.enviaEmail(emails, "E-mail automático de senha - aluno.bepiducb.com.br", str.ToString());

                            lblResultado.Text = "Foi enviado para seu e-mail.";
                        }
                        else
                        {
                            lblResultado.Text = "O e-mail não está cadastrado, entrar em contato com o administrador.";
                        }
                    }
                    else
                    {
                        lblResultado.Text = "Favor, digite o seu e-mail no campo de e-mail para verificação!";
                        txtUsuario.Focus();
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
        private void preencheComboProfessores()
        {
            ProfessorBRL brl = new ProfessorBRL();

            this.cmbProfessores.DataSource = brl.allProfessor();

            this.cmbProfessores.DataTextField  = "NomeProfessor";
            this.cmbProfessores.DataValueField = "IdProfessor";
            this.cmbProfessores.DataBind();

            this.cmbProfessores.Items.Insert(0, new ListItem("Selecione", "0"));
        }
        protected void cmdLogin_Click(object sender, EventArgs e)
        {
            try
            {
                //if (Session["Tipo"].Equals("Professor"))
                //{
                ProfessorDTO dto = new ProfessorDTO();
                dto.pwProfessor = cript2.code.business.SimpleCripto.Encrypt(txtPassword.Text + hdEmail.Value.Substring(0, 2), System.Configuration.ConfigurationManager.AppSettings["cript2Hash"].ToString());

                if (!String.IsNullOrEmpty(hdId.Value))
                {
                    dto.idProfessor = int.Parse(hdId.Value);
                }

                dto.emailProfessor = hdEmail.Value;

                ProfessorBRL brl = new ProfessorBRL();
                if (brl.updateProfessorSenhaByEmaileId(dto))
                {
                    lblResultado.Text = "Senha alterada com sucesso. <br>Favor acessar o link <a href='Login?Professor=S'>Login</a> para entrar no sistema.";
                    desabilitaCampos();
                }
                else
                {
                    lblResultado.Text = "Erro ao tentar mudar a senha, entrar em contato com o administrador";
                }

                //}
                //else if (Session["Tipo"].Equals("Aluno"))
                //{
                //    AlunoDTO dto = new AlunoDTO();
                //    dto.password = cript2.code.business.SimpleCripto.Encrypt(txtPassword.Text + Session["Email"].ToString().Substring(0, 2), System.Configuration.ConfigurationManager.AppSettings["cript2Hash"].ToString());
                //    dto.idAluno = int.Parse(Session["Id"].ToString());
                //    dto.email = Session["Email"].ToString();

                //    AlunoBRL brl = new AlunoBRL();
                //    if (brl.updateAlunoSenhaByEmaileId(dto))
                //    {
                //        lblResultado.Text = "Senha alterada com sucesso. <br>Favor acessar o link <a href='Login'>Login</a> para entrar no sistema.";
                //        desabilitaCampos();
                //    }
                //    else
                //        lblResultado.Text = "Erro ao tentar mudar a senha, entrar em contato com o administrador";
                //}
            }
            catch (Exception ex)
            {
                lblResultado.Text = "Erro aconteceu. <br> " + ex.ToString();
            }
        }
        protected void cmdLogar_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                try
                {
                    ProfessorDTO dto = new ProfessorDTO();
                    dto.emailProfessor = txtUsuario.Text;
                    dto.pwProfessor    = cript2.code.business.SimpleCripto.Encrypt(txtPass.Text + txtUsuario.Text.Substring(0, 2), System.Configuration.ConfigurationManager.AppSettings["cript2Hash"].ToString());

                    ProfessorBRL brl     = new ProfessorBRL();
                    DataTable    dtTable = brl.searchProfessor(dto);

                    if (dtTable != null && dtTable.Rows.Count > 0)
                    {
                        string _nome = HttpUtility.UrlEncode(dtTable.Rows[0]["NomeProfessor"].ToString(), Encoding.GetEncoding(28597)).Replace("+", " ");

                        if (Request.QueryString["ReturnUrl"] == null)
                        {
                            CriarCookie(_nome,
                                        dtTable.Rows[0]["EmailProfessor"].ToString(),
                                        dtTable.Rows[0]["IdProfessor"].ToString(),
                                        "P",
                                        "");

                            FormsAuthentication.SetAuthCookie("webformAutentication", false);
                            Response.Redirect("/Private/Dados", true);
                        }
                        else
                        {
                            FormsAuthentication.RedirectFromLoginPage("webformAutentication", true);
                        }
                    }
                    else
                    {
                        lblResultado.Text = "E-mail ou senha inválidos. <Br>Tente novamente ou entre em contato conosco.";
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
        protected void cmdLogin_Click(object sender, EventArgs e)
        {
            // try
            //{
            if (Page.IsValid)
            {
                if (hdProfessor.Value.Equals("P"))
                {
                    ProfessorDTO dto = new ProfessorDTO();
                    dto.emailProfessor = txtEmail.Text;
                    dto.pwProfessor    = cript2.code.business.SimpleCripto.Encrypt(txtPassword.Text + txtEmail.Text.Substring(0, 2), System.Configuration.ConfigurationManager.AppSettings["cript2Hash"].ToString());

                    ProfessorBRL brl     = new ProfessorBRL();
                    DataTable    dtTable = brl.searchProfessor(dto);

                    if (dtTable != null && dtTable.Rows.Count > 0)
                    {
                        string _nome = HttpUtility.UrlEncode(dtTable.Rows[0]["NomeProfessor"].ToString(), Encoding.GetEncoding(28597)).Replace("+", " ");
                        CriarCookie(_nome,
                                    dtTable.Rows[0]["EmailProfessor"].ToString(),
                                    dtTable.Rows[0]["IdProfessor"].ToString(),
                                    "P",
                                    "");

                        Response.Redirect("Dados.aspx");
                    }
                    else
                    {
                        lblResultado.Text = "E-mail ou senha inválidos. <Br>Tente novamente ou entre em contato conosco.";
                    }
                }
                else if (hdProfessor.Value.Equals("A"))
                {
                    AlunoDTO dto = new AlunoDTO();
                    dto.email    = txtEmail.Text;
                    dto.password = cript2.code.business.SimpleCripto.Encrypt(txtPassword.Text + txtEmail.Text.Substring(0, 2), System.Configuration.ConfigurationManager.AppSettings["cript2Hash"].ToString());

                    AlunoBRL  brl     = new AlunoBRL();
                    DataTable dtTable = brl.searchUserLogin(dto);

                    if (dtTable != null && dtTable.Rows.Count > 0)
                    {
                        string _nome = HttpUtility.UrlEncode(dtTable.Rows[0]["Nome"].ToString(), Encoding.GetEncoding(28597)).Replace("+", " ");
                        CriarCookie(_nome,
                                    dtTable.Rows[0]["Email"].ToString(),
                                    dtTable.Rows[0]["IdAluno"].ToString(),
                                    "A",
                                    dtTable.Rows[0]["CPF"].ToString());

                        Response.Redirect("Dados.aspx");
                    }
                    else
                    {
                        lblResultado.Text = "E-mail ou senha inválidos. <Br>Tente novamente ou entre em contato conosco.";
                    }
                }
            }
            //}
            //catch (Exception ex)
            //{
            //    enviaEmailError(txtEmail.Text, ex.ToString() + ex.StackTrace.ToString());
            //}
        }