/// <summary>
        /// 
        /// </summary>
        /// <param name="typeID"></param>
        /// <returns></returns>
        internal Business.TradeType GetTradeType(int typeID)
        {
            Business.TradeType result = new TradeType();
            if (Business.Market.MarketArea != null)
            {
                bool flag = false;
                int count = Business.Market.MarketArea.Count;
                for (int i = 0; i < count; i++)
                {
                    if (flag)
                        break;

                    if (Business.Market.MarketArea[i].Type != null)
                    {
                        int countType = Business.Market.MarketArea[i].Type.Count;
                        for (int j = 0; j < countType; j++)
                        {
                            if (Business.Market.MarketArea[i].Type[j].ID == typeID)
                            {
                                result = Business.Market.MarketArea[i].Type[j];
                                flag = true;
                                break;
                            }
                        }
                    }
                }
            }

            return result;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="investorID"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <returns></returns>
        public static List<TradingServer.ClientBusiness.Command> FacadeGetCommandHistoryWithDateTime(int investorID, DateTime startTime, DateTime endTime)
        {
            List<ClientBusiness.Command> Result = new List<ClientBusiness.Command>();
            List<Business.OpenTrade> tempResult = new List<Business.OpenTrade>();

            if (Business.Market.IsConnectMT4)
            {
                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)
                        {
                            string cmd = BuildCommandElement5ConnectMT4.Mode.BuildCommand.Instance.ConvertGetCommandHistoryToString(Business.Market.InvestorList[i].Code, startTime, endTime);

                            //string cmdResult = Business.Market.InstanceSocket.SendToMT4(Business.Market.DEFAULT_IPADDRESS, Business.Market.DEFAULT_PORT, cmd);
                            string cmdResult = Element5SocketConnectMT4.Business.SocketConnect.Instance.SendSocket(cmd);

                            if (!string.IsNullOrEmpty(cmdResult))
                            {
                                //List<BuildCommandElement5ConnectMT4.Business.OnlineTrade> listHistory = BuildCommandElement5ConnectMT4.Mode.ReceiveCommand.Instance.ConvertOnlineTradeToListString(cmdResult);
                                List<BuildCommandElement5ConnectMT4.Business.OnlineTrade> listHistory = BuildCommandElement5ConnectMT4.Mode.ReceiveCommand.Instance.ConvertHistoryToListString(cmdResult);
                                if (listHistory != null)
                                {
                                    int countHistory = listHistory.Count;
                                    for (int j = 0; j < countHistory; j++)
                                    {
                                        Business.OpenTrade newOpenTrade = new Business.OpenTrade();

                                        //newOpenTrade.ClientCode = tbCommandHistory[i].ClientCode;
                                        newOpenTrade.ClosePrice = listHistory[j].ClosePrice;
                                        newOpenTrade.CloseTime = listHistory[j].CloseTime;
                                        newOpenTrade.CommandCode = listHistory[j].CommandCode;
                                        newOpenTrade.Commission = listHistory[j].Commission;
                                        newOpenTrade.ExpTime = listHistory[j].TimeExpire;
                                        newOpenTrade.ID = listHistory[j].CommandID;
                                        //Investor

                                        #region FILL COMMAND TYPE
                                        switch (listHistory[j].CommandType)
                                        {
                                            case "0":
                                                {
                                                    Business.TradeType resultType = Business.Market.marketInstance.GetTradeType(1);
                                                    newOpenTrade.Type = resultType;
                                                }
                                                break;

                                            case "1":
                                                {
                                                    Business.TradeType resultType = Business.Market.marketInstance.GetTradeType(2);
                                                    newOpenTrade.Type = resultType;
                                                }
                                                break;

                                            case "2":
                                                {
                                                    Business.TradeType resultType = Business.Market.marketInstance.GetTradeType(7);
                                                    newOpenTrade.Type = resultType;
                                                }
                                                break;

                                            case "3":
                                                {
                                                    Business.TradeType resultType = Business.Market.marketInstance.GetTradeType(8);
                                                    newOpenTrade.Type = resultType;
                                                }
                                                break;

                                            case "4":
                                                {
                                                    Business.TradeType resultType = Business.Market.marketInstance.GetTradeType(9);
                                                    newOpenTrade.Type = resultType;
                                                }
                                                break;

                                            case "5":
                                                {
                                                    Business.TradeType resultType = Business.Market.marketInstance.GetTradeType(10);
                                                    newOpenTrade.Type = resultType;
                                                }
                                                break;

                                            case "6":
                                                {
                                                    if (listHistory[j].Profit >= 0)
                                                    {
                                                        Business.TradeType resultType = new Business.TradeType();
                                                        resultType.ID = 13;
                                                        resultType.Name = "Deposit";
                                                        newOpenTrade.Type = resultType;
                                                    }
                                                    else
                                                    {
                                                        Business.TradeType resultType = new Business.TradeType();
                                                        resultType.ID = 14;

                                                        resultType.Name = "Withdraw";
                                                        newOpenTrade.Type = resultType;
                                                    }
                                                }
                                                break;

                                            case "7":
                                                {
                                                    if (listHistory[j].Profit >= 0)
                                                    {
                                                        Business.TradeType resultType = new Business.TradeType();
                                                        resultType.ID = 15;
                                                        resultType.Name = "CreditIn";
                                                        newOpenTrade.Type = resultType;
                                                    }
                                                    else
                                                    {
                                                        Business.TradeType resultType = new Business.TradeType();
                                                        resultType.ID = 16;
                                                        resultType.Name = "CreditOut";
                                                        newOpenTrade.Type = resultType;
                                                    }
                                                }
                                                break;
                                        }
                                        #endregion

                                        #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].Code.ToUpper().Trim() == listHistory[j].InvestorCode)
                                                {
                                                    newOpenTrade.Investor = Business.Market.InvestorList[m];
                                                    break;
                                                }
                                            }
                                        }
                                        #endregion

                                        newOpenTrade.OpenPrice = listHistory[j].OpenPrice;
                                        newOpenTrade.OpenTime = listHistory[j].OpenTime;

                                        if (newOpenTrade.Type.ID == 13 || newOpenTrade.Type.ID == 14 || newOpenTrade.Type.ID == 15 || newOpenTrade.Type.ID == 16)
                                        {
                                            newOpenTrade.CloseTime = newOpenTrade.OpenTime;
                                        }

                                        newOpenTrade.Profit = listHistory[j].Profit;
                                        newOpenTrade.Size = listHistory[j].Size;
                                        newOpenTrade.StopLoss = listHistory[j].StopLoss;
                                        newOpenTrade.Swap = listHistory[j].Swap;
                                        //newOpenTrade.Taxes = listHistory[j].Taxes;
                                        newOpenTrade.Comment = listHistory[j].Comment;
                                        //newOpenTrade.AgentCommission = listHistory[j].AgentCommission;
                                        newOpenTrade.TakeProfit = listHistory[j].TakeProfit;

                                        #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 (Flag == true)
                                                    break;

                                                if (Business.Market.SymbolList[k].Name.ToUpper().Trim() == listHistory[j].SymbolName.ToUpper().Trim())
                                                {
                                                    newOpenTrade.Symbol = Business.Market.SymbolList[k];

                                                    Flag = true;
                                                    break;
                                                }
                                            }
                                        }
                                        #endregion

                                        tempResult.Add(newOpenTrade);
                                    }
                                }
                            }

                            break;
                        }
                    }
                }
            }
            else
            {
                tempResult = ClientFacade.OpenTradeInstance.GetCommandHistoryWithTime(investorID, startTime, endTime);
            }

            if (tempResult != null)
            {
                int count = tempResult.Count;
                for (int i = 0; i < count; i++)
                {
                    if (tempResult[i].Investor == null || tempResult[i].Type == null)
                        continue;

                    ClientBusiness.Command newCommand = new ClientBusiness.Command();
                    newCommand.ClosePrice = tempResult[i].ClosePrice;
                    newCommand.CommandID = tempResult[i].ID;
                    if (tempResult[i].Type != null)
                    {
                        newCommand.CommandType = tempResult[i].Type.Name;
                        newCommand.TypeID = tempResult[i].Type.ID;
                    }
                    newCommand.Commission = tempResult[i].Commission;
                    newCommand.InvestorID = tempResult[i].Investor.InvestorID;

                    bool IsBuy = false;
                    if (tempResult[i].Type != null)
                    {
                        if (tempResult[i].Type.ID == 1 || tempResult[i].Type.ID == 3 || tempResult[i].Type.ID == 5 ||
                            tempResult[i].Type.ID == 7 || tempResult[i].Type.ID == 9 || tempResult[i].Type.ID == 11)
                            IsBuy = true;
                    }

                    newCommand.IsBuy = IsBuy;
                    newCommand.OpenPrice = tempResult[i].OpenPrice.ToString();
                    newCommand.Size = double.Parse(tempResult[i].Size.ToString());
                    newCommand.StopLoss = tempResult[i].StopLoss;
                    newCommand.Swap = tempResult[i].Swap;
                    if (tempResult[i].Symbol != null)
                    {
                        newCommand.Symbol = tempResult[i].Symbol.Name;
                    }
                    newCommand.TakeProfit = tempResult[i].TakeProfit;
                    newCommand.Time = tempResult[i].OpenTime.ToString();
                    newCommand.TimeExpiry = tempResult[i].ExpTime;
                    newCommand.Profit = Math.Round(tempResult[i].Profit, 2);
                    newCommand.ClientCode = tempResult[i].ClientCode;
                    newCommand.CommandCode = tempResult[i].CommandCode;
                    newCommand.CloseTime = tempResult[i].CloseTime;
                    newCommand.Comment = tempResult[i].Comment;

                    Result.Add(newCommand);
                }
            }

            return Result;
        }