各位大侠,小弟做了一个使用扫描器把二维条码输入textbox的系统,调试时就是不能在textbox中输入正确的数值以下是代码
        private void textBox5_TextChanged(object sender, EventArgs e)
        {
            if(textBox5 .Text!="")
            {
                if (textBox5.Text.Length != 13)
                {
                    MessageBox.Show("SN长度错误,请确认!!!");
                    textBox5.Text = "";
                    return;
                }
                try
                {
                    con.Open();
                    cmd.CommandText = "select 1 from dbo.Netgear_DB where netgear_SN='" + textBox5.Text.Trim() + "'";
                    if (null !=cmd.ExecuteScalar())
                    {
                        MessageBox.Show("SN已经存在");
                    }
                    else
                    {
                        con.Close();
                        int a = 0, b = 0, c = 12, check = 0;
                        string str = textBox5.Text;
                        string[] strs = new string[textBox5.Text.Length];
                        for (int i = 0; i < strs.Length; i++)
                        {
                            if (i != 7)
                            {
                                strs[i] = textBox5.Text.Substring(i, 1);
                                a = ConvertBase32ToBase10(strs[i]);
                                if (a != 100)
                                {
                                    b += a * c;
                                    c--;
                                }
                                else
                                {
                                    MessageBox.Show("SN编码规则不正确,请确认");
                                    textBox5.Text = "";
                                    return;                                }
                            }
                            else
                            {
                                
                                check = ConvertBase32ToBase10(textBox5.Text.Substring(i, 1));
                                if (check == 100)
                                {
                                    MessageBox.Show("SN检验码错误,请确认");
                                    textBox5.Text = "";
                                    return; ;                                }                            }
                        }
                        
                        if (b % 32 == check)
                        {
                            this.textBox6.Focus();
                           
                        }
                        else
                        {
                            MessageBox.Show("SN 编码错误,请更正");
                            textBox5.Text = "";
                            return;
                        }
                    }
                }
                finally
                {                }
            }
        }请各位帮忙,看看哪里出了问题,跪谢

解决方案 »

  1.   

    http://download.csdn.net/source/2606754
      

  2.   

    问题补充就是运行时,输入条码数据,textbox中无数据显示
      

  3.   

    那个码是不是code-128的啊,条行码是根据数字生成的,如果扫出不对,证明那个数字生成就是错的,你看看代码里能不能生成你那个码。跟扫描没关系。
      

  4.   


    我以前用的扫描枪背面有dip开关,能够设置扫描后是否自动输入回车,你看看你的扫描枪文档,是否也有类似设置?