From 49faa9786d0099a489d103079d2e095a38bb9d04 Mon Sep 17 00:00:00 2001 From: tanshu Date: Thu, 17 May 2018 15:52:27 +0530 Subject: [PATCH] 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. --- .../Data Contracts/CustomerBO.cs | 6 +-- .../Data Contracts/FoodTableBO.cs | 4 +- .../Data Contracts/InventoryBO.cs | 6 +-- .../Data Contracts/InventoryModifierBO.cs | 6 +-- .../Data Contracts/KotBO.cs | 10 ++-- .../Data Contracts/MachineLocationBO.cs | 5 +- .../Data Contracts/ModifierBO.cs | 8 ++- .../Data Contracts/PrintLocationBO.cs | 5 +- .../Data Contracts/ProductBO.cs | 5 +- .../Data Contracts/ProductGroupBO.cs | 5 +- .../Data Contracts/ProductGroupModifierBO.cs | 6 +-- .../Data Contracts/ReprintBO.cs | 6 +-- .../Data Contracts/SettingBO.cs | 7 +-- .../Data Contracts/TaxBO.cs | 6 +-- .../Data Contracts/VoucherBO.cs | 9 ++-- .../Data Contracts/VoucherSettlementBO.cs | 3 +- .../Tanshu.Accounts.Contracts.csproj | 7 ++- .../Tanshu.Accounts.Helpers.csproj | 7 ++- Tanshu.Accounts.PointOfSale/MainForm.cs | 6 +-- .../Management/ManagementForm.cs | 19 ++++--- .../Properties/Resources.Designer.cs | 2 +- .../Sales/SalesForm.cs | 1 - .../Tanshu.Accounts.PointOfSale.csproj | 11 +++- Tanshu.Accounts.Print/PlatformPrinter.cs | 2 +- Tanshu.Accounts.Print/PrinterLinux.cs | 14 ++++-- Tanshu.Accounts.Print/PrinterSocket.cs | 50 +++++++++++++++++++ Tanshu.Accounts.Print/PrinterWindows.cs | 10 ++-- .../Tanshu.Accounts.Print.csproj | 9 +++- Tanshu.Accounts.Print/Thermal.cs | 18 +++++-- Tanshu.Accounts.Print/ThermalPrinter.cs | 19 ------- Tanshu.Accounts.Repository/ManagementBI.cs | 7 ++- .../Tanshu.Accounts.Repository.csproj | 8 ++- Tanshu.Accounts.Repository/VoucherBI.cs | 4 +- Tanshu.Accounts.sln | 6 ++- 34 files changed, 175 insertions(+), 122 deletions(-) create mode 100644 Tanshu.Accounts.Print/PrinterSocket.cs delete mode 100644 Tanshu.Accounts.Print/ThermalPrinter.cs diff --git a/Tanshu.Accounts.Contracts/Data Contracts/CustomerBO.cs b/Tanshu.Accounts.Contracts/Data Contracts/CustomerBO.cs index a616d2b..5520368 100644 --- a/Tanshu.Accounts.Contracts/Data Contracts/CustomerBO.cs +++ b/Tanshu.Accounts.Contracts/Data Contracts/CustomerBO.cs @@ -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 diff --git a/Tanshu.Accounts.Contracts/Data Contracts/FoodTableBO.cs b/Tanshu.Accounts.Contracts/Data Contracts/FoodTableBO.cs index 5260e61..dbb6743 100644 --- a/Tanshu.Accounts.Contracts/Data Contracts/FoodTableBO.cs +++ b/Tanshu.Accounts.Contracts/Data Contracts/FoodTableBO.cs @@ -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 { diff --git a/Tanshu.Accounts.Contracts/Data Contracts/InventoryBO.cs b/Tanshu.Accounts.Contracts/Data Contracts/InventoryBO.cs index 5b8dded..7cff58b 100644 --- a/Tanshu.Accounts.Contracts/Data Contracts/InventoryBO.cs +++ b/Tanshu.Accounts.Contracts/Data Contracts/InventoryBO.cs @@ -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 { diff --git a/Tanshu.Accounts.Contracts/Data Contracts/InventoryModifierBO.cs b/Tanshu.Accounts.Contracts/Data Contracts/InventoryModifierBO.cs index 89114c7..9751e43 100644 --- a/Tanshu.Accounts.Contracts/Data Contracts/InventoryModifierBO.cs +++ b/Tanshu.Accounts.Contracts/Data Contracts/InventoryModifierBO.cs @@ -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 { diff --git a/Tanshu.Accounts.Contracts/Data Contracts/KotBO.cs b/Tanshu.Accounts.Contracts/Data Contracts/KotBO.cs index e2a4f1f..e5507a7 100644 --- a/Tanshu.Accounts.Contracts/Data Contracts/KotBO.cs +++ b/Tanshu.Accounts.Contracts/Data Contracts/KotBO.cs @@ -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 { diff --git a/Tanshu.Accounts.Contracts/Data Contracts/MachineLocationBO.cs b/Tanshu.Accounts.Contracts/Data Contracts/MachineLocationBO.cs index 588f26b..0f29b32 100644 --- a/Tanshu.Accounts.Contracts/Data Contracts/MachineLocationBO.cs +++ b/Tanshu.Accounts.Contracts/Data Contracts/MachineLocationBO.cs @@ -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 { diff --git a/Tanshu.Accounts.Contracts/Data Contracts/ModifierBO.cs b/Tanshu.Accounts.Contracts/Data Contracts/ModifierBO.cs index 80ca129..8dd20e2 100644 --- a/Tanshu.Accounts.Contracts/Data Contracts/ModifierBO.cs +++ b/Tanshu.Accounts.Contracts/Data Contracts/ModifierBO.cs @@ -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 { diff --git a/Tanshu.Accounts.Contracts/Data Contracts/PrintLocationBO.cs b/Tanshu.Accounts.Contracts/Data Contracts/PrintLocationBO.cs index 4a83361..9026ec5 100644 --- a/Tanshu.Accounts.Contracts/Data Contracts/PrintLocationBO.cs +++ b/Tanshu.Accounts.Contracts/Data Contracts/PrintLocationBO.cs @@ -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 { diff --git a/Tanshu.Accounts.Contracts/Data Contracts/ProductBO.cs b/Tanshu.Accounts.Contracts/Data Contracts/ProductBO.cs index 9314864..057cbfd 100644 --- a/Tanshu.Accounts.Contracts/Data Contracts/ProductBO.cs +++ b/Tanshu.Accounts.Contracts/Data Contracts/ProductBO.cs @@ -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 { diff --git a/Tanshu.Accounts.Contracts/Data Contracts/ProductGroupBO.cs b/Tanshu.Accounts.Contracts/Data Contracts/ProductGroupBO.cs index 541e543..9c5150d 100644 --- a/Tanshu.Accounts.Contracts/Data Contracts/ProductGroupBO.cs +++ b/Tanshu.Accounts.Contracts/Data Contracts/ProductGroupBO.cs @@ -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 { diff --git a/Tanshu.Accounts.Contracts/Data Contracts/ProductGroupModifierBO.cs b/Tanshu.Accounts.Contracts/Data Contracts/ProductGroupModifierBO.cs index c2e0564..f13cc13 100644 --- a/Tanshu.Accounts.Contracts/Data Contracts/ProductGroupModifierBO.cs +++ b/Tanshu.Accounts.Contracts/Data Contracts/ProductGroupModifierBO.cs @@ -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 { diff --git a/Tanshu.Accounts.Contracts/Data Contracts/ReprintBO.cs b/Tanshu.Accounts.Contracts/Data Contracts/ReprintBO.cs index 2dff57e..3c23ace 100644 --- a/Tanshu.Accounts.Contracts/Data Contracts/ReprintBO.cs +++ b/Tanshu.Accounts.Contracts/Data Contracts/ReprintBO.cs @@ -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 { diff --git a/Tanshu.Accounts.Contracts/Data Contracts/SettingBO.cs b/Tanshu.Accounts.Contracts/Data Contracts/SettingBO.cs index 13e254a..30c59c4 100644 --- a/Tanshu.Accounts.Contracts/Data Contracts/SettingBO.cs +++ b/Tanshu.Accounts.Contracts/Data Contracts/SettingBO.cs @@ -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 { diff --git a/Tanshu.Accounts.Contracts/Data Contracts/TaxBO.cs b/Tanshu.Accounts.Contracts/Data Contracts/TaxBO.cs index f24d169..25fdf5d 100644 --- a/Tanshu.Accounts.Contracts/Data Contracts/TaxBO.cs +++ b/Tanshu.Accounts.Contracts/Data Contracts/TaxBO.cs @@ -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 diff --git a/Tanshu.Accounts.Contracts/Data Contracts/VoucherBO.cs b/Tanshu.Accounts.Contracts/Data Contracts/VoucherBO.cs index 6cb3507..1c3857c 100644 --- a/Tanshu.Accounts.Contracts/Data Contracts/VoucherBO.cs +++ b/Tanshu.Accounts.Contracts/Data Contracts/VoucherBO.cs @@ -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 { diff --git a/Tanshu.Accounts.Contracts/Data Contracts/VoucherSettlementBO.cs b/Tanshu.Accounts.Contracts/Data Contracts/VoucherSettlementBO.cs index f8a1b19..c0db348 100644 --- a/Tanshu.Accounts.Contracts/Data Contracts/VoucherSettlementBO.cs +++ b/Tanshu.Accounts.Contracts/Data Contracts/VoucherSettlementBO.cs @@ -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 diff --git a/Tanshu.Accounts.Contracts/Tanshu.Accounts.Contracts.csproj b/Tanshu.Accounts.Contracts/Tanshu.Accounts.Contracts.csproj index 3dc2993..3be35db 100644 --- a/Tanshu.Accounts.Contracts/Tanshu.Accounts.Contracts.csproj +++ b/Tanshu.Accounts.Contracts/Tanshu.Accounts.Contracts.csproj @@ -1,5 +1,5 @@  - + Debug AnyCPU @@ -14,6 +14,11 @@ 512 + + + + + 3.5 true diff --git a/Tanshu.Accounts.Helpers/Tanshu.Accounts.Helpers.csproj b/Tanshu.Accounts.Helpers/Tanshu.Accounts.Helpers.csproj index 2ec98bf..f7b3d09 100644 --- a/Tanshu.Accounts.Helpers/Tanshu.Accounts.Helpers.csproj +++ b/Tanshu.Accounts.Helpers/Tanshu.Accounts.Helpers.csproj @@ -1,5 +1,5 @@  - + Debug AnyCPU @@ -12,6 +12,11 @@ Tanshu.Accounts.Helpers v3.5 512 + + + + + 3.5 true diff --git a/Tanshu.Accounts.PointOfSale/MainForm.cs b/Tanshu.Accounts.PointOfSale/MainForm.cs index a7b5221..eec3c6f 100644 --- a/Tanshu.Accounts.PointOfSale/MainForm.cs +++ b/Tanshu.Accounts.PointOfSale/MainForm.cs @@ -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 { diff --git a/Tanshu.Accounts.PointOfSale/Management/ManagementForm.cs b/Tanshu.Accounts.PointOfSale/Management/ManagementForm.cs index 8bf7564..ce48058 100644 --- a/Tanshu.Accounts.PointOfSale/Management/ManagementForm.cs +++ b/Tanshu.Accounts.PointOfSale/Management/ManagementForm.cs @@ -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(), 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(); diff --git a/Tanshu.Accounts.PointOfSale/Properties/Resources.Designer.cs b/Tanshu.Accounts.PointOfSale/Properties/Resources.Designer.cs index e2e011a..fa8f9d9 100644 --- a/Tanshu.Accounts.PointOfSale/Properties/Resources.Designer.cs +++ b/Tanshu.Accounts.PointOfSale/Properties/Resources.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // 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. diff --git a/Tanshu.Accounts.PointOfSale/Sales/SalesForm.cs b/Tanshu.Accounts.PointOfSale/Sales/SalesForm.cs index 64dc419..413473e 100644 --- a/Tanshu.Accounts.PointOfSale/Sales/SalesForm.cs +++ b/Tanshu.Accounts.PointOfSale/Sales/SalesForm.cs @@ -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; diff --git a/Tanshu.Accounts.PointOfSale/Tanshu.Accounts.PointOfSale.csproj b/Tanshu.Accounts.PointOfSale/Tanshu.Accounts.PointOfSale.csproj index 8638037..353fd69 100644 --- a/Tanshu.Accounts.PointOfSale/Tanshu.Accounts.PointOfSale.csproj +++ b/Tanshu.Accounts.PointOfSale/Tanshu.Accounts.PointOfSale.csproj @@ -1,5 +1,5 @@  - + Debug AnyCPU @@ -28,6 +28,11 @@ 1.0.0.%2a false true + + + + + 3.5 true @@ -494,7 +499,9 @@ SalesForm.cs Designer - + + Designer + Form diff --git a/Tanshu.Accounts.Print/PlatformPrinter.cs b/Tanshu.Accounts.Print/PlatformPrinter.cs index f1522f7..5194348 100644 --- a/Tanshu.Accounts.Print/PlatformPrinter.cs +++ b/Tanshu.Accounts.Print/PlatformPrinter.cs @@ -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); } } diff --git a/Tanshu.Accounts.Print/PrinterLinux.cs b/Tanshu.Accounts.Print/PrinterLinux.cs index 46ed14b..6097032 100644 --- a/Tanshu.Accounts.Print/PrinterLinux.cs +++ b/Tanshu.Accounts.Print/PrinterLinux.cs @@ -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; } diff --git a/Tanshu.Accounts.Print/PrinterSocket.cs b/Tanshu.Accounts.Print/PrinterSocket.cs new file mode 100644 index 0000000..dde705b --- /dev/null +++ b/Tanshu.Accounts.Print/PrinterSocket.cs @@ -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; + } + } + } +} diff --git a/Tanshu.Accounts.Print/PrinterWindows.cs b/Tanshu.Accounts.Print/PrinterWindows.cs index e635825..907c557 100644 --- a/Tanshu.Accounts.Print/PrinterWindows.cs +++ b/Tanshu.Accounts.Print/PrinterWindows.cs @@ -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)) { diff --git a/Tanshu.Accounts.Print/Tanshu.Accounts.Print.csproj b/Tanshu.Accounts.Print/Tanshu.Accounts.Print.csproj index b30cd54..69e548e 100644 --- a/Tanshu.Accounts.Print/Tanshu.Accounts.Print.csproj +++ b/Tanshu.Accounts.Print/Tanshu.Accounts.Print.csproj @@ -1,5 +1,5 @@  - + Debug AnyCPU @@ -12,6 +12,11 @@ Tanshu.Accounts.Print v3.5 512 + + + + + 3.5 true @@ -58,10 +63,10 @@ + - diff --git a/Tanshu.Accounts.Print/Thermal.cs b/Tanshu.Accounts.Print/Thermal.cs index 358380d..79d4ff4 100644 --- a/Tanshu.Accounts.Print/Thermal.cs +++ b/Tanshu.Accounts.Print/Thermal.cs @@ -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 diff --git a/Tanshu.Accounts.Print/ThermalPrinter.cs b/Tanshu.Accounts.Print/ThermalPrinter.cs deleted file mode 100644 index 929b5cc..0000000 --- a/Tanshu.Accounts.Print/ThermalPrinter.cs +++ /dev/null @@ -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); - } - } -} diff --git a/Tanshu.Accounts.Repository/ManagementBI.cs b/Tanshu.Accounts.Repository/ManagementBI.cs index c28fb63..c24d602 100644 --- a/Tanshu.Accounts.Repository/ManagementBI.cs +++ b/Tanshu.Accounts.Repository/ManagementBI.cs @@ -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 { diff --git a/Tanshu.Accounts.Repository/Tanshu.Accounts.Repository.csproj b/Tanshu.Accounts.Repository/Tanshu.Accounts.Repository.csproj index 2dde8c4..cff8593 100644 --- a/Tanshu.Accounts.Repository/Tanshu.Accounts.Repository.csproj +++ b/Tanshu.Accounts.Repository/Tanshu.Accounts.Repository.csproj @@ -1,5 +1,5 @@  - + Debug AnyCPU @@ -12,7 +12,11 @@ Tanshu.Accounts.Repository v3.5 512 - Full + + + + + 3.5 true diff --git a/Tanshu.Accounts.Repository/VoucherBI.cs b/Tanshu.Accounts.Repository/VoucherBI.cs index 480d274..e4f0996 100644 --- a/Tanshu.Accounts.Repository/VoucherBI.cs +++ b/Tanshu.Accounts.Repository/VoucherBI.cs @@ -232,12 +232,12 @@ namespace Tanshu.Accounts.Repository public void DiscountPrintedBill(Guid oldVoucherID, Voucher newVoucher) { + Insert(newVoucher); + var oldVoucher = _session.Get(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) diff --git a/Tanshu.Accounts.sln b/Tanshu.Accounts.sln index feadf9d..307ddc0 100644 --- a/Tanshu.Accounts.sln +++ b/Tanshu.Accounts.sln @@ -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}"