using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Windows.Forms; using System.Drawing.Printing; using System.Runtime.InteropServices; namespace Neo.Legitimate.Printing { [Guid("4AFAEBD0-92B0-49A8-B29E-6300011BE5F4")] public interface AppReceiptPrinterInterface { void AppPrintReceipt(string ReceiptNumber, string cashierReceiptNumber, string paymentType, string applicantData, string receiptItems, string province, string printedBy, short Copies, string PrinterPath, int height, int width, bool Preview, bool IsReprint); } [ProgId("Neo.Legitimate.ReceiptPrinterControl")] [Guid("44290006-0D62-4454-9E9C-B5623D7D921A")] [ClassInterface(ClassInterfaceType.None)] public partial class AppReceiptPrinterControl : UserControl, AppReceiptPrinterInterface { public AppReceiptPrinterControl() { InitializeComponent(); #region Testing provinceTextBox.Text = "Kwazulu Natal"; CopiesTextBox.Text = "1"; widthTextBox.Text = "210"; heightTextBox.Text = "297"; printerPathTextBox.Text = "Hewlett-Packard LaserJet 2300 series"; printedByTextBox.Text = "Bob Jones"; ReceiptItemsTextBox.Text = "APP0001213,6207305488087,MTHEMBENI ZUNGU,New Operating Licence for member mthembeni zungu,1,300.00,MOPHELA ESTON TAXI OWNERS ASSOCIATION,NC15450,YH63B9003201#APP0024749,5404045254082,NA NGCOBO,Renewal for licence LKNKZN0128452,1,300.00,IZINGOLWENI TAXI OWNERS ASSOCIATION,NPS58267,JTFSX22P806062079,REGIONXXX,ND102030,JTFSX22P806062000#APP0024750,5404045254082,NA NGCOBO,New Operating Licence for member impendhle services (pty) ltd impendhle services (pty) ltd,1,300.00,IZINGOLWENI TAXI OWNERS ASSOCIATION,ND102030,JTFSX22P806062079,REGIONXXX,,#APP0024751,5404045254082,NA NGCOBO,Renewal for licence LKNKZN0128452,1,1200.00,IZINGOLWENI TAXI OWNERS ASSOCIATION,NPS58267,JTFSX22P806062079,REGIONXXX,ND102030,JTFSX22P806062000#APP0001217,6110075388083,SM MADONDO,New Operating Licence for member sm madondo,1,300.00,YELLOW-WOOD PARK TAXI ASSOCIATION,ND398729,AHT41YH6309080561"; applicantDataTextBox.Text = "H Bantjes"; AssociationNameTextBox.Text = ""; paymentTypeTextBox.Text = "Cash"; cashierReceiptTextBox.Text = "25107"; ReceiptNumberTextBox.Text = "RCT0025107"; previewCheckBox.Checked = true; chkReprint.Checked = true; #endregion } private void printButton_Click_1(object sender, EventArgs e) { Print(); } #region public AppPrintReceipt method public void AppPrintReceipt(string ReceiptNumber, string cashierReceiptNumber, string paymentType, string applicantData, string receiptItems, string province, string printedBy, short Copies, string PrinterPath, int height, int width, bool Preview, bool IsReprint) { this.ReceiptNumberTextBox.Text = ReceiptNumber; this.cashierReceiptTextBox.Text = cashierReceiptNumber; this.paymentTypeTextBox.Text = paymentType; this.applicantDataTextBox.Text = applicantData; this.ReceiptItemsTextBox.Text = receiptItems; this.provinceTextBox.Text = province; this.printedByTextBox.Text = printedBy; this.chkReprint.Checked = IsReprint; if (Copies.ToString() == "999") { string userInput = Microsoft.VisualBasic.Interaction.InputBox("Please enter the number of receipts you would like to print.", "Print receipts", "6", 400, 400).ToString(); try { if (userInput.Length == 0) { return; } int numberCopies = Int32.Parse(userInput); this.CopiesTextBox.Text = numberCopies.ToString(); } catch { MessageBox.Show("Invalid number entered."); return; } } else { this.CopiesTextBox.Text = Copies.ToString(); } this.heightTextBox.Text = height.ToString(); this.widthTextBox.Text = width.ToString(); this.previewCheckBox.Checked = Preview; this.printerPathTextBox.Text = GetPrinter(PrinterPath); if (this.printerPathTextBox.Text.Length == 0) { MessageBox.Show("No printer named " + PrinterPath + " found."); } else { try { Print(); if (!Preview) { MessageBox.Show(this.CopiesTextBox.Text + " copies printed to " + printerPathTextBox.Text); } } catch (Exception e) { MessageBox.Show(e.Message); } } } #endregion #region private Print() Method private void Print() { AppReceiptPrinter receiptPrinter1 = new AppReceiptPrinter(this.ReceiptNumberTextBox.Text, this.cashierReceiptTextBox.Text, this.paymentTypeTextBox.Text, this.applicantDataTextBox.Text, this.ReceiptItemsTextBox.Text, this.provinceTextBox.Text, this.AssociationNameTextBox.Text,this.printedByTextBox.Text, Convert.ToInt16(this.CopiesTextBox.Text), GetPrinter(this.printerPathTextBox.Text), Convert.ToInt16(this.heightTextBox.Text), Convert.ToInt16(this.widthTextBox.Text), this.previewCheckBox.Checked, this.chkReprint.Checked); receiptPrinter1.Print(); } #endregion #region getPrinter private string GetPrinter(string PrinterPath) { string printerName = ""; foreach (String printer in PrinterSettings.InstalledPrinters) { if (printer.ToLower().Contains(PrinterPath.ToLower())) { printerName = printer; } } return printerName; } #endregion } }