internal Product(bool isReadonly, PaperFormat format, PaperType type, string printer, string channel, float price, PriceManager.ModifiedHandler handler) { _isReadonly = isReadonly; _format = format; _type = type; _printer = printer; _channel = channel; _price = price; _handler = handler; }
public PaperFormat AddPaperFormat(string name, float width, float height, int dpi) { if (!_isReadonly) { PaperFormat format = new PaperFormat(_isReadonly, name, width, height, dpi, Modified); _formats.Add(format); if (Modified != null) { Modified(); } return(format); } else { throw new NotSupportedException(); } }
public Product AddProduct(PaperFormat format, PaperType type, string printer) { if (!_isReadonly) { Product newProduct = new Product(_isReadonly, format, type, printer, null, 1, Modified); newProduct.AddDiscount(new Discount(1, int.MaxValue, 1)); _products.Add(newProduct.ToString(), newProduct); if (Modified != null) { Modified(); } return(newProduct); } else { throw new NotSupportedException(); } }
public void RemovePaperFormat(PaperFormat format) { if (!_isReadonly) { if (format != null && _formats.Contains(format)) { _formats.Remove(format); if (Modified != null) { Modified(); } } } else { throw new NotSupportedException(); } }
private void Load(string filename, ModifiedHandler handler) { _products.Clear(); _services.Clear(); _formats.Clear(); _minilabFormats.Clear(); _instantFormats.Clear(); _types.Clear(); _minilabTypes.Clear(); _instantTypes.Clear(); var settings = new XmlReaderSettings(); settings.IgnoreComments = true; settings.IgnoreProcessingInstructions = true; settings.IgnoreWhitespace = true; using (var reader = XmlReader.Create(filename, settings)) { reader.ReadStartElement("price"); if (reader.Name == "settings" && !reader.IsEmptyElement) { reader.Read(); if (reader.Name == "setting" && reader.GetAttribute("key") == SalesTaxPercent.Key) { SalesTaxPercent.Init(float.Parse(reader.GetAttribute("value"), CultureInfo.InvariantCulture)); } reader.Read(); if (reader.Name == "setting" && reader.GetAttribute("key") == SalesTaxComment.Key) { SalesTaxComment.Init(reader.GetAttribute("value")); } reader.Read(); if (reader.Name == "setting" && reader.GetAttribute("key") == MinimumCost.Key) { MinimumCost.Init(float.Parse(reader.GetAttribute("value"), CultureInfo.InvariantCulture)); } reader.Read(); reader.ReadEndElement(); } if (reader.Name == "formats" && !reader.IsEmptyElement) { reader.Read(); while (reader.Name == "format") { PaperFormat format = new PaperFormat( _isReadonly, reader.GetAttribute("name"), float.Parse(reader.GetAttribute("width"), CultureInfo.InvariantCulture), float.Parse(reader.GetAttribute("height"), CultureInfo.InvariantCulture), int.Parse(reader.GetAttribute("dpi"), CultureInfo.InvariantCulture), handler); if (!ContainsPaperFormat(format.Name)) { _formats.Add(format); } reader.Read(); } reader.ReadEndElement(); } if (reader.Name == "types" && !reader.IsEmptyElement) { reader.Read(); while (reader.Name == "type") { PaperType type = new PaperType(_isReadonly, reader.GetAttribute("name"), reader.GetAttribute("description"), handler); if (!ContainsPaperType(type.Name)) { _types.Add(type); } reader.Read(); } reader.ReadEndElement(); } if (reader.Name == "products" && !reader.IsEmptyElement) { reader.Read(); while (reader.Name == "product") { PaperFormat format = GetPaperFormat(reader.GetAttribute("format")); PaperType type = GetPaperType(reader.GetAttribute("type")); string printer = reader.GetAttribute("printer"); string channel = reader.GetAttribute("channel"); if (format != null && type != null && !_products.ContainsKey(format.Name + type.Name + (!string.IsNullOrEmpty(printer) ? Constants.InstantKey : ""))) { var product = new Product(_isReadonly, format, type, printer, channel, float.Parse(reader.GetAttribute("price"), CultureInfo.InvariantCulture), handler); if (string.IsNullOrEmpty(printer) || format.IsFree) { if (!_minilabFormats.Contains(format)) { _minilabFormats.Add(format); } if (!_minilabTypes.Contains(type)) { _minilabTypes.Add(type); } } else { if (!_instantFormats.Contains(format)) { _instantFormats.Add(format); } if (!_instantTypes.Contains(type)) { _instantTypes.Add(type); } } reader.Read(); if (reader.Name == "discounts" && !reader.IsEmptyElement) { reader.Read(); while (reader.Name == "discount") { product.Discounts.Add(new Discount( int.Parse(reader.GetAttribute("start"), CultureInfo.InvariantCulture), string.IsNullOrEmpty(reader.GetAttribute("end")) ? int.MaxValue : int.Parse(reader.GetAttribute("end"), CultureInfo.InvariantCulture), float.Parse(reader.GetAttribute("price"), CultureInfo.InvariantCulture))); reader.Read(); } reader.ReadEndElement(); } _products.Add(product.ToString(), product); reader.Read(); } else { reader.Skip(); } } reader.ReadEndElement(); } if (reader.Name == "services" && !reader.IsEmptyElement) { reader.Read(); while (reader.Name == "service") { Service service = new Service( _isReadonly, reader.GetAttribute("name"), reader.GetAttribute("description"), float.Parse(reader.GetAttribute("price"), CultureInfo.InvariantCulture), bool.Parse(reader.GetAttribute("fixed")), bool.Parse(reader.GetAttribute("permanent")), handler); if (!ContainsService(service.Name)) { _services.Add(service); } reader.Read(); } reader.ReadEndElement(); } } }
public float GetDiscountPrice(PaperFormat format, PaperType type, string instant, int count) { return(_products[format.Name + type.Name + instant].GetDiscountPrice(count)); }
public float GetBasePrice(PaperFormat format, PaperType type, string instant) { return(_products[format.Name + type.Name + instant].Price); }