Ejemplo n.º 1
0
        private bool UpdateStock(string symbol)
        {
            var ret = true;
            var related = new List<string>();
            var sql = new SqlDb();
            //////log.WriteEntry(symbol + "-1-" + ret, EventLogEntryType.Information);
            try
            {
                var redis = new RedisClient(ConfigRedis.Host, ConfigRedis.Port);
                var key = string.Format(RedisKey.Key, symbol.ToUpper());
                var bExisted = false;
                var stock = new Stock() { Symbol = symbol };
                #region Update stock from sql
                //stock.Symbol = "AAA";
                //load stock data 

                //profile
                var profile = bExisted ? stock.CompanyProfile : new CompanyProfile { Symbol = stock.Symbol };
                var basicInfo = bExisted ? profile.basicInfos : new BasicInfo() { Symbol = stock.Symbol };
                var basicCommon = bExisted ? profile.basicInfos.basicCommon : new BasicCommon() { Symbol = stock.Symbol };
                var category = bExisted ? profile.basicInfos.category : new CategoryObject();
                var firstInfo = bExisted ? profile.basicInfos.firstInfo : new FirstInfo() { Symbol = stock.Symbol };
                var commonInfo = bExisted ? profile.commonInfos : new CommonInfo() { Symbol = stock.Symbol };
                //basic information
                if (!bExisted || related.Contains("SB"))
                {
                    try
                    {
                        var dt = sql.GetSymbolData(symbol);
                        if (dt.Rows.Count <= 0) return true;

                        var row = dt.Rows[0];

                        #region StockCompactInfo

                        var compactkey = string.Format(RedisKey.KeyCompactStock, symbol.ToUpper());
                        var compact = new StockCompactInfo() { Symbol = symbol.ToUpper(), TradeCenterId = int.Parse(row["TradeCenterId"].ToString()), CompanyName = row["CompanyName"].ToString(), EPS = double.Parse(row["EPS"].ToString()), FolderChart = row["FolderChart"].ToString(), ShowTradeCenter = row["ShowTradeCenter"].ToString().ToUpper() == "TRUE", IsBank = row["IsBank"].ToString().ToUpper() == "TRUE", IsCCQ = row["IsCCQ"].ToString().ToUpper() == "TRUE" };
                        if (redis.ContainsKey(compactkey))
                            redis.Set(compactkey, compact);
                        else
                            redis.Add(compactkey, compact);
                        #endregion

                        stock.Symbol = row["Symbol"].ToString();
                        stock.TradeCenterId = int.Parse(row["TradeCenterId"].ToString());
                        stock.IsDisabled = row["IsDisabled"].ToString() == "TRUE";
                        stock.StatusText = row["StatusText"].ToString();
                        stock.ShowTradeCenter = row["ShowTradeCenter"].ToString().ToUpper() == "TRUE";
                        stock.FolderImage = row["FolderChart"].ToString();
                        stock.IsBank = row["IsBank"].ToString() == "TRUE";
                        stock.IsCCQ = row["IsCCQ"].ToString().ToUpper() == "TRUE";

                        //profile - basicInfo
                        basicInfo.Name = row["CompanyName"].ToString();
                        basicInfo.TradeCenter = stock.TradeCenterId.ToString();

                        //profile - basicInfo - basicCommon
                        /*PE = double.Parse(row["PE"].ToString()),*/
                        basicCommon.AverageVolume = double.Parse(row["AVG10SS"].ToString());
                        basicCommon.Beta = double.Parse(row["Beta"].ToString());
                        basicCommon.EPS = double.Parse(row["EPS"].ToString());
                        basicCommon.TotalValue = double.Parse(row["MarketCap"].ToString());
                        basicCommon.ValuePerStock = double.Parse(row["BookValue"].ToString());
                        basicCommon.VolumeTotal = double.Parse(row["SLCPNY"].ToString());
                        basicCommon.OutstandingVolume = double.Parse(row["TotalShare"].ToString());
                        basicCommon.PE = basicCommon.EPS != 0 ? (double.Parse(row["LastPrice"].ToString()) / basicCommon.EPS) : 0;
                        basicCommon.EPSDate = row["EPSDate"].ToString();
                        basicCommon.CCQv3 = double.Parse(row["CCQv3"].ToString());
                        basicCommon.CCQv6 = double.Parse(row["CCQv6"].ToString());
                        basicCommon.CCQdate = DateTime.ParseExact(row["CCQdate"].ToString(), "yyyy.MM.dd", CultureInfo.InvariantCulture, DateTimeStyles.None);

                        basicInfo.basicCommon = basicCommon;

                        //profile - basicInfo - category
                        category.ID = int.Parse(row["CategoryId"].ToString());
                        category.Name = row["CategoryName"].ToString();
                        basicInfo.category = category;

                        //profile - basicInfo - firstInfo
                        firstInfo.FirstPrice = double.Parse(row["FirstPrice"].ToString());
                        firstInfo.FirstTrade = row["FirstTrade"].Equals(DBNull.Value) ? null : ((DateTime?)row["FirstTrade"]);
                        firstInfo.FirstVolume = double.Parse(row["FirstVolume"].ToString());
                        basicInfo.firstInfo = firstInfo;

                        profile.basicInfos = basicInfo;

                        //profile - commonInfo
                        commonInfo.Capital = double.Parse(row["VonDieuLe"].ToString());
                        commonInfo.Category = row["CategoryName"].ToString();
                        commonInfo.Content = row["About"].ToString();
                        commonInfo.OutstandingVolume = double.Parse(row["TotalShare"].ToString());
                        commonInfo.TotalVolume = double.Parse(row["SLCPNY"].ToString());
                        commonInfo.Content += "<p><b>Địa chỉ:</b> " + row["Address"].ToString() + "</p>";
                        commonInfo.Content += "<p><b>Điện thoại:</b> " + row["Phone"].ToString() + "</p>";
                        commonInfo.Content += "<p><b>Người phát ngôn:</b> " + row["Spokenman"].ToString() + "</p>";
                        if (!string.IsNullOrEmpty(row["Email"].ToString())) commonInfo.Content += "<p><b>Email:</b> <a href='mailto:" + row["Email"] + "'>" + row["Email"] + "</a></p>";
                        if (!string.IsNullOrEmpty(row["Website"].ToString())) commonInfo.Content += "<p><b>Website:</b> <a href='" + row["Website"] + "' target='_blank'>" + row["Website"] + "</a></p>";
                        commonInfo.AuditFirmName = row["AuditName"].ToString();
                        commonInfo.AuditFirmSite = row["AuditSite"].ToString().Trim();
                        commonInfo.ConsultantName = row["ConsultantName"].ToString();
                        commonInfo.ConsultantSite = row["ConsultantSite"].ToString();
                        commonInfo.BusinessLicense = row["BusinessLicense"].ToString();

                        profile.commonInfos = commonInfo;

                        //business plans
                        var plans = new List<BusinessPlan>();
                        if (row["HasPlan"].ToString() == "1")
                        {
                            plans.Add(new BusinessPlan() { Body = row["PlanNote"].ToString(), Date = (DateTime)row["PlanDate"], DividendsMoney = double.Parse(row["Dividend"].ToString()), DividendsStock = double.Parse(row["DivStock"].ToString()), ID = int.Parse(row["PlanId"].ToString()), IncreaseExpected = double.Parse(row["CapitalRaising"].ToString()), ProfitATax = double.Parse(row["NetIncome"].ToString()), ProfitBTax = double.Parse(row["TotalProfit"].ToString()), Revenue = double.Parse(row["TotalIncome"].ToString()), Symbol = stock.Symbol, Year = int.Parse(row["KYear"].ToString()) });
                        }
                        stock.BusinessPlans1 = plans;
                    }
                    catch (Exception ex)
                    {
                        ////log.WriteEntry(symbol + " : BasicInfo : " + ex.ToString(), EventLogEntryType.Error);
                        ret = false;
                    }
                }

                //profile - subsidiaries
                if (!bExisted || related.Contains("SS"))
                {
                    try
                    {


                        var subsidiaries = new List<OtherCompany>();
                        var associates = new List<OtherCompany>();
                        var cdt = sql.GetChildrenCompany(stock.Symbol);
                        var i = 0;
                        foreach (DataRow cdr in cdt.Rows)
                        {
                            i++;
                            var child = new OtherCompany() { Name = cdr["CompanyName"].ToString(), Note = cdr["NoteInfo"].ToString(), OwnershipRate = double.Parse(cdr["Rate"].ToString()), Order = i, SharedCapital = double.Parse(cdr["TotalShareValue"].ToString()), Symbol = stock.Symbol, TotalCapital = double.Parse(cdr["CharterCapital"].ToString()) };
                            if (cdr["isCongTyCon"].ToString() == "1") subsidiaries.Add(child);
                            else associates.Add(child);
                        }
                        profile.Subsidiaries = subsidiaries;
                        profile.AssociatedCompanies = associates;
                    }
                    catch (Exception ex)
                    {
                        ////log.WriteEntry(symbol + " : Cty con : " + ex.ToString(), EventLogEntryType.Error);
                        ret = false;
                    }
                }

                //profile - financePeriod
                if (!bExisted || related.Contains("SF"))
                {
                    try
                    {
                        var periods = new List<FinancePeriod>();
                        var financeInfo = new List<FinanceInfo>();

                        var fyt = sql.GetFinancePeriod(stock.Symbol);
                        FinancePeriod period = null;
                        var tmp = 0;
                        foreach (DataRow fyr in fyt.Rows)
                        {
                            if (period == null || tmp != int.Parse(fyr["Year"].ToString()) * 10 + int.Parse(fyr["QuarterType"].ToString()))
                            {
                                if (period != null) { period.UpdateTitle(); periods.Add(period); }
                                period = new FinancePeriod() { Quarter = int.Parse(fyr["QuarterType"].ToString()), Year = int.Parse(fyr["Year"].ToString()) };
                            }
                            tmp = int.Parse(fyr["Year"].ToString()) * 10 + int.Parse(fyr["QuarterType"].ToString());
                            switch (fyr["MaChiTieu"].ToString())
                            {
                                case "Audited":
                                    period.SubTitle = fyr["TieuDeNhom"].ToString();
                                    break;
                                case "QuarterModify":
                                    var qrt = fyr["TieuDeNhom"].ToString();
                                    var qrti = 0;
                                    if (qrt.EndsWith("T")) { period.QuarterTitle = qrt.Remove(qrt.Length - 1) + " tháng"; }
                                    else if (int.TryParse(qrt, out qrti) && qrti >= 1 && qrti < 5)
                                    {
                                        period.QuarterTitle = "Quý " + qrti;
                                    }
                                    else period.QuarterTitle = "";
                                    break;
                                case "YearModify":
                                    if (int.TryParse(fyr["TieuDeNhom"].ToString(), out qrti))
                                    {
                                        period.YearTitle = "Năm " + qrti;
                                    }
                                    else period.YearTitle = "";
                                    break;
                                case "FromDate":
                                    qrt = fyr["TieuDeNhom"].ToString();
                                    if (qrt.Contains("/"))
                                        period.BeginTitle = qrt.Substring(0, qrt.LastIndexOf("/"));
                                    break;
                                case "ToDate":
                                    qrt = fyr["TieuDeNhom"].ToString();
                                    if (qrt.Contains("/"))
                                        period.EndTitle = qrt.Substring(0, qrt.LastIndexOf("/"));
                                    break;
                                default:
                                    break;
                            }
                        }
                        if (period != null) { period.UpdateTitle(); periods.Add(period); }
                        profile.FinancePeriods = periods;

                        //profile - financeInfo

                        var fit = sql.GetChiTieuFinance(stock.Symbol);
                        var fvt = sql.GetFinanceData(stock.Symbol);
                        var groupId = 0;
                        FinanceInfo info = null;
                        foreach (DataRow fir in fit.Rows)
                        {
                            if (info == null || groupId != int.Parse(fir["LoaiChiTieu"].ToString()))
                            {
                                if (info != null) financeInfo.Add(info);
                                info = new FinanceInfo() { NhomChiTieuId = groupId, Symbol = stock.Symbol, TenNhomChiTieu = fir["TenLoaiChiTieu"].ToString() };
                            }
                            groupId = int.Parse(fir["LoaiChiTieu"].ToString());
                            var chiTieu = new FinanceChiTieu() { ChiTieuId = fir["MaChiTieu"].ToString(), TenChiTieu = fir["TieuDeKhac"].ToString() };
                            if (fir["MaChiTieu"].ToString() == "ROA")
                            {
                                int b = 0;
                            }
                            foreach (var financePeriod in periods)
                            {
                                var fvrs = fvt.Select("MaChiTieu = '" + fir["MaChiTieu"] + "' AND Year = " + financePeriod.Year + " AND QuarterType = " + financePeriod.Quarter);
                                if (fvrs.Length > 0)
                                {
                                    chiTieu.Values.Add(new FinanceValue() { Quarter = financePeriod.Quarter, Year = financePeriod.Year, Value = double.Parse(fvrs[0]["FinanceValue"].ToString()) });
                                }
                                else
                                {
                                    chiTieu.Values.Add(new FinanceValue() { Quarter = financePeriod.Quarter, Year = financePeriod.Year, Value = 0 });
                                }
                            }

                            info.ChiTieus.Add(chiTieu);
                        }
                        if (info != null) financeInfo.Add(info);
                        profile.financeInfos = financeInfo;
                    }
                    catch (Exception ex)
                    {
                        ////log.WriteEntry(symbol + " : FinanceInfo : " + ex.ToString(), EventLogEntryType.Error);
                        ret = false;
                    }
                }

                //profile - leader
                if (!bExisted || related.Contains("SC"))
                {
                    try
                    {
                        var leaders = new List<Leader>();
                        var ldt = sql.GetCeos(stock.Symbol);
                        foreach (DataRow ldr in ldt.Rows)
                        {
                            leaders.Add(new Leader() { GroupID = ldr["ParentId"].ToString(), Name = ldr["FullName"].ToString(), Positions = ldr["TenNhom"].ToString() });
                        }
                        profile.Leaders = leaders;
                    }
                    catch (Exception ex)
                    {
                        ////log.WriteEntry(symbol + " : Leaders : " + ex.ToString(), EventLogEntryType.Error);
                        ret = false;
                    }
                }

                //profile - owner
                if (!bExisted || related.Contains("SH"))
                {
                    try
                    {
                        var owners = new List<MajorOwner>();
                        var odt = sql.GetShareHolders(stock.Symbol);
                        foreach (DataRow odr in odt.Rows)
                        {
                            owners.Add(new MajorOwner() { Name = odr["FullName"].ToString(), Rate = double.Parse(odr["ShareHoldPct"].ToString()), ToDate = (DateTime)odr["DenNgay"], Volume = double.Parse(odr["SoCoPhieu"].ToString()) });
                        }
                        profile.MajorOwners = owners;
                    }
                    catch (Exception ex)
                    {
                        ////log.WriteEntry(symbol + " : Owners : " + ex.ToString(), EventLogEntryType.Error);
                        ret = false;
                    }
                }

                //profile - CEO
                if (!bExisted || related.Contains("SCN"))
                {
                    try
                    {
                        var ceos = new List<StockCeo>();
                        var cdt = sql.GetCeosNew(stock.Symbol);
                        foreach (DataRow cdr in cdt.Rows)
                        {
                            var ceo = new StockCeo() { CeoId = int.Parse(cdr["CeoId"].ToString()), CeoCode = cdr["CeoCode"].ToString(), GroupID = int.Parse(cdr["PositionType"].ToString()), Name = cdr["CeoName"].ToString(), Positions = cdr["PositionName"].ToString(), Process = cdr["CeoProfileShort"].ToString(), Age = 0 };
                            var birthday = cdr["CeoBirthday"].ToString();
                            if (birthday.Contains("/"))
                            {
                                int year;
                                if (!int.TryParse(birthday.Substring(birthday.LastIndexOf("/") + 1), out year)) year = 0;
                                if (year > 0)
                                {
                                    if (year < 100) year = 1900 + year;
                                    ceo.Age = year;
                                }
                            }
                            ceos.Add(ceo);
                        }
                        profile.AssociatedCeo = ceos;
                    }
                    catch (Exception ex)
                    {
                        ////log.WriteEntry(symbol + " : CEO New : " + ex.ToString(), EventLogEntryType.Error);
                        ret = false;
                    }
                }

                stock.CompanyProfile = profile;
                /*================================*/

                //dividend histories
                if (!bExisted || related.Contains("SD"))
                {
                    try
                    {
                        var divs = new List<DividendHistory>();
                        var ddt = sql.GetDividendHistory(stock.Symbol);
                        foreach (DataRow ddr in ddt.Rows)
                        {
                            divs.Add(new DividendHistory() { DonViDoiTuong = ddr["DonViDoiTuong"].ToString(), NgayGDKHQ = (DateTime)ddr["NgayGDKHQ"], GhiChu = ddr["GhiChu"].ToString(), SuKien = ddr["SuKien"].ToString(), Symbol = stock.Symbol, TiLe = ddr["TiLe"].ToString() });
                        }
                        stock.DividendHistorys = divs;
                    }
                    catch (Exception ex)
                    {
                        //log.WriteEntry(symbol + " : Dividend : " + ex.ToString(), EventLogEntryType.Error);
                        ret = false;
                    }
                }

                //báo cáo phân tích
                if (!bExisted || related.Contains("SA"))
                {
                    try
                    {
                        var reports = new List<Reports>();
                        var rdt = sql.GetAnalysisReports(stock.Symbol);
                        foreach (DataRow rdr in rdt.Rows)
                        {
                            reports.Add(new Reports() { ID = int.Parse(rdr["ID"].ToString()), Title = rdr["title"].ToString(), DateDeploy = (DateTime)rdr["PublishDate"], ResourceCode = rdr["Source"].ToString(), IsHot = rdr["IsHot"].ToString().ToLower() == "true" });
                        }
                        stock.Reports3 = reports;
                    }
                    catch (Exception ex)
                    {
                        //log.WriteEntry(symbol + " : AnalyseReport : " + ex.ToString(), EventLogEntryType.Error);
                        ret = false;
                    }
                }

                //công ty cùng ngành
                if (!bExisted || related.Contains("SCA"))
                {
                    try
                    {
                        var samecateCompanies = new List<StockShortInfo>();
                        var scdt = sql.GetSameCateCompanies(stock.Symbol);
                        foreach (DataRow scdr in scdt.Rows)
                        {
                            samecateCompanies.Add(new StockShortInfo() { Symbol = scdr["StockSymbol"].ToString(), TradeCenterId = int.Parse(scdr["TradeCenterId"].ToString()), Name = scdr["FullName"].ToString(), EPS = double.Parse(scdr["EPS"].ToString()) });
                        }
                        stock.SameCategory = samecateCompanies;
                    }
                    catch (Exception ex)
                    {
                        //log.WriteEntry(symbol + " : SameCate : " + ex.ToString(), EventLogEntryType.Error);
                        ret = false;
                    }
                }

                //eps tương đương
                if (!bExisted || related.Contains("SEPS"))
                {
                    try
                    {
                        var sameEPSCompanies = new List<StockShortInfo>();
                        var sedt = sql.GetSameEPSCompanies(stock.Symbol);
                        foreach (DataRow sedr in sedt.Rows)
                        {
                            sameEPSCompanies.Add(new StockShortInfo() { Symbol = sedr["StockSymbol"].ToString(), TradeCenterId = int.Parse(sedr["TradeCenterId"].ToString()), Name = sedr["FullName"].ToString(), EPS = double.Parse(sedr["EPS"].ToString()), MarketValue = double.Parse(sedr["MarketCap"].ToString()) });
                        }
                        stock.SameEPS = sameEPSCompanies;
                    }
                    catch (Exception ex)
                    {
                        //log.WriteEntry(symbol + " : SameEPS : " + ex.ToString(), EventLogEntryType.Error);
                        ret = false;
                    }
                }

                //pe tương đương
                if (!bExisted || related.Contains("SPE"))
                {
                    try
                    {
                        var samePECompanies = new List<StockShortInfo>();
                        var spdt = sql.GetSamePECompanies(stock.Symbol);
                        foreach (DataRow spdr in spdt.Rows)
                        {
                            samePECompanies.Add(new StockShortInfo() { Symbol = spdr["StockSymbol"].ToString(), TradeCenterId = int.Parse(spdr["TradeCenterId"].ToString()), Name = spdr["FullName"].ToString(), EPS = double.Parse(spdr["EPS"].ToString()), MarketValue = double.Parse(spdr["MarketCap"].ToString()) });
                        }
                        stock.SamePE = samePECompanies;
                    }
                    catch (Exception ex)
                    {
                        ////log.WriteEntry(symbol + " : SamePE : " + ex.ToString(), EventLogEntryType.Error);
                        ret = false;
                    }
                }

                //stock history
                var history = bExisted ? stock.StockPriceHistory : new StockCompactHistory();

                //stock history - price
                if (!bExisted || related.Contains("SP"))
                {
                    try
                    {
                        var price = new List<PriceCompactHistory>();
                        var pdt = sql.GetPriceHistory(stock.Symbol, 10);
                        foreach (DataRow pdr in pdt.Rows)
                        {
                            price.Add(new PriceCompactHistory() { ClosePrice = double.Parse(pdr["Price"].ToString()), BasicPrice = double.Parse(pdr["BasicPrice"].ToString()), Ceiling = double.Parse(pdr["Ceiling"].ToString()), Floor = double.Parse(pdr["Floor"].ToString()), Volume = double.Parse(pdr["Volume"].ToString()), TotalValue = double.Parse(pdr["TotalValue"].ToString()), TradeDate = (DateTime)pdr["TradeDate"] });
                        }
                        history.Price = price;
                    }
                    catch (Exception ex)
                    {
                        //log.WriteEntry(symbol + " : Price : " + ex.ToString(), EventLogEntryType.Error);
                        ret = false;
                    }
                }

                //stock history - order
                if (!bExisted || related.Contains("SO"))
                {
                    try
                    {
                        var order = new List<OrderCompactHistory>();
                        var hodt = sql.GetOrderHistory(stock.Symbol, 10);
                        foreach (DataRow hodr in hodt.Rows)
                        {
                            order.Add(new OrderCompactHistory() { AskAverageVolume = double.Parse(hodr["AskAverage"].ToString()), AskLeft = double.Parse(hodr["AskLeft"].ToString()), BidAverageVolume = double.Parse(hodr["BidAverage"].ToString()), BidLeft = double.Parse(hodr["BidLeft"].ToString()), TradeDate = (DateTime)hodr["Trading_Date"] });
                        }
                        history.Orders = order;
                    }
                    catch (Exception ex)
                    {
                        //log.WriteEntry(symbol + " : Order : " + ex.ToString(), EventLogEntryType.Error);
                        ret = false;
                    }
                }

                //stock history - foreign
                if (!bExisted || related.Contains("SFT"))
                {
                    try
                    {
                        var foreign = new List<ForeignCompactHistory>();
                        var fdt = sql.GetForeignHistory(stock.Symbol, 10);
                        foreach (DataRow fdr in fdt.Rows)
                        {
                            foreign.Add(new ForeignCompactHistory() { BuyPercent = double.Parse(fdr["FBuyPercent"].ToString()), SellPercent = double.Parse(fdr["FSellPercent"].ToString()), NetVolume = double.Parse(fdr["FNetVolume"].ToString()), NetValue = double.Parse(fdr["FNetValue"].ToString()), TradeDate = (DateTime)fdr["Trading_Date"] });
                        }
                        history.Foreign = foreign;
                    }
                    catch (Exception ex)
                    {
                        //log.WriteEntry(symbol + " : Foreign : " + ex.ToString(), EventLogEntryType.Error);
                        ret = false;
                    }
                }

                stock.StockPriceHistory = history;
                /*====================*/

                //tin tức và sự kiện
                if (!bExisted || related.Contains("SN"))
                {
                    try
                    {
                        //var news = new List<StockNews>();
                        //var ndt = sql.GetCompanyNews(stock.Symbol, -1);
                        //foreach (DataRow ndr in ndt.Rows)
                        //{
                        //    news.Add(new StockNews() { DateDeploy = (DateTime)ndr["PostTime"], ID = int.Parse(ndr["Id"].ToString()), Title = ndr["Title"].ToString(), TypeID = ndr["ConfigId"].ToString() });
                        //}
                        //stock.StockNews = news;
                        var keylist = string.Format(RedisKey.KeyCompanyNewsByStock, stock.Symbol, 0); //Tất cả
                        var ls = new List<string>();
                        var pdt = sql.GetCompanyNews(stock.Symbol, -1);

                        var key1 = string.Format(RedisKey.KeyCompanyNewsByStock, stock.Symbol, 1); //Tình hình SXKD & Phân tích khác
                        var key2 = string.Format(RedisKey.KeyCompanyNewsByStock, stock.Symbol, 2); // Cổ tức - Chốt quyền
                        var key3 = string.Format(RedisKey.KeyCompanyNewsByStock, stock.Symbol, 3); // Thay đổi nhân sự
                        var key4 = string.Format(RedisKey.KeyCompanyNewsByStock, stock.Symbol, 4); // Tăng vốn - Cổ phiếu quỹ
                        var key5 = string.Format(RedisKey.KeyCompanyNewsByStock, stock.Symbol, 5); // GD cđ lớn & cđ nội bộ
                        var cate1 = new List<string>();
                        var cate2 = new List<string>();
                        var cate3 = new List<string>();

                        var cate4 = new List<string>();
                        var cate5 = new List<string>();
                        var stocknews = new List<StockNews>();
                        foreach (DataRow rdr in pdt.Rows)
                        {
                            var compact = new StockNews() { ID = int.Parse(rdr["ID"].ToString()), Body = "", DateDeploy = (DateTime)rdr["PostTime"], Image = "", Title = rdr["title"].ToString(), Sapo = "", TypeID = rdr["ConfigId"].ToString(), Symbol = rdr["StockSymbols"].ToString() };
                            var obj = new StockNews() { ID = int.Parse(rdr["ID"].ToString()), Body = rdr["Content"].ToString(), DateDeploy = (DateTime)rdr["PostTime"], Image = rdr["ImagePath"].ToString(), Title = rdr["title"].ToString(), Sapo = rdr["SubContent"].ToString(), TypeID = rdr["ConfigId"].ToString(), Symbol = rdr["StockSymbols"].ToString() };
                            for (int i = 0xD800; i < 0xDFFF; i++)
                            {
                                obj.Body.Replace((char)i, ' ');
                            }

                            if (stocknews.Count < 6) { stocknews.Add(compact); }
                            var newskey = obj.DateDeploy.ToString("yyyyMMddHHmm") + obj.ID;
                            var compactkey = string.Format(RedisKey.KeyCompanyNewsCompact, obj.ID);
                            var detailkey = string.Format(RedisKey.KeyCompanyNewsDetail, obj.ID);
                            if (redis.ContainsKey(compactkey))
                                redis.Set(compactkey, compact);
                            else
                                redis.Add(compactkey, compact);
                            if (redis.ContainsKey(detailkey))
                                redis.Set(detailkey, obj);
                            else
                                redis.Add(detailkey, obj);

                            if (!ls.Contains(newskey)) ls.Add(newskey);
                            #region Update category list
                            if (obj.TypeID.Contains("1"))
                            {
                                if (!cate1.Contains(newskey)) cate1.Add(newskey);
                            }
                            else
                            {
                                if (cate1.Contains(newskey)) cate1.Remove(newskey);
                            }
                            if (obj.TypeID.Contains("2"))
                            {
                                if (!cate2.Contains(newskey)) cate2.Add(newskey);
                            }
                            else
                            {
                                if (cate2.Contains(newskey)) cate2.Remove(newskey);
                            }
                            if (obj.TypeID.Contains("3"))
                            {
                                if (!cate3.Contains(newskey)) cate3.Add(newskey);
                            }
                            else
                            {
                                if (cate3.Contains(newskey)) cate3.Remove(newskey);
                            }
                            if (obj.TypeID.Contains("4"))
                            {
                                if (!cate4.Contains(newskey)) cate4.Add(newskey);
                            }
                            else
                            {
                                if (cate4.Contains(newskey)) cate4.Remove(newskey);
                            }
                            if (obj.TypeID.Contains("5"))
                            {
                                if (!cate5.Contains(newskey)) cate5.Add(newskey);
                            }
                            else
                            {
                                if (cate5.Contains(newskey)) cate5.Remove(newskey);
                            }
                            #endregion
                        }
                        stock.StockNews = stocknews;

                        ls.Sort();
                        ls.Reverse();
                        if (redis.ContainsKey(keylist))
                            redis.Set(keylist, ls);
                        else
                            redis.Add(keylist, ls);
                        #region Update category list
                        cate1.Sort();
                        cate1.Reverse();
                        if (redis.ContainsKey(key1))
                            redis.Set(key1, cate1);
                        else
                            redis.Add(key1, cate1);
                        cate2.Sort();
                        cate2.Reverse();
                        if (redis.ContainsKey(key2))
                            redis.Set(key2, cate2);
                        else
                            redis.Add(key2, cate2);
                        cate3.Sort();
                        cate3.Reverse();
                        if (redis.ContainsKey(key3))
                            redis.Set(key3, cate3);
                        else
                            redis.Add(key3, cate3);
                        cate4.Sort();
                        cate4.Reverse();
                        if (redis.ContainsKey(key4))
                            redis.Set(key4, cate4);
                        else
                            redis.Add(key4, cate4);
                        cate5.Sort();
                        cate5.Reverse();
                        if (redis.ContainsKey(key5))
                            redis.Set(key5, cate5);
                        else
                            redis.Add(key5, cate5);
                        #endregion
                    }
                    catch (Exception ex)
                    {
                        //log.WriteEntry(symbol + " : News : " + ex.ToString(), EventLogEntryType.Error);
                        ret = false;
                    }
                }
                #endregion

                if (redis.ContainsKey(key))
                    redis.Set<Stock>(key, stock);
                else
                    redis.Add<Stock>(key, stock);
            }
            catch (Exception ex)
            {
                ////log.WriteEntry(symbol + ": " + ex.ToString(), EventLogEntryType.Error);
                ret = false;
            }

            return ret;
        }
