using System;
using System.Data;
using System.Collections.Generic;
using LTP.Common;
using FOUPOS.Model;
using FOUPOS.DALFactory;
using FOUPOS.IDAL;
namespace FOUPOS.BLL
{
	/// <summary>
	/// 业务逻辑类FClass 的摘要说明。
	/// </summary>
	public class FClass
	{
		private readonly IFClass dal=DataAccess.CreateFClass();
		public FClass()
		{}
		#region  成员方法
		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int CID)
		{
			return dal.Exists(CID);
		}
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string cunit)
        {
            return dal.Exists(cunit);
        }
		/// <summary>
		/// 增加一条数据
		/// </summary>
		public void Add(FOUPOS.Model.FClass model)
		{
			dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public void Update(FOUPOS.Model.FClass model)
		{
			dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public void Delete(int CID)
		{
			
			dal.Delete(CID);
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public FOUPOS.Model.FClass GetModel(int CID)
		{
			
			return dal.GetModel(CID);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中。
		/// </summary>
		public FOUPOS.Model.FClass GetModelByCache(int CID)
		{
			
			string CacheKey = "FClassModel-" + CID;
			object objModel = LTP.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(CID);
					if (objModel != null)
					{
						int ModelCache = LTP.Common.ConfigHelper.GetConfigInt("ModelCache");
						LTP.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (FOUPOS.Model.FClass)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<FOUPOS.Model.FClass> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			List<FOUPOS.Model.FClass> modelList = new List<FOUPOS.Model.FClass>();
			int rowsCount = ds.Tables[0].Rows.Count;
			if (rowsCount > 0)
			{
				FOUPOS.Model.FClass model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new FOUPOS.Model.FClass();
					if(ds.Tables[0].Rows[n]["CID"].ToString()!="")
					{
						model.CID=int.Parse(ds.Tables[0].Rows[n]["CID"].ToString());
					}
					model.CUnit=ds.Tables[0].Rows[n]["CUnit"].ToString();
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  成员方法
	}
}

