示例#1
0
        //创建新卡
        private void bttadd_Click(object sender, EventArgs e)
        {
            //如果没有发现可用设备,提示信息
            if (!getinvatehandle)
            {
                MessageBox.Show("请先连接设备!");
                return;
            }
            else if (string.IsNullOrEmpty(txtnewID.Text))
            {
                MessageBox.Show("未检测到可用卡!");
                return;
            }
            else if (UserInfoManage.GetSelectUserinfoByID(txtnewID.Text) != null)
            {
                MessageBox.Show("此卡已经开户,请更换新卡!");
                return;
            }
            else if (string.IsNullOrEmpty(txtmoney.Text))
            {
                MessageBox.Show("请先输入充值金额!");
                return;
            }
            else if (int.Parse(this.txtmoney.Text) <= 0)
            {
                MessageBox.Show("请先输入有效充值金额!");
                return;
            }
            string UserinfoName = this.txtuserName.Text;
            string reg1         = @"^[\u4e00-\u9fa5]+$";

            //如果账户含有中文,则提示信息
            if (!Regex.IsMatch(UserinfoName, reg1))
            {
                MessageBox.Show("账户名称只支持中文!");
            }
            try
            {
                byte[] name = Encoding.Default.GetBytes(this.txtuserName.Text);
                if (EPCSDKHelper.FastWriteTag(handle, 0x03, 0, 6, name, 0))
                {
                    byte[] id = new byte[12];
                    if (EPCSDKHelper.ReadTag(handle, 0x03, 0, 6, id, 0))
                    {
                        Userinfo userinfo = new Userinfo();
                        userinfo.UsercardID = this.txtnewID.Text;
                        userinfo.UserName   = UserinfoName;
                        userinfo.UserMoney  = decimal.Parse(this.txtmoney.Text);
                        if (UserInfoManage.AddUserinfo(userinfo))
                        {
                            MessageBox.Show("开卡成功!");
                        }
                        else
                        {
                            MessageBox.Show("开卡失败!");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }