public bool UpdateExRates(IDalSession DataSession) { theCurrencies = InstrumentMapper.GetCurrencies(DataSession); ICurrency loadedCurrency = null; List<exRateDate> innerRates = null; bool isDirty = false; foreach (KeyValuePair<DateTime, List<exRateDate>> de in theDates.OrderBy(x => x.Key)) { innerRates = de.Value; foreach (exRateDate erd in innerRates) { if (isCurrencyLoaded(erd.rateCurrency, ref loadedCurrency)) { HistoricalExRate newRate = new HistoricalExRate(loadedCurrency, erd.rate , erd.rateDate, 0m, 0m, 1m); if (!(loadedCurrency.HistoricalExRates.ContainsExRate(newRate))) { loadedCurrency.HistoricalExRates.AddExRate(newRate); isDirty = true; } else if (loadedCurrency.HistoricalExRates.GetItemByDate(newRate.RateDate).Rate != newRate.Rate) { loadedCurrency.HistoricalExRates.GetItemByDate(newRate.RateDate).Rate = newRate.Rate; isDirty = true; } } } } if (isDirty) { foreach (ICurrency currency in theCurrencies) { InstrumentMapper.Update(DataSession, currency); // Hashtable parameters = new Hashtable(); // parameters.Add("InstrumentID", currency.Key); // DataSession.ExecuteStoredProcedure("EXEC dbo.TG_FillHistExRatesWeekendsHolidays @InstrumentID = :InstrumentID", parameters); } } return true; }
public static bool UpdateInstrumentPriceHistory(int[] dateKeys, int instrumentId, decimal newQuantity, bool ignoreWarning, out string errMessage) { bool success = true; errMessage = ""; if (dateKeys == null || dateKeys.Count() == 0) throw new B4F.TotalGiro.ApplicationLayer.Common.GridviewNoSelectionException(); DateTime[] dates = dateKeys .Select(k => getDataFromPriceHistoryKey(k).Item1) .OrderBy(k => k) .ToArray(); using (IDalSession session = NHSessionFactory.CreateSession()) { IInstrument instrument = InstrumentMapper.GetInstrument(session, instrumentId); List<DateTime> notExistingDates = new List<DateTime>(); bool saveStuff = false; if (instrument != null) { switch (instrument.SecCategory.Key) { case SecCategories.Cash: IList<IHistoricalExRate> exRates = HistoricalExRateMapper.GetHistoricalExRates(session, instrumentId, dates); if (exRates != null && exRates.Count > 0) { foreach (DateTime date in dates) { IHistoricalExRate exRate = exRates.Where(x => x.RateDate == date).FirstOrDefault(); if (exRate != null) { if (exRate.Rate != newQuantity) { exRate.Rate = newQuantity; if (!ignoreWarning) ignoreWarning = CheckNewRate(session, exRate, false, out errMessage); if (!string.IsNullOrEmpty(errMessage)) return false; saveStuff = true; } } else notExistingDates.Add(date); } } else notExistingDates.AddRange(dates); if (saveStuff) session.Update(exRates); saveStuff = false; ICurrency currency = instrument.ToCurrency; foreach (DateTime date in notExistingDates) { IHistoricalExRate newExRate = new HistoricalExRate(currency, newQuantity, date); currency.HistoricalExRates.AddExRate(newExRate); if (!ignoreWarning) ignoreWarning = CheckNewRate(session, newExRate, false, out errMessage); if (!string.IsNullOrEmpty(errMessage)) return false; saveStuff = true; } if (saveStuff) InstrumentMapper.Update(session, currency); break; default: IInstrumentsWithPrices iwp = (IInstrumentsWithPrices)instrument; Price newPrice = new Price(newQuantity, iwp.CurrencyNominal, iwp); IList<IHistoricalPrice> prices = HistoricalPriceMapper.GetHistoricalPrices(session, instrumentId, dates); if (prices != null && prices.Count > 0) { foreach (DateTime date in dates) { IHistoricalPrice price = prices.Where(x => x.Date == date).FirstOrDefault(); if (price != null) { if (!price.Price.Equals(newPrice)) { price.Price = newPrice; if (!ignoreWarning) ignoreWarning = CheckNewPrice(session, price, false, out errMessage); if (!string.IsNullOrEmpty(errMessage)) return false; saveStuff = true; } } else notExistingDates.Add(date); } } else notExistingDates.AddRange(dates); if (saveStuff) session.Update(prices); saveStuff = false; foreach (DateTime date in notExistingDates) { IHistoricalPrice newHistoricalPrice = new HistoricalPrice(newPrice, date); iwp.HistoricalPrices.AddHistoricalPrice(newHistoricalPrice); if (!ignoreWarning) ignoreWarning = CheckNewPrice(session, newHistoricalPrice, false, out errMessage); if (!string.IsNullOrEmpty(errMessage)) return false; saveStuff = true; } if (saveStuff) InstrumentMapper.Update(session, iwp); break; } } } return success; }
public static void UpdateHistoricalExRate(DateTime Date, bool ignoreWarning, decimal newQuantity, int original_InstrumentId) { IDalSession session = NHSessionFactory.CreateSession(); ICurrency currency = InstrumentMapper.GetCurrency(session, original_InstrumentId); IHistoricalExRate historicalExRate = HistoricalExRateMapper.GetHistoricalExRate(session, currency, Date); if (historicalExRate == null) { IHistoricalExRate newExRate = new HistoricalExRate(currency, newQuantity, Date); currency.HistoricalExRates.AddExRate(newExRate); if (!ignoreWarning) InstrumentPriceUpdateAdapter.CheckNewRate(session, newExRate); InstrumentMapper.Update(session, currency); } else { if (historicalExRate.Rate != newQuantity) { historicalExRate.Rate = newQuantity; if (!ignoreWarning) InstrumentPriceUpdateAdapter.CheckNewRate(session, historicalExRate); HistoricalExRateMapper.Update(session, historicalExRate); } } session.Close(); }
public static void UpdateInstrumentPriceHistory(decimal newQuantity, bool ignoreWarning, int DateKey, int Key, int instrumentId) { using (IDalSession session = NHSessionFactory.CreateSession()) { IInstrument instrument = InstrumentMapper.GetInstrument(session, instrumentId); var res = getDataFromPriceHistoryKey(DateKey); DateTime date = res.Item1; bool exist = res.Item2; if (instrument != null) { switch (instrument.SecCategory.Key) { case SecCategories.Cash: if (exist) { IHistoricalExRate newExRate = HistoricalExRateMapper.GetHistoricalExRate(session, Key); if (newExRate.Rate != newQuantity) { newExRate.Rate = newQuantity; if (!ignoreWarning) CheckNewRate(session, newExRate); HistoricalExRateMapper.Update(session, newExRate); } } else { ICurrency currency = instrument.ToCurrency; IHistoricalExRate newExRate = new HistoricalExRate(currency, newQuantity, date); currency.HistoricalExRates.AddExRate(newExRate); if (!ignoreWarning) CheckNewRate(session, newExRate); InstrumentMapper.Update(session, currency); } break; default: IInstrumentsWithPrices iwp = (IInstrumentsWithPrices)instrument; Price price = new Price(newQuantity, iwp.CurrencyNominal, iwp); if (exist) { IHistoricalPrice newPrice = HistoricalPriceMapper.GetHistoricalPrice(session, Key); if (newPrice.Price != price) { newPrice.Price = price; if (!ignoreWarning) CheckNewPrice(session, newPrice); HistoricalPriceMapper.Update(session, newPrice); } } else { IHistoricalPrice newPrice = new HistoricalPrice(price, date); iwp.HistoricalPrices.AddHistoricalPrice(newPrice); if (!ignoreWarning) CheckNewPrice(session, newPrice); InstrumentMapper.Update(session, iwp); } break; } } } }
private bool processLine(string text, DateTime currencyDate) { Currency loadedCurrency = null; string[] theParts = text.Split(new char[] { ' ' }); if ((theParts[0].Length == 3) && ((theParts[0])[0] != ' ')) { if (isCurrencyLoaded(theParts[0], ref loadedCurrency)) { HistoricalExRate newRate = new HistoricalExRate(loadedCurrency, Decimal.Parse(theParts[theParts.GetUpperBound(0)]), currencyDate, 0m, 0m, 1m); if (!(loadedCurrency.HistoricalExRates.ContainsExRate(newRate))) { loadedCurrency.HistoricalExRates.AddExRate(newRate); } } Console.WriteLine(theParts[0].ToString()); return true; } return false; }