Ejemplo n.º 1
0
        private void LoginButton_Click(object sender, EventArgs e)
        {
            if (txtLogin.Text.Equals(string.Empty))
            {
                MessageBox.Show("Digite o nome de login.", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (txtPwd.Text.Equals(string.Empty))
            {
                MessageBox.Show("Digite a senha.", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            gtiCore.Ocupado(this);
            gtiCore.ServerName = txtServer.Text;

            string      _connection   = gtiCore.Connection_Name();
            Sistema_bll sistema_Class = new Sistema_bll(_connection);

            try {
                string sUser = sistema_Class.Retorna_User_FullName(txtLogin.Text);
                gtiCore.Liberado(this);
                if (string.IsNullOrEmpty(sUser))
                {
                    gtiCore.Liberado(this);
                    MessageBox.Show("Usuário não cadastrado!", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                string sPwd    = sistema_Class.Retorna_User_Password(txtLogin.Text);
                string sPwdOld = sistema_Class.Retorna_User_Password_Old(txtLogin.Text);

                TAcessoFunction _access  = new TAcessoFunction();
                string          _decrypt = _access.DecryptGTI(sPwdOld);
                if (string.IsNullOrEmpty(_decrypt))
                {
                    gtiCore.Liberado(this);
                    MessageBox.Show("Por favor cadastre uma senha!", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    SenhaButton_Click(null, null);
                    return;
                }
                else
                {
                    if (string.Compare(txtPwd.Text, _decrypt) != 0)
                    {
                        gtiCore.Liberado(this);
                        MessageBox.Show("Senha inválida.", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
            } catch (Exception ex) {
                gtiCore.Liberado(this);
                MessageBox.Show(ex.InnerException.Message, "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            gtiCore.LastUser = txtLogin.Text.ToUpper();
            gtiCore.UserId   = sistema_Class.Retorna_User_LoginId(txtLogin.Text);
            //gtiCore.LastUser = txtLogin.Text.ToUpper();
            //Properties.Settings.Default.Save();
            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            config.AppSettings.Settings["lastuser"].Value = txtLogin.Text.ToUpper();
            config.Save(ConfigurationSaveMode.Modified);
            ConfigurationManager.RefreshSection("appSettings");

            int nId = gtiCore.UserId;

            LoadDBSettings(nId);

            usuarioStruct cUser  = sistema_Class.Retorna_Usuario(nId);
            int?          nSetor = cUser.Setor_atual;

            if (nSetor == null || nSetor == 0)
            {
                Usuario_Setor form = new Usuario_Setor();
                form.nId = nId;
                var result = form.ShowDialog(this);
                if (result != DialogResult.OK)
                {
                    return;
                }
            }
            gtiCore.UpdateUserBinary();
            //Update user Binary
            //string sTmp = sistema_Class.GetUserBinary(nId);
            //int nSize = sistema_Class.GetSizeofBinary();
            //GtiTypes.UserBinary = gtiCore.Decrypt(sTmp);
            //if (nSize > GtiTypes.UserBinary.Length) {
            //    int nDif = nSize - GtiTypes.UserBinary.Length;
            //    sTmp = new string('0', nDif);
            //    GtiTypes.UserBinary += sTmp;
            //}
            //     string h = GtiTypes.UserBinary;
            Close();
            Main f1 = (Main)Application.OpenForms["Main"];

            f1.UserToolStripStatus.Text = gtiCore.LastUser;
            f1.LockForm(false);
            gtiCore.Liberado(this);
        }
Ejemplo n.º 2
0
        private void LoginButton_Click(object sender, EventArgs e)
        {
            if (LoginText.Text.Equals(string.Empty))
            {
                MessageBox.Show("Digite o nome de login.", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (PwdText.Text.Equals(string.Empty))
            {
                MessageBox.Show("Digite a senha.", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            gtiCore.Ocupado(this);
            Properties.Settings.Default.ServerName = ServerText.Text;
            Properties.Settings.Default.Save();

            string      _connection   = gtiCore.Connection_Name();
            Sistema_bll sistema_Class = new Sistema_bll(_connection);

            try {
                string sUser = sistema_Class.Retorna_User_FullName(LoginText.Text);
                gtiCore.Liberado(this);
                if (string.IsNullOrEmpty(sUser))
                {
                    gtiCore.Liberado(this);
                    MessageBox.Show("Usuário não cadastrado!", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                string sPwd = sistema_Class.Retorna_User_Password(LoginText.Text);
                if (string.IsNullOrEmpty(sPwd))
                {
                    gtiCore.Liberado(this);
                    MessageBox.Show("Por favor cadastre uma senha!", "Senha não cadastrada", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    SenhaButton_Click(null, null);
                    return;
                }
                else
                {
                    TAcessoFunction _tAcesso = new TAcessoFunction();
                    if (string.Compare(PwdText.Text, _tAcesso.DecryptGTI(sPwd)) != 0)
                    {
                        gtiCore.Liberado(this);
                        MessageBox.Show("Senha inválida.", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        PwdText.Text = "";
                        return;
                    }
                }
            } catch (Exception ex) {
                gtiCore.Liberado(this);
                MessageBox.Show(ex.InnerException.Message, "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            Properties.Settings.Default.ServerName = ServerText.Text.ToUpper();
            Properties.Settings.Default.LastUser   = LoginText.Text.ToUpper();
            Properties.Settings.Default.UserId     = sistema_Class.Retorna_User_LoginId(LoginText.Text);
            Properties.Settings.Default.Save();

            Int32         nId    = Properties.Settings.Default.UserId;
            usuarioStruct cUser  = sistema_Class.Retorna_Usuario(nId);
            int?          nSetor = cUser.Setor_atual;

            if (nSetor == null || nSetor == 0)
            {
                Usuario_Setor form = new Usuario_Setor {
                    nId = nId
                };
                var result = form.ShowDialog(this);
                if (result != DialogResult.OK)
                {
                    return;
                }
            }
            gtiCore.UpdateUserBinary();
            //Update user Binary
            //string sTmp = sistema_Class.GetUserBinary(nId);
            //Int32 nSize = sistema_Class.GetSizeofBinary();
            //GtiTypes.UserBinary = gtiCore.Decrypt(sTmp);
            //if (nSize > GtiTypes.UserBinary.Length) {
            //    Int32 nDif = nSize - GtiTypes.UserBinary.Length;
            //    sTmp = new string('0', nDif);
            //    GtiTypes.UserBinary += sTmp;
            //}
            //     string h = GtiTypes.UserBinary;
            Close();
            Main f1 = (Main)Application.OpenForms["Main"];

            f1.UserToolStripStatus.Text = gtiCore.Retorna_Last_User();
            f1.LockForm(false);
            gtiCore.Liberado(this);
        }