Add Printer Class, printerForm
This commit is contained in:
parent
5f7ac10f22
commit
315d2fd03a
|
@ -141,6 +141,7 @@
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="PlateDetector.cs" />
|
<Compile Include="PlateDetector.cs" />
|
||||||
<Compile Include="PlateProcessor.cs" />
|
<Compile Include="PlateProcessor.cs" />
|
||||||
|
<Compile Include="Printer.cs" />
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Sidebar.cs">
|
<Compile Include="Sidebar.cs">
|
||||||
|
@ -223,6 +224,9 @@
|
||||||
<Content Include="plateLong.xml">
|
<Content Include="plateLong.xml">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
|
<Content Include="PrinterForm.html">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<BootstrapperPackage Include=".NETFramework,Version=v4.6.1">
|
<BootstrapperPackage Include=".NETFramework,Version=v4.6.1">
|
||||||
|
|
72
AIParkingApplication/Printer.cs
Normal file
72
AIParkingApplication/Printer.cs
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
using Microsoft.Win32;
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace AIParkingApplication
|
||||||
|
{
|
||||||
|
public class Printer
|
||||||
|
{
|
||||||
|
private WebBrowser webBrowser;
|
||||||
|
public Printer()
|
||||||
|
{
|
||||||
|
webBrowser = new WebBrowser();
|
||||||
|
SetupPrinterPageSetting();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DoPrint(PrinterData printData)
|
||||||
|
{
|
||||||
|
webBrowser.Left = 0;
|
||||||
|
string documentText = ProcessingString("PrinterForm.html", printData);
|
||||||
|
if (!string.IsNullOrEmpty(documentText))
|
||||||
|
{
|
||||||
|
webBrowser.DocumentText = documentText;
|
||||||
|
webBrowser.DocumentCompleted += WebBrowser_DocumentCompleted;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
|
||||||
|
{
|
||||||
|
((WebBrowser)sender).Print();
|
||||||
|
}
|
||||||
|
|
||||||
|
private string ProcessingString(string path, PrinterData printerField)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string htmlStr = File.ReadAllText(path);
|
||||||
|
htmlStr = htmlStr.Replace("{PLATE_STRING}", printerField.PlateString)
|
||||||
|
.Replace("{TIME_PARKING_IN}", printerField.TimeParkingIn)
|
||||||
|
.Replace("{TIME_PARKING_OUT}", printerField.TimeParkingOut)
|
||||||
|
.Replace("{MONEY_AMOUNT}", printerField.MoneyAmount.ToString());
|
||||||
|
return htmlStr;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"ProcessingString\texMessage:{ex.Message}");
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupPrinterPageSetting()
|
||||||
|
{
|
||||||
|
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer\PageSetup", RegistryKeyPermissionCheck.ReadWriteSubTree);
|
||||||
|
|
||||||
|
key.SetValue("footer", string.Empty, RegistryValueKind.String);
|
||||||
|
key.SetValue("header", string.Empty, RegistryValueKind.String);
|
||||||
|
key.SetValue("margin_top", 0);
|
||||||
|
key.SetValue("margin_right", 0.2);
|
||||||
|
key.SetValue("margin_bottom", 0.5);
|
||||||
|
key.SetValue("margin_left", 0.2);
|
||||||
|
key.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class PrinterData
|
||||||
|
{
|
||||||
|
public string PlateString { get; set; }
|
||||||
|
public string TimeParkingIn { get; set; }
|
||||||
|
public string TimeParkingOut { get; set; }
|
||||||
|
public int MoneyAmount { get; set; }
|
||||||
|
}
|
||||||
|
}
|
31
AIParkingApplication/printerForm.html
Normal file
31
AIParkingApplication/printerForm.html
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Document</title>
|
||||||
|
<style>
|
||||||
|
@media only print {
|
||||||
|
@page {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
margin: 0 20px;
|
||||||
|
height: 100px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body style="">
|
||||||
|
<h3 style="text-align: center;"><em>BỆNH VIỆN BẠCH MAI</em></h3>
|
||||||
|
<h2 style="text-align: center;"><strong>Biên lai thu tiền</strong></h2>
|
||||||
|
<p>Biển số xe: <em><strong>{PLATE_STRING}</strong></em></p>
|
||||||
|
<p>Thời gian vào: <em><strong>{TIME_PARKING_IN}</strong></em></p>
|
||||||
|
<p>Thời gian ra: <strong><em>{TIME_PARKING_OUT}</em></strong></p>
|
||||||
|
<p>Số tiền: <strong><em>{MONEY_AMOUNT}</em></strong></p>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
Loading…
Reference in New Issue
Block a user