Win CE 5.0 嵌入式开发(摩托罗拉MC3000数据采集器,条码扫描仪)

 

图片

 public Main()
        {
            InitializeComponent();
            this.txtbarcode.Focus();
        }
        //扫描txt文本文件查询操作
        private void BarCodeScan()
        {
            string code = this.txtbarcode.Text.Trim();
            string fileName = "barcodeinfo.txt";
            StreamReader sr = new StreamReader(fileName, Encoding.Default);//以gb2312字符编码格式读取文本。
            string str;
            int count=0;
            while ((str = sr.ReadLine()) != null)//读取每一行
            {
                if (str.IndexOf(code) == 0)
                {
                    this.listBoxCode.Items.Add(str);
                    this.listBoxCode.SelectedIndex = this.listBoxCode.Items.Count - 1;
                    count = count + 1;
                }
            }
            if (count == 0)
            {
                this.listBoxCode.Items.Add(code + "    无条码信息");
                this.listBoxCode.SelectedIndex = this.listBoxCode.Items.Count - 1;
            }
            sr.Close();
            this.txtbarcode.Text = null;
        }

        //点击enter后的动作
        private void txtbarcode_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar.ToString() == "/r")
            {
                BarCodeScan();
            }
        }

        //删除按钮功能
        private void BtnDelete_Click(object sender, EventArgs e)
        {
            if (this.listBoxCode.SelectedItem == null)
            {
                MessageBox.Show("请先选择需要删除的行!");
            }
            else
            {
                DialogResult MsgBoxResult;//设置对话框的返回值
                MsgBoxResult = MessageBox.Show("你确定要删除此条码?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2);
                if (MsgBoxResult == DialogResult.Yes)//如果对话框的返回值是YES(按"Y"按钮)
                {
                    this.listBoxCode.Items.Remove(listBoxCode.SelectedItem);
                    this.txtbarcode.Focus();

                }
                if (MsgBoxResult == DialogResult.No)//如果对话框的返回值是NO(按"N"按钮)
                {
                    this.txtbarcode.Focus();
                }          
            }
        }

        // 提取字符串中为数字的字符串
        public string getNum(String str)
        {
            string ss="";
            for (int i = 0; i < str.Length; i++)
            {
                if (Char.IsNumber(str, i) == true)
                {
                    ss += str.Substring(i, 1);
                }
                else
                {
                    if (str.Substring(i, 1) == ",")
                    {
                        ss += str.Substring(i, 1);
                    }
                }
                   
            }
            return ss;
        }

        private void BtnOut_Click(object sender, EventArgs e)
        {
            if (this.listBoxCode.Items.Count == 0)
            {
                MessageBox.Show("没有数据可导出!");
            }
            else
            {
                using (StreamWriter sw = new StreamWriter("barcode.txt",true))
                {
                    for (int i = 0; i < listBoxCode.Items.Count; i++)
                    {
                        string str = listBoxCode.Items[i].ToString();
                        sw.WriteLine(getNum(str));
                    }
                    MessageBox.Show("数据导出成功!");
                } 
            }
        }

        private void BtnReset_Click(object sender, EventArgs e)
        {
            if (this.listBoxCode.Items.Count == 0)
            {
                MessageBox.Show("条码列表无数据!");
            }
            else
            {
                DialogResult MsgBoxResult;//设置对话框的返回值
                MsgBoxResult = MessageBox.Show("你确定要清空条码列表?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2);
                if (MsgBoxResult == DialogResult.Yes)//如果对话框的返回值是YES(按"Y"按钮)
                {
                    this.listBoxCode.Items.Clear();
                    this.txtbarcode.Focus();

                }
                if (MsgBoxResult == DialogResult.No)//如果对话框的返回值是NO(按"N"按钮)
                {
                    this.txtbarcode.Focus();
                }
            }
        }

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值