/// <summary> /// 修改 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_xiugai_Click(object sender, EventArgs e) { try { if (id != 0) { if (TextBoxBll.Intextnull(this.txt_mobile.Text, 3)) { MessageBox.Show("请输入正确的电话号码", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else if (TextBoxBll.Intextnull(this.txt_commissionRate.Text, 4))//验证提成是否为1~0之间的数字 { MessageBox.Show("提成必须是0~1的数字", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else if (TextBoxBll.Intextnull(this.txt_name.Text, 1)) { MessageBox.Show("姓名格式错误", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else { Saleman saleman = new Saleman() { SalesmanName = this.txt_name.Text, Mobile = this.txt_mobile.Text, Pwd = this.txt_pwd.Text, Gender = this.cbo_gander.Text, BaseSalary = this.txt_basesalary.Text, CommissionRate = this.txt_commissionRate.Text, Work = this.cbo_work.Text }; if (SalemanBll.UpdateSaleman(saleman)) { MessageBox.Show("修改成功", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else { MessageBox.Show("修改失败", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } } } else { MessageBox.Show("请选择员工", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { this.dgv_renyuan.DataSource = SalemanBll.GetSaleman(); this.txt_basesalary.Text = ""; this.txt_commissionRate.Text = ""; this.txt_mobile.Text = ""; this.txt_name.Text = ""; this.txt_pwd.Text = ""; } }
/// <summary> /// 修改 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_xiugai_Click(object sender, EventArgs e) { try { if (this.txt_phone.Text == "" || this.txt_name.Text == "" || this.txt_zhekou.Text == "") { MessageBox.Show("信息不能为空", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } //else if (TextBoxBll.Intextnull(this.txt_name.Text, 1)) //{ // MessageBox.Show("姓名过长", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); //} else if (TextBoxBll.Intextnull(this.txt_phone.Text, 3)) { MessageBox.Show("请输入正确的电话号码", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else if (TextBoxBll.Intextnull(this.txt_zhekou.Text, 2))//验证折扣是否为1~0之间的数字 { MessageBox.Show("积分必须是正整数", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else { //string sql = string.Format("update vip set VipName='{0}',Mobile='{1}',Gender='{2}',Discount={3} where vipID={4}) ", txt_name.Text, txt_phone.Text, this.cbo_gander.Text, this.txt_zhekou.Text, id); Vip vip = new Vip() { VipID = id, Mobile = this.txt_phone.Text, jifen = 0, VipName = this.txt_name.Text, Gender = this.cbo_gander.Text }; if (VipBll.UpdateVip(vip)) { this.dgv_VIP.DataSource = VipBll.GetBooks(); MessageBox.Show("修改成功", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } } } catch (Exception ex) { MessageBox.Show(ex.Message); throw; } finally { this.dgv_VIP.DataSource = VipBll.GetBooks(); this.txt_name.Text = ""; this.txt_phone.Text = ""; this.txt_zhekou.Text = ""; this.cbo_gander.SelectedIndex = 0; } }
/// <summary> /// 添加 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_zengjia_Click(object sender, EventArgs e) { try { if (this.txt_phone.Text == "" || this.txt_name.Text == "" || this.txt_zhekou.Text == "") { MessageBox.Show("信息不能为空", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else if (TextBoxBll.Intextnull(this.txt_name.Text, 1)) { MessageBox.Show("姓名过长", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else if (TextBoxBll.Intextnull(this.txt_phone.Text, 3)) { MessageBox.Show("请输入正确的电话号码", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else if (TextBoxBll.Intextnull(this.txt_zhekou.Text, 2))//验证折扣是否为1~0之间的数字 { MessageBox.Show("积分必须是正整数", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else { Vip vip = new Vip() { Mobile = this.txt_phone.Text, jifen = 0, VipName = this.txt_name.Text, Gender = this.cbo_gander.Text }; VipBll.InsertVip(vip); MessageBox.Show("添加成功", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } } catch (Exception ex) { MessageBox.Show(ex.Message); throw; } finally { this.dgv_VIP.DataSource = VipBll.GetBooks(); this.txt_name.Text = ""; this.txt_phone.Text = ""; this.txt_zhekou.Text = ""; this.cbo_gander.SelectedIndex = 0; } }
public void 添加会员() { Vip vip = new Vip() { VipName = this.txt_name.Text, Mobile = this.txt_phone.Text, Gender = this.cbo_sex.Text, jifen = 0 }; //编写SQL语句(添加会员信息) //执行命令 if (vip.VipName == "") { MessageBox.Show("姓名不能为空", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else if (vip.Mobile == "" && TextBoxBll.Intextnull(this.txt_phone.Text, 3)) { MessageBox.Show("电话不能为空", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else if (vip.Gender == "") { MessageBox.Show("请选择性别", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else if (TextBoxBll.Intextnull(this.txt_name.Text, 1)) { MessageBox.Show("名字格式不正确", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else { if (VipBll.InsertVip(vip)) { MessageBox.Show("添加成功", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); this.txt_name.Text = ""; this.txt_phone.Text = ""; this.cbo_sex.Text = ""; } } }
bool isVIP = false;//是否为会员 private void btn_jiansuo_Click(object sender, EventArgs e) { try { if (TextBoxBll.Intextnull(this.txt_vip.Text, 3)) { MessageBox.Show("请正确填写电话号码", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else { if (VipBll.SelectVipBymobilebool(this.txt_vip.Text)) { isVIP = true; DataTable dt = VipBll.SetVipByMobile(this.txt_vip.Text); MessageBox.Show("尊敬的会员:" + dt.Rows[0][1].ToString() + ",你好!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); checkBox1.Enabled = true; jifenshu.Text = dt.Rows[0][4].ToString(); } } } catch (Exception) { } }
/// <summary> /// 添加员工 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_zengjia_Click(object sender, EventArgs e) { try { if (this.txt_basesalary.Text == "" || this.txt_commissionRate.Text == "" || this.txt_mobile.Text == "" || this.txt_name.Text == "" || this.txt_pwd.Text == "") { MessageBox.Show("信息不能为空", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } if (TextBoxBll.Intextnull(this.txt_mobile.Text, 3)) { MessageBox.Show("请输入正确的电话号码", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else if (TextBoxBll.Intextnull(this.txt_commissionRate.Text, 4))//验证提成是否为1~0之间的数字 { MessageBox.Show("提成必须是0~1的数字", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else if (TextBoxBll.Intextnull(this.txt_name.Text, 1)) { MessageBox.Show("姓名格式错误", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else if (SalemanBll.SelectSalemanByMobile(this.txt_mobile.Text)) { MessageBox.Show("电话号码已存在", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else { Saleman saleman = new Saleman() { SalesmanName = this.txt_name.Text, Mobile = this.txt_mobile.Text, Pwd = this.txt_pwd.Text, Gender = this.cbo_gander.Text, BaseSalary = this.txt_basesalary.Text, CommissionRate = this.txt_commissionRate.Text, Work = this.cbo_work.Text }; if (SalemanBll.InsertSalesman(saleman)) { MessageBox.Show("添加成功", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else { MessageBox.Show("添加失败", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } flag = true; } } catch (Exception) { MessageBox.Show("请正确填写信息", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } finally { this.dgv_renyuan.DataSource = SalemanBll.GetSaleman(); this.txt_basesalary.Text = ""; this.txt_commissionRate.Text = ""; this.txt_mobile.Text = ""; this.txt_name.Text = ""; this.txt_pwd.Text = ""; } }
/// <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); } }
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; } } }
/// <summary> /// 添加员工 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { Saleman saleman = new Saleman() { SalesmanName = this.txt_name.Text, Mobile = this.txt_mobile.Text, Pwd = this.txt_pwd.Text, Gender = this.cbo_sex.Text, BaseSalary = this.txt_money.Text, CommissionRate = this.txt_ticheng.Text, Work = this.cbo_work.Text }; if (saleman.SalesmanName == "" && TextBoxBll.Intextnull(this.txt_name.Text, 1)) { MessageBox.Show("姓名格式不正确", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } else if (saleman.Mobile == "") { MessageBox.Show("电话号码不能为空", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } else if (TextBoxBll.Intextnull(this.txt_name.Text, 1)) { MessageBox.Show("姓名格式错误", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else if (TextBoxBll.Intextnull(this.txt_mobile.Text, 3)) { MessageBox.Show("请输入正确的电话号码", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else if (saleman.Pwd == "") { MessageBox.Show("密码不能为空", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } else if (saleman.Gender == "") { MessageBox.Show("性别不能为空", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } else if (saleman.BaseSalary == "") { MessageBox.Show("底薪不能为空", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } else if (saleman.CommissionRate == "") { MessageBox.Show("提成不能为空", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } else if (TextBoxBll.Intextnull(this.txt_ticheng.Text, 4)) { MessageBox.Show("提成必须是0~1的小数!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else if (TextBoxBll.Intextnull(this.txt_money.Text, 2)) { MessageBox.Show("工资必须为正整数", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else { //判断是否存在 if (SalemanBll.SelectSalemanByMobile(saleman.Mobile)) { MessageBox.Show("员工以存在 请勿重复添加 如需修改请至管理界面", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else { //添加员工 //如果添加成功则初始化数据 if (SalemanBll.InsertSalesman(saleman)) { this.txt_name.Text = ""; this.txt_mobile.Text = ""; this.txt_pwd.Text = ""; this.cbo_sex.SelectedIndex = 0; this.txt_money.Text = ""; this.txt_ticheng.Text = ""; this.cbo_work.SelectedIndex = 0; MessageBox.Show("添加成功", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } } } }
/// <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 = ""; } } }