Ejemplo n.º 1
0
        public void PrintVoucher(string printerName, string printDocumentName, int length, string documentInitialization, IList <IPrintLine> lines)
        {
            Debug.Assert(!string.IsNullOrEmpty(printerName));

            var b = new StringBuilder();

            b.Append(MTPL.PUMOn(true));
            b.Append(MTPL.SetFormLength(length));//6119
            b.AppendLine(documentInitialization);

            PrintLine lastLine = null;

            const int MIN_V_STEP = 50;

            foreach (PrintLine line in lines)
            {
                if (lastLine == null || Math.Abs(line.Y - lastLine.Y) > MIN_V_STEP)
                {
                    b.Append(MTPL.SetAbsolutePosition((int)line.X, (int)line.Y));
                }
                else
                {
                    b.Append(MTPL.SetAbsoluteHorizontalPosition((int)line.X));
                }

                line.Print(b);
                lastLine = line;
            }

            b.Append(ASCII.FF);

            string text = b.ToString();

            PrinterQueue.AddJob(printerName, printDocumentName, text);
        }
Ejemplo n.º 2
0
        public void PrintVoucher(string printerName, string printDocName, int length, string docInitialization, IList <IPrintLine> lines)
        {
            StringBuilder builder = new StringBuilder();

            //Setting form length
            if (FormLength > 0)
            {
                builder.Append(MTPL.SetFormLength(FormLength));
            }

            builder.Append(Context);
            builder.Clean();

            //Parse commands
            var pattern1 = @"\[cmd\s*:\s*{([^}]*)\}\s*\]"; //{(char)27 + "[11w"}
            var re1      = new Regex(pattern1, RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase |
                                     RegexOptions.IgnorePatternWhitespace | RegexOptions.Multiline);

            re1.Replace(ref builder, (ma) =>
            {
                return(ma.Groups[1].Success ?
                       CacheManager.Instance.Table.GetValueAdd <string>(ma.Groups[1].Value,
                                                                        new Func <string>(() => Convert.ToString(CommonTools.Eval(ma.Groups[1].Value)))) :
                       null);
            });

            //Replace spaces
            builder.Replace("<nbsp>", " ");

            //<ht><ht>[VATNumber,10]<ht>[VATNumber,-10]<ht>[VATNumber]<br>
            foreach (PrintLine line in lines)
            {
                //Parse params
                var pattern2 = string.Format(@"\[(?<name>{0})(?<value>,\-?\d+)?\]", line.Description);
                var re2      = new Regex(pattern2, RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase |
                                         RegexOptions.IgnorePatternWhitespace | RegexOptions.Multiline);
                re2.Replace(ref builder, (ma) =>
                {
                    if (ma.Groups[2].Success)
                    {
                        return(string.Format(string.Concat("{0", ma.Groups["value"].Value, "}"), line.Text));
                    }
                    else if (ma.Groups[1].Success)
                    {
                        return(line.Text ?? "");
                    }
                    else
                    {
                        return(null);
                    }
                });
            }

            //Replace htabs
            builder.Replace("<ht>", ASCII.HT);
            //Replace vtabs
            builder.Replace("<vt>", ASCII.VT);
            //Replace line breaks
            builder.Replace("<br>", ASCII.LF + ASCII.CR);
            //End of form
            builder.Append(ASCII.FF);

            var docText = builder.ToString();

            PrinterQueue.AddJob(printerName, printDocName, docText);
        }