📄 hotelaccessor.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using DBaoBookingManagement.Entity;
namespace DBaoBookingManagement.DataAccess
{
/// <summary>
/// 对Hotel表进行操作的类
/// </summary>
public class HotelAccessor:DataAccessor
{
//根据ID查询酒店
public DataTable QueryById(int id)
{
string sql = "select * from Hotel where HotelId=" + id;
try
{
return base.Query(sql);
}
catch (Exception ex)
{
throw new Exception("根据酒店ID查询酒店时出现错误:" + ex.Message);
}
}
//查询所有酒店
public DataTable QueryAll()
{
string sql = "select * from Hotel";
try
{
return base.Query(sql);
}
catch (Exception ex)
{
throw new Exception("查询所有酒店时出现错误:" + ex.Message);
}
}
//根据城市ID查询酒店
public DataTable QueryByCityId(int id)
{
string sql = "select * from Hotel where CityId=" + id;
try
{
return base.Query(sql);
}
catch (Exception ex)
{
throw new Exception("根据城市ID查询酒店时出现错误:" + ex.Message);
}
}
//根据酒店ID删除酒店
public bool DeleteById(int id)
{
string sql = "delete Hotel where HotelId=" + id;
try
{
return base.ExecuteSqlNoneQuery(sql);
}
catch (Exception ex)
{
throw new Exception("根据酒店ID删除酒店时出现错误:" + ex.Message);
}
}
//插入酒店
public bool Insert(Hotel entity)
{
string hotelName = entity.HotelName;
int star = entity.Star;
string description = entity.Description;
int cityId = entity.CityId;
string synthesis = entity.Synthesis;
string pets = entity.Pets;
string activePlace = entity.ActivePlace;
string service = entity.Service;
string net = entity.Net;
string parking = entity.Parking;
string cancel = entity.Cancel;
string children = entity.Children;
string creditcard = entity.Creditcard;
string sql = "insert into Hotel(HotelName,Star,Description,CityId,"+
"Synthesis,Pets,ActivePlace,Service,Net,Parking,Cancel,Children,Creditcard)" +
"values('" + hotelName + "'," + star + ",'" + description + "'," + cityId + ",'" + synthesis + "','" +
pets+"','"+activePlace+"','"+service+"','"+net+"','"+parking+"','"+
cancel+"','"+children+"','"+creditcard+"')";
try
{
return base.ExecuteSqlNoneQuery(sql);
}
catch (Exception ex)
{
throw new Exception("插入酒店时出现错误:" + ex.Message);
}
}
//修改酒店
public bool Update(Hotel entity)
{
int id = entity.HotelId;
string hotelName = entity.HotelName;
int star = entity.Star;
string description = entity.Description;
int cityId = entity.CityId;
string synthesis = entity.Synthesis;
string pets = entity.Pets;
string activePlace = entity.ActivePlace;
string service = entity.Service;
string net = entity.Net;
string parking = entity.Parking;
string cancel = entity.Cancel;
string children = entity.Children;
string creditcard = entity.Creditcard;
string sql = "update Hotel set HotelName='" + hotelName + "',Star=" +
star + ",Description='" + description + "',CityId=" + cityId+
",Synthesis='" + synthesis + "',Pets='" + pets + "',ActivePlace='" + activePlace + "',Service='" +
service+"',Net='"+net+"',Parking='"+parking+"',Cancel='"+cancel+"',Children='"+children+"',Creditcard='"+
creditcard+"' where HotelId="+id;
try
{
return base.ExecuteSqlNoneQuery(sql);
}
catch (Exception ex)
{
throw new Exception("修改酒店时出现错误:" + ex.Message);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -