1、数据库系统设计实验报告数据库系统设计实验报告 课程:数据库系统原理与应用 * 专业:13级计本班 学号:* *(一) 数据库系统设计一、实验目的 掌握数据库设计的基本技术,熟悉数据库设计的每个步骤中的任务和实施方法,并加深对数据库系统概念和特点的理解。二、实验内容设计一个简单的客户点餐数据库应用系统,完成设计报告。重点为数据库系统结构特性设计部分,包括需求分析、概念设计和逻辑设计。三、实验原理、方法利用数据库设计的4个阶段:需求分析(分析用户要求)、概念设计(信息分析和定义)、逻辑设计(设计实现)和物理设计(物理数据库设计)。概念模型设计时采用自底向上的方法,即自顶向下地进行需求分析,然后再自
2、底向上地设计概念结构,和自底向上的设计方法。四、实验步骤1、系统需求分析 1.1操作环境与软件 操作环境:Windows 7 数据库软件:SQL server 2008 系统编辑软件:VS2010 1.2系统设计与功能分析 系统设计:本系统用于客户与订单在点餐上的联系信息 功能分析:用于输入和查询客户的点餐情况和餐厅的菜单信息2、概念结构设计(E-R图)3、逻辑结构设计 3.1 管理员表FieldTypekeyNULL用户名nchar(10) PRINO密码Nchar(6)NO备注Yes 3.2 用户表FieldTypekeyNULL用户名nchar(10)PRINO密码Nchar(6)NO姓
3、名nchar(10)NO性别nchar(1)NO电话nchar(11)NO地址nvarchar(50)NO备注nvarchar(50)Yes 3.3 菜单表FieldTypekeyNULL菜名nchar(10)PRINO价格moneyNO剩余量intNO客户评价nvarchar(50)Yes3.4 订单表FieldTypekeyNULL订单号intPRINO菜名nchar(10)NO点餐数量intNO姓名nchar(10)NO地址nvarchar(50)NO4、主要步骤(1)登录窗体: 验证用户登录 定义一个连接数据库的类:class Class1 public static DataRow
4、login; public static bool isman; public static void checkuser(string 用户名, string 密码) SqlConnection cn = new SqlConnection(Properties.Settings.Default.xkSetting); SqlDataAdapter da = new SqlDataAdapter(SELECT * FROM guanli WHERE 用户名=用户名 AND 密码=密码, cn); da.SelectCommand.Parameters.Add(用户名, SqlDbType.N
5、VarChar, 10).Value = 用户名; da.SelectCommand.Parameters.Add(密码, SqlDbType.NVarChar, 6).Value = 密码; DataSet ds = new DataSet(); da.Fill(ds); if (ds.Tables0.Rows.Count 0) login = ds.Tables0.Rows0; isman = true; else login = null; public static void yonghu(string xinmin, string 密码) SqlConnection cn = new
6、 SqlConnection(Properties.Settings.Default.xkSetting); SqlDataAdapter da = new SqlDataAdapter(SELECT * FROM yonghu WHERE xinmin=xinmin AND 密码=密码, cn); da.SelectCommand.Parameters.Add(xinmin, SqlDbType.NVarChar, 10).Value = xinmin; da.SelectCommand.Parameters.Add(密码, SqlDbType.NVarChar, 6).Value = 密码
7、; DataSet ds = new DataSet(); da.Fill(ds); if (ds.Tables0.Rows.Count 0) login = ds.Tables0.Rows0; isman = true; else login = null; 输入用户名和密码,选择管理员选项,点击登录:验证代码如下:public Form1() InitializeComponent(); private void button1_Click(object sender, EventArgs e) if(checkBox1.Checked) Class1.checkuser(textBox1
8、.Text,textBox2.Text); else Class1.yonghu(textBox1.Text,textBox2.Text); if (Class1.login = null) MessageBox.Show(密码错误, 登录, MessageBoxButtons.OK, MessageBoxIcon.Information); else Close(); Program.name = textBox1.Text; private void button3_Click(object sender, EventArgs e) Close(); private void button
9、2_Click(object sender, EventArgs e) this.textBox1.Text = ; this.textBox2.Text = ; private void Form1_Load(object sender, EventArgs e) private void button4_Click(object sender, EventArgs e) zhuce f = new zhuce(); f.Show(); 验证出错截图:(2)设计主窗体:主窗体代码:public partial class Form2 : Form DataSet ds = new DataS
10、et(); public Form2() InitializeComponent(); private void Form2_Load(object sender, EventArgs e) / TODO: 这行代码将数据加载到表“dsxk.kuaican”中。您可以根据需要移动或删除它。 this.kuaicanTableAdapter.Fill(this.dsxk.kuaican); / TODO: 这行代码将数据加载到表“dsxk.xican”中。您可以根据需要移动或删除它。 this.xicanTableAdapter.Fill(this.dsxk.xican); / TODO: 这行
11、代码将数据加载到表“dsxk.wodedindan”中。您可以根据需要移动或删除它。 this.wodedindanTableAdapter.Fill(this.dsxk.wodedindan); / TODO: 这行代码将数据加载到表“dsxk.wodedindan”中。您可以根据需要移动或删除它。 this.wodedindanTableAdapter.Fill(this.dsxk.wodedindan); / TODO: 这行代码将数据加载到表“dsxk.zhongcan”中。您可以根据需要移动或删除它。 this.zhongcanTableAdapter.Fill(this.dsxk.
12、zhongcan); panel1.Visible = false; panel2.Visible = false; panel3.Visible = false; panel4.Visible = false; panel5.Visible = true; private void label1_Click(object sender, EventArgs e) private void 首页ToolStripMenuItem_Click(object sender, EventArgs e) panel1.Visible =false; panel2.Visible =false; pan
13、el3.Visible = false; panel4.Visible = false; panel5.Visible = true; private void 退出登录ToolStripMenuItem_Click(object sender, EventArgs e) Form1 myf = new Form1(); myf.Show(); private void 中餐ToolStripMenuItem_Click(object sender, EventArgs e) panel1.Visible = true; panel2.Visible = false; panel3.Visib
14、le = false; panel4.Visible = false; panel5.Visible = false; private void 我的订单ToolStripMenuItem_Click(object sender, EventArgs e) panel1.Visible = false; panel2.Visible = false; panel3.Visible = false; panel4.Visible = true; panel5.Visible = false; private void 退出登录ToolStripMenuItem1_Click(object sen
15、der, EventArgs e) Close(); private void toolStripButton1_Click(object sender, EventArgs e) Form3 a = new Form3(); a.Show(); private void 西餐ToolStripMenuItem_Click(object sender, EventArgs e) panel1.Visible = false; panel2.Visible = true; panel3.Visible = false; panel4.Visible = false; panel5.Visible
16、 = false; private void 酒水ToolStripMenuItem_Click(object sender, EventArgs e) panel1.Visible = false; panel2.Visible = false; panel3.Visible = true; panel4.Visible = false; panel5.Visible = false; private void toolStripButton2_Click(object sender, EventArgs e) Form4 a = new Form4(); a.Show(); private
17、 void 个人信息ToolStripMenuItem_Click(object sender, EventArgs e) Form5 a = new Form5(); a.Show(); (3)建立各子窗体:1.菜单项下的子窗体显示,我选用的是PENER控件,方便在主窗体内刷新数据。2.3.4. private void Form5_Load(object sender, EventArgs e) SqlDataAdapter OleDat; DataTable dt; SqlConnection cn = new SqlConnection(Properties.Settings.Defa
18、ult.xkSetting); cn.Open(); dt = new DataTable(); string mysql = select * from yonghu where 用户名 = + Program.name + ; OleDat = new SqlDataAdapter(mysql, cn); OleDat.Fill(dt); this.textBox1.Text = dt.Rows01.ToString(); this.textBox2.Text = dt.Rows02.ToString(); this.textBox3.Text = dt.Rows03.ToString()
19、; this.textBox4.Text = dt.Rows04.ToString(); this.textBox5.Text = dt.Rows05.ToString(); this.textBox6.Text = dt.Rows06.ToString(); this.textBox7.Text = dt.Rows07.ToString();(3)创建数据集(4)管理员权限:更新点餐菜单,管理注册用户代码:public Form3() InitializeComponent(); private void zhongcanBindingNavigatorSaveItem_Click(obje
20、ct sender, EventArgs e) this.Validate(); this.zhongcanBindingSource.EndEdit(); this.tableAdapterManager.UpdateAll(this.dsxk); private void Form3_Load(object sender, EventArgs e) / TODO: 这行代码将数据加载到表“dsxk.xican”中。您可以根据需要移动或删除它。 this.xicanTableAdapter.Fill(this.dsxk.xican); / TODO: 这行代码将数据加载到表“dsxk.zho
21、ngcan”中。您可以根据需要移动或删除它。 this.zhongcanTableAdapter.Fill(this.dsxk.zhongcan); 管理用户代码:public partial class Form4 : Form public Form4() InitializeComponent(); private void yonghuBindingNavigatorSaveItem_Click(object sender, EventArgs e) this.Validate(); this.yonghuBindingSource.EndEdit(); this.tableAdapt
22、erManager.UpdateAll(this.dsxk); private void Form4_Load(object sender, EventArgs e) / TODO: 这行代码将数据加载到表“dsxk.yonghu”中。您可以根据需要移动或删除它。 this.yonghuTableAdapter.Fill(this.dsxk.yonghu); (5)注册新用户:验证注册信息代码:private void button1_Click(object sender, EventArgs e) string 用户名 = textBox1.Text.Trim(); string 密码 =
23、 textBox2.Text.Trim(); string xinmin = textBox3.Text.Trim(); string xinbie = textBox4.Text.Trim(); string nianlin = textBox5.Text.Trim(); string dianhua = textBox6.Text.Trim(); string QQ = textBox7.Text.Trim(); string beizhu = textBox8.Text.Trim(); SqlConnection cn = new SqlConnection(Properties.Set
24、tings.Default.xkSetting); string sql = string.Format(update yonghu set 用户名=0,密码=1,xinbie= 2,nianlin= 3,dianhua=4,QQ=5,beizhu=6 where xinmin=7, 用户名, 密码, xinbie, nianlin, dianhua, QQ, beizhu ,xinmin); SqlCommand cmd = new SqlCommand(sql, cn); cn.Open(); int n = Convert.ToInt32(cmd.ExecuteNonQuery(); if (n!= 1) MessageBox.Show(更新失败); else MessageBox.Show(更新成功); 6、实验总结通过本次实验大作业,首先我深刻认识到自己在编程各方面的不足,其次,值得肯定的是自己的坚忍不拔的学习耐力与