public void AddToPriceGroup(int priceGroupId, IList <PriceBase> priceBaseToAdd) { PriceGroup priceGroup = GetById(priceGroupId); List <CurrencyRateView> currencyRateViews = ControllerManager.CurrencyRate.GetAllRates() as List <CurrencyRateView>; this.BeginTransaction(); foreach (PriceBase priceBase in priceBaseToAdd) { PriceAttribute priceAttribute = new PriceAttribute(); priceAttribute.PriceGroup = priceGroup; priceAttribute.PriceBase = priceBase; CurrencyRateView cr = currencyRateViews.Find(delegate(CurrencyRateView record) { if (record.FromCurrency == priceBase.PriceListCurrency && record.ToCurrency == priceGroup.Currency) { return(true); } return(false); }); priceAttribute.Price = priceBase.PriceList * cr.Rate; priceAttribute.PriceCurrency = priceGroup.Currency; priceAttribute.CurrencyRate = cr.ToCurrencyRate; priceAttribute.PricePurchaseCurrencyRate = priceBase.PricePurchaseCurrencyRate; priceAttribute.PriceSuggestCurrencyRate = priceBase.PriceSuggestCurrencyRate; NHibernateSession.Save(priceAttribute); } CommitChanges(); }
public static void CheckTarget() { //Console.WriteLine("checkingtarget1:" + CheckingTarget); if (CheckingTarget) { //Console.WriteLine("checkingtarget2:" + CheckingTarget); PairWatching = CurrencyRateController.CurrencyData[TargetPairName]; //Console.WriteLine(PairWatching.Bid + " " + TargetValue); if (TargetIsAbove) { if (TargetValue <= PairWatching.Bid) { CurrencyRateView.TargetNotification(); CheckingTarget = false; //Console.WriteLine("checkingtarget3A:" + CheckingTarget); } } else { if (TargetValue >= PairWatching.Bid) { CurrencyRateView.TargetNotification(); CheckingTarget = false; //Console.WriteLine("checkingtarget3B:" + CheckingTarget); } } //Console.WriteLine("checkingtarget3:" + CheckingTarget); } }
private void ProcessRecords() { Utils.GetLogger().Debug("Processing Records"); foreach (PriceBase priceBase in priceBases) { // Ignore if ((priceBase.PricePurchase == 0 && priceBase.PriceSuggest == 0) || priceBase.Status != PriceBaseStatus.NotVerified) { continue; } List <PriceCalculation> lstPriceCalculationCopy = new List <PriceCalculation>(priceCalculations); // Remove formulas with TP if (priceBase.PricePurchase == 0) { lstPriceCalculationCopy = priceCalculations.FindAll(delegate(PriceCalculation record) { if (!record.Formula.Contains("TP")) { return(true); } return(false); }); } // Remove formulas with GRP else if (priceBase.PriceSuggest == 0) { lstPriceCalculationCopy = priceCalculations.FindAll(delegate(PriceCalculation record) { if (!record.Formula.Contains("GRP")) { return(true); } return(false); }); } // Find default formula PriceCalculation defaultPriceCalculation = lstPriceCalculationCopy.Find(delegate(PriceCalculation record) { if (record.Priority == PriceCalculationPriority.Default) { return(true); } return(false); }); int providerId = priceBase.Provider.ID; List <IDIDView> productCategories = lstProductByCategories.FindAll(delegate(IDIDView record) { if (record.Id1 == priceBase.Product.ID) { return(true); } return(false); } ); if (lstPriceCalculationCopy.Count > 0) { lstPriceCalculationCopy = lstPriceCalculationCopy.FindAll(delegate(PriceCalculation record) { if (record.Provider != null && record.Provider.ID == providerId && record.CategoryBase != null && productCategories.Count > 0) { if (productCategories.Exists(delegate(IDIDView record2) { if (record2.Id2 == record.CategoryBase.ID) { return(true); } return(false); })) { return(true); } } if (record.Provider != null && record.Provider.ID == providerId && record.CategoryBase == null) { return(true); } if (record.Provider == null && record.CategoryBase != null && productCategories.Count > 0) { if (productCategories.Exists(delegate(IDIDView record2) { if (record2.Id2 == record.CategoryBase.ID) { return(true); } return(false); })) { return(true); } } return(false); }); } // If there is a better formula than Default, set it. PriceCalculation selectedPriceCalculation = lstPriceCalculationCopy.Count > 0 ? lstPriceCalculationCopy[0] : defaultPriceCalculation; // If no formula found, return; if (selectedPriceCalculation == null) { continue; } Utils.GetLogger().Debug(string.Format("Selected formula {0} for PriceBase [{1}/{2}]", selectedPriceCalculation.Formula, priceBase.Product.ID, priceBase.Provider.ID)); // Find current rate for PriceSuggest CurrencyRateView currentRate = currencyRateViews.Find(delegate(CurrencyRateView record) { if (record.FromCurrency.ID == priceBase.PriceSuggestCurrency.ID && record.ToCurrency.ID == priceBase.PriceListCurrency.ID) { return(true); } return(false); }); object[] loCodeParms = new object[2]; loCodeParms[0] = priceBase.PriceSuggest * currentRate.Rate; // Find current rate for PricePurchase currentRate = currencyRateViews.Find(delegate(CurrencyRateView record) { if (record.FromCurrency.ID == priceBase.PricePurchaseCurrency.ID && record.ToCurrency.ID == priceBase.PriceListCurrency.ID) { return(true); } return(false); }); loCodeParms[1] = priceBase.PricePurchase * currentRate.Rate; Utils.GetLogger().Debug(string.Format("Executing formula {0} for PriceBase [{1}/{2}]", selectedPriceCalculation.Formula, priceBase.Product.ID, priceBase.Provider.ID)); // Calculate with the specified formula decimal finalPriceList = Convert.ToDecimal(loObject.GetType().InvokeMember("Formula" + selectedPriceCalculation.ID.ToString(), BindingFlags.InvokeMethod, null, loObject, loCodeParms)); // Ignore if same price if (finalPriceList == priceBase.PriceList) { continue; } //// Create the Price Base history record if needed. //if (createHistory) // ControllerManager.PriceBaseHistory.SaveAudit(priceBase, HistoryStatus.ModificationPolitics, userId); // Assign new price priceBase.PriceList = finalPriceList; priceBase.TimeStamp.ModifiedOn = DateTime.Now; if (userId.HasValue) { priceBase.TimeStamp.ModifiedBy = userId; } Utils.GetLogger().Debug(string.Format("Setting price of {0} for PriceBase [{1}/{2}]", finalPriceList, priceBase.Product.ID, priceBase.Provider.ID)); } priceBases.Clear(); Utils.GetLogger().Debug("Finish executing data for Price Calculator"); }