Пример #1
0
        /// <summary>
        /// 添加与编辑UseLog记录
        /// </summary>
        /// <param name="page">当前页面指针</param>
        /// <param name="model">UseLog表实体</param>
        /// <param name="content">更新说明</param>
        /// <param name="isCache">是否更新缓存</param>
        /// <param name="isAddUseLog">是否添加用户操作日志</param>
        public void Save(Page page, UseLog 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 ? "添加" : "编辑") + "UseLog记录成功,ID为【" + model.Id + "】";
                    }

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

                //出现异常,保存出错日志信息
                CommonBll.WriteLog(result, e);
            }
        }
Пример #2
0
        /// <summary>
        /// 添加用户操作日志
        /// </summary>
        /// <param name="page">页面指针</param>
        /// <param name="useLogOccurrence">用户操作内容备注,{0}=用户名称,{1}=当前页面名称</param>
        public void Save(Page page, string useLogOccurrence)
        {
            try
            {
                //创建用户操作日志对象
                var uselog = new UseLog();
                //记录登录时间
                uselog.AddDate = DateTime.Now;
                //获取用户在线实体
                var model = OnlineUsersBll.GetInstence().GetOnlineUsersModelForLog();
                if (model != null)
                {
                    //当前用户ID
                    uselog.Manager_Id = model.Manager_Id;
                    //当前用户名称
                    uselog.Manager_CName = model.Manager_CName;
                }
                else
                {
                    //当前用户ID
                    uselog.Manager_Id = 0;
                    //当前用户名称
                    uselog.Manager_CName = "";
                }
                if (page != null)
                {
                    //当前页面ID
                    var menu = MenuInfoBll.GetInstence().GetMenuInfo(page.Request.Url.AbsolutePath);
                    if (menu == null)
                    {
                        uselog.MenuInfo_Id = 0;
                    }
                    else
                    {
                        uselog.MenuInfo_Id = menu.Id;
                        //当前页面名称
                        uselog.MenuInfo_Name = menu.Name;
                    }

                    //判断是否为首页
                    if (uselog.MenuInfo_Id == 0)
                    {
                        if (page.Request.Url.AbsolutePath.Equals("/WebManage/Main.aspx"))
                        {
                            //当前页面名称
                            uselog.MenuInfo_Name = "首页";
                        }
                    }
                }

                //当前用户IP
                uselog.Ip = IpHelper.GetUserIp();

                //操作内容
                uselog.Notes = StringHelper.FilterSql(String.Format(useLogOccurrence, uselog.Manager_CName, uselog.MenuInfo_Name));
                //插入记录
                uselog.Save();
            }
            catch (Exception e)
            {
                //记录日志
                CommonBll.WriteLog("添加用户操作日志时出现异常", e);
            }
        }