在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例C#语言基础 → C# 超市管理系统源码(含数据库)

C# 超市管理系统源码(含数据库)

C#语言基础

下载此实例
  • 开发语言:C#
  • 实例大小:1.34M
  • 下载次数:65
  • 浏览次数:1210
  • 发布时间:2020-12-21
  • 实例类别:C#语言基础
  • 发 布 人:aaayy
  • 文件格式:.rar
  • 所需积分:3

实例介绍

【实例简介】

该系统工作流程:超市工作人员在管理商品时,用户对商品的价格,折扣等进行管理,并进行增删改。(1)该管理软件将对商品进行管理和统计,对产品的价格进行录入管理和统计;(2)根据需要对商品名称、价格、是否打折等进行查询,并能显示详细信息;(3)为用户提供账号管理工具,以便用户对账号进行管理,具体为登录修改用户密码;(4)提供商品的增加,删除,修改,对商品进行管理,还可以分类查看打折商品和原价商品。数据库中需要存储的数据:用户登录名、密码、商品名称、价格、是否打折、商品类别、打折价格等。

【实例截图】from clipboard
【核心代码】

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();

                    }

                }

            }

        }


实例下载地址

网友评论

第 1 楼 1175264 发表于: 2020-12-25 08:24 20
加个查询更好

支持(0) 盖楼(回复)

第 2 楼 逸仙 发表于: 2021-01-10 23:36 16
加个查询更好

1175264 2020-12-25 08:24 20

怎么连接数据库啊

支持(0) 盖楼(回复)

第 3 楼 1175264 发表于: 2021-01-11 07:29 06
加个查询更好

1175264 2020-12-25 08:24 20

怎么连接数据库啊

逸仙 2021-01-10 23:36 16

给数据库那个文件夹所有权限,在数据库文件夹右击属性安全编辑换成管理员给他所有权限(尤其是完全控制一定要勾上),然后直接附加到你的数据库就好了

支持(0) 盖楼(回复)

第 4 楼 2499692880 发表于: 2021-09-30 10:20 14
为什么不可用

支持(0) 盖楼(回复)

发表评论

(您的评论需要经过审核才能显示)

查看所有4条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警