Example #1
0
        /// <summary>
        /// 窗体加载执行方法
        /// </summary>
        private void MainFormLoad()
        {
            string LoginName = ServerConfig.TraderID;
            string passWord  = ServerConfig.PassWord;
            string message;
            //将TraderId和passWord通过管理中心服务进行验证
            bool result = wcfLogic.AdminConfirmation(LoginName, passWord, out message);

            //如果验证通过则说明登陆的是管理员,下单界面禁用
            if (result)
            {
                menuOrder.Visible    = false;
                menuQuery.Visible    = false;
                menuSettings.Visible = false;
                toolOrder.Visible    = false;
            }
            //验证不通过则是交易员,试玩界面禁用
            else
            {
                menuReInitData.Visible = false;
                ToolStripMenuItemAddCaption.Visible = false;
            }

            wcfLogic.LoadTraderInfo();
        }
        /// <summary>
        /// 登录按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                #region 根据用户输入的服务其地址进行连接相对应的服务
                string      errMsg    = "";
                mdiMainForm mainForm  = new mdiMainForm();
                bool        isSuccess = mainForm.Initialize(txtTradeID.Text.Trim(), ref errMsg);
                if (!isSuccess)
                {
                    //errMsg = ResourceOperate.Instanse.GetResourceByKey("WCF");
                    error.SetError(txtPassword, errMsg);
                    return;
                }
                #endregion 根据用户输入的服务其地址进行连接相对应的服务
                #region 对用户输入的信息进行判断,并在判断通过时保存到配置文件中

                if (!string.IsNullOrEmpty(this.txtTradeID.Text))
                {
                    #region 对资金帐户的长度和输入格式进行判断

                    #region 判断文本框中数据是否与APP中数据是否相等,如果相等则不修改APP中数据,否则修改APP中数据

                    string Password = this.txtPassword.Text;
                    int    userId;
                    if (!string.IsNullOrEmpty(Password))
                    {
                        #region 对TraderID进行判断

                        string message;
                        //将用户输入的密码进行加密,否则与数据库中加密过的密码进行比较会出现密码验证错误
                        string password = Encrypt.DesEncrypt(Password, string.Empty);

                        //对用户输入的TradeId进行判断,如果查询出柜台说明该用户是交易员,否则进行管理员判断
                        int.TryParse(this.txtTradeID.Text.Trim(), out userId);
                        GTA.VTS.CustomersOrders.TransactionManageService.CT_Counter counter =
                            wcfLogic.TransactionConfirm(userId, password, out message);
                        if (counter == null)
                        {
                            string LoginName  = this.txtTradeID.Text.Trim();
                            string Loginerror = ResourceOperate.Instanse.GetResourceByKey("Loginerror");

                            #region 管理员验证

                            string messages;
                            bool   result = wcfLogic.AdminConfirmation(LoginName,
                                                                       password,
                                                                       out messages);
                            if (!result)
                            {
                                error.Clear();
                                error.SetError(txtPassword, Loginerror);
                                return;
                            }
                            ServerConfig.TraderID = LoginName;
                            ServerConfig.PassWord = password;
                            ServerConfig.Refresh();
                            this.DialogResult = DialogResult.OK;
                            this.Close();

                            #endregion 管理员验证
                        }
                        else
                        {
                            int counterID = counter.CouterID;
                            int trade;
                            if (int.TryParse(txtTradeID.Text, out trade))
                            {
                                Capitalaccount(counterID, trade);
                                ServerConfig.PassWord = password;
                                ServerConfig.TraderID = txtTradeID.Text.Trim();
                                ServerConfig.Refresh();
                                this.DialogResult = DialogResult.OK;
                                this.Close();
                            }
                            else
                            {
                                error.Clear();
                                string errors = ResourceOperate.Instanse.GetResourceByKey("TradeError");
                                error.SetError(txtPassword, errors);
                                return;
                            }
                        }

                        #endregion 对TraderID进行判断
                    }
                    else
                    {
                        error.Clear();
                        string errors = ResourceOperate.Instanse.GetResourceByKey("errors");
                        error.SetError(txtPassword, errors);
                        return;
                    }

                    #endregion 判断文本框中数据是否与APP中数据是否相等,如果相等则不修改APP中数据,否则修改APP中数据

                    #endregion 对资金帐户的长度和输入格式进行判断
                }
                else
                {
                    error.Clear();
                    string TradeIDerror = ResourceOperate.Instanse.GetResourceByKey("TradeIDerror");
                    error.SetError(txtTradeID, TradeIDerror);
                    return;
                }

                #endregion
            }
            catch (Exception ex)
            {
                LogHelper.WriteError(ex.Message, ex);
            }
        }