2013-02-26 111 views
0

我开发了一个服装商店的应用程序以在该应用程序中打印发票我想使用条形码扫描仪从包含条形码的物料标签中自动收集信息并自动填充所有信息我的表格,然后打印发票。 请给出一些建议如何解决这个问题。 我也使用Microsoft.PointOfService库。在windows应用程序中使用条形码扫描器C#

回答

0

通常,条形码扫描器只是将所有识别的符号作为标准键盘输入发送。因此,当用户将注意力集中在应用程序中的文本字段并扫描条形码时,就像用户手动输入条形码符号并按“Enter”(或任何其他键,取决于扫描仪设置)一样。

+0

@亚历克斯·基谢廖夫感谢您的答复.. – 2013-02-26 10:30:07

1

假设在表单中有一个文本框,当条形码扫描时,它会在文本框中键入条形码字符。通常,一些扫描仪可以配置为在扫描结束时添加另一个字符,通常是新行字符。借此,您可以收听文本框的KeyPress事件,并处理新行字符。当它被触发时,那么你可以检索表单中的其他细节。

+0

谢谢您的回答 – 2013-02-26 10:28:27

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; 
相关问题