///////////////////////////////////////////////////////////////// // // (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. // // 本软件为 ** 公司开发,版权所有,违者必究,23810511@qq.com // ///////////////////////////////////////////////////////////////// using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using Newtonsoft.Json; using QuiltingCommon; namespace QuiltingBusiness { public class EvaluationresultPool : PoolInterface { private static List bufferPool = new List(); public static List BufferPool { get { return bufferPool; } } public static void InitializeResults() { DataTable dt = MysqlHelper.ExecuteDataTable("select * from EvaluationResult t where IsActive = 1"); var results = MysqlHelper.DataTableToIList(dt) as List; lock (bufferPool) { bufferPool.Clear(); bufferPool.AddRange(results); } } public static void Update(object obj) { lock (bufferPool) { EvaluationresultEntity key = obj as EvaluationresultEntity; if(key != null) { bufferPool.RemoveAll(q => q.RecId == key.RecId); bufferPool.Add((EvaluationresultEntity)key.Clone()); } } } public static void Delete(string recid) { lock (bufferPool) { bufferPool.RemoveAll(q => q.RecId == recid); } } public static EvaluationresultEntity GetById(string recid) { return bufferPool.FirstOrDefault(t => t.RecId == recid); } public static EvaluationresultEntity GetByCode(string code) { return bufferPool.FirstOrDefault(t => t.ResultCode == code); } public static string LoadValidationByKey(string currentUserId, string currentClientId, string currentSendParameter) { string key = currentSendParameter; var datas = bufferPool.Where(q => key == "" || q.ResultCode.Contains(key) || q.ResultName.Contains(key)) .Select(item => new { RecId = item.RecId, Code = item.ResultCode, Name = item.ResultName }).OrderBy(o => o.Code).ToList(); OutEntity oe = new OutEntity() { ErrorCode = ErrorCode.Success, ReturnObj = JsonConvert.SerializeObject(datas) }; return JsonConvert.SerializeObject(oe); } /* public static string LoadSelections(string currentUserId, string currentClientId, 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.ResultCode.Contains(keyword) || q.ResultName.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.ResultCode, SelectName = buffer.ResultName, 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 currentClientId, 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.ResultCode, SelectName = buffer.ResultName, 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 }) }); }//*/ } }