Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Force users to use Barcode Scanner
Message
From
24/06/2010 13:57:22
 
 
To
24/06/2010 12:17:23
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01470416
Message ID:
01470445
Views:
45
>I'm writing a WPF application using VS 2008 for a client that wants to force the users to scan a barcode for data entry into MOST textboxes. But they want a password protected override button on the form that will allow a person to manually enter the text if, for some reason, the barcode is unreadable or the reader is not working.
>
>Does anybody know of a way to ignore data entry into textboxes using the keyboard, but allow barcode scanned text?

On the timing approach maybe something like this:
<Window x:Class="WpfApplication2.Window2"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window2" Height="300" Width="300">
    <DockPanel>
        <TextBox DockPanel.Dock="Top" x:Name="TB" KeyDown="TextBox_KeyDown"></TextBox>
        <TextBox DockPanel.Dock="Top" x:Name="RealBox" IsEnabled="False"></TextBox>
    </DockPanel>
</Window>
Behind:
using System;
using System.Windows;
using System.Windows.Input;

namespace WpfApplication2
{
    public partial class Window2 : Window
    {
        public Window2() {InitializeComponent(); }

        private DateTime start;
        bool counting;

        private void TextBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (counting)
            {
                if (e.Key == Key.OemPlus)
                {
                    //End input
                    if (DateTime.Now < start.AddSeconds(2) && TB.Text.Length==6)
                    {
                        RealBox.Text = TB.Text + "+";
                    }
                    else
                        RealBox.Text = string.Empty;
                    counting = false;
                    TB.Text = string.Empty;
                    e.Handled = true;
                    return;
                }
            }
            if (!counting && e.Key == Key.OemPlus)
            {
                start = DateTime.Now;
                counting = true;
            }
        }
    }
}
Only input with a length of 6 characters and starting and ending with a + sign that is entered in less than 2 seconds will get into the 'RealBox'. Obviously you will need to reduce the time check in real life.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform