Example #1
0
 private void frmLogin_FormClosing(object sender, FormClosingEventArgs e)
 {
     try
     {
         if (!Login && !String.IsNullOrEmpty(Acesso.NM_CONFIG))
         {
             Acesso.NM_CONFIG_TEMP = Acesso.NM_CONFIG;
             HlpDbFuncoesGeral.NovaConexao();
             Acesso.CarregaDadosBanco();
         }
     }
     catch (Exception ex)
     {
         new HLPexception(ex);
     }
 }
Example #2
0
        private void btnEntrar_Click(object sender, EventArgs e)
        {
            try
            {
                errorProvider1.Dispose();
                if (txtUsuario.Text.Equals(""))
                {
                    errorProvider1.SetError(txtUsuario, "Campo Obrigatório");
                }
                else if (txtSenha.Text.Equals(""))
                {
                    errorProvider1.SetError(txtSenha, "Campo Obrigatório");
                }
                else
                {
                    HlpDbFuncoesGeral.NovaConexao();
                    Acesso.CarregaDadosBanco();
                    string sUser  = txtUsuario.Text.ToUpper().Trim().PadLeft(10, '0');
                    string sSenha = txtSenha.Text.ToUpper().Trim();

                    int iCountUser = Convert.ToInt32(HlpDbFuncoes.qrySeekValue("ACESSO", "count(acesso.CD_OPERADO)", "acesso.CD_OPERADO = '" + sUser + "'"));

                    string sTipoUsuario = "";

                    if (iCountUser > 0)
                    {
                        StringBuilder sQuery = new StringBuilder();
                        if (Acesso.NM_RAMO != Acesso.BancoDados.TRANSPORTE)
                        {
                            sQuery.Append("select acesso.tp_operado, acesso.cd_senha, COALESCE(acesso.st_altera_dados_nfe,'S') st_altera_dados_nfe ");
                            if (HlpDbFuncoes.fExisteCampo("ST_ACESSA_CONFIG_NFE", "ACESSO"))
                            {
                                sQuery.Append(", COALESCE(ACESSO.ST_ACESSA_CONFIG_NFE,'N')ST_ACESSA_CONFIG_NFE ");
                            }
                            else
                            {
                                sQuery.Append(", 'N' ST_ACESSA_CONFIG_NFE ");
                            }

                            sQuery.Append("from acesso ");
                            sQuery.Append("where acesso.cd_senha = '" + belCriptografia.Encripta(sSenha) + "' ");
                            sQuery.Append("and acesso.CD_OPERADO = '" + sUser + "'");
                        }
                        else
                        {
                            sQuery.Append("select acesso.tp_operado, acesso.cd_senha ");
                            sQuery.Append("from acesso ");
                            sQuery.Append("where acesso.cd_senha = '" + belCriptografia.Encripta(sSenha) + "' ");
                            sQuery.Append("and acesso.CD_OPERADO = '" + sUser + "'");
                        }

                        DataTable dt = HlpDbFuncoes.qrySeekRet(sQuery.ToString());

                        foreach (DataRow dr in dt.Rows)
                        {
                            sTipoUsuario = dr["tp_operado"].ToString();
                            if (Acesso.NM_RAMO != Acesso.BancoDados.TRANSPORTE)
                            {
                                Acesso.bALTERA_DADOS = (dr["st_altera_dados_nfe"].ToString().Equals("N") ? false : true);
                                Acesso.bALTER_CONFIG = (dr["ST_ACESSA_CONFIG_NFE"].ToString().Equals("S") ? true : false);
                            }
                        }

                        if (sTipoUsuario != "")
                        {
                            Login              = true;
                            Acesso.NM_CONFIG   = Acesso.NM_CONFIG_TEMP;
                            Acesso.USER_LOGADO = true;
                            Acesso.CarregaAcesso();
                            CarregaVariavesSistema();
                            Acesso.NM_USER = sUser;
                            this.Close();
                        }
                        else
                        {
                            errorProvider1.SetError(txtSenha, "Senha Incorreta");
                            txtSenha.Focus();
                            txtSenha.Text = "";
                        }
                    }
                    else
                    {
                        errorProvider1.SetError(txtUsuario, "Usuário Incorreto");
                        txtUsuario.Focus();
                        txtUsuario.Text = "";
                    }
                }
            }
            catch (Exception ex)
            {
                new HLPexception(ex);
            }
        }