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

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

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

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

            dal.Delete(UID);
        }

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

            return dal.GetModel(UID);
        }
        /// <summary>
        /// 登录验证
        /// </summary>
        public FOUPOS.Model.FUser GetModel(string uname, string upwd)
        {

            return dal.GetModel(uname, upwd);
        }
        /// <summary>
        /// 得到一个对象实体，从缓存中。
        /// </summary>
        public FOUPOS.Model.FUser GetModelByCache(int UID)
        {

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

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<FOUPOS.Model.FUser> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            List<FOUPOS.Model.FUser> modelList = new List<FOUPOS.Model.FUser>();
            int rowsCount = ds.Tables[0].Rows.Count;
            if (rowsCount > 0)
            {
                FOUPOS.Model.FUser model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new FOUPOS.Model.FUser();
                    if (ds.Tables[0].Rows[n]["UID"].ToString() != "")
                    {
                        model.UID = int.Parse(ds.Tables[0].Rows[n]["UID"].ToString());
                    }
                    model.UName = ds.Tables[0].Rows[n]["UName"].ToString();
                    if (ds.Tables[0].Rows[n]["URight"].ToString() != "")
                    {
                        model.URight = int.Parse(ds.Tables[0].Rows[n]["URight"].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  成员方法
    }
}