Ejemplo n.º 2
0
 private void button23_Click(object sender, EventArgs e)
 {
     var redis = new RedisClient(ConfigRedis.Host, ConfigRedis.Port);
     var sql = new SqlDb();
     sql.OpenDb();
     var date = "";
     #region Lịch sự kiện
     var lskdt = sql.GetLichSuKien(date);
     var keys = redis.ContainsKey(RedisKey.KeyLichSuKien) ? redis.Get<List<string>>(RedisKey.KeyLichSuKien) : new List<string>();
     var removals = keys.FindAll(s => s.Substring(0, 8) == date.Replace(".", ""));
     foreach (var removal in removals)
     {
         var key = string.Format(RedisKey.KeyLichSuKienObject, removal.Substring(removal.LastIndexOf(":") + 1));
         if (redis.ContainsKey(key)) redis.Remove(key);
         keys.Remove(removal);
     }
     foreach (DataRow ldr in lskdt.Rows)
     {
         var o = new LichSuKien() { ID = int.Parse(ldr["ID"].ToString()), LoaiSuKien = ldr["EventType_List"].ToString(), MaCK = ldr["StockSymbols"].ToString(), MaSan = 0, News_ID = ldr["News_ID"].ToString(), Title = ldr["EventTitle"].ToString(), NgayBatDau = ldr["NgayBatDau"].ToString(), NgayKetThuc = ldr["NgayKetThuc"].ToString(), NgayThucHien = ldr["NgayThucHien"].ToString(), TenCty = "", TomTat = "", PostDate = (DateTime) ldr["PostDate"]};
         try
         {
             o.EventDate = (DateTime) ldr["EventDate"];
         }catch(Exception)
         {
             o.EventDate = DateTime.Parse("2000-01-01");
         }
         var key = string.Format(RedisKey.KeyLichSuKienObject, o.ID);
         if (redis.ContainsKey(key))
             redis.Set(key, o);
         else
             redis.Add(key, o);
         key = string.Format(RedisKey.KeyLichSuKienObjectInList, o.EventDate.ToString("yyyyMMdd"), string.IsNullOrEmpty(o.LoaiSuKien.Trim())? "_" : o.LoaiSuKien, o.ID);
         if (!keys.Contains(key)) keys.Add(key);
     }
     if (redis.ContainsKey(RedisKey.KeyLichSuKien))
         redis.Set(RedisKey.KeyLichSuKien, keys);
     else
         redis.Add(RedisKey.KeyLichSuKien, keys);
     #endregion
     #region Lịch sự kiện tóm tắt
     lskdt = sql.GetLichSuKienTomTat();
     var lls = new List<LichSuKien>();
     foreach (DataRow ldr in lskdt.Rows)
     {
         var o = new LichSuKien() { ID = int.Parse(ldr["ID"].ToString()), LoaiSuKien = ldr["EventType_List"].ToString(), MaCK = ldr["StockSymbols"].ToString(), MaSan = 0, News_ID = ldr["News_ID"].ToString(), Title = ldr["EventTitle"].ToString(), NgayBatDau = ldr["NgayBatDau"].ToString(), NgayKetThuc = ldr["NgayKetThuc"].ToString(), NgayThucHien = ldr["NgayThucHien"].ToString(), TenCty = "", TomTat = "", PostDate = (DateTime)ldr["PostDate"] };
         try
         {
             o.EventDate = (DateTime)ldr["EventDate"];
         }
         catch (Exception)
         {
             o.EventDate = DateTime.Parse("2000-01-01");
         }
         lls.Add(o);
     }
     if (redis.ContainsKey(RedisKey.KeyLichSuKienTomTat))
         redis.Set(RedisKey.KeyLichSuKienTomTat, lls);
     else
         redis.Add(RedisKey.KeyLichSuKienTomTat, lls);
     #endregion
     sql.CloseDb();
 }
