private void btn_JianSuo_Click(object sender, EventArgs e) { //检索条形码是否存在 如果存在则将数据显示出来 DataTable dt = BooksBLL.SelectBooksTypeByBarCode(txt_tiaoxingma.Text); if (dt.Rows.Count == 1) { MessageBox.Show("当前书本已存在", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); txt_goodsname.Text = dt.Rows[0]["BooksName"].ToString(); this.cbo_type.Text = dt.Rows[0]["TypeName"].ToString(); txt_jinjia.Text = dt.Rows[0]["StorePrice"].ToString(); txt_maijia.Text = dt.Rows[0]["SalePrice"].ToString(); txt_zhekou.Text = dt.Rows[0]["Discount"].ToString(); lbl_kucun.Text = dt.Rows[0]["StockNum"].ToString(); label8.Text = "当前库存数:"; this.txt_goodsname.ReadOnly = true; this.txt_jinjia.ReadOnly = true; this.txt_maijia.ReadOnly = true; this.txt_tiaoxingma.ReadOnly = true; this.txt_zhekou.ReadOnly = true; this.cbo_type.Enabled = false; } else { MessageBox.Show("书本不存在,请填写信息", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } }
/// <summary> /// 添加书本 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void skinButton2_Click(object sender, EventArgs e) { //获取类型ID try { booktype = TypeBLL.GetTypeIDByTypeName(this.cbo_type.Text); } catch (Exception) { MessageBox.Show("请先去添加书本类型", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } try { //添加书本 if (this.txt_goodname.Text == "" || this.txt_jinjia.Text == "" || this.txt_kucun.Text == "" || this.txt_shoujia.Text == "" || this.txt_tiaoxingma.Text == "" || this.txt_zhekou.Text == "") { MessageBox.Show("带*号不能为空", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } else if (TextBoxBll.Intextnull(this.txt_kucun.Text, 2)) { MessageBox.Show("库存必须为正整数", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else if (TextBoxBll.Intextnull(this.txt_zhekou.Text, 4)) { MessageBox.Show("折扣请输入0~1的数字", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } else if (BooksBLL.SelectBooksTypeByBarCode(this.txt_tiaoxingma.Text).Rows.Count > 0) { MessageBox.Show("该条形码已存在", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } else if (TextBoxBll.Intextnull(this.txt_tiaoxingma.Text, 1)) { MessageBox.Show("条形码长度过长", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else { Books gs = new Books(); gs.BooksName = this.txt_goodname.Text; gs.TypeID = booktype; gs.BarCode = this.txt_tiaoxingma.Text; gs.StorePrice = decimal.Parse(this.txt_jinjia.Text.ToString()); gs.SalePrice = decimal.Parse(this.txt_shoujia.Text.ToString()); gs.Discount = decimal.Parse(this.txt_zhekou.Text.ToString()); gs.StockNum = int.Parse(this.txt_kucun.Text); gs.StockDate = DateTime.Parse(this.dtp_riqi.Text.ToString()); if (BooksBLL.InsertBooks(gs)) { MessageBox.Show("添加成功", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); //绑定数据源 this.dgv_goods.DataSource = BooksBLL.GetBooksandType(); //初始化文本框数据 this.txt_goodsname.Text = null; this.txt_jinjia.Text = null; this.txt_kucun.Text = null; this.txt_shoujia.Text = null; this.txt_tiaoxingma.Text = null; this.txt_zhekou.Text = null; } } } catch (Exception) { MessageBox.Show("请正确填写信息", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } }
/// <summary> /// 导入书本 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_daoru_Click(object sender, EventArgs e) { int allNum = 0; //统计书本总数 bool b = true; //用于判断书本是否存在 //如果按的是“回车键” //获取条形码 string barCode = this.txt_shangping.Text; if (true) { //购物列表中不存在该书本 //根据输入的条形码,查询书本信息 DataTable dt_books = BooksBLL.SelectBooksTypeByBarCode(barCode); //未查询到书本 if (dt_books.Rows.Count == 0) { MessageBox.Show("书本未找到,请检查条形码是否正确!", "温馨提示:", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (dt_books.Rows[0]["StockNum"].ToString() == "0") { MessageBox.Show("书本以售空,请及时补货", "温馨提示"); return; } bool flag = true; //书本是否存在于购物车 计算书本数量 for (int i = 0; i < this.lv_sales.Items.Count; i++) { //判断添加书本数量是否超过库存 if (dt_books.Rows[0]["BooksName"].ToString() == this.lv_sales.Items[i].SubItems[2].Text) { string goodsName = dt_books.Rows[0]["BooksName"].ToString(); int stockNum = BooksBLL.GetStockNumByBooksName(goodsName);; if (stockNum == num) { MessageBox.Show("库存数不足", "温馨提示"); b = false; flag = false; break; } else { if (flag) { this.lv_sales.Items[i].SubItems[6].Text = (int.Parse(this.lv_sales.Items[i].SubItems[6].Text) + 1).ToString(); num++; //书本存在则数量加 1 b = false; //如果书本存在则把布尔变量b--赋值为false discount = double.Parse(dt_books.Rows[0]["Discount"].ToString()); price = double.Parse(dt_books.Rows[0]["SalePrice"].ToString()) * discount; //显示金额信息 this.lbl_money.Text = sum.ToString(); } } } else { //初始化数量 num = 1; } } if (b) { //创建购物项 ListViewItem item = new ListViewItem(dt_books.Rows[0]["BarCode"].ToString()); item.SubItems.Add(dt_books.Rows[0]["BooksID"].ToString()); item.SubItems.Add(dt_books.Rows[0]["BooksName"].ToString()); item.SubItems.Add(dt_books.Rows[0]["TypeName"].ToString()); item.SubItems.Add(dt_books.Rows[0]["SalePrice"].ToString()); item.SubItems.Add(dt_books.Rows[0]["Discount"].ToString()); item.SubItems.Add(num.ToString()); //for (int i = 0; i < lv_sales.Items.Count; i++) //{ // //记录书本ID,结算时需要用到该值 // id1[i] = int.Parse(dt_goods.Rows[0]["BooksID"].ToString()); //} //添加至购物车列表 this.lv_sales.Items.Add(item); } //获取ListView(书本)中所有行并显示 for (int i = 0; i < this.lv_sales.Items.Count; i++) { allNum += int.Parse(this.lv_sales.Items[i].SubItems[6].Text); } DataTable dt = VipBll.SetVipByMobile(this.txt_vip.Text); if (flag) { allGoodsNum = allNum; lbl_goods.Text = allNum.ToString(); discount = double.Parse(dt_books.Rows[0]["Discount"].ToString()); price = double.Parse(dt_books.Rows[0]["SalePrice"].ToString()) * discount; //求和 sum += (price); //得到真实总价 sum4 = sum; //将现在的总价赋给临时变量,sum4来处理积分抵扣显示数据 if (checkBox1.Checked == true) //若选择抵扣 { if (sum > int.Parse(dt.Rows[0][4].ToString()) * 0.1) //如果真实总价大于积分抵扣 { sum4 -= int.Parse(dt.Rows[0][4].ToString()) * 0.1; //临时总价被抵扣 this.jifenxianshi.Text = "积分已抵扣" + int.Parse(dt.Rows[0][4].ToString()) * 0.1; //显示抵扣积分 } if (sum <= int.Parse(dt.Rows[0][4].ToString()) * 0.1) //表示总价小于积分 { sum4 = 0; this.jifenxianshi.Text = "积分已抵扣" + sum; //显示抵扣积分 bijiao = false; //标记 总价小于积分 } } if (checkBox1.Checked == false) { sum4 = sum; //还原价格 } this.lbl_money.Text = sum4.ToString(); //显示改变的价格 } } }
/// <summary> /// 添加书本 /// </summary> public void 添加书本() { //执行命令 if (this.txt_goodsname.Text == "") { MessageBox.Show("书名不能为空", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } else if (this.txt_tiaoxingma.Text == "") { MessageBox.Show("书的条形码不能为空", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } else if (this.txt_tiaoxingma.Text == "") { MessageBox.Show("书的条形码不能为空", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } else if (TextBoxBll.Intextnull(this.txt_zhekou.Text, 4)) { MessageBox.Show("折扣必须为0~1的小数", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } else if (TextBoxBll.Intextnull(this.txt_goodsnum.Text, 2)) { MessageBox.Show("书的数量错误", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } else if (decimal.Parse(this.txt_jinjia.Text.ToString()) < 0 || this.txt_jinjia.Text == "") { MessageBox.Show("请正确填写书的进价", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } else if (decimal.Parse(this.txt_maijia.Text.ToString()) < 0 || this.txt_maijia.Text == "") { MessageBox.Show("请正确填写书的售价", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } else if (decimal.Parse(this.txt_zhekou.Text.ToString()) > 0 && decimal.Parse(this.txt_zhekou.Text.ToString()) < 1 || this.txt_zhekou.Text == "") { MessageBox.Show("请正确填写书的折扣", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } else if (int.Parse(this.txt_goodsnum.Text.ToString()) < 0) { MessageBox.Show("进货数量不正确", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } Books gs = new Books(); gs.BooksName = this.txt_goodsname.Text; gs.TypeID = TypeBLL.GetTypeIDByTypeName(this.cbo_type.Text); gs.BarCode = this.txt_tiaoxingma.Text; gs.StorePrice = decimal.Parse(this.txt_jinjia.Text.ToString()); gs.SalePrice = decimal.Parse(this.txt_maijia.Text.ToString()); gs.Discount = decimal.Parse(this.txt_zhekou.Text.ToString()); gs.StockNum = int.Parse(this.txt_goodsnum.Text); gs.StockDate = DateTime.Parse(DateTime.Now.ToString("yyyy年MM月dd日HH:mm:ss")); DataTable dt = BooksBLL.SelectBooksTypeByBarCode(this.txt_tiaoxingma.Text); //进货 if (dt.Rows.Count == 1) { try { //进货 int newGoods = int.Parse(this.txt_goodsnum.Text); int oldGoods = int.Parse(dt.Rows[0]["StockNum"].ToString()); BooksBLL.InsertbooksByBarCod(newGoods, oldGoods, this.txt_tiaoxingma.Text); MessageBox.Show("进货成功", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { this.txt_goodsname.ReadOnly = false; this.txt_jinjia.ReadOnly = false; this.txt_maijia.ReadOnly = false; this.txt_tiaoxingma.ReadOnly = false; this.txt_zhekou.ReadOnly = false; this.cbo_type.Enabled = true; //初始化数据 this.cbo_type.Text = ""; this.txt_goodsname.Text = ""; this.txt_goodsnum.Text = ""; this.txt_jinjia.Text = ""; this.txt_maijia.Text = ""; this.txt_tiaoxingma.Text = ""; this.txt_zhekou.Text = ""; } } else { try { //执行添加操作 if (BooksBLL.InsertBooks(gs)) { MessageBox.Show("添加成功", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { //初始化数据 this.cbo_type.SelectedIndex = 0; this.txt_goodsname.Text = ""; this.txt_goodsnum.Text = ""; this.txt_jinjia.Text = ""; this.txt_maijia.Text = ""; this.txt_tiaoxingma.Text = ""; this.txt_zhekou.Text = ""; } } }