touristtypeaccessor.cs

来自「本系统是基于三层架构和Ajax控件结合的酒店预订系统」· CS 代码 · 共 102 行

CS
102
字号
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using DBaoBookingManagement.Entity;

namespace DBaoBookingManagement.DataAccess
{
    /// <summary>
    /// 对TouristType表进行操作的类
    /// </summary>
    public class TouristTypeAccessor:DataAccessor
    {
        //根据游客类型ID查询游客类型
        public DataTable QueryById(int id)
        {
            string sql = "select * from TouristType where TypeId=" + id;
            try
            {
                return base.Query(sql);
            }
            catch (Exception ex)
            {
                throw new Exception("根据游客类型ID查询游客类型时出现错误:" + ex.Message);
            }
        }

        //根据游客类型名称查询游客类型
        public DataTable QueryByName(string typeName)
        {
            string sql = "select * from TouristType where TypeName='" + typeName + "'";
            try
            {
                return base.Query(sql);
            }
            catch (Exception ex)
            {
                throw new Exception("根据游客类型名称查询游客类型时出现错误:" + ex.Message);
            }
        }

        //查询所有游客类型
        public DataTable QueryAll()
        {
            string sql = "select * from TouristType";
            try
            {
                return base.Query(sql);
            }
            catch (Exception ex)
            {
                throw new Exception("查询所有游客类型时出现错误:" + ex.Message);
            }
        }

        //插入游客类型
        public bool Insert(TouristType entity)
        {
            string typeName = entity.TypeName;
            string sql = "insert into TouristType(TypeName) values('" + typeName + "')";
            try
            {
                return base.ExecuteSqlNoneQuery(sql);
            }
            catch (Exception ex)
            {
                throw new Exception("插入游客类型时出现错误:" + ex.Message);
            }
        }

        //根据游客类型ID删除游客类型
        public bool DeleteById(int id)
        {
            string sql = "delete TouristType where TypeId=" + id;
            try
            {
                return base.ExecuteSqlNoneQuery(sql);
            }
            catch (Exception ex)
            {
                throw new Exception("根据游客类型ID删除游客类型时出现错误:" + ex.Message);
            }
        }

        //修改游客类型
        public bool Update(TouristType entity)
        {
            int id = entity.TypeId;
            string typeName = entity.TypeName;
            string sql = "update TouristType set TypeName='" + typeName + "' where TypeId=" + id;
            try
            {
                return base.ExecuteSqlNoneQuery(sql);
            }
            catch (Exception ex)
            {
                throw new Exception("修改游客类型时出现错误:" + ex.Message);
            }
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?