Ejemplo n.º 3
0
        private void button2_Click(object sender, EventArgs e)
        {
            var redis = new RedisClient(ConfigRedis.Host, ConfigRedis.Port);
            var sql = new SqlDb();
            #region FN
            try
            {
                var keylist = string.Format(RedisKey.KeyCompanyNewsByCate, 0); //Tất cả
                var ls = new List<string>();

                var pdt = sql.GetCompanyNews("A", 1000);

                var key1 = string.Format(RedisKey.KeyCompanyNewsByCate, 1); //Tình hình SXKD & Phân tích khác
                var key2 = string.Format(RedisKey.KeyCompanyNewsByCate, 2); // Cổ tức - Chốt quyền
                var key3 = string.Format(RedisKey.KeyCompanyNewsByCate, 3); // Thay đổi nhân sự
                var key4 = string.Format(RedisKey.KeyCompanyNewsByCate, 4); // Tăng vốn - Cổ phiếu quỹ
                var key5 = string.Format(RedisKey.KeyCompanyNewsByCate, 5); // GD cđ lớn & cđ nội bộ
                var cate1 = (redis.ContainsKey(key1)) ? redis.Get<List<string>>(key1) : new List<string>();

                var cate2 = (redis.ContainsKey(key2)) ? redis.Get<List<string>>(key2) : new List<string>();
                var cate3 = (redis.ContainsKey(key3)) ? redis.Get<List<string>>(key3) : new List<string>();

                var cate4 = (redis.ContainsKey(key4)) ? redis.Get<List<string>>(key4) : new List<string>();
                var cate5 = (redis.ContainsKey(key5)) ? redis.Get<List<string>>(key5) : new List<string>();

                foreach (DataRow rdr in pdt.Rows)
                {
                    var compact = new StockNews() { ID = int.Parse(rdr["ID"].ToString()), Body = "", DateDeploy = (DateTime)rdr["PostTime"], Image = "", Title = rdr["title"].ToString(), Sapo = "", TypeID = rdr["ConfigId"].ToString(), Symbol = rdr["StockSymbols"].ToString() };
                    var obj = new StockNews() { ID = int.Parse(rdr["ID"].ToString()), Body = rdr["Content"].ToString(), DateDeploy = (DateTime)rdr["PostTime"], Image = rdr["ImagePath"].ToString(), Title = rdr["title"].ToString(), Sapo = rdr["SubContent"].ToString(), TypeID = rdr["ConfigId"].ToString(), Symbol = rdr["StockSymbols"].ToString() };
                    var key = obj.DateDeploy.ToString("yyyyMMddHHmm") + obj.ID;
                    var compactkey = string.Format(RedisKey.KeyCompanyNewsCompact, obj.ID);
                    if (redis.ContainsKey(compactkey))
                        redis.Set(compactkey, compact);
                    else
                        redis.Add(compactkey, compact);
                    var detailkey = string.Format(RedisKey.KeyCompanyNewsDetail, obj.ID);
                    if (redis.ContainsKey(detailkey))
                        redis.Set(detailkey, obj);
                    else
                        redis.Add(detailkey, obj);

                    if (!ls.Contains(key)) ls.Add(key);
                    #region Update category list
                    if (obj.TypeID.Contains("1"))
                    {
                        if (!cate1.Contains(key)) cate1.Add(key);
                    }
                    else
                    {
                        if (cate1.Contains(key)) cate1.Remove(key);
                    }
                    if (obj.TypeID.Contains("2"))
                    {
                        if (!cate2.Contains(key)) cate2.Add(key);
                    }
                    else
                    {
                        if (cate2.Contains(key)) cate2.Remove(key);
                    }
                    if (obj.TypeID.Contains("3"))
                    {
                        if (!cate3.Contains(key)) cate3.Add(key);
                    }
                    else
                    {
                        if (cate3.Contains(key)) cate3.Remove(key);
                    }
                    if (obj.TypeID.Contains("4"))
                    {
                        if (!cate4.Contains(key)) cate4.Add(key);
                    }
                    else
                    {
                        if (cate4.Contains(key)) cate4.Remove(key);
                    }
                    if (obj.TypeID.Contains("5"))
                    {
                        if (!cate5.Contains(key)) cate5.Add(key);
                    }
                    else
                    {
                        if (cate5.Contains(key)) cate5.Remove(key);
                    }
                    #endregion
                }
                ls.Sort();
                ls.Reverse();
                if (redis.ContainsKey(keylist))
                    redis.Set(keylist, ls);
                else
                    redis.Add(keylist, ls);
                #region Update category list
                cate1.Sort();
                cate1.Reverse();
                if (redis.ContainsKey(key1))
                    redis.Set(key1, cate1);
                else
                    redis.Add(key1, cate1);
                cate2.Sort();
                cate2.Reverse();
                if (redis.ContainsKey(key2))
                    redis.Set(key2, cate2);
                else
                    redis.Add(key2, cate2);
                cate3.Sort();
                cate3.Reverse();
                if (redis.ContainsKey(key3))
                    redis.Set(key3, cate3);
                else
                    redis.Add(key3, cate3);
                cate4.Sort();
                cate4.Reverse();
                if (redis.ContainsKey(key4))
                    redis.Set(key4, cate4);
                else
                    redis.Add(key4, cate4);
                cate5.Sort();
                cate5.Reverse();
                if (redis.ContainsKey(key5))
                    redis.Set(key5, cate5);
                else
                    redis.Add(key5, cate5);
                #endregion
            }
            catch (Exception ex)
            {
                //log.WriteEntry(symbol + " : FN : " + ex.ToString(), EventLogEntryType.Error);
                //ret = false;
            }
            #endregion

            var topkey = RedisKey.KeyTop20News;
            var ndt = sql.GetCompanyNews("A", 100);
            var topls = new List<StockNews>();
            foreach (DataRow ndr in ndt.Rows)
            {
                var da = (DateTime)ndr["PostTime"];
                //if (double.Parse(da.ToString("yyyyMMddHHmm")) > double.Parse(DateTime.Now.ToString("yyyyMMddHHmm"))) continue;
                topls.Add(new StockNews() { ID = int.Parse(ndr["ID"].ToString()), Body = "", DateDeploy = (DateTime)ndr["PostTime"], Image = "", Title = ndr["title"].ToString(), Sapo = "", TypeID = ndr["ConfigId"].ToString(), Symbol = ndr["StockSymbols"].ToString() });
                // if (topls.Count >= 20) break;
            }
            if (redis.ContainsKey(topkey))
                redis.Set(topkey, topls);
            else
                redis.Add(topkey, topls);
        }
