バーコード スキャナーを使用して、バーコードを含むアイテム タグから情報を自動的に収集し、フォームにすべての情報を自動的に入力してから、請求書を印刷します。この問題を解決する方法をいくつか提案してください。Microsoft.PointOfService ライブラリも使用します。
6612 次
3 に答える
1
フォームにテキストボックスがあるとします。バーコードがスキャンされると、テキストボックスにバーコード文字が入力されます。通常、一部のスキャナーは、スキャンの最後に別の文字を追加するように構成できます。最も一般的なのは改行文字です。これにより、テキストボックスの KeyPress イベントをリッスンし、改行文字を処理できます。それがトリガーされると、フォーム内の他の詳細を取得できます。
于 2013-02-26T08:02:25.340 に答える
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 に答える
0
通常、バーコード スキャナは、認識されたすべての記号を標準のキーボード入力として送信するだけです。したがって、ユーザーがアプリケーションのテキスト フィールドにフォーカスを設定してバーコードをスキャンすると、ユーザーがバーコード記号を手動で入力して [Enter] (またはスキャナーの設定に応じて他のキー) を押した場合と同じになります。
于 2013-02-26T08:01:35.887 に答える