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>
    /// 业务逻辑类FDetail 的摘要说明。
    /// </summary>
    public class FDetail
    {
        private readonly IFDetail dal = DataAccess.CreateFDetail();
        public FDetail()
        { }
        #region  成员方法
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int DID)
        {
            return dal.Exists(DID);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(FOUPOS.Model.FDetail model)
        {
            dal.Add(model);
        }

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

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(int DID)
        {

            dal.Delete(DID);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public FOUPOS.Model.FDetail GetModel(int DID)
        {

            return dal.GetModel(DID);
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中。
        /// </summary>
        public FOUPOS.Model.FDetail GetModelByCache(int DID)
        {

            string CacheKey = "FDetailModel-" + DID;
            object objModel = LTP.Common.DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel(DID);
                    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.FDetail)objModel;
        }

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

                    model.GNum = ds.Tables[0].Rows[n]["GNum"].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  成员方法
    }
}

