public static StockSymbol_FullDynamicData GetCurrentData(TradeCenter tradeCenter, string symbols, int full)
            {
                StockSymbol_FullDynamicData currentData = new StockSymbol_FullDynamicData();
                try
                {
                    bool isHOChange = false, isHAChange = false;
                    int currentHOChangeId = full, currentHAChangeId = full;

                    GetDatabaseState(ref currentHOChangeId, ref currentHAChangeId, ref isHOChange, ref isHAChange);

                    if (tradeCenter == TradeCenter.HoSE)
                    {
                        #region Lay du lieu HoSE
                        DataTable dtPriceData = new DataTable();
                        if (symbols != "" && (isHOChange || full == -1)) dtPriceData = GetHOSEDatatable_MemCache(symbols, (full == -1));

                        DataTable dtIndexData = new DataTable();
                        dtIndexData = GetHOSEIndexDatatable_MemCache();

                        currentData.ChangeId = currentHOChangeId;

                        #region Index
                        currentData.SessionId = 0;
                        currentData.Indexs = new IndexItem[3];

                        if (dtIndexData.Rows.Count > 0)
                        {
                            #region Xác định phiên
                            if (Lib.FormatDouble(dtIndexData.Rows[0]["Index3"]) != "0") // Phiên 3
                            {
                                currentData.SessionId = 3;
                            }
                            else if (Lib.FormatDouble(dtIndexData.Rows[0]["Index2"]) != "0") // Phiên 2
                            {
                                currentData.SessionId = 2;
                            }
                            else if (Lib.FormatDouble(dtIndexData.Rows[0]["Index1"]) != "0") // Phiên 1
                            {
                                currentData.SessionId = 1;
                            }
                            #endregion

                            currentData.PreviousIndex = Lib.FormatDouble(dtIndexData.Rows[0]["PrevIndex"]);

                            currentData.Indexs[0].Index = Lib.FormatDouble(dtIndexData.Rows[0]["Index1"]);
                            currentData.Indexs[0].Quantity = Lib.FormatDouble(dtIndexData.Rows[0]["Quantity1"]);
                            currentData.Indexs[0].Volume = Lib.FormatDouble(dtIndexData.Rows[0]["Vol1"]);
                            currentData.Indexs[0].Value = Lib.FormatDouble(dtIndexData.Rows[0]["Value1"]);

                            currentData.Indexs[1].Index = Lib.FormatDouble(dtIndexData.Rows[0]["Index2"]);
                            currentData.Indexs[1].Quantity = Lib.FormatDouble(dtIndexData.Rows[0]["Quantity2"]);
                            currentData.Indexs[1].Volume = Lib.FormatDouble(dtIndexData.Rows[0]["Vol2"]);
                            currentData.Indexs[1].Value = Lib.FormatDouble(dtIndexData.Rows[0]["Value2"]);

                            currentData.Indexs[2].Index = Lib.FormatDouble(dtIndexData.Rows[0]["Index3"]);
                            currentData.Indexs[2].Quantity = Lib.FormatDouble(dtIndexData.Rows[0]["Quantity3"]);
                            currentData.Indexs[2].Volume = Lib.FormatDouble(dtIndexData.Rows[0]["Vol3"]);
                            currentData.Indexs[2].Value = Lib.FormatDouble(dtIndexData.Rows[0]["Value3"]);
                        }
                        else
                        {
                            currentData.PreviousIndex = "0";

                            currentData.Indexs[0].Index = "0";
                            currentData.Indexs[0].Quantity = "0";
                            currentData.Indexs[0].Volume = "0";
                            currentData.Indexs[0].Value = "0";

                            currentData.Indexs[1].Index = "0";
                            currentData.Indexs[1].Quantity = "0";
                            currentData.Indexs[1].Volume = "0";
                            currentData.Indexs[1].Value = "0";

                            currentData.Indexs[2].Index = "0";
                            currentData.Indexs[2].Quantity = "0";
                            currentData.Indexs[2].Volume = "0";
                            currentData.Indexs[2].Value = "0";
                        }
                        #endregion

                        #region Thông tin giá hiện tại
                        List<SymbolItem> items = new List<SymbolItem>();
                        foreach (DataRow drPriceData in dtPriceData.Rows)
                        {
                            SymbolItem symbol = new SymbolItem();

                            symbol.Symbol = drPriceData["Symbol"].ToString();

                            symbol.Datas = new string[22];

                            symbol.Datas[(int)HoSE_FieldName.Ref] = Lib.FormatDouble(drPriceData["Ref"]);
                            symbol.Datas[(int)HoSE_FieldName.Cei] = Lib.FormatDouble(drPriceData["Ceiling"]);
                            symbol.Datas[(int)HoSE_FieldName.Flo] = Lib.FormatDouble(drPriceData["Floor"]);

                            symbol.Datas[(int)HoSE_FieldName.TraP] = FormatPrice(drPriceData["TradingPrice"], drPriceData["Ceiling"], drPriceData["Floor"], drPriceData["Ref"]);
                            symbol.Datas[(int)HoSE_FieldName.TraV] = FormatVolume(drPriceData["TradingVol"], drPriceData["TradingPrice"], drPriceData["Ceiling"], drPriceData["Floor"], drPriceData["Ref"]);

                            string BidPrice1 = (drPriceData["BidPrice1"] == null ? "" : drPriceData["BidPrice1"].ToString());
                            string BidVol1 = (drPriceData["BidVol1"] == null ? "" : drPriceData["BidVol1"].ToString());
                            if (BidPrice1 == "" || BidPrice1 == "0")
                            {
                                if (BidVol1 == "" || BidVol1 == "0")
                                {
                                    BidPrice1 = "";
                                }
                                else
                                {
                                    if (currentData.SessionId == 1)
                                    {
                                        BidPrice1 = "ATO";
                                    }
                                    else if (currentData.SessionId == 3)
                                    {
                                        BidPrice1 = "ATC";
                                    }
                                    else
                                    {
                                        BidPrice1 = "";
                                    }
                                }
                            }
                            else
                            {
                                BidPrice1 = drPriceData["BidPrice1"].ToString();
                            }

                            symbol.Datas[(int)HoSE_FieldName.BidP1] = FormatPrice(BidPrice1, drPriceData["Ceiling"], drPriceData["Floor"], drPriceData["Ref"]);
                            symbol.Datas[(int)HoSE_FieldName.BidV1] = FormatVolume(drPriceData["BidVol1"], BidPrice1, drPriceData["Ceiling"], drPriceData["Floor"], drPriceData["Ref"]);
                            symbol.Datas[(int)HoSE_FieldName.BidP2] = FormatPrice(drPriceData["BidPrice2"], drPriceData["Ceiling"], drPriceData["Floor"], drPriceData["Ref"]);
                            symbol.Datas[(int)HoSE_FieldName.BidV2] = FormatVolume(drPriceData["BidVol2"], drPriceData["BidPrice2"], drPriceData["Ceiling"], drPriceData["Floor"], drPriceData["Ref"]);
                            symbol.Datas[(int)HoSE_FieldName.BidP3] = FormatPrice(drPriceData["BidPrice3"], drPriceData["Ceiling"], drPriceData["Floor"], drPriceData["Ref"]);
                            symbol.Datas[(int)HoSE_FieldName.BidV3] = FormatVolume(drPriceData["BidVol3"], drPriceData["BidPrice3"], drPriceData["Ceiling"], drPriceData["Floor"], drPriceData["Ref"]);

                            string SellPrice1 = (drPriceData["SellPrice1"] == null ? "" : drPriceData["SellPrice1"].ToString());
                            string SellVol1 = (drPriceData["SellVol1"] == null ? "" : drPriceData["SellVol1"].ToString());
                            if (SellPrice1 == "" || SellPrice1 == "0")
                            {
                                if (SellVol1 == "" || SellVol1 == "0")
                                {
                                    SellPrice1 = "";
                                }
                                else
                                {
                                    if (currentData.SessionId == 1)
                                    {
                                        SellPrice1 = "ATO";
                                    }
                                    else if (currentData.SessionId == 3)
                                    {
                                        SellPrice1 = "ATC";
                                    }
                                    else
                                    {
                                        SellPrice1 = "";
                                    }
                                }
                            }
                            else
                            {
                                SellPrice1 = drPriceData["SellPrice1"].ToString();
                            }

                            symbol.Datas[(int)HoSE_FieldName.SelP1] = FormatPrice(SellPrice1, drPriceData["Ceiling"], drPriceData["Floor"], drPriceData["Ref"]);
                            symbol.Datas[(int)HoSE_FieldName.SelV1] = FormatVolume(drPriceData["SellVol1"], SellPrice1, drPriceData["Ceiling"], drPriceData["Floor"], drPriceData["Ref"]);
                            symbol.Datas[(int)HoSE_FieldName.SelP2] = FormatPrice(drPriceData["SellPrice2"], drPriceData["Ceiling"], drPriceData["Floor"], drPriceData["Ref"]);
                            symbol.Datas[(int)HoSE_FieldName.SelV2] = FormatVolume(drPriceData["SellVol2"], drPriceData["SellPrice2"], drPriceData["Ceiling"], drPriceData["Floor"], drPriceData["Ref"]);
                            symbol.Datas[(int)HoSE_FieldName.SelP3] = FormatPrice(drPriceData["SellPrice3"], drPriceData["Ceiling"], drPriceData["Floor"], drPriceData["Ref"]);
                            symbol.Datas[(int)HoSE_FieldName.SelV3] = FormatVolume(drPriceData["SellVol3"], drPriceData["SellPrice3"], drPriceData["Ceiling"], drPriceData["Floor"], drPriceData["Ref"]);

                            symbol.Datas[(int)HoSE_FieldName.Pri1] = FormatPrice(drPriceData["TradingPrice1"], drPriceData["Ceiling"], drPriceData["Floor"], drPriceData["Ref"]);

                            symbol.Datas[(int)HoSE_FieldName.Max] = FormatPrice(drPriceData["TradingPriceMax"], drPriceData["Ceiling"], drPriceData["Floor"], drPriceData["Ref"]);
                            symbol.Datas[(int)HoSE_FieldName.Min] = FormatPrice(drPriceData["TradingPriceMin"], drPriceData["Ceiling"], drPriceData["Floor"], drPriceData["Ref"]);

                            FormatChangeValue(out symbol.Datas[(int)HoSE_FieldName.Chg], out symbol.Datas[(int)HoSE_FieldName.Img], drPriceData["TradingPrice"], drPriceData["Ceiling"], drPriceData["Floor"], drPriceData["Ref"]);

                            items.Add(symbol);
                        }
                        currentData.Symbols = items.ToArray();
                        #endregion
                        dtIndexData.Dispose();
                        dtPriceData.Dispose();
                        #endregion
                    }
                    else
                    {
                        #region Lay du lieu HaSTC
                        DataTable dtPriceData = new DataTable();
                        if (symbols != "" && (isHAChange || full == -1)) dtPriceData = GetHASTCDatatable_MemCache(symbols, (full == -1));

                        DataTable dtIndexData = new DataTable();
                        dtIndexData = GetHASTCIndexDatatable_MemCache();

                        currentData.ChangeId = currentHAChangeId;

                        #region Index
                        currentData.SessionId = 0;
                        currentData.Indexs = new IndexItem[1];

                        if (dtIndexData.Rows.Count > 0)
                        {
                            currentData.PreviousIndex = Lib.FormatDouble(dtIndexData.Rows[0]["PrevIndex"]);

                            currentData.Indexs[0].Index = Lib.FormatDouble(dtIndexData.Rows[0]["Index"]);
                            currentData.Indexs[0].Quantity = Lib.FormatDouble(dtIndexData.Rows[0]["Quantity"]);
                            currentData.Indexs[0].Volume = Lib.FormatDouble(dtIndexData.Rows[0]["Vol"]);
                            currentData.Indexs[0].Value = Lib.FormatDouble(dtIndexData.Rows[0]["Value"]);
                        }
                        else
                        {
                            currentData.PreviousIndex = "0";

                            currentData.Indexs[0].Index = "0";
                            currentData.Indexs[0].Quantity = "0";
                            currentData.Indexs[0].Volume = "0";
                            currentData.Indexs[0].Value = "0";
                        }
                        #endregion

                        #region Thông tin giá hiện tại
                        List<SymbolItem> items = new List<SymbolItem>();
                        foreach (DataRow drPriceData in dtPriceData.Rows)
                        {
                            SymbolItem symbol = new SymbolItem();

                            symbol.Symbol = drPriceData["Symbol"].ToString();

                            symbol.Datas = new string[22];

                            symbol.Datas[(int)HaSTC_FieldName.Ref] = Lib.FormatDouble(drPriceData["Ref"]);
                            symbol.Datas[(int)HaSTC_FieldName.Cei] = Lib.FormatDouble(drPriceData["Ceiling"]);
                            symbol.Datas[(int)HaSTC_FieldName.Flo] = Lib.FormatDouble(drPriceData["Floor"]);

                            symbol.Datas[(int)HaSTC_FieldName.TraP] = FormatPrice(drPriceData["TradingPrice"], drPriceData["Ceiling"], drPriceData["Floor"], drPriceData["Ref"]);
                            symbol.Datas[(int)HaSTC_FieldName.TraV] = FormatVolume(drPriceData["TradingVol"], drPriceData["TradingPrice"], drPriceData["Ceiling"], drPriceData["Floor"], drPriceData["Ref"]);

                            symbol.Datas[(int)HaSTC_FieldName.BidP1] = FormatPrice(drPriceData["BidPrice1"], drPriceData["Ceiling"], drPriceData["Floor"], drPriceData["Ref"]);
                            symbol.Datas[(int)HaSTC_FieldName.BidV1] = FormatVolume(drPriceData["BidVol1"], drPriceData["BidPrice1"], drPriceData["Ceiling"], drPriceData["Floor"], drPriceData["Ref"]);
                            symbol.Datas[(int)HaSTC_FieldName.BidP2] = FormatPrice(drPriceData["BidPrice2"], drPriceData["Ceiling"], drPriceData["Floor"], drPriceData["Ref"]);
                            symbol.Datas[(int)HaSTC_FieldName.BidV2] = FormatVolume(drPriceData["BidVol2"], drPriceData["BidPrice2"], drPriceData["Ceiling"], drPriceData["Floor"], drPriceData["Ref"]);
                            symbol.Datas[(int)HaSTC_FieldName.BidP3] = FormatPrice(drPriceData["BidPrice3"], drPriceData["Ceiling"], drPriceData["Floor"], drPriceData["Ref"]);
                            symbol.Datas[(int)HaSTC_FieldName.BidV3] = FormatVolume(drPriceData["BidVol3"], drPriceData["BidPrice3"], drPriceData["Ceiling"], drPriceData["Floor"], drPriceData["Ref"]);

                            symbol.Datas[(int)HaSTC_FieldName.SelP1] = FormatPrice(drPriceData["SellPrice1"], drPriceData["Ceiling"], drPriceData["Floor"], drPriceData["Ref"]);
                            symbol.Datas[(int)HaSTC_FieldName.SelV1] = FormatVolume(drPriceData["SellVol1"], drPriceData["SellPrice1"], drPriceData["Ceiling"], drPriceData["Floor"], drPriceData["Ref"]);
                            symbol.Datas[(int)HaSTC_FieldName.SelP2] = FormatPrice(drPriceData["SellPrice2"], drPriceData["Ceiling"], drPriceData["Floor"], drPriceData["Ref"]);
                            symbol.Datas[(int)HaSTC_FieldName.SelV2] = FormatVolume(drPriceData["SellVol2"], drPriceData["SellPrice2"], drPriceData["Ceiling"], drPriceData["Floor"], drPriceData["Ref"]);
                            symbol.Datas[(int)HaSTC_FieldName.SelP3] = FormatPrice(drPriceData["SellPrice3"], drPriceData["Ceiling"], drPriceData["Floor"], drPriceData["Ref"]);
                            symbol.Datas[(int)HaSTC_FieldName.SelV3] = FormatVolume(drPriceData["SellVol3"], drPriceData["SellPrice3"], drPriceData["Ceiling"], drPriceData["Floor"], drPriceData["Ref"]);

                            symbol.Datas[(int)HaSTC_FieldName.TTV] = Lib.FormatDouble(drPriceData["TotalTradingVolume"]);

                            symbol.Datas[(int)HaSTC_FieldName.Max] = FormatPrice(drPriceData["TradingPriceMax"], drPriceData["Ceiling"], drPriceData["Floor"], drPriceData["Ref"]);
                            symbol.Datas[(int)HaSTC_FieldName.Min] = FormatPrice(drPriceData["TradingPriceMin"], drPriceData["Ceiling"], drPriceData["Floor"], drPriceData["Ref"]);

                            FormatChangeValue(out symbol.Datas[(int)HaSTC_FieldName.Chg], out symbol.Datas[(int)HaSTC_FieldName.Img], drPriceData["TradingPrice"], drPriceData["Ceiling"], drPriceData["Floor"], drPriceData["Ref"]);

                            items.Add(symbol);
                        }
                        currentData.Symbols = items.ToArray();
                        #endregion
                        dtIndexData.Dispose();
                        dtPriceData.Dispose();
                        #endregion
                    }
                }
                catch (Exception ex)
                {
                    Lib.WriteLog(ex);
                }
                return currentData;
            }
            public static StockSymbol_DynamicData GetTop10Symbols(TopSymbolBy type, TradeCenter tradeCenter, params string[] fields)
            {
                StockSymbol_DynamicData currentData = new StockSymbol_DynamicData();

                //string cacheName = "";
                //if (type == TopSymbolBy.TopUp)
                //{
                //    cacheName = (tradeCenter == TradeCenter.AllTradeCenter ? "MemCached_Top10_Tang_All" : (tradeCenter == TradeCenter.HaSTC ? "MemCached_Top10_Tang_HaSTC" : "MemCached_Top10_Tang_HoSE"));
                //}
                //else if (type == TopSymbolBy.TopDown)
                //{
                //    cacheName = (tradeCenter == TradeCenter.AllTradeCenter ? "MemCached_Top10_Giam_All" : (tradeCenter == TradeCenter.HaSTC ? "MemCached_Top10_Giam_HaSTC" : "MemCached_Top10_Giam_HoSE"));
                //}
                //else
                //{
                //    cacheName = (tradeCenter == TradeCenter.AllTradeCenter ? "MemCached_Top10_KhoiLuong_All" : (tradeCenter == TradeCenter.HaSTC ? "MemCached_Top10_KhoiLuong_HaSTC" : "MemCached_Top10_KhoiLuong_HoSE"));
                //}

                //DataTable dtStockList = GetDataTable(cacheName);
                //var dtStockList = new DataTable();
                List<SymbolItem> items = new List<SymbolItem>();
                #region Get From WebService
                //if (dtStockList == null || dtStockList.Rows.Count == 0)
                //{
                    //CafeF_DataService.CafeF_DataService dataServices = new CafeF_EmbedData.CafeF_DataService.CafeF_DataService();
                    //WServices.Function dataServices = new WServices.Function();
                    var key = "";
                    switch (type)
                    {
                        case TopSymbolBy.TopUp:
                            switch (tradeCenter)
                            {
                                case TradeCenter.HaSTC:
                                    //dtStockList = dataServices.GetTopSymbol(10,
                                    //                                        WServices.Function.TopStockSymbol.TopUp,
                                    //                                        WServices.Function.TradeCenter.HaSTC).Tables[0];
                                    key = string.Format(RedisKey.KeyTopStock, RedisKey.KeyTopStockCenter.Ha, RedisKey.KeyTopStockType.PriceUp);
                                    break;
                                case TradeCenter.HoSE:
                                    //dtStockList = dataServices.GetTopSymbol(10,
                                    //                                        WServices.Function.TopStockSymbol.TopUp,
                                    //                                        WServices.Function.TradeCenter.HoSE).Tables[0];
                                    key = string.Format(RedisKey.KeyTopStock, RedisKey.KeyTopStockCenter.Ho, RedisKey.KeyTopStockType.PriceUp);
                                    break;
                                default:
                                    //dtStockList = dataServices.GetTopSymbol(10,
                                    //                                        WServices.Function.TopStockSymbol.TopUp,
                                    //                                        WServices.Function.TradeCenter.All).Tables[0];
                                    key = string.Format(RedisKey.KeyTopStock, RedisKey.KeyTopStockCenter.All, RedisKey.KeyTopStockType.PriceUp);
                                    break;
                            }
                            break;
                        case TopSymbolBy.TopDown:
                            switch (tradeCenter)
                            {
                                case TradeCenter.HaSTC:
                                    //dtStockList = dataServices.GetTopSymbol(10,
                                    //                                        WServices.Function.TopStockSymbol.TopDown,
                                    //                                        WServices.Function.TradeCenter.HaSTC).Tables[0];
                                    key = string.Format(RedisKey.KeyTopStock, RedisKey.KeyTopStockCenter.Ha, RedisKey.KeyTopStockType.PriceDown);
                                    break;
                                case TradeCenter.HoSE:
                                    //dtStockList = dataServices.GetTopSymbol(10,
                                    //                                        WServices.Function.TopStockSymbol.TopDown,
                                    //                                        WServices.Function.TradeCenter.HoSE).Tables[0];
                                    key = string.Format(RedisKey.KeyTopStock, RedisKey.KeyTopStockCenter.Ho, RedisKey.KeyTopStockType.PriceDown);
                                    break;
                                default:
                                    //dtStockList = dataServices.GetTopSymbol(10,
                                    //                                        WServices.Function.TopStockSymbol.TopDown,
                                    //                                        WServices.Function.TradeCenter.All).Tables[0];
                                    key = string.Format(RedisKey.KeyTopStock, RedisKey.KeyTopStockCenter.All, RedisKey.KeyTopStockType.PriceDown);
                                    break;
                            }
                            break;
                        default:
                            switch (tradeCenter)
                            {
                                case TradeCenter.HaSTC:
                                    //dtStockList = dataServices.GetTopSymbol(10,
                                    //                                        WServices.Function.TopStockSymbol.TopTrade,
                                    //                                        WServices.Function.TradeCenter.HaSTC).Tables[0];
                                    key = string.Format(RedisKey.KeyTopStock, RedisKey.KeyTopStockCenter.Ha, RedisKey.KeyTopStockType.VolumeDown);
                                    break;
                                case TradeCenter.HoSE:
                                    //dtStockList = dataServices.GetTopSymbol(10,
                                    //                                        WServices.Function.TopStockSymbol.TopTrade,
                                    //                                        WServices.Function.TradeCenter.HoSE).Tables[0];
                                    key = string.Format(RedisKey.KeyTopStock, RedisKey.KeyTopStockCenter.Ho, RedisKey.KeyTopStockType.VolumeDown);
                                    break;
                                default:
                                    //dtStockList = dataServices.GetTopSymbol(10,
                                    //                                        WServices.Function.TopStockSymbol.TopTrade,
                                    //                                        WServices.Function.TradeCenter.All).Tables[0];
                                    key = string.Format(RedisKey.KeyTopStock, RedisKey.KeyTopStockCenter.All, RedisKey.KeyTopStockType.VolumeDown);
                                    break;
                            }
                            break;
                    }
                    var tops = BLFACTORY.RedisClient.Get<List<TopStock>>(key);
                    //'Quantity':0,'Price':1,'Change':2,'ChangePercent':3
                //}
                foreach (var top in tops)
                {
                    object[] datas = new object[fields.Length];
                    datas[0] = top.Volume;
                    datas[1] = top.Price;
                    datas[2] = top.Price - top.BasicPrice;
                    datas[3] = top.BasicPrice <= 0 ? 0 : (top.Price - top.BasicPrice) / top.BasicPrice * 100;
                    items.Add(new SymbolItem(top.Symbol,datas));
                }
                #endregion

                //if (dtStockList == null || dtStockList.Rows.Count == 0)
                //{
                //    DataTable dtTemp;
                //    if (tradeCenter == TradeCenter.AllTradeCenter)
                //    {
                //        dtTemp = GetStockSymbolData(TradeCenter.HoSE);
                //        dtTemp.Merge(GetStockSymbolData(TradeCenter.HaSTC));
                //    }
                //    else
                //    {
                //        dtTemp = GetStockSymbolData(tradeCenter);
                //    }
                //    using (DataView dvTemp = new DataView(dtTemp))
                //    {
                //        dvTemp.RowFilter = (type == TopSymbolBy.TopUp ? "chgIndex > 0" : (type == TopSymbolBy.TopDown ? "chgIndex < 0" : ""));
                //        dvTemp.Sort = (type == TopSymbolBy.TopUp ? "chgIndex DESC" : (type == TopSymbolBy.TopDown ? "chgIndex ASC" : "totalTradingQtty DESC"));
                //        dtStockList = dvTemp.ToTable();
                //    }
                //    dtTemp.Dispose();
                //}

               

                //for (int i = 0; i < dtStockList.Rows.Count && i < 10; i++)
                //{
                //    object[] datas = new object[fields.Length];

                //    for (int j = 0; j < fields.Length; j++)
                //    {
                //        if (fields[j].ToLower() == "currentprice")
                //        {
                //            if (Lib.Object2Double(dtStockList.Rows[i][fields[j]]) > 0)
                //            {
                //                datas[j] = dtStockList.Rows[i][fields[j]];
                //            }
                //            else
                //            {
                //                try
                //                {
                //                    datas[j] = dtStockList.Rows[i]["basicPrice"];
                //                }
                //                catch
                //                {
                //                    datas[j] = 0;
                //                }
                //            }
                //        }
                //        else
                //        {
                //            datas[j] = dtStockList.Rows[i][fields[j]];
                //        }
                //    }

                //    items.Add(new SymbolItem(dtStockList.Rows[i]["code"].ToString(), datas));
                //}

                //dtStockList.Dispose();

                

                currentData.Symbols = items.ToArray();
                //Lib.WriteLog("Top10CP: " + currentData.Symbols.Length.ToString() + " Items");
                return currentData;
            }
            public static FinanceStatement GetTopFinanceStatement(TopFinanceStatementBy type, TradeCenter tradeCenter)
            {
                FinanceStatement currentData = new FinanceStatement();

                //DataTable dtPriceData = new DataTable("StockPriceData");
                //dtPriceData.Merge(GetStockSymbolData(TradeCenter.HaSTC));
                //dtPriceData.Merge(GetStockSymbolData(TradeCenter.HoSE));

                //string cacheName = "";

                //if (type == TopFinanceStatementBy.TopPE)
                //{
                //    if (tradeCenter == TradeCenter.AllTradeCenter)
                //    {
                //        cacheName += "MemCached_Top10_PE_All";
                //    }
                //    else if (tradeCenter == TradeCenter.HaSTC)
                //    {
                //        cacheName += "MemCached_Top10_PE_HaSTC";
                //    }
                //    else
                //    {
                //        cacheName += "MemCached_Top10_PE_HoSE";
                //    }
                //}
                //else if (type == TopFinanceStatementBy.TopEPS)
                //{
                //    if (tradeCenter == TradeCenter.AllTradeCenter)
                //    {
                //        cacheName += "MemCached_Top10_EPS_All";
                //    }
                //    else if (tradeCenter == TradeCenter.HaSTC)
                //    {
                //        cacheName += "MemCached_Top10_EPS_HaSTC";
                //    }
                //    else
                //    {
                //        cacheName += "MemCached_Top10_EPS_HoSE";
                //    }
                //}
                //else
                //{
                //    if (tradeCenter == TradeCenter.AllTradeCenter)
                //    {
                //        cacheName += "MemCached_Top10_Capital_All";
                //    }
                //    else if (tradeCenter == TradeCenter.HaSTC)
                //    {
                //        cacheName += "MemCached_Top10_Capital_HaSTC";
                //    }
                //    else
                //    {
                //        cacheName += "MemCached_Top10_Capital_HoSE";
                //    }
                //}
                ////using (FinanceStatementData fsdTopData = new FinanceStatementData(cacheName))
                //DataTable fsdTopData = DistCache.Get<DataTable>(cacheName);

                //if (fsdTopData == null || fsdTopData.Rows.Count == 0)
                //{
                    //#region Get From WebService
                    //if (fsdTopData == null || fsdTopData.Rows.Count == 0)
                    //{
                    //    //CafeF_DataService.CafeF_DataService dataServices = new CafeF_EmbedData.CafeF_DataService.CafeF_DataService();
                    //    WServices.Function dataServices = new WServices.Function();
                var key = "";
                switch (type)
                {
                    case TopFinanceStatementBy.TopEPS:
                        switch (tradeCenter)
                        {
                            case TradeCenter.HaSTC:
                                //fsdTopData = dataServices.GetTopCompany(10,
                                //                                        WServices.Function.TopCompany.TopEPS,
                                //                                        WServices.Function.TradeCenter.HaSTC).Tables[0];
                                key = string.Format(RedisKey.KeyTopStock, RedisKey.KeyTopStockCenter.Ha, RedisKey.KeyTopStockType.EPS);
                                break;
                            case TradeCenter.HoSE:
                                //fsdTopData = dataServices.GetTopCompany(10,
                                //                                        WServices.Function.TopCompany.TopEPS,
                                //                                        WServices.Function.TradeCenter.HoSE).Tables[0];
                                key = string.Format(RedisKey.KeyTopStock, RedisKey.KeyTopStockCenter.Ho, RedisKey.KeyTopStockType.EPS);
                                break;
                            default:
                                //fsdTopData = dataServices.GetTopCompany(10,
                                //                                        WServices.Function.TopCompany.TopEPS,
                                //                                        WServices.Function.TradeCenter.All).Tables[0];
                                key = string.Format(RedisKey.KeyTopStock, RedisKey.KeyTopStockCenter.All, RedisKey.KeyTopStockType.EPS);
                                break;
                        }
                        break;
                    case TopFinanceStatementBy.TopPE:
                        switch (tradeCenter)
                        {
                            case TradeCenter.HaSTC:
                                //fsdTopData = dataServices.GetTopCompany(10,
                                //                                        WServices.Function.TopCompany.TopPE,
                                //                                        WServices.Function.TradeCenter.HaSTC).Tables[0];
                                key = string.Format(RedisKey.KeyTopStock, RedisKey.KeyTopStockCenter.Ha, RedisKey.KeyTopStockType.PE);
                                break;
                            case TradeCenter.HoSE:
                                //fsdTopData = dataServices.GetTopCompany(10,
                                //                                        WServices.Function.TopCompany.TopPE,
                                //                                        WServices.Function.TradeCenter.HoSE).Tables[0];
                                key = string.Format(RedisKey.KeyTopStock, RedisKey.KeyTopStockCenter.Ho, RedisKey.KeyTopStockType.PE);
                                break;
                            default:
                                //fsdTopData = dataServices.GetTopCompany(10,
                                //                                        WServices.Function.TopCompany.TopPE,
                                //                                        WServices.Function.TradeCenter.All).Tables[0];
                                key = string.Format(RedisKey.KeyTopStock, RedisKey.KeyTopStockCenter.All, RedisKey.KeyTopStockType.PE);
                                break;
                        }
                        break;
                    default:
                        switch (tradeCenter)
                        {
                            case TradeCenter.HaSTC:
                                //fsdTopData = dataServices.GetTopCompany(10,
                                //                                        WServices.Function.TopCompany.TopCapital,
                                //                                        WServices.Function.TradeCenter.HaSTC).Tables[0];
                                key = string.Format(RedisKey.KeyTopStock, RedisKey.KeyTopStockCenter.Ha, RedisKey.KeyTopStockType.MarketCap);
                                break;
                            case TradeCenter.HoSE:
                                //fsdTopData = dataServices.GetTopCompany(10,
                                //                                        WServices.Function.TopCompany.TopCapital,
                                //                                        WServices.Function.TradeCenter.HoSE).Tables[0];
                                key = string.Format(RedisKey.KeyTopStock, RedisKey.KeyTopStockCenter.Ho, RedisKey.KeyTopStockType.MarketCap);
                                break;
                            default:
                                //fsdTopData = dataServices.GetTopCompany(10,
                                //                                        WServices.Function.TopCompany.TopCapital,
                                //                                        WServices.Function.TradeCenter.All).Tables[0];
                                key = string.Format(RedisKey.KeyTopStock, RedisKey.KeyTopStockCenter.All, RedisKey.KeyTopStockType.MarketCap);
                                break;
                        }
                        break;
                }
                    //}
                    //#endregion
                //}

                //fsdTopData.TableName = "TopData";
                //using (DataSet dsTopData = new DataSet())
                //{
                //    dsTopData.Merge(dtPriceData);
                //    dsTopData.Merge(fsdTopData);

                //    DataColumn parentColumn = dsTopData.Tables["StockPriceData"].Columns["code"];
                //    DataColumn childColumn = dsTopData.Tables["TopData"].Columns[FinanceStatementData.FIELD_SYMBOL];

                //    DataRelation relTopPE_StockPriceData = new DataRelation("TopData_StockPriceData", parentColumn, childColumn, false);

                //    dsTopData.Relations.Add(relTopPE_StockPriceData);

                //    dsTopData.Tables["TopData"].Columns.Add("basicPrice", typeof(double), "Parent.basicPrice");
                //    dsTopData.Tables["TopData"].Columns.Add("currentPrice", typeof(double), "Parent.currentPrice");
                //    dsTopData.Tables["TopData"].Columns.Add("chgIndex", typeof(double), "Parent.chgIndex");
                //    dsTopData.Tables["TopData"].Columns.Add("pctIndex", typeof(double), "Parent.pctIndex");

                //    List<FinanceStatementItem> items = new List<FinanceStatementItem>();

                //    for (int i = 0; i < dsTopData.Tables["TopData"].Rows.Count; i++)
                //    {
                //        if (Lib.Object2Double(dsTopData.Tables["TopData"].Rows[i]["currentPrice"]) == 0)
                //        {
                //            items.Add(new FinanceStatementItem(dsTopData.Tables["TopData"].Rows[i][FinanceStatementData.FIELD_SYMBOL].ToString(),
                //                                        Lib.Object2Double(dsTopData.Tables["TopData"].Rows[i][FinanceStatementData.FIELD_PE]),
                //                                        Lib.Object2Double(dsTopData.Tables["TopData"].Rows[i][FinanceStatementData.FIELD_EPS]),
                //                                        Lib.Object2Double(dsTopData.Tables["TopData"].Rows[i][FinanceStatementData.FIELD_CAPITAL]),
                //                                        Lib.Object2Double(dsTopData.Tables["TopData"].Rows[i]["basicPrice"]),
                //                                        Lib.Object2Double(dsTopData.Tables["TopData"].Rows[i]["chgIndex"]),
                //                                        Lib.Object2Double(dsTopData.Tables["TopData"].Rows[i]["pctIndex"]), 0, 0));
                //        }
                //        else
                //        {
                //            items.Add(new FinanceStatementItem(dsTopData.Tables["TopData"].Rows[i][FinanceStatementData.FIELD_SYMBOL].ToString(),
                //                                        Lib.Object2Double(dsTopData.Tables["TopData"].Rows[i][FinanceStatementData.FIELD_PE]),
                //                                        Lib.Object2Double(dsTopData.Tables["TopData"].Rows[i][FinanceStatementData.FIELD_EPS]),
                //                                        Lib.Object2Double(dsTopData.Tables["TopData"].Rows[i][FinanceStatementData.FIELD_CAPITAL]),
                //                                        Lib.Object2Double(dsTopData.Tables["TopData"].Rows[i]["currentPrice"]),
                //                                        Lib.Object2Double(dsTopData.Tables["TopData"].Rows[i]["chgIndex"]),
                //                                        Lib.Object2Double(dsTopData.Tables["TopData"].Rows[i]["pctIndex"]), 0, 0));
                //        }
                //    }

                //    currentData.FinanceStatements = items.ToArray();
                //}
                var items = new List<FinanceStatementItem>();

                var tops = BLFACTORY.RedisClient.Get<List<TopStock>>(key);
                    //'Quantity':0,'Price':1,'Change':2,'ChangePercent':3
                //}
                foreach (var top in tops)
                {
                    items.Add(new FinanceStatementItem(top.Symbol,top.PE, top.EPS, top.MarketCap, top.Price, top.Price - top.BasicPrice, top.BasicPrice==0?0:((top.Price - top.BasicPrice)/top.BasicPrice*100), 0,0));
                }

                currentData.FinanceStatements = items.ToArray();
                return currentData;
            }
        private void loadData(TradeCenter tradeCenter, DateTime tradeDate)
        {
            List<OrderHistory> data = OrderHistoryBL.get_OrderHistoryByCenterAndDate((int)tradeCenter, tradeDate);
            data.Sort("BuyLeft desc");
            rptData.DataSource = data; 
            rptData.DataBind();
            string index =  "VNINDEX";
            if (tradeCenter == TradeCenter.HoSE)
            {
                index = "VNINDEX";
            }
            if (tradeCenter == TradeCenter.HaSTC)
            {
                index = "HNX-INDEX";
            }
            if (tradeCenter == TradeCenter.UpCom)
            {
                index = "UPCOM-INDEX";
            }

            List<OrderHistory> CompareOrder = OrderHistoryBL.get_TwoOrderHistoryBySymbolAndDate(index, tradeDate);
            if (CompareOrder.Count==2)
            {
                string[] comparedResults = compareCurrent_PreviousTrading(CompareOrder[0], CompareOrder[1]);
                div1.InnerHtml = "<span style='font-weight:bold;'>Tổng số lệnh đặt mua:&nbsp;</span>" + String.Format("{0:#,##0}", CompareOrder[0].BuyOrderCount) + "&nbsp;cổ phiếu&nbsp;" + comparedResults[0];
                div2.InnerHtml = "<span style='font-weight:bold;'>Tổng khối lượng đặt mua:&nbsp;</span>" + String.Format("{0:#,##0}", CompareOrder[0].BuyVolume) + "&nbsp;cổ phiếu&nbsp;" + comparedResults[1];
                try
                {
                    div5.InnerHtml = "<span style='font-weight:bold;'>KLTB 1 lệnh mua:&nbsp;</span>" + String.Format("{0:#,##0}", CompareOrder[0].BuyVolume /( CompareOrder[0].BuyOrderCount == 0 ? 1 : CompareOrder[0].BuyOrderCount)) + "&nbsp;cổ phiếu";
                }
                catch { }

                div3.InnerHtml = "<span style='font-weight:bold;'>Tổng số lệnh đặt bán:&nbsp;</span>" + String.Format("{0:#,##0}", CompareOrder[0].SellOrderCount) + "&nbsp;cổ phiếu&nbsp;" + comparedResults[2];
                div4.InnerHtml = "<span style='font-weight:bold;'>Tổng khối lượng đặt bán:&nbsp;</span>" + String.Format("{0:#,##0}", CompareOrder[0].SellVolume) + "&nbsp;cổ phiếu&nbsp;" + comparedResults[3];
                try
                {
                    div6.InnerHtml = "<span style='font-weight:bold;'>KLTB 1 lệnh bán:&nbsp;</span>" + String.Format("{0:#,##0}", CompareOrder[0].SellVolume / (CompareOrder[0].SellOrderCount == 0 ? 1 : CompareOrder[0].SellOrderCount)) + "&nbsp;cổ phiếu";
                }
                catch { }
                divDumua.InnerHtml = "&nbsp;&nbsp;&nbsp;Dư mua:&nbsp;" + String.Format("{0:#,##0}", Math.Abs(CompareOrder[0].BuyVolume - CompareOrder[0].Volume)) + "&nbsp;cổ phiếu";
                divDuban.InnerHtml = "&nbsp;&nbsp;&nbsp;Dư bán:&nbsp;" + String.Format("{0:#,##0}", Math.Abs(CompareOrder[0].SellVolume - CompareOrder[0].Volume)) + "&nbsp;cổ phiếu";
            }
        }