⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 city.cs

📁 详细讲述了数据库编程
💻 CS
字号:
using System;
using System.Data;
using System.Collections;

using HRManager.DataAccessLayer;
using HRManager.DataAccessHelper;

namespace HRManager.BusinessLogicLayer
{
	/// <summary>
	/// 职位城市类
	/// </summary>
	public class City
	{
		#region 私有成员

		private int _cityId;			//城市ID
		private string _cityName;		//城市名

		private bool _exist;				//是否存在标志

		#endregion 私有成员

		#region 属性
		
		public int CityID
		{
			set
			{
				this._cityId=value;
			}
			get
			{
				return this._cityId;
			}
		}
		public string CityName
		{
			set
			{
				this._cityName=value;
			}
			get
			{
				return this._cityName;
			}
		}
		public bool Exist
		{
			get
			{
				return this._exist;
			}
		}

		#endregion 属性

		#region 方法

        /// <summary>
        /// 根据参数cityId,获取城市详细信息
        /// </summary>
        /// <param name="cityId">城市ID</param>
        public void LoadData(int cityId)
        {
            Database db = new Database();		//实例化一个Database类

            string sql = "";
            sql = "Select * from [City] where cityId = " + cityId;

            DataRow dr = db.GetDataRow(sql);	//利用Database类的GetDataRow方法查询数据

            //根据查询得到的数据,对成员赋值
            if (dr != null)
            {
                this._cityId = GetSafeData.ValidateDataRow_N(dr, "CityId");
                this._cityName = GetSafeData.ValidateDataRow_S(dr, "CityName");

                this._exist = true;
            }
            else
            {
                this._exist = false;
            }
        }
		
		/// <summary>
		/// 根据查询条件哈希表,查询数据
		/// </summary>
		/// <param name="queryItems">查询条件哈希表</param>
		/// <returns>查询结果数据DataTable</returns>
		public static DataTable Query(Hashtable queryItems)
		{
			string where=SqlStringConstructor.GetConditionClause(queryItems);
			string sql="Select * From [City]"+where;
			Database db = new Database();
			return db.GetDataTable(sql);
		}

		#endregion 方法
	}
}

⌨️ 快捷键说明

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