private void bttmoney_Click(object sender, EventArgs e) { //如果未检测到可用卡,则提示信息 if (string.IsNullOrEmpty(txtxiaofeiID.Text)) { MessageBox.Show("未检测到可用账户!"); return; } else if (UserInfoManage.GetSelectUserinfoByID(txtxiaofeiID.Text) == null) { MessageBox.Show("此卡还未开通,请开卡或换卡!"); return; } else if (string.IsNullOrEmpty(txtxiaofeiMoney.Text)) { MessageBox.Show("请先输入充值金额!"); return; } else if (int.Parse(this.txtxiaofeiMoney.Text) <= 0) { MessageBox.Show("请输入有效的充值金额!"); return; } Userinfo userinfo = new Userinfo(); userinfo.UsercardID = this.txtxiaofeiID.Text; userinfo.UserName = this.txtxiaofeiName.Text; userinfo.UserMoney = decimal.Parse(this.txtxiaofeiMoney.Text); if (UserInfoManage.UpdateUserinfo(userinfo)) { MessageBox.Show("充值成功!"); } }
//购买商品 private void bttgoodsshooping_Click(object sender, EventArgs e) { //如果未检测到可用卡,则提示信息 if (string.IsNullOrEmpty(txtGoodsuserID.Text)) { MessageBox.Show("未检测到可用账户!"); return; } else { Userinfo userinfo = UserInfoManage.GetSelectUserinfoByID(txtGoodsuserID.Text); if (userinfo == null) { MessageBox.Show("此卡还未开通,请开卡或者换卡!"); return; } else if (string.IsNullOrEmpty(txtGoodsID.Text)) { MessageBox.Show("请先选择购买商品!"); return; } else { decimal result = userinfo.UserMoney - Convert.ToDecimal(this.txtGoodsPrice.Text); if (result < 0) { MessageBox.Show("此卡余额不足,请充值后购买!"); return; } } } UserxiaofeiInfo userxiaofei = new UserxiaofeiInfo(); userxiaofei.UsercardID = Convert.ToString(this.txtGoodsuserID.Text); userxiaofei.GoodsID = Convert.ToInt32(this.txtGoodsID.Text); userxiaofei.Userxiaomoney = Convert.ToDecimal(this.txtGoodsPrice.Text); userxiaofei.UserTime = DateTime.Now; if (UserxiaofeiInfoservice.InsertUserxiaofeiinfo(userxiaofei)) { MessageBox.Show("商品购买成功!"); } else { MessageBox.Show("商品购买失败!"); } }
//创建新卡 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); } }