/*
'' ============================================================================================
'' 项目名称：风越项目范例ASPX普通三层结构
'' 项目版本：V1.0
'' 项目描述：风越项目范例，用于建立ASPX普通三层结构
'' 文件名称：BLL_CITY.cs
'' 文件描述：业务逻辑层 CITY （城市）
'' 公司名称：中极网盛
'' 开发人员：刘怒
'' 创建日期：2008-12-25 20:23:50
'' 修订日期：2009-01-14 12:12:19
'' 版权信息：Copyright (C) 2008

'' 项目升级时需读取以下生成工具的版权信息
'' 生成工具：风越代码生成器 [FireCode Creator]
'' 当前版本：通用版 V1.5
'' 官方网站：http://www.sino8848.com
'' ============================================================================================
*/

using System;
using System.Data;
using System.Collections.Generic;
using Fyp_3TierCommon.Model;
using Fyp_3TierCommon.DAL;
using FypSystem.Common;

namespace Fyp_3TierCommon.BLL
{
    /// <summary>
    ///  CITY （城市） 业务逻辑层
    /// </summary>
    public class BLL_CITY
    {
        private readonly Fyp_3TierCommon.DAL.DAL_CITY dal_CITY = new Fyp_3TierCommon.DAL.DAL_CITY();
        public BLL_CITY()
        {
        }

        #region 记录是否存在
        /// <summary>
        /// 记录是否存在
        /// </summary>
        /// <param name="CITY_ID">CITY_ID</param>
        /// <returns></returns>
        public bool Exists(int? CITY_ID)
        {
            return dal_CITY.Exists(CITY_ID);
        }
        #endregion

        #region 添加数据
        /// <summary>
        /// 添加数据
        /// </summary>
        /// <param name="model">CITY实体对象</param>
        public void Add(Fyp_3TierCommon.Model.Model_CITY model)
        {
            dal_CITY.Add(model);
        }
        #endregion

        #region 更新数据
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="model">CITY实体对象</param>
        public void Update(Fyp_3TierCommon.Model.Model_CITY model)
        {
            dal_CITY.Update(model);
        }
        #endregion

        #region 删除
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="CITY_ID">CITY_ID</param>
        public void Delete(int? CITY_ID)
        {
            dal_CITY.Delete(CITY_ID);
        }
        #endregion

        #region 获取对象实体
        /// <summary>
        /// 获取对象实体
        /// </summary>
        /// <param name="CITY_ID">CITY_ID</param>
        /// <returns></returns>
        public Model_CITY GetModel(int? CITY_ID)
        {
            return dal_CITY.GetModel(CITY_ID);
        }
        #endregion

        #region 获取数据列表 DataSet
        /// <summary>
        /// 获取数据列表 DataSet
        /// </summary>
        /// <param name="strWhere">指定查询条件的SQL语句，不包含where</param>
        /// <returns></returns>
        public DataSet GetDataSet(string strWhere)
        {
            return dal_CITY.GetDataSet(strWhere);
        }

		/// <summary>
		/// 获取全部数据列表 DataSet
		/// </summary>
		public DataSet GetDataSet()
		{
			return GetDataSet("");
		}
        #endregion

        #region 获取数据列表 DataTable
        /// <summary>
        /// 获取数据列表 DataTable
        /// </summary>
        /// <param name="strWhere">指定查询条件的SQL语句，不包含where</param>
        /// <returns></returns>
        public DataTable GetDataTable(string strWhere)
        {
            return dal_CITY.GetDataTable(strWhere);
        }

        /// <summary>
        /// 获取数据列表 DataTable
        /// </summary>
        /// <param name="strWhere">指定查询条件的SQL语句，不包含where</param>
        /// <param name="strOrder">排序字段，如id desc，不包含order by</param>
        /// <returns></returns>
        public DataTable GetDataTable(string strWhere, string strOrder)
        {
            return dal_CITY.GetDataTable(strWhere, strOrder);
        }

		/// <summary>
		/// 获取全部数据列表 DataTable
		/// </summary>
		public DataTable GetDataTable()
		{
			return GetDataTable("");
		}
        #endregion

        #region 获取数据列表 Model List
        /// <summary>
        /// 获取数据列表 Model List
        /// </summary>
        /// <param name="strWhere">查询条件的SQL语句，不包含where</param>
        /// <returns></returns>
        public List<Fyp_3TierCommon.Model.Model_CITY> GetModelList(string strWhere)
        {
            DataSet ds = dal_CITY.GetDataSet(strWhere);
            List<Fyp_3TierCommon.Model.Model_CITY> modelList = new List<Fyp_3TierCommon.Model.Model_CITY>();
            int iRowsCount = ds.Tables[0].Rows.Count;
            if (iRowsCount > 0)
            {
                Fyp_3TierCommon.Model.Model_CITY model;
                for (int i = 0; i < iRowsCount; i++)
                {
                    model = new Fyp_3TierCommon.Model.Model_CITY();
                    DataRow dr = ds.Tables[0].Rows[i];

                    
                    

                     
                    if (dr["CITY_ID"].ToString().Length > 0)
                    {
                        model.CITY_ID = int.Parse(dr["CITY_ID"].ToString());
                    }
                    

                    
                    
                    

                     
                    if (dr["PROVINCE_ID"].ToString().Length > 0)
                    {
                        model.PROVINCE_ID = int.Parse(dr["PROVINCE_ID"].ToString());
                    }
                    

                    
                    
                     
                    model.CITY_CN = dr["CITY_CN"].ToString();
                    

                    

                    
                    
                     
                    model.CITY_EN = dr["CITY_EN"].ToString();
                    

                    

                    
                    
                    

                     
                    if (dr["CITY_AREA_CODE"].ToString().Length > 0)
                    {
                        model.CITY_AREA_CODE = int.Parse(dr["CITY_AREA_CODE"].ToString());
                    }
                    

                    
                    
                    modelList.Add(model);
                }
            }
            return modelList;
        }
        #endregion
    }
}