department.cs

来自「详细讲述了数据库编程」· CS 代码 · 共 102 行

CS
102
字号
using System;
using System.Data;
using System.Collections;

using MyOA.DataAccessLayer;
using MyOA.DataAccessHelper;

namespace MyOA.BusinessLogicLayer
{
	/// <summary>
	/// Department 的摘要说明。
	/// </summary>
	public class Department
	{
		#region 私有成员

		private int _departmentId;			//部门ID
		private string _departmentName;		//部门名

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

		#endregion 私有成员

		#region 属性
		
		public int DepartmentID
		{
			set
			{
				this._departmentId=value;
			}
			get
			{
				return this._departmentId;
			}
		}
		public string DepartmentName
		{
			set
			{
				this._departmentName=value;
			}
			get
			{
				return this._departmentName;
			}
		}
		public bool Exist
		{
			get
			{
				return this._exist;
			}
		}

		#endregion 属性

		#region 方法
		
		/// <summary>
		/// 根据参数departmentId,获取部门详细信息
		/// </summary>
		/// <param name="topicID">部门ID</param>
		public void LoadData(int departmentId)
		{
			Database db=new Database();		//实例化一个Database类

			string sql="";
			sql="Select * from [Department] where DepartmentId = "+ departmentId ;

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

			//根据查询得到的数据,对成员赋值
			if(dr!=null)
			{
				this._departmentId=GetSafeData.ValidateDataRow_N(dr,"DepartmentId");
				this._departmentName=GetSafeData.ValidateDataRow_S(dr,"DepartmentName");
				
				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 [Department]"+where;
			Database db = new Database();
			return db.GetDataTable(sql);
		}
		#endregion 方法
	}
}

⌨️ 快捷键说明

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