You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
3.3 KiB
95 lines
3.3 KiB
using System;
|
|
using System.Windows;
|
|
using System.IO;
|
|
using System.Windows.Xps.Packaging;
|
|
using CodeReason.Reports;
|
|
//using ZXing;
|
|
//using ZXing.QrCode;
|
|
using System.Drawing;
|
|
using System.Drawing.Imaging;
|
|
using System.Windows.Media.Imaging;
|
|
using SSWMS.Common;
|
|
|
|
namespace SSWMS.Client
|
|
{
|
|
public partial class PrintQRCode : Window
|
|
{
|
|
private string QRCode = string.Empty;
|
|
public PrintQRCode(string sQRCode)
|
|
{
|
|
InitializeComponent();
|
|
QRCode = sQRCode;
|
|
Window_Loaded(null, null);
|
|
}
|
|
|
|
private void Window_Loaded(object sender, RoutedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
using (StreamReader reader = new StreamReader(new FileStream(AppDomain.CurrentDomain.BaseDirectory + @"@Files\Templates\QRCode.xaml", FileMode.Open, FileAccess.Read)))
|
|
{
|
|
ReportDocument reportDocument = new ReportDocument()
|
|
{
|
|
XamlData = reader.ReadToEnd(),
|
|
XamlImagePath = Path.Combine(Environment.CurrentDirectory, @"@Files\Templates\")
|
|
};
|
|
reportDocument.ImageProcessing += ReportDocument_ImageProcessing;
|
|
reportDocument.ImageError += ReportDocument_ImageError;
|
|
ReportData data = new ReportData();
|
|
string[] asQRCode = this.QRCode.Split('-');
|
|
if (asQRCode.Length == 2)
|
|
{
|
|
data.ReportDocumentValues.Add("QRCodeText1", string.Format("{0}-{1}",
|
|
asQRCode[0], asQRCode[1]));
|
|
data.ReportDocumentValues.Add("QRCodeText2", string.Format("-{0}-{1}-{2}-{3}",
|
|
1, 2, 3, 4));
|
|
}
|
|
XpsDocument xps = reportDocument.CreateXpsDocument(data);
|
|
dvQRCode.Document = xps.GetFixedDocumentSequence();
|
|
reader.Close();
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageDialog.ShowException(ex);
|
|
this.Close();
|
|
}
|
|
}
|
|
|
|
private void ReportDocument_ImageError(object sender, ImageErrorEventArgs e)
|
|
{
|
|
e.Handled = true;
|
|
}
|
|
|
|
private void ReportDocument_ImageProcessing(object sender, ImageEventArgs e)
|
|
{
|
|
if (e.Image.Name == "QRCodeImage")
|
|
{
|
|
//IBarcodeWriter ibw = new BarcodeWriter()
|
|
//{
|
|
// Format = BarcodeFormat.QR_CODE,
|
|
// Options = new QrCodeEncodingOptions
|
|
// {
|
|
// DisableECI = true,
|
|
// CharacterSet = "UTF-8"
|
|
// }
|
|
//};
|
|
//Bitmap bitmap = ibw.Write(this.QRCode);
|
|
//if (bitmap != null)
|
|
//{
|
|
// MemoryStream ms = new MemoryStream();
|
|
// bitmap.Save(ms, ImageFormat.Bmp);
|
|
// ms.Position = 0;
|
|
// bitmap.Dispose();
|
|
|
|
// BitmapImage bi = new BitmapImage();
|
|
// bi.BeginInit();
|
|
// bi.StreamSource = ms;
|
|
// bi.EndInit();
|
|
// e.Image.Source = bi;
|
|
//}
|
|
}
|
|
}
|
|
}
|
|
}
|