嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 3 元微信扫码支付:3 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
该系统工作流程:超市工作人员在管理商品时,用户对商品的价格,折扣等进行管理,并进行增删改。(1)该管理软件将对商品进行管理和统计,对产品的价格进行录入管理和统计;(2)根据需要对商品名称、价格、是否打折等进行查询,并能显示详细信息;(3)为用户提供账号管理工具,以便用户对账号进行管理,具体为登录修改用户密码;(4)提供商品的增加,删除,修改,对商品进行管理,还可以分类查看打折商品和原价商品。数据库中需要存储的数据:用户登录名、密码、商品名称、价格、是否打折、商品类别、打折价格等。
private void frmEditCommodity_Load(object sender, EventArgs e)
{
if (commodityID==0)//添加
{
this.GetCommoditySort();
}
else//修改
{
this.GetCommodity();
this.btnSave.Text = "修改";
}
}
private void btnSave_Click(object sender, EventArgs e)//保存
{
if (CheckInput())
{
if (commodityID==0)//新增
{
InsertCommodity();
}
else//修改
{
UpdateCommodity();
}
}
}
private void chkIsPrice_CheckStateChanged(object sender, EventArgs e) //选择被更改
{
if ( chkIsPrice .Checked)
{
this.numReducedPrice.Enabled = true;
}
else
{
this.numReducedPrice.Enabled = false;
this.numReducedPrice.Value = this.numPrice.Value;
}
}
新增商品的方法:
private void InsertCommodity()
{
DBHelper db = new DBHelper();
try
{
//sql语句
string sql = string.Format("insert into Commodity(CommodityName,SortID,CommodityPrice,IsDiscount,ReducedPrice) values('{0}','{1}','{2}','{3}','{4}')",
txtName.Text.Trim(), Convert.ToInt32(cboSort.SelectedValue), this.numPrice.Value,
this.chkIsPrice.Checked ? 1 : 0, numReducedPrice.Value);
Console.WriteLine(sql);
SqlCommand cmd = new SqlCommand(sql, db.Connection);//执行工具
db.OpenConnection();//打开数据库连接
int result = cmd.ExecuteNonQuery(); //执行
if (result==1)
{
MessageBox.Show ("添加成功","系统提示",MessageBoxButtons.OK,MessageBoxIcon.Information );
this.Close();
}
}
catch (Exception )
{
MessageBox.Show("数据库操作失败, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
finally
{
}
}
修改商品的方法:
private void UpdateCommodity()
{
DBHelper helper = new DBHelper();
try
{
string sql = string.Format("update Commodity set Commodity.CommodityName ='{0}',Commodity.SortID='{1}',Commodity.CommodityPrice ='{2}', Commodity.IsDiscount ='{3}',Commodity.ReducedPrice ='{4}' where Commodity.CommodityID ='{5}'",txtName.Text.Trim(),Convert.ToInt32 (cboSort .SelectedValue),this.numPrice.Value ,this.chkIsPrice.Checked?1:0,numReducedPrice .Value ,this.commodityID);
//执行工具
SqlCommand cmd = new SqlCommand(sql.ToString(), helper.Connection);
helper.OpenConnection();//打开数据库连接
int result = cmd.ExecuteNonQuery()//执行
if (result == 1)//判断
{
MessageBox.Show("修改成功", "系统提示?", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Close();
}
}
catch (Exception )
{
MessageBox.Show("数据库操作发生错误", "系统提示",MessageBoxButtons.OK, MessageBoxIcon.Information);
}
finally
{
helper.CloseConnection();
}
}
删除商品方法:
private void DeleteCommodityByID()
{
if (this.dgvCommodity.CurrentRow != null)
{
DialogResult dr = MessageBox.Show("确定要删除名称为" dgvCommodity.CurrentRow.Cells[1].Value, "系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
if (dr == DialogResult.OK)
{
DBHelper helper = new DBHelper();
try
{
//sql语句
StringBuilder sb = new StringBuilder();
sb.AppendFormat("delete from Commodity where CommodityID={0}", Convert.ToInt32(dgvCommodity.CurrentRow.Cells[0].Value));
//执行
SqlCommand cmd = new SqlCommand(sb.ToString(), helper.Connection);
//打开数据库连接
helper.OpenConnection();
//执行
int result = cmd.ExecuteNonQuery();
if (result == 1)
{
MessageBox.Show("删除成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
//重新绑定dgv
this.FillCommodityInfo();
}
}
catch (Exception)
{
MessageBox.Show("数据库操作失败, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
finally
{
helper.CloseConnection();
}
}
}
}