Ejemplo n.º 1
0
        private void addImageToDoc(TextModel sectionModel, FlowDocument doc)
        {
            if (sectionModel.ImageModel == null)
            {
                return;
            }

            BlockUIContainer imageBlock = ImageHelper.getImageBlock(sectionModel.ImageModel, doc);

            if (imageBlock != null)
            {
                doc.Blocks.Add(imageBlock);
            }
        }
Ejemplo n.º 2
0
        private void addSectionToDoc(TextModel sectionModel, FlowDocument doc)
        {
            foreach (ParagraphModel item in sectionModel.Paragraphs)
            {
                Paragraph par  = null;
                string    sBuf = null;

                // обработка строк шаблона заголовка
                if (item.Text.Contains("{OrderDate}") == true)
                {
                    sBuf = item.Text.Replace("{OrderDate}", string.Format("{0:dd.MM.yyyy HH:mm:ss}", _order.OrderDate));
                    Run inLineObj = getRunFromModel(item, sBuf);
                    par = new Paragraph(inLineObj);
                }
                else if (item.Text.Contains("{OrderNumber}") == true)
                {
                    // форматированный текст до и после номера счета
                    List <Run> runBlocks = new List <Run>();
                    Run        r;

                    string[] aStr = item.Text.Split(new string[] { "{OrderNumber}" }, StringSplitOptions.RemoveEmptyEntries);
                    // текст перед номером
                    if (aStr.Length > 0)
                    {
                        sBuf = aStr[0];
                        r    = getRunFromModel(item, sBuf); r.FontWeight = FontWeights.Bold;
                        runBlocks.Add(r);
                    }
                    // номер заказа
                    r          = getRunFromModel(item, _order.OrderNumberForPrint.ToString());
                    r.FontSize = item.FontSize + 3; r.FontWeight = FontWeights.Bold;
                    runBlocks.Add(r);

                    // идентификатор устройства
                    if ((aStr.Length > 1) && (aStr[1].Contains("{ssdId}")))
                    {
                        sBuf = (string)AppLib.GetAppGlobalValue("ssdID");
                        if (sBuf != null)
                        {
                            aStr = aStr[1].Split(new string[] { "{ssdId}" }, StringSplitOptions.RemoveEmptyEntries);
                            // текст до идентификатора
                            if (aStr.Length > 0)
                            {
                                runBlocks.Add(getRunFromModel(item, aStr[0]));
                            }
                            // идентификатор
                            r = getRunFromModel(item, sBuf); runBlocks.Add(r);
                            // текст после идент.
                            if (aStr.Length > 1)
                            {
                                runBlocks.Add(getRunFromModel(item, aStr[1]));
                            }
                        }
                    }

                    par = new Paragraph();  // собрать тексты в абзац
                    par.Inlines.AddRange(runBlocks);
                }
                else
                {
                    Run inLineObj = getRunFromModel(item, item.Text);
                    par = new Paragraph(inLineObj);
                }

                // формат абзаца
                if (par != null)
                {
                    par.Margin = new Thickness(item.LeftMargin, item.TopMargin, item.RightMargin, item.ButtomMargin);
                    doc.Blocks.Add(par);
                    par = null;
                }
            }
        }
Ejemplo n.º 3
0
        private FlowDocument createDocument(int width)
        {
            // создать объекты верхнего и нижнего колонтитулов
            XmlDocument xmlHeader = new XmlDocument();

            xmlHeader.Load(AppDomain.CurrentDomain.BaseDirectory + string.Format(@"PrinterBill\Header-{0}.xml", _langId));
            XmlDocument xmlFooter = new XmlDocument();

            xmlFooter.Load(AppDomain.CurrentDomain.BaseDirectory + string.Format(@"PrinterBill\Footer-{0}.xml", _langId));
            TextModel textHeader = new TextModel();
            TextModel textFooter = new TextModel();

            textHeader = DeSerialize <TextModel>(xmlHeader.OuterXml);
            textFooter = DeSerialize <TextModel>(xmlFooter.OuterXml);
            int       leftMargin     = getLineMargin("BillLineLeftMargin");
            Thickness lineMargin     = getLineMargin();
            Thickness lineMarginIngr = lineMargin;

            lineMarginIngr.Top = getLineMargin("BillLineIngrTopMargin");
            Thickness lineMarginPrice = lineMargin;

            lineMarginPrice.Top = getLineMargin("BillLinePriceTopMargin");

            var doc = new FlowDocument();

            doc.PageWidth = width;
            // значения по умолчанию
            doc.FontFamily = new FontFamily("Panton-Bold");
            doc.FontWeight = FontWeights.Normal;
            doc.FontStyle  = FontStyles.Normal;
            doc.FontSize   = Convert.ToInt32(AppLib.GetAppGlobalValue("BillLineFontSize", 12));

            // вставить изображение в заголовок
            addImageToDoc(textHeader, doc);
            // метка, если заказ С СОБОЙ
            if (_order.takeAway == true)
            {
                string langText = AppLib.GetLangTextFromAppProp("takeOrderOut");
                langText = string.Concat(" **** ", langText.ToUpper(), " ****");
                addParagraph(doc, langText, 1.5 * doc.FontSize, FontWeights.Bold, FontStyles.Normal, new Thickness(leftMargin, 20, 0, 10), TextAlignment.Center);
            }
            // добавить форматированный заголовок
            addSectionToDoc(textHeader, doc);

            // добавить строки заказа
            string  currencyName = AppLib.GetLangTextFromAppProp("CurrencyName");
            string  sAppSet;
            decimal totalPrice = 0; string itemName, stringRow;

            foreach (DishItem item in _order.Dishes)
            {
                // блюдо
                itemName = AppLib.GetLangText(item.langNames);
                // c гарниром?
                if ((item.SelectedGarnishes != null) && (item.SelectedGarnishes.Count > 0))
                {
                    DishAdding garn     = item.SelectedGarnishes[0];
                    string     garnName = AppLib.GetLangText(garn.langNames);
                    // 2017-02-02 Формирование полного наименования блюда с гарниром
                    // если DishFullNameInGargnish = true, то полное имя берем из гарнира,
                    // иначе к имени блюда добавляем имя гарнира
                    sAppSet = AppLib.GetAppSetting("DishFullNameInGarnish");
                    if (sAppSet != null && sAppSet.ToBool())
                    {
                        itemName = garnName;
                    }
                    else
                    {
                        itemName += " " + AppLib.GetLangTextFromAppProp("withGarnish") + " " + garnName;
                    }
                }
                //string stringRow = itemName.Substring(0, itemName.Count() > 30 ? 30 : itemName.Count());
                addParagraph(doc, itemName, doc.FontSize, doc.FontWeight, doc.FontStyle, lineMargin);

                // добавить ингредиенты
                if (item.SelectedIngredients != null)
                {
                    stringRow = "  + "; bool isFirst = true;
                    foreach (DishAdding ingr in item.SelectedIngredients)
                    {
                        itemName   = AppLib.GetLangText(ingr.langNames);
                        stringRow += ((isFirst) ? "" : "; ") + itemName;
                        isFirst    = false;
                    }
                    addParagraph(doc, stringRow, 0.9 * doc.FontSize, doc.FontWeight, FontStyles.Italic, lineMarginIngr);
                }

                // стоимость блюда
                decimal price       = item.GetPrice();
                string  priceString = string.Format("{0} x {1:0.00} {3} = {2:0.00} {3}", item.Count, price, item.Count * price, currencyName);
                addParagraph(doc, priceString, doc.FontSize, doc.FontWeight, doc.FontStyle, lineMarginPrice, TextAlignment.Right);
                totalPrice += item.Count * price;
            }
            // итог
            addTotalLine(doc, doc.FontSize, totalPrice, currencyName, leftMargin);

            // добавить форматированный "подвал"
            addSectionToDoc(textFooter, doc);
            // вставить изображение в "подвал"
            addImageToDoc(textFooter, doc);

            // печать штрих-кода
            string           bcVal13      = _order.BarCodeValue + BarCodeLib.getUPCACheckDigit(_order.BarCodeValue);
            Image            imageBarCode = BarCodeLib.GetBarcodeImage(bcVal13, (int)(1.2 * doc.PageWidth), 50);
            BlockUIContainer bcContainer  = new BlockUIContainer()
            {
                Child  = imageBarCode,
                Margin = new Thickness(leftMargin, 10, 0, 0)
            };

            doc.Blocks.Add(bcContainer);
            // вывести значение баркода в чек
            //string bcDisplay = string.Format("{0} {1} {2} {3}", bcVal13.Substring(0,2), bcVal13.Substring(2, 6), bcVal13.Substring(8, 4), bcVal13.Substring(12,1));
            string bcDisplay = string.Format("{0}  {1}  {2}", bcVal13.Substring(0, 1), bcVal13.Substring(1, 6), bcVal13.Substring(7));

            addParagraph(doc, bcDisplay, 0.75 * doc.FontSize, doc.FontWeight, doc.FontStyle, new Thickness(leftMargin, 5, 0, 0), TextAlignment.Center);

            return(doc);
        }