int stocknum = 0; //库存 /// <summary> /// 确定购买按钮 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_jiezhang_Click(object sender, EventArgs e) { if (this.lv_sales.Items.Count == 0) { MessageBox.Show("当前无添加书本", "温馨提示"); return; } else { //检索是否能否成功销售 int error = 0; for (int i = 0; i < this.lv_sales.Items.Count; i++) { stocknum = int.Parse(this.lv_sales.Items[i].SubItems[6].Text.ToString()); if (!BooksBLL.UpdateBooksStockNum(this.lv_sales.Items[i].SubItems[2].Text.ToString(), stocknum)) { error++; } } if (error > 0) { MessageBox.Show("库存数可能不足", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else { //存已买的书本的信息 string info = "单号:" + lbl_danhao.Text + "\r\n"; //将书本信息存入字符变量info for (int i = 0; i < this.lv_sales.Items.Count; i++) { info += "书本名字:" + this.lv_sales.Items[i].SubItems[2].Text + "\r\n书本价格:" + this.lv_sales.Items[i].SubItems[4].Text + "\r\n书本折扣:" + this.lv_sales.Items[i].SubItems[5].Text + "\r\n书本数量:" + this.lv_sales.Items[i].SubItems[6].Text + "\r\n"; } info += "总金额:" + lbl_money.Text + "\r\n"; info += "购物员:" + lbl_yuangong.Text; //创建打印信息 for (int i = 0; i < this.lv_sales.Items.Count; i++) { if (stocknum >= 0) { using (StreamWriter st = new StreamWriter(@"D:\小票.txt", false, Encoding.UTF8)) { if (!TextBoxBll.Intextnull(this.txt_shishou.Text, 2) || TextBoxBll.Intextnull(this.txt_shishou.Text, 1)) { if (this.txt_shishou.Text == "") { MessageBox.Show("请输入实收金额", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } else if (this.txt_shishou.Text != null && double.Parse(this.txt_shishou.Text.ToString()) >= double.Parse(this.lbl_money.Text.ToString())) { this.lbl_zhaoling.Text = (double.Parse(this.txt_shishou.Text.ToString()) - double.Parse(this.lbl_money.Text.ToString())).ToString(); st.Write(info); st.Flush(); messge = true; } else { MessageBox.Show("实收金额小于应付金额", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } } else { MessageBox.Show("请正确输入预收金额", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } } } } } //结算成功 if (messge) { //将信息保存至销售表 int Salesmanid = SalemanBll.SelectSalemanByName(this.lbl_yuangong.Text); DateTime time = DateTime.Parse(DateTime.Now.ToString("yyyy年MM月dd日")); SaleBll.InsertSale(this.lbl_danhao.Text, time, sum, Salesmanid); for (int j = 0; j < lv_sales.Items.Count; j++) { //将信息保存至销售详情表 SalesDetail sale = new SalesDetail() { BooksID = BooksBLL.GetBooksIDbyBooksName(this.lv_sales.Items[j].SubItems[2].Text), Quantity = num, SalesID = SaleBll.GetSDIDByTime(this.lbl_danhao.Text), AloneAmount = decimal.Parse(this.lv_sales.Items[j].SubItems[4].Text) * decimal.Parse(this.lv_sales.Items[j].SubItems[5].Text) }; SalesDailBLL.InsertSaleDail(sale); } DataTable dt = VipBll.SetVipByMobile(this.txt_vip.Text); if (isVIP) { if (bijiao == true) //总价大于积分,默认为true { double sum2 = sum / 10; // 1:10积分产生 int sum1 = (int)sum2; //积分取整 if (checkBox1.Checked == true) //若使用积分抵扣 { sum = sum - double.Parse(dt.Rows[0][4].ToString()) * 0.1; //真实价格处理 VipBll.ClearjifenByPhone(this.txt_vip.Text); //积分已抵扣完,现将vip积分清空 } VipBll.UpdatejifenByPhone(this.txt_vip.Text, int.Parse(sum1.ToString())); //正常积分增加 this.jifenshu.Text = sum1.ToString(); //显示结账后的积分 } if (bijiao == false) //总价小于积分抵扣。积分有剩 { double sum2 = sum * 10; //花费的积分 int sum5 = (int)(double.Parse(dt.Rows[0][4].ToString()) - sum2); //抵扣后的积分 if (checkBox1.Checked == true) //若使用积分 { sum = 0; //真实价格处理 VipBll.DecreasejifenByPhone(this.txt_vip.Text, int.Parse(sum2.ToString())); //之前积分减去抵扣积分 } VipBll.UpdatejifenByPhone(this.txt_vip.Text, int.Parse(sum.ToString())); //正常积分增加,不过总价以为0,积分不会增加 this.jifenshu.Text = sum5.ToString(); //显示结账后的积分 } } MessageBox.Show("结算成功,祝您生活愉快", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); //信息初始化 this.lv_sales.Items.Clear(); this.lbl_goods.Text = "0"; liushuihao(); this.lbl_money.Text = "0.0000"; num = 1; this.lbl_zhaoling.Text = "0.0"; this.txt_shishou.Text = ""; this.jifenxianshi.Text = ""; error = 0; sum = 0; sum3 = 0; sum4 = 0; bijiao = true; } } }