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

            return(new DataAccess.Model.GROUPAREA
            {
                Id = model.Id,
                AREA_ID = model.AREA_ID,
                AREA_NAME = model.AREA_NAME,
                AREA_ADD = model.AREA_ADD,
                AREA_TEL = model.AREA_TEL,
                AREA_EMAIL = model.AREA_EMAIL,
                AREA_CONTECT = model.AREA_CONTECT,
                AREA_MEMO = model.AREA_MEMO,
                AREA_STATUS = model.AREA_STATUS,
                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,
                STATUS = model.STATUS,
            });
        }
Exemplo n.º 2
0
        /// <summary>
        /// 添加与编辑GROUPAREA记录
        /// </summary>
        /// <param name="page">当前页面指针</param>
        /// <param name="model">GROUPAREA表实体</param>
        /// <param name="content">更新说明</param>
        /// <param name="isCache">是否更新缓存</param>
        /// <param name="isAddUseLog">是否添加用户操作日志</param>
        public void Save(Page page, GROUPAREA 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 ? "添加" : "编辑") + "GROUPAREA记录成功,ID为【" + model.Id + "】";
                    }

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

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

                if (model == null)
                {
                    //从数据库中读取
                    var tem = GROUPAREA.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缓存中获取GROUPAREA表记录时出现异常", e);

                return(null);
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// 获取指定Id记录
 /// </summary>
 /// <param name="id">主键Id</param>
 /// <param name="isCache">是否从缓存中读取</param>
 /// <returns>DataAccess.Model.GROUPAREA</returns>
 public DataAccess.Model.GROUPAREA 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 = GROUPAREA.SingleOrDefault(x => x.Id == id);
         if (model == null)
         {
             return(null);
         }
         else
         {
             //对查询出来的实体进行转换
             return(Transform(model));
         }
     }
 }
Exemplo n.º 5
0
        /// <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(GROUPAREA.Exists(x => x.Id == id));
        }
        /// <summary>
        /// 列表按键绑定——修改列表控件属性
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Grid1_PreRowDataBound(object sender, FineUI.GridPreRowEventArgs e)
        {
            //绑定是否显示状态列
            int o = e.RowIndex;

            DataRowView row = e.DataItem as DataRowView;


            string AREA_ID = ((System.Data.DataRowView)(row)).Row.Table.Rows[e.RowIndex][GROUPAREATable.AREA_ID].ToString();
            var    model   = new GROUPAREA(x => x.AREA_ID == AREA_ID);

            if (model != null)
            {
                // ((System.Data.DataRowView)(gr.DataItem)).Row[e.RowIndex]
                var tf = Grid1.FindColumn("Area_Id") as FineUI.LinkButtonField;
                tf.Text = model.AREA_NAME;
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// 获取数据表中的某个值——从数据库中查询,如果使用了缓存,删除成功后会清空本表的所有缓存记录,然后重新加载进缓存
        /// </summary>
        /// <param name="page">当前页面指针</param>
        /// <param name="expression">条件语句</param>
        /// <param name="isAddUseLog">是否添加用户操作日志</param>
        public void Delete(Page page, Expression <Func <GROUPAREA, bool> > expression, bool isAddUseLog = true)
        {
            //执行删除
            GROUPAREA.Delete(expression);

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

            if (isAddUseLog)
            {
                //添加用户操作记录
                UseLogBll.GetInstence().Save(page, "{0}删除了GROUPAREA表记录!");
            }
        }
Exemplo n.º 8
0
        /////
        /////取消
        //public override void Cancel()
        //{


        //}

        #region 保存
        /// <summary>
        /// 数据保存
        /// </summary>
        /// <returns></returns>
        public override string Save()
        {
            string result = string.Empty;
            int    id     = ConvertHelper.Cint0(hidId.Text);

            try
            {
                #region 数据验证

                if (string.IsNullOrEmpty(txtAREA_NAME.Text.Trim()))
                {
                    return(txtAREA_NAME.Label + "不能为空!");
                }

                if (string.IsNullOrEmpty(txtAREA_ID.Text.Trim()))
                {
                    return(txtAREA_ID.Label + "不能为空!");
                }

                string area_id = txtAREA_ID.Text.Trim();
                Expression <Func <DataAccess.Model.GROUPAREA, bool> > list = null;
                list = x => x.AREA_ID == area_id;

                if (GROUPAREABll.GetInstence().Exist(list))
                {
                    return(txtAREA_ID.Label + "区域ID不能重复!");
                }

                //var sUrl = StringHelper.Left(txtUrl.Text, 400);
                //if (BranchBll.GetInstence().Exist(x => x.Url == sUrl && x.Id != id))
                //{
                //    return txtUrl.Label + "已存在!请重新输入!";
                //}

                #endregion

                int userId = OnlineUsersBll.GetInstence().GetManagerId();

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

                model.AREA_ID      = txtAREA_ID.Text;
                model.AREA_NAME    = txtAREA_NAME.Text;
                model.AREA_ADD     = txtAREA_ADD.Text;
                model.AREA_TEL     = txtAREA_TEL.Text;
                model.AREA_EMAIL   = txtAREA_EMAIL.Text;
                model.AREA_CONTECT = txtAREA_CONTECT.Text;
                model.AREA_MEMO    = txtAREA_MEMO.Text;
                model.AREA_STATUS  = ConvertHelper.StringToByte(ddlAREA_STATUS.SelectedValue);
                model.CRT_DATETIME = DateTime.Now.ToString();
                model.CRT_USER_ID  = userId.ToString();
                model.MOD_DATETIME = DateTime.Now;
                model.MOD_USER_ID  = userId.ToString();
                model.LAST_UPDATE  = DateTime.Now;
                model.STATUS       = 0;

                #endregion

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

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

            return(result);
        }
Exemplo n.º 9
0
        /// <summary>
        /// 从IIS缓存中获取GROUPAREA表记录
        /// </summary>
        /// <param name="isCache">是否从缓存中读取</param>
        public IList <DataAccess.Model.GROUPAREA> 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.GROUPAREA>)obj);
                    }
                }
                else
                {
                    //定义临时实体集
                    IList <DataAccess.Model.GROUPAREA> list = null;

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

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

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

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

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

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

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

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

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

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

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

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

                case "CRT_DATETIME":
                    model      = list.SingleOrDefault(x => x.CRT_DATETIME == (string)value);
                    expression = x => x.CRT_DATETIME == (string)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 "STATUS":
                    model      = list.SingleOrDefault(x => x.STATUS == (byte)value);
                    expression = x => x.STATUS == (byte)value;
                    break;

                default:
                    return(null);
                }

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

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

                return(null);
            }
        }