Ejemplo n.º 4
0
        private void button22_Click(object sender, EventArgs e)
        {
            var redis = new RedisClient(ConfigRedis.Host, ConfigRedis.Port);
            var keys = redis.SearchKeys(string.Format(RedisKey.BDSKey, "*"));
            var sql = new SqlDb();
            sql.OpenDb();
            var dt = sql.GetAllLandProjects();
            var i = 0;
            foreach (var key in keys)
            {
                //ceo:ceocode:{0}:Object
                var t = key.Replace("tiendoBDS:tiendocode:", "").Replace(":Object", "");
                if (dt.Select("MaTienDo = '" + t + "'").Length == 0)
                {
                    redis.Remove(key);
                    i++;
                }
            }
            sql.CloseDb();

            MessageBox.Show(i.ToString("#,##0"));
        }
Ejemplo n.º 5
0
        private void button17_Click(object sender, EventArgs e)
        {

            var symbol = "SCR";
            var redis = new RedisClient(ConfigRedis.Host, ConfigRedis.Port);
            var sql = new SqlDb();
            var test = redis.Get<TienDoBDS>(string.Format(RedisKey.BDSKey, "SCR_07"));

            //var ls = redis.Get<List<TienDoBDS>>(key) ?? new List<TienDoBDS>();
            var ldt = sql.GetLandProject(symbol);
            var adt = sql.GetLandProject_Area(symbol);
            var pdt = sql.GetLandProject_Profit(symbol);
            foreach (DataRow ldr in ldt.Rows)
            {
                var key = string.Format(RedisKey.BDSKey, ldr["MaTienDo"].ToString());
                var o = new TienDoBDS() { MaCK = ldr["MaCK"].ToString(), MaTienDo = ldr["MaTienDo"].ToString(), TenDuAn = ldr["TenDuAn"].ToString(), HinhThucKinhDoanh = ldr["HinhThucKinhDoanh"].ToString(), DiaDiem = ldr["DiaDiem"].ToString(), ThanhPho = ldr["ThanhPho"].ToString(), TongVon = decimal.Parse(ldr["TongVon"].ToString()), Donvi = ldr["Donvi"].ToString(), TyLeGhopVon = ldr["TyLeGhopVon"].ToString(), TyLeDenBu = ldr["TyLeDenBu"].ToString(), GhiChu = ldr["GhiChu"].ToString(), MoTa = ldr["Mota"].ToString(), URL = ldr["URL"].ToString(), ID = int.Parse(ldr["ID"].ToString()), BDSImages = GetLandImages(ldr["MaTienDo"].ToString()) };
                DateTime d;
                if (DateTime.TryParse(ldr["ViewDate"].ToString(), out d))
                {
                    o.ViewDate = d;      
                }
              
                var adrs = adt.Select("MaTienDo='" + o.MaTienDo + "'");
                var als = new List<TienDoBDSDienTich>();
                foreach(var adr in adrs)
                {
                    als.Add(new TienDoBDSDienTich(){MaTienDo = o.MaTienDo, DienTich = decimal.Parse(adr["DienTich"].ToString()), LoaiDienTich = adr["LoaiDienTich"].ToString()});
                }
                o.DienTichs = als;

                var pdrs = pdt.Select("MaTienDo='" + o.MaTienDo + "'");
                var pls = new List<TienDoBDSLoiNhuan>();
                foreach (var pdr in pdrs)
                {
                    pls.Add(new TienDoBDSLoiNhuan() { MaTienDo = o.MaTienDo, LoiNhuanDoanhThu = decimal.Parse(pdr["LoiNhuanDoanhThu"].ToString()), LoaiLoiNhuan = pdr["LoaiLoiNhuan"].ToString() });
                }
                o.LoiNhuans = pls;

                if (redis.ContainsKey(key))
                    redis.Set(key, o);
                else
                    redis.Add(key, o);

                //ls.Add(o);
            }

            var a = 0;
        }
Ejemplo n.º 6
0
        private void button16_Click(object sender, EventArgs e)
        {
            var redis = new RedisClient(ConfigRedis.Host, ConfigRedis.Port);
            var key = string.Format(RedisKey.KeyCompanyNewsDetail, 32639);

            var sql = new SqlDb();
            var pdt = sql.GetCompanyNews("VNM", -1);

            var stocknews = new List<StockNews>();
            foreach (DataRow rdr in pdt.Rows)
            {
                var compact = new StockNews() { ID = int.Parse(rdr["ID"].ToString()), Body = "", DateDeploy = (DateTime)rdr["PostTime"], Image = "", Title = rdr["title"].ToString(), Sapo = "", TypeID = rdr["ConfigId"].ToString(), Symbol = rdr["StockSymbols"].ToString() };
                var obj = new StockNews() { ID = int.Parse(rdr["ID"].ToString()), Body = rdr["Content"].ToString(), DateDeploy = (DateTime)rdr["PostTime"], Image = rdr["ImagePath"].ToString(), Title = rdr["title"].ToString(), Sapo = rdr["SubContent"].ToString(), TypeID = rdr["ConfigId"].ToString(), Symbol = rdr["StockSymbols"].ToString() };


                if (obj.ID == 32639)
                {
                    redis.Set<StockNews>(key, obj);
                }
            }
            var o2 = redis.Get<StockNews>(key);
        }
