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>
    /// 业务逻辑类FAccount 的摘要说明。
    /// </summary>
    public class FAccount
    {
        private readonly IFAccount dal = DataAccess.CreateFAccount();
        public FAccount()
        { }
        #region  成员方法
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int ID)
        {
            return dal.Exists(ID);
        }
        public int GetMaxID()
        {
            return dal.GetMaxID();
        }
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(FOUPOS.Model.FAccount model)
        {
            dal.Add(model);
        }

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

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

            dal.Delete(ID);
        }

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

            return dal.GetModel(ID);
        }

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

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

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<FOUPOS.Model.FAccount> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            List<FOUPOS.Model.FAccount> modelList = new List<FOUPOS.Model.FAccount>();
            int rowsCount = ds.Tables[0].Rows.Count;
            if (rowsCount > 0)
            {
                FOUPOS.Model.FAccount model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new FOUPOS.Model.FAccount();
                    model.AccountNum = ds.Tables[0].Rows[n]["AccountNum"].ToString();
                    if (ds.Tables[0].Rows[n]["GetMoney"].ToString() != "")
                    {
                        model.GetMoney = decimal.Parse(ds.Tables[0].Rows[n]["GetMoney"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["ID"].ToString() != "")
                    {
                        model.ID = int.Parse(ds.Tables[0].Rows[n]["ID"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["JoinTime"].ToString() != "")
                    {
                        model.JoinTime = DateTime.Parse(ds.Tables[0].Rows[n]["JoinTime"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["NoGetMoney"].ToString() != "")
                    {
                        model.NoGetMoney = decimal.Parse(ds.Tables[0].Rows[n]["NoGetMoney"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["SumMoney"].ToString() != "")
                    {
                        model.SumMoney = decimal.Parse(ds.Tables[0].Rows[n]["SumMoney"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["UID"].ToString() != "")
                    {
                        model.UID = int.Parse(ds.Tables[0].Rows[n]["UID"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

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

        public DataSet GetDetailList(string strWhere)
        {
            return dal.GetDetailList(strWhere);
        }

        #endregion  成员方法
    }
}

