You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

151 lines
6.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/////////////////////////////////////////////////////////////////
//
// (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开发版权所有违者必究32032519810221811023810511@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 TestdotpartvaluePool : PoolInterface
{
private static List<TestdotpartvalueEntity> bufferPool = new List<TestdotpartvalueEntity>();
public static List<TestdotpartvalueEntity> BufferPool
{
get { return bufferPool; }
}
public static void InitializeResults()
{
DataTable dt = MysqlHelper.ExecuteDataTable("select * from TestDotPartValue t where IsActive = 1");
var results = MysqlHelper.DataTableToIList<TestdotpartvalueEntity>(dt) as List<TestdotpartvalueEntity>;
lock (bufferPool)
{
bufferPool.Clear();
bufferPool.AddRange(results);
}
}
public static void Update(object obj)
{
lock (bufferPool)
{
TestdotpartvalueEntity key = obj as TestdotpartvalueEntity;
if(key != null)
{
bufferPool.RemoveAll(q => q.RecId == key.RecId);
bufferPool.Add((TestdotpartvalueEntity)key.Clone());
}
}
}
public static void Delete(string recid)
{
lock (bufferPool)
{
bufferPool.RemoveAll(q => q.RecId == recid);
}
}
public static TestdotpartvalueEntity GetById(string recid)
{
return bufferPool.FirstOrDefault(t => t.RecId == recid);
}
public static TestdotpartvalueEntity GetByCode(string code)
{
return bufferPool.FirstOrDefault(t => t.ValueCode == code);
}
public static string LoadValidationByKey(string currentUserId, string currentClientId, string currentSendParameter)
{
string key = currentSendParameter;
var datas = bufferPool.Where(q => key == "" || q.ValueCode.Contains(key) || q.ValueName.Contains(key))
.Select(item => new
{
RecId = item.RecId,
Code = item.ValueCode,
Name = item.ValueName
}).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<ConditionEntity> ce = JsonConvert.DeserializeObject(se.Conditions, typeof(List<ConditionEntity>)) as List<ConditionEntity>;
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.ValueCode.Contains(keyword) || q.ValueName.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.ValueCode,
SelectName = buffer.ValueName,
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.ValueCode,
SelectName = buffer.ValueName,
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
})
});
}//*/
}
}