Ejemplo n.º 7
0
        private void button14_Click(object sender, EventArgs e)
        {
            var redis = new RedisClient(ConfigRedis.Host, ConfigRedis.Port);
            var symbol = "CEO_00662";
            var sql = new SqlDb();
            #region CEO

            var ceokey = string.Format(RedisKey.CeoKey, symbol);
            var cdt = sql.GetCeosNew_Profile(symbol);
            if (cdt.Rows.Count == 0)
            {
                if (redis.ContainsKey(ceokey)) redis.Remove(ceokey);
            }
            else
            {
                var ceo = new Ceo();
                ceo.CeoName = cdt.Rows[0]["CeoName"].ToString(); ceo.CeoBirthday = cdt.Rows[0]["CeoBirthday"].ToString(); ceo.CeoIdNo = cdt.Rows[0]["CeoIdNo"].ToString(); ceo.CeoAchievements = cdt.Rows[0]["CeoAchievements"].ToString(); ceo.CeoHomeTown = cdt.Rows[0]["CeoHomeTown"].ToString(); ceo.CeoSchoolDegree = cdt.Rows[0]["CeoLevel"].ToString();
                ceo.CeoCode = cdt.Rows[0]["CeoCode"].ToString();
                if (ceo.CeoBirthday != "" && ceo.CeoBirthday.Contains("/"))
                {
                    ceo.CeoBirthday = ceo.CeoBirthday.Substring(ceo.CeoBirthday.LastIndexOf("/") + 1);
                }
                ceo.CeoImage = "";
                //photo
                //school title
                var css = new List<CeoSchool>();
                var sdt = sql.GetCeosNew_School(symbol);
                foreach (DataRow sdr in sdt.Rows)
                {
                    css.Add(new CeoSchool() { CeoTitle = sdr["CeoTitle"].ToString(), SchoolTitle = sdr["SchoolTitle"].ToString(), SchoolYear = sdr["SchoolYear"].ToString() });
                }
                ceo.CeoSchool = css;

                //ceo position
                var cps = new List<CeoPosition>();
                var pdt = sql.GetCeosNew_Position(symbol);
                foreach (DataRow pdr in pdt.Rows)
                {
                    var cp = new CeoPosition() { PositionTitle = pdr["PositionTitle"].ToString(), PositionCompany = pdr["PositionCompany"].ToString() };
                    if (string.IsNullOrEmpty(cp.PositionTitle)) cp.PositionTitle = pdr["PositionName"].ToString();
                    if (string.IsNullOrEmpty(cp.PositionCompany)) cp.PositionCompany = pdr["FullName"].ToString();

                    //__/01/2007
                    string cpd = pdr["CeoPosDate"].ToString();
                    if (cpd.Contains("/"))
                    {
                        int day, month, year;
                        if (!int.TryParse(cpd.Substring(0, cpd.IndexOf("/")), out day)) day = 0;
                        cpd = cpd.Substring(cpd.IndexOf("/") + 1);
                        if (!int.TryParse(cpd.Substring(0, cpd.IndexOf("/")), out month)) month = 0;
                        cpd = cpd.Substring(cpd.IndexOf("/") + 1);
                        if (!int.TryParse(cpd, out year)) year = 0;
                        if (year == 0)
                        {
                            cp.CeoPosDate = "";
                        }
                        else if (day == 0 && month == 0)
                        {
                            cp.CeoPosDate = "" + year;
                        }
                        else if (month > 0 && day == 0)
                        {
                            cp.CeoPosDate = month + "/" + year;
                        }
                        else if (day > 0 && month > 0)
                        {
                            cp.CeoPosDate = day + "/" + month + "/" + year;
                        }
                        else
                        {
                            cp.CeoPosDate = "";
                        }
                    }

                    cps.Add(cp);
                }
                ceo.CeoPosition = cps;

                //asset
                var cas = new List<CeoAsset>();
                var adt = sql.GetCeosNew_Asset(symbol);
                foreach (DataRow adr in adt.Rows)
                {
                    cas.Add(new CeoAsset() { Symbol = adr["Symbol"].ToString(), AssetVolume = double.Parse(adr["AssetVolume"].ToString()).ToString("#,##0"), UpdatedDate = ((DateTime)adr["UpdatedDate"]).ToString("MM/yyyy") });
                }
                ceo.CeoAsset = cas;

                //relation
                var crs = new List<CeoRelation>();
                var rdt = sql.GetCeosNew_Relation(symbol);
                foreach (DataRow rdr in rdt.Rows)
                {
                    crs.Add(new CeoRelation() { Symbol = rdr["Symbol"].ToString(), AssetVolume = double.Parse(rdr["AssetVolume"].ToString()).ToString("#,##0"), UpdatedDate = ((DateTime)rdr["UpdatedDate"]).ToString("MM/yyyy"), Name = rdr["CeoName"].ToString(), CeoCode = rdr["CeoCode"].ToString(), RelationTitle = rdr["RelationTitle"].ToString() });
                }
                ceo.CeoRelation = crs;

                //process
                var cos = new List<CeoProcess>();
                var odt = sql.GetCeosNew_Process(symbol);
                foreach (DataRow odr in odt.Rows)
                {
                    cos.Add(new CeoProcess() { ProcessBegin = odr["ProcessBegin"].ToString(), ProcessEnd = odr["ProcessEnd"].ToString(), ProcessDesc = odr["ProcessDesc"].ToString(), Symbol = odr["Symbol"].ToString()});
                }
                ceo.CeoRelation = crs;

                //news
                var cns = new List<CeoNews>();
                var wdt = sql.GetCeosNew_News(symbol);
                var ids = "";
                foreach (DataRow ndr in wdt.Rows)
                {
                    ids += "," + ndr["NewsId"];
                }
                var wdt2 = sql.GetCeosNew_NewsDetail(ids);
                foreach (DataRow ndr in wdt2.Rows)
                {
                    cns.Add(new CeoNews() { Title = ndr["News_Title"].ToString(), PublishDate = (DateTime)ndr["News_PublishDate"], NewsLink = string.Format("/{0}CA{1}/{2}.chn", ndr["News_Id"], ndr["Cat_ID"], CafeF.Redis.BL.Utils.UnicodeToKoDauAndGach(ndr["News_Title"].ToString())) });
                }
                ceo.CeoRelation = crs;

                if (redis.ContainsKey(ceokey))
                {
                    redis.Set(ceokey, ceo);
                }
                else
                {
                    redis.Add(ceokey, ceo);
                }
            }
            #endregion
        }
