设备管理_设备管理系统程序设计_第1页
设备管理_设备管理系统程序设计_第2页
设备管理_设备管理系统程序设计_第3页
设备管理_设备管理系统程序设计_第4页
设备管理_设备管理系统程序设计_第5页
已阅读5页,还剩22页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

C#程序设计大作业题 目: 设备管理系统 专 业: 计算机科学与技术s 学 号: 姓 名: 朱 晓 敏 完成日期: 2012/11/6 目 录1 前言22 需求分析22.1要求22.2任务22.3运行环境22.4开发工具23 概要设计与详细设计33.1系统流程图33.2数据库设计43.2.1建立数据字典43.2.2数据库详细设计44 编码与实现54.1分析54.2具体代码实现74.3界面实现165 课程设计总结24参考文献25评语及成绩01 前言设计一个设备管理系统,该系统主要针对设备管理员。系统首先要求用户登录,用户必须输入正确的用户名和密码;系统主界面包括设备查询功能及数据维护功能,设备查询功能是按一定的条件查询所需要的设备信息,数据维护主要是通过增加或删除来修改数据。2 需求分析2.1要求(1)用Csharp语言实现程序设计;(2)采用.NET开发工具来设计主窗体和子窗体等;(3)画出系统模块的流程图;(4)完成数据库的设计;(5)界面友好(良好的人机互交),程序要有注释。2.2任务(1)设计一个登陆窗体和主窗体,7个子窗体来显示相关信息;(2)管理员必须输入正确的用户名和密码,才能进入主窗体进行相关操作;(3)画出所有模块的流程图;(4)完成数据库的设计;(5)编写代码;(6)程序分析与调试。2.3运行环境(1)WINDOWS2000/XP系统(2)Visual Studio 2005编译环境2.4开发工具 C#: C#(C Sharp)是微软为NET Framework量身订做的程序语言,C#拥有C/C+的强大功能以及Visual Basic简易使用的特性,是第一个组件导向(Component-oriented)的程序语言,和C+与Java一样亦为对象导向(object-oriented)程序语言。3 概要设计与详细设计3.1系统流程图首先要有一个登录模块对登录用户进行验证,如果验证成功则进入系统的主窗体,登录主窗体之后管理员以操作所有的功能:查询、修改、增加设备信息、辅助工具、退出。开始用户名及密码选择操作类型查询设备信息修改设备信息添加设备信息删除设备信息设备信息表退出NY图3.1 系统流程图3.2数据库设计3.2.1建立数据字典在开发设备管理系统之前,分析了改系统的数据量。选择Microsoft SQL Server2005数据库存储这些信息,数据库命名为MyDevice,在数据库中创建了2个数据表用于不同的信息。1.设备管理员数据字典 名字:设备管理员表(User)描述:记录管理员的具体详细信息定义:设备管理员表=用户编号+用户名+密码 位置:设备管理数据库2.设备数据字典名字:设备信息表(equipment)描述:记录设备的具体详细信息定义:设备信息表=设备编号+设备名称+设备数量+设备价格 位置:设备管理数据库3.2.2数据库详细设计表1 User表结构列名数据类型 说明userIdint用户编号,主键,标识列,表示增量1,标识种子1UserNamenvarchar(50)用户名,非空passwordnvarchar(50)密码,非空表2 equipment表结构列名数据类型 说明idint设备编号,主键,标识列,表示增量1,标识种子1namenvarchar(50)设备名称,非空pricemoney设备名称,非空countint设备数量,非空4 编码与实现4.1分析(1)登陆界面的设计打开Visual Studio 2005,新建一个名为DeviceSystem项目,然后打开一个窗体并命名为userlogin.cs。在此窗体中添加2个标签(用户名和密码)、2个按钮(确定和取消)和2个textBox等,如图所示 图4.1 登陆窗体(2)系统主窗体的设计添加窗体并命名为frmMain.cs,在此窗体添加一个MenuStrip控件,一个 ToolStrip控件及3个按钮,一个Time控件,toolStripStatus控件并分别设置各属性,如图所示 图4.2 系统主窗体(3)子窗体的设计添加4个窗体并依此命名为frmselecName.cs、frmselecPrice.cs、frmDataMaint.cs、frmDeletedevice.cs并分别添加工具控件及设置各属性,如图所示图4.3 按名称查询窗图4.4 按价格查询窗体图4.5 数据维护窗体4.2具体代码实现1.登录窗体frmlogin.csusing System;using System.Configuration;namespace DeviceSystem private void btnYes_Click(object sender, EventArgs e) string userName = txtName.Text; string password = txtPwd.Text; string cons = ConfigurationManager.ConnectionStringsDeviceSystem.Properties.Settings.MyDeviceConnectionString.ConnectionString; SqlConnection connection = new SqlConnection(cons); /获取用户名和密码匹配的行的数量的SQL语句 string sql=String.Format(select count(*) from User where username=0and password=1,userName,password); try connection.Open(); /打开数据库连接 SqlCommand command = new SqlCommand(sql,connection); /创建Command对象 int num = (int)command.ExecuteScalar(); /执行查询语句,返回匹配的行数 if (num 0) /如果有匹配的行,则表明用户名和密码正确 MessageBox.Show(欢迎进入设备管理系统!, 登录成功, MessageBoxButtons.OK, MessageBoxIcon.Information); frmMain mainForm=new frmMain(); /创建主窗体对象 mainForm.Show(); /显示窗体 this.Visible=false; /登陆窗体隐藏 else MessageBox.Show(您输入的用户名或密码错误!, 登录失败, MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Exclamation); /MessageBoxIcon.Exclamation是由三角符号组成的警惕图 catch (Exception ex) MessageBox.Show(ex.Message,操作数据库出错啦!,MessageBoxButtons.OK,MessageBoxIcon.Exclamation); finally connection.Close(); /关闭数据库连接 private void btnCancel_Click(object sender, EventArgs e) txtName.Text = ; txtPwd.Text = ; txtName.Focus();/将光标指定在txtName上 2.主窗体frmMain.csusing System;using System.Windows.Forms;namespace DeviceSystem private void timer1_Tick(object sender, EventArgs e) DateTime dt = DateTime.Now; /获取当前时间 tssData.Text = dt.ToLongDateString() ; private void tsmExit_Click(object sender, EventArgs e) Application.Exit(); private void tsmSelecName_Click(object sender, EventArgs e) frmselecName selectname = new frmselecName(); /创建子窗体对象 selectname.MdiParent = this; /指定当前窗体为MDI父窗体 selectname.Show(); /打开子窗体 tssStatus.Text = 按名称查询; /在状态栏中显示操作内容 private void tsmSelecPrice_Click(object sender, EventArgs e) frmselecPrice selectprice = new frmselecPrice(); /创建子窗体对象 selectprice.MdiParent = this; /指定当前窗体为MDI父窗体 selectprice.Show(); /打开子窗体 tssStatus.Text = 按单价查询; /在状态栏中显示操作内容 private void tsmUpdate_Click(object sender, EventArgs e) frmDataMaint datamaint = new frmDataMaint(); /创建子窗体对象 datamaint.MdiParent = this; /指定当前窗体为MDI父窗体 datamaint.Show(); /打开子窗体 tssStatus.Text = 修改数据; /在状态栏中显示操作内容 private void tsmabout_Click(object sender, EventArgs e) frmAbout about = new frmAbout(); /创建子窗体对象 about.MdiParent = this; / /指定当前窗体为MDI父窗体 about.Show(); /打开子窗体 tssStatus.Text = 关于我们; /在状态栏中显示操作内容 private void tsmjsq_Click(object sender, EventArgs e) frmjsq jsq = new frmjsq(); /创建子窗体对象 jsq.MdiParent = this; /指定当前窗体为MDI父窗体 jsq.Show(); /打开子窗体 tssStatus.Text = 计算器; /在状态栏中显示操作内容 private void tsmdate_Click(object sender, EventArgs e) frmTime time = new frmTime(); /创建子窗体对象 time.MdiParent = this; /指定当前窗体为MDI父窗体 time.Show(); / /打开子窗体 tssStatus.Text = 万年历; /在状态栏中显示操作内容 private void tsmdel_Click(object sender, EventArgs e) frmDeletedevice delete = new frmDeletedevice(); /创建子窗体对象 delete.MdiParent = this; /指定当前窗体为MDI父窗体 delete.Show(); /打开子窗体 tssStatus.Text = 设备数据维护; /在状态栏中显示操作内容 3.子窗体frmMain.csusing System;using System.Windows.Forms;using System.Data.SqlClient;using System.Configuration;namespace DeviceSystem public frmselecName() InitializeComponent(); string cons = ConfigurationManager.ConnectionStringsDeviceSystem.Properties.Settings.MyDeviceConnectionString.ConnectionString connection = new SqlConnection(cons); private void frmselecName_Load(object sender, EventArgs e) / TODO: 这行代码将数据加载到表“myDeviceDataSet.equipment”中。您可以根据需要移动或移除它。 this.equipmentTableAdapter.Fill(this.myDeviceDataSet.equipment); private void btnSelectName_Click(object sender, EventArgs e) string name = textBox1.Text; /按名称查询设备 string sql = String.Format(select * from equipment where name like %0%,name); try SqlDataAdapter dataAdapter = new SqlDataAdapter(sql, connection); DataSet datSet = new DataSet(equipment); dataAdapter.Fill(datSet); /设置各列的显示数据字段 dataGridView1.Columns0.DataPropertyName = id; dataGridView1.Columns1.DataPropertyName = name; dataGridView1.Columns2.DataPropertyName = price; dataGridView1.Columns3.DataPropertyName = count; dataGridView1.DataSource = datSet.Tables0; catch (Exception ex) MessageBox.Show(ex.Message, 操作数据库出错啦!, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); private void button1_Click(object sender, EventArgs e) this.Close(); 4.子窗体frmselecPrice.csusing System;using System.Drawing;using System.Data.SqlClient;using System.Configuration;namespace DeviceSystem public frmselecPrice() InitializeComponent(); string cons = ConfigurationManager.ConnectionStringsDeviceSystem.Properties.Settings.MyDeviceConnectionString.ConnectionString; connection = new SqlConnection(cons); private void btnselectPrice_Click(object sender, EventArgs e) / decimal表示十进制数 decimal price1, price2; try price1 = Convert.ToDecimal(textBox1.Text); price2 = Convert.ToDecimal(textBox2.Text); catch price1 = 0; price2 = M;/默认为最大值 if(price1price2) /如果price1price2,交换两者 decimal temp=price1; price1=price2; price2=temp; /按价格查询设备 string sql=String.Format(select * from equipment where price between 0 and 1,price1,price2); try SqlDataAdapter dataAdapter = new SqlDataAdapter(sql, connection); DataSet datSet = new DataSet(equipment); dataAdapter.Fill(datSet); /设置各列的显示数据字段 dataGridView1.Columns0.DataPropertyName = id; dataGridView1.Columns1.DataPropertyName = name; dataGridView1.Columns2.DataPropertyName = price; dataGridView1.Columns3.DataPropertyName = count; dataGridView1.DataSource = datSet.Tables0; catch (Exception ex) MessageBox.Show(ex.Message, 操作数据库出错啦!, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); private void frmselecPrice_Load(object sender, EventArgs e) / TODO: 这行代码将数据加载到表“myDeviceDataSet.equipment”中。您可以根据需要移动或移除它。 this.equipmentTableAdapter.Fill(this.myDeviceDataSet.equipment); private void button1_Click(object sender, EventArgs e) this.Close(); 5.子窗体frmDataMaint.csusing System;using System.Data.SqlClient;namespace DeviceSystem private void frmDataMaint_Load(object sender, EventArgs e) / TODO: 这行代码将数据加载到表“myDeviceDataSet.equipment”中。您可以根据需要移动或移除它。 this.equipmentTableAdapter.Fill(this.myDeviceDataSet.equipment); private void btnsave_Click(object sender, EventArgs e) equipmentTableAdapter.Update(myDeviceDataSet.equipment); private void btnguanbi_Click(object sender, EventArgs e) this.Close(); private void btnrefresh_Click(object sender, EventArgs e) equipmentTableAdapter.Fill(myDeviceDataSet.equipment); 6.子窗体frmDeletedevice.csusing System;using System.Data.SqlClient;using System.Configuration;namespace DeviceSystem public partial class frmDeletedevice : Form SqlConnection con; SqlDataAdapter da; DataSet ds; SqlCommand com; public frmDeletedevice() InitializeComponent(); private void frmDeletedevice_Load(object sender, EventArgs e) BKY(); string cons = ConfigurationManager.ConnectionStringsDeviceSystem.Properties.Settings.MyDeviceConnectionString.ConnectionString; con= new SqlConnection(cons); /绑定cbosm da = new SqlDataAdapter(select name from equipment, con); ds = new DataSet(); da.Fill(ds, equipment); cbosm.DataSource = ds.Tablesequipment; cbosm.DisplayMember = name; FillDgvshebei(); private void FillDgvshebei() /绑定dgvshebei da = new SqlDataAdapter(select * from equipment, con); ds = new DataSet(); da.Fill(ds, equipment); dgvshebei.DataSource = ds.Tables0; private void dgvshebei_CellClick(object sender, DataGridViewCellEventArgs e) txthao.Text = Convert.ToString(dgvshebeiid, dgvshebei.CurrentCell.RowIndex.Value); txtname.Text = Convert.ToString(dgvshebeiname, dgvshebei.CurrentCell.RowIndex.Value); txtC.Text = Convert.ToString(dgvshebeiprice, dgvshebei.CurrentCell.RowIndex.Value); txtD.Text = Convert.ToString(dgvshebeicount, dgvshebei.CurrentCell.RowIndex.Value); private void tsbdel_Click(object sender, EventArgs e) com = new SqlCommand(delete from equipment where id= + txthao.Text + , con); if (con.State = ConnectionState.Closed) con.Open(); int i = (int)com.ExecuteNonQuery(); con.Close(); if (i 0) FillDgvshebei(); MessageBox.Show(删除成功!); private bool bselect() com = new SqlCommand(select count(*) from equipment where id= + txthao.Text + and name= + txtname.Text + , con); if (con.State = ConnectionState.Closed) con.Open(); int i = (int)com.ExecuteScalar(); con.Close(); if (i 0) MessageBox.Show(已有这条记录!); Clear(); return true; else return false; private void Clear() txthao.Text = ; txtname.Clear(); private void tslbaocun_Click(object sender, EventArgs e) if (txtname.Text = | txtC.Text = | txtD.Text = ) MessageBox.Show(填写不完整!); else if (bselect() = false) com = new SqlCommand(insert into equipment(name,price,count)values( + txtname.Text + , + txtC.Text + , + txtD.Text + ), con); if (con.State = ConnectionState.Closed) con.Open(); int j = (int)com.ExecuteNonQuery(); con.Close(); if (j 0) FillDgvshebei(); MessageBox.Show(增加成功!); private void tsbquxiao_Click(object sender, EventArgs e) Clear(); BKY(); private void BKY() txthao.Enabled = false; txtname.Enabled = false; tslbaocun.Enabled = false; tsbquxiao.Enabled = false; private void KY() txthao.Enabled = true; txtname.Enabled = true; tslbaocun.Enabled = true; tsbquxiao.Enabled = true; private void tsmjia_Click(object sender, EventArgs e) KY(); private void btntui_Click(object sender, EventArgs e) this.Close(); 4.3界面实现首先用户进入登录界面,必须输入正确的用户名和密码,否则会提示用户名或密码错误,请重新输入:图4.6 输入正确后,点击确定按钮后则进入系统的主界面,进行相关操作:图4.7 点击“按名称查询”,进入查询界面,输入

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论