Files
lserp_cs_6.0/插件库/Lskj.PubInvoiceOut/FrmQrCode.cs
T
tdx e28188af85 SVN r1146
SVN-Revision: r1146
2026-03-22 13:50:57 +00:00

137 lines
6.3 KiB
C#

using Lskj.Control;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ZXing;
using ZXing.QrCode;
namespace Lskj.PubInvoiceOut
{
public partial class FrmQrCode : BaseForm
{
public EventHandler<ResultEventArgs> OnAttestationCallback;
public EventHandler<ResultEventArgs> OnVerifyQrCodeCallback;
public System.Threading.Thread thread;
public FrmQrCode()
{
InitializeComponent();
this.Load += OnFrmQrCodeLoad;
}
private void OnFrmQrCodeLoad(object sender, EventArgs e)
{
ResultEventArgs resultEventArgs = new ResultEventArgs();
if (OnAttestationCallback != null)
{
OnAttestationCallback(null, resultEventArgs);
if (resultEventArgs.Code.Equals("0000"))
{
string qrId = resultEventArgs.Result;
var options = new QrCodeEncodingOptions
{
Width = 180,
Height = 180,
Margin = 1
};
var writer = new BarcodeWriter();
writer.Format = BarcodeFormat.QR_CODE;
writer.Options = options;
var bitmap = writer.Write(qrId);
this.qrCodeImage.Image = bitmap;
}
else
{
MessageUtil.Show(resultEventArgs.Message);
this.DialogResult = DialogResult.Cancel;
this.Close();
this.Dispose();
return;
}
thread = new System.Threading.Thread(() =>
{
bool isContain = true;
while (isContain)
{
try
{
if (OnVerifyQrCodeCallback != null)
{
OnVerifyQrCodeCallback(null, resultEventArgs);
}
if (resultEventArgs.Code.Equals("0000"))
{
if (resultEventArgs.Result.Equals("2"))//完成
{
if (this.InvokeRequired && this.IsHandleCreated)
{
this.Invoke(new Action(() =>
{
this.DialogResult = DialogResult.OK;
this.Close();
this.Dispose();
}));
}
else
{
this.DialogResult = DialogResult.OK;
this.Close();
this.Dispose();
}
}
else if (resultEventArgs.Result.Equals("3"))//过期
{
resultEventArgs = new ResultEventArgs();
if (OnAttestationCallback != null)
{
OnAttestationCallback(null, resultEventArgs);
if (resultEventArgs.Code.Equals("0000"))
{
string qrId = resultEventArgs.Result;
var options = new QrCodeEncodingOptions
{
Width = 180,
Height = 180,
Margin = 1
};
var writer = new BarcodeWriter();
writer.Format = BarcodeFormat.QR_CODE;
writer.Options = options;
var bitmap = writer.Write(qrId);
if (this.InvokeRequired && this.IsHandleCreated)
{
this.Invoke(new Action(() =>
{
this.qrCodeImage.Image = bitmap;
}));
}
else
{
this.qrCodeImage.Image = bitmap;
}
}
else
{
if (this.InvokeRequired && this.IsHandleCreated)
{
this.Invoke(new Action(() =>
{
MessageUtil.Show(resultEventArgs.Message);
this.DialogResult = DialogResult.Cancel;
this.Close();
this.Dispose();
}));
}
else
{
MessageUtil.Show(resultEventArgs.Message);
this.DialogResult = DialogResult.Cancel;
this.Close();
this.Dispose();
}