コード例 #1
0
        public void TextLine()
        {
            var content = PrintContent.TextLine("Test");

            content.FontSize            = 32;
            content.Background          = Brushes.Bisque;
            content.FontWeight          = FontWeights.ExtraBold;
            content.HorizontalAlignment = HorizontalAlignment.Right;
            content.Padding             = new Thickness(12);
            content.Margin = new Thickness(24);

            Assert.That(content.Text, Is.EqualTo("Test"));

            var icontent = (IPrintContent)content;

            var grid      = (Grid)icontent.Content;
            var uiElement = (TextBlock)grid.Children[0];

            Assert.That(uiElement.Text, Is.EqualTo("Test"));

            Assert.That(uiElement.FontSize, Is.EqualTo(32));
            Assert.That(grid.Background, Is.EqualTo(Brushes.Bisque));
            Assert.That(uiElement.FontWeight, Is.EqualTo(FontWeights.ExtraBold));
            Assert.That(uiElement.HorizontalAlignment, Is.EqualTo(HorizontalAlignment.Right));
            Assert.That(uiElement.Padding, Is.EqualTo(new Thickness(12)));
            Assert.That(grid.Margin, Is.EqualTo(new Thickness(24)));
        }
コード例 #2
0
ファイル: BarCodePrint.cs プロジェクト: mylifein/CTCodePrint
        public bool PrintBC(string templateFileName, PrintContent printContent, MandatoryField manF)
        {
            //未加載模板文件或者模板發生變更時,重新加載新的模板
            if (lbl.Documents.Count == 0 || templateFileName.IndexOf(lbl.ActiveDocument.Name) == -1)
            {
                lbl.Documents.Open(templateFileName, false);// 调用设计好的label文件
            }
            Document doc = lbl.ActiveDocument;

            try
            {
                if (manF.Ctcodem == "0")
                {
                    doc.Variables.FormVariables.Item("ctcode").Value = printContent.CtCode;   //给参数传值             可以不傳參數
                }

                int Num = 1;                      //打印数量
                doc.Printer.SwitchTo(DefaultPrinter());
                doc.PrintLabel(1, 1, 1, Num, 1, "");
                //doc.PrintDocument(Num);           //打印
            }
            catch (Exception ex)
            {
                return(false);                          //返回,後面代碼不執行
            }
            finally
            {
                doc.FormFeed();
            }
            return(true);
        }
コード例 #3
0
        public void HorizontalLine_Height([Random(1, 100, 1)] int height)
        {
            var horizontalLine = PrintContent.HorizontalLine(height).Content;

            horizontalLine.Measure(new Size(double.MaxValue, double.MaxValue));

            Assert.That(horizontalLine.DesiredSize.Height, Is.EqualTo(height));
        }
コード例 #4
0
        public void BlankLine_HeightValid([Random(1, 100, 1)] int height)
        {
            var content = PrintContent.BlankLine(height).Content;

            content.Measure(new Size(double.MaxValue, double.MaxValue));

            Assert.That(content.DesiredSize.Height, Is.EqualTo(height));
        }
コード例 #5
0
        public void Combine()
        {
            var content1 = PrintContent.BlankLine(10);
            var content2 = PrintContent.BlankLine(10);

            var combined = PrintContent.Combine(content1, content2).Content;

            combined.Measure(new Size(double.MaxValue, double.MaxValue));

            Assert.That(combined.DesiredSize.Height, Is.EqualTo(20));
        }
        public SuccessResponse PostByQuery([FromQuery] string IP, [FromBody] PrintContent content)
        {
            string zplString = content.ZPL;

            IPAddress  ipAddress  = IPAddress.Parse(IP);
            int        port       = 9100;
            IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, port);
            Socket     client     = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

            byte[] sendmsg = Encoding.UTF8.GetBytes(zplString);

            try
            {
                Ping      pingSender = new Ping();
                PingReply reply      = pingSender.Send(ipAddress);

                if (reply.Status != IPStatus.Success)
                {
                    SuccessResponse response = new SuccessResponse
                    {
                        success = false,
                        message = reply.Status.ToString()
                    };
                    return(response);
                }
                else
                {
                    client.Connect(ipEndPoint);
                    int n = client.Send(sendmsg);
                    client.Shutdown(SocketShutdown.Both);
                    client.Close();
                    SuccessResponse response = new SuccessResponse
                    {
                        success = true,
                        message = zplString
                    };
                    return(response);
                }
            }
            catch (Exception ex)
            {
                SuccessResponse errorResponse = new SuccessResponse
                {
                    success = false,
                    message = ex.ToString() + zplString
                };
                return(errorResponse);
            }
        }
コード例 #7
0
        public void OnPrintRequest(PrintRequestData requestData, IPrintReceiver printReceiver)
        {
            // Get information about the requested print received from the terminal
            DocumentType documentType = requestData.DocumentType;
            PrintContent printContent = requestData.Content;

            if (printContent.Format == PrintFormatType.Text)
            {
                ContentText contentText    = printContent.Text;
                string      plainTextPrint = contentText.PlainText;
            }
            // Handle print
            // Return response
            printReceiver.PrintSuccess();
        }
コード例 #8
0
        public override IEnumerable <IPrintContent> ItemCollection()
        {
            yield return(PrintContent.TextLine("Test", 10));

            yield return(PrintContent.BlankLine(50));

            yield return(PrintContent.PageBreak());

            yield return(PrintContent.BlankLine(50));

            yield return(PrintContent.BlankLine(90));

            yield return(new DirectPrintContent {
                Content = new TextBlock {
                    Background = Brushes.Red
                }
            });

            yield return(PrintContent.BlankLine(100));
        }
コード例 #9
0
        public void TextLine_Configuration()
        {
            StringLineItemConfiguration configuration = new StringLineItemConfiguration()
            {
                FontFamily          = new FontFamily("Verdana"),
                FontSize            = 10,
                HorizontalAlignment = HorizontalAlignment.Right
            };

            var content = PrintContent.TextLine("Test", configuration);

            var icontent = (IPrintContent)content;

            var grid      = (Grid)icontent.Content;
            var uiElement = (TextBlock)grid.Children[0];

            Assert.That(uiElement.FontSize, Is.EqualTo(10));
            Assert.That(uiElement.FontFamily, Is.EqualTo(new FontFamily("Verdana")));
            Assert.That(uiElement.HorizontalAlignment, Is.EqualTo(HorizontalAlignment.Right));
        }
コード例 #10
0
 public override IEnumerable <IPrintContent> ItemCollection()
 {
     return(_collToPrint.Select(obj => PrintContent.TextLine(obj.Text)));
     //return _collToPrint.Select(obj => new MyShownObjectLineItem(obj, _printDimensions));
 }
コード例 #11
0
 public override IEnumerable <IPrintContent> ItemCollection()
 {
     return(_collToPrint.Select(obj => PrintContent.TextLine(obj.Text)));
 }
コード例 #12
0
 public override IEnumerable <IPrintContent> ItemCollection()
 {
     yield return(PrintContent.TextLine("Test", 10));
 }
コード例 #13
0
 public override IEnumerable <IPrintContent> ItemCollection()
 {
     return(_collToPrint.Where(e => e.Text != null)
            .Select(e => e.Text !)
            .Select(text => PrintContent.TextLine(text)));
 }
コード例 #14
0
 public void PageBreak_AccessContent_ThrowsInvalidOperationException()
 {
     Assert.That(() => PrintContent.PageBreak().Content, Throws.InvalidOperationException);
 }
コード例 #15
0
 public void BlankLine_HeightNegative_ThrowsArgumentOutOfRangeException()
 {
     Assert.That(() => PrintContent.BlankLine(0), Throws.InstanceOf <ArgumentOutOfRangeException>());
     Assert.That(() => PrintContent.BlankLine(-1), Throws.InstanceOf <ArgumentOutOfRangeException>());
 }
コード例 #16
0
 public void TextLine_Configuration_Null_Throws()
 {
     Assert.That(() => PrintContent.TextLine("Test", null), Throws.ArgumentNullException);
 }