lxl 2 роки тому
батько
коміт
afe7eb1fda

+ 3 - 2
.gitignore

@@ -19,8 +19,6 @@
 /EMIS.Entities.HRServices/obj/Release
 /EMIS.Entities.Log/bin/Debug
 /EMIS.Entities.Log/obj/Debug
-/EMiS.DataLogic
-/EMIS.Services
 /EMIS.ExtensionLogic.LCNX/obj
 /EMIS.ResourcesHBKD/obj
 /EMIS.ResourcesHBGD/obj
@@ -44,3 +42,6 @@
 /学校扩展文件
 /广体终端机/Net版本/packages
 /督导评语7.16/App_Data
+/EMIS.Services/bin/Debug
+/EMIS.Services/obj/x86/Debug
+/EMIS.Services/obj/x86/Release

+ 40 - 0
EMiS.DataLogic/Log/OperateLogDAL.cs

@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using EMIS.DataLogic.Repositories.Log;
+using EMIS.ViewModel.Log;
+using EMIS.Entities.Log;
+using System.Linq.Expressions;
+
+namespace EMIS.DataLogic.Log
+{
+    public class OperateLogDAL
+    {
+        public OperateRepository OperateRepository { get; set; }
+        public VWUserRepository VWUserRepository { get; set; }
+
+        public IQueryable<OperateLogView> GetOperateLogView(Expression<Func<Log_Operate, bool>> exp, Expression<Func<VW_Sys_User, bool>> userExp)
+        {
+            var q = (from o in OperateRepository.GetList(exp) 
+                     join vu in VWUserRepository.GetList(userExp) on o.UserID equals vu.UserID 
+                     orderby o.OperateTime descending 
+                     select new OperateLogView {
+                        OperateID = o.OperateID,
+                        UserID = vu.UserID,
+                        LoginID = vu.LoginID,
+                        UserName = vu.Name,
+                        IP = o.IP,
+                        TableName = o.TableName,
+                        SourceUrl = o.SourceUrl,
+                        Operate = o.Operate,
+                        Detail = o.Detail,
+                        IsSuccess = o.IsSuccess,
+                        IsSuccessDesc = ((o.IsSuccess == true) ? "是" : "否"),
+                        OperateTime = o.OperateTime
+                     });
+
+            return q;
+        }
+    }
+}

+ 117 - 0
EMiS.DataLogic/Repositories/Log/LogRepository.cs

