示例#1
0
        /// <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(); //显示改变的价格
                }
            }
        }