C#实习报告1.docx
《C#实习报告1.docx》由会员分享,可在线阅读,更多相关《C#实习报告1.docx(20页珍藏版)》请在冰点文库上搜索。
C#实习报告1
XXX学院
课程名称:
C#实验报告
年级:
大二
班级:
09软件工程一班
姓名:
XXXX
学号:
1234567
酒店管理系统
一.实习目的:
掌握程序三层开发结构的运用。
二.实习环境:
windowsXp操作系统,VS2005开发工具,SQLerver2005。
三.实习内容:
酒店管理系统
四.项目需求:
为了使先进的电脑技术与现代酒店服务管理完美地结合起来,实现住宿、餐饮、娱乐全新慨念的服务和管理方式。
同时收集用于管理控制本项目开发所需的所有信息。
1.产品用户:
酒店工作人员以及所有需要住店人群
2.软件描述:
序号
子系统名称
模块名称
模块标识
代码大小
1
前客户系统
入住客人登记
SysLog
xxLoc
2
客房类型系统
客人选择住宿房类型
RoomType
xxLoc
3
登录系统
修改、查询、添加用户
Longin
xxLoc
4
房间信息系统
房间信息及入住状态
RoomInfo
xxLoc
5
个人住宿信息
个人信息表
Grxxb
xxLoc
3.主体功能
五.代码实施:
登入酒店管理系统登录界面的代码实现如下:
namespaceGrogshopManageSystem
{
publicpartialclassFrmLongin:
Form
{
publicFrmLongin()
{
InitializeComponent();
}
privatevoidbtnLongin_Click(objectsender,EventArgse)
{
SqlConnectionconn=newSqlConnection("server=.;integratedsecurity=True;database=USU");
conn.Open();
SqlCommandcmd=newSqlCommand("select*fromUseLoginwhereuserName='"+this.txtName.Text.Trim()+"'anduserPwd='"+this.txtPwd.Text.Trim()+"'",conn);
SqlDataReaderdr=cmd.ExecuteReader();
stringstrName=this.txtName.Text.Trim();
stringstrPwd=this.txtPwd.Text.Trim();
if(strName.IndexOf("'")>0||strPwd.IndexOf("-")>0)
{
MessageBox.Show("请不要注释攻击!
");
}
else
{
if(dr.Read())
{
MessageBox.Show("登录成功");
FrmLongFrmL=newFrmLong();
FrmL.Show();
this.Hide();
}
else
{
MessageBox.Show("登录失败");
}
}
conn.Close();
}
}
}
运行结果如下:
小结:
登录界面的用户和密码必须是所建数据库中存在的信息,如果没有的话系统就会提示登录失败。
但是如果一些用户使用不正当的SQL语句注入登录系统的话也可以成功,为了避免这一情况的发生,程序中使用了一个判断语句防止SQL的攻击。
namespaceGrogshopManageSystem
{
publicpartialclassFrmLong:
Form
{
publicFrmLong()
{
InitializeComponent();
}
privatevoidForm1_Load(objectsender,EventArgse)
{
}
privatevoid客户类型设置ToolStripMenuItem_Click(objectsender,EventArgse)
{
FrmroomInfoFrmInfo=newFrmroomInfo();
FrmInfo.MdiParent=this;
FrmInfo.Show();
foreach(Formiteminthis.MdiChildren)
{
if(item.Name!
="FrmroomInfo")
item.Hide();
}
}
privatevoid客户信息设置ToolStripMenuItem_Click(objectsender,EventArgse)
{
FrmroomTypeFrmType=newForm3();
FrmType.MdiParent=this;
FrmType.Show();
foreach(Formiteminthis.MdiChildren)
{
if(item.Name!
="FrmroomType")
item.Hide();
}
}
privatevoid退出系统ToolStripMenuItem_Click(objectsender,EventArgse)
{
DialogResultdr=MessageBox.Show("你确定退出当前系统吗?
","退出提示",MessageBoxButtons.YesNo,MessageBoxIcon.Question,MessageBoxDefaultButton.Button1);
if(dr==DialogResult.Yes)
{
Application.Exit();
}
}
}
}
登陆成功后,运行结果如下
小结:
当登录成功之后就会跳转到这个酒店管理系统的主窗体。
主窗体当中运用了ToolStripMenu控件。
基础设置中包括客户类型,以及客户信息。
当点击客户类型的时候会弹出客户类型信息的窗体,当点客户信息的时候会弹出客户信息的窗体。
通用数据访问层,代码如下:
namespaceCabaretSystem.DAL
{
publicclassDBHelp
{
privatestaticSqlConnection_connection;
publicstaticSqlConnectionConnection
{
get
{
if(_connection==null)
{
_connection=newSqlConnection("server=.;integratedsecurity=True;database=Cabaret");
_connection.Open();
}
if(_connection.State==ConnectionState.Open)
{
_connection.Close();
_connection.Open();
}
return_connection;
}
set
{
DBHelp._connection=value;
}
}
//insertupdatadelete
publicstaticintExecutecommand(stringsql)
{
SqlCommandcmd=newSqlCommand(sql,Connection);
returncmd.ExecuteNonQuery();
}
//数据存储,方法重载
publicstaticintExecutecommand(stringsql,paramsSqlParameter[]paramList)
{
SqlCommandcmd=newSqlCommand(sql,Connection);
cmd.Parameters.AddRange(paramList);
cmd.CommandType=CommandType.StoredProcedure;
returncmd.ExecuteNonQuery();
}
//select
publicstaticSqlDataReaderGetreader(stringsql)
{
SqlCommandcmd=newSqlCommand(sql,Connection);
returncmd.ExecuteReader();
}
publicstaticSqlDataReaderGetreader(stringsql,paramsSqlParameter[]paramList)
{
SqlCommandcmd=newSqlCommand(sql,Connection);
cmd.Parameters.AddRange(paramList);
cmd.CommandType=CommandType.StoredProcedure;
returncmd.ExecuteReader();
}
//insertupdatadeleteselect
publicstaticDataTableGettable(stringsql)
{
SqlDataAdaptersda=newSqlDataAdapter(sql,Connection);
DataTabledt=newDataTable();
sda.Fill(dt);
returndt;
}
publicstaticDataTableGettable(stringsql,paramsSqlParameter[]paramList)
{
SqlDataAdaptersda=newSqlDataAdapter(sql,Connection);
sda.SelectCommand.Parameters.AddRange(paramList);
sda.SelectCommand.CommandType=CommandType.StoredProcedure;
DataTabledt=newDataTable();
sda.Fill(dt);
returndt;
}
}
}
小结:
DAL数据库通用访问层,用于连接数据库读取数据,在三层结构中处于底层,代码可以重用。
房间类型信息的数据操作代码(包括查询,修改,删除,添加):
namespaceCabaretSystem.DAL
{
classDALType
{
///
///查询全部房间类型信息
///
///
publicDataTableselectAllType()
{
returnDBHelp.Gettable("selectAllUser");
}
//根据名称查询类型表的一行数据
publicDataTableselectByType(stringstrname)
{
SqlParameterparam_name=newSqlParameter("@typename",strname);
returnDBHelp.Gettable("selectBytypeInfo",param_name);
}
//在客房类型表里插入一行数据
publicintaddOneType(stringstrTypeName,decimaldecRoomPrice,stringstrAddBed,decimaldecAddBedPrice,stringstrExplain)
{
SqlParameterparam_typename=newSqlParameter("@typeName,,",strTypeName);
SqlParameterparam_roomprice=newSqlParameter("@roomPrice",decRoomPrice);
SqlParameterparam__addbed=newSqlParameter("@addBed",strAddBed);
SqlParameterparam_addbedprice=newSqlParameter("@addBedPrice",decAddBedPrice);
SqlParameterparam_explain=newSqlParameter("@explain",strExplain);
SqlParameter[]paramList=newSqlParameter[]{param_typename,param_roomprice,param_addbed,param_addbedprice,param_explain};
returnDBHelp.Executecommand("addOnetypeInfo",paramList);
}
//修改房间类型
publicintaddOneType(intintID,stringstrTypeName,decimaldecRoomPrice,stringstrAddBed,decimaldecAddBedPrice,stringstrExplain)
{
SqlParameterparam_typeid=newSqlParameter("typeID",intID);
SqlParameterparam_typename=newSqlParameter("@typeName",strTypeName);
SqlParameterparam_roomprice=newSqlParameter("@roomPrice",decRoomPrice);
SqlParameterparam__addbed=newSqlParameter("@addBed",strAddBed);
SqlParameterparam_addbedprice=newSqlParameter("@addBedPrice",decAddBedPrice);
SqlParameterparam_explain=newSqlParameter("@explain",strExplain);
SqlParameter[]paramList=newSqlParameter[]{param_typeid,param_typename,param_roomprice,param_addbed,param_addbedprice,param_explain};
returnDBHelp.Executecommand("upOnetypeInfo",paramList);
}
//删除一条房间类型信息
publicintdelOneType(stringstrtypeName)
{
SqlParameterparam_typename=newSqlParameter("@typeName",strtypeName);
returnDBHelp.Executecommand("delOnetypeInfo",param_typename);
}
}
}
小结:
对房间类型信息操作。
数据库代码,包括存储过程:
dropdatabaseCabaret
createdatabaseCabaret-----建数据库
go
------------------
useCabaret
go
createtableRoomType-----房间类型表
(
typeIDintprimarykeyidentity(1,1),---类型ID
typeNamechar(8)notnull,-----------类型名称
roomPriceintnotnull,------------------房间价格
addBedchar
(2)notnull,-----------------是否加床
addPriceintnotnull,-------------------加床价格
explainnvarchar(50)---------------------介绍
)
Go
useCabaret
go
insertintoRoomType(typeName,roomPrice,addBed,addPrice,explain)
select'标准间',200,'是',60,'无独立卫生间'union
select'双人间',300,'否',0,'有卫生间'union
select'套间',500,'否',60,'可以看电视'union
select'豪华间',800,'是',60,'可上网'union
select'总统套间',1800,'是',60,'有卫星电话'
go
--查找类型全表
createprocedureselectAllUser
as
select*fromRoomType
go
--根据类型名称查找数据
createprocselectBytypeInfo
(
@Typenamechar(8)
)
as
select*fromRoomTypewheretypeName=@Typename
go
--增加一条类型信息
createprocaddOnetypeInfo
(
@typeNamechar(8),
@roomPriceint,
@addBedchar
(2),
@addBedPriceint,
@explainnvarchar(50)
)
as
insertintoRoomTypevalues(@typeName,@roomPrice,@addBed,@addBedPrice,@explain)
go
--根据类型删除数据
createprocdelOnetypeInfo
(
@typeNamechar(8)
)
as
deletefromkefanglxwheretypeName=@typeName
go
--根据类型ID修改数据
createprocupOnetypeInfo
(
@typeIDint,
@typeNamechar(8),
@typePriceint,
@addBedchar
(2),
@addBedPriceint,
@explainnvarchar(50)
)
as
updateRoomTypesettypeName=@typeName,typePrice=@typePrice,@addBed=addBed,addBedPrice=@addBedPrice,explain=@explainwheretypeID=@typeID
go
房间类型表
客房信息表
小结:
利用存储结构,封装业务逻辑,可以重复调用,执行速度快,减少网络流量,安全系数高。
房间信息操作数据代码
namespaceCabaretSystem.DAL
{
classroomInfo
{
publicDataTablegetAllroomInfo()
{
returnDBhelp.GetTable("select*fromroomInfo");
}
//新增方法
publicintaddroomInfo(intRoomId,intChow,stringstate,intRZhow,stringdepict)
{
returnDBhelp.ExecuteCommand("insertintoroomInfo(RoomId,Chow,state,RZhow,depict)values('"+RoomId+"','"+Chow+"','"+state+"','"+RZhow+"','"+depict+"')");
}
//修改方法
publicintupdateRoomInfo(intRoomId,intChow,stringstate,intRZhow,stringdepict)
{
returnDBhelp.ExecuteCommand("updateroomInfosetChow="+Chow+",state='"+state+"',RZhow="+RZhow+",depict='"+depict+"'whereRoomId="+RoomId+"");
}
//删除方法
publicintdeledeRoomInfo(intRoomId)
{
returnDBhelp.ExecuteCommand("deletefromroomInfowhereRoomId='"+RoomId+"'");
}
//查询方法
publicDataTableGetTableInfo(intRoomId)
{
returnDBhelp.GetTable("select*fromRoomInfowhereRoomIdlike'%"+RoomId+"%'");
}
//通过类型名称查找价格
publicDataTableGetPriceByName(stringstrName)
{
returnDBhelp.GetTable("selectpricefromroomTyplewhereTypleName='"+strName+"'");
}
}
}
小结:
数据层中(DAL)的代码就是写一些对客户信息进行修改,删除,添加,查询的一些方法,通过SQL语句,对数据进行查询,删除,添加,查询而已。
业务逻辑层BLL,传递界面层的参数。
逻辑层是界面层和数据层的桥梁,它响应界面层的用户请求,执行任务并从数据层抓取数据,并将必要的数据传送给界面层。
房间类型逻辑层
namespaceCabaretSystem.BLL
{
publicclassroomInfoManager
{
roomInforoominfo=n