@@ -0,0 +1,117 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Linq.Expressions;
+using System.Data.Entity;
+using System.Data.Entity.Infrastructure;
+using Bowin.Common.Data;
+using Bowin.Common.Linq.Entity;
+
+namespace EMIS.DataLogic.Repositories.Log
+{
+    public class LogRepository<TEntity> where TEntity : class
+    {
+        private LogUnitOfWork _unitOfWork;
+
+        private LogRepository()
+        {
+
+        }
+
+        public LogRepository(LogUnitOfWork unitOfWork)
+        {
+            this._unitOfWork = unitOfWork;
+        }
+
+        public TEntity GetSingle(Expression<Func<TEntity, bool>> expression)
+        {
+            return this.Entities.Where<TEntity>(expression).FirstOrDefault<TEntity>();
+        }
+
+        public TEntity GetSingle(Expression<Func<TEntity, bool>> expression, params string[] paths)
+        {
+            IQueryable<TEntity> source = this.Entities;//.Include(path)
+            foreach (var path in paths)
+            {
+                source = source.Include(path);
+            }
+            return source.Where<TEntity>(expression).FirstOrDefault<TEntity>();
+        }
+
+        public TEntity GetSingle(Expression<Func<TEntity, bool>> expression, params Expression<Func<TEntity, object>>[] paths)
+        {
+            IQueryable<TEntity> source = this.Entities;//.Include(path)
+            foreach (var path in paths)
+            {
+                source = source.Include(path);
+            }
+            return source.Where<TEntity>(expression).FirstOrDefault<TEntity>();
+        }
+
+        public IQueryable<TEntity> Entities
+        {
+            get
+            {
+                return this._unitOfWork.Set<TEntity>();
+            }
+        }
+
+        public LogUnitOfWork UnitOfWork
+        {
+            get
+            {
+                return this._unitOfWork;
+            }
+        }
+
+        public GridResultSet<TEntity> GetPagedList<S>(Expression<Func<TEntity, bool>> expression, int pageIndex, int pageSize, Expression<Func<TEntity, S>> orderBy, bool descending, params Expression<Func<TEntity, object>>[] paths)
+        {
+            IQueryable<TEntity> source = this.Entities;//.Include(path)
+            foreach (var path in paths)
+            {
+                source = source.Include(path);
+            }
+            source = source.Where<TEntity>(expression);
+            source = descending ? source.OrderByDescending<TEntity, S>(orderBy) : source.OrderBy<TEntity, S>(orderBy);
+
+            GridResultSet<TEntity> gridResult = new GridResultSet<TEntity>();
+
+            gridResult.rows = source.Skip<TEntity>((pageIndex) * pageSize).Take<TEntity>(pageSize).ToList();
+            gridResult.total = source.Count();
+            return gridResult;
+        }
+
+        public GridResultSet<TEntity> GetPagedList<S>(Expression<Func<TEntity, bool>> expression, int pageIndex, int pageSize, Expression<Func<TEntity, S>> orderBy, bool descending)
+        {
+            try
+            {
+                IQueryable<TEntity> source = this.Entities.Where<TEntity>(expression);
+                source = descending ? source.OrderByDescending<TEntity, S>(orderBy) : source.OrderBy<TEntity, S>(orderBy);
+
+                GridResultSet<TEntity> gridResult = new GridResultSet<TEntity>();
+
+                gridResult.rows = source.Skip<TEntity>((pageIndex) * pageSize).Take<TEntity>(pageSize).ToList();
+                gridResult.total = source.Count();
+
+                return gridResult;
+            }
+            catch (Exception ex)
+            {
+                throw ex;
+            }
+        }
+
+        public IQueryable<TEntity> GetList<S>(Expression<Func<TEntity, bool>> expression, Expression<Func<TEntity, S>> orderBy, bool descending)
+        {
+            var source = GetList(expression);
+            return descending ? source.OrderByDescending<TEntity, S>(orderBy) : source.OrderBy<TEntity, S>(orderBy);
+        }
+
+        public IQueryable<TEntity> GetList(Expression<Func<TEntity, bool>> expression)
+        {
+            return this.Entities.Where<TEntity>(expression);
+        }
+
+    }
+}

+ 15 - 0
EMiS.DataLogic/Repositories/Log/OperateRepository.cs

@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using EMIS.Entities.Log;
+
+namespace EMIS.DataLogic.Repositories.Log
+{
+    public class OperateRepository : LogRepository<Log_Operate>
+    {
+        public OperateRepository(LogUnitOfWork unitOfWork)
+            : base(unitOfWork)
+        { }
+    }
+}

+ 1 - 0
EMiS.DataLogic/Repositories/Log/RepositoryGenerator.cs

@@ -0,0 +1 @@
+

+ 231 - 0
EMiS.DataLogic/Repositories/Log/RepositoryGenerator.tt

@@ -0,0 +1,231 @@
+<#@ template debug="true" hostspecific="true" language="C#" #>
+<#@ assembly name="System.Core"#>
+<#@ assembly name="System.Data.Linq"#>
+<#@ assembly name="EnvDTE"#>
+<#@ assembly name="System.Xml"#>
+<#@ assembly name="System.Xml.Linq"#>
+<#@ import namespace="System.Diagnostics" #>
+<#@ import namespace="System"#>
+<#@ import namespace="System.CodeDom"#>
+<#@ import namespace="System.CodeDom.Compiler"#>
+<#@ import namespace="System.Collections.Generic"#>
+<#@ import namespace="System.Data.Linq"#>
+<#@ import namespace="System.Data.Linq.Mapping"#>
+<#@ import namespace="System.IO"#>
+<#@ import namespace="System.Linq"#>
+<#@ import namespace="System.Reflection"#>
+<#@ import namespace="System.Text"#>
+<#@ import namespace="System.Xml.Linq"#>
+<#@ import namespace="Microsoft.VisualStudio.TextTemplating"#>
+<#@ VolatileAssembly processor="T4Toolbox.VolatileAssemblyProcessor" name="$(SolutionDir)\packages\EntityFramework.6.1.3\lib\net40\EntityFramework.dll" #>
+<#@ VolatileAssembly processor="T4Toolbox.VolatileAssemblyProcessor" name="$(SolutionDir)\EMIS.Entities.Log\bin\Debug\EMIS.Entities.Log.dll" #>
+
+<#
+var manager = Manager.Create(Host, GenerationEnvironment); 
+var blAssembly = Assembly.GetAssembly(typeof(EMIS.Entities.Log.EMISNewLogContext));
+var types = blAssembly.GetTypes().Where(x => 
+				x.FullName.StartsWith("EMIS.Entities.Log") && 
+                !x.Name.EndsWith("Mapping") && x.Name != "TableKeyDictionary" && !x.Name.EndsWith("Context"));
+
+foreach(var type in types)
+{
+	int startIndex = type.Name.IndexOf("_") + 1;
+	int length = type.Name.Length - startIndex;
+	string classShortName = type.Name.Substring(startIndex, length);
+	string className = classShortName + "Repository";
+
+	if (type.Name.StartsWith("VW"))
+	{
+		int secondStartIndex = classShortName.IndexOf("_") + 1;
+		classShortName = "VW" + classShortName.Substring(secondStartIndex, classShortName.Length - secondStartIndex);
+		className = classShortName + "Repository";
+	}
+
+	if (classShortName.StartsWith("SS_"))
+	{
+		continue;
+	}
+
+	manager.StartNewFile(className + ".cs");
+#>
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using EMIS.Entities.Log;
+
+namespace EMIS.DataLogic.Repositories.Log
+{
+    public class <#=className#> : LogRepository<<#=type.Name#>>
+    {
+        public <#=className#>(LogUnitOfWork unitOfWork)
+            : base(unitOfWork)
+        { }
+    }
+}
+<#	
+	manager.EndBlock();
+}
+manager.Process(true);
+#>
+<#+
+// Manager class records the various blocks so it can split them up
+class Manager {
+    private class Block {
+        public String Name;
+        public int Start, Length;
+    }
+
+    private Block currentBlock;
+    private List<Block> files = new List<Block>();
+    private Block footer = new Block();
+    private Block header = new Block();
+    private ITextTemplatingEngineHost host;
+    private StringBuilder template;
+    protected List<String> generatedFileNames = new List<String>();
+
+    public static Manager Create(ITextTemplatingEngineHost host, StringBuilder template) {
+        return (host is IServiceProvider) ? new VSManager(host, template) : new Manager(host, template);
+    }
+
+    public void StartNewFile(String name) {
+        if (name == null)
+            throw new ArgumentNullException("name");
+        CurrentBlock = new Block { Name = name };
+    }
+
+    public void StartFooter() {
+        CurrentBlock = footer;
+    }
+
+    public void StartHeader() {
+        CurrentBlock = header;
+    }
+
+    public void EndBlock() {
+        if (CurrentBlock == null)
+            return;
+        CurrentBlock.Length = template.Length - CurrentBlock.Start;
+        if (CurrentBlock != header && CurrentBlock != footer)
+            files.Add(CurrentBlock);
+        currentBlock = null;
+    }
+
+    public virtual void Process(bool split) {
+        if (split) {
+            EndBlock();
+            String headerText = template.ToString(header.Start, header.Length);
+            String footerText = template.ToString(footer.Start, footer.Length);
+            String outputPath = Path.GetDirectoryName(host.TemplateFile);
+            files.Reverse();
+            foreach(Block block in files) {
+                String fileName = Path.Combine(outputPath, block.Name);
+                String content = headerText + template.ToString(block.Start, block.Length) + footerText;
+                generatedFileNames.Add(fileName);
+                CreateFile(fileName, content);
+                template.Remove(block.Start, block.Length);
+            }
+        }
+    }
+
+    protected virtual void CreateFile(String fileName, String content) {
+        if (IsFileContentDifferent(fileName, content))
+            File.WriteAllText(fileName, content);
+    }
+
+    public virtual String GetCustomToolNamespace(String fileName) {
+        return null;
+    }
+
+    public virtual String DefaultProjectNamespace {
+        get { return null; }
+    }
+
+    protected bool IsFileContentDifferent(String fileName, String newContent) {
+        return !(File.Exists(fileName) && File.ReadAllText(fileName) == newContent);
+    }
+
+    private Manager(ITextTemplatingEngineHost host, StringBuilder template) {
+        this.host = host;
+        this.template = template;
+    }
+
+    private Block CurrentBlock {
+        get { return currentBlock; }
+        set {
+            if (CurrentBlock != null)
+                EndBlock();
+            if (value != null)
+                value.Start = template.Length;
+            currentBlock = value;
+        }
+    }
+
+    private class VSManager: Manager {
+        private EnvDTE.ProjectItem templateProjectItem;
+        private EnvDTE.DTE dte;
+        private Action<String> checkOutAction;
+        private Action<IEnumerable<String>> projectSyncAction;
+
+        public override String DefaultProjectNamespace {
+            get {
+                return templateProjectItem.ContainingProject.Properties.Item("DefaultNamespace").Value.ToString();
+            }
+        }
+
+        public override String GetCustomToolNamespace(string fileName) {
+            return dte.Solution.FindProjectItem(fileName).Properties.Item("CustomToolNamespace").Value.ToString();
+        }
+
+        public override void Process(bool split) {
+            if (templateProjectItem.ProjectItems == null)
+                return;
+            base.Process(split);
+            projectSyncAction.EndInvoke(projectSyncAction.BeginInvoke(generatedFileNames, null, null));
+        }
+
+        protected override void CreateFile(String fileName, String content) {
+            if (IsFileContentDifferent(fileName, content)) {
+                CheckoutFileIfRequired(fileName);
+                File.WriteAllText(fileName, content);
+            }
+        }
+
+        internal VSManager(ITextTemplatingEngineHost host, StringBuilder template)
+            : base(host, template) {
+            var hostServiceProvider = (IServiceProvider) host;
+            if (hostServiceProvider == null)
+                throw new ArgumentNullException("Could not obtain IServiceProvider");
+            dte = (EnvDTE.DTE) hostServiceProvider.GetService(typeof(EnvDTE.DTE));
+            if (dte == null)
+                throw new ArgumentNullException("Could not obtain DTE from host");
+            templateProjectItem = dte.Solution.FindProjectItem(host.TemplateFile);
+            checkOutAction = (String fileName) => dte.SourceControl.CheckOutItem(fileName);
+            projectSyncAction = (IEnumerable<String> keepFileNames) => ProjectSync(templateProjectItem, keepFileNames);
+        }
+
+        private static void ProjectSync(EnvDTE.ProjectItem templateProjectItem, IEnumerable<String> keepFileNames) {
+            var keepFileNameSet = new HashSet<String>(keepFileNames);
+            var projectFiles = new Dictionary<String, EnvDTE.ProjectItem>();
+            var originalFilePrefix = Path.GetFileNameWithoutExtension(templateProjectItem.get_FileNames(0)) + ".";
+            foreach(EnvDTE.ProjectItem projectItem in templateProjectItem.ProjectItems)
+                projectFiles.Add(projectItem.get_FileNames(0), projectItem);
+
+            // Remove unused items from the project
+            foreach(var pair in projectFiles)
+                if (!keepFileNames.Contains(pair.Key) && !(Path.GetFileNameWithoutExtension(pair.Key) + ".").StartsWith(originalFilePrefix))
+                    pair.Value.Delete();
+
+            // Add missing files to the project
+            foreach(String fileName in keepFileNameSet)
+                if (!projectFiles.ContainsKey(fileName))
+                    templateProjectItem.ProjectItems.AddFromFile(fileName);
+        }
+
+        private void CheckoutFileIfRequired(String fileName) {
+            var sc = dte.SourceControl;
+            if (sc != null && sc.IsItemUnderSCC(fileName) && !sc.IsItemCheckedOut(fileName))
+                checkOutAction.EndInvoke(checkOutAction.BeginInvoke(fileName, null, null));
+        }
+    }
+} #>

+ 15 - 0
EMiS.DataLogic/Repositories/Log/VWUserRepository.cs

@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using EMIS.Entities.Log;
+
+namespace EMIS.DataLogic.Repositories.Log
+{
+    public class VWUserRepository : LogRepository<VW_Sys_User>
+    {
+        public VWUserRepository(LogUnitOfWork unitOfWork)
+            : base(unitOfWork)
+        { }
+    }
+}