public PriceRenderer(Price price, OutputConfig config) { this.price = price; this.config = config; BuildChanges(); AddColumns(); RenderCollection(price.root, -1); MergeTables(); }
static void Main(string[] args) { Config config = Config.Load("config.txt"); Price source = new Price(config.input); Price result = new Price(source, config.convert); PriceRenderer renderer = new PriceRenderer(result, config.output); string template = File.ReadAllText(config.input.template); int position = template.IndexOf(TEMPLATE_TABLE); using (StreamWriter writer = new StreamWriter(File.Open("output.html", FileMode.Create), Encoding.Default)) { writer.Write(template.Substring(0, position)); renderer.result.Output(writer); writer.Write(template.Substring(position + TEMPLATE_TABLE.Length)); } return; }
private void RenderCollection(Price.Collection collection, int level) { if ((null != collection.name) && (level != -1)) AddHeader(collection.name, config.headers[level]); if (collection.products.Count != 0) FlushHeaders(); for (int productIndex = 0; productIndex < collection.products.Count; ++productIndex) { Price.Product product = collection.products[productIndex]; bool divideName = false; int groupCapacity = 0; if (null != product.groupName) { if (group == product.groupName) { // Продолжение старой группы divideName = true; } else { for (int i = productIndex; i < collection.products.Count; ++i) { if (rowIndex + i + headers.Count - productIndex >= config.lines) break; if (product.groupName == collection.products[i].groupName) ++groupCapacity; else break; } if (groupCapacity != 1) { // Начало новой группы divideName = true; } } } int opt = (int)((product.cost * config.opt ) / 100 + 0.5); int rozn = (int)((opt * config.rozn) / 100 + 0.5); Change change = null; changes.TryGetValue(product.code, out change); Table.Row row = AddRow(); row.cells[0].text = Convert.ToString(RenderCode(product.code)); row.cells[3].text = opt.ToString(); row.cells[4].text = rozn.ToString(); row.cells[5].text = product.pv.ToString(); if (change != null && change.isCode) row.cells[0].cls += " changed"; if (change != null && change.isCost) { row.cells[3].cls += " changed"; row.cells[4].cls += " changed"; } if (change != null && change.isPv) row.cells[5].cls += " changed"; if (divideName) { if (product.shortName.Length == 0 || product.shortName[0] == ',') row.cells[2].text = RenderName(config.basename + product.shortName); else row.cells[2].text = RenderName(product.shortName); if (change != null && change.isName) row.cells[2].cls += " changed"; if (0 != groupCapacity) { row.cells[1].text = RenderName(product.groupName); row.cells[1].rowspan = groupCapacity; row.cells[1].cls = "group"; bool isChange = true; for (int i = 0; i < groupCapacity; ++i) { Change subChange = null; changes.TryGetValue(collection.products[productIndex + i].code, out subChange); if (subChange == null || !subChange.isName) { isChange = false; break; } } if (isChange) row.cells[1].cls += " changed"; group = product.groupName; } } else { row.cells[1].text = RenderName(product.name); row.cells[1].cls = "simple-long"; row.cells[1].colspan = 2; if (change != null && change.isName) row.cells[1].cls += " changed"; group = null; } } foreach (Price.Collection subCollection in collection.collections) RenderCollection(subCollection, level + 1); }
private Bill CreateBill(Price finalPrice) { return new Bill { Price = finalPrice }; }
/** * Создает омский прайс на основе новосибирского прайса, * выполняя следующие преобразования: * 1) Группирует товары в соответствии с конфигурацией; * 2) Сортирует товары по кодам, сохраняя группировку. */ public Price(Price source, ConvertConfig config) { root = ConvertCollection(source.root, config); }