Ejemplo n.º 8
0
        private void button9_Click(object sender, EventArgs e)
        {
            var redis = new RedisClient(ConfigRedis.Host, ConfigRedis.Port);
            var sql = new SqlDb();
            var keylist = RedisKey.KeyAnalysisReport;
            var ls = new List<string>();
            var pdt = sql.GetAnalysisReports("A", 2000);
            foreach (DataRow rdr in pdt.Rows)
            {
                var key = string.Format(RedisKey.KeyAnalysisReportDetail, rdr["ID"]);
                var obj = new Reports() { ID = int.Parse(rdr["ID"].ToString()), Body = rdr["Des"].ToString(), DateDeploy = (DateTime)rdr["PublishDate"], file = new FileObject() { FileName = rdr["FileName"].ToString(), FileUrl = "http://images1.cafef.vn/Images/Uploaded/DuLieuDownload/PhanTichBaoCao/" + rdr["FileName"] }, IsHot = (rdr["IsHot"].ToString() == "1"), ResourceCode = rdr["Source"].ToString(), Symbol = rdr["Symbol"].ToString(), Title = rdr["title"].ToString(), SourceID = int.Parse(rdr["SourceId"].ToString()), ResourceName = rdr["SourceFullName"].ToString(), ResourceLink = rdr["SourceUrl"].ToString() };
                var id = obj.DateDeploy.ToString("yyyyMMdd") + obj.ID;
                if (redis.ContainsKey(key))
                    redis.Set(key, obj);
                else
                    redis.Add(key, obj);
                if (!ls.Contains(id)) ls.Add(id);
            }
            //ls.Add("201101131222");
            //ls.Add("201103021220");
            ls.Sort();
            ls.Reverse();

            if (redis.ContainsKey(keylist))
                redis.Set(keylist, ls);
            else
                redis.Add(keylist, ls);
            MessageBox.Show(ls[0]);
        }