namespace BLL { using System; using System.Collections; using System.Linq; using System.Net; using System.Web.UI.WebControls; public static class Sys_LogService { /// /// 记录数 /// private static int count { get; set; } /// /// 定义变量 /// private static IQueryable qq = from x in Funs.DB.Sys_Log orderby x.OperationTime descending select x; /// /// 获取分页列表 /// /// /// /// public static IEnumerable getListData(string systemId, string projectId, string userId, string startTime, string endTime, int startRowIndex, int maximumRows) { IQueryable q = qq; if (userId != "0" && !string.IsNullOrEmpty(userId)) { q = q.Where(e => e.UserId == userId); } if (!String.IsNullOrEmpty(startTime)) { q = q.Where(e => e.OperationTime >= Convert.ToDateTime(startTime)); } if (!String.IsNullOrEmpty(endTime)) { q = q.Where(e => e.OperationTime <= Convert.ToDateTime(endTime)); } if (projectId != "0" && !string.IsNullOrEmpty(projectId)) { q = q.Where(e => e.ProjectId == projectId); } if (systemId != "0" && !string.IsNullOrEmpty(systemId)) { q = q.Where(e => e.SystemId == systemId); } count = q.Count(); if (count == 0) { return new object[] { "" }; } return from x in q.Skip(startRowIndex).Take(maximumRows) select new { UserName = (from u in Funs.DB.Sys_User where u.UserId == x.UserId select u.UserName).FirstOrDefault(), x.OperationTime, x.Ip, x.HostName, x.OperationLog, //ProjectName = (from u in db.Base_Project where u.ProjectId == x.ProjectId select u.ProjectName).FirstOrDefault(), //SystemName = (from u in db.Sys_System where u.SystemId == x.SystemId select u.SystemName).FirstOrDefault(), }; } /// /// 获取列表数 /// /// public static int getListCount(string systemId, string projectId, string userId, string startTime, string endTime) { return count; } /// /// 添加操作日志 /// /// /// public static void AddLog(string userId, string opLog) { //SetOvertime(userId); //Model.EProjectDB db = Funs.DB; Model.Sys_Log log = new Model.Sys_Log(); //log.LogId = SQLHelper.GetNewID(typeof(Model.Sys_Log)); log.LogId = Guid.NewGuid().ToString(); log.HostName = Dns.GetHostName(); IPAddress[] ips = Dns.GetHostAddresses(log.HostName); if (ips.Length > 0) { foreach (IPAddress ip in ips) { if (ip.ToString().IndexOf('.') != -1) { log.Ip = ip.ToString(); } } } log.OperationTime = DateTime.Now; log.OperationLog = opLog; log.UserId = userId; //log.ProjectId = projectId; //log.SystemId = systemId; Funs.DB.Sys_Log.InsertOnSubmit(log); Funs.DB.SubmitChanges(); } /// /// 根据人员Id查询所有日志信息的数量 /// /// 人员Id /// 日志信息的数量 public static int GetLogCountByUserId(string userId) { var q = (from x in Funs.DB.Sys_Log where x.UserId == userId select x).ToList(); return q.Count(); } /// /// 根据人员Id删除所有相关日志信息 /// /// public static void DeleteLogByUserId(string userId) { var q = (from x in Funs.DB.Sys_Log where x.UserId == userId select x).ToList(); if (q != null) { Funs.DB.Sys_Log.DeleteAllOnSubmit(q); Funs.DB.SubmitChanges(); } } } }