Moved to a new printer name format in PrintLocation

If printing from windows, then the printer name should be prefixed with smb.
If printing from linux, then the printer name should be prefixed with cups.
If printing directly, then the printer name should be prefixed with pdl.
This commit is contained in:
tanshu 2018-05-17 15:52:27 +05:30
parent 7733b16611
commit 49faa9786d
34 changed files with 175 additions and 122 deletions

View File

@ -1,7 +1,7 @@
using NHibernate.Mapping.ByCode.Conformist;
using NHibernate.Mapping.ByCode;
using System.Collections.Generic;
using NHibernate.Mapping.ByCode;
using NHibernate.Mapping.ByCode.Conformist;
using System;
using System.Collections.Generic;
namespace Tanshu.Accounts.Entities
{
public class Customer

View File

@ -1,5 +1,5 @@
using NHibernate.Mapping.ByCode.Conformist;
using NHibernate.Mapping.ByCode;
using NHibernate.Mapping.ByCode;
using NHibernate.Mapping.ByCode.Conformist;
using System;
namespace Tanshu.Accounts.Entities
{

View File

@ -1,9 +1,7 @@
using System.Collections.Generic;
using Tanshu.Accounts.Contracts;
using NHibernate.Mapping.ByCode;
using NHibernate.Mapping.ByCode.Conformist;
using NHibernate.Mapping.ByCode;
using System;
using System.ComponentModel;
using System.Collections.Generic;
namespace Tanshu.Accounts.Entities
{

View File

@ -1,8 +1,6 @@
using System;
using System.Runtime.Serialization;
using Tanshu.Accounts.Contracts;
using NHibernate.Mapping.ByCode;
using NHibernate.Mapping.ByCode.Conformist;
using NHibernate.Mapping.ByCode;
using System;
namespace Tanshu.Accounts.Entities
{

View File

@ -1,10 +1,8 @@
using System;
using System.Runtime.Serialization;
using Tanshu.Accounts.Entities.Auth;
using System.Collections.Generic;
using Tanshu.Accounts.Contracts;
using NHibernate.Mapping.ByCode;
using NHibernate.Mapping.ByCode.Conformist;
using NHibernate.Mapping.ByCode;
using System;
using System.Collections.Generic;
using Tanshu.Accounts.Entities.Auth;
namespace Tanshu.Accounts.Entities
{

View File

@ -1,7 +1,6 @@
using System;
using System.Runtime.Serialization;
using NHibernate.Mapping.ByCode;
using NHibernate.Mapping.ByCode.Conformist;
using NHibernate.Mapping.ByCode;
using System;
namespace Tanshu.Accounts.Entities
{

View File

@ -1,9 +1,7 @@
using System;
using System.Runtime.Serialization;
using System.Collections.Generic;
using Tanshu.Accounts.Contracts;
using NHibernate.Mapping.ByCode;
using NHibernate.Mapping.ByCode.Conformist;
using NHibernate.Mapping.ByCode;
using System;
using System.Collections.Generic;
namespace Tanshu.Accounts.Entities
{

View File

@ -1,7 +1,6 @@
using System;
using System.Runtime.Serialization;
using NHibernate.Mapping.ByCode;
using NHibernate.Mapping.ByCode.Conformist;
using NHibernate.Mapping.ByCode;
using System;
namespace Tanshu.Accounts.Entities
{

View File

@ -1,8 +1,7 @@
using Tanshu.Accounts.Contracts;
using NHibernate.Mapping.ByCode;
using NHibernate.Mapping.ByCode.Conformist;
using NHibernate.Mapping.ByCode;
using System.Collections.Generic;
using System;
using System.Collections.Generic;
namespace Tanshu.Accounts.Entities
{

View File

@ -1,8 +1,7 @@
using System.Collections.Generic;
using Tanshu.Accounts.Contracts;
using NHibernate.Mapping.ByCode;
using NHibernate.Mapping.ByCode.Conformist;
using NHibernate.Mapping.ByCode;
using System;
using System.Collections.Generic;
namespace Tanshu.Accounts.Entities
{

View File

@ -1,8 +1,6 @@
using System;
using System.Runtime.Serialization;
using Tanshu.Accounts.Contracts;
using NHibernate.Mapping.ByCode;
using NHibernate.Mapping.ByCode.Conformist;
using NHibernate.Mapping.ByCode;
using System;
namespace Tanshu.Accounts.Entities
{

View File

@ -1,7 +1,7 @@
using System;
using Tanshu.Accounts.Entities.Auth;
using NHibernate.Mapping.ByCode;
using NHibernate.Mapping.ByCode.Conformist;
using NHibernate.Mapping.ByCode;
using System;
using Tanshu.Accounts.Entities.Auth;
namespace Tanshu.Accounts.Entities
{

View File

@ -1,9 +1,6 @@
using System;
using System.Runtime.Serialization;
using Tanshu.Accounts.Contracts;
using NHibernate.Mapping.ByCode;
using NHibernate.Mapping.ByCode.Conformist;
using NHibernate.Mapping.ByCode;
using System.Collections.Generic;
using System;
namespace Tanshu.Accounts.Entities
{

View File

@ -1,8 +1,6 @@
using System;
using System.Runtime.Serialization;
using Tanshu.Accounts.Contracts;
using NHibernate.Mapping.ByCode;
using NHibernate.Mapping.ByCode.Conformist;
using NHibernate.Mapping.ByCode;
using System;
using System.Collections.Generic;
namespace Tanshu.Accounts.Entities

View File

@ -1,9 +1,8 @@
using System;
using System.Collections.Generic;
using Tanshu.Accounts.Contracts;
using Tanshu.Accounts.Entities.Auth;
using NHibernate.Mapping.ByCode;
using NHibernate.Mapping.ByCode.Conformist;
using NHibernate.Mapping.ByCode;
using System;
using System.Collections.Generic;
using Tanshu.Accounts.Entities.Auth;
namespace Tanshu.Accounts.Entities
{

View File

@ -1,6 +1,5 @@
using Tanshu.Accounts.Contracts;
using NHibernate.Mapping.ByCode;
using NHibernate.Mapping.ByCode.Conformist;
using NHibernate.Mapping.ByCode;
using System;
namespace Tanshu.Accounts.Entities

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@ -14,6 +14,11 @@
<FileAlignment>512</FileAlignment>
<StartupObject>
</StartupObject>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>3.5</OldToolsVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@ -12,6 +12,11 @@
<AssemblyName>Tanshu.Accounts.Helpers</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>3.5</OldToolsVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>

View File

@ -1,18 +1,16 @@
using System;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq.Expressions;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Tanshu.Accounts.Contracts;
using Tanshu.Accounts.Entities;
using Tanshu.Accounts.Entities.Auth;
using Tanshu.Accounts.Helpers;
using Tanshu.Accounts.Management;
using Tanshu.Accounts.PointOfSale.Sales;
using Tanshu.Accounts.Repository;
using Tanshu.Common;
using Tanshu.Common.KeyboardControl;
using System.Configuration;
using System.Data.SqlClient;
namespace Tanshu.Accounts.PointOfSale
{

View File

@ -1,14 +1,13 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Web.Script.Serialization;
using System.Windows.Forms;
using Tanshu.Accounts.Repository;
using System.ComponentModel;
using Tanshu.Accounts.Entities;
using Tanshu.Accounts.Repository;
namespace Tanshu.Accounts.Management
{
@ -240,8 +239,8 @@ namespace Tanshu.Accounts.Management
var ei = new ExcelInfo()
{
Date = date,
StartBill = bi.FullBillID(bills.StartBill, Tanshu.Accounts.Entities.VoucherType.Regular),
FinishBill = bi.FullBillID(bills.FinishBill, Tanshu.Accounts.Entities.VoucherType.Regular),
StartBill = bi.FullBillID(bills.StartBill, VoucherType.Regular),
FinishBill = bi.FullBillID(bills.FinishBill, VoucherType.Regular),
SaleAndVat = new Dictionary<decimal, SaleInfo>(),
ServiceTax = serviceTax
};
@ -287,14 +286,14 @@ namespace Tanshu.Accounts.Management
e.Result = sheet;
}
private void bwGo_ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e)
private void bwGo_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
var time = (_stopwatch.ElapsedMilliseconds / 1000).ToString() + "s / " + (_totalStopwatch.ElapsedMilliseconds / 1000).ToString() + "s";
_stopwatch.Reset();
_stopwatch.Start();
txtStatus.Text = (string)e.UserState + " " + time + " \r\n" + txtStatus.Text;
}
private void bwGo_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
private void bwGo_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
_stopwatch.Stop();
_totalStopwatch.Stop();
@ -305,7 +304,7 @@ namespace Tanshu.Accounts.Management
else
txtStatus.Text = "Cancelled :(\r\n" + txtStatus.Text;
}
private void bwExcel_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
private void bwExcel_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
_stopwatch.Stop();
_totalStopwatch.Stop();
@ -597,13 +596,13 @@ namespace Tanshu.Accounts.Management
}
}
private void bwFinalSanction_ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e)
private void bwFinalSanction_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
var time = (_totalStopwatch.ElapsedMilliseconds / 1000).ToString() + "s";
txtStatus.Text = (string)e.UserState + " in " + time;
}
private void bwFinalSanction_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
private void bwFinalSanction_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
var time = "Done in " + (_totalStopwatch.ElapsedMilliseconds / 1000).ToString() + "s";
_totalStopwatch.Stop();

View File

@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.34209
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.

View File

@ -2,7 +2,6 @@
using System.Linq;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Threading;
using System.Windows.Forms;
using Tanshu.Accounts.Contracts;

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@ -28,6 +28,11 @@
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>3.5</OldToolsVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@ -494,7 +499,9 @@
<DependentUpon>SalesForm.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<None Include="App.config" />
<None Include="App.config">
<SubType>Designer</SubType>
</None>
<Compile Include="Reports\SaleAnalysisForm.cs">
<SubType>Form</SubType>
</Compile>

View File

@ -3,6 +3,6 @@
// 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);
internal abstract bool Print(string documentName, string printingText);
}
}

View File

@ -5,6 +5,7 @@ namespace Tanshu.Accounts.Print
{
internal class PrinterLinux : PlatformPrinter
{
private string location;
// ReSharper disable InconsistentNaming
#region API Declarations
enum http_status_t /**** HTTP status codes ****/
@ -71,17 +72,20 @@ namespace Tanshu.Accounts.Print
const string CUPS_FORMAT_TEXT = "text/plain";
#endregion
internal override bool Print(string printerName, string documentName, string printingText)
internal PrinterLinux(string location)
{
this.location = location.Substring(5).Normalize();
}
internal override bool Print(string documentName, string printingText)
{
var cupsOption = new IntPtr(0);
var CUPS_HTTP_DEFAULT = new IntPtr(0);
var jobId = cupsCreateJob(CUPS_HTTP_DEFAULT, printerName, documentName, 0, cupsOption);
var jobId = cupsCreateJob(CUPS_HTTP_DEFAULT, location, documentName, 0, cupsOption);
if (jobId > 0)
{
cupsStartDocument(CUPS_HTTP_DEFAULT, printerName, jobId, documentName, CUPS_FORMAT_TEXT, 1);
cupsStartDocument(CUPS_HTTP_DEFAULT, location, jobId, documentName, CUPS_FORMAT_TEXT, 1);
cupsWriteRequestData(CUPS_HTTP_DEFAULT, printingText, printingText.Length);
cupsFinishDocument(CUPS_HTTP_DEFAULT, printerName);
cupsFinishDocument(CUPS_HTTP_DEFAULT, location);
}
return jobId > 0;
}

View File

@ -0,0 +1,50 @@
using System;
using System.Net.Sockets;
namespace Tanshu.Accounts.Print
{
internal class PrinterSocket : PlatformPrinter
{
private string location;
// Cut Code for the printer Alt-29, Alt-86, Alt-49
internal PrinterSocket(string location)
{
this.location = location;
}
internal override bool Print(string documentName, string printingText)
{
try
{
Uri uri = new Uri(location);
TcpClient client = new TcpClient(uri.Host, uri.Port);
// Translate the passed message into ASCII and store it as a Byte array.
Byte[] data = System.Text.Encoding.ASCII.GetBytes(printingText);
// Get a client stream for reading and writing.
NetworkStream stream = client.GetStream();
// Send the message to the connected TcpServer.
stream.Write(data, 0, data.Length);
Console.WriteLine("Sent: {0}", printingText);
// Close everything.
stream.Close();
client.Close();
return true;
}
catch (ArgumentNullException e)
{
Console.WriteLine("ArgumentNullException: {0}", e);
return false;
}
catch (SocketException e)
{
Console.WriteLine("SocketException: {0}", e);
return false;
}
}
}
}

View File

@ -5,6 +5,7 @@ namespace Tanshu.Accounts.Print
{
internal class PrinterWindows : PlatformPrinter
{
private string location;
// Cut Code for the printer Alt-29, Alt-86, Alt-49
#region API Declarations
// Structure and API declarions:
@ -39,8 +40,11 @@ namespace Tanshu.Accounts.Print
[DllImport("winspool.drv", EntryPoint = "WritePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
internal static extern bool WritePrinter(IntPtr hPrinter, IntPtr pBytes, Int32 dwCount, out Int32 dwWritten);
#endregion
internal override bool Print(string printerName, string documentName, string printingText)
internal PrinterWindows (string location)
{
this.location = location.Substring(4).Normalize();
}
internal override bool Print(string documentName, string printingText)
{
IntPtr hPrinter = new IntPtr(0);
// The printer handle.
@ -53,7 +57,7 @@ namespace Tanshu.Accounts.Print
di.pDocName = documentName;
di.pDataType = "RAW";
if (OpenPrinter(printerName.Normalize(), out hPrinter, IntPtr.Zero))
if (OpenPrinter(location, out hPrinter, IntPtr.Zero))
{
if (StartDocPrinter(hPrinter, 1, di))
{

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@ -12,6 +12,11 @@
<AssemblyName>Tanshu.Accounts.Print</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>3.5</OldToolsVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@ -58,10 +63,10 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="PrinterSocket.cs" />
<Compile Include="ThermalBill.cs" />
<Compile Include="PlatformPrinter.cs" />
<Compile Include="PrinterLinux.cs" />
<Compile Include="ThermalPrinter.cs" />
<Compile Include="PrinterWindows.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Thermal.cs" />

View File

@ -65,14 +65,26 @@ namespace Tanshu.Accounts.Print
return string.Format("{0," + length + "}", temp);
}
private static bool PrintRaw(PrintLocation printer, string text, string documentName)
private static PlatformPrinter GetPrinter(string location)
{
if (location.StartsWith("smb://"))
return new PrinterWindows(location);
else if (location.StartsWith("cups://"))
return new PrinterLinux(location);
else if (location.StartsWith("pdl://"))
return new PrinterSocket(location);
throw new NotImplementedException();
}
private static bool PrintRaw(PrintLocation location, string text, string documentName)
{
#if (DEBUG)
MessageBox.Show(text);
return true;
#else
text += printer.CutCode;
if (!ThermalPrinter.Printer.Print(printer.Printer, documentName, text))
text += location.CutCode;
var printer = GetPrinter(location.Printer);
if (!printer.Print(documentName, text))
MessageBox.Show("Error in PrintRAW Function. Please Report immediately");
return true;
#endif

View File

@ -1,19 +0,0 @@
using System;
namespace Tanshu.Accounts.Print
{
internal class ThermalPrinter
{
internal static PlatformPrinter Printer;
static ThermalPrinter()
{
Printer = RunningOnLinux() ? (PlatformPrinter)new PrinterLinux() : new PrinterWindows();
}
internal static bool RunningOnLinux()
{
var platform = (int)Environment.OSVersion.Platform;
return (platform == 4) || (platform == 6) || (platform == 128);
}
}
}

View File

@ -1,11 +1,10 @@
using System;
using System.Collections;
using NHibernate;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using NHibernate;
using Tanshu.Accounts.Entities;
using System.ComponentModel;
namespace Tanshu.Accounts.Repository
{

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@ -12,7 +12,11 @@
<AssemblyName>Tanshu.Accounts.Repository</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkSubset>Full</TargetFrameworkSubset>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>3.5</OldToolsVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>

View File

@ -232,12 +232,12 @@ namespace Tanshu.Accounts.Repository
public void DiscountPrintedBill(Guid oldVoucherID, Voucher newVoucher)
{
Insert(newVoucher);
var oldVoucher = _session.Get<Voucher>(oldVoucherID);
oldVoucher.User = Session.User;
oldVoucher.Void = true;
oldVoucher.VoidReason = string.Format("Bill Discounted / Changed. New Bill ID is {0}", newVoucher.FullBillID);
Insert(newVoucher);
Update(oldVoucher);
}
public void MoveTable(Guid voucherID, Guid tableID)

View File

@ -1,6 +1,8 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tanshu.Accounts.Contracts", "Tanshu.Accounts.Contracts\Tanshu.Accounts.Contracts.csproj", "{59A6F8B8-12EE-4D8E-BEBB-61CB665A2C17}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tanshu.Accounts.PointOfSale", "Tanshu.Accounts.PointOfSale\Tanshu.Accounts.PointOfSale.csproj", "{16FC8CDC-B535-4CB5-92D9-AA901E0A4AA4}"