示例#1
0
      }//calculateListPrice

      //-----------------------------------------------------------------------------------------------------//

      private double GetCurrency(PriceRecord priceRecord)
      {
         PriceListRecord priceListRecord = null;
         try
         {
            currencyData = ws.CreateObject("CurrencyData");
            double xRate = 1;
            priceListRecord = (PriceListRecord)ws.CreateObject("PriceListRecord");
            string priceListName = (String)SDOHelper.Read(priceRecord, "EXT_REF");
            SDOHelper.Write(priceListRecord, "REFERENCE", priceListName);
            if (!priceListRecord.Find(false))
               return xRate;

            int currCode = (sbyte)SDOHelper.Read(priceListRecord, "CURRENCY") + 1;
            double baseCurrencyCode = (double)sageUserSet.baseCurrCode;
            if (currCode != baseCurrencyCode)
            {
               currencyData.Read(currCode);
               xRate = (double)SDOHelper.Read(currencyData, "EXCHANGE_RATE");
            }//If

            return xRate;
         }
         finally
         {
            if (priceListRecord != null)
            {
               Marshal.FinalReleaseComObject(priceListRecord);
               priceListRecord = null;
            }//If
         }//Finally

      }//getCurrency
        public async Task <IActionResult> PutProductShop(int id, ProductShop productShop)
        {
            if (id != productShop.ProductShopId)
            {
                return(BadRequest());
            }
            var pr = new PriceRecord();

            pr.Price     = productShop.Price;
            pr.PriceDate = productShop.PriceDate;

            productShop.AddRecord(pr);
            _context.Entry(productShop).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductShopExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#3
0
        public string Run(List <PriceRecord> tradeData)
        {
            decimal highestGap = 0;
            var     buyPrice   = new PriceRecord();
            var     sellPrice  = new PriceRecord();

            foreach (var openingPriceRecord in tradeData)
            {
                // sell candidates should be prices after openingPriceRecord.DayOfMonth, and greater than openingPriceRecord.Value
                var sellCandidates = tradeData
                                     .Where(x => x.DayOfMonth > openingPriceRecord.DayOfMonth)
                                     .Where(x => x.Value > openingPriceRecord.Value);

                foreach (var sellCandidate in sellCandidates)
                {
                    var gap = sellCandidate.Value - openingPriceRecord.Value;
                    if (gap > highestGap)
                    {
                        buyPrice   = openingPriceRecord;
                        sellPrice  = sellCandidate;
                        highestGap = gap;
                    }
                }
            }

            return($"{buyPrice.DayOfMonth}({buyPrice.Value}),{sellPrice.DayOfMonth}({sellPrice.Value})");
        }
示例#4
0
        private void CapList(int itemId)
        {
            PriceRecord temp = _context.ListTrends.Where(e => e.TrackListId == itemId &&
                                                         e.DaysAgo == 30).ToList()[0];

            _context.Remove(temp);
            _context.SaveChanges();
        }
示例#5
0
        public async Task <ActionResult> DbUpdate(string authKey)
        {
            if (authKey != MailConfig.SendPass)
            {
                return(NoContent());
            }
            var Listings = _context.TrackLists.Where(e => e.UserId != 7).ToList();

            foreach (var item in Listings)
            {
                float price = 0f;
                try
                {
                    string[] info = await PriceScraper.FetchData(item.PageUrl);

                    price = float.Parse(info[1]);
                    if (item.MaxPrice >= price)
                    {
                        MailSender.MakeEmail(item.ListedEmail, item.ItemName,
                                             info[1], item.PageUrl, item.Vendor);
                    }
                }
                catch
                {
                    RemoveItem(item.Id);
                    continue;
                }

                var nodes = _context.ListTrends.Where(e => e.TrackListId == item.Id).ToList();

                bool isMax = false;
                nodes.ForEach(e => e.DaysAgo += 1);
                if (nodes.Count == 30)
                {
                    isMax = true;
                }
                PriceRecord NewNode = new PriceRecord
                {
                    DaysAgo     = 0,
                    Price       = price,
                    ItemName    = item.ItemName,
                    TrackListId = item.Id
                };
                _context.ListTrends.Add(NewNode);
                _context.SaveChanges();

                if (isMax)
                {
                    CapList(item.Id);
                }
            }

            return(Ok());
        }
示例#6
0
        private List <PriceRecord> BuildModelFromFileContents(IReadOnlyList <string> data)
        {
            var list = new List <PriceRecord>();

            for (var index = 0; index < data.Count; index++)
            {
                var priceAsDecimal = Convert.ToDecimal(data[index]);
                var priceRecord    = new PriceRecord {
                    DayOfMonth = index + 1, Value = priceAsDecimal
                };
                list.Add(priceRecord);
            }

            return(list);
        }
示例#7
0
        private async Task <ActionResult> AppendPriceRecord(string itemName, float price, int uid)
        {
            var tmpId = _context.TrackLists.SingleOrDefault(t =>
                                                            t.ItemName == itemName && t.UserId == uid);

            PriceRecord pr = new PriceRecord
            {
                DaysAgo     = 0,
                Price       = price,
                ItemName    = itemName,
                TrackListId = tmpId.Id
            };

            _context.ListTrends.Add(pr);
            await _context.SaveChangesAsync();

            return(NoContent());
        }
示例#8
0
        public override List <PriceRecord> GetPriceRecords(DateTime lastDateTime)
        {
            if (!IsAvailable)
            {
                return(new List <PriceRecord>());
            }

            var priceRecords = new List <PriceRecord>();

            var tickerUrl = Properties.Settings.Default.RavaUrl + "?";

            tickerUrl = Parameters.Aggregate(tickerUrl, (current, parameter) => current + (parameter.Key + "=" + parameter.Value + "&"));

            tickerUrl = tickerUrl.TrimEnd(new [] { '&' });

            var client            = new WebClient();
            var input             = client.DownloadString(tickerUrl);
            var matchSymbolValues = Regex.Matches(input,
                                                  @"<td>(\d{2})\/(\d{2})\/(\d{2})<\/td><td>(\d[\d.,]+)<\/td><td>(\d[\d.,]+)<\/td><td>(\d[\d.,]+)<\/td><td>(\d[\d.,]+)<\/td><td>(\d[\d.,]+)",
                                                  RegexOptions.Singleline);

            foreach (Match match in matchSymbolValues)
            {
                var date = new DateTime(Int32.Parse("20" + match.Groups[3].Value),
                                        Int32.Parse(match.Groups[2].Value),
                                        Int32.Parse(match.Groups[1].Value));
                if (date <= lastDateTime)
                {
                    break;
                }
                var pr = new PriceRecord(new MetaLibDate(date), float.Parse(match.Groups[4].Value),
                                         float.Parse(match.Groups[5].Value),
                                         float.Parse(match.Groups[6].Value), float.Parse(match.Groups[7].Value),
                                         float.Parse(match.Groups[8].Value));
                priceRecords.Add(pr);
            }

            priceRecords = priceRecords.OrderBy(x => x.Date.Date).ToList();

            return(priceRecords);
        }
示例#9
0
      }//parseExMsg

      //------------------------------------------------------------------------------------------------------------------//

      /// <summary>
      /// Make sure all objects are released for garbage collection.
      /// </summary>
      public void DestroyAllObjects()
      {
         if (priceRecord != null)
         {
            Marshal.FinalReleaseComObject(priceRecord);
            priceRecord = null;
         }//If
         if (salesRecord != null)
         {
            Marshal.FinalReleaseComObject(salesRecord);
            salesRecord = null;
         }//If
         if (currencyData != null)
         {
            Marshal.FinalReleaseComObject(currencyData);
            currencyData = null;
         }//If
         if (stockRecord != null)
         {
            Marshal.FinalReleaseComObject(stockRecord);
            stockRecord = null;
         }//If

         if (ws != null)
         {
            ws.Disconnect();
            Marshal.FinalReleaseComObject(ws);
            ws = null;
         }//If

         if (sdo != null)
         {
            Marshal.FinalReleaseComObject(sdo);
            sdo = null;
         }//If

      }//DestroyAllObjects
示例#10
0
        public override List <PriceRecord> GetPriceRecords(DateTime lastDateTime)
        {
            if (!IsAvailable)
            {
                return(new List <PriceRecord>());
            }

            var symbolId = Parameters["SymbolId"];

            var priceRecords = new List <PriceRecord>();

            var tickerUrl         = Properties.Settings.Default.IOLCsvUrl + symbolId;
            var client            = new WebClient();
            var symbolCsv         = client.DownloadString(tickerUrl);
            var matchSymbolValues = Regex.Matches(symbolCsv,
                                                  @"(\d{4}-\d{2}-\d{2}) \d{2}:\d{2}:\d{2};([\d,]+);([\d,]+);([\d,]+);([\d,]+);([\d,.]+)",
                                                  RegexOptions.Singleline);

            foreach (Match match in matchSymbolValues)
            {
                var date = DateTime.Parse(match.Groups[1].Value);
                if (date <= lastDateTime)
                {
                    break;
                }
                var pr = new PriceRecord(new MetaLibDate(date), float.Parse(match.Groups[2].Value),
                                         float.Parse(match.Groups[3].Value),
                                         float.Parse(match.Groups[4].Value), float.Parse(match.Groups[5].Value),
                                         float.Parse(match.Groups[6].Value));
                priceRecords.Add(pr);
            }

            priceRecords = priceRecords.OrderBy(x => x.Date.Date).ToList();

            return(priceRecords);
        }
 public MinPriceCalculatorStrategy(Product product, Price parent)
 {
     _product      = product ?? throw new ArgumentNullException(nameof(product), @"Product cannot be null.");
     _parentRecord = _product.Links.First(l => l.PriceRecord.PriceNavigation == parent).PriceRecord;
 }
示例#12
0
 /// <summary>
 /// Adds the current <see cref="PriceRecord"/> to the passed <see cref="QifDocument"/>
 /// </summary>
 /// <param name="document"><see cref="QifDocument"/> to which the transaction is added</param>
 public void Yield(QifDocument document)
 {
     document.AddTransaction(GetType().Name, item);
     item = new PriceRecord();
 }
        public void Seed()
        {
            if (_context.Shop.Any() ||
                _context.Brand.Any() ||
                _context.Product.Any() ||
                _context.ProductShops.Any() ||
                _context.PriceRecords.Any())
            {
                return;
            }

            Address a1 = new(1, "Goiás", "Aparecida de Goiânia", "Nova Olinda", "Av. Santana");
            Address a2 = new(2, "Goiás", "Aparecida de Goiânia", "Parque Itamarati", "Av. Maria Lopes");


            Shop s1 = new(3, "Cristo Rei 2", a1);
            Shop s2 = new(4, "Armazem Castro", a2);


            Brand b1 = new(5, "Sadia");
            Brand b2 = new(6, "Perdigão");


            Product p1 = new(7, "Coxa e sobre-coxa", "img1", "Carne", b1);
            Product p2 = new(8, "Coxa e sobre-coxa", "img2", "Carne", b1);

            ProductShop ps1 = new(1, p1, s1, 11.00, DateTime.Today);
            ProductShop ps2 = new(2, p2, s1, 11.00, DateTime.Today);

            ProductShop ps3 = new(3, p1, s2, 12.00, DateTime.Today);
            ProductShop ps4 = new(4, p2, s2, 12.00, DateTime.Today);

            PriceRecord pr1 = new PriceRecord(1, ps1, ps1.Price, ps1.PriceDate);
            PriceRecord pr2 = new PriceRecord(2, ps2, ps2.Price, ps2.PriceDate);
            PriceRecord pr3 = new PriceRecord(3, ps3, ps3.Price, ps3.PriceDate);
            PriceRecord pr4 = new PriceRecord(4, ps4, ps4.Price, ps4.PriceDate);

            ps1.AddRecord(pr1);
            ps1.AddRecord(pr2);
            ps1.AddRecord(pr3);
            ps1.AddRecord(pr4);

            b1.InsertProduct(p1);
            b2.InsertProduct(p2);

            b1.InsertProduct(p1);
            b2.InsertProduct(p2);

            s1.AddProduct(ps1);
            s1.AddProduct(ps2);

            s2.AddProduct(ps3);
            s2.AddProduct(ps4);

            _context.ProductShops.AddRange(ps1, ps2, ps3, ps4);
            _context.PriceRecords.AddRange(pr1, pr2, pr3, pr4);
            _context.Shop.AddRange(s1, s2);
            _context.Brand.AddRange(b1, b2);
            _context.Product.AddRange(p1, p2);

            _context.SaveChanges();
        }
示例#14
0
      }//CTOR

      //-------------------------------------------------------------------------------------------------------//

      /// <summary>
      /// Reads all invoices and stores it's values in a List.
      /// </summary>
      /// <param name="customersFileName"></param>
      public MyDictionary<MyDictionary<double>> ReadPriceListData()
      {
         //PriceListActivity set to new() so null is not returned.
         MyDictionary<MyDictionary<double>> PriceListActivity = new MyDictionary<MyDictionary<double>>();
         try
         {
            sdo = new SDOEngine();
            //Try a connection, will throw an exception if it fails
            ws = (WorkSpace)sdo.Workspaces.Add("App Server Update");
            ws.Connect(sageUserSet.sageDBDir, sageUserSet.sageUsername, sageUserSet.sagePassword, "UniqueUpdater");

            //Dictionary of PriceList Name vs PriceList Data.
            MyDictionary<MyDictionary<double>> miniPLActivity = new MyDictionary<MyDictionary<double>>();
            //Dictionary of PriceList Name vs PriceListUserList.
            MyDictionary<List<string>> plUsers = new MyDictionary<List<string>>();

            //Create instances of the objects
            priceRecord = (PriceRecord)ws.CreateObject("PriceRecord");
            salesRecord = (SalesRecord)ws.CreateObject("SalesRecord");
            stockRecord = (StockRecord)ws.CreateObject("StockRecord");


            //Create a dictionary of PL's that are acually being referenced v's Empty ProductActivities.
            //Single Price Lists can be used for multiple Customers
            salesRecord.MoveFirst();
            do
            {
               string cusCode;
               string cusPriceListRef = ((String)SDOHelper.Read(salesRecord, "PRICE_LIST_REF")).Trim();

               //If pLists already contains PL then add customer to it's entry. Else make new entry if not empty string.
               if (plUsers.ContainsKey(cusPriceListRef))
               {
                  cusCode = (String)SDOHelper.Read(salesRecord, "ACCOUNT_REF");
                  plUsers[cusPriceListRef].Add(cusCode);
               }
               else if (!cusPriceListRef.Equals(String.Empty))
               {
                  plUsers[cusPriceListRef] = new List<string>();
                  cusCode = (String)SDOHelper.Read(salesRecord, "ACCOUNT_REF");
                  plUsers[cusPriceListRef].Add(cusCode);

                  //Add new entry for each priceList.
                  miniPLActivity[cusPriceListRef] = new MyDictionary<double>();
               }//Else

            } while (salesRecord.MoveNext());

            Dictionary<string, double> productActivity = null;
            string plName = String.Empty;
            string plNamePrev = String.Empty;
            double calcValue;
            int calcMeth;
            double xRate = 1;
            double costPrice;
            double salePrice;
            double listPrice;
            string stockCode;

            //Start at first pricerecord
            priceRecord.MoveFirst();
            do
            {
               //Get first stock code in Price List.
               stockCode = (String)SDOHelper.Read(priceRecord, "STOCK_CODE");
               //Create SDO stockRecord with this stockCode to use for searching later.
               SDOHelper.Write(stockRecord, "STOCK_CODE", stockCode);

               plName = ((string)SDOHelper.Read(priceRecord, "EXT_REF")).Trim();
               calcValue = (double)SDOHelper.Read(priceRecord, "VALUE");
               calcMeth = (sbyte)SDOHelper.Read(priceRecord, "DISCOUNT_TYPE");
               salePrice = (double)SDOHelper.Read(stockRecord, "SALES_PRICE");
               costPrice = CheckProduct(stockCode).CostPrice;

               if (plName.Equals(plNamePrev))
               {
                  //Old plName: Check stock, if found get it's list price & add to productActivity from PLACtivity.
                  if (stockRecord.Find(false))
                  {
                     listPrice = CalculateListPrice(calcValue, calcMeth, costPrice, salePrice, xRate);
                     productActivity[stockCode] = listPrice;
                  }//If
               }
               else if (miniPLActivity.ContainsKey(plName))
               {
                  //New name: Check stock, if found get it's list price & add to productActivity from PLACtivity. 
                  //Change plNamePrev
                  //Get new currency, keep till next Price List.
                  if (stockRecord.Find(false))
                  {
                     xRate = GetCurrency(priceRecord);
                     listPrice = CalculateListPrice(calcValue, calcMeth, costPrice, salePrice, xRate);
                     productActivity = miniPLActivity[plName];
                     productActivity[stockCode] = listPrice;
                     plNamePrev = plName;
                  }//If
               }//Else

            } while (priceRecord.MoveNext());


            //Give each customer their own PriceList.
            foreach (string key in plUsers.Keys)
            {
               foreach (string cusCode in plUsers[key])
               {
                  PriceListActivity[cusCode] = miniPLActivity[key];
               }//ForEach
            }//ForEach   
         }
         finally
         {
            DestroyAllObjects();
         }//Finally


         return PriceListActivity;

      }//ReadPriceListData
 public CompositePriceViewModel(PriceRecord priceRecord)
 {
     _priceRecord = priceRecord;
 }