/// <summary>
        ///  发送用户名和密码,处理可能出现的异常,登录成功后将User对象放入客户端,然后启动主窗体。
        /// </summary>
        private void login()
        {
            if (!CheckName())
            {
                this.userNameTextBox.Focus();
                this.userNameTextBox.SelectAll();
                return;
            }

            if (!CheckPassword())
            {
                this.passwordTextBox.Focus();
                this.passwordTextBox.SelectAll();
                return;
            }

            try
            {
                LogedInUser user = null;
                if (ClientConfiguration.IsOffline && (File.Exists(ClientConfiguration.LocalDBFile) && LoginUserOfflineBLL.GetInstance("ClientDB").GetUserCount(userNameTextBox.Text.Trim()) > 0))
                {
                    //离线登录,并取得当前登录用户信息
                    user = LoginUserOfflineBLL.GetInstance("ClientDB").Login(userNameTextBox.Text.Trim(), SecretUtil.MD5Encoding(passwordTextBox.Text));
                }
                else
                {
                    //在线
                    user = ProxyFactory.UserProxy.DoLogin(userNameTextBox.Text.Trim(), SecretUtil.MD5Encoding(passwordTextBox.Text));
                }

                user.HighId = CommUtilBLL.GetInstance("ClientTempDB").GetHighID();
                ClientSession.GetInstance().CurrentUser = user;
                ClientSession.GetInstance().IsLogin     = true;
            }
            catch (LoginException loginEx)
            {
                XtraMessageBox.Show(string.Format("用户登录失败:\n  {0}.", loginEx.Message), "登录失败", MessageBoxButtons.OKCancel);
                //XtraMessageBox.Show(loginEx.StackTrace);
                EventLog.WriteEntry("login", loginEx.StackTrace);
                return;
            }
            catch (Exception ex)
            {
                //这个处理不友好,发布前需要修改
                XtraMessageBox.Show(string.Format("用户登录失败:\n  {0}.", ex.Message), "登录失败", MessageBoxButtons.OKCancel);
                //XtraMessageBox.Show(ex.StackTrace);
                EventLog.WriteEntry("login", ex.StackTrace);
                return;
            }
            this.Hide();
            //usercode写入到app.config文件
            string userCode     = userNameTextBox.Text;
            string userCodeList = ClientConfiguration.UserCode;

            if (!userCodeList.Contains(userCode))
            {
                if (!string.IsNullOrEmpty(userCodeList))
                {
                    ClientConfiguration.UserCode = userCode + "," + userCodeList;
                }
                else
                {
                    ClientConfiguration.UserCode = userCode;
                }
            }
            ClientConfiguration.LastUserCode = userCode;
            ClientConfiguration.Save();

            UserConfigXml.SetConfigInfo("LoginLog", "LoginedUsersCode", ClientConfiguration.UserCode);
            UserConfigXml.SetConfigInfo("LoginLog", "LastLoginedUserCode", ClientConfiguration.LastUserCode);


            this.passwordTextBox.Text = "";
            if (!ClientConfiguration.MenuStyle.Equals("0"))
            {
                new MainForm(this).Show();
            }
            else
            {
                new ParentForm(this).Show();
            }
            //this.Close();
        }
Exemplo n.º 2
0
        private void sbSave_Click(object sender, EventArgs e)
        {
            string sOldpass      = "";
            string sOldpassInput = this.teOrignPsd.Text;
            string sNewpass1     = this.teNewPsd.Text;
            string sNewpass2     = this.teAffirmPsd.Text;


            if (string.IsNullOrEmpty(sOldpassInput))
            {
                XtraMessageBox.Show("旧密码不能为空值!请输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            if (string.IsNullOrEmpty(sNewpass1))
            {
                XtraMessageBox.Show("新密码不能为空值!请输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            //将输入的信息保存到隐藏控件,保存失败时重新写回到页面显示控件中

            //取出本地物化视图中的用户密码
            DataTable dt = PassMgrDAO.GetInstance().GetLocalsysUserInfo(base.CurrentUserId);

            if (dt.Rows.Count > 0)
            {
                //数据库中未加密,这里直接取出后进行比较,如果加密以后,请在此先解密
                sOldpass = dt.Rows[0]["PASSWORD"].ToString();

                //判断输入的密码是否和登陆用户的当前密码相同
                if (sOldpass == SecretUtil.MD5Encoding(sOldpassInput))
                {
                    //判断两次输入的新密码是否相同
                    if (sNewpass1 == sNewpass2)
                    {
                        try
                        {
                            //保存新密码
                            sNewpass1 = SecretUtil.MD5Encoding(sNewpass1);
                            this.SavePassword(sNewpass1);
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                    }
                    else
                    {
                        //提示用户两次输入的新密码不一致
                        XtraMessageBox.Show("两次输入的新密码不一致!请重新输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
                else
                {
                    //提示用户旧密码输入错误
                    XtraMessageBox.Show("用户旧密码输入错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            else
            {
                //本系统未找到当前用户信息
                XtraMessageBox.Show("本系统未找到当前用户信息!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }