Example #1
0
        private void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            if (GlobalInfo.DeviceType == DeviceType.JSP.GetHashCode())
            {
                if (string.IsNullOrEmpty(tbloginNsrsbh.Text))
                {
                    MessageBoxEx.Show(this, PRO_ReceiptsInvMgr.Resources.Message.PromptInputNsrsbh, PRO_ReceiptsInvMgr.Resources.Message.Tips, MessageBoxExButtons.OK, MessageBoxExIcon.Error);
                    return;
                }
            }
            else
            {
                if (string.IsNullOrEmpty(cbxSkpLoginNsrsbh.Text))
                {
                    MessageBoxEx.Show(this, PRO_ReceiptsInvMgr.Resources.Message.PromptInputNsrsbh, PRO_ReceiptsInvMgr.Resources.Message.Tips, MessageBoxExButtons.OK, MessageBoxExIcon.Error);
                    return;
                }
            }


            if (string.IsNullOrEmpty(loginPwd.Password))
            {
                MessageBoxEx.Show(this, PRO_ReceiptsInvMgr.Resources.Message.PromptInputPwd, PRO_ReceiptsInvMgr.Resources.Message.Tips, MessageBoxExButtons.OK, MessageBoxExIcon.Error);
                return;
            }
            if (string.IsNullOrEmpty(taxKey.Password))
            {
                MessageBoxEx.Show(this, PRO_ReceiptsInvMgr.Resources.Message.PromptInputKey, PRO_ReceiptsInvMgr.Resources.Message.Tips, MessageBoxExButtons.OK, MessageBoxExIcon.Error);
                return;
            }

            CryptTool.UserPin = taxKey.Password;
            var ret = CryptTool.openThisDevice();

            if (ret != 0)
            {
                string msg = CryptTool.ErrorMsg;
                if (msg.Contains("0xA7"))
                {
                    msg = PRO_ReceiptsInvMgr.Resources.Message.NotFindTax;
                }
                MessageBoxEx.Show(this, msg, PRO_ReceiptsInvMgr.Resources.Message.Tips, MessageBoxExButtons.OK, MessageBoxExIcon.Error);
                return;
            }

            string errorMsg = string.Empty;
            string nsrsbh   = GlobalInfo.DeviceType == DeviceType.JSP.GetHashCode() ? tbloginNsrsbh.Text : cbxSkpLoginNsrsbh.Text.ToString();

            //登陆时取token   20190324
//             int retryCount = 3;
//             do
//             {
//                 --retryCount;
//                 GlobalInfo.token = GetTokenHelper.GetToken_dll(nsrsbh, CryptTool.UserPin, GlobalInfo.Dqdm);
//             } while (GlobalInfo.token.Length == 0 && retryCount > 0);

            var retObj = loginService.Login(nsrsbh, loginPwd.Password, GlobalInfo.token, out errorMsg);

            if (retObj == null)
            {
                MessageBoxEx.Show(this, errorMsg, PRO_ReceiptsInvMgr.Resources.Message.Tips, MessageBoxExButtons.OK, MessageBoxExIcon.Error);
                return;
            }
            else
            {
                GlobalInfo.NSRSBH      = nsrsbh;
                GlobalInfo.Dqdm        = retObj.areaId;
                GlobalInfo.AppId       = retObj.appKey;
                GlobalInfo.ExpiredTime = retObj.expiredTime;
                GlobalInfo.JxPwd       = taxKey.Password;

                ConfigObject configObject = new ConfigObject();
                configObject.NSRSBH   = nsrsbh;
                configObject.LoginPwd = loginPwd.Password;
                configObject.CertPwd  = taxKey.Password;
                configObject.TaxType  = GlobalInfo.DeviceType;

                if (chbRemember.IsChecked.HasValue)
                {
                    configObject.IsRemember = chbRemember.IsChecked.Value;
                    loginService.UpdateOrSaveUserInfo(configObject);
                }


                MainWindow win = new MainWindow();
                this.Close();
                win.Show();
                LoginWinInstance = null;
            }
        }