数据库轿车销售信息管理系统基于C和SQLserver
沈阳理工大学课程设计专用纸NO.24目 录一、课程设计的目的和意义1二、需求分析1三、概念结构设计E-R图3四、逻辑结构设计4五、数据库实施4六、界面设计与代码6七、课程设计心得与体会23八、参考文献23 轿车销售信息管理系统一、课程设计的目的和意义数据库课程设计是在学生系统的学习了数据库原理课程后,按照关系型数据库的基本原理,综合运用所学的知识,以小组为单位,设计开发一个小型的数据库管理系统。通过对一个实际问题的分析、设计与实现,将原理与应用相结合,使学生学会如何把书本上学到的知识用于解决实际问题,培养学生的动手能力;另一方面,使学生能深入理解和灵活掌握教学内容。大型数据库课程设计是电脑专业集中实践性教学环节之一,是学习完数据库原理及应用课程后进行的一次全面的综合练习。其目的在于加深对大型数据库课程理论和基本知识的理解,掌握使用数据库进行软件设计的基本方法,提高运用数据库解决实际问题的能力。培养学生正确的设计思想,理论联系实际的工作作风,严肃认真、实事求是的科学态度和勇于探索的创新精神。培养学生综合运用所学知识与生产实践经验,分析和解决工程技术问题的能力。二、需求分析轿车销售信息管理系统表达在对各种信息的插入、修改、查询。经过分析系统的需求之后得悉其主要功能如下:1、 可对轿车信息、职工信息、客户信息、轿车销售信息等基本表进行查询操作。2、 可对轿车信息、职工信息、客户信息、轿车销售信息等基本表进行添加操作。3、 可对轿车信息、职工信息、客户信息、轿车销售信息等基本表进行修改操作。4、 可对轿车信息、职工信息、客户信息、轿车销售信息等基本表进行插入操作。5、打印输出销售报表。系统总体设计图如图1所示:汽车销售信息管理系统界面操作数据库管理 登轿车信息表职工信息表 录 删 除添 加查 询修 改客 轿 户 车 信 销 息 售 表 信职工信息表 轿车信息表 息客 轿 表 户 车 信 销 息 售 表 信 息 表 图1 整体设计图三、概念结构设计E-R图 型号轿车编号职工编号颜色生产厂家价格轿车名称学历籍贯年龄性别出厂日期销售汽车职工 服务购买客户客户名称联系方式客户编号业务记录地址 E-R图四、逻辑结构设计将E-R图转换成关系模式:轿车信息轿车编号,型号,轿车颜色,生产厂家,出厂日期,价格;职工信息职工编号,性别,年龄,籍贯,学历;客户信息客户编号,客户名称,联系方式,地址,业务记录;轿车销售信息销售编号,销售日期,轿车类型,颜色,数量,职工编号,客户编号;五、数据库实施建立数据库,打开SQL Server 2008,建立数据库:轿车销售信息管理系统。 1.在轿车销售信息管理系统数据库中,添加轿车信息表,设置轿车编号为主键,不允许为空,如图1所示图1右键选择编辑前200行,输入数据,如图2所示图22.添加职工信息表,设置职工编号为主键,不允许为空,如图3所示:图3右键选择编辑前200行,输入数据,如图4所示: 图43.添加客户信息表,设置客户编号主键,不允许为空,如图5所示: 图5右键选择编辑前200行,输入数据,如图8所示:图64. 添加汽车销售信息表,设置销售编号编号为主键,不允许为空,如图7所示 图7右键选择编辑前200行,输入数据,如图8所示: 图8六、界面设计与代码1.登录界面在界面输入框中输入已在数据库中的用户名和密码,点击登录按钮,如图9所示: 图9提示登录成功,单击确定进入主菜单,如图10所示 图10双击登录按钮,更新单击事件处理程序,主要代码如下:private void button1_Click(object sender, EventArgs e) string username = textBox1.Text.Trim(); string password = textBox2.Text.Trim(); string connString = "Data Source=LENOVO-PC;Initial Catalog=MYCAR;Integrated Security =True" SqlConnection conn = new SqlConnection(connString); try string sql = String.Format("select count(*) from login_mes where 账号='0' and 密码='1'", username, password); conn.Open(); SqlCommand command = new SqlCommand(sql, conn); int num = (int)command.ExecuteScalar(); if (num > 0) MessageBox.Show("登陆成功,欢送进入轿车销售管理系统!"); Form1 forms = new Form1(); forms.Show(); this.Visible = false; else textBox2.Text = "" MessageBox.Show("您输入的账户名或密码错误!", "登陆失败!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); catch (Exception ex) MessageBox.Show(ex.Message, "操作数据库出错!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); finally conn.Close(); private void button2_Click(object sender, EventArgs e) this.Visible = false; 2.主界面如图11所示: 图114.点击轿车信息,双击查询按钮,编写程序代码如下: private void button2_Click(object sender, EventArgs e) string connString = "Data Source=WIN-LH5EK84HEPR;Initial Catalog=大学生就业咨询系统 ;Integrated Security=True;Pooling=False;" SqlConnection connection = new SqlConnection(connString); SqlCommand command = new SqlCommand(); string sql = String.Format("select * FROM 学生信息表 WHERE 学号='0'", textBox2.Text); try int i = 0; connection.Open(); / 打开数据库连接 command.Connection = connection; command.CommandText = sql;/设置 Command 对象要执行的SQL语句 SqlDataReader dataReader = command.ExecuteReader(); while (dataReader.Read() i+; textBox8.Text = dataReader"学号".ToString(); textBox1.Text = dataReader"".ToString(); textBox7.Text = dataReader"性别".ToString(); textBox3.Text = dataReader"专业".ToString(); textBox4.Text = dataReader"学历".ToString(); textBox5.Text = dataReader"毕业年份".ToString(); textBox6.Text = dataReader"毕业学校".ToString(); if (i = 0) MessageBox.Show("该生不存在", "查询失败", MessageBoxButtons.OK, MessageBoxIcon.Information); catch (Exception ex) MessageBox.Show(ex.Message, "操作数据库出错!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); finally connection.Close();/ 关闭数据库连接 查询数据后,出现如图12:private void search_Click(object sender, EventArgs e) if (tabControl1.SelectedTab.Text.ToString() = "轿车信息") show.Text = null; string connString = "Data Source=LENOVO-PC;Initial Catalog=MYCAR;Integrated Security =True" SqlConnection conn = new SqlConnection(connString); try conn.Open(); string carnumber = carnumbox.Text.Trim(); string modelboxs = modelbox.Text.Trim(); string sql = String.Format("select * from car_mes where 轿车编号='0' or 型号='1'", carnumber, modelboxs); SqlCommand command = new SqlCommand(sql, conn); SqlDataReader dataReader = command.ExecuteReader(); int i = 0; for (i = 0; dataReader.Read(); i+) show.Text += "轿车编号:" + Convert.ToString(dataReader0) + "n" show.Text += "型号:" + Convert.ToString(dataReader1) + "n" show.Text += "轿车名称: " + Convert.ToString(dataReader2) + "n" show.Text += "颜色: " + Convert.ToString(dataReader3) + "n" show.Text += "生产厂家: " + Convert.ToString(dataReader4) + "n" show.Text += "出厂日期: " + Convert.ToString(dataReader5) + "n" show.Text += "价格: " + Convert.ToString(dataReader6) + "nn" if (i = 0) MessageBox.Show("无此查询信息!查询失败!"); dataReader.Close(); conn.Close(); catch (Exception ex) MessageBox.Show(ex.Message); else if (tabControl1.SelectedTab.Text.ToString() = "客户信息") show.Text = null; string connString = "Data Source=LENOVO-PC;Initial Catalog=MYCAR;Integrated Security =True" SqlConnection conn = new SqlConnection(connString); try conn.Open(); string clientnum = textBox16.Text.Trim(); string clientnam = textBox15.Text.Trim(); string sql = String.Format("select * from cus_mes where 客户编号='0' or 客户名称='1' ", clientnum, clientnam); SqlCommand command = new SqlCommand(sql, conn); SqlDataReader dataReader = command.ExecuteReader(); int i = 0; for (i = 0; dataReader.Read(); i+) show.Text += "客户编号:" + Convert.ToString(dataReader0) + "n" show.Text += "客户:" + Convert.ToString(dataReader1) + "n" show.Text += "联系方式: " + Convert.ToString(dataReader2) + "n" show.Text += "地址:" + Convert.ToString(dataReader3) + "n" show.Text += "业务记录:" + Convert.ToString(dataReader4) + "nnn" if (i = 0) MessageBox.Show("无此查询信息!查询失败!"); dataReader.Close(); conn.Close(); catch (Exception ex) MessageBox.Show(ex.Message); 查询成功,结果显示:双击添加按钮,程序代码如下:private void add_Click(object sender, EventArgs e) if (tabControl1.SelectedTab.Text.ToString() = "轿车信息") show.Text = null; string connString = "Data Source=LENOVO-PC;Initial Catalog=MYCAR;Integrated Security =True" SqlConnection conn = new SqlConnection(connString); try conn.Open(); string sql = String.Format("insert into car_mes (编号,型号,轿车名称,颜色,生产厂家,出厂日期,价格) values('0','1','2','3','4','5','6') ", carnumbox.Text, modelbox.Text, textBox17.Text, color.Text, textBox4.Text, textBox5.Text, textBox6.Text); SqlCommand command = new SqlCommand(sql, conn); int i = command.ExecuteNonQuery(); if (i > 0) MessageBox.Show("添加成功!"); conn.Close(); catch (Exception ex) MessageBox.Show(ex.Message,"数据库操作有误!"); else if (tabControl1.SelectedTab.Text.ToString() = "职工信息") show.Text = null; string connString = "Data Source=LENOVO-PC;Initial Catalog=MYCAR;Integrated Security =True" SqlConnection conn = new SqlConnection(connString); try conn.Open(); string sql = String.Format("insert into staff_mes (职工编号,性别,年龄,籍贯,学历) values('0','1','2','3','4','5') ", textBox12.Text, textBox11.Text, textBox10.Text, textBox9.Text, textBox8.Text, textBox7.Text); SqlCommand command = new SqlCommand(sql, conn); int i = command.ExecuteNonQuery(); if (i > 0) MessageBox.Show("添加成功!"); conn.Close(); catch (Exception ex) MessageBox.Show(ex.Message, "数据库操作有误!"); else if (tabControl1.SelectedTab.Text.ToString() = "客户信息") show.Text = null; string connString = "Data Source=LENOVO-PC;Initial Catalog=MYCAR;Integrated Security =True" SqlConnection conn = new SqlConnection(connString); try conn.Open(); string sql = String.Format("insert into cus_mes (客户编号,客户名称,联系方式,地址,业务记录) values('0','1','2','3','4') ", textBox16.Text, textBox15.Text, textBox14.Text, textBox13.Text, textBox18.Text); SqlCommand command = new SqlCommand(sql, conn); int i = command.ExecuteNonQuery(); if (i > 0) MessageBox.Show("添加成功!"); conn.Close(); catch (Exception ex) MessageBox.Show(ex.Message, "数据库操作有误!"); else if (tabControl1.SelectedTab.Text.ToString() = "轿车销售信息") show.Text = null; string connString = "Data Source=LENOVO-PC;Initial Catalog=MYCAR;Integrated Security =True" SqlConnection conn = new SqlConnection(connString); try conn.Open(); string sql = String.Format("insert into sell_mes (销售编号,销售日期,轿车类型,颜色,数量,职工编号,客户编号) values('0','1','2','3','4','5','6') ", textBox25.Text, textBox24.Text, textBox19.Text, textBox23.Text, textBox22.Text, textBox21.Text, textBox20.Text); SqlCommand command = new SqlCommand(sql, conn); int i = command.ExecuteNonQuery(); if (i > 0) MessageBox.Show("添加成功!"); conn.Close(); catch (Exception ex) MessageBox.Show(ex.Message, "数据库操作有误!"); 添加成功,提示:双击修改按钮,程序代码如下:private void change_Click(object sender, EventArgs e) if (tabControl1.SelectedTab.Text.ToString() = "轿车信息") show.Text = null; string connString = "Data Source=LENOVO-PC;Initial Catalog=MYCAR;Integrated Security =True" SqlConnection conn = new SqlConnection(connString); try conn.Open(); string sql = String.Format("update car_mes set 价格='0' where 编号='1'",textBox6.Text,carnumbox.Text); SqlCommand command = new SqlCommand(sql, conn); int i = command.ExecuteNonQuery(); if (i > 0) MessageBox.Show("修改成功!"); conn.Close(); catch (Exception ex) MessageBox.Show(ex.Message, "数据库操作有误!"); else if (tabControl1.SelectedTab.Text.ToString() = "职工信息") show.Text = null; string connString = "Data Source=LENOVO-PC;Initial Catalog=MYCAR;Integrated Security =True" SqlConnection conn = new SqlConnection(connString); try conn.Open(); string sql = String.Format("update staff_mes set 学历='0' where 职工编号='1'", textBox7.Text, textBox12.Text); SqlCommand command = new SqlCommand(sql, conn); int i = command.ExecuteNonQuery(); if (i > 0) MessageBox.Show("修改成功!"); conn.Close(); catch (Exception ex) MessageBox.Show(ex.Message, "数据库操作有误!"); else if (tabControl1.SelectedTab.Text.ToString() = "客户信息") show.Text = null; string connString = "Data Source=LENOVO-PC;Initial Catalog=MYCAR;Integrated Security =True" SqlConnection conn = new SqlConnection(connString); try conn.Open(); string sql = String.Format("update cus_mes set 业务记录='0' where 客户编号='1'",textBox18.Text, textBox16.Text); SqlCommand command = new SqlCommand(sql, conn); int i = command.ExecuteNonQuery(); if (i > 0) MessageBox.Show("修改成功!"); conn.Close(); catch (Exception ex) MessageBox.Show(ex.Message, "数据库操作有误!"); else if (tabControl1.SelectedTab.Text.ToString() = "轿车销售信息") show.Text = null; string connString = "Data Source=LENOVO-PC;Initial Catalog=MYCAR;Integrated Security =True" SqlConnection conn = new SqlConnection(connString); try conn.Open(); string sql = String.Format("update sell_mes set 数量='0' where 销售编号='1'", textBox22.Text, textBox25.Text); SqlCommand command = new SqlCommand(sql, conn); int i = command.ExecuteNonQuery(); if (i > 0) MessageBox.Show("修改成功!"); conn.Close(); catch (Exception ex) MessageBox.Show(ex.Message, "数据库操作有误!"); 修改成功,显示如下:5.双击打印输出销售报表,添加程序代码如下:private void button1_Click(object sender, EventArgs e) show.Text = null; string connString = "Data Source=LENOVO-PC;Initial Catalog=MYCAR;Integrated Security =True" SqlConnection conn = new SqlConnection(connString); try conn.Open(); string carnumber = carnumbox.Text.Trim(); string modelboxs = modelbox.Text.Trim(); string sql = String.Format("select * from sell_mes,staff_mes where sell_mes.职工编号=staff_mes.职工编号" ); SqlCommand command = new SqlCommand(sql, conn); SqlDataReader dataReader = command.ExecuteReader(); int i = 0; for (i = 0; dataReader.Read(); i+) show.Text += "销售编号:" + Convert.ToString(dataReader0) + "n" show.Text += "销售日期:" + Convert.ToString(dataReader1) + "n" show.Text += "轿车类型: " + Convert.ToString(dataReader2) + "n" show.Text += "颜色: " + Convert.ToString(dataReader3) + "n" show.Text += "数量: " + Convert.ToString(dataReader4) + "n" show.Text += "职工编号: " + Convert.ToString(dataReader5) + "n" show.Text += "客户编号: " + Convert.ToString(da