cityaccessor.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>
    /// 对City表进行操作的类
    /// </summary>
    public class CityAccessor:DataAccessor
    {
        //查询所有城市
        public DataTable QueryAll()
        {
            string sql = "select * from City";
            try
            {
                return base.Query(sql);
            }
            catch (Exception ex)
            {
                throw new Exception("查询所有城市时出现错误:"+ex.Message);
            }
        }

        //根据城市ID查询城市
        public DataTable QueryById(int id)
        {
            string sql = "select * from City where CityId="+id;
            try
            {
                return base.Query(sql);
            }
            catch (Exception ex)
            {
                throw new Exception("根据城市ID查询城市时出现错误:" + ex.Message);
            }
        }

        //根据城市名称查询城市
        public DataTable QueryByName(string cityName)
        {
            string sql = "select * from City where CityName='" + cityName + "'";
            try
            {
                return base.Query(sql);
            }
            catch (Exception ex)
            {
                throw new Exception("根据城市名称查询城市时出现错误:" + ex.Message);
            }
        }

        //插入城市
        public bool Insert(City entity)
        {
            string cityName = entity.CityName;
            string sql = "insert into City(CityName) values('" + cityName + "')";
            try
            {
                return base.ExecuteSqlNoneQuery(sql);
            }
            catch (Exception ex)
            {
                throw new Exception("插入城市时出现错误:"+ex.Message);
            }
        }

        //修改城市
        public bool Update(City entity)
        {
            int id = entity.CityId;
            string cityName = entity.CityName;
            string sql = "update City set CityName='" + cityName + "' where CityId="+id;
            try
            {
                return base.ExecuteSqlNoneQuery(sql);
            }
            catch (Exception ex)
            {
                throw new Exception("修改城市时出现错误:"+ex.Message);
            }
        }

        //根据城市ID删除城市
        public bool DeleteById(int id)
        {
            string sql = "delete City where CityId=" + id;
            try
            {
                return base.ExecuteSqlNoneQuery(sql);
            }
            catch (Exception ex)
            {
                throw new Exception("删除City表时出现错误:"+ex.Message);
            }
        }
    }
}

⌨️ 快捷键说明

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