我为服装店开发了一个应用程序以在该应用程序中打印发票我想使用条形码扫描仪自动从包含条形码的项目标签中收集信息,并自动在我的表格中填写所有信息,然后我打印发票。请给出一些建议如何解决这个问题。我也使用 Microsoft.PointOfService 库。
问问题
6612 次
3 回答
1
假设您在表单中有一个文本框,当条码扫描时,它会在文本框中键入条码字符。通常,某些扫描仪可以配置为在扫描结束时添加另一个字符,最常见的是换行符。有了这个,你可以监听文本框的 KeyPress 事件,并处理换行符。当触发时,您可以检索表单中的其他详细信息。
于 2013-02-26T08:02:25.340 回答
0
通常,条码扫描器只是将所有可识别的符号作为标准键盘输入发送。因此,当用户将焦点设置在应用程序中的文本字段并扫描条形码时,就像用户只是手动输入条形码符号并按“Enter”(或任何其他键,取决于扫描仪设置)一样。
于 2013-02-26T08:01:35.887 回答
0
我的个人图书馆中有一个类来检测扫描仪的工作:
public sealed class ScanReader
{
#region Delegates
public delegate void _DataLoaded(string ScannedData);
#endregion
private readonly double MyMaxMillisecondsBetweenPress;
private readonly List<Regex> MyRegex;
private readonly Timer TimeToNextKeyPress = new Timer();
private string CardBuff = string.Empty;
private bool FirstKeyPress = true;
private DateTime Stamp;
/// <summary>
/// ScanReader constructor
/// </summary>
/// <param name="Press"> Form where KeyPreview = true </param>
/// <param name="Regs"> Regular expressions for filtering scanned data</param>
/// <param name="MaxMillisecondsBetweenPress"> The maximum time between pressing the keys in milliseconds, default = 60 </param>
public ScanReader(Form form, List<Regex> Regs = null, double MaxMillisecondsBetweenPress = 0)
{
MyRegex = Regs ?? null;
MyMaxMillisecondsBetweenPress = MaxMillisecondsBetweenPress == 0 ? 60 : MaxMillisecondsBetweenPress;
form.KeyPress += KeyPressed;
TimeToNextKeyPress.Interval =
Convert.ToInt32(MyMaxMillisecondsBetweenPress + MyMaxMillisecondsBetweenPress*0.2);
TimeToNextKeyPress.Tick += TimeToNextKeyPress_Tick;
}
public event _DataLoaded OnDataLoaded;
private void TimeToNextKeyPress_Tick(object sender, EventArgs e)
{
TimeToNextKeyPress.Stop();
if (MyRegex.Count > 0)
{
foreach (Regex reg in MyRegex)
{
if (reg.IsMatch(CardBuff))
{
OnDataLoaded(CardBuff);
return;
}
}
}
else
OnDataLoaded(CardBuff);
}
private void KeyPressed(object sender, KeyPressEventArgs e)
{
if (FirstKeyPress)
{
Stamp = DateTime.Now;
FirstKeyPress = false;
CardBuff = e.KeyChar.ToString();
}
else
{
if ((DateTime.Now - Stamp).TotalMilliseconds < MyMaxMillisecondsBetweenPress)
{
Stamp = DateTime.Now;
CardBuff += e.KeyChar;
}
else
{
Stamp = DateTime.Now;
CardBuff = e.KeyChar.ToString();
}
}
TimeToNextKeyPress.Stop();
TimeToNextKeyPress.Start();
}
}
如何使用:
var myReader = new ScanReader(this, new List<Regex>
{
new Regex(@"296\d{13,13}"),
new Regex(@"K%.{5,34}"),
new Regex(@"C%.{5,34}"),
new Regex(@"E%.{5,34}"),
});
myReader.OnDataLoaded += FillControls;
于 2013-02-26T08:45:25.460 回答