/// <summary>
        /// 
        /// </summary>
        /// <param name="listInvestorID"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <returns></returns>
        internal List<Business.OpenTrade> GetCommandHistoryWithListInvestorID(List<int> listInvestorID, DateTime start, DateTime end, int ManagerID)
        {
            List<Business.OpenTrade> Result = new List<Business.OpenTrade>();
            List<Business.OpenTrade> listLastCommand = new List<Business.OpenTrade>();

            System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(DBConnection.DBConnection.Connection);

            DS.CommandHistoryDataTable tbCommandHistory = new DS.CommandHistoryDataTable();
            System.Data.SqlClient.SqlDataAdapter adap = new System.Data.SqlClient.SqlDataAdapter();
            DSTableAdapters.CommandHistoryTableAdapter adapCommandHistory = new DSTableAdapters.CommandHistoryTableAdapter();

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

                DateTime timeLastBalance = start.AddDays(-1);
                if (timeLastBalance.DayOfWeek == DayOfWeek.Sunday)
                {
                    timeLastBalance = timeLastBalance.AddDays(-2);
                }

                if (timeLastBalance.DayOfWeek == DayOfWeek.Saturday)
                {
                    timeLastBalance = timeLastBalance.AddDays(-1);
                }

                DateTime timeStartLastBalance = new DateTime(timeLastBalance.Year, timeLastBalance.Month, timeLastBalance.Day, 00, 00, 00);
                DateTime tempTimeEndLastBalance = timeStartLastBalance.AddDays(1);
                DateTime timeEndLastBalance = new DateTime(tempTimeEndLastBalance.Year, tempTimeEndLastBalance.Month, tempTimeEndLastBalance.Day, 00, 00, 00);

                #region FILL LIST INVESTOR SEARCH
                string listInvestor = string.Empty;
                if (listInvestorID != null)
                {
                    int countListInvestor = listInvestorID.Count;
                    for (int i = 0; i < countListInvestor; i++)
                    {
                        if (i == countListInvestor - 1)
                        {
                            listInvestor += listInvestorID[i];
                        }
                        else
                        {
                            listInvestor += listInvestorID[i] + ",";
                        }
                    }
                }
                #endregion

                string sql = "SELECT * FROM CommandHistory WHERE (InvestorID IN(" + listInvestor + ")) AND (CloseTime >= '" + start + "') AND (CloseTime <= '" + end + "')" +
                    " AND CommandTypeID NOT IN(21) AND (IsDelete = 0)";
                adap.SelectCommand = new System.Data.SqlClient.SqlCommand(sql, conn);
                tbCommandHistory = new DS.CommandHistoryDataTable();
                adap.Fill(tbCommandHistory);

                //close connection
                conn.Close();

                if (tbCommandHistory != null)
                {
                    int count = tbCommandHistory.Count;
                    for (int i = 0; i < count; i++)
                    {
                        bool isExistInvestor = false;
                        Business.OpenTrade newOpenTrade = new Business.OpenTrade();
                        newOpenTrade.ClientCode = tbCommandHistory[i].ClientCode;
                        newOpenTrade.ClosePrice = tbCommandHistory[i].ClosePrice;
                        newOpenTrade.CloseTime = tbCommandHistory[i].CloseTime;
                        newOpenTrade.CommandCode = tbCommandHistory[i].CommandCode;
                        newOpenTrade.Commission = tbCommandHistory[i].Commission;
                        newOpenTrade.ExpTime = tbCommandHistory[i].ExpTime;
                        newOpenTrade.ID = tbCommandHistory[i].CommandHistoryID;

                        if (Business.Market.InvestorList != null && Business.Market.InvestorList.Count > 0)
                        {
                            int countInvestor = Business.Market.InvestorList.Count;
                            for (int j = 0; j < countInvestor; j++)
                            {
                                if (Business.Market.InvestorList[j].InvestorID == tbCommandHistory[i].InvestorID)
                                {
                                    newOpenTrade.Investor = Business.Market.InvestorList[j];
                                    isExistInvestor = true;
                                    break;
                                }
                            }
                        }

                        newOpenTrade.IsClose = true;
                        newOpenTrade.OpenPrice = tbCommandHistory[i].OpenPrice;
                        newOpenTrade.OpenTime = tbCommandHistory[i].OpenTime;
                        newOpenTrade.Profit = tbCommandHistory[i].Profit;
                        newOpenTrade.Size = tbCommandHistory[i].Size;
                        newOpenTrade.StopLoss = tbCommandHistory[i].StopLoss;
                        newOpenTrade.Swap = tbCommandHistory[i].Swap;
                        newOpenTrade.ManagerID = ManagerID;

                        if (tbCommandHistory[i].SymbolID > 0)
                        {
                            if (Business.Market.SymbolList != null)
                            {
                                int countSymbol = Business.Market.SymbolList.Count;
                                for (int j = 0; j < countSymbol; j++)
                                {
                                    if (Business.Market.SymbolList[j].SymbolID == tbCommandHistory[i].SymbolID)
                                    {
                                        newOpenTrade.Symbol = Business.Market.SymbolList[j];
                                        break;
                                    }
                                }
                            }
                        }

                        newOpenTrade.TakeProfit = tbCommandHistory[i].TakeProfit;
                        newOpenTrade.Taxes = tbCommandHistory[i].Taxes;
                        newOpenTrade.Comment = tbCommandHistory[i].Comment;
                        newOpenTrade.AgentCommission = tbCommandHistory[i].AgentCommission;
                        newOpenTrade.Type = new Business.TradeType();
                        newOpenTrade.Type.ID = tbCommandHistory[i].CommandTypeID;
                        newOpenTrade.AgentCommission = tbCommandHistory[i].AgentCommission;
                        newOpenTrade.AgentRefConfig = tbCommandHistory[i].AgentRefConfig;
                        //newOpenTrade.IsActivePending = tbCommandHistory[i].IsActivePending;
                        //newOpenTrade.IsStopLossAndTakeProfit = tbCommandHistory[i].IsStopLossTakeProfit;

                        Result.Add(newOpenTrade);
                    }
                }
            }
            catch (Exception ex)
            {
                return null;
            }
            finally
            {

            }

            return Result;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="Start"></param>
        /// <param name="Limit"></param>
        /// <param name="InvestorID"></param>
        /// <returns></returns>
        internal List<Business.OpenTrade> GetCommandHistoryWithStartLimit(int InvestorID, int ManagerID, DateTime TimeStart, DateTime TimeEnd)
        {
            List<Business.OpenTrade> Result = new List<Business.OpenTrade>();
            //List<Business.OpenTrade> tempResult = new List<Business.OpenTrade>();
            System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(DBConnection.DBConnection.Connection);
            DSTableAdapters.CommandHistoryTableAdapter adap = new DSTableAdapters.CommandHistoryTableAdapter();
            DS.CommandHistoryDataTable tbCommandHistory = new DS.CommandHistoryDataTable();

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

                //Get Data
                tbCommandHistory = adap.GetCommandHistoryWithStartLimit(InvestorID, TimeStart, TimeEnd);

                //Close Connection
                adap.Connection.Close();
                conn.Close();

                #region FILL DATA
                if (tbCommandHistory != null && tbCommandHistory.Count > 0)
                {
                    int count = tbCommandHistory.Count;
                    for (int i = 0; i < count; i++)
                    {
                        if (tbCommandHistory[i].CommandTypeID == 21)
                            continue;

                        Business.OpenTrade newOpenTrade = new Business.OpenTrade();
                        newOpenTrade.ClientCode = tbCommandHistory[i].ClientCode;
                        newOpenTrade.ClosePrice = tbCommandHistory[i].ClosePrice;
                        newOpenTrade.CloseTime = tbCommandHistory[i].CloseTime;
                        newOpenTrade.CommandCode = tbCommandHistory[i].CommandCode;
                        newOpenTrade.Commission = tbCommandHistory[i].Commission;
                        newOpenTrade.ExpTime = tbCommandHistory[i].ExpTime;
                        newOpenTrade.ID = tbCommandHistory[i].CommandHistoryID;
                        newOpenTrade.Investor = new Business.Investor();
                        newOpenTrade.Investor.InvestorID = tbCommandHistory[i].InvestorID;
                        newOpenTrade.IsClose = true;
                        newOpenTrade.OpenPrice = tbCommandHistory[i].OpenPrice;
                        newOpenTrade.OpenTime = tbCommandHistory[i].OpenTime;
                        newOpenTrade.Profit = tbCommandHistory[i].Profit;
                        newOpenTrade.Size = tbCommandHistory[i].Size;
                        newOpenTrade.StopLoss = tbCommandHistory[i].StopLoss;
                        newOpenTrade.Swap = tbCommandHistory[i].Swap;
                        newOpenTrade.ManagerID = ManagerID;
                        newOpenTrade.Comment = tbCommandHistory[i].Comment;

                        if (tbCommandHistory[i].SymbolID > 0)
                        {
                            if (Business.Market.SymbolList != null)
                            {
                                int countSymbol = Business.Market.SymbolList.Count;
                                for (int j = 0; j < countSymbol; j++)
                                {
                                    if (Business.Market.SymbolList[j].SymbolID == tbCommandHistory[i].SymbolID)
                                    {
                                        newOpenTrade.Symbol = Business.Market.SymbolList[j];
                                        break;
                                    }
                                }
                            }
                        }

                        newOpenTrade.TakeProfit = tbCommandHistory[i].TakeProfit;
                        newOpenTrade.Taxes = tbCommandHistory[i].Taxes;
                        newOpenTrade.Type = new Business.TradeType();
                        newOpenTrade.Type.ID = tbCommandHistory[i].CommandTypeID;
                        newOpenTrade.Type.Name = TradingServer.Facade.FacadeGetTypeNameByTypeID(newOpenTrade.Type.ID);
                        newOpenTrade.AgentCommission = tbCommandHistory[i].AgentCommission;
                        newOpenTrade.IsActivePending = tbCommandHistory[i].IsActivePending;
                        newOpenTrade.IsStopLossAndTakeProfit = tbCommandHistory[i].IsStopLossTakeProfit;

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

            return Result;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="commandID"></param>
        /// <returns></returns>
        internal Business.OpenTrade GetCommandHistoryByCommandID(int commandID)
        {
            Business.OpenTrade result = new Business.OpenTrade();
            System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(DBConnection.DBConnection.Connection);
            DSTableAdapters.CommandHistoryTableAdapter adap = new DSTableAdapters.CommandHistoryTableAdapter();
            DS.CommandHistoryDataTable tbCommandHistory = new DS.CommandHistoryDataTable();

            try
            {
                conn.Open();
                adap.Connection = conn;
                tbCommandHistory = adap.GetCommandHistoryByID(commandID);
                if (tbCommandHistory != null)
                {
                    //CALL FUNCTION FILL INSTANCE OF COMMAND
                    result = TradingServer.ClientFacade.FillInstanceOpenTrade(tbCommandHistory[0].SymbolID, tbCommandHistory[0].InvestorID, tbCommandHistory[0].CommandTypeID);

                    result.AgentCommission = tbCommandHistory[0].AgentCommission;
                    result.ClientCode = tbCommandHistory[0].ClientCode;
                    result.ClosePrice = tbCommandHistory[0].ClosePrice;
                    result.CloseTime = tbCommandHistory[0].CloseTime;
                    result.CommandCode = tbCommandHistory[0].CommandCode;
                    result.Comment = tbCommandHistory[0].Comment;
                    result.Commission = tbCommandHistory[0].Commission;
                    result.ExpTime = tbCommandHistory[0].ExpTime;
                    result.ID = tbCommandHistory[0].CommandHistoryID;

                    result.IsClose = true;
                    result.OpenPrice = tbCommandHistory[0].OpenPrice;
                    result.OpenTime = tbCommandHistory[0].OpenTime;
                    result.Profit = tbCommandHistory[0].Profit;
                    result.Size = tbCommandHistory[0].Size;
                    result.StopLoss = tbCommandHistory[0].StopLoss;
                    result.Swap = tbCommandHistory[0].Swap;
                    result.TotalSwap = tbCommandHistory[0].TotalSwaps;

                    result.TakeProfit = tbCommandHistory[0].TakeProfit;
                    result.Taxes = tbCommandHistory[0].Taxes;
                    result.AgentRefConfig = tbCommandHistory[0].AgentRefConfig;
                    result.IsActivePending = tbCommandHistory[0].IsActivePending;
                    result.IsStopLossAndTakeProfit = tbCommandHistory[0].IsStopLossTakeProfit;
                }
            }
            catch (Exception ex)
            {
                return null;
            }
            finally
            {
                adap.Connection.Close();
                conn.Close();
            }

            return result;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="investorID"></param>
        /// <returns></returns>
        internal List<Business.OpenTrade> GetCommandHistoryByInvestorInMonth(int investorID)
        {
            List<Business.OpenTrade> Result = new List<Business.OpenTrade>();
            System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(DBConnection.DBConnection.Connection);
            DSTableAdapters.CommandHistoryTableAdapter adap = new DSTableAdapters.CommandHistoryTableAdapter();
            DS.CommandHistoryDataTable tbCommandHistory = new DS.CommandHistoryDataTable();

            try
            {
                conn.Open();
                adap.Connection = conn;
                tbCommandHistory = adap.GetHistoryByInvestorInMonth(investorID);

                if (tbCommandHistory != null)
                {
                    int count = tbCommandHistory.Count;
                    for (int i = 0; i < count; i++)
                    {
                        Business.OpenTrade newOpenTrade = new Business.OpenTrade();
                        newOpenTrade.ClientCode = tbCommandHistory[i].ClientCode;
                        newOpenTrade.ClosePrice = tbCommandHistory[i].ClosePrice;
                        newOpenTrade.CloseTime = tbCommandHistory[i].CloseTime;
                        newOpenTrade.CommandCode = tbCommandHistory[i].CommandCode;
                        newOpenTrade.Commission = tbCommandHistory[i].Commission;
                        newOpenTrade.ExpTime = tbCommandHistory[i].ExpTime;
                        newOpenTrade.ID = tbCommandHistory[i].CommandHistoryID;
                        //Investor

                        #region Find Trade Type In Market Area
                        //Find Trade Type
                        bool FlagType = false;
                        if (Business.Market.MarketArea != null)
                        {
                            int countMarketArea = Business.Market.MarketArea.Count;
                            for (int j = 0; j < countMarketArea; j++)
                            {
                                if (FlagType == false)
                                {
                                    if (Business.Market.MarketArea[j].Type != null)
                                    {
                                        int countTradeType = Business.Market.MarketArea[j].Type.Count;
                                        for (int n = 0; n < countTradeType; n++)
                                        {
                                            if (Business.Market.MarketArea[j].Type[n].ID == tbCommandHistory[i].CommandTypeID)
                                            {
                                                newOpenTrade.Type = Business.Market.MarketArea[j].Type[n];
                                                FlagType = true;
                                                break;
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    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].InvestorID == tbCommandHistory[i].InvestorID)
                                {
                                    newOpenTrade.Investor = Business.Market.InvestorList[m];
                                    break;
                                }
                            }
                        }
                        #endregion

                        newOpenTrade.OpenPrice = tbCommandHistory[i].OpenPrice;
                        newOpenTrade.OpenTime = tbCommandHistory[i].OpenTime;
                        newOpenTrade.Profit = tbCommandHistory[i].Profit;
                        newOpenTrade.Size = tbCommandHistory[i].Size;
                        newOpenTrade.StopLoss = tbCommandHistory[i].StopLoss;
                        newOpenTrade.Swap = tbCommandHistory[i].Swap;
                        newOpenTrade.Comment = tbCommandHistory[i].Comment;
                        newOpenTrade.Taxes = tbCommandHistory[i].Taxes;
                        newOpenTrade.AgentCommission = tbCommandHistory[i].AgentCommission;
                        newOpenTrade.TakeProfit = tbCommandHistory[i].TakeProfit;
                        newOpenTrade.IsStopLossAndTakeProfit = tbCommandHistory[i].IsStopLossTakeProfit;
                        newOpenTrade.IsActivePending = tbCommandHistory[i].IsActivePending;

                        #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].SymbolID == tbCommandHistory[i].SymbolID)
                                {
                                    newOpenTrade.Symbol = Business.Market.SymbolList[k];

                                    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, tbCommandHistory[i].SymbolID);
                                    }
                                }
                            }
                        }
                        #endregion

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

            return Result;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="numberGet"></param>
        /// <returns></returns>
        internal List<Business.OpenTrade> GetTopClosePosition(int numberGet, List<int> listInvestorID)
        {
            List<Business.OpenTrade> result = new List<Business.OpenTrade>();

            System.Data.SqlClient.SqlConnection conn = new SqlConnection(DBConnection.DBConnection.Connection);
            System.Data.SqlClient.SqlDataAdapter adap = new System.Data.SqlClient.SqlDataAdapter();
            DS.CommandHistoryDataTable tbCommandHistory = new DS.CommandHistoryDataTable();

            try
            {
                conn.Open();

                string strInvestor = string.Empty;
                if (listInvestorID != null && listInvestorID.Count > 0)
                {
                    int count = listInvestorID.Count;
                    for (int i = 0; i < count; i++)
                    {
                        if (i == count - 1)
                            strInvestor += listInvestorID[i];
                        else
                            strInvestor += listInvestorID[i] + ",";
                    }
                }

                string sql = "SELECT TOP(" + numberGet + ") * FROM CommandHistory WHERE (InvestorID IN(" + strInvestor + ")) AND " +
                    " CommandTypeID NOT IN(13, 14, 15, 16, 21, 3, 4, 7, 8, 9, 10) AND (IsDelete = 0) ORDER BY CloseTime DESC";
                adap.SelectCommand = new System.Data.SqlClient.SqlCommand(sql, conn);
                tbCommandHistory = new DS.CommandHistoryDataTable();
                adap.Fill(tbCommandHistory);

                if (tbCommandHistory != null)
                {
                    int count = tbCommandHistory.Count;
                    for (int i = 0; i < count; i++)
                    {
                        Business.OpenTrade newOpenTrade = new Business.OpenTrade();
                        newOpenTrade.ClientCode = tbCommandHistory[i].ClientCode;
                        newOpenTrade.ClosePrice = tbCommandHistory[i].ClosePrice;
                        newOpenTrade.CloseTime = tbCommandHistory[i].CloseTime;
                        newOpenTrade.CommandCode = tbCommandHistory[i].CommandCode;
                        newOpenTrade.Commission = tbCommandHistory[i].Commission;
                        newOpenTrade.ExpTime = tbCommandHistory[i].ExpTime;
                        newOpenTrade.ID = tbCommandHistory[i].CommandHistoryID;
                        //Investor

                        #region Find Trade Type In Market Area
                        //Find Trade Type
                        bool FlagType = false;
                        if (Business.Market.MarketArea != null)
                        {
                            int countMarketArea = Business.Market.MarketArea.Count;
                            for (int j = 0; j < countMarketArea; j++)
                            {
                                if (FlagType == false)
                                {
                                    if (Business.Market.MarketArea[j].Type != null)
                                    {
                                        int countTradeType = Business.Market.MarketArea[j].Type.Count;
                                        for (int n = 0; n < countTradeType; n++)
                                        {
                                            if (Business.Market.MarketArea[j].Type[n].ID == tbCommandHistory[i].CommandTypeID)
                                            {
                                                newOpenTrade.Type = Business.Market.MarketArea[j].Type[n];
                                                FlagType = true;
                                                break;
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    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].InvestorID == tbCommandHistory[i].InvestorID)
                                {
                                    newOpenTrade.Investor = Business.Market.InvestorList[m];
                                    break;
                                }
                            }
                        }
                        #endregion

                        newOpenTrade.OpenPrice = tbCommandHistory[i].OpenPrice;
                        newOpenTrade.OpenTime = tbCommandHistory[i].OpenTime;
                        newOpenTrade.Profit = tbCommandHistory[i].Profit;
                        newOpenTrade.Size = tbCommandHistory[i].Size;
                        newOpenTrade.StopLoss = tbCommandHistory[i].StopLoss;
                        newOpenTrade.Swap = tbCommandHistory[i].Swap;
                        newOpenTrade.TakeProfit = tbCommandHistory[i].TakeProfit;
                        newOpenTrade.Taxes = tbCommandHistory[i].Taxes;
                        newOpenTrade.Comment = tbCommandHistory[i].Comment;
                        newOpenTrade.AgentCommission = tbCommandHistory[i].AgentCommission;
                        newOpenTrade.IsActivePending = tbCommandHistory[i].IsActivePending;
                        newOpenTrade.IsStopLossAndTakeProfit = tbCommandHistory[i].IsStopLossTakeProfit;
                        newOpenTrade.IsClose = true;

                        #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 == tbCommandHistory[i].SymbolID)
                                {
                                    newOpenTrade.Symbol = Business.Market.SymbolList[k];
                                    Flag = true;
                                    break;
                                }

                                if (Flag == false)
                                {
                                    if (Business.Market.SymbolList[k].RefSymbol != null)
                                    {
                                        newOpenTrade.Symbol = this.FindSymbolReference(Business.Market.SymbolList[k].RefSymbol, newOpenTrade, tbCommandHistory[i].SymbolID);

                                        if (newOpenTrade.Symbol != null && newOpenTrade.Symbol.SymbolID > 0)
                                            break;
                                    }
                                }
                            }
                        }
                        #endregion

                        result.Add(newOpenTrade);
                    }
                }
            }
            catch (Exception ex)
            {
                result = null;
            }
            finally
            {
                adap.SelectCommand.Connection.Close();
                conn.Close();
            }

            return result;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="rowNumber"></param>
        /// <param name="from"></param>
        /// <returns></returns>
        internal List<Business.OpenTrade> GetAllHistoryStartEnd(int rowNumber, int from)
        {
            List<Business.OpenTrade> Result = new List<Business.OpenTrade>();
            System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(DBConnection.DBConnection.Connection);
            DSTableAdapters.CommandHistoryTableAdapter adap = new DSTableAdapters.CommandHistoryTableAdapter();
            DS.CommandHistoryDataTable tbCommandHistory = new DS.CommandHistoryDataTable();

            try
            {
                conn.Open();
                adap.Connection = conn;
                tbCommandHistory = adap.GetAllHistoryWithStartStop(rowNumber, from);

                if (tbCommandHistory != null)
                {
                    int count = tbCommandHistory.Count;
                    for (int i = 0; i < count; i++)
                    {
                        Business.OpenTrade newOpenTrade = new Business.OpenTrade();
                        newOpenTrade.AgentCommission = tbCommandHistory[i].AgentCommission;
                        newOpenTrade.ClientCode = tbCommandHistory[i].ClientCode;
                        newOpenTrade.ClosePrice = tbCommandHistory[i].ClosePrice;
                        newOpenTrade.CloseTime = tbCommandHistory[i].CloseTime;
                        newOpenTrade.CommandCode = tbCommandHistory[i].CommandCode;
                        newOpenTrade.Comment = tbCommandHistory[i].Comment;
                        newOpenTrade.Commission = tbCommandHistory[i].Commission;
                        newOpenTrade.ExpTime = tbCommandHistory[i].ExpTime;
                        newOpenTrade.ID = tbCommandHistory[i].CommandHistoryID;
                        newOpenTrade.IsClose = true;

                        if (Business.Market.InvestorList != null)
                        {
                            int countInvestor = Business.Market.InvestorList.Count;
                            for (int j = 0; j < countInvestor; j++)
                            {
                                if (Business.Market.InvestorList[j].InvestorID == tbCommandHistory[i].InvestorID)
                                {
                                    newOpenTrade.Investor = Business.Market.InvestorList[j];
                                    break;
                                }
                            }
                        }

                        newOpenTrade.OpenPrice = tbCommandHistory[i].OpenPrice;
                        newOpenTrade.OpenTime = tbCommandHistory[i].OpenTime;
                        newOpenTrade.Profit = tbCommandHistory[i].Profit;
                        newOpenTrade.Size = tbCommandHistory[i].Size;
                        newOpenTrade.StopLoss = tbCommandHistory[i].StopLoss;
                        newOpenTrade.Swap = tbCommandHistory[i].Swap;

                        if (Business.Market.SymbolList != null)
                        {
                            int countSymbol = Business.Market.SymbolList.Count;
                            for (int j = 0; j < countSymbol; j++)
                            {
                                if (Business.Market.SymbolList[j].SymbolID == tbCommandHistory[i].SymbolID)
                                {
                                    newOpenTrade.Symbol = Business.Market.SymbolList[j];
                                    break;
                                }
                            }
                        }

                        newOpenTrade.TakeProfit = tbCommandHistory[i].TakeProfit;
                        newOpenTrade.Taxes = tbCommandHistory[i].Taxes;
                        newOpenTrade.Comment = tbCommandHistory[i].Comment;
                        newOpenTrade.AgentCommission = tbCommandHistory[i].AgentCommission;

                        newOpenTrade.Type = new Business.TradeType();
                        newOpenTrade.Type.ID = tbCommandHistory[i].CommandTypeID;
                        newOpenTrade.Type.Name = TradingServer.Facade.FacadeGetTypeNameByTypeID(tbCommandHistory[i].CommandTypeID);
                        newOpenTrade.IsActivePending = tbCommandHistory[i].IsActivePending;
                        newOpenTrade.IsStopLossAndTakeProfit = tbCommandHistory[i].IsStopLossTakeProfit;

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

            return Result;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="commandTypeID"></param>
        /// <param name="dateTime"></param>
        /// <param name="investorID"></param>
        /// <returns></returns>
        internal Business.OpenTrade GetLastBalanceOfInvestor(int commandTypeID, DateTime dateTime, int investorID,DateTime timeEnd)
        {
            Business.OpenTrade result = new Business.OpenTrade();
            System.Data.SqlClient.SqlConnection conn = new SqlConnection(DBConnection.DBConnection.Connection);
            DSTableAdapters.CommandHistoryTableAdapter adap = new DSTableAdapters.CommandHistoryTableAdapter();
            DS.CommandHistoryDataTable tbCommandHistory = new DS.CommandHistoryDataTable();

            try
            {
                conn.Open();
                adap.Connection = conn;
                tbCommandHistory = adap.GetLastBalanceWithDateTime(commandTypeID, investorID, dateTime, timeEnd);

                if (tbCommandHistory != null)
                {
                    #region MAP LASS BALANCE OF INVESTOR
                    result.ClientCode = tbCommandHistory[0].ClientCode;
                    result.ClosePrice = tbCommandHistory[0].ClosePrice;
                    result.CloseTime = tbCommandHistory[0].CloseTime;
                    result.CommandCode = tbCommandHistory[0].CommandCode;
                    result.Commission = tbCommandHistory[0].Commission;
                    result.ExpTime = tbCommandHistory[0].ExpTime;
                    result.ID = tbCommandHistory[0].CommandHistoryID;
                    //Investor

                    result.Type = new Business.TradeType();

                    #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 == tbCommandHistory[0].InvestorID)
                            {
                                result.Investor = Business.Market.InvestorList[m];
                                break;
                            }
                        }
                    }
                    #endregion

                    result.OpenPrice = tbCommandHistory[0].OpenPrice;
                    result.OpenTime = tbCommandHistory[0].OpenTime;
                    result.Profit = tbCommandHistory[0].Profit;
                    result.Size = tbCommandHistory[0].Size;
                    result.StopLoss = tbCommandHistory[0].StopLoss;
                    result.Swap = tbCommandHistory[0].Swap;
                    result.Comment = tbCommandHistory[0].Comment;
                    result.Taxes = tbCommandHistory[0].Taxes;
                    result.AgentCommission = tbCommandHistory[0].AgentCommission;
                    result.TakeProfit = tbCommandHistory[0].TakeProfit;
                    result.IsActivePending = tbCommandHistory[0].IsActivePending;
                    result.IsStopLossAndTakeProfit = tbCommandHistory[0].IsStopLossTakeProfit;

                    #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].SymbolID == tbCommandHistory[0].SymbolID)
                            {
                                result.Symbol = Business.Market.SymbolList[k];

                                Flag = true;
                                break;
                            }
                        }
                    }
                    #endregion
                    #endregion
                }
            }
            catch (Exception ex)
            {
                return null;
            }
            finally
            {
                adap.Connection.Close();
                conn.Close();
            }

            return result;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="commandCode"></param>
        /// <returns></returns>
        internal Business.OpenTrade GetHistoryByCommandCode(string commandCode)
        {
            Business.OpenTrade result = new Business.OpenTrade();
            System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(DBConnection.DBConnection.Connection);
            DSTableAdapters.CommandHistoryTableAdapter adap = new DSTableAdapters.CommandHistoryTableAdapter();
            DS.CommandHistoryDataTable tbCommandHistory = new DS.CommandHistoryDataTable();

            try
            {
                conn.Open();
                adap.Connection = conn;
                tbCommandHistory = adap.GetHistoryByCommandCode(commandCode);

                if (tbCommandHistory != null)
                {
                    result.AgentCommission = tbCommandHistory[0].AgentCommission;
                    result.ClientCode = tbCommandHistory[0].ClientCode;
                    result.ClosePrice = tbCommandHistory[0].ClosePrice;
                    result.CloseTime = tbCommandHistory[0].CloseTime;
                    result.CommandCode = tbCommandHistory[0].CommandCode;
                    result.Comment = tbCommandHistory[0].Comment;
                    result.Commission = tbCommandHistory[0].Commission;
                    result.ExpTime = tbCommandHistory[0].ExpTime;
                    result.ID = tbCommandHistory[0].CommandHistoryID;
                    result.IsClose = true;

                    if (Business.Market.InvestorList != null)
                    {
                        int countInvestor = Business.Market.InvestorList.Count;
                        for (int j = 0; j < countInvestor; j++)
                        {
                            if (Business.Market.InvestorList[j].InvestorID == tbCommandHistory[0].InvestorID)
                            {
                                result.Investor = Business.Market.InvestorList[j];
                                break;
                            }
                        }
                    }

                    result.OpenPrice = tbCommandHistory[0].OpenPrice;
                    result.OpenTime = tbCommandHistory[0].OpenTime;
                    result.Profit = tbCommandHistory[0].Profit;
                    result.Size = tbCommandHistory[0].Size;
                    result.StopLoss = tbCommandHistory[0].StopLoss;
                    result.Swap = tbCommandHistory[0].Swap;

                    if (Business.Market.SymbolList != null)
                    {
                        int countSymbol = Business.Market.SymbolList.Count;
                        for (int j = 0; j < countSymbol; j++)
                        {
                            if (Business.Market.SymbolList[j].SymbolID == tbCommandHistory[0].SymbolID)
                            {
                                result.Symbol = Business.Market.SymbolList[j];
                                break;
                            }
                        }
                    }

                    result.TakeProfit = tbCommandHistory[0].TakeProfit;
                    result.Taxes = tbCommandHistory[0].Taxes;
                    result.Comment = tbCommandHistory[0].Comment;
                    result.AgentCommission = tbCommandHistory[0].AgentCommission;
                    result.IsActivePending = tbCommandHistory[0].IsActivePending;
                    result.IsStopLossAndTakeProfit = tbCommandHistory[0].IsStopLossTakeProfit;

                    if (Business.Market.MarketArea != null)
                    {
                        int countMarketArea = Business.Market.MarketArea.Count;
                        for (int j = 0; j < countMarketArea; j++)
                        {
                            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 == tbCommandHistory[0].CommandTypeID)
                                    {
                                        result.Type = Business.Market.MarketArea[j].Type[n];
                                        break;
                                    }
                                }
                            }
                        }
                    }

                    if (result.Type == null)
                    {
                        result.Type = new Business.TradeType();
                        result.Type.ID = tbCommandHistory[0].CommandTypeID;
                        result.Type.Name = TradingServer.Facade.FacadeGetTypeNameByTypeID(tbCommandHistory[0].CommandTypeID);
                    }
                }
            }
            catch (Exception ex)
            {
                return null;
            }
            finally
            {
                adap.Connection.Close();
                conn.Close();
            }

            return result;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="listInvestorID"></param>
        /// <returns></returns>
        internal Dictionary<int, double> GetDepositInvestor(List<int> listInvestorID)
        {
            Dictionary<int, double> result = new Dictionary<int, double>();

            System.Data.SqlClient.SqlConnection conn = new SqlConnection(DBConnection.DBConnection.Connection);
            DSTableAdapters.CommandHistoryTableAdapter adap = new DSTableAdapters.CommandHistoryTableAdapter();
            DS.CommandHistoryDataTable tbCommandHistory = new DS.CommandHistoryDataTable();

            try
            {
                conn.Open();
                adap.Connection = conn;
                if (listInvestorID != null)
                {
                    int count = listInvestorID.Count;
                    for (int i = 0; i < count; i++)
                    {
                        tbCommandHistory = adap.GetDepositByInvestorID(listInvestorID[i]);
                        if (tbCommandHistory != null)
                        {
                            int countHistory = tbCommandHistory.Count;
                            double deposit = 0;
                            for (int j = 0; j < countHistory; j++)
                            {
                                deposit += tbCommandHistory[j].Profit;
                            }

                            result.Add(listInvestorID[i], deposit);
                        }
                    }
                }
            }
            catch (Exception ex)
            {

            }
            finally
            {
                adap.Connection.Close();
                conn.Close();
            }

            return result;
        }
示例#10
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="InvestorID"></param>
        /// <param name="Start"></param>
        /// <param name="Limit"></param>
        /// <returns></returns>
        internal List<Business.OrderData> GetOrderByInvestorID(int InvestorID, int Start, int Limit)
        {
            List<Business.OrderData> Result = new List<Business.OrderData>();
            System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(DBConnection.DBConnection.Connection);
            DSTableAdapters.InvestorTableAdapter adapInvestor = new DSTableAdapters.InvestorTableAdapter();
            DSTableAdapters.OnlineCommandTableAdapter adapOpenTrade = new DSTableAdapters.OnlineCommandTableAdapter();
            DSTableAdapters.CommandHistoryTableAdapter adapHistory = new DSTableAdapters.CommandHistoryTableAdapter();
            DSTableAdapters.InvestorAccountLogTableAdapter adapAccountLog = new DSTableAdapters.InvestorAccountLogTableAdapter();

            DS.InvestorDataTable tbInvestor = new DS.InvestorDataTable();
            DS.OnlineCommandDataTable tbOnlineCommand = new DS.OnlineCommandDataTable();
            DS.CommandHistoryDataTable tbCommandHistory = new DS.CommandHistoryDataTable();
            DS.InvestorAccountLogDataTable tbInvestorAccountLog = new DS.InvestorAccountLogDataTable();

            try
            {
                conn.Open();
                adapInvestor.Connection = conn;
                adapOpenTrade.Connection = conn;
                adapHistory.Connection = conn;
                adapAccountLog.Connection = conn;

                tbOnlineCommand = adapOpenTrade.GetOpenTradeByInvestorID(Start, InvestorID, Limit);
                tbCommandHistory = adapHistory.GetHistoryByInvestorID(Start, InvestorID, Limit);
                tbInvestorAccountLog = adapAccountLog.GetInvestorLogByInvestorID(Start, InvestorID, Limit);

                if (tbOnlineCommand != null)
                {
                    int count = tbOnlineCommand.Count;
                    for (int i = 0; i < count; i++)
                    {
                        Business.OrderData newOrderData = new Business.OrderData();
                        newOrderData.OrderCode = "OPT001";
                        newOrderData.Code = tbOnlineCommand[i].CommandCode;
                        newOrderData.ID = tbOnlineCommand[i].OnlineCommandID;

                        tbInvestor = adapInvestor.GetInvestorNameByInvestorID(tbOnlineCommand[i].InvestorID);
                        if (tbInvestor != null)
                            newOrderData.Login = tbInvestor[0].Code;

                        newOrderData.InvestorID = tbOnlineCommand[i].InvestorID;
                        newOrderData.AgentCommission = 0;
                        newOrderData.ClosePrice = tbOnlineCommand[i].ClosePrice;
                        newOrderData.CloseTime = tbOnlineCommand[i].CloseTime;
                        //newOrderData.Comment = tbOnlineCommand[i]
                        newOrderData.Commission = tbOnlineCommand[i].Commission;
                        newOrderData.ExpDate = tbOnlineCommand[i].ExpTime;
                        newOrderData.Lots = tbOnlineCommand[i].Size;
                        //newOrderData.MarginRate =
                        //newOrderData.OneConvRate
                        newOrderData.OpenPrice = tbOnlineCommand[i].OpenPrice;
                        newOrderData.OpenTime = tbOnlineCommand[i].OpenTime;
                        newOrderData.Profit = tbOnlineCommand[i].Profit;
                        newOrderData.StopLoss = tbOnlineCommand[i].StopLoss;
                        newOrderData.Swaps = tbOnlineCommand[i].Swap;
                        newOrderData.Symbol = TradingServer.Facade.FacadeGetSymbolNameBySymbolID(tbOnlineCommand[i].SymbolID);
                        newOrderData.TakeProfit = tbOnlineCommand[i].TakeProfit;
                        newOrderData.Taxes = tbOnlineCommand[i].Taxes;
                        //newOrderData.TwoConvRate
                        newOrderData.Type = TradingServer.Facade.FacadeGetTypeNameByTypeID(tbOnlineCommand[i].CommandTypeID);
                        //newOrderData.ValueDate

                        Result.Add(newOrderData);
                    }
                }

                if (tbCommandHistory != null)
                {
                    int count = tbCommandHistory.Count;
                    for (int i = 0; i < count; i++)
                    {
                        Business.OrderData newOrderData = new Business.OrderData();
                        newOrderData.OrderCode = "CMH01";

                        newOrderData.Code = tbCommandHistory[i].CommandCode;
                        newOrderData.ID = tbCommandHistory[i].CommandHistoryID;

                        tbInvestor = adapInvestor.GetInvestorNameByInvestorID(tbCommandHistory[i].InvestorID);
                        if (tbInvestor != null)
                            newOrderData.Login = tbInvestor[0].Code;

                        newOrderData.InvestorID = tbCommandHistory[i].InvestorID;
                        newOrderData.AgentCommission = 0;
                        newOrderData.ClosePrice = tbCommandHistory[i].ClosePrice;
                        newOrderData.CloseTime = tbCommandHistory[i].CloseTime;
                        //newOrderData.Code = tbOnlineCommand[i].inves
                        //newOrderData.Comment = tbOnlineCommand[i]
                        newOrderData.Commission = tbCommandHistory[i].Commission;
                        newOrderData.ExpDate = tbCommandHistory[i].ExpTime;
                        newOrderData.Lots = tbCommandHistory[i].Size;
                        //newOrderData.MarginRate =
                        //newOrderData.OneConvRate
                        newOrderData.OpenPrice = tbCommandHistory[i].OpenPrice;
                        newOrderData.OpenTime = tbCommandHistory[i].OpenTime;
                        newOrderData.Profit = tbCommandHistory[i].Profit;
                        newOrderData.StopLoss = tbCommandHistory[i].StopLoss;
                        newOrderData.Swaps = tbCommandHistory[i].Swap;
                        newOrderData.Symbol = TradingServer.Facade.FacadeGetSymbolNameBySymbolID(tbCommandHistory[i].SymbolID);
                        newOrderData.TakeProfit = tbCommandHistory[i].TakeProfit;
                        newOrderData.Taxes = tbCommandHistory[i].Taxes;
                        //newOrderData.TwoConvRate
                        switch (tbCommandHistory[i].CommandTypeID)
                        {
                            case 13:
                                {
                                    newOrderData.Type = "ADP01";
                                }
                                break;
                            case 14:
                                {
                                    newOrderData.Type = "WRD01";
                                }
                                break;
                            case 15:
                                {
                                    newOrderData.Type = "ACD01";
                                }
                                break;
                            case 16:
                                {
                                    newOrderData.Type = "CRD01";
                                }
                                break;
                            default:
                                {
                                    newOrderData.Type = TradingServer.Facade.FacadeGetTypeNameByTypeID(tbCommandHistory[i].CommandTypeID);
                                }
                                break;
                        }
                        //newOrderData.Type = TradingServer.Facade.FacadeGetTypeNameByTypeID(tbCommandHistory[i].CommandTypeID);
                        //newOrderData.ValueDate

                        Result.Add(newOrderData);
                    }
                }

                if (tbInvestorAccountLog != null)
                {
                    int count = tbInvestorAccountLog.Count;
                    for (int i = 0; i < count; i++)
                    {
                        Business.OrderData newOrderData = new Business.OrderData();
                        newOrderData.OrderCode = "IAL01";
                        newOrderData.Code = tbInvestorAccountLog[i].DealID;
                        newOrderData.ID = tbInvestorAccountLog[i].ID;

                        tbInvestor = adapInvestor.GetInvestorNameByInvestorID(tbInvestorAccountLog[i].InvestorID);
                        if (tbInvestor != null)
                            newOrderData.Login = tbInvestor[0].Code;

                        newOrderData.InvestorID = tbInvestorAccountLog[i].InvestorID;
                        //newOrderData.AgentCommission = 0;
                        //newOrderData.ClosePrice = tbCommandHistory[i].ClosePrice;
                        //newOrderData.CloseTime = tbCommandHistory[i].CloseTime;
                        //newOrderData.Code = tbOnlineCommand[i].inves
                        //newOrderData.Comment = tbOnlineCommand[i]
                        //newOrderData.Commission = tbCommandHistory[i].Commission;
                        //newOrderData.ExpDate = tbCommandHistory[i].ExpTime;
                        //newOrderData.Lots = tbCommandHistory[i].Size;
                        //newOrderData.MarginRate =
                        //newOrderData.OneConvRate
                        //newOrderData.OpenPrice = tbCommandHistory[i].OpenPrice;
                        newOrderData.OpenTime = tbInvestorAccountLog[i].Date;
                        //newOrderData.Profit = tbCommandHistory[i].Profit;
                        //newOrderData.StopLoss = tbCommandHistory[i].StopLoss;
                        //newOrderData.Swaps = tbCommandHistory[i].Swap;
                        //newOrderData.Symbol = TradingServer.Facade.FacadeGetSymbolNameBySymbolID(tbCommandHistory[i].SymbolID);
                        //newOrderData.TakeProfit = tbCommandHistory[i].TakeProfit;
                        //newOrderData.Taxes = tbCommandHistory[i].Taxes;
                        //newOrderData.TwoConvRate
                        newOrderData.Type = tbInvestorAccountLog[i].Code;
                        newOrderData.Comment = tbInvestorAccountLog[i].Comment;
                        newOrderData.Profit = tbInvestorAccountLog[i].Amount;
                        //newOrderData.ValueDate

                        Result.Add(newOrderData);
                    }
                }
            }
            catch (Exception ex)
            {
                return null;
            }
            finally
            {
                adapInvestor.Connection.Close();
                adapOpenTrade.Connection.Close();
                adapHistory.Connection.Close();
                adapAccountLog.Connection.Close();
                conn.Close();
            }

            return Result;
        }
示例#11
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="Code"></param>
        /// <returns></returns>
        internal Business.OrderData GetOrderByCode(string Code)
        {
            Business.OrderData Result = new Business.OrderData();
            System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(DBConnection.DBConnection.Connection);
            DSTableAdapters.OnlineCommandTableAdapter adapOnlineCommand = new DSTableAdapters.OnlineCommandTableAdapter();
            DSTableAdapters.CommandHistoryTableAdapter adapCommandHistory = new DSTableAdapters.CommandHistoryTableAdapter();
            DSTableAdapters.InvestorAccountLogTableAdapter adapAccountLog = new DSTableAdapters.InvestorAccountLogTableAdapter();
            DSTableAdapters.InvestorTableAdapter adapInvestor = new DSTableAdapters.InvestorTableAdapter();

            DS.OnlineCommandDataTable tbOnlineCommand = new DS.OnlineCommandDataTable();
            DS.CommandHistoryDataTable tbCommandHistory = new DS.CommandHistoryDataTable();
            DS.InvestorAccountLogDataTable tbAccountLog = new DS.InvestorAccountLogDataTable();
            DS.InvestorDataTable tbInvestor = new DS.InvestorDataTable();

            try
            {
                bool flag = false;
                conn.Open();
                adapAccountLog.Connection = conn;
                adapCommandHistory.Connection = conn;
                adapOnlineCommand.Connection = conn;
                adapInvestor.Connection = conn;

                tbOnlineCommand = adapOnlineCommand.GetOnlineCommandByCommandCode(Code);
                if (tbOnlineCommand != null && tbOnlineCommand.Count > 0)
                {
                    Result.OrderCode = "OPT001";
                    Result.Code = tbOnlineCommand[0].CommandCode;

                    tbInvestor = adapInvestor.GetInvestorNameByInvestorID(tbOnlineCommand[0].InvestorID);
                    if (tbInvestor != null)
                        Result.Login = tbInvestor[0].Code;

                    Result.InvestorID = tbOnlineCommand[0].InvestorID;
                    Result.AgentCommission = 0;
                    Result.ClosePrice = tbOnlineCommand[0].ClosePrice;
                    Result.CloseTime = tbOnlineCommand[0].CloseTime;
                    //newOrderData.Comment = tbOnlineCommand[i]
                    Result.Commission = tbOnlineCommand[0].Commission;
                    Result.ExpDate = tbOnlineCommand[0].ExpTime;
                    Result.Lots = tbOnlineCommand[0].Size;
                    //newOrderData.MarginRate =
                    //newOrderData.OneConvRate
                    Result.OpenPrice = tbOnlineCommand[0].OpenPrice;
                    Result.OpenTime = tbOnlineCommand[0].OpenTime;
                    Result.Profit = tbOnlineCommand[0].Profit;
                    Result.StopLoss = tbOnlineCommand[0].StopLoss;
                    Result.Swaps = tbOnlineCommand[0].Swap;
                    Result.Symbol = TradingServer.Facade.FacadeGetSymbolNameBySymbolID(tbOnlineCommand[0].SymbolID);
                    Result.TakeProfit = tbOnlineCommand[0].TakeProfit;
                    Result.Taxes = tbOnlineCommand[0].Taxes;
                    //newOrderData.TwoConvRate
                    Result.Type = TradingServer.Facade.FacadeGetTypeNameByTypeID(tbOnlineCommand[0].CommandTypeID);
                    //newOrderData.ValueDate
                    flag = true;
                }

                if (!flag)
                {
                    tbCommandHistory = adapCommandHistory.GetCommandHistoryByCommandCode(Code);
                    if (tbCommandHistory != null && tbCommandHistory.Count > 0)
                    {
                        Result.OrderCode = "CMH01";
                        Result.Code = tbCommandHistory[0].CommandCode;

                        tbInvestor = adapInvestor.GetInvestorNameByInvestorID(tbCommandHistory[0].InvestorID);
                        if (tbInvestor != null)
                            Result.Login = tbInvestor[0].Code;

                        Result.InvestorID = tbCommandHistory[0].InvestorID;
                        Result.AgentCommission = 0;
                        Result.ClosePrice = tbCommandHistory[0].ClosePrice;
                        Result.CloseTime = tbCommandHistory[0].CloseTime;
                        //newOrderData.Code = tbOnlineCommand[i].inves
                        //newOrderData.Comment = tbOnlineCommand[i]
                        Result.Commission = tbCommandHistory[0].Commission;
                        Result.ExpDate = tbCommandHistory[0].ExpTime;
                        Result.Lots = tbCommandHistory[0].Size;
                        //newOrderData.MarginRate =
                        //newOrderData.OneConvRate
                        Result.OpenPrice = tbCommandHistory[0].OpenPrice;
                        Result.OpenTime = tbCommandHistory[0].OpenTime;
                        Result.Profit = tbCommandHistory[0].Profit;
                        Result.StopLoss = tbCommandHistory[0].StopLoss;
                        Result.Swaps = tbCommandHistory[0].Swap;
                        Result.Symbol = TradingServer.Facade.FacadeGetSymbolNameBySymbolID(tbCommandHistory[0].SymbolID);
                        Result.TakeProfit = tbCommandHistory[0].TakeProfit;
                        Result.Taxes = tbCommandHistory[0].Taxes;
                        //newOrderData.TwoConvRate
                        Result.Type = TradingServer.Facade.FacadeGetTypeNameByTypeID(tbCommandHistory[0].CommandTypeID);
                        //newOrderData.ValueDate

                        flag = true;
                    }
                }

                if (!flag)
                {
                    tbAccountLog = adapAccountLog.GetInvestorAccountLogByCode(Code);
                    if (tbAccountLog != null && tbAccountLog.Count > 0)
                    {
                        Result.OrderCode = "IAL01";
                        Result.Code = tbAccountLog[0].DealID;

                        tbInvestor = adapInvestor.GetInvestorNameByInvestorID(tbAccountLog[0].InvestorID);
                        if (tbInvestor != null)
                            Result.Login = tbInvestor[0].Code;

                        Result.InvestorID = tbAccountLog[0].InvestorID;
                        //newOrderData.AgentCommission = 0;
                        //newOrderData.ClosePrice = tbCommandHistory[i].ClosePrice;
                        //newOrderData.CloseTime = tbCommandHistory[i].CloseTime;
                        //newOrderData.Code = tbOnlineCommand[i].inves
                        //newOrderData.Comment = tbOnlineCommand[i]
                        //newOrderData.Commission = tbCommandHistory[i].Commission;
                        //newOrderData.ExpDate = tbCommandHistory[i].ExpTime;
                        //newOrderData.Lots = tbCommandHistory[i].Size;
                        //newOrderData.MarginRate =
                        //newOrderData.OneConvRate
                        //newOrderData.OpenPrice = tbCommandHistory[i].OpenPrice;
                        Result.OpenTime = tbAccountLog[0].Date;
                        //newOrderData.Profit = tbCommandHistory[i].Profit;
                        //newOrderData.StopLoss = tbCommandHistory[i].StopLoss;
                        //newOrderData.Swaps = tbCommandHistory[i].Swap;
                        //newOrderData.Symbol = TradingServer.Facade.FacadeGetSymbolNameBySymbolID(tbCommandHistory[i].SymbolID);
                        //newOrderData.TakeProfit = tbCommandHistory[i].TakeProfit;
                        //newOrderData.Taxes = tbCommandHistory[i].Taxes;
                        //newOrderData.TwoConvRate
                        Result.Type = tbAccountLog[0].Code;
                        Result.Comment = tbAccountLog[0].Comment;
                        Result.Profit = tbAccountLog[0].Amount;
                    }
                }
            }
            catch (Exception ex)
            {
                return null;
            }
            finally
            {
                adapAccountLog.Connection.Close();
                adapCommandHistory.Connection.Close();
                adapInvestor.Connection.Close();
                adapOnlineCommand.Connection.Close();
                conn.Close();
            }

            return Result;
        }