c#如果扫描仪读数保存到数据库 - 表格背景 - 摩托罗拉手持扫描仪

时间:2015-11-24 10:42:39

标签: c# database barcode-scanner motorola

我写了一个简单的程序,用手扫描器代码39条形码(USB端口)读取到文本框,并将结果('如果文本框已更改')保存到数据库。但是如果表单被隐藏,那么它就不会被读到正确的位置。有人可以帮我解决这个问题吗?我想某种方式,如果扫描仪读取然后自动保存到数据库,但如何?

一些代码:

     void countDown_Tick(object sender, EventArgs e)
  {

   TimeRemained--;

   if (TimeRemained == 0 && (txt_kod.Text != ""))
   {
       try
       {
           if (txt_kod.Text.Length == 4 )
           {

               connection.Open();
               OleDbCommand command = new OleDbCommand();
               command.Connection = connection;
               //MessageBox.Show(mini);
               command.CommandText = " insert into Jelenlet (Kod,Datum) values  ('" + txt_kod.Text + "','" + adat + "')";

               command.ExecuteNonQuery();
               // MessageBox.Show(txt_kod.Text);


               connection.Close();
               txt_kod.Text = String.Empty;

           }
           else
           {
               //MessageBox.Show("Rossz beolvasás");
               Console.Beep();
               Console.Beep();
               Console.Beep();

               txt_kod.Text = String.Empty;
               connection.Close();
           }
       }

       catch (Exception ex)
       {

           MessageBox.Show("Error " + ex);
           connection.Close();

       }





   }

      private void timer1_Tick(object sender, EventArgs e)
    {
        DateTime dateTime = DateTime.Now;
        this.time_lbl.Text = dateTime.ToString("yyyy/MM/dd");
    }
    Timer countDown = new Timer();
    int TimeRemained;
    string adat;
    private void textBox1_TextChanged(object sender, EventArgs e)
    {
        //timer2.Start();

        countDown.Interval = 1000;
        TimeRemained = 1;

        countDown.Tick += new EventHandler(countDown_Tick);
        countDown.Enabled = true;


      //  MessageBox.Show(idoszak_lbl.Text);
        //MessageBox.Show(adat);
        adat = time_lbl.Text + "." + idoszak_lbl.Text;
        //adat = time_lbl.Text + "." + idoszak_lbl.Text + "." + lbl_hobbi.Text; // csütörtök vizsgálat esetén













    }

我有很多形式在这个程序中同时使用,我不会等待阅读,我想自动化它。

我想使用摩托罗拉手持扫描仪。

0 个答案:

没有答案