///////////////////////////////////////////////////////////////// // // (C) Copyright 2013, Kenneth, Inc. // All rights reserved. Confidential. Except as pursuant // to a written agreement with Kenneth, this software may // not be used or distributed. This software may be covered // by one or more patents. // // 本软件为Kenneth开发,版权所有,违者必究,320325198102218110,23810511@qq.com // ///////////////////////////////////////////////////////////////// using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using BaseEntity; using BaseCommon; using BaseResource; using Newtonsoft.Json; namespace WebBusiness { public class {ClassName}Pool : PoolInterface { private static List<{ClassName}Entity> bufferPool = new List<{ClassName}Entity>(); public static List<{ClassName}Entity> BufferPool { get { return bufferPool; } } public static void InitializeResults() { DataTable dt = SqlHelper.ExecuteDataTable("select * from {TableName} t where IsActive = 1"); var results = SqlHelper.DataTableToIList<{ClassName}Entity>(dt) as List<{ClassName}Entity>; lock (bufferPool) { bufferPool.Clear(); bufferPool.AddRange(results); } } public static void Update({ClassName}Entity key) { lock (bufferPool) { if(key != null) { bufferPool.RemoveAll(q => q.RecId == key.RecId); bufferPool.Add(({ClassName}Entity)key.Clone()); } } } public static void Delete(string recid) { lock (bufferPool) { bufferPool.RemoveAll(q => q.RecId == recid); } } public static string GetNameById(string recid) { return bufferPool.FirstOrDefault(t => t.RecId == recid)?.{QueryField2}; } public static {ClassName}Entity GetById(string recid) { return bufferPool.FirstOrDefault(t => t.RecId == recid); } public static {ClassName}Entity GetByCode(string code) { return bufferPool.FirstOrDefault(t => t.{QueryField1} == code); } public static string LoadValidationByKey(string currentUserId, string currentStoreId, string currentSendParameter) { string key = currentSendParameter; var datas = bufferPool.Where(q => key == "" || q.{QueryField1}.Contains(key) || q.{QueryField2}.Contains(key)) .Select(item => new { RecId = item.RecId, Code = item.{QueryField1}, Name = item.{QueryField2} }).OrderBy(o => o.Code).ToList(); OutEntity oe = new OutEntity() { ErrorCode = ErrorCode.Success, ReturnObj = JsonConvert.SerializeObject(datas) }; return JsonConvert.SerializeObject(oe); } {OpenLoadSelections}/* public static string LoadSelections(string currentUserId, string currentStoreId, string currentSendParameter) { PagerEntity se = JsonConvert.DeserializeObject(currentSendParameter, typeof(PagerEntity)) as PagerEntity; List ce = JsonConvert.DeserializeObject(se.Conditions, typeof(List)) as List; string keyword = ce.Where(q => q.Name.Equals("KeyWord1")).FirstOrDefault()?.Value.ToLower(); //string keyword2 = ce.Where(q => q.Name.Equals("KeyWord2")).FirstOrDefault()?.Value.ToLower(); string dateFrom = ce.Where(q => q.Name.Equals("DateFrom")).FirstOrDefault()?.Value; string dateTo = ce.Where(q => q.Name.Equals("DateTo")).FirstOrDefault()?.Value; //string selectType = ce.Where(q => q.Name.Equals("SelectType")).FirstOrDefault()?.Value; //string[] types = selectType.Split('_'); DateTime dtStart; DateTime dtEnd; if (!DateTime.TryParse(dateFrom, out dtStart)) dtStart = new DateTime(1900, 1, 1); if (!DateTime.TryParse(dateTo, out dtEnd)) dtEnd = new DateTime(2100, 1, 1); var data = bufferPool.Where(q => keyword == "" || q.{QueryField1}.Contains(keyword) || q.{QueryField2}.Contains(keyword)) .AsQueryable().OrderBy(se.OrderBy, se.SortOrder); int count = data.Count(); var result = new { total = Math.Ceiling(count * 1.0 / se.Rows), page = se.PageIndex, records = count, rows = data.Skip((se.PageIndex - 1) * se.Rows).Take(se.Rows).Select(buffer => new SelectionEntity() { RecId = buffer.RecId, SelectCode = buffer.{QueryField1}, SelectName = buffer.{QueryField2}, SelectDetail = string.Empty, CreateTime = buffer.CreateTime, ModifyTime = buffer.ModifyTime }) }; OutEntity oe = new OutEntity() { ErrorCode = ErrorCode.Success, ReturnObj = JsonConvert.SerializeObject(result) }; return JsonConvert.SerializeObject(oe); } public static string LoadSelectionText(string currentUserId, string currentStoreId, string currentSendParameter) { var buffer = bufferPool.Where(q => q.RecId == currentSendParameter).FirstOrDefault(); if (buffer != null) { OutEntity oe = new OutEntity() { ErrorCode = ErrorCode.Success, ReturnObj = JsonConvert.SerializeObject(new SelectionEntity() { RecId = buffer.RecId, SelectCode = buffer.{QueryField1}, SelectName = buffer.{QueryField2}, SelectDetail = string.Empty, CreateTime = buffer.CreateTime, ModifyTime = buffer.ModifyTime }) }; return JsonConvert.SerializeObject(oe); } return JsonConvert.SerializeObject(new OutEntity() { ErrorCode = ErrorCode.Success, ReturnObj = JsonConvert.SerializeObject(new SelectionEntity() { RecId = "", SelectCode = "", SelectName = "", SelectDetail = string.Empty }) }); }//*/ } }