/// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        internal List<Business.OpenTrade> InitOnlineCommand()
        {
            List<Business.OpenTrade> result = new List<Business.OpenTrade>();
            System.Data.SqlClient.SqlConnection conn = new SqlConnection(DBConnection.DBConnection.Connection);
            DSTableAdapters.OnlineCommandTableAdapter adap = new DSTableAdapters.OnlineCommandTableAdapter();
            DS.OnlineCommandDataTable tbOnlineCommand = new DS.OnlineCommandDataTable();

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

                if (tbOnlineCommand != null)
                {
                    int count = tbOnlineCommand.Count;
                    for (int i = 0; i < count; i++)
                    {
                        //Business.OpenTrade newOpenTradeSymbol = new Business.OpenTrade();
                        //Business.OpenTrade newOpenTradeInvestor = new Business.OpenTrade();
                        //Business.OpenTrade newOpenTradeExe = new Business.OpenTrade();

                        Business.OpenTrade newOpenTradeSymbol = new Business.OpenTrade(tbOnlineCommand[i].IsActivePendig, tbOnlineCommand[i].IsStopLossTakeProfit);
                        Business.OpenTrade newOpenTradeInvestor = new Business.OpenTrade(tbOnlineCommand[i].IsActivePendig, tbOnlineCommand[i].IsStopLossTakeProfit);
                        Business.OpenTrade newOpenTradeExe = new Business.OpenTrade(tbOnlineCommand[i].IsActivePendig, tbOnlineCommand[i].IsStopLossTakeProfit);

                        #region FIND SYMBOL AND TYPE INSTANCE FOR COMMAND(COMMAND IN SYMBOL, COMMAND IN INVESTOR, COMMAND IN COMMAND EXECUTOR
                        if (Business.Market.SymbolList != null && Business.Market.SymbolList.Count > 0)
                        {
                            int countSymbol = Business.Market.SymbolList.Count;
                            for (int j = 0; j < countSymbol; j++)
                            {
                                if (Business.Market.SymbolList[j].SymbolID == tbOnlineCommand[i].SymbolID)
                                {
                                    newOpenTradeExe.Symbol = Business.Market.SymbolList[j];
                                    newOpenTradeInvestor.Symbol = Business.Market.SymbolList[j];
                                    newOpenTradeSymbol.Symbol = Business.Market.SymbolList[j];

                                    break;
                                }
                            }
                        }
                        #endregion

                        #region SEARCH MARKET AND GET TYPE COMMAND
                        if (Business.Market.MarketArea != null)
                        {
                            int countMarketArea = Business.Market.MarketArea.Count;
                            bool flagMarketArea = false;
                            for (int j = 0; j < countMarketArea; j++)
                            {
                                if (flagMarketArea)
                                    break;

                                if (Business.Market.MarketArea[j].Type != null)
                                {
                                    int countType = Business.Market.MarketArea[j].Type.Count;
                                    for (int n = 0; n < countType; n++)
                                    {
                                        if (Business.Market.MarketArea[j].Type[n].ID == tbOnlineCommand[i].CommandTypeID)
                                        {
                                            newOpenTradeExe.Type = Business.Market.MarketArea[j].Type[n];
                                            newOpenTradeInvestor.Type = Business.Market.MarketArea[j].Type[n];
                                            newOpenTradeSymbol.Type = Business.Market.MarketArea[j].Type[n];

                                            flagMarketArea = true;

                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        #endregion

                        #region FIND INVESTOR AND IGROUPSECURITY INSTANCE OF COMMAND(COMMAND IN SYMBOL, COMMAND IN INVESTOR, COMMAND IN COMMAND EXECUTOR
                        if (Business.Market.InvestorList != null)
                        {
                            int countInvestor = Business.Market.InvestorList.Count;
                            for (int j = 0; j < countInvestor; j++)
                            {
                                if (Business.Market.InvestorList[j].InvestorID == tbOnlineCommand[i].InvestorID)
                                {
                                    newOpenTradeSymbol.Investor = Business.Market.InvestorList[j];
                                    newOpenTradeInvestor.Investor = Business.Market.InvestorList[j];
                                    newOpenTradeExe.Investor = Business.Market.InvestorList[j];

                                    #region GET IGROUP SECURITY
                                    if (Business.Market.IGroupSecurityList != null)
                                    {
                                        int countIGroupSecurity = Business.Market.IGroupSecurityList.Count;
                                        for (int n = 0; n < countIGroupSecurity; n++)
                                        {
                                            if (Business.Market.IGroupSecurityList[n].SecurityID == newOpenTradeSymbol.Symbol.SecurityID &&
                                                Business.Market.IGroupSecurityList[n].InvestorGroupID == newOpenTradeSymbol.Investor.InvestorGroupInstance.InvestorGroupID)
                                            {
                                                newOpenTradeSymbol.IGroupSecurity = Business.Market.IGroupSecurityList[n];
                                                newOpenTradeInvestor.IGroupSecurity = Business.Market.IGroupSecurityList[n];
                                                newOpenTradeExe.IGroupSecurity = Business.Market.IGroupSecurityList[n];

                                                break;
                                            }
                                        }
                                    }
                                    #endregion

                                    break;
                                }
                            }
                        }
                        #endregion

                        #region GET SPREAD DIFFIRENCE FOR COMMAND
                        //GET SPREAD DIFFRENCE OF OPEN TRADE
                        double spreadDifference = TradingServer.Model.CommandFramework.CommandFrameworkInstance.GetSpreadDifference(newOpenTradeInvestor.Symbol.SecurityID,
                            newOpenTradeInvestor.Investor.InvestorGroupInstance.InvestorGroupID);

                        newOpenTradeExe.SpreaDifferenceInOpenTrade = spreadDifference;
                        newOpenTradeInvestor.SpreaDifferenceInOpenTrade = spreadDifference;
                        newOpenTradeSymbol.SpreaDifferenceInOpenTrade = spreadDifference;
                        #endregion

                        //===============================
                        #region SET CLOSE PRICES COMMAND
                        if (tbOnlineCommand[i].CommandTypeID == 1 || tbOnlineCommand[i].CommandTypeID == 11)
                        {
                            newOpenTradeExe.ClosePrice = newOpenTradeExe.Symbol.TickValue.Bid;
                            newOpenTradeInvestor.ClosePrice = newOpenTradeInvestor.Symbol.TickValue.Bid;
                            newOpenTradeSymbol.ClosePrice = newOpenTradeSymbol.Symbol.TickValue.Bid;
                        }

                        if (tbOnlineCommand[i].CommandTypeID == 2 || tbOnlineCommand[i].CommandTypeID == 12)
                        {
                            newOpenTradeExe.ClosePrice = (newOpenTradeExe.Symbol.TickValue.Ask +
                                Business.Symbol.ConvertNumberPip(newOpenTradeExe.Symbol.Digit, newOpenTradeExe.SpreaDifferenceInOpenTrade));

                            newOpenTradeInvestor.ClosePrice = (newOpenTradeInvestor.Symbol.TickValue.Ask +
                                Business.Symbol.ConvertNumberPip(newOpenTradeInvestor.Symbol.Digit, newOpenTradeInvestor.SpreaDifferenceInOpenTrade));

                            newOpenTradeSymbol.ClosePrice = (newOpenTradeSymbol.Symbol.TickValue.Ask +
                                Business.Symbol.ConvertNumberPip(newOpenTradeSymbol.Symbol.Digit, newOpenTradeSymbol.SpreaDifferenceInOpenTrade));
                        }
                        #endregion

                        //=================================

                        #region NEW INSTANCES FOR COMMAND EXECUTOR
                        newOpenTradeExe.AgentCommission = tbOnlineCommand[i].AgentCommission;
                        newOpenTradeExe.ClientCode = tbOnlineCommand[i].ClientCode;
                        newOpenTradeExe.CloseTime = tbOnlineCommand[i].CloseTime;
                        newOpenTradeExe.CommandCode = tbOnlineCommand[i].CommandCode;
                        newOpenTradeExe.Comment = tbOnlineCommand[i].Comment;
                        newOpenTradeExe.Commission = tbOnlineCommand[i].Commission;
                        newOpenTradeExe.ExpTime = tbOnlineCommand[i].ExpTime;
                        newOpenTradeExe.FreezeMargin = 0;
                        newOpenTradeExe.ID = tbOnlineCommand[i].OnlineCommandID;
                        newOpenTradeExe.IsClose = tbOnlineCommand[i].IsClose;
                        newOpenTradeExe.OpenPrice = tbOnlineCommand[i].OpenPrice;
                        newOpenTradeExe.OpenTime = tbOnlineCommand[i].OpenTime;
                        newOpenTradeExe.Profit = tbOnlineCommand[i].Profit;
                        newOpenTradeExe.Size = tbOnlineCommand[i].Size;
                        newOpenTradeExe.StopLoss = tbOnlineCommand[i].StopLoss;
                        newOpenTradeExe.Swap = tbOnlineCommand[i].Swap;
                        newOpenTradeExe.TakeProfit = tbOnlineCommand[i].TakeProfit;
                        newOpenTradeExe.Taxes = tbOnlineCommand[i].Taxes;
                        newOpenTradeExe.TotalSwap = tbOnlineCommand[i].TotalSwaps;
                        newOpenTradeExe.RefCommandID = tbOnlineCommand[i].RefCommandID;
                        newOpenTradeExe.AgentRefConfig = tbOnlineCommand[i].AgentRefConfig;
                        #endregion

                        #region NEW INSTANCE FOR SYMBOL LIST
                        newOpenTradeSymbol.AgentCommission = tbOnlineCommand[i].AgentCommission;
                        newOpenTradeSymbol.ClientCode = tbOnlineCommand[i].ClientCode;
                        newOpenTradeSymbol.CloseTime = tbOnlineCommand[i].CloseTime;
                        newOpenTradeSymbol.CommandCode = tbOnlineCommand[i].CommandCode;
                        newOpenTradeSymbol.Comment = tbOnlineCommand[i].Comment;
                        newOpenTradeSymbol.Commission = tbOnlineCommand[i].Commission;
                        newOpenTradeSymbol.ExpTime = tbOnlineCommand[i].ExpTime;
                        newOpenTradeSymbol.FreezeMargin = 0;
                        newOpenTradeSymbol.ID = tbOnlineCommand[i].OnlineCommandID;
                        newOpenTradeSymbol.IsClose = tbOnlineCommand[i].IsClose;
                        newOpenTradeSymbol.OpenPrice = tbOnlineCommand[i].OpenPrice;
                        newOpenTradeSymbol.OpenTime = tbOnlineCommand[i].OpenTime;
                        newOpenTradeSymbol.Profit = tbOnlineCommand[i].Profit;
                        newOpenTradeSymbol.Size = tbOnlineCommand[i].Size;
                        newOpenTradeSymbol.StopLoss = tbOnlineCommand[i].StopLoss;
                        newOpenTradeSymbol.Swap = tbOnlineCommand[i].Swap;
                        newOpenTradeSymbol.TakeProfit = tbOnlineCommand[i].TakeProfit;
                        newOpenTradeSymbol.Taxes = tbOnlineCommand[i].Taxes;
                        newOpenTradeSymbol.TotalSwap = tbOnlineCommand[i].TotalSwaps;
                        newOpenTradeSymbol.InsExe = newOpenTradeExe;
                        newOpenTradeSymbol.RefCommandID = tbOnlineCommand[i].RefCommandID;
                        newOpenTradeSymbol.AgentRefConfig = tbOnlineCommand[i].AgentRefConfig;
                        #endregion

                        #region NEW INSTANCE FOR INVESTOR LIST
                        newOpenTradeInvestor.AgentCommission = tbOnlineCommand[i].AgentCommission;
                        newOpenTradeInvestor.ClientCode = tbOnlineCommand[i].ClientCode;
                        newOpenTradeInvestor.CloseTime = tbOnlineCommand[i].CloseTime;
                        newOpenTradeInvestor.CommandCode = tbOnlineCommand[i].CommandCode;
                        newOpenTradeInvestor.Comment = tbOnlineCommand[i].Comment;
                        newOpenTradeInvestor.Commission = tbOnlineCommand[i].Commission;
                        newOpenTradeInvestor.ExpTime = tbOnlineCommand[i].ExpTime;
                        newOpenTradeInvestor.FreezeMargin = 0;
                        newOpenTradeInvestor.ID = tbOnlineCommand[i].OnlineCommandID;
                        newOpenTradeInvestor.IsClose = tbOnlineCommand[i].IsClose;
                        newOpenTradeInvestor.OpenPrice = tbOnlineCommand[i].OpenPrice;
                        newOpenTradeInvestor.OpenTime = tbOnlineCommand[i].OpenTime;
                        newOpenTradeInvestor.Profit = tbOnlineCommand[i].Profit;
                        newOpenTradeInvestor.Size = tbOnlineCommand[i].Size;
                        newOpenTradeInvestor.StopLoss = tbOnlineCommand[i].StopLoss;
                        newOpenTradeInvestor.Swap = tbOnlineCommand[i].Swap;
                        newOpenTradeInvestor.TakeProfit = tbOnlineCommand[i].TakeProfit;
                        newOpenTradeInvestor.Taxes = tbOnlineCommand[i].Taxes;
                        newOpenTradeInvestor.TotalSwap = tbOnlineCommand[i].TotalSwaps;
                        newOpenTradeInvestor.InsExe = newOpenTradeExe;
                        newOpenTradeInvestor.RefCommandID = tbOnlineCommand[i].RefCommandID;
                        newOpenTradeInvestor.AgentRefConfig = tbOnlineCommand[i].AgentRefConfig;
                        #endregion

                        //======================================
                        #region ADD COMMAND TO COMMAND EXECUTOR
                        if (Business.Market.CommandExecutor == null)
                            Business.Market.CommandExecutor = new List<Business.OpenTrade>();

                        Business.Market.CommandExecutor.Add(newOpenTradeExe);
                        #endregion

                        #region ADD COMMAND TO INVESTOR LIST
                        if (Business.Market.InvestorList != null)
                        {
                            int countInvestor = Business.Market.InvestorList.Count;
                            for (int j = 0; j < countInvestor; j++)
                            {
                                if (Business.Market.InvestorList[j].InvestorID == tbOnlineCommand[i].InvestorID)
                                {
                                    if (Business.Market.InvestorList[j].CommandList == null)
                                        Business.Market.InvestorList[j].CommandList = new List<Business.OpenTrade>();

                                    Business.Market.InvestorList[j].CommandList.Add(newOpenTradeInvestor);

                                    break;
                                }
                            }
                        }
                        #endregion

                        #region ADD COMMAND TO SYMBOL LIST
                        if (Business.Market.SymbolList != null)
                        {
                            int countSymbol = Business.Market.SymbolList.Count;
                            for (int j = 0; j < countSymbol; j++)
                            {
                                if (Business.Market.SymbolList[j].SymbolID == tbOnlineCommand[i].SymbolID)
                                {
                                    if (Business.Market.SymbolList[j].CommandList == null)
                                        Business.Market.SymbolList[j].CommandList = new List<Business.OpenTrade>();

                                    Business.Market.SymbolList[j].CommandList.Add(newOpenTradeSymbol);

                                    break;
                                }
                            }
                        }
                        #endregion

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

            return result;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        internal List<Business.OpenTrade> GetAllOnlineCommand()
        {
            List<Business.OpenTrade> Result = new List<Business.OpenTrade>();
            System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(DBConnection.DBConnection.Connection);
            DSTableAdapters.OnlineCommandTableAdapter adap = new DSTableAdapters.OnlineCommandTableAdapter();
            DS.OnlineCommandDataTable tbOnlineCommand = new DS.OnlineCommandDataTable();

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

                if (tbOnlineCommand != null)
                {
                    int count = tbOnlineCommand.Count;
                    for (int i = 0; i < count; i++)
                    {
                        Business.OpenTrade newOpenTrade = new Business.OpenTrade();
                        newOpenTrade.ID = tbOnlineCommand[i].OnlineCommandID;

                        #region Find Symbol In Symbol List
                        if (Business.Market.SymbolList != null)
                        {
                            bool Flag = false;
                            int countSymbol = Business.Market.SymbolList.Count;
                            for (int k = 0; k < countSymbol; k++)
                            {
                                if (Business.Market.SymbolList[k].SymbolID == tbOnlineCommand[i].SymbolID)
                                {
                                    #region SEARCH IN MARKET OF SYMBOL AND GET TYPE OF COMMAND
                                    bool tempFlag = false;
                                    if (Business.Market.MarketArea != null)
                                    {
                                        int countMarketArea = Business.Market.MarketArea.Count;
                                        for (int n = 0; n < countMarketArea; n++)
                                        {
                                            if (tempFlag)
                                                break;

                                            if (Business.Market.MarketArea[n].Type != null)
                                            {
                                                int countType = Business.Market.MarketArea[n].Type.Count;
                                                for (int m = 0; m < countType; m++)
                                                {
                                                    if (Business.Market.MarketArea[n].Type[m].ID == tbOnlineCommand[i].CommandTypeID)
                                                    {
                                                        newOpenTrade.Type = Business.Market.MarketArea[n].Type[m];
                                                        tempFlag = true;
                                                        break;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    #endregion

                                    newOpenTrade.Symbol = Business.Market.SymbolList[k];
                                    newOpenTrade.ClientCode = tbOnlineCommand[i].ClientCode;

                                    switch (newOpenTrade.Type.ID)
                                    {
                                        case 1:
                                            newOpenTrade.ClosePrice = newOpenTrade.Symbol.TickValue.Bid;
                                            break;
                                        case 2:
                                            newOpenTrade.ClosePrice = newOpenTrade.Symbol.TickValue.Ask;
                                            break;
                                        case 11:
                                            newOpenTrade.ClosePrice = newOpenTrade.Symbol.TickValue.Bid;
                                            break;
                                        case 12:
                                            newOpenTrade.ClosePrice = newOpenTrade.Symbol.TickValue.Ask;
                                            break;
                                    }

                                    newOpenTrade.CloseTime = tbOnlineCommand[i].CloseTime;
                                    newOpenTrade.ExpTime = tbOnlineCommand[i].ExpTime;
                                    newOpenTrade.IsClose = tbOnlineCommand[i].IsClose;
                                    newOpenTrade.OpenPrice = tbOnlineCommand[i].OpenPrice;
                                    newOpenTrade.OpenTime = tbOnlineCommand[i].OpenTime;
                                    newOpenTrade.Size = tbOnlineCommand[i].Size;
                                    newOpenTrade.StopLoss = tbOnlineCommand[i].StopLoss;
                                    newOpenTrade.TakeProfit = tbOnlineCommand[i].TakeProfit;
                                    newOpenTrade.Commission = tbOnlineCommand[i].Commission;
                                    newOpenTrade.Swap = Math.Round(tbOnlineCommand[i].Swap, 2);
                                    newOpenTrade.Profit = tbOnlineCommand[i].Profit;
                                    newOpenTrade.CommandCode = tbOnlineCommand[i].CommandCode;
                                    newOpenTrade.Taxes = tbOnlineCommand[i].Taxes;
                                    newOpenTrade.Comment = tbOnlineCommand[i].Comment;
                                    newOpenTrade.AgentCommission = tbOnlineCommand[i].AgentCommission;
                                    newOpenTrade.TotalSwap = tbOnlineCommand[i].TotalSwaps;
                                    newOpenTrade.RefCommandID = tbOnlineCommand[i].RefCommandID;

                                    #region Find Investor In Investor List
                                    if (Business.Market.InvestorList != null)
                                    {
                                        int countInvestor = Business.Market.InvestorList.Count;
                                        for (int m = 0; m < countInvestor; m++)
                                        {
                                            if (Business.Market.InvestorList[m].InvestorID == tbOnlineCommand[i].InvestorID)
                                            {
                                                newOpenTrade.Investor = Business.Market.InvestorList[m];

                                                #region Find IGroupSecurity In IGroupSecurity List
                                                if (Business.Market.IGroupSecurityList != null)
                                                {
                                                    int countIGroupSecurity = Business.Market.IGroupSecurityList.Count;
                                                    for (int p = 0; p < countIGroupSecurity; p++)
                                                    {
                                                        if (Business.Market.IGroupSecurityList[p].SecurityID == newOpenTrade.Symbol.SecurityID &&
                                                            Business.Market.IGroupSecurityList[p].InvestorGroupID == newOpenTrade.Investor.InvestorGroupInstance.InvestorGroupID)
                                                        {
                                                            newOpenTrade.IGroupSecurity = Business.Market.IGroupSecurityList[p];
                                                            break;
                                                        }
                                                    }
                                                }
                                                #endregion

                                                if (Business.Market.InvestorList[m].CommandList == null)
                                                    Business.Market.InvestorList[m].CommandList = new List<Business.OpenTrade>();

                                                Business.Market.InvestorList[m].CommandList.Add(newOpenTrade);
                                                break;
                                            }
                                        }
                                    }
                                    #endregion

                                    //GET SPREAD DIFFRENCE OF OPEN TRADE
                                    double spreadDifference = TradingServer.Model.CommandFramework.CommandFrameworkInstance.GetSpreadDifference(newOpenTrade.Symbol.SecurityID, newOpenTrade.Investor.InvestorGroupInstance.InvestorGroupID);
                                    newOpenTrade.SpreaDifferenceInOpenTrade = spreadDifference;

                                    if (Business.Market.SymbolList[k].CommandList == null)
                                        Business.Market.SymbolList[k].CommandList = new List<Business.OpenTrade>();

                                    Business.Market.SymbolList[k].CommandList.Add(newOpenTrade);

                                    #region ADD COMMAND TO COMMAND EXECUTORY
                                    if (Business.Market.CommandExecutor == null)
                                        Business.Market.CommandExecutor = new List<Business.OpenTrade>();

                                    Business.Market.CommandExecutor.Add(newOpenTrade);

                                    #endregion

                                    Flag = true;
                                    break;
                                }

                                //if (Flag == false)
                                //{
                                //    if (Business.Market.SymbolList[k].RefSymbol != null && Business.Market.SymbolList[k].RefSymbol.Count > 0)
                                //    {
                                //        newOpenTrade.Symbol = this.FindSymbolReference(Business.Market.SymbolList[k].RefSymbol, newOpenTrade, tbOnlineCommand[i].SymbolID);
                                //    }
                                //}
                            }
                        }
                        #endregion

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

            return Result;
        }