コード例 #1
0
        public int AddLog(string busingessName, string opContent)
        {
            LogModel log = new LogModel();

            log.BusinessName  = busingessName;
            log.OperationIp   = PublicMethod.GetClientIP();
            log.OperationTime = DateTime.Now;
            log.OperationType = (int)OperationType.Other;
            log.UserId        = SysVisitor.Instance.UserId;
            log.SqlText       = "";

            int logId = LogDal.Instance.Insert(log);

            if (logId > 0)
            {
                //添加日志详细信息
                StringBuilder sb = new StringBuilder();

                var sqlTemp =
                    "insert into Sys_LogDetails (logid,fieldName,fieldtext,oldvalue,newvalue,remark) values('{0}','{1}','{2}','{3}','{4}','{5}')";
                sb.AppendFormat(sqlTemp, logId, "", "", "", "", opContent);

                if (sb.Length > 0)
                {
                    return(DbUtils.ExecuteNonQuery(sb.ToString(), null));
                }
            }
            return(0);
        }
コード例 #2
0
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="username">用户名</param>
        /// <param name="password">密码</param>
        /// <param name="saveCookieDays">保存cookie天数</param>
        /// <returns></returns>
        public bool UserLogin(string username, string password, int saveCookieDays = 1)
        {
            if (UserLogin(username, password))
            {
                //写入cookie
                CookieHelper.WriteCookie(SysVisitor.CookieNameKey, SysVisitor.CookieUserNameKey, username, "", saveCookieDays);
                var desPass = StringHelper.EncryptDES(password, Key.DESkey);
                CookieHelper.WriteCookie(SysVisitor.CookieNameKey, SysVisitor.CookiePasswordKey, desPass, "", saveCookieDays);


                //写入登录日志
                LogModel log = new LogModel();
                log.BusinessName  = "用户登录";
                log.OperationIp   = PublicMethod.GetClientIP();
                log.OperationTime = DateTime.Now;
                log.PrimaryKey    = "";
                log.UserId        = SysVisitor.Instance.UserId;
                log.TableName     = "";
                log.OperationType = (int)OperationType.Login;
                LogDal.Instance.Insert(log);

                return(true);
            }
            return(false);
        }
コード例 #3
0
        /// <summary>
        /// 添加更新操作日志
        /// </summary>
        /// <param name="oldObj">旧实体对象</param>
        /// <param name="newObj">新实体对象</param>
        /// <returns></returns>
        public int UpdateLog(T oldObj, T newObj)
        {
            return(1);

            Type objTye = typeof(T);

            PropertyInfo property = objTye.GetProperty("FID");

            LogModel log = new LogModel();

            log.BusinessName  = GetBusingessName();
            log.OperationIp   = PublicMethod.GetClientIP();
            log.OperationTime = DateTime.Now;
            log.OperationType = (int)OperationType.Update;
            log.PrimaryKey    = property.GetValue(newObj, null).ToString();
            log.TableName     = TableConvention.Resolve(newObj);
            log.UserId        = SysVisitor.Instance.UserId;
            log.SqlText       = "";


            //添加日志详细信息
            StringBuilder sb = new StringBuilder();

            var sqlTemp =
                "insert into Sys_LogDetails (FID, logid,fieldName,fieldtext,oldvalue,newvalue,remark) values('{0}','{1}','{2}','{3}','{4}','{5}','')";

            string logId = LogDal.Instance.Insert(log);

            if (logId != "")
            {
                var propertyList = objTye.GetInfos();
                foreach (PropertyInfo p in propertyList)
                {
                    object oldVal = p.GetValue(oldObj, null);
                    object newVal = p.GetValue(newObj, null);

                    if (!string.Equals(p.Name, "FID", StringComparison.CurrentCultureIgnoreCase) &&
                        p.GetCustomAttributes(true).OfType <DbFieldAttribute>().Count(dbFieldAttribute => !dbFieldAttribute.IsDbField) == 0 &&
                        !ignoredFields.Contains(p.Name, StringComparer.InvariantCultureIgnoreCase))
                    {
                        if (!IsEqual(p.PropertyType, oldVal, newVal))
                        {
                            sb.AppendFormat(sqlTemp, Guid.NewGuid().ToString(), logId, p.Name, GetFieldText(p), oldVal, newVal, "");
                            sb.AppendLine();
                        }
                    }
                }

                if (sb.Length > 0)
                {
                    return(DbUtils.ExecuteNonQuery(sb.ToString(), null));
                }
                return(LogDal.Instance.Delete(logId));
            }
            return(0);
        }
コード例 #4
0
        /// <summary>
        /// 添加操作日志
        /// </summary>
        /// <param name="t">实体类</param>
        /// <returns></returns>
        public int AddLog(T t, string busingessName = "")
        {
            return(0);

            Type         objTye   = typeof(T);
            PropertyInfo property = objTye.GetProperty("FID");

            LogModel log = new LogModel();

            log.BusinessName  = busingessName ?? GetBusingessName();
            log.OperationIp   = PublicMethod.GetClientIP();
            log.OperationTime = DateTime.Now;
            log.OperationType = (int)OperationType.Add;
            if (property != null)
            {
                log.PrimaryKey = property.GetValue(t, null).ToString();
            }
            log.TableName = TableConvention.Resolve(t);
            log.UserId    = SysVisitor.Instance.UserId;
            log.SqlText   = "";


            string logId = LogDal.Instance.Insert(log);

            if (logId != "")
            {
                //添加日志详细信息
                StringBuilder sb = new StringBuilder();

                var sqlTemp =
                    "insert into Sys_LogDetails (fid, logid,fieldName,fieldtext,oldvalue,newvalue,remark) values('{0}','{1}','{2}','{3}','{4}','{5}','');";
                foreach (PropertyInfo pi in objTye.GetProperties())
                {
                    if (!string.Equals(pi.Name, "FID", StringComparison.CurrentCultureIgnoreCase) &&
                        pi.GetCustomAttributes(true).OfType <DbFieldAttribute>().Count(dbFieldAttribute => !dbFieldAttribute.IsDbField) == 0 &&
                        !ignoredFields.Contains(pi.Name, StringComparer.InvariantCultureIgnoreCase))
                    {
                        sb.AppendFormat(sqlTemp, Guid.NewGuid().ToString(), logId, pi.Name, GetFieldText(pi), "", pi.GetValue(t, null));
                        sb.AppendLine();
                    }
                }

                if (sb.Length > 0)
                {
                    return(DbUtils.ExecuteNonQuery(sb.ToString(), null));
                }
            }
            return(0);
        }
コード例 #5
0
        public void LoginOut()
        {
            //写入退出日志
            LogModel log = new LogModel();

            log.BusinessName  = "用户退出";
            log.OperationIp   = PublicMethod.GetClientIP();
            log.OperationTime = DateTime.Now;
            log.PrimaryKey    = "";
            log.UserId        = UserId;
            log.TableName     = "";
            log.OperationType = (int)OperationType.LoginOut;
            LogDal.Instance.Insert(log);


            CookieHelper.ClearUserCookie("", SysVisitor.CookieNameKey);
            UserName = null;
            UserId   = 0;
        }