public static CompanyInfo GetAllCompanyByTradeId(int tradeId) { CompanyInfo currentData = new CompanyInfo(); //CompanyHelper_Update company = new CompanyHelper_Update(); //currentData.RecordCount = company.Select_Count_TradeCenter("", -1, tradeId, (int)FilterType.NoFilter); //currentData.PageIndex = 1; //currentData.PageCount = 1; //using (DataTable dtCompanies = company.GetTradeCenter(tradeId.ToString())) //{ // List<CompanyInfoItem> items = new List<CompanyInfoItem>(); // if (dtCompanies != null) // { // using (DataTable dtCompaniesIncludePrice = GetOnlineInfo(dtCompanies)) // { // for (int i = 0; i < dtCompaniesIncludePrice.Rows.Count; i++) // { // if (Lib.Object2Double(dtCompaniesIncludePrice.Rows[i]["CurrentPrice"]) == 0) // { // items.Add(new CompanyInfoItem(dtCompaniesIncludePrice.Rows[i]["StockSymbol"].ToString(), // dtCompaniesIncludePrice.Rows[i]["Fullname"].ToString(), // dtCompaniesIncludePrice.Rows[i]["Symbol"].ToString(), // Lib.Object2Double(dtCompaniesIncludePrice.Rows[i]["BasicPrice"]), // Lib.Object2Double(dtCompaniesIncludePrice.Rows[i]["PE"]), // Lib.Object2Double(dtCompaniesIncludePrice.Rows[i]["EPS"]) // )); // } // else // { // items.Add(new CompanyInfoItem(dtCompaniesIncludePrice.Rows[i]["StockSymbol"].ToString(), // dtCompaniesIncludePrice.Rows[i]["Fullname"].ToString(), // dtCompaniesIncludePrice.Rows[i]["Symbol"].ToString(), // Lib.Object2Double(dtCompaniesIncludePrice.Rows[i]["CurrentPrice"]), // Lib.Object2Double(dtCompaniesIncludePrice.Rows[i]["PE"]), // Lib.Object2Double(dtCompaniesIncludePrice.Rows[i]["EPS"]) // ) // ); // } // } // } // } // currentData.CompanyInfos = items.ToArray(); //} var items = new List<CompanyInfoItem>(); var key = tradeId > 0 ? string.Format(RedisKey.KeyStockListByCenter, tradeId): RedisKey.KeyStockList; var sds = BLFACTORY.RedisClient.Get<List<StockCompact>>(key); var ss = new List<string>(); foreach (var sym in sds) { ss.Add(sym.Symbol); } var infos = StockBL.GetStockCompactInfoMultiple(ss); var prices = StockBL.GetStockPriceMultiple(ss); foreach (var sym in sds) { var item = new CompanyInfoItem(); item.Symbol = sym.Symbol; item.TradeCenter = Utils.GetCenterName(sym.TradeCenterId.ToString()); if(prices.ContainsKey(sym.Symbol)) { var price = prices[sym.Symbol]; if(price!=null) { item.Price = price.Price; } } if(infos.ContainsKey(sym.Symbol)) { var info = infos[sym.Symbol]; if(info!=null) { item.CompanyName = info.CompanyName; item.EPS = Math.Round(info.EPS, 2); item.PE = (info.EPS == 0) ? 0 : Math.Round(item.Price / info.EPS, 2); } } items.Add(item); } currentData.RecordCount = items.Count; currentData.PageIndex = 1; currentData.PageCount = 1; currentData.CompanyInfos = items.ToArray(); return currentData; }
public static CompanyInfo SearchCompany(int tradeId, int industryId, FilterType filterType, string keyword, int pageIndex, int pageSize) { CompanyInfo currentData = new CompanyInfo(); //if (!string.IsNullOrEmpty(keyword)) //{ // keyword = keyword.Replace("'", ""); //} //else //{ // keyword = ""; //} //CompanyHelper_Update company = new CompanyHelper_Update(); //currentData.RecordCount = company.Select_Count_TradeCenter(keyword, industryId, tradeId, (int)filterType); //currentData.PageIndex = pageIndex; //if (currentData.RecordCount > 1) //{ // currentData.PageCount = ((int)(currentData.RecordCount - 1) / pageSize) + 1; //} //else //{ // currentData.PageCount = 1; //} //if (pageIndex <= 0) //{ // currentData.PageIndex = 1; //} //else //{ // if (pageIndex > currentData.PageCount) // { // currentData.PageIndex = currentData.PageCount; // } // else // { // currentData.PageIndex = pageIndex; // } //} //using (DataTable dtCompanies = company.GetTradeCenter(tradeId, keyword, industryId, currentData.PageIndex, pageSize, (int)filterType)) //{ // List<CompanyInfoItem> items = new List<CompanyInfoItem>(); // if (dtCompanies != null) // { // using (DataTable dtCompaniesIncludePrice = GetOnlineInfo(dtCompanies)) // { // for (int i = 0; i < dtCompaniesIncludePrice.Rows.Count; i++) // { // items.Add(new CompanyInfoItem(dtCompaniesIncludePrice.Rows[i]["StockSymbol"].ToString(), // dtCompaniesIncludePrice.Rows[i]["Fullname"].ToString(), // dtCompaniesIncludePrice.Rows[i]["Symbol"].ToString(), // Lib.Object2Double(dtCompaniesIncludePrice.Rows[i]["CurrentPrice"]), // Lib.Object2Double(dtCompaniesIncludePrice.Rows[i]["PE"]), // Lib.Object2Double(dtCompaniesIncludePrice.Rows[i]["EPS"]) // )); // } // } // } // currentData.CompanyInfos = items.ToArray(); //} //return currentData; var items = new List<CompanyInfoItem>(); var key = tradeId > 0 ? string.Format(RedisKey.KeyStockListByCenter, tradeId) : RedisKey.KeyStockList; var sds = BLFACTORY.RedisClient.Get<List<StockCompact>>(key); sds = sds.FindAll(s => s.Symbol.Contains(keyword) && (industryId == -1||s.CategoryId==industryId)); if(filterType==FilterType.StockSymbol) { currentData.RecordCount = sds.Count; //Neu loc theo chu cai sds = sds.GetPaging(pageIndex, pageSize); } var ss = new List<string>(); Dictionary<string, StockCompactInfo> infos; if (filterType == FilterType.NoFilter && !string.IsNullOrEmpty(keyword)) { foreach (var sym in sds) { ss.Add(sym.Symbol); } infos = StockBL.GetStockCompactInfoMultiple(ss); foreach (var info in infos) { if (info.Value == null) continue; var sym = info.Value.Symbol; //ss.Remove(info.Value.Symbol); var index = sds.FindIndex(s=>s.Symbol==sym); if(index >0) sds.RemoveAt(index); } currentData.RecordCount = sds.Count; sds = sds.GetPaging(pageIndex, pageSize); } if (sds.Count > pageSize) { currentData.RecordCount = sds.Count; sds = sds.GetPaging(pageIndex, pageSize); } ss = new List<string>(); foreach (var sym in sds) { ss.Add(sym.Symbol); } infos = StockBL.GetStockCompactInfoMultiple(ss); var prices = StockBL.GetStockPriceMultiple(ss); foreach (var sym in sds) { var item = new CompanyInfoItem {Symbol = sym.Symbol, TradeCenter = Utils.GetCenterName(sym.TradeCenterId.ToString()), Price = 0, CompanyName = ""}; if (prices.ContainsKey(sym.Symbol)) { var price = prices[sym.Symbol]; if (price != null) { item.Price = price.Price; } } if (infos.ContainsKey(sym.Symbol)) { var info = infos[sym.Symbol]; if (info != null) { item.CompanyName = info.CompanyName; item.EPS = Math.Round(info.EPS,2); item.PE = (info.EPS == 0) ? 0 : Math.Round(item.Price / info.EPS, 2); } } if(string.IsNullOrEmpty(item.CompanyName)) continue; items.Add(item); } currentData.PageIndex = pageIndex; currentData.PageCount = (int)Math.Ceiling((double)currentData.RecordCount / pageSize); currentData.CompanyInfos = items.ToArray(); return currentData; }