/// <summary>
        /// GET INVESTOR ACCOUNT BY INVESTOR ID IN MARKET
        /// </summary>
        /// <param name="InvestorID"></param>
        /// <returns></returns>
        internal string GetInvestorByInvestorID(int InvestorID)
        {
            string Result = string.Empty;
            Business.Investor Investor = new Business.Investor();
            Investor = TradingServer.Facade.FacadeGetInvestorAccountByInvestorID(InvestorID);
            Result = Model.CommandFramework.CommandFrameworkInstance.ExtractInvestorToString(Investor);

            return Result;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="RowNumber"></param>
        /// <returns></returns>
        internal List<Business.Investor> GetInvestorByStartEnd(int RowNumber,int Limit)
        {
            List<Business.Investor> Result = new List<Business.Investor>();
            System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(DBConnection.DBConnection.Connection);
            DSTableAdapters.InvestorTableAdapter adap = new DSTableAdapters.InvestorTableAdapter();
            DSTableAdapters.InvestorProfileTableAdapter adapInvestorProfile = new DSTableAdapters.InvestorProfileTableAdapter();
            DS.InvestorDataTable tbInvestor = new DS.InvestorDataTable();
            DS.InvestorProfileDataTable tbInvestorProfile = new DS.InvestorProfileDataTable();

            try
            {
                conn.Open();
                adap.Connection = conn;
                adapInvestorProfile.Connection = conn;
                tbInvestor = adap.GetInvestorByStartEnd(RowNumber, Limit);
                if (tbInvestor != null)
                {
                    int count = tbInvestor.Count;
                    for (int i = 0; i < count; i++)
                    {
                        tbInvestorProfile = adapInvestorProfile.GetInvestorProfileByInvestorID(tbInvestor[i].InvestorID);

                        Business.Investor newInvestor = new Business.Investor();
                        newInvestor.InvestorID = tbInvestor[i].InvestorID;
                        newInvestor.AgentID = tbInvestor[i].AgentID;
                        //Fill Investor Group Instance
                        if (Business.Market.InvestorGroupList != null)
                        {
                            int countInvestorGroup = Business.Market.InvestorGroupList.Count;
                            for (int j = 0; j < countInvestorGroup; j++)
                            {
                                if (Business.Market.InvestorGroupList[j].InvestorGroupID == tbInvestor[i].InvestorGroupID)
                                {
                                    newInvestor.InvestorGroupInstance = Business.Market.InvestorGroupList[j];
                                    break;
                                }
                            }
                        }

                        //newInvestor.InvestorGroupInstance = TradingServer.Facade.FacadeGetInvestorGroupByInvestorGroupID(tbInvestor[i].InvestorGroupID);
                        newInvestor.InvestorStatusID = tbInvestor[i].InvestorStatusID;
                        newInvestor.Balance = tbInvestor[i].Balance;
                        newInvestor.Code = tbInvestor[i].Code;
                        newInvestor.Credit = tbInvestor[i].Credit;
                        newInvestor.IsDisable = tbInvestor[i].IsDisible;
                        newInvestor.TaxRate = tbInvestor[i].TaxRate;
                        newInvestor.Leverage = tbInvestor[i].Leverage;
                        newInvestor.PreviousLedgerBalance = tbInvestor[i].PreviousLedgerBalance;
                        newInvestor.UserConfig = tbInvestor[i].UserConfig;
                        newInvestor.RefInvestorID = tbInvestor[i].RefInvestorID;

                        //Add Data InvestorProfile To Result
                        if (tbInvestorProfile != null && tbInvestorProfile.Count > 0)
                        {
                            newInvestor.InvestorProfileID = tbInvestorProfile[0].InvestorProfileID;
                            newInvestor.Address = tbInvestorProfile[0].Address;
                            newInvestor.City = tbInvestorProfile[0].City;
                            newInvestor.InvestorComment = tbInvestorProfile[0].Comment;
                            newInvestor.Country = tbInvestorProfile[0].Country;
                            newInvestor.Email = tbInvestorProfile[0].Email;
                            newInvestor.NickName = tbInvestorProfile[0].NickName;
                            newInvestor.Phone = tbInvestorProfile[0].Phone;
                            newInvestor.RegisterDay = tbInvestorProfile[0].RegisterDay;
                            newInvestor.State = tbInvestorProfile[0].State;
                            newInvestor.ZipCode = tbInvestorProfile[0].ZipCode;
                            newInvestor.IDPassport = tbInvestorProfile[0].IDPassport;
                        }

                        Result.Add(newInvestor);
                    }
                }
            }
            catch (Exception ex)
            {
                return null;
            }
            finally
            {
                adap.Connection.Close();
                adapInvestorProfile.Connection.Close();
                conn.Close();
            }

            return Result;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="investorID"></param>
        /// <param name="loginKey"></param>
        /// <returns></returns>
        internal bool CheckOnlineInvestor(int investorID, string loginKey)
        {
            bool result = false;
            bool isExits = false;
            Business.Investor InstanceInvestor = null;

            if (Business.Market.InvestorList != null)
            {
                int count = Business.Market.InvestorList.Count;
                for (int i = 0; i < count; i++)
                {
                    if (Business.Market.InvestorList[i].InvestorID == investorID)
                    {
                        //save instance investor
                        InstanceInvestor = Business.Market.InvestorList[i];

                        if (Business.Market.InvestorList[i].LoginKey == loginKey)
                        {
                            Business.Investor newInvestor = new Business.Investor();
                            newInvestor.InvestorID = investorID;
                            newInvestor.LastConnectTime = DateTime.Now;
                            newInvestor.numTimeOut = 30;
                            newInvestor.TickInvestor = new List<Business.Tick>();
                            newInvestor.Code = Business.Market.InvestorList[i].Code;
                            newInvestor.IsLogout = false;
                            newInvestor.LoginKey = loginKey;
                            newInvestor.LoginType = TypeLogin.Primary;
                            newInvestor.InvestorGroupInstance = Business.Market.InvestorList[i].InvestorGroupInstance;

                            //set islogout for investor list
                            Business.Market.InvestorList[i].IsLogout = false;

                            if (Business.Market.InvestorList[i].InvestorGroupInstance.IsEnable && !Business.Market.InvestorList[i].IsDisable)
                            {
                                Business.Market.InvestorOnline.Add(newInvestor);
                                TradingServer.Facade.FacadeSendNotifyManagerRequest(1, newInvestor);
                            }

                            isExits = true;
                            result = true;

                            break;
                        }
                    }
                }
            }

            if (!isExits)
            {
                if (InstanceInvestor != null && InstanceInvestor.InvestorID > 0)
                {
                    bool flag = false;
                    if (Business.Market.InvestorOnline != null)
                    {
                        int count = Business.Market.InvestorOnline.Count;
                        for (int i = 0; i < count; i++)
                        {
                            if (Business.Market.InvestorOnline[i].InvestorID == investorID && Business.Market.InvestorOnline[i].LoginKey == loginKey)
                            {
                                flag = true;
                                break;
                            }
                        }
                    }

                    if (!flag)
                    {
                        Business.Investor newInvestor = new Business.Investor();
                        newInvestor.InvestorID = investorID;
                        newInvestor.LastConnectTime = DateTime.Now;
                        newInvestor.numTimeOut = 30;
                        newInvestor.TickInvestor = new List<Business.Tick>();
                        newInvestor.Code = InstanceInvestor.Code;
                        newInvestor.IsLogout = false;
                        newInvestor.LoginKey = loginKey;
                        newInvestor.LoginType = TypeLogin.ReadOnly;
                        newInvestor.InvestorGroupInstance = InstanceInvestor.InvestorGroupInstance;

                        ////set islogout for investor list
                        //Business.Market.InvestorList[i].IsLogout = false;

                        Business.Market.InvestorOnline.Add(newInvestor);
                        TradingServer.Facade.FacadeSendNotifyManagerRequest(1, newInvestor);

                        result = true;
                    }
                }
            }

            return result;
        }
        /// <summary>
        /// Get All Investor Profile
        /// </summary>
        /// <returns>List<Business.InvestorProfile</returns>
        internal List<Business.Investor> GetAllInvestorProfile()
        {
            List<Business.Investor> Result = new List<Business.Investor>();
            System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(DBConnection.DBConnection.Connection);
            DSTableAdapters.InvestorProfileTableAdapter adap = new DSTableAdapters.InvestorProfileTableAdapter();
            DS.InvestorProfileDataTable tbInvestorProfile = new DS.InvestorProfileDataTable();

            try
            {
                conn.Open();
                adap.Connection = conn;

                tbInvestorProfile = adap.GetData();
                if (tbInvestorProfile != null)
                {
                    int count = tbInvestorProfile.Count;
                    for (int i = 0; i < count; i++)
                    {
                        Business.Investor newInvestorProfile = new Business.Investor();
                        newInvestorProfile.InvestorID = tbInvestorProfile[i].InvestorID;
                        newInvestorProfile.Address = tbInvestorProfile[i].Address;
                        newInvestorProfile.Phone = tbInvestorProfile[i].Phone;
                        newInvestorProfile.City = tbInvestorProfile[i].City;
                        newInvestorProfile.Country = tbInvestorProfile[i].Country;
                        newInvestorProfile.Email = tbInvestorProfile[i].Email;
                        newInvestorProfile.ZipCode = tbInvestorProfile[i].ZipCode;
                        newInvestorProfile.RegisterDay = tbInvestorProfile[i].RegisterDay;
                        newInvestorProfile.InvestorComment = tbInvestorProfile[i].Comment;
                        newInvestorProfile.State = tbInvestorProfile[i].State;
                        newInvestorProfile.NickName = tbInvestorProfile[i].NickName;
                        newInvestorProfile.IDPassport = tbInvestorProfile[i].IDPassport;

                        Result.Add(newInvestorProfile);
                    }
                }
            }
            catch (Exception ex)
            {
                return null;
            }
            finally
            {
                adap.Connection.Close();
                conn.Close();
            }

            return Result;
        }
        /// <summary>
        /// Get Investor By Investor ID
        /// </summary>
        /// <param name="InvestorID">int InvestorID</param>
        /// <returns>Business.Investor</returns>
        internal Business.Investor GetInvestorByInvestorID(int InvestorID)
        {
            Business.Investor Result = new Business.Investor();
            System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(DBConnection.DBConnection.Connection);
            DSTableAdapters.InvestorTableAdapter adap = new DSTableAdapters.InvestorTableAdapter();
            DS.InvestorDataTable tbInvestor = new DS.InvestorDataTable();
            DSTableAdapters.InvestorProfileTableAdapter adapInvestorProfile = new DSTableAdapters.InvestorProfileTableAdapter();
            DS.InvestorProfileDataTable tbInvestorProfile = new DS.InvestorProfileDataTable();

            try
            {
                conn.Open();
                adap.Connection = conn;
                adapInvestorProfile.Connection = conn;
                tbInvestor = adap.GetInvestorByInvestorID(InvestorID);

                if (tbInvestor != null)
                {
                    tbInvestorProfile = adapInvestorProfile.GetInvestorProfileByInvestorID(tbInvestor[0].InvestorID);

                    if (tbInvestorProfile != null)
                    {
                        //Add Data Investor To Result
                        Result.InvestorID = tbInvestor[0].InvestorID;
                        Result.AgentID = tbInvestor[0].AgentID;
                        //Result.InvestorGroupInstance = TradingServer.Facade.FacadeGetInvestorGroupByInvestorGroupID(tbInvestor[0].InvestorGroupID);

                        if (Business.Market.InvestorGroupList != null)
                        {
                            int countInvestorGroup = Business.Market.InvestorGroupList.Count;
                            for (int j = 0; j < countInvestorGroup; j++)
                            {
                                if (Business.Market.InvestorGroupList[j].InvestorGroupID == tbInvestor[0].InvestorGroupID)
                                {
                                    Result.InvestorGroupInstance = Business.Market.InvestorGroupList[j];

                                    break;
                                }
                            }
                        }
                        Result.InvestorStatusID = tbInvestor[0].InvestorStatusID;
                        Result.Balance = tbInvestor[0].Balance;
                        Result.Code = tbInvestor[0].Code;
                        Result.Credit = tbInvestor[0].Credit;
                        Result.IsDisable = tbInvestor[0].IsDisible;
                        Result.TaxRate = tbInvestor[0].TaxRate;
                        Result.Leverage = tbInvestor[0].Leverage;
                        Result.PreviousLedgerBalance = tbInvestor[0].PreviousLedgerBalance;
                        Result.UserConfig = tbInvestor[0].UserConfig;
                        Result.RefInvestorID = tbInvestor[0].RefInvestorID;

                        //Add Data InvestorProfile To Result
                        Result.Address = tbInvestorProfile[0].Address;
                        Result.City = tbInvestorProfile[0].City;
                        Result.InvestorComment = tbInvestorProfile[0].Comment;
                        Result.Country = tbInvestorProfile[0].Country;
                        Result.Email = tbInvestorProfile[0].Email;
                        Result.NickName = tbInvestorProfile[0].NickName;
                        Result.Phone = tbInvestorProfile[0].Phone;
                        Result.RegisterDay = tbInvestorProfile[0].RegisterDay;
                        Result.State = tbInvestorProfile[0].State;
                        Result.ZipCode = tbInvestorProfile[0].ZipCode;
                        Result.IDPassport = tbInvestorProfile[0].IDPassport;
                    }
                }
            }
            catch (Exception ex)
            {
                return null;
            }
            finally
            {
                adap.Connection.Close();
                conn.Close();
            }

            return Result;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="code"></param>
        /// <param name="readPwd"></param>
        /// <returns></returns>
        internal Business.Investor LoginWithReadPwd(string code, string readPwd)
        {
            Business.Investor result = new Business.Investor();
            System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(DBConnection.DBConnection.Connection);
            DSTableAdapters.InvestorTableAdapter adap = new DSTableAdapters.InvestorTableAdapter();
            DSTableAdapters.InvestorProfileTableAdapter adapInvestorProfile = new DSTableAdapters.InvestorProfileTableAdapter();
            DS.InvestorDataTable tbInvestor = new DS.InvestorDataTable();
            DS.InvestorProfileDataTable tbInvestorProfile = new DS.InvestorProfileDataTable();

            try
            {
                conn.Open();
                adap.Connection = conn;
                adapInvestorProfile.Connection = conn;
                tbInvestor = adap.LoginWithReadPwd(code, readPwd);

                //string hash = Model.ValidateCheck.GetEncodedString(Password);
                if (tbInvestor != null && tbInvestor.Count > 0)
                {
                    //Add Data From Table Investor To Result
                    result.InvestorID = tbInvestor[0].InvestorID;
                    result.AgentID = tbInvestor[0].AgentID;
                    result.Balance = tbInvestor[0].Balance;
                    result.Code = tbInvestor[0].Code;
                    result.Credit = tbInvestor[0].Credit;
                    //Result.IsOnline = true;
                    result.IsDisable = tbInvestor[0].IsDisible;
                    result.ReadOnly = tbInvestor[0].ReadOnly;
                    result.IsReadOnly = true;

                    if (Business.Market.InvestorGroupList != null)
                    {
                        int count = Business.Market.InvestorGroupList.Count;
                        for (int i = 0; i < count; i++)
                        {
                            if (Business.Market.InvestorGroupList[i].InvestorGroupID == tbInvestor[0].InvestorGroupID)
                            {
                                result.InvestorGroupInstance = Business.Market.InvestorGroupList[i];
                                break;
                            }
                        }
                    }

                    result.InvestorStatusID = tbInvestor[0].InvestorStatusID;
                    result.IsDisable = tbInvestor[0].IsDisible;
                    result.Leverage = tbInvestor[0].Leverage;
                    result.PreviousLedgerBalance = tbInvestor[0].PreviousLedgerBalance;

                    tbInvestorProfile = adapInvestorProfile.GetInvestorProfileByInvestorID(tbInvestor[0].InvestorID);
                    if (tbInvestorProfile != null && tbInvestorProfile.Count > 0)
                    {
                        //Add Data From Table InvestorProfile To Result
                        result.Address = tbInvestorProfile[0].Address;
                        result.City = tbInvestorProfile[0].City;
                        result.InvestorComment = tbInvestorProfile[0].Comment;
                        result.Country = tbInvestorProfile[0].Country;
                        result.Email = tbInvestorProfile[0].Email;
                        result.NickName = tbInvestorProfile[0].NickName;
                        result.Phone = tbInvestorProfile[0].Phone;
                        result.RegisterDay = tbInvestorProfile[0].RegisterDay;
                        result.State = tbInvestorProfile[0].State;
                        result.ZipCode = tbInvestorProfile[0].ZipCode;
                        result.InvestorProfileID = tbInvestorProfile[0].InvestorProfileID;
                        result.IDPassport = tbInvestorProfile[0].IDPassport;
                    }
                }
            }
            catch (Exception ex)
            {
                return null;
            }
            finally
            {
                adap.Connection.Close();
                conn.Close();
            }

            return result;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="Code"></param>
        /// <returns></returns>
        internal Business.Investor SelectInvestorByCode(string Code)
        {
            Business.Investor newInvestor = new Business.Investor();
            System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(DBConnection.DBConnection.Connection);
            DSTableAdapters.InvestorTableAdapter adap = new DSTableAdapters.InvestorTableAdapter();
            DS.InvestorDataTable tbInvestor = new DS.InvestorDataTable();
            DSTableAdapters.InvestorProfileTableAdapter adapProfile = new DSTableAdapters.InvestorProfileTableAdapter();
            DS.InvestorProfileDataTable tbInvestorProfile = new DS.InvestorProfileDataTable();

            try
            {
                conn.Open();
                adap.Connection = conn;
                adapProfile.Connection = conn;
                tbInvestor = adap.SelectInvestorByCode(Code);

                if (tbInvestor != null)
                {
                    tbInvestorProfile = adapProfile.GetInvestorProfileByInvestorID(tbInvestor[0].InvestorID);

                    if (tbInvestorProfile != null && tbInvestorProfile.Count > 0)
                    {
                        newInvestor.InvestorProfileID = tbInvestorProfile[0].InvestorProfileID;
                        newInvestor.Address = tbInvestorProfile[0].Address;
                        newInvestor.Phone = tbInvestorProfile[0].Phone;
                        newInvestor.City = tbInvestorProfile[0].City;
                        newInvestor.Country = tbInvestorProfile[0].Country;
                        newInvestor.Email = tbInvestorProfile[0].Email;
                        newInvestor.ZipCode = tbInvestorProfile[0].ZipCode;
                        newInvestor.RegisterDay = tbInvestorProfile[0].RegisterDay;
                        newInvestor.InvestorComment = tbInvestorProfile[0].Comment;
                        newInvestor.State = tbInvestorProfile[0].State;
                        newInvestor.NickName = tbInvestorProfile[0].NickName;
                        newInvestor.IDPassport = tbInvestorProfile[0].IDPassport;
                    }
                    else
                    {
                        newInvestor.InvestorProfileID = -1;
                        newInvestor.Address = "NaN";
                        newInvestor.Phone = "NaN";
                        newInvestor.City = "NaN";
                        newInvestor.Country = "NaN";
                        newInvestor.Email = "NaN";
                        newInvestor.ZipCode = "NaN";
                        newInvestor.RegisterDay = DateTime.Now;
                        newInvestor.InvestorComment = "NaN";
                        newInvestor.State = "NaN";
                        newInvestor.NickName = "NaN";
                        newInvestor.IDPassport = "";
                    }
                    newInvestor.InvestorID = tbInvestor[0].InvestorID;
                    newInvestor.InvestorStatusID = tbInvestor[0].InvestorStatusID;
                    //newInvestor.InvestorGroupInstance = TradingServer.Facade.FacadeGetInvestorGroupByInvestorGroupID(tbInvestor[0].InvestorGroupID);

                    if (Business.Market.InvestorGroupList != null)
                    {
                        int countInvestorGroup = Business.Market.InvestorGroupList.Count;
                        for (int j = 0; j < countInvestorGroup; j++)
                        {
                            if (Business.Market.InvestorGroupList[j].InvestorGroupID == tbInvestor[0].InvestorGroupID)
                            {
                                newInvestor.InvestorGroupInstance = Business.Market.InvestorGroupList[j];
                                break;
                            }
                        }
                    }

                    newInvestor.AgentID = tbInvestor[0].AgentID;
                    newInvestor.Balance = tbInvestor[0].Balance;
                    newInvestor.Credit = tbInvestor[0].Credit;
                    newInvestor.Code = tbInvestor[0].Code;
                    newInvestor.IsDisable = tbInvestor[0].IsDisible;
                    newInvestor.TaxRate = tbInvestor[0].TaxRate;
                    newInvestor.Leverage = tbInvestor[0].Leverage;
                    newInvestor.AllowChangePwd = tbInvestor[0].AllowChangePwd;
                    newInvestor.ReadOnly = tbInvestor[0].ReadOnly;
                    newInvestor.SendReport = tbInvestor[0].SendReport;
                    newInvestor.PreviousLedgerBalance = tbInvestor[0].PreviousLedgerBalance;
                    newInvestor.PhonePwd = tbInvestor[0].PhonePwd;
                }
            }
            catch (Exception ex)
            {
                return null;
            }
            finally
            {
                adap.Connection.Close();
                adapProfile.Connection.Close();
                conn.Close();
            }

            return newInvestor;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="Code"></param>
        /// <param name="Password"></param>
        /// <returns></returns>
        internal Business.Investor LoginAgent(string Code, string Password)
        {
            Business.Investor Result = new Business.Investor();
            System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(DBConnection.DBConnection.Connection);
            DSTableAdapters.InvestorTableAdapter adapInvestor = new DSTableAdapters.InvestorTableAdapter();
            DS.InvestorDataTable tbInvestor = new DS.InvestorDataTable();

            try
            {
                conn.Open();
                adapInvestor.Connection = conn;

                //string hash = Model.ValidateCheck.GetEncodedString(Password);
                //string hash = Model.ValidateCheck.Encrypt(Password);

                tbInvestor = adapInvestor.LoginSystem(Code, Password);
                if (tbInvestor != null)
                {
                    //Add Data From Table Investor To Result
                    Result.InvestorID = tbInvestor[0].InvestorID;
                    //Result.AgentID = tbInvestor[0].AgentID;
                    //Result.Balance = tbInvestor[0].Balance;
                    //Result.Code = tbInvestor[0].Code;
                    //Result.Credit = tbInvestor[0].Credit;

                    //if (Business.Market.InvestorGroupList != null)
                    //{
                    //    int count = Business.Market.InvestorGroupList.Count;
                    //    for (int i = 0; i < count; i++)
                    //    {
                    //        if (Business.Market.InvestorGroupList[i].InvestorGroupID == tbInvestor[0].InvestorGroupID)
                    //        {
                    //            Result.InvestorGroupInstance = Business.Market.InvestorGroupList[i];
                    //            break;
                    //        }
                    //    }
                    //}

                    //Result.InvestorStatusID = tbInvestor[0].InvestorStatusID;
                    //Result.IsDisable = tbInvestor[0].IsDisible;
                    //Result.Leverage = tbInvestor[0].Leverage;
                }
            }
            catch (Exception ex)
            {
                return null;
            }
            finally
            {
                adapInvestor.Connection.Close();
                conn.Close();
            }

            return Result;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="investorID"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        internal Business.Investor CheckMasterPassword(int investorID, string password)
        {
            Business.Investor result = new Business.Investor();
            System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(DBConnection.DBConnection.Connection);
            DSTableAdapters.InvestorTableAdapter adap = new DSTableAdapters.InvestorTableAdapter();
            DS.InvestorDataTable tbInvestor = new DS.InvestorDataTable();

            try
            {
                conn.Open();
                adap.Connection = conn;
                tbInvestor = adap.VerifyMasterPassword(investorID, password);

                //string hash = Model.ValidateCheck.GetEncodedString(Password);
                if (tbInvestor != null && tbInvestor.Count > 0)
                {
                    //Add Data From Table Investor To Result
                    result.InvestorID = tbInvestor[0].InvestorID;
                    result.AgentID = tbInvestor[0].AgentID;
                    result.Balance = tbInvestor[0].Balance;
                    result.Code = tbInvestor[0].Code;
                    result.Credit = tbInvestor[0].Credit;
                    //Result.IsOnline = true;
                    result.IsDisable = tbInvestor[0].IsDisible;
                    result.ReadOnly = true;

                    if (Business.Market.InvestorGroupList != null)
                    {
                        int count = Business.Market.InvestorGroupList.Count;
                        for (int i = 0; i < count; i++)
                        {
                            if (Business.Market.InvestorGroupList[i].InvestorGroupID == tbInvestor[0].InvestorGroupID)
                            {
                                result.InvestorGroupInstance = Business.Market.InvestorGroupList[i];
                                break;
                            }
                        }
                    }

                    result.InvestorStatusID = tbInvestor[0].InvestorStatusID;
                    result.IsDisable = tbInvestor[0].IsDisible;
                    result.Leverage = tbInvestor[0].Leverage;
                    result.PreviousLedgerBalance = tbInvestor[0].PreviousLedgerBalance;
                }
            }
            catch (Exception ex)
            {
                return null;
            }
            finally
            {
                adap.Connection.Close();
                conn.Close();
            }

            return result;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="InvestorProfileID"></param>
        /// <returns></returns>
        internal Business.Investor GetInvestorProfileByInvestorProfileID(int InvestorProfileID)
        {
            Business.Investor Result = new Business.Investor();
            System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(DBConnection.DBConnection.Connection);
            DSTableAdapters.InvestorProfileTableAdapter adap = new DSTableAdapters.InvestorProfileTableAdapter();
            DS.InvestorProfileDataTable tbInvestorProfile = new DS.InvestorProfileDataTable();

            try
            {
                conn.Open();
                adap.Connection = conn;

                tbInvestorProfile = adap.GetInvestorProfileByInvestorProfileID(InvestorProfileID);

                if (tbInvestorProfile != null)
                {
                    int count = tbInvestorProfile.Count;
                    Result.Address = tbInvestorProfile[0].Address;
                    Result.City = tbInvestorProfile[0].City;
                    Result.InvestorComment = tbInvestorProfile[0].Comment;
                    Result.Country = tbInvestorProfile[0].Country;
                    Result.Email = tbInvestorProfile[0].Email;
                    Result.InvestorID = tbInvestorProfile[0].InvestorID;
                    Result.NickName = tbInvestorProfile[0].NickName;
                    Result.Phone = tbInvestorProfile[0].Phone;
                    Result.RegisterDay = tbInvestorProfile[0].RegisterDay;
                    Result.State = tbInvestorProfile[0].State;
                    Result.ZipCode = tbInvestorProfile[0].ZipCode;
                    Result.IDPassport = tbInvestorProfile[0].IDPassport;
                }
            }
            catch (Exception ex)
            {
                return null;
            }
            finally
            {
                adap.Connection.Close();
                conn.Close();
            }

            return Result;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public string GetNextRandomCode()
        {
            while (TradingCalculate.flagRendCode)
            {
                System.Threading.Thread.Sleep(100);
            }

            TradingCalculate.flagRendCode = true;

            lock (Business.Market.syncObject)
            {
                string result = string.Empty;
                if (Business.Market.InvestorList != null)
                {
                    int index = 0;
                    int count = Business.Market.InvestorList.Count;

                    #region SORT INVESTOR
                    for (int i = 0; i < count; i++)
                    {
                        for (int j = i + 1; j < count; j++)
                        {
                            int codeI = 0;
                            int codeJ = 0;
                            bool parseI = int.TryParse(Business.Market.InvestorList[i].Code, out codeI);
                            bool parseJ = int.TryParse(Business.Market.InvestorList[j].Code, out codeJ);

                            if (parseI && parseJ)
                            {
                                if (codeJ < codeI)
                                {
                                    Business.Investor temp = new Business.Investor();
                                    temp = Business.Market.InvestorList[i];
                                    Business.Market.InvestorList[i] = Business.Market.InvestorList[j];
                                    Business.Market.InvestorList[j] = temp;
                                }
                            }
                            else
                            {
                                if (parseJ)
                                {
                                    Business.Investor temp = new Business.Investor();
                                    temp = Business.Market.InvestorList[i];
                                    Business.Market.InvestorList[i] = Business.Market.InvestorList[j];
                                    Business.Market.InvestorList[j] = Business.Market.InvestorList[i];
                                }
                            }
                        }
                    }
                    #endregion

                    #region REND NEXT CODE
                    int countInvestor = Business.Market.InvestorList.Count;
                    if (countInvestor > 1)
                    {
                        #region COUNT INVESTOR LIST > 1
                        for (int j = 0; j < countInvestor; j++)
                        {
                            int codeIndexI = 0;
                            int codeIndexJ = 0;
                            bool parseIndexI = int.TryParse(Business.Market.InvestorList[j].Code, out codeIndexI);
                            int n = j + 1;
                            bool parseIndexJ = false;
                            if (n < countInvestor)
                            {
                                parseIndexJ = int.TryParse(Business.Market.InvestorList[j + 1].Code, out codeIndexJ);
                            }

                            if (parseIndexI && parseIndexJ)
                            {
                                int temp = codeIndexJ - codeIndexI;
                                if (temp > 1)
                                {
                                    int tempResult = codeIndexI + 1;
                                    result = tempResult.ToString();
                                    while (result.Length < 8)
                                    {
                                        result = "0" + result;
                                    }

                                    TradingCalculate.flagRendCode = false;

                                    return result;
                                }
                            }
                            else
                            {
                                if (parseIndexI)
                                {
                                    int tempResult = codeIndexI + 1;
                                    result = tempResult.ToString();
                                    while (result.Length < 8)
                                    {
                                        result = "0" + result;
                                    }

                                    TradingCalculate.flagRendCode = false;

                                    return result;
                                }
                            }

                            index++;
                        }
                        #endregion
                    }
                    else
                    {
                        if (countInvestor == 0) //count investor list == 0
                        {
                            int tempResult = 1;
                            result = tempResult.ToString();

                            while (result.Length < 8)
                            {
                                result = "0" + result;
                            }

                            TradingCalculate.flagRendCode = false;

                            return result;
                        }
                        else//count investor list == 1
                        {
                            #region COUNT INVESTOR LIST = 1
                            int codeI = 0;
                            int codeJ = 0;
                            bool parseJ = false;
                            parseJ = int.TryParse(Business.Market.InvestorList[0].Code, out codeJ);

                            if (parseJ)
                            {
                                int temp = codeJ - codeI;
                                if (temp > 1)
                                {
                                    int tempResult = codeI + 1;
                                    result = tempResult.ToString();
                                    while (result.Length < 8)
                                    {
                                        result = "0" + result;
                                    }

                                    TradingCalculate.flagRendCode = false;

                                    return result;
                                }
                                else
                                {
                                    int tempResult = codeJ + 1;
                                    result = tempResult.ToString();
                                    while (result.Length < 8)
                                    {
                                        result = "0" + result;
                                    }

                                    TradingCalculate.flagRendCode = false;

                                    return result;
                                }
                            }
                            else
                            {
                                int tempResult = codeI + 1;
                                result = tempResult.ToString();
                                while (result.Length < 8)
                                {
                                    result = "0" + result;
                                }

                                TradingCalculate.flagRendCode = false;

                                return result;
                            }
                            #endregion
                        }
                    }
                    #endregion
                }

                return result.ToString();
            }
        }
示例#12
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="AgentGroupID"></param>
        /// <param name="Name"></param>
        /// <returns></returns>
        internal int AddNewAgent(Business.Agent agent)
        {
            int idAgent = -1;
            System.Data.SqlClient.SqlTransaction trans = null;
            System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(DBConnection.DBConnection.Connection);
            DSTableAdapters.AgentTableAdapter adapAgent = new DSTableAdapters.AgentTableAdapter();
            DSTableAdapters.IAgentGroupTableAdapter adapIAgentGroup = new DSTableAdapters.IAgentGroupTableAdapter();
            try
            {
                conn.Open();
                trans                                          = conn.BeginTransaction();
                adapAgent.Connection                           = conn;
                adapAgent.Transaction                          = trans;

                adapIAgentGroup.Connection                     = conn;
                adapIAgentGroup.Transaction                    = trans;

                #region Create Investor
                Business.Investor investor                     = new Business.Investor();
                investor.InvestorStatusID                      = -1;
                investor.InvestorGroupInstance                 = new Business.InvestorGroup();
                investor.InvestorGroupInstance.InvestorGroupID = -1;
                investor.AgentID                               = string.Empty;
                investor.Balance                               = 0;
                investor.Credit                                = 0;
                investor.Code                                  = agent.Code;
                investor.PrimaryPwd                            = agent.Pwd;
                investor.ReadOnlyPwd                           = "";
                investor.PhonePwd                              = "";
                investor.IsDisable                             = true;
                investor.TaxRate                               = 0;
                investor.Leverage                              = 0;
                //Investor Profile
                DateTime registerDay                           = new DateTime();
                investor.Address                               = "";
                investor.Phone                                 = "";
                investor.City                                  = "";
                investor.Country                               = "";
                investor.Email                                 = "";
                investor.ZipCode                               = "";
                investor.RegisterDay                           = registerDay;
                investor.Comment                               = "";
                investor.State                                 = "";
                investor.NickName                              = "";
                investor.AllowChangePwd                        = false;
                investor.ReadOnly                              = false;
                investor.SendReport                            = false;
                #endregion

                int idInvestor = TradingServer.Facade.FacadeAddNewInvestor(investor);
                if (idInvestor < 1)
                {
                    throw new Exception("Data error");
                }

                agent.InvestorID = idInvestor;
                if (agent.AgentGroupID == -1)
                {
                    idAgent = int.Parse(adapAgent.AddNewAgent(null, agent.Name, agent.InvestorID, agent.Comment, agent.IsDisable, agent.IsIpFilter, agent.IpForm, agent.IpTo, agent.GroupCondition).ToString());
                }
                else idAgent = int.Parse(adapAgent.AddNewAgent(agent.AgentGroupID, agent.Name, agent.InvestorID, agent.Comment, agent.IsDisable, agent.IsIpFilter, agent.IpForm, agent.IpTo, agent.GroupCondition).ToString());
                if (idAgent < 1)
                {
                    throw new Exception("Data error");
                }

                List<int> listInvestorGroupIDs = new List<int>();
                listInvestorGroupIDs = agent.MakeListIAgentGroupManager(agent.GroupCondition);
                int count = listInvestorGroupIDs.Count;
                for (int i = 0; i < count; i++)
                {
                    int idIAgentGroup = int.Parse(adapIAgentGroup.AddIAgentGroup(idAgent, listInvestorGroupIDs[i]).ToString());
                    if (idIAgentGroup < 1)
                    {
                        throw new Exception("Data error");
                    }
                }

                trans.Commit();
            }
            catch (Exception ex)
            {
                trans.Rollback();
                idAgent = -1;
            }
            finally
            {
                adapAgent.Connection.Close();
                adapIAgentGroup.Connection.Close();
                conn.Close();
            }

            return idAgent;
        }