c sharp 班级通讯录管理系统实训报告.docx
《c sharp 班级通讯录管理系统实训报告.docx》由会员分享,可在线阅读,更多相关《c sharp 班级通讯录管理系统实训报告.docx(17页珍藏版)》请在冰豆网上搜索。
![c sharp 班级通讯录管理系统实训报告.docx](https://file1.bdocx.com/fileroot1/2023-1/14/4a3b6712-2bbf-4105-adbd-1e8ab0fa3f55/4a3b6712-2bbf-4105-adbd-1e8ab0fa3f551.gif)
csharp班级通讯录管理系统实训报告
csharp班级通讯录管理系统实训报告
《C#应用程序设计》
实
训
报
告
系部:
信息工程系班级:
12软件班姓名:
陶沪指导教师:
刘春友实训时间:
2013年春季学期
班级通讯录管理系统实训报告一、实训主题
班级通讯录系统的开发和运用
二、实训时间:
2013年6月1日,2013年6月27日
三、实训目的
教会学生利用Visulstatus2005开发平台开发出班级通讯录系统,并利用.netFramework组件实际与数据库的连接,建立班级通讯录的显示,查询,添加,修改,删除四个功能块窗体,以及登录界面和主界面两个辅助窗体.最终实现班级通讯录系统增,删,改,查四项基本功能.
四、实训内容与要求:
“班级通讯录管理系统”是以班级学生的个人信息为主的管理系统,合理的数据库结构设计可以提高数据存储的效率,保证数据的完整性和一致性。
运用结构化开发方法,分析并开发一个小型、简单的“班级通讯录管理系统”。
功能:
设计一个班级通讯录管理系统,班级通讯录数据信息构成内容可自行设计(如班级、学号、姓名、性别、年龄、电话、邮政编码、邮箱等)。
要求实现显示、查找、添加、删除、修改某个记录等功能。
五、实训中的重要知识和方法
ADO.NET概述:
ADO.NET提供诸如SQLServer和XML这
样的数据源以及通过OLEDB和ODBC公开的数据源的一致访问。
ADO.NET包含于用于连接到数据库,执行命令和检索结果的.NETFramework数据提供程序。
这些结果或者被直接处理,放在ADO.NETDataSet对象中以便用特别的方式向用户开放,并与来自多个源的数据组合:
或者在层之间传递。
DataSet对象也可以独立于.NETFramework数据提供程序,用于管理应用程序本地的数据或源自XML的数据。
ADO.NET用于访问和操作数据的两个主要组件是:
.NETFramework数据提供程序和DataSet。
.NETFramework数据提供程序用于连接到数据库,执行命令和检索结果。
DataSet可以用于多种不同的数据源,用于XML数据,或用于管理应用程序本地的数据。
DataSet包含一个或多个DataTable对象的集合,这些对象由数据行和数据列以及有关DataTable对象中数据的主键,外键,约束和关系信息组成。
六、实训步骤
1.总体结构图
班级通讯录
管理系统
删除联系人修改联系人查找联系人添加联系人
2.流程图:
登录
否
判断用户名的有效性和
合法性
是
班级通讯录管理系统主界面查删添修询除加改联联联联系系系系人人人人信信信信息息息息
3.数据库设计
字段名类型长度是否为空是否为主说明
键
userId文本10否是用户名userPwd文本10否否用户密码字段名类型长度是否为空是否为主说明
键
stuNo文本8否是学号stuName文本10否否姓名classId文本10是否班级Sex文本2否否性别birthday日期/时间10是否出生日期tel文本15是否电话address文本100是否家庭住址QQ文本6是否邮政编码email文本30是否电子邮箱remark文本是否备注七、实训代码
数据库链接代码:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Text;
usingSystem.Data.OleDb;
usingSystem.Windows.Forms;
usingSystem.Data;
namespace班级通讯录管理系统
{
classDataAccess
{
//定义连接字符串
privatestringstrDSN;
//定义数据库连接对象
OleDbConnectionoledbCon;
//数据库连接方法
publicvoiddataCon()
{
strDSN="Provider=Microsoft.Jet.OLEDB.4.0;DataSource="+Application.StartupPath.ToString()+"\\class.mdb";
oledbCon=newOleDbConnection(strDSN);
}
//获取DataSet
publicDataSetgetDataset(stringsql)
{
DataSetds=newDataSet();
oledbCon.Open();
try
{
OleDbCommandoledbCom=newOleDbCommand(sql,oledbCon);
OleDbDataAdapteroledbDa=newOleDbDataAdapter(oledbCom);
oledbDa.Fill(ds);
returnds;
}
catch(Exceptionex)
{
thrownewException(ex.ToString());
}
finally
{
oledbCon.Close();
}
}
//执行SQL语句
publicboolsqlExec(stringsql)
{
try
{
oledbCon.Open();
}
catch
{
MessageBox.Show("数据库未连接");
}
try
{
OleDbCommandoledbCom=newOleDbCommand(sql,oledbCon);
oledbCom.ExecuteNonQuery();
returntrue;
}
catch(Exceptionex)
{
MessageBox.Show(ex.Message,"提示");
returnfalse;
}
finally
{
oledbCon.Close();
}
}
}
}
登录界面:
usingSystem;
usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;
usingSystem.Drawing;
usingSystem.Text;
usingSystem.Windows.Forms;usingSystem.Data.OleDb;
namespace班级通讯录管理系统
{
publicpartialclassUsersLogin:
Form
{
publicUsersLogin()
{
InitializeComponent();
}
privatevoidUsersLogin_Activated(objectsender,EventArgse)
{
//将光标放在用户名文本框上
textBox1.Focus();
}
privatevoidbutton1_Click(objectsender,EventArgse)
{
stringusername,password;
stringstrSql="";
DataSetds;
//判断文本框是否为空
if(textBox1.Text.Trim()!
=""&&textBox2.Text.Trim()!
="")
{
username=textBox1.Text.Trim();
password=textBox2.Text.Trim();
strSql="select*fromusersloginwhereuserId='"+username+"'anduserPwd='"
+password+"'";
//实例化类
DataAccessdata=newDataAccess();
//连接数据库
data.dataCon();
//执行查询语句,获取Dataset
ds=data.getDataset(strSql);
//判断是否登录成功
if(ds.Tables[0].Rows.Count==1)
{
MainfMain=newMain();
fMain.Show();
this.Hide();
}
else
{
MessageBox.Show("用户名或密码错误~","登录失败");
}
}
}
privatevoidbutton2_Click(objectsender,EventArgse)
{
Application.Exit();
}
privatevoidlabel2_Click(objectsender,EventArgse)
{
}
}
}
主界面:
usingSystem;
usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;
usingSystem.Drawing;
usingSystem.Text;
usingSystem.Windows.Forms;
namespace班级通讯录管理系统
{
publicpartialclassMain:
Form
{
publicMain()
{
InitializeComponent();
}
privatevoidMain_FormClosing(objectsender,FormClosingEventArgse)
{
Application.Exit();
}
privatevoid添加联系人ToolStripMenuItem_Click(objectsender,EventArgse)
{
AddLinkmanfrm2=newAddLinkman();
frm2.Show();
}
privatevoid删除联系人ToolStripMenuItem_Click(objectsender,EventArgse)
{
ManageLinkmanfrm4=newManageLinkman();
frm4.Show();
}
privatevoid显示全部联系人ToolStripMenuItem_Click(objectsender,EventArgse)
{
AllLinkmanfrm1=newAllLinkman();
frm1.Show();
}
privatevoid修改联系人ToolStripMenuItem_Click(objectsender,EventArgse)
{
ManageLinkmanfrm3=newManageLinkman();
frm3.Show();
}
privatevoid查询联系人ToolStripMenuItem_Click(objectsender,EventArgse)
{
ManageLinkmanfrm4=newManageLinkman();
frm4.Show();
}
privatevoid退出系统ToolStripMenuItem_Click(objectsender,EventArgse)
{
Application.Exit();
}
}
}
查询窗体代码:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;usingSystem.Data;
usingSystem.Drawing;
usingSystem.Text;
usingSystem.Windows.Forms;
namespace班级通讯录管理系统
{
publicpartialclassManageLinkman:
Form
{
publicManageLinkman()
{
InitializeComponent();
}
publicstaticstringstuNo;
publicstaticstringStuNo
{
get{returnstuNo;}
set{stuNo=value;}
}
privatevoidbutton1_Click(objectsender,EventArgse)
{
stringstrSql;
stringconditon="";
DataAccessdata=newDataAccess();
DataSetds;
if(textBox1.Text!
="")
{
conditon+="andstuNo='"+textBox1.Text+"'";
}
if(textBox2.Text!
="")
{
conditon+="andstuName='"+textBox2.Text+"'";
}
if(textBox3.Text!
="")
{
conditon+="andclassId='"+textBox3.Text+"'";
}
if(comboBox1.Text!
="")
{
conditon+="andSex='"+comboBox1.Text+"'";
}
strSql="selectstuNoas学号,stuNameas姓名,Sexas性别,birthdayas出生日期,
classIdas班级,telas电话,addressas家庭地址,postalcodeas邮政编码,emailas电子邮箱,
remarkas备注fromusersinfowhere1=1"+conditon;
data.dataCon();
ds=data.getDataset(strSql);
dataGridView1.DataSource=ds.Tables[0];
}
privatevoidbutton2_Click(objectsender,EventArgse)
{
stringstrSql;
DataAccessdata=newDataAccess();
strSql="deletefromusersinfowherestuNo='"+dataGridView1.CurrentRow.Cells[0].Value.ToString()+"'";
data.dataCon();
if(data.sqlExec(strSql))
{
MessageBox.Show("删除成功~");
}
else
{
MessageBox.Show("删除失败~");
}
}
privatevoidbutton3_Click(objectsender,EventArgse)
{
ManageLinkman.StuNo=dataGridView1.CurrentRow.Cells[0].Value.ToString();
EditLinkmans1=newEditLinkman();
s1.Show();
}
}
}
修改窗体代码:
usingSystem;
usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;
usingSystem.Drawing;
usingSystem.Text;
usingSystem.Windows.Forms;
namespace班级通讯录管理系统
{
publicpartialclassEditLinkman:
Form
{
publicEditLinkman()
{
InitializeComponent();
}
privatevoidbutton1_Click(objectsender,EventArgse)
{
stringstrSql="";
if(textBox2.Text!
=""&&textBox3.Text!
=""&&textBox4.Text!
=""&&
textBox5.Text!
=""&&textBox6.Text!
=""&&textBox7.Text!
=""&&textBox8.Text!
=""&&
textBox9.Text!
=""&&comboBox1.Text!
="")
{
strSql="updateuesrsinfosetstuName='"+textBox2.Text+"',Sex='"+
comboBox1.Text+"',birthday='"+textBox4.Text+"',classId='"+textBox3.Text+"',tel='"+
textBox5.Text+"',Address='"+textBox8.Text+"',postalcode='"+textBox6.Text+"',email='"
+textBox7.Text+"',remark='"+textBox9.Text+"',wherestuNo='"+ManageLinkman.stuNo+"'";
DataAccessdata=newDataAccess();
data.dataCon();
if(data.sqlExec(strSql))
{
MessageBox.Show("修改成功~");
}
else
{
MessageBox.Show("修改失败~");
}
}
else
{
MessageBox.Show("输入未完全~");
}
}
privatevoidEditLinkman_Load(objectsender,EventArgse)
{
textBox1.Text=ManageLinkman.StuNo;
}
privatevoidbutton2_Click(objectsender,EventArgse)
{
this.Close();
}
}
}
添加窗体代码:
usingSystem;
usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;
usingSystem.Drawing;
usingSystem.Text;
usingSystem.Windows.Forms;
namespace班级通讯录管理系统
{
publicpartialclassAddLinkman:
Form
{
publicAddLinkman()
{
InitializeComponent();
}
privatevoidbutton1_Click(objectsender,EventArgse)
{
stringstrSql;
DataAccessdata=newDataAccess();
strSql="insertinto
usersinfo(stuNo,stuName,classId,birthday,tel,postalcode,email,address,remark,Sex)values
('"+textBox1.Text+"','"+textBox2.Text+"','"+textBox3.Text+"','"+textBox4.Text
+"','"+textBox5.Text+"','"+textBox6.Text+"','"+textBox7.Text+"','"+textBox8.Text+"','"+textBox9.Text+"','"+comboBox1.Text+"')";
data.dataCon();
if(data.sqlExec(strSql))
{
MessageBox.Show("添加成功~");
}
else
{
MessageBox.Show("添加失败~");
}
}
privatevoidbutton2_Click(objectsender,EventArgse)
{
this.Close();
}
}
}
显示所有联系人窗体代码:
usingSystem;
usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;
usingSystem.Drawing;
usingSystem.Text;
usingSystem.Windows.Forms;
namespace班级通讯录管理系统
{
publicpartialclassAllLinkman:
Form
{
publicAllLinkman()
{
InitializeComponent();
}
privatevoidbutton1_Click(objectsender,EventArgse)
{
stringstrSql;
DataAccessdata=newDataAccess();
DataSetds;
strSql="select*fromusersinfo";
data.dataCon();
ds=data.getDataset(str