用C#做小型超市的收银界面,在输入商品编码后想在dataGridView空间中累计显示买的所有商品的信息,怎么做
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用C#做小型超市的收银界面,在输入商品编码后想在dataGridView空间中累计显示买的所有商品的信息,怎么做相关的知识,希望对你有一定的参考价值。
我只会用SELECT语句显示当前输入的商品编码对应的商品信息,希望高手指点。
下面是代码:private void txtID_MouseEnter(object sender, EventArgs e)
string sql = "SELECT MerchID as 商品编号,Merchbarcode as 条形码,MerchName as 商品名称,MerchPrice as 单价,MerchNum as 数量,Total as 总计,MerchSale as 折扣 FROM MerchInfo WHERE MerchID='" + txtID.Text.Trim() + "'";
//string sql = "INSERT INTO MerchSell(MerchID,Merchbarcode,MerchName,MerchPrice,MerchNum,Total,MerchSale)SELECT MerchID as 商品编号,Merchbarcode as 条形码,MerchName as 商品名称,MerchPrice as 单价,MerchNum as 数量,Total as 总计,MerchSale as 折扣 FROM MerchInfo WHERE MerchID='" + txtID.Text.Trim() + "'";
////string sql1 = "INSERT INTO MerchSell(MerchID,Merchbarcode,MerchName,MerchPrice,MerchNum,MerchSale,Total)values(select * from MerchInfo WHERE MerchID='" + txtID.Text.Trim() + "')";
DataSet ds = OperateDB.ExecuteDataSet(sql);
dataGridView1.DataSource = ds.Tables[0].DefaultView;
private void richTextBox1_TextChanged(object sender, EventArgs e)
string sql = "SELECT MerchID as 商品编号,Merchbarcode as 条形码,MerchName as 商品名称,MerchPrice as 单价,MerchNum as 数量,Total as 总计,MerchSale as 折扣 FROM MerchInfo WHERE MerchID='" + txtID.Text.Trim() + "'";
private void richTextBox1_TextChanged(object sender, EventArgs e)
string sql = "SELECT MerchID as 商品编号,Merchbarcode as 条形码,MerchName as 商品名称,MerchPrice as 单价,MerchNum as 数量,Total as 总计,MerchSale as 折扣 FROM MerchInfo WHERE MerchID='" + txtID.Text.Trim() + "'";
//string sql = "INSERT INTO MerchSell(MerchID,Merchbarcode,MerchName,MerchPrice,MerchNum,Total,MerchSale)SELECT MerchID as 商品编号,Merchbarcode as 条形码,MerchName as 商品名称,MerchPrice as 单价,MerchNum as 数量,Total as 总计,MerchSale as 折扣 FROM MerchInfo WHERE MerchID='" + txtID.Text.Trim() + "'";
////string sql1 = "INSERT INTO MerchSell(MerchID,Merchbarcode,MerchName,MerchPrice,MerchNum,MerchSale,Total)values(select * from MerchInfo WHERE MerchID='" + txtID.Text.Trim() + "')";
DataSet ds = OperateDB.ExecuteDataSet(sql);
dataGridView1.DataSource = ds.Tables[0].DefaultView;
追问
还是没办法累计显示,怎样才能在输了第二个条形码后还保留第一次输入条形码的商品的信息?
追答定义一个全局变量 public double value=0;//放在该窗体的构造函数前
private void richTextBox1_TextChanged
//先获取这次条码输入的值,并将该值赋给value;
然后累加value+=value;
//记得不需要累加的时候初始化value:value=0;
还是不行啊。。具体要怎么写?
参考技术A 不要绑定数据 ,手动添加行DataGridViewRow dr = new DataGridViewRow();
foreach (DataGridViewColumn c in dataGridView1.Columns)//遍历单元格数量
dr.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell);//给行添加单元格
dr.Cells[0].Value = 商品编号;
dr.Cells[1].Value = 条形码;
dr.Cells[2].Value = 商品名称;
dr.Cells[3].Value =单价;
dr.Cells[4].Value =数量;
dr.Cells[5].Value =总计;
dr.Cells[6].Value =折扣;
dataGridView1.Rows.Add(dr); 参考技术B 输入商品编码的文本框的change事件中,更新gridview即可追问
具体怎么做?能不能说详细点,我是新手不太会
超市收银系统设计
首先根据业务分析共有几个功能模块:
收银员模块:
服务台模块:会员管理(注册、注销、信息修改等),商品管理(商品的退货,库存管理)
管理员模块:查看收银台销售情况和商品情况
共有模块:登录,用户身份验证,退出
用户:服务台用户,收银员,管理员
权限:
服务台:管理维护,对会员、商品的信息进行管理和维护
收银员用户:结账权限
以上是关于用C#做小型超市的收银界面,在输入商品编码后想在dataGridView空间中累计显示买的所有商品的信息,怎么做的主要内容,如果未能解决你的问题,请参考以下文章