/// <summary>
        /// 添加与编辑TAKEIN00记录
        /// </summary>
        /// <param name="page">当前页面指针</param>
        /// <param name="model">TAKEIN00表实体</param>
        /// <param name="content">更新说明</param>
        /// <param name="isCache">是否更新缓存</param>
        /// <param name="isAddUseLog">是否添加用户操作日志</param>
        public void Save(Page page, TAKEIN00 model, string content = null, bool isCache = true, bool isAddUseLog = true)
        {
            try {
                //保存
                model.Save();

                //判断是否启用缓存
                if (CommonBll.IsUseCache() && isCache)
                {
                    SetModelForCache(model);
                }

                if (isAddUseLog)
                {
                    if (string.IsNullOrEmpty(content))
                    {
                        content = "{0}" + (model.Id == 0 ? "添加" : "编辑") + "TAKEIN00记录成功,ID为【" + model.Id + "】";
                    }

                    //添加用户访问记录
                    UseLogBll.GetInstence().Save(page, content);
                }
            }
            catch (Exception e) {
                var result = "执行TAKEIN00Bll.Save()函数出错!";

                //出现异常,保存出错日志信息
                CommonBll.WriteLog(result, e);
            }
        }
        /// <summary>
        /// 从IIS缓存中获取指定Id记录
        /// </summary>
        /// <param name="id">主键Id</param>
        /// <returns>DataAccess.Model.TAKEIN00</returns>
        public DataAccess.Model.TAKEIN00 GetModelForCache(long id)
        {
            try
            {
                //从缓存中读取指定Id记录
                var model = GetModelForCache(x => x.Id == id);

                if (model == null)
                {
                    //从数据库中读取
                    var tem = TAKEIN00.SingleOrDefault(x => x.Id == id);
                    if (tem == null)
                    {
                        return(null);
                    }
                    else
                    {
                        //对查询出来的实体进行转换
                        model = Transform(tem);
                        return(model);
                    }
                }
                else
                {
                    return(model);
                }
            }
            catch (Exception e)
            {
                //记录日志
                CommonBll.WriteLog("从IIS缓存中获取TAKEIN00表记录时出现异常", e);

                return(null);
            }
        }
        /// <summary>
        /// 将TAKEIN00记录实体(SubSonic实体)转换为普通的实体(DataAccess.Model.TAKEIN00)
        /// </summary>
        /// <param name="model">SubSonic插件生成的实体</param>
        /// <returns>DataAccess.Model.TAKEIN00</returns>
        public DataAccess.Model.TAKEIN00 Transform(TAKEIN00 model)
        {
            if (model == null)
            {
                return(null);
            }

            return(new DataAccess.Model.TAKEIN00
            {
                Id = model.Id,
                SHOP_ID = model.SHOP_ID,
                TAKEIN_ID = model.TAKEIN_ID,
                STATUS = model.STATUS,
                INPUT_DATE = model.INPUT_DATE,
                STOCK_ID = model.STOCK_ID,
                USER_ID = model.USER_ID,
                APP_USER = model.APP_USER,
                APP_DATETIME = model.APP_DATETIME,
                RELATE_ID = model.RELATE_ID,
                Memo = model.Memo,
                CRT_DATETIME = model.CRT_DATETIME,
                CRT_USER_ID = model.CRT_USER_ID,
                MOD_DATETIME = model.MOD_DATETIME,
                MOD_USER_ID = model.MOD_USER_ID,
                LAST_UPDATE = model.LAST_UPDATE,
                Trans_STATUS = model.Trans_STATUS,
                TAKEIN_TYPE = model.TAKEIN_TYPE,
            });
        }
 /// <summary>
 /// 获取指定Id记录
 /// </summary>
 /// <param name="id">主键Id</param>
 /// <param name="isCache">是否从缓存中读取</param>
 /// <returns>DataAccess.Model.TAKEIN00</returns>
 public DataAccess.Model.TAKEIN00 GetModel(long id, bool isCache = true)
 {
     //判断是否使用缓存
     if (CommonBll.IsUseCache() && isCache)
     {
         //从缓存中获取List
         var list = GetList();
         if (list == null)
         {
             return(null);
         }
         else
         {
             //在List查询指定主键Id的记录
             return(list.SingleOrDefault(x => x.Id == id));
         }
     }
     else
     {
         //从数据库中直接读取
         var model = TAKEIN00.SingleOrDefault(x => x.Id == id);
         if (model == null)
         {
             return(null);
         }
         else
         {
             //对查询出来的实体进行转换
             return(Transform(model));
         }
     }
 }
        /// <summary>
        /// 判断指定主键Id的记录是否存在——在IIS缓存或数据库中查找
        /// </summary>
        /// <param name="id">主键Id</param>
        /// <returns></returns>
        public bool Exist(int id)
        {
            if (id <= 0)
            {
                return(false);
            }

            //判断是否启用缓存
            if (CommonBll.IsUseCache())
            {
                return(Exist(x => x.Id == id));
            }

            //从数据库中查找
            return(TAKEIN00.Exists(x => x.Id == id));
        }
        /// <summary>
        /// 获取数据表中的某个值——从数据库中查询,如果使用了缓存,删除成功后会清空本表的所有缓存记录,然后重新加载进缓存
        /// </summary>
        /// <param name="page">当前页面指针</param>
        /// <param name="expression">条件语句</param>
        /// <param name="isAddUseLog">是否添加用户操作日志</param>
        public void Delete(Page page, Expression <Func <TAKEIN00, bool> > expression, bool isAddUseLog = true)
        {
            //执行删除
            TAKEIN00.Delete(expression);

            //判断是否启用缓存
            if (CommonBll.IsUseCache())
            {
                //清空当前表所有缓存记录
                DelAllCache();
                //重新载入缓存
                GetList();
            }

            if (isAddUseLog)
            {
                //添加用户操作记录
                UseLogBll.GetInstence().Save(page, "{0}删除了TAKEIN00表记录!");
            }
        }
        /// <summary>
        /// 从IIS缓存中获取TAKEIN00表记录
        /// </summary>
        /// <param name="isCache">是否从缓存中读取</param>
        public IList <DataAccess.Model.TAKEIN00> GetList(bool isCache = true)
        {
            try
            {
                //判断是否使用缓存
                if (CommonBll.IsUseCache() && isCache)
                {
                    //检查指定缓存是否过期——缓存当天有效,第二天自动清空
                    if (CommonBll.CheckCacheIsExpired(const_CacheKey_Date))
                    {
                        //删除缓存
                        DelAllCache();
                    }

                    //从缓存中获取DataTable
                    var obj = CacheHelper.GetCache(const_CacheKey);
                    //如果缓存为null,则查询数据库
                    if (obj == null)
                    {
                        var list = GetList(false);

                        //将查询出来的数据存储到缓存中
                        CacheHelper.SetCache(const_CacheKey, list);
                        //存储当前时间
                        CacheHelper.SetCache(const_CacheKey_Date, DateTime.Now);

                        return(list);
                    }
                    //缓存中存在数据,则直接返回
                    else
                    {
                        return((IList <DataAccess.Model.TAKEIN00>)obj);
                    }
                }
                else
                {
                    //定义临时实体集
                    IList <DataAccess.Model.TAKEIN00> list = null;

                    //获取全表缓存加载条件表达式
                    var exp = GetExpression <TAKEIN00>();
                    //如果条件为空,则查询全表所有记录
                    if (exp == null)
                    {
                        //从数据库中获取所有记录
                        var all = TAKEIN00.All();
                        list = all == null ? null : Transform(all.ToList());
                    }
                    else
                    {
                        //从数据库中查询出指定条件的记录,并转换为指定实体集
                        var all = TAKEIN00.Find(exp);
                        list = all == null ? null : Transform(all);
                    }

                    return(list);
                }
            }
            catch (Exception e)
            {
                //记录日志
                CommonBll.WriteLog("从IIS缓存中获取TAKEIN00表记录时出现异常", e);
            }

            return(null);
        }
 /// <summary>
 /// 更新IIS缓存中指定Id记录
 /// </summary>
 /// <param name="model">记录实体</param>
 public void SetModelForCache(TAKEIN00 model)
 {
     SetModelForCache(Transform(model));
 }
        /// <summary>
        /// 从IIS缓存中获取指定Id记录
        /// </summary>
        /// <param name="conditionColName">条件列名</param>
        /// <param name="value">条件值</param>
        /// <returns>DataAccess.Model.TAKEIN00</returns>
        public DataAccess.Model.TAKEIN00 GetModelForCache(string conditionColName, object value)
        {
            try
            {
                //从缓存中获取List
                var list = GetList();
                DataAccess.Model.TAKEIN00           model      = null;
                Expression <Func <TAKEIN00, bool> > expression = null;

                //返回指定条件的实体
                switch (conditionColName)
                {
                case "Id":
                    model      = list.SingleOrDefault(x => x.Id == (int)value);
                    expression = x => x.Id == (int)value;
                    break;

                case "SHOP_ID":
                    model      = list.SingleOrDefault(x => x.SHOP_ID == (string)value);
                    expression = x => x.SHOP_ID == (string)value;
                    break;

                case "TAKEIN_ID":
                    model      = list.SingleOrDefault(x => x.TAKEIN_ID == (string)value);
                    expression = x => x.TAKEIN_ID == (string)value;
                    break;

                case "STATUS":
                    model      = list.SingleOrDefault(x => x.STATUS == (int)value);
                    expression = x => x.STATUS == (int)value;
                    break;

                case "INPUT_DATE":
                    model      = list.SingleOrDefault(x => x.INPUT_DATE == (DateTime)value);
                    expression = x => x.INPUT_DATE == (DateTime)value;
                    break;

                case "STOCK_ID":
                    model      = list.SingleOrDefault(x => x.STOCK_ID == (string)value);
                    expression = x => x.STOCK_ID == (string)value;
                    break;

                case "USER_ID":
                    model      = list.SingleOrDefault(x => x.USER_ID == (string)value);
                    expression = x => x.USER_ID == (string)value;
                    break;

                case "APP_USER":
                    model      = list.SingleOrDefault(x => x.APP_USER == (string)value);
                    expression = x => x.APP_USER == (string)value;
                    break;

                case "APP_DATETIME":
                    model      = list.SingleOrDefault(x => x.APP_DATETIME == (DateTime)value);
                    expression = x => x.APP_DATETIME == (DateTime)value;
                    break;

                case "RELATE_ID":
                    model      = list.SingleOrDefault(x => x.RELATE_ID == (string)value);
                    expression = x => x.RELATE_ID == (string)value;
                    break;

                case "Memo":
                    model      = list.SingleOrDefault(x => x.Memo == (byte)value);
                    expression = x => x.Memo == (byte)value;
                    break;

                case "CRT_DATETIME":
                    model      = list.SingleOrDefault(x => x.CRT_DATETIME == (DateTime)value);
                    expression = x => x.CRT_DATETIME == (DateTime)value;
                    break;

                case "CRT_USER_ID":
                    model      = list.SingleOrDefault(x => x.CRT_USER_ID == (string)value);
                    expression = x => x.CRT_USER_ID == (string)value;
                    break;

                case "MOD_DATETIME":
                    model      = list.SingleOrDefault(x => x.MOD_DATETIME == (DateTime)value);
                    expression = x => x.MOD_DATETIME == (DateTime)value;
                    break;

                case "MOD_USER_ID":
                    model      = list.SingleOrDefault(x => x.MOD_USER_ID == (string)value);
                    expression = x => x.MOD_USER_ID == (string)value;
                    break;

                case "LAST_UPDATE":
                    model      = list.SingleOrDefault(x => x.LAST_UPDATE == (DateTime)value);
                    expression = x => x.LAST_UPDATE == (DateTime)value;
                    break;

                case "Trans_STATUS":
                    model      = list.SingleOrDefault(x => x.Trans_STATUS == (byte)value);
                    expression = x => x.Trans_STATUS == (byte)value;
                    break;

                case "TAKEIN_TYPE":
                    model      = list.SingleOrDefault(x => x.TAKEIN_TYPE == (byte)value);
                    expression = x => x.TAKEIN_TYPE == (byte)value;
                    break;

                default:
                    return(null);
                }

                if (model == null)
                {
                    //从数据库中读取
                    var tem = TAKEIN00.SingleOrDefault(expression);
                    if (tem == null)
                    {
                        return(null);
                    }
                    else
                    {
                        //对查询出来的实体进行转换
                        model = Transform(tem);

                        return(model);
                    }
                }
                else
                {
                    return(model);
                }
            }
            catch (Exception e)
            {
                //记录日志
                CommonBll.WriteLog("从IIS缓存中获取TAKEIN00表记录时出现异常", e);

                return(null);
            }
        }
示例#10
0
        /// <summary>
        /// 数据保存
        /// </summary>
        /// <returns></returns>
        public override string Save()
        {
            string result = string.Empty;
            int    id     = ConvertHelper.Cint0(hidId.Text);

            try
            {
                #region 数据验证

                if (string.IsNullOrEmpty(txtSHOP_ID.Text.Trim()))
                {
                    return(txtSHOP_ID.Label + "不能为空!");
                }
                //var sName = StringHelper.Left(txtName.Text, 50);
                //if (BranchBll.GetInstence().Exist(x => x.Name == sName && x.Id != id))
                //{
                //    return txtName.Label + "已存在!请重新输入!";
                //}
                //if (string.IsNullOrEmpty(txtId.Text.Trim()))
                //{
                //    return txtId.Label + "不能为空!";
                //}
                //var sUrl = StringHelper.Left(txtUrl.Text, 400);
                //if (BranchBll.GetInstence().Exist(x => x.Url == sUrl && x.Id != id))
                //{
                //    return txtUrl.Label + "已存在!请重新输入!";
                //}

                #endregion

                #region 赋值
                //读取资料
                var model = new TAKEIN00(x => x.Id == id);

                model.SHOP_ID      = txtSHOP_ID.Text;                                //分店编号
                model.TAKEIN_ID    = txtTAKEIN_ID.Text;                              //计划单号
                model.STATUS       = ConvertHelper.Cint0(txtSTATUS.Text.ToString()); //单据状态
                model.INPUT_DATE   = DateTime.Now;                                   // ConvertHelper.StringToDatetime(txtINPUT_DATE.Text.ToString()); //单据日期
                model.STOCK_ID     = txtSTOCK_ID.Text.ToString();
                model.USER_ID      = txtUSER_ID.Text;                                //制单人
                model.APP_USER     = txtAPP_USER.Text;                               //审核人
                model.APP_DATETIME = DateTime.Now;                                   //ConvertHelper.StringToDatetime(txtAPP_DATETIME.Text.ToString());//审核时间

                model.RELATE_ID = txtRELATE_ID.Text;                                 //关联单号

                model.Memo = ConvertHelper.StringToByte(txtMemo.Text.ToString());    //备注

                // txtLOCKED.Text = model.LOCKED.ToString();//月结锁定
                model.CRT_DATETIME = DateTime.Now;                                                //ConvertHelper.StringToDatetime(txtCRT_DATETIME.Text.ToString());//建档日期
                model.CRT_USER_ID  = txtCRT_USER_ID.Text;                                         //建档人员
                model.MOD_USER_ID  = txtMOD_USER_ID.Text;                                         //修改日期
                model.MOD_DATETIME = DateTime.Now;                                                //ConvertHelper.StringToDatetime(txtMOD_DATETIME.Text.ToString());//修改人员
                model.LAST_UPDATE  = DateTime.Now;                                                //ConvertHelper.StringToDatetime(txtLAST_UPDATE.Text.ToString());//最后异动时间
                model.Trans_STATUS = ConvertHelper.StringToByte(txtTrans_STATUS.Text.ToString()); //传输状态

                #endregion

                //----------------------------------------------------------
                //存储到数据库
                TAKEIN00Bll.GetInstence().Save(this, model);
            }
            catch (Exception e)
            {
                result = "保存失败!";

                //出现异常,保存出错日志信息
                CommonBll.WriteLog(result, e);
            }

            return(result);
        }