41 lines
1.1 KiB
C#
41 lines
1.1 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace Tanshu.Accounts.Print
|
|||
|
{
|
|||
|
internal static class PrinterTcpIp
|
|||
|
{
|
|||
|
internal static bool Print(string printerName, string documentName, string printingText)
|
|||
|
{
|
|||
|
// Printer IP Address and communication port
|
|||
|
string ipAddress = printerName.Split(':')[0];
|
|||
|
int port = int.Parse(printerName.Split(':')[1]);
|
|||
|
|
|||
|
try
|
|||
|
{
|
|||
|
// Open connection
|
|||
|
System.Net.Sockets.TcpClient client = new System.Net.Sockets.TcpClient(ipAddress, port);
|
|||
|
|
|||
|
// Write ZPL String to connection
|
|||
|
System.IO.StreamWriter writer = new System.IO.StreamWriter(client.GetStream());
|
|||
|
writer.Write(printingText);
|
|||
|
writer.Flush();
|
|||
|
|
|||
|
// Close Connection
|
|||
|
writer.Close();
|
|||
|
client.Close();
|
|||
|
}
|
|||
|
catch
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
}
|