超市商品管理系统

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

系 统 关 于
修 改 密 码
增 加 商 品
删 除 商 品
更 新 商 品
查 找 商 品
界面原则分析
• 统一性原则 ▷界面风格统一: 用相同方式展现相同类型的数据,如:商品价格 ▷交互风格统一: 用相同方式完成相同类型的操作,如:选择日期 • 美观性原则 ▷界面美观大方,布局合理 • 易用性原则 ▷操作方便,如:Tab键顺序,回车代替确定键 • 友好性原则 ▷输入错误或系统发生错误有及时的提示 ▷危险性操作有确定操作的提示
删除商品信息代码实现(部分)
• • • • • • • • • • • • • • • • DialogResult choice; string name = this.dgvCommodity.CurrentRow.Cells[0].Value.ToString(); choice = MessageBox.Show("确认要删除商品名称”+"+name+"“的数据吗?", "提示?", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (choice == DialogResult.Yes) { if (dgvCommodiwk.baidu.comy.SelectedRows.Count > 0) { DBHelper db = new DBHelper(); db.conn.Open(); string sql = string.Format("delete from Commodity where CommodityID={0}", name); SqlCommand comm = new SqlCommand(sql, db.conn); int Result = comm.ExecuteNonQuery(); if (Result != 1) { MessageBox.Show("删除失败!?", "提示?", MessageBoxButtons.OK, MessageBoxIcon.Information); Filter();
转换成小数类型
修改商品信息代码中出现的问题
• FrmEditCommodity1 frm = new FrmEditCommodity1(); • frm.commodityID = Convert.ToInt32(this.dgvCommodity.Current Row.Cells[0].Value); • frm.ShowDialog(); • this.show();
谢谢观赏
超 市 商 品 管 理 系 统
系统设计目的
• 该课程的设计,使我们学习WinForms应用程序 的基本控件和部分高级控件的属性、方法和事件, 并能够采用连接式和断开式两种方法使应用程序 和数据库进行连接,完成后,进行的一次全面的 综合训练,其目的在于加深对客户端程序设计基 本知识的理解,掌握运用C#开发应用程序的基本 方法及基本技巧。
• • • •
• • • • •
} else { MessageBox.Show("删除成功!?", "提示?", MessageBoxButtons.OK, MessageBoxIcon.Information); this.show(); } MessageBox.Show("数据库操作失败", "提示?", MessageBoxButtons.OK, MessageBoxIcon.Error); db.conn.Close(); }
系统开发步骤
• • • • 明确需求 设计数据库 创建项目 按照顺序,制作下面的窗体并编写代码 ☆ “登录”窗体 ☆ “超市商品管理”主窗体 ☆ “修改密码”窗体 ☆ “商品列表”窗体 • ☆ “编辑商品信息”窗体 • ☆ “关于”窗体 测试
系统结构图
超市商品管理系统
用户管理
商品管理
用 户 登 录
案例小结
• 构建布局合理美观的Windows窗体
MenuStrip控件显示系统菜单 PictureBox控件显示商品管理和商品类别图片 TreeView控件显示关于商品正价和商品特价的树状菜单 ComboBox控件显示商品类别 NumericUpDown控件显示商品的预售价格和特价价格 DateGridView控件显示商品列表信息
最后感谢小组的所有成员,没有你们的努力,我们根本无法完 成这个案例,不管最后的结果如何,我都希望同学们不要放弃,继 续加油!!!! 另外,在做这个项目的过程中,我的冒犯之处还请各位同学们 不要介意,也别生气,谢谢大家!!! 小组成员: 组长:张会川 组员:魏泽明、吴 宇、赵鹏程
赵 秦、赵亚红、周 铖
修改商品信息代码实现(部分)及界面设计
• • • • • • • • • • • • • • • • • • • tring sql = string.Format("select C.CommodityName,S.SortName,C.CommodityPrice,C.IsDiscount,C.ReducedPrice from Commodity as C,CommoditySort as S where C.SortID=S.SortID and CommodityID ={0}", this.commodityID); SqlCommand comm = new SqlCommand(sql, db.conn); db.conn.Open(); SqlDataReader my = comm.ExecuteReader(); if (my.Read()) { this.txtName.Text = my["CommodityName"].ToString(); this.cboSort.Text = my["SortName"].ToString(); this.numPrice.Value = decimal.Parse((my["CommodityPrice"]).ToString()); if (my["IsDiscount"].ToString() == "true") { this.chkIsPrice.Checked = true; } else { this.chkIsPrice.Checked = false; } this.numReducedPrice.Value = decimal.Parse(my["ReducedPrice"].ToString ()); } my.Close(); db.conn.Close();
修改密码代码实现(部分)及界面设计
• • • • • • • • • • • • • • • • • • • • • • • • • • • //非空验证 if (CheckPwd()) { //查寻密码 string sql = "select PassWord from User1 "; db.conn.Open(); SqlCommand comm = new SqlCommand(sql, db.conn); SqlDataReader myread = comm.ExecuteReader(); myread.Read(); user.Password1 = myread["PassWord"].ToString(); myread["PassWord"].ToString(); myread.Close(); db.conn.Close(); //验证输入密码和原密码是否一致 if (this.txtOldPwd.Text.Equals(this.user.Password1)) (this.txtOldPwd.Text.Equals(this.user.Password1)) { //将新密码保存到数据库中 if (SeavePwd()) { MessageBox.Show("修改成功|", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } else { MessageBox.Show("修改失败“,提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
• 使用ADO.NET操作数据
编写DBHelper类提供应用程序与数据库的连接,关闭操作 使用Connection对象建立应用程序于数据库的连接 使用Command对象提交SQL语句,对数据库中的数据进行处理 使用DataReader返回数据库查询数据 使用DataAdapter对象实现数据集的数据填充和数据库中数据的更新操作 使用DataView对象实现数据筛选
查看商品列表代码实现(部分)及界面的设计
• • • • • • • • • • • • • • • • • • DBHelper db = new DBHelper(); try { string sql = "select A.CommodityID,A.CommodityName,B.SortName,A.CommodityPrice, A.IsDiscount,A.ReducedPrice from Commodity as A,CommoditySort as B where A.SortID = B.SortID"; ds = new DataSet(); SqlDataAdapter adapter = new SqlDataAdapter(sql, db.conn); adapter.Fill(ds, "Commodity"); //绑定¨ this.dgvCommodity.DataSource = ds.Tables["Commodity"]; } catch (Exception) { MessageBox.Show("出现异常", "操作提示?", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); } finally { db.conn.Close(); }
登录界面设计
• 通过登录界面进入系统界面,使用到标签控件,文本框, 以及按钮实现登录与退出的功能。
登录 • • • • 取消 •
输入用户名和密码 用户名和密码不能为空 用户名和密码要在数据库中存在 验证通过跳转到主窗体 点击“取消”时,退出应用程序
代码实现(部分)
• string sql = String.Format("select * from User1 where UserName='{0}'and PassWord='{1}'", this.txtName.Text, this.txtPwd.Text); • db.conn.Open(); • SqlCommand command = new SqlCommand(sql, db.conn); • int i = (int)command.ExecuteScalar(); • if (i > 0) • { • return true; • } • else • { • MessageBox.Show("您输入的用户不存在!?"); • return false; • }
相关文档
最新文档