コード例 #1
0
ファイル: Form1.cs プロジェクト: LiLulong/Dragon_Library
        //连接设备
        private void bttopen_Click(object sender, EventArgs e)
        {
            int portNo = Convert.ToInt32(this.cmbCom.Text.Replace("COM", ""));

            try
            {
                if (!getinvatehandle)
                {
                    handle = EPCSDKHelper.OpenComm(portNo);
                    if (getinvatehandle)
                    {
                        EPCSDKHelper.StopReading(handle, 0);
                        this.toolStripStatusLabel1.Text = "连接状态:连接";
                        this.toolStripStatusLabel2.Text = "连接的COM口:" + this.cmbCom.Text;
                    }
                    else
                    {
                        MessageBox.Show("连接设备失败,可能其他管理员端正在连接设备!");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: LiLulong/Dragon_Library
 //读取标签信息到相关文本框  txtID帐号 txtName账户姓名
 private void ReadInfo(TextBox txtID, TextBox txtname)
 {
     //如果没有发现可用设备,则提示信息
     if (!getinvatehandle)
     {
         MessageBox.Show("请连接相关设备!");
         return;
     }
     try
     {
         byte[] tagId      = new byte[12];
         byte[] antennaNos = new byte[1];
         byte[] data       = new byte[12];
         //获取账户帐号
         if (txtID != null && EPCSDKHelper.IdentifySingleTag(handle, tagId, antennaNos, 0))
         {
             txtID.Text = ConvertHelper.ByteArrayToHexString(tagId);
             //获取账户姓名
             if (txtname != null && EPCSDKHelper.ReadTag(handle, 0x03, 0, 6, data, 0))
             {
                 txtname.Text = Encoding.Default.GetString(data);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
コード例 #3
0
ファイル: Form1.cs プロジェクト: LiLulong/Dragon_Library
 //关闭设备
 private void bttclose_Click(object sender, EventArgs e)
 {
     try
     {
         if (getinvatehandle)
         {
             EPCSDKHelper.CloseComm(handle);
             handle = IntPtr.Zero;
             this.toolStripStatusLabel1.Text = "连接状态:断开";
             this.toolStripStatusLabel2.Text = "连接的COM口:无";
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
コード例 #4
0
ファイル: Form1.cs プロジェクト: LiLulong/Dragon_Library
        //创建新卡
        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);
            }
        }