Ejemplo n.º 1
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="id"></param>
        /// <param name="pwd"></param>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        private bool Login(string id, string pwd, ref string errMsg)
        {
            var         errCode = 0;
            AccountInfo info    = ListAccountInfo.FirstOrDefault(c => c.ID == this.LoginID);

            if (info != null)
            {
                TimeSpan span = DateTime.Now - info.LastLoginTime;
                if (span.TotalSeconds < 10)
                {
                    var loginWindow = LoginWindow as LoginWindowView;
                    loginWindow?.LoginFault();
                    return(false);
                }
                else
                {
                    //    info.IsLogin = true;
                    info.LastLoginTime = DateTime.Now;
                    DataConverter.EntityToXml(
                        System.Environment.CurrentDirectory + "/AccountCache.xml", ListAccountInfo, ref errMsg);
                }
            }
            Stopwatch stopWatch = new Stopwatch();

            if (!AntSdkService.AntSdkLogin(id, pwd, UserSelectedState.OnlineState, IdentifyingCode, ref errCode, ref errMsg))
            {
                if (info != null)
                {
                    info.LastLoginTime = DateTime.Now.AddMinutes(-1);
                }
                //TimeSpan time = DateTime.Now - LoginPwdErrorDateTime;
                if (errCode == 10022)
                {
                    if (info != null && !info.IsIdentifyingCode)
                    {
                        info.IsIdentifyingCode = true;
                    }
                    LoginPwd = string.Empty;
                    if (!IsIdentifyingCode)
                    {
                        IsIdentifyingCode = true;
                    }
                    IdentifyingCode = string.Empty;
                    SetVerifyCodeImage();
                    if (!loginIDList.ContainsKey(id))
                    {
                        loginIDList.Add(id, DateTime.Now.AddMinutes(-1));
                    }
                }
                else if (errCode == 10014 && IsIdentifyingCode)
                {
                    IdentifyingCode = string.Empty;
                    SetVerifyCodeImage();
                }
                else if (errCode == 10023)
                {
                    IdentifyingCode = string.Empty;
                    if (!IsIdentifyingCode)
                    {
                        if (!loginIDList.ContainsKey(id))
                        {
                            loginIDList.Add(id, DateTime.Now.AddMinutes(-1));
                        }
                        IsIdentifyingCode = true;
                    }
                    SetVerifyCodeImage();
                    //this.TipsLabelText = errMsg;
                }
                DataConverter.EntityToXml(
                    System.Environment.CurrentDirectory + "/AccountCache.xml", ListAccountInfo, ref errMsg);
                return(false);
            }
            else
            {
                if (info != null && info.IsIdentifyingCode)
                {
                    info.IsIdentifyingCode = false;
                    DataConverter.EntityToXml(
                        System.Environment.CurrentDirectory + "/AccountCache.xml", ListAccountInfo, ref errMsg);
                }
                loginIDList.Remove(id);
                checkCode          = string.Empty;
                IdentifyingCode    = string.Empty;
                LoginPwdErrorCount = 0;
                //LoginPwdErrorDateTime = DateTime.Now.AddMinutes(-1);
            }
            SaveAccountInfo();
            stopWatch.Stop();
            LogHelper.WriteDebug($"[LoadAction_Login({stopWatch.Elapsed.TotalMilliseconds}毫秒)]");
            return(true);
        }