예제 #1
0
        /// <summary>
        /// 用戶登錄
        /// </summary>
        private void DoLogin()
        {
            try
            {
                string strCode = tbxUserName.Text.ToString();
                string strPwd  = desEncrypt.getMd5Hash(tbxPwd.Text.ToString());
                //获取用户信息
                DADictuser user = new DADictuser();
                user.Usercode = strCode;
                string strUsercode = user.Usercode;
                user = new DADictuserBLL().GetDADictuserInfoByUserCode(user);
                //获取系统参数
                decimal cid = DefaultConfig.DACONFIGID;
                //转换不成功
                if (!decimal.TryParse(ConfigurationManager.AppSettings["DaConfigID"], out cid))
                {
                    ShowMessageHelper.ShowBoxMsg("请先维护好配置ID!");
                    return;
                }
                config = configBll.SelectyDAConfigInfo(cid);
                if (config == null)
                {
                    ShowMessageHelper.ShowBoxMsg("没有ID为[" + cid + "]的配置记录");
                    return;
                }
                //再次校验用户名
                if (user == null || user.Usercode != strUsercode)
                {
                    ShowMessageHelper.ShowBoxMsg("帐号或密码错误,请重新输入!");
                    return;
                }
                //存在对应用户校验密码跟用户状态
                if (user != null && user.Password == strPwd)
                {
                    //账户已被停用
                    if (user.Isactive.ToString() == "0")
                    {
                        ShowMessageHelper.ShowBoxMsg("该账户已被停用!");
                        return;
                    }
                    else//账户未已被停用
                    {
                        //保存用户信息
                        LoginUserInfo userInfo = new LoginUserInfo();
                        userInfo.UserCode = tbxUserName.Text.ToString();
                        userInfo.UserId   = user.Dictuserid.ToString();
                        userInfo.UserName = user.Username;
                        userInfo.UserType = 1;
                        //登录webservice获取SID保存
                        if (config != null)
                        {
                            string strSideCode = config.Sitecode; //分点代码
                            string strUrl      = config.Address;  //调用webservice地址
                            string username    = config.Username; //登录用户名
                            string password    = config.Password; //登录用户密码

                            //设置调用webservice登录方法的参数
                            string[] par = new string[] { strSideCode, username, password, user.Username };
                            //获取webservice更新
                            WebServiceUtils.SetIsUpdate(config.Address);
                            //登录验证
                            object loginResult = WebServiceUtils.ExecuteMethod("Login", par);

                            //返回登录验证信息:1|SID,0|errorMsg
                            string[] loginMsg = loginResult.ToString().Split('|');
                            //登录成功 设置SID
                            if (loginMsg[0] == "1")
                            {
                                userInfo.SID = loginMsg[1].ToString();
                                ////设置调用webservice获取中心库数据(客户表、项目表、基础字典表)方法的参数
                                //DateTime itemdt = new DATablelastdateBLL().SelectyDATablelastdateInfoByTableName("da_dicttestitem");
                                //DateTime librarydt = new DATablelastdateBLL().SelectyDATablelastdateInfoByTableName("da_dictlibrary");
                                //DateTime customerdt = new DATablelastdateBLL().SelectyDATablelastdateInfoByTableName("da_dictcustomer");
                                //object[] parameters = new object[] { userInfo.SID, itemdt, librarydt, customerdt };
                                //string strXML = WebServiceUtils.Execute(strUrl, "GetCenterTableDate", parameters);
                                //string  reg  =   common.GetCenterTableDate(strXML);
                                //ShowMessageHelper.ShowBoxMsg(reg);
                            }
                            else
                            {
                                ShowMessageHelper.ShowBoxMsg("WebService登录失败,错误信息:" + loginMsg[1].ToString() + "\n请检查系统参数配置!");
                            }
                        }
                        //保存用户信息到SystemConfig类
                        SystemConfig.UserInfo = userInfo;
                        //登录成功
                        bLogin            = true;
                        this.DialogResult = DialogResult.OK;
                    }
                }
                else
                {
                    ShowMessageHelper.ShowBoxMsg("帐号或密码错误,请重新输入!");
                    return;
                }
            }
            catch (Exception ex)
            {
                ShowMessageHelper.ShowBoxMsg("登录的过程中发生了错误,错误信息:" + ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }