Experimental Support for CUPS Printing, not working as of now.
This commit is contained in:
parent
59909a5ee7
commit
0eb5c7d939
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<connectionStrings>
|
<connectionStrings>
|
||||||
<add name="FluentCon" connectionString="Server=sovereign;Initial Catalog=Pets;User ID=sa;Password=123456" />
|
<add name="FluentCon" connectionString="Server=.;Initial Catalog=Pets;User ID=sa;Password=123456" />
|
||||||
</connectionStrings>
|
</connectionStrings>
|
||||||
<appSettings>
|
<appSettings>
|
||||||
<add key ="Location" value ="Office"/>
|
<add key ="Location" value ="Office"/>
|
||||||
|
@ -456,13 +456,15 @@ namespace Tanshu.Accounts.PointOfSale
|
|||||||
_saleForm.ClearBill(_bill);
|
_saleForm.ClearBill(_bill);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FormLoad()
|
public SaleFormState FormLoad()
|
||||||
{
|
{
|
||||||
ClearBill();
|
ClearBill();
|
||||||
if (_editVoucherID.HasValue)
|
if (_editVoucherID.HasValue)
|
||||||
{
|
{
|
||||||
LoadBill(_editVoucherID.Value);
|
LoadBill(_editVoucherID.Value);
|
||||||
|
return SaleFormState.Billing;
|
||||||
}
|
}
|
||||||
|
return SaleFormState.Waiting;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void SettleBill()
|
internal void SettleBill()
|
||||||
|
8
Tanshu.Accounts.Print/PlatformPrinter.cs
Normal file
8
Tanshu.Accounts.Print/PlatformPrinter.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
namespace Tanshu.Accounts.Print
|
||||||
|
{
|
||||||
|
// Cut Code for the printer Alt-29, Alt-86, Alt-49
|
||||||
|
internal abstract class PlatformPrinter
|
||||||
|
{
|
||||||
|
internal abstract bool Print(string printerName, string documentName, string printingText);
|
||||||
|
}
|
||||||
|
}
|
47
Tanshu.Accounts.Print/PrinterLinux.cs
Normal file
47
Tanshu.Accounts.Print/PrinterLinux.cs
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
using System;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace Tanshu.Accounts.Print
|
||||||
|
{
|
||||||
|
internal class PrinterLinux : PlatformPrinter
|
||||||
|
{
|
||||||
|
#region API Declarations
|
||||||
|
// ReSharper disable InconsistentNaming
|
||||||
|
[DllImport("libcups", CharSet = CharSet.Ansi)]
|
||||||
|
static extern int cupsPrintFile(string printer, string filename, string title, int num_options, IntPtr options);
|
||||||
|
// int cupsPrintFile (const char *name, const char *filename, const char *title, int num_options, cups_option_t *options);
|
||||||
|
|
||||||
|
[DllImport("libcups", CharSet = CharSet.Ansi)]
|
||||||
|
static extern int cupsCreateJob(string http, string name, string title, int num_options, IntPtr options);
|
||||||
|
// int cupsCreateJob (http_t *http, const char *name, const char *title, int num_options, cups_option_t *options);
|
||||||
|
|
||||||
|
[DllImport("libcups", CharSet = CharSet.Ansi)]
|
||||||
|
static extern int cupsStartDocument(string http, string name, int job_id, string docname, string format, int last_document);
|
||||||
|
// http_status_t cupsStartDocument (http_t *http, const char *name, int job_id, const char *docname, const char *format, int last_document);
|
||||||
|
|
||||||
|
[DllImport("libcups", CharSet = CharSet.Ansi)]
|
||||||
|
static extern int cupsWriteRequestData(string http, string buffer, int length);
|
||||||
|
// http_status_t cupsWriteRequestData (http_t *http, const char *buffer, size_t length);
|
||||||
|
|
||||||
|
[DllImport("libcups", CharSet = CharSet.Ansi)]
|
||||||
|
static extern int cupsFinishDocument(string http, string name);
|
||||||
|
// ipp_status_t cupsFinishDocument (http_t *http, const char *name);
|
||||||
|
// ReSharper restore InconsistentNaming
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
internal override bool Print(string printerName, string documentName, string printingText)
|
||||||
|
{
|
||||||
|
var cupsOption = new IntPtr(0);
|
||||||
|
const string CUPS_HTTP_DEFAULT = "CUPS_HTTP_DEFAULT";
|
||||||
|
var jobId = cupsCreateJob(CUPS_HTTP_DEFAULT, printerName, documentName, 0, cupsOption);
|
||||||
|
if (jobId > 0)
|
||||||
|
{
|
||||||
|
const string format = "CUPS_FORMAT_TEXT";
|
||||||
|
cupsStartDocument(CUPS_HTTP_DEFAULT, printerName, jobId, documentName, format, 1);
|
||||||
|
cupsWriteRequestData(CUPS_HTTP_DEFAULT, printingText, printingText.Length);
|
||||||
|
cupsFinishDocument(CUPS_HTTP_DEFAULT, printerName);
|
||||||
|
}
|
||||||
|
return jobId > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,12 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace Tanshu.Accounts.Print
|
namespace Tanshu.Accounts.Print
|
||||||
{
|
{
|
||||||
internal class RawPrinterHelper
|
internal class PrinterWindows : PlatformPrinter
|
||||||
{
|
{
|
||||||
// Cut Code for the printer Alt-29, Alt-86, Alt-49
|
// Cut Code for the printer Alt-29, Alt-86, Alt-49
|
||||||
#region API Declarations
|
#region API Declarations
|
||||||
@ -43,35 +40,28 @@ namespace Tanshu.Accounts.Print
|
|||||||
internal static extern bool WritePrinter(IntPtr hPrinter, IntPtr pBytes, Int32 dwCount, out Int32 dwWritten);
|
internal static extern bool WritePrinter(IntPtr hPrinter, IntPtr pBytes, Int32 dwCount, out Int32 dwWritten);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
internal static bool PrintString(string printerName, string documentName, string printingText, char[] lineBreakChars)
|
internal override bool Print(string printerName, string documentName, string printingText)
|
||||||
{
|
{
|
||||||
string[] PageText;
|
|
||||||
IntPtr hPrinter = new IntPtr(0);
|
IntPtr hPrinter = new IntPtr(0);
|
||||||
// The printer handle.
|
// The printer handle.
|
||||||
Int32 dwError;
|
|
||||||
// Last error -incase there was trouble.
|
// Last error -incase there was trouble.
|
||||||
DOCINFOA di = new DOCINFOA();
|
DOCINFOA di = new DOCINFOA();
|
||||||
// Describes your document(name, port, data type).
|
// Describes your document(name, port, data type).
|
||||||
bool bSuccess = false; // Your success code.
|
var bSuccess = false; // Your success code.
|
||||||
|
|
||||||
// Set up the DOCINFO structure.
|
// Set up the DOCINFO structure.
|
||||||
di.pDocName = documentName;
|
di.pDocName = documentName;
|
||||||
di.pDataType = "RAW";
|
di.pDataType = "RAW";
|
||||||
PageText = printingText.Split(lineBreakChars );
|
|
||||||
|
|
||||||
if (OpenPrinter(printerName.Normalize(), out hPrinter, System.IntPtr.Zero))
|
if (OpenPrinter(printerName.Normalize(), out hPrinter, IntPtr.Zero))
|
||||||
{
|
{
|
||||||
if (StartDocPrinter(hPrinter, 1, di))
|
if (StartDocPrinter(hPrinter, 1, di))
|
||||||
{
|
{
|
||||||
for (int i = 0; i < PageText.Length; i++)
|
if (!StartPagePrinter(hPrinter))
|
||||||
{
|
return false;
|
||||||
if (StartPagePrinter(hPrinter))
|
|
||||||
{
|
|
||||||
//Write your printer - specific bytes to the printer.
|
//Write your printer - specific bytes to the printer.
|
||||||
bSuccess = SendLine(PageText[i], hPrinter);
|
bSuccess = SendLine(printingText, hPrinter);
|
||||||
EndPagePrinter(hPrinter);
|
EndPagePrinter(hPrinter);
|
||||||
}
|
|
||||||
}
|
|
||||||
EndDocPrinter(hPrinter);
|
EndDocPrinter(hPrinter);
|
||||||
}
|
}
|
||||||
ClosePrinter(hPrinter);
|
ClosePrinter(hPrinter);
|
||||||
@ -79,14 +69,13 @@ namespace Tanshu.Accounts.Print
|
|||||||
// If you did not succeed, GetLastError may give more information about why not.
|
// If you did not succeed, GetLastError may give more information about why not.
|
||||||
if (bSuccess == false)
|
if (bSuccess == false)
|
||||||
{
|
{
|
||||||
dwError = Marshal.GetLastWin32Error();
|
Marshal.GetLastWin32Error();
|
||||||
}
|
}
|
||||||
return bSuccess;
|
return bSuccess;
|
||||||
}// SendBytesToPrinter()
|
}// SendBytesToPrinter()
|
||||||
|
|
||||||
internal static bool SendLine(string szString, IntPtr hPrinter)
|
internal static bool SendLine(string szString, IntPtr hPrinter)
|
||||||
{
|
{
|
||||||
bool bSuccess = false;
|
|
||||||
Int32 dwWritten = 0;
|
Int32 dwWritten = 0;
|
||||||
Int32 dwCount = szString.Length; // How many characters are in the string?
|
Int32 dwCount = szString.Length; // How many characters are in the string?
|
||||||
|
|
||||||
@ -95,9 +84,7 @@ namespace Tanshu.Accounts.Print
|
|||||||
// the string to ANSI text.
|
// the string to ANSI text.
|
||||||
|
|
||||||
// Write your bytes.
|
// Write your bytes.
|
||||||
bSuccess = WritePrinter(hPrinter, pBytes, dwCount, out dwWritten);
|
return WritePrinter(hPrinter, pBytes, dwCount, out dwWritten);
|
||||||
|
|
||||||
return bSuccess;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -78,7 +78,10 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="RawPrinterHelper.cs" />
|
<Compile Include="PlatformPrinter.cs" />
|
||||||
|
<Compile Include="PrinterLinux.cs" />
|
||||||
|
<Compile Include="ThermalPrinter.cs" />
|
||||||
|
<Compile Include="PrinterWindows.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Thermal.cs" />
|
<Compile Include="Thermal.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -239,19 +239,9 @@ namespace Tanshu.Accounts.Print
|
|||||||
MessageBox.Show(text);
|
MessageBox.Show(text);
|
||||||
return true;
|
return true;
|
||||||
#else
|
#else
|
||||||
try
|
|
||||||
{
|
|
||||||
text += printer.CutCode;
|
text += printer.CutCode;
|
||||||
if (!RawPrinterHelper.PrintString(printer.Printer, documentName, text, new[] { ';' }))
|
if (!ThermalPrinter.Printer.Print(printer.Printer, documentName, text))
|
||||||
{
|
|
||||||
GC.Collect();
|
|
||||||
MessageBox.Show("Error in PrintRAW Function. Please Report immediately");
|
MessageBox.Show("Error in PrintRAW Function. Please Report immediately");
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
30
Tanshu.Accounts.Print/ThermalPrinter.cs
Normal file
30
Tanshu.Accounts.Print/ThermalPrinter.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
using System;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace Tanshu.Accounts.Print
|
||||||
|
{
|
||||||
|
internal class ThermalPrinter
|
||||||
|
{
|
||||||
|
private static readonly bool _runningOnLinux;
|
||||||
|
internal static PlatformPrinter Printer;
|
||||||
|
static ThermalPrinter()
|
||||||
|
{
|
||||||
|
_runningOnLinux = RunningOnLinux();
|
||||||
|
Printer = _runningOnLinux ? (PlatformPrinter)new PrinterLinux() : new PrinterWindows();
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static bool RunningOnLinux()
|
||||||
|
{
|
||||||
|
var platform = (int)Environment.OSVersion.Platform;
|
||||||
|
if ((platform == 4) || (platform == 6) || (platform == 128))
|
||||||
|
{
|
||||||
|
if (Environment.GetEnvironmentVariable("not_supported_MONO_MWF_USE_NEW_X11_BACKEND") != null ||
|
||||||
|
Environment.GetEnvironmentVariable("MONO_MWF_MAC_FORCE_X11") != null)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user