public void SetUp() { priceList = new PriceList <Tire>(); priceList.Add(new Tire("Tire1", 160, 75, CarcassType.Radial, 15), 2500); priceList.Add(new Tire("Tire2", 180, 65, CarcassType.Diagonal, 16), 3000); priceList.Add(new Tire("Tire3", 170, 60, CarcassType.BiasBelt, 13), 2700); }
public void AddPurchase(Purchase purchase) { PurchaseList.Add(purchase); var price = new ItemPrice(purchase.Article.Price, purchase.Amount); PriceList.Add(price); }
private static void Lab7_Example() { var priceList = new PriceList <Tire>(); priceList.Add(new Tire("Hakapelita", 160, 75, CarcassType.Radial, 15), 4000); priceList.Add(new Tire("Kama", 170, 75, CarcassType.Radial, 14), 2500); Console.WriteLine("Test JSON serializing"); TestSerializer(priceList, new TirePriceListJsonSerializer(), "serialize.json"); Console.WriteLine("\nTest XML serializing"); TestSerializer(priceList, new TirePriceListXmlSerializer(), "serialize.xml"); Console.WriteLine("\nTest Binary serializing"); TestSerializer(priceList, new TirePriceListBinarySerializer(), "serialize.bin"); }
public void ContainsTest() { var item = new KeyValuePair <Tire, double>(new Tire("MyTire", 160, 70, CarcassType.Radial, 15), 2600); priceList.Add(item); Assert.IsTrue(priceList.Contains(item)); }
public PriceList GetPriceList() { var list = new PriceList(); var s = $" Period {InvoiceTerm.Start.ToShortDateString()} to {InvoiceTerm.End.ToShortDateString()}."; list.Add(ConsumptionPrice()); // and other consumption dependent components (fees, environment taxes, etc) list.AppendToDescription(s); list.AddRange(StandingCharges()); // and other term dependent components (grid charges, administration, etc) var total = list.Sum(); total.Description = "Total." + s; list.Add(total); return(list); }
public bool AddSku(string id, double price) { if (ValidateSkuEntry(id, price)) { PriceList.Add(id, price); return(PriceList.Any(sku => sku.Key.Equals(id) && sku.Value.Equals(price))); } return(false); }
static void Main(string[] args) { var priceList = new PriceList <Tire>(); priceList.Add(new Tire("Kama1", 160, 70, CarcassType.Radial, 15), 2000); priceList.Add(new Tire("Kama2", 170, 80, CarcassType.Radial, 16), 3000); priceList.Add(new Tire("Kama3", 175, 75, CarcassType.Radial, 15), 2500); priceList.Add(new Tire("Kama4", 165, 65, CarcassType.Radial, 14), 2800); priceList.Add(new Tire("Kama5", 160, 70, CarcassType.Radial, 13), 3500); Console.WriteLine("Diameter = 15"); foreach (var tire in priceList.WithDiameterEqual(15)) { Console.WriteLine(tire); } Console.WriteLine("Price > 2500"); foreach (var tire in priceList.WithPriceGreaterThan(2500)) { Console.WriteLine(tire); } }
public void UpdatePrice() { var topics = intouch.Board.GetTopics(new BoardGetTopicsParams() { GroupId = groupId, Preview = 0, PreviewLength = 0, Order = 2 }).Result; var pricetopic = topics.Data.Items.FirstOrDefault(t => t.Title.ToLower().Contains("commission") || t.Title.ToLower().Contains("price") || t.Title.ToLower().Contains("прайс")); var comments = cit.Board.GetComments(new Citrina.StandardApi.Models.BoardGetCommentsRequest() { AccessToken = serviceToken, GroupId = groupId, TopicId = pricetopic.Id }).Result; AdditionalInfoAboutCommissions = comments.Response.Items.First().Text; var prices = comments.Response.Items.Skip(1).Where(p => p.Text.StartsWith("◄")).ToArray(); PriceList.Clear(); foreach (var pricecomment in prices) { string name = "", cost = "", format = "", addchar = "", size = ""; IEnumerable <PhotosPhoto> examples; var match = Regex.Match(pricecomment.Text, "◄(.+)\\.?\n"); if (match.Success) { name = match.Groups[1].Value; name = name.Trim(new[] { ' ', '.' }); name = name[0].ToString().ToUpper() + name.Substring(1).ToLower(); } match = Regex.Match(pricecomment.Text, "Стоимость: (.+)\n"); if (match.Success) { cost = match.Groups[1].Value; } match = Regex.Match(pricecomment.Text, "персонажа (.+)\n"); if (match.Success) { addchar = match.Groups[1].Value; } match = Regex.Match(pricecomment.Text, "Формат : (\\w+)"); if (match.Success) { format = match.Groups[1].Value; } match = Regex.Match(pricecomment.Text, "Размер: ?(.*)\n"); if (match.Success) { size = match.Groups[1].Value; } examples = pricecomment.Attachments.Select(a => a.Photo).ToArray(); PriceList.Add(new PriceItem(name, cost, addchar, format, size, examples)); } }
private PriceList GetFee() { var list = new PriceList(); var date = Start; while (date < End) { var next = date.AddDays(1); var time = new TimeSpanItem(date, DateTimeExtensions.Min(next, End), TimeSpanUnit.TenMinutes, Rounding.Up); var price = new ItemPrice(FeeParams.UnitFee, time); list.Add(Price.Min(price, FeeParams.DailyFee).AppendToDescription($"Parking time {date} to {next.AddMinutes(-1)}")); date = next; } var total = list.Sum(); total.Description = $"Total fee for parking time {Start} to {End}"; list.Add(total); return(list); }
public void View(IList selectedClients, SessionTariff tariff, Boolean isInternet) { ClientsList = selectedClients; if (!PriceList.Contains(tariff)) { PriceList.Add(tariff); } SelectedTariff = tariff; IsInternetSession = isInternet; this.InitDataContext(); this.ShowDialog(); }
private void brnaddPrices_Click(object sender, EventArgs e) { try { priceList.Add(new Prices(Convert.ToInt32(tbxStugpris.Text), Convert.ToInt32(tbxHusvagnPris.Text), Convert.ToInt32(tbxKWHpris.Text))); } catch (Exception ex) { MessageBox.Show(ex.Message); } tbxPrisLista.Text = "1 Natt i Stuga: " + priceList.Get(0).CabinPrice + Environment.NewLine + "1 Natt i Husvagn: " + priceList.Get(0).TrailerPrice + Environment.NewLine + "1 kWh: " + priceList.Get(0).KwhPrice; }
public PriceList StandingCharges() { var list = new PriceList(); for (var i = 0; i < MonthsInInvoiceTerm; i++) { var term = InvoiceTerm.TermSpan((uint)i); var charge = Contract.MonthlyCharge.Clone().AppendToDescription( $" Period {term.Start.ToShortDateString()} to {term.End.ToShortDateString()}."); list.Add(charge); } return(list); }
public PriceList GetPrice(ICurrencyRateService rateService) { var list = new PriceList(); foreach (var r in Rides) { var currencyRate = rateService.GetRate(CurrencyUnit.EUR, r.UnitPrice.CurrencyUnit, r.Start); var currencyItem = new CurrencyItem(CurrencyUnit.EUR, r.UnitPrice.CurrencyUnit, currencyRate); var distanceItem = new LogisticItem(r.Distance, r.DistanceUnit, Rounding.HalfToEven); var itemPrice = new ItemPrice(r.UnitPrice, distanceItem, currencyItem) { Description = $"Ride from {r.From} to {r.To}." }; list.Add(itemPrice); } var total = list.Sum(); total.Description = $"Total."; list.Add(total); return(list); }
/// <summary> /// Читает из файла XML и десериализует в прайс-лист /// </summary> /// <param name="path">Путь к файлу</param> /// <returns>Прайс-лист</returns> public PriceList <Tire> Deserialize(string path) { Pair[] arr; using (var stream = new StreamReader(path, Encoding.UTF8)) { arr = (Pair[])(new XmlSerializer(typeof(Pair[]))).Deserialize(stream); } var priceList = new PriceList <Tire>(); foreach (var item in arr) { priceList.Add(item.Key, item.Value); } return(priceList); }
/// <summary> /// Читает из бинарного файла и десериализует в прайс-лист /// </summary> /// <param name="path">Путь к файлу</param> /// <returns>Прайс-лист</returns> public PriceList <Tire> Deserialize(string path) { Pair[] arr; using (var stream = File.Open(path, FileMode.Open)) { arr = (Pair[])(new BinaryFormatter()).Deserialize(stream); } var priceList = new PriceList <Tire>(); foreach (var item in arr) { priceList.Add(item.Key, item.Value); } return(priceList); }
public bool TryGetFromCache(string ticker, Exchange?exchange, DateTime?from, DateTime?to, PriceInterval interval, out PriceList prices) { prices = new PriceList(); try { string fileName = $"{ticker}"; if (exchange.HasValue) { fileName += $"_{exchange}"; } if (from.HasValue) { fileName += $"_{from}"; } if (to.HasValue) { fileName += $"_{to}"; } fileName += $"_{interval.ToString()}.csv"; string file = Path.Combine(FOLDER, fileName); if (File.Exists(file)) { string[] lines = File.ReadAllLines(file); for (int i = 1; i < lines.Length; i++) { HistoricalPrice p = HistoricalPrice.From(lines[i]); prices.Add(p); } return(true); } else { return(false); } } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception) { return(false); } #pragma warning restore CA1031 // Do not catch general exception types }
public override PriceList GetPrice(Subscription subscription, DateTime date) { var list = new PriceList() { DiscountReturn(subscription, date), FeeReturn(subscription, date) }; list.ReverseSign(); // because money flows in opposite direction var total = list.Sum(); total.Description = "Total"; list.Add(total); return(list); }
public void View(IList selectedClients) { this.isDifferentSession = true; sliderHGrid.IsEnabled = false; sliderMGrid.IsEnabled = false; ClientsList = selectedClients; var newTarrif = new SessionTariff() { Name = "== Текущий ==", LimitedTimeMode = true, CostPerHourGame = 13, CostPerHourInternet = 13 }; PriceList.Add(newTarrif); SelectedTariff = newTarrif; this.InitDataContext(); this.ShowDialog(); }
private static void Lab6_Example() { PriceList <Tire> priceList = new PriceList <Tire>(); var random = new Random(); for (int i = 0; i < 10000; ++i) { priceList.Add(new Tire("Hakkapelita", 1, 1, CarcassType.Radial, 15), random.Next()); } var progressHolder = new ProgressHolder(); Thread thread = new Thread(() => priceList.Sort(progressHolder)); thread.Start(); Console.Write("Progress: 0%"); while (progressHolder.Progress < 100) { Console.Write("\rProgress: {0}%", progressHolder.Progress); Thread.Sleep(100); } Console.WriteLine("\rProgress: 100%"); thread.Join(); }
public bool TryGetHistoricalPrices(string ticker, Exchange?exchange, DateTime?from, DateTime?to, PriceInterval priceInterval, out PriceList prices, out string errorMessage) { double fromValue; if (from.HasValue) { fromValue = (from.Value - DATE_1970).TotalSeconds; } else { fromValue = (FIRST_DATE - DATE_1970).TotalSeconds; } double toValue; if (to.HasValue) { toValue = (to.Value - DATE_1970).TotalSeconds; } else { toValue = (DateTime.Now - DATE_1970).TotalSeconds; } string content = YahooApiCaller.GetHistoricalPrices(ticker, fromValue, toValue, priceInterval); string[] lines = content.Split('\n'); prices = new PriceList(); for (int i = 1; i < lines.Length; i++) { HistoricalPrice p = HistoricalPrice.From(lines[i]); prices.Add(p); } errorMessage = "ok"; return(true); }
public async Task <IActionResult> Add(string name, int priceListType) { return(await Task.Run(() => { if (!Request.IsAdmin()) { return Json("Nemate dovoljno prava!"); } try { PriceList pl = new PriceList(); pl.Name = name; pl.Type = (PriceListType)priceListType; pl.Add(); return Json("1"); } catch (Exception ex) { AR.ARDebug.Log(ex.ToString()); return Json(ex.ToString()); } })); }
public bool TryGetHistoricalPrices(string ticker, Exchange?exchange, DateTime?from, DateTime?to, PriceInterval interval, out PriceList prices, out string errorMessage) { //https://api.nasdaq.com/api/quote/AAPL/chart?assetclass=stocks&fromdate=2010-04-15&todate=2020-04-15 if (from.HasValue == false) { from = DateTime.Now; } if (to.HasValue == false) { to = DateTime.Now; } bool ok = NasdaqApiCaller.GetPrices(ticker, exchange, from.Value, to.Value, interval, out HttpStatusCode statusCode, out NasdaqResponse nasdaqResponse, out string jsonResponse, out errorMessage); prices = new PriceList(); foreach (var nasdaqPrice in nasdaqResponse.Data.Prices) { HistoricalPrice price = new HistoricalPrice(); price.Close = nasdaqPrice.Price; prices.Add(price); } return(true); }
/// <summary> /// 获取商品的当前价格 /// </summary> private PriceList GetPriceList() { //先忽略平台和skuId,稍后从结果集中过滤 var caller = this._realTime ? (Func<int, string, int, PriceList>)GetPriceFromService : GetPriceFromCache; var list = caller(this._userId, this._equipmentCode, this._goodsId); var result = new PriceList(this._goodsId); foreach (var price in (list ?? result)) { if (this._platType != Enum_PlatType.ALL && !price.ContainsPlatType(this._platType)) { continue; } if (this._skuId != 0 && price.SkuId != this._skuId) { continue; } result.Add(price); } return result; }
private static PriceList ExtraFromJson(string json) { var list = new PriceList(12900); var beginTime = DateTime.Parse("2016-01-29 11:17:48"); var endTime = DateTime.Now.AddHours(10); var platTypeFlag = ConvertToPlatTypeFlag(false, true, true, true); list.Add(new Price(100, 13595, platTypeFlag, EnumActivityType.手机专享, 5, beginTime, endTime)); list.Add(new Price(149)); return list; }
/// <summary> /// 编辑的参数 /// </summary> /// <param name="para"></param> public ConditionBillViewModel(object para) { //需要合约号 下单的类型和价格 以及数量 //触发的类型 KeyValue kv0 = new KeyValue() { Id = 0, Value = "最新价" }; KeyValue kv1 = new KeyValue() { Id = 1, Value = "买一价" }; KeyValue kv2 = new KeyValue() { Id = 2, Value = "卖一价" }; PriceList.Add(kv0); PriceList.Add(kv1); PriceList.Add(kv2); KeyValue ttype0 = new KeyValue() { Id = 0, Value = ">=" }; KeyValue ttype1 = new KeyValue() { Id = 1, Value = "<=" }; TrrigerCondition.Add(ttype0); TrrigerCondition.Add(ttype1); KeyValue kv03 = new KeyValue() { Id = 0, Value = "最新价" }; KeyValue kv13 = new KeyValue() { Id = 1, Value = "买一价" }; KeyValue kv23 = new KeyValue() { Id = 2, Value = "卖一价" }; PriceList3.Add(kv03); PriceList3.Add(kv13); PriceList3.Add(kv23); KeyValue ttype03 = new KeyValue() { Id = 0, Value = ">=" }; KeyValue ttype13 = new KeyValue() { Id = 1, Value = "<=" }; TrrigerCondition3.Add(ttype03); TrrigerCondition3.Add(ttype13); }
private ConditionBillViewModel(ConditionBillModelViewModel condtion) { //需要合约号 下单的类型和价格 以及数量 _IsEnabled = false; ContractCode = condtion.ContractCode; VarietyModel vm = null; string[] values = condtion.ContractCode.Split(' '); if (values.Length != 3) { return; } string varietie = values[1]; if (ContractVariety.Varieties.ContainsKey(varietie)) { vm = ContractVariety.Varieties[varietie]; } if (vm == null) { return; } Increment = vm.tick_size; lend = vm.precision; typePrice = condtion.PriceType; if (typePrice == "M") { IsTypePrice = Visibility.Visible; IsPrice = Visibility.Collapsed; Price = 0; PriceTypeBill = "市价"; _priceType = "市价"; } else if (typePrice == "R") { Price = 0; PriceTypeBill = "对手价"; _priceType = "对手价"; IsTypePrice = Visibility.Visible; IsPrice = Visibility.Collapsed; } else { Price = condtion.OrderPrice; typePrice = "L"; IsTypePrice = Visibility.Collapsed; IsPrice = Visibility.Visible; } OrderPrice = condtion.TrrigerPrice; OrderPrice3 = condtion.TrrigerPrice; Num = condtion.OrderVolume; //触发的类型 KeyValue kv0 = new KeyValue() { Id = 0, Value = "最新价" }; KeyValue kv1 = new KeyValue() { Id = 1, Value = "买一价" }; KeyValue kv2 = new KeyValue() { Id = 2, Value = "卖一价" }; PriceList.Add(kv0); PriceList.Add(kv1); PriceList.Add(kv2); PriceItem = kv0; KeyValue ttype0 = new KeyValue() { Id = 0, Value = ">=" }; KeyValue ttype1 = new KeyValue() { Id = 1, Value = "<=" }; TrrigerConditionItem = ttype0; TrrigerCondition.Add(ttype0); TrrigerCondition.Add(ttype1); KeyValue kv03 = new KeyValue() { Id = 0, Value = "最新价" }; KeyValue kv13 = new KeyValue() { Id = 1, Value = "买一价" }; KeyValue kv23 = new KeyValue() { Id = 2, Value = "卖一价" }; PriceList3.Add(kv03); PriceList3.Add(kv13); PriceList3.Add(kv23); PriceItem3 = kv03; KeyValue ttype03 = new KeyValue() { Id = 0, Value = ">=" }; KeyValue ttype13 = new KeyValue() { Id = 1, Value = "<=" }; IsFirst = true; TrrigerCondition3.Add(ttype03); TrrigerCondition3.Add(ttype13); TrrigerConditionItem3 = ttype03; if (condtion.Direction == "B") { IsBuy = true; IsSell = false; } else if (condtion.Direction == "S") { IsBuy = false; IsSell = true; } if (condtion.OpenOffset == (int)OffsetType.OFFSET_OPEN) { IsOpen = true; IsCloseing = false; } else if (condtion.OpenOffset == (int)OffsetType.OFFSET_COVER) { IsCloseing = true; IsOpen = false; } if (condtion.ConditionType == (int)YunConditionType.Y_PRICE) { IsFirst = true; IsSecond = false; IsThird = false; TrrigerConditionItem = TrrigerCondition[condtion.TrrigerCondition]; PriceItem = PriceList[condtion.TrrigerPriceType]; } else if (condtion.ConditionType == (int)YunConditionType.Y_TIME) { IsFirst = false; IsSecond = true; IsThird = false; TrrigerTime = condtion.TrrigerContime; //trriger_contime } else if (condtion.ConditionType == (int)YunConditionType.Y_TIMEPRICE) { IsFirst = false; IsSecond = false; IsThird = true; TrrigerConditionItem = TrrigerCondition3[condtion.TrrigerCondition]; PriceItem3 = PriceList3[condtion.TrrigerPriceType]; TrrigerTime3 = condtion.TrrigerContime; } Upatatecondtion = condtion; }
private ConditionBillViewModel(string contractCode, double price, string pricetype, int num) { _IsEnabled = true; //需要合约号 下单的类型和价格 以及数量 ContractCode = contractCode; VarietyModel vm = null; string[] values = contractCode.Split(' '); if (values.Length != 3) { return; } string varietie = values[1]; if (ContractVariety.Varieties.ContainsKey(varietie)) { vm = ContractVariety.Varieties[varietie]; } if (vm == null) { return; } Increment = vm.tick_size; lend = vm.precision; if (pricetype == "市价") { IsTypePrice = Visibility.Visible; IsPrice = Visibility.Collapsed; Price = 0; typePrice = "M"; } else if (pricetype == "对手价") { Price = 0; typePrice = "R"; IsTypePrice = Visibility.Visible; IsPrice = Visibility.Collapsed; } else { Price = price; typePrice = "L"; IsTypePrice = Visibility.Collapsed; IsPrice = Visibility.Visible; } PriceTypeBill = pricetype; _priceType = pricetype; OrderPrice = price; OrderPrice3 = price; Num = num; //触发的类型 KeyValue kv0 = new KeyValue() { Id = 0, Value = "最新价" }; KeyValue kv1 = new KeyValue() { Id = 1, Value = "买一价" }; KeyValue kv2 = new KeyValue() { Id = 2, Value = "卖一价" }; PriceList.Add(kv0); PriceList.Add(kv1); PriceList.Add(kv2); PriceItem = kv0; KeyValue ttype0 = new KeyValue() { Id = 0, Value = ">=" }; KeyValue ttype1 = new KeyValue() { Id = 1, Value = "<=" }; TrrigerConditionItem = ttype0; TrrigerCondition.Add(ttype0); TrrigerCondition.Add(ttype1); KeyValue kv03 = new KeyValue() { Id = 0, Value = "最新价" }; KeyValue kv13 = new KeyValue() { Id = 1, Value = "买一价" }; KeyValue kv23 = new KeyValue() { Id = 2, Value = "卖一价" }; PriceList3.Add(kv03); PriceList3.Add(kv13); PriceList3.Add(kv23); PriceItem3 = kv03; KeyValue ttype03 = new KeyValue() { Id = 0, Value = ">=" }; KeyValue ttype13 = new KeyValue() { Id = 1, Value = "<=" }; IsFirst = true; TrrigerCondition3.Add(ttype03); TrrigerCondition3.Add(ttype13); TrrigerConditionItem3 = ttype03; }