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.

537 lines
36 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.
//
// 本软件为 ** 公司开发版权所有违者必究23810511@qq.com
//
/////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using System.IO;
using System.Reflection;
using System.Data;
using System.Data.SqlClient;
using System.Transactions;
using QuiltingCommon;
using MySql.Data.MySqlClient;
namespace QuiltingBusiness
{
public partial class Testpartvalue
{
#region private const functions
private static object lockobj = new object();
private const string _onlyTableName="TestPartValue";
private const string _fields = "t.RecId,t.ValueCode,t.ValueName,t.ReferenceId,t.ReferenceType,t.TestPart,t.TestPartDisplayer,t.PartAvg,t.PartMax,t.PartMin,t.AnalysisResult,t.CreateBy,t.CreateTime,t.ModifyBy,t.ModifyTime,t.IsActive";
private const string _tableName = "TestPartValue t";
private const string _log_fields = "t.LogId,t.RecId,t.ValueCode,t.ValueName,t.ReferenceId,t.ReferenceType,t.TestPart,t.TestPartDisplayer,t.PartAvg,t.PartMax,t.PartMin,t.AnalysisResult,t.CreateBy,t.CreateTime,t.ModifyBy,t.ModifyTime,t.IsActive,t.OperTime,t.OperUser,t.OperType,t.OperInfo";
private const string _log_tableName = "TestPartValue_log t";
private static string QueryFromWhere(string dateFrom, DateTime dtStart, DateTime dtEnd, string keyword1, string keyword2, string createby = null, string testpart = null, string testpartDisplayer = null)
{
string fromwhere = string.Empty;
fromwhere = fromwhere + ((testpart == null || testpart == "") ? "" : string.Format(" and t.TestPart = '{0}' ", testpart));
fromwhere = fromwhere + ((testpartDisplayer == null || testpartDisplayer == "") ? "" : string.Format(" and t.TestPartDisplayer like '%{0}%' ", testpartDisplayer));
fromwhere = fromwhere + ((createby == null || createby == "") ? "" : string.Format(" and t.CreateBy = '{0}' ", createby));
fromwhere = fromwhere + ((dateFrom == null || dateFrom == "") ? "" : string.Format(" and t.CreateTime >= '{0}' and t.CreateTime <= '{1}' ", dtStart, dtEnd));
fromwhere = fromwhere + ((keyword1 == null || keyword1 == "") ? "" : string.Format(" and (t.ValueCode like '%{0}%' or t.ValueName like '%{0}%') ", keyword1));
fromwhere = fromwhere + ((keyword2 == null || keyword2 == "") ? "" : string.Format(" and (t.ValueCode like '%{0}%' or t.ValueName like '%{0}%') ", keyword2));
fromwhere = fromwhere + " and t.IsActive > 0 ";
return fromwhere;
}
private static void InsertToLog(MySqlConnection connection, string recid, string currentUserId, string opertype)
{
TestpartvalueEntity data = LoadResult(connection, recid);
if (data != null)
{
MySqlParameter paramLogId = new MySqlParameter("@LogId", MySqlDbType.VarChar) { Value = Guid.NewGuid().ToString() };
MySqlParameter paramRecId = new MySqlParameter("@RecId", MySqlDbType.VarChar) { Value = data.RecId };
MySqlParameter paramValueCode = new MySqlParameter("@ValueCode", MySqlDbType.VarChar) { Value = data.ValueCode };
MySqlParameter paramValueName = new MySqlParameter("@ValueName", MySqlDbType.VarChar) { Value = data.ValueName };
MySqlParameter paramReferenceId = new MySqlParameter("@ReferenceId", MySqlDbType.VarChar) { Value = data.ReferenceId };
MySqlParameter paramReferenceType = new MySqlParameter("@ReferenceType", MySqlDbType.VarChar) { Value = data.ReferenceType };
MySqlParameter paramTestPart = new MySqlParameter("@TestPart", MySqlDbType.VarChar) { Value = data.TestPart };
MySqlParameter paramTestPartDisplayer = new MySqlParameter("@TestPartDisplayer", MySqlDbType.VarChar) { Value = data.TestPartDisplayer };
MySqlParameter paramPartAvg = new MySqlParameter("@PartAvg", MySqlDbType.VarChar) { Value = data.PartAvg };
MySqlParameter paramPartMax = new MySqlParameter("@PartMax", MySqlDbType.VarChar) { Value = data.PartMax };
MySqlParameter paramPartMin = new MySqlParameter("@PartMin", MySqlDbType.VarChar) { Value = data.PartMin };
MySqlParameter paramAnalysisResult = new MySqlParameter("@AnalysisResult", MySqlDbType.VarChar) { Value = data.AnalysisResult };
MySqlParameter paramCreateBy = new MySqlParameter("@CreateBy", MySqlDbType.VarChar) { Value = data.CreateBy };
MySqlParameter paramCreateTime = new MySqlParameter("@CreateTime", MySqlDbType.DateTime) { Value = data.CreateTime };
MySqlParameter paramModifyBy = new MySqlParameter("@ModifyBy", MySqlDbType.VarChar) { Value = data.ModifyBy };
MySqlParameter paramModifyTime = new MySqlParameter("@ModifyTime", MySqlDbType.DateTime) { Value = data.ModifyTime };
MySqlParameter paramIsActive = new MySqlParameter("@IsActive", MySqlDbType.VarChar) { Value = data.IsActive };
MySqlParameter paramOperType = new MySqlParameter("@OperType", MySqlDbType.VarChar) { Value = opertype };
MySqlParameter paramOperUser = new MySqlParameter("@OperUser", MySqlDbType.VarChar) { Value = currentUserId };
MySqlParameter paramOperTime = new MySqlParameter("@OperTime", MySqlDbType.DateTime) { Value = DateTime.Now };
MySqlParameter paramOperInfo = new MySqlParameter("@OperInfo", MySqlDbType.VarChar) { Value = "" };
MysqlHelper.ExecuteNonQuery(connection, "insert into TestPartValue_log (LogId,RecId,ValueCode,ValueName,ReferenceId,ReferenceType,TestPart,TestPartDisplayer,PartAvg,PartMax,PartMin,AnalysisResult,CreateBy,CreateTime,ModifyBy,ModifyTime,IsActive,OperType,OperUser,OperTime,OperInfo) values (@LogId,@RecId,@ValueCode,@ValueName,@ReferenceId,@ReferenceType,@TestPart,@TestPartDisplayer,@PartAvg,@PartMax,@PartMin,@AnalysisResult,@CreateBy,@CreateTime,@ModifyBy,@ModifyTime,@IsActive,@OperType,@OperUser,@OperTime,@OperInfo)",
new MySqlParameter[] { paramLogId, paramRecId, paramValueCode, paramValueName, paramReferenceId, paramReferenceType, paramTestPart, paramTestPartDisplayer, paramPartAvg, paramPartMax, paramPartMin, paramAnalysisResult, paramCreateBy, paramCreateTime, paramModifyBy, paramModifyTime, paramIsActive, paramOperType, paramOperUser, paramOperTime, paramOperInfo });
}
}
private static TestpartvalueEntity LoadResult(MySqlConnection connection, string recid)
{
MySqlParameter paramRecId = new MySqlParameter("@RecId", MySqlDbType.VarChar) { Value = recid };
DataTable dt = MysqlHelper.ExecuteDataTable(connection, "select * from TestPartValue t where t.RecId = @RecId and t.IsActive > 0 limit 1", paramRecId);
TestpartvalueEntity data = MysqlHelper.DataRow0ToEntity<TestpartvalueEntity>(dt) as TestpartvalueEntity;
return data;
}
private static TestpartvalueEntityExtension LoadResult(string recid)
{
MySqlParameter paramRecId = new MySqlParameter("@RecId", MySqlDbType.VarChar) { Value = recid };
DataTable dt = MysqlHelper.ExecuteDataTable("select * from TestPartValue t where t.RecId = @RecId and t.IsActive > 0 limit 1", paramRecId);
TestpartvalueEntityExtension data = MysqlHelper.DataRow0ToEntity<TestpartvalueEntityExtension>(dt) as TestpartvalueEntityExtension;
if (data != null)
{
ConvertSingleData(data);
}
return data;
}
private static string GetConditionValue(List<ConditionEntity> ce, string keyword)
{
if(ce.Where(q => q.Name.Equals(keyword)).FirstOrDefault() != null)
{
return ce.Where(q => q.Name.Equals(keyword, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault().Value;
}
return string.Empty;
}
#endregion
public static string LoadResults(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 createby = GetConditionValue(ce, "CreateBy");
string keyword1 = GetConditionValue(ce, "KeyWord1");
string keyword2 = GetConditionValue(ce, "KeyWord2");
string dateFrom = GetConditionValue(ce, "DateFrom");
string dateTo = GetConditionValue(ce, "DateTo");
string testpart = GetConditionValue(ce, "TestPart");
string testpartDisplayer = GetConditionValue(ce, "TestPartDisplayer");
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);
int count = 0;
string fromwhere = QueryFromWhere(dateFrom, dtStart, dtEnd, keyword1, keyword2, createby, testpart, testpartDisplayer);
DataTable dt = MysqlHelper.GetPager(out count, _fields, _tableName, fromwhere, se.OrderBy, se.SortOrder, se.PageIndex, se.Rows);
List<TestpartvalueEntityExtension> rows = MysqlHelper.DataTableToIList<TestpartvalueEntityExtension>(dt) as List<TestpartvalueEntityExtension>;
foreach (var row in rows)
{
ConvertSingleData(row);
}
RecordEntity result = new RecordEntity();
result.total = (int)Math.Ceiling(count * 1.0 / se.Rows);
result.page = se.PageIndex;
result.records = count;
result.rows = rows;
OutEntity oe = new OutEntity() { ErrorCode = ErrorCode.Success, ReturnObj = JsonConvert.SerializeObject(result) };
return JsonConvert.SerializeObject(oe);
}
public static string SaveResult(string currentUserId, string currentClientId, string currentSendParameter)
{
lock(lockobj)
{
var se = JsonConvert.DeserializeObject(currentSendParameter, typeof(BaseSendEntity)) as BaseSendEntity;
using (var tranScope = new TransactionScope())
{
string connectionString = AppHelper.GetLinkString();
using (MySqlConnection connection = new MySqlConnection(connectionString))
{
TestpartvalueEntity send = JsonConvert.DeserializeObject(se.SendKey, typeof(TestpartvalueEntity)) as TestpartvalueEntity;
MySqlParameter paramRecId = new MySqlParameter("@RecId", MySqlDbType.VarChar) { Value = send.RecId };
MySqlParameter paramValueCode = new MySqlParameter("@ValueCode", MySqlDbType.VarChar) { Value = send.ValueCode };
MySqlParameter paramValueName = new MySqlParameter("@ValueName", MySqlDbType.VarChar) { Value = send.ValueName };
MySqlParameter paramReferenceId = new MySqlParameter("@ReferenceId", MySqlDbType.VarChar) { Value = send.ReferenceId };
MySqlParameter paramReferenceType = new MySqlParameter("@ReferenceType", MySqlDbType.VarChar) { Value = send.ReferenceType };
MySqlParameter paramTestPart = new MySqlParameter("@TestPart", MySqlDbType.VarChar) { Value = send.TestPart };
var TestPartobj = TestpartPool.GetById(send.TestPart);
MySqlParameter paramTestPartDisplayer = new MySqlParameter("@TestPartDisplayer", MySqlDbType.VarChar);
if (TestPartobj != null)
{
paramTestPartDisplayer = new MySqlParameter("@TestPartDisplayer", MySqlDbType.VarChar) { Value = TestPartobj.PartName };
}
MySqlParameter paramPartAvg = new MySqlParameter("@PartAvg", MySqlDbType.VarChar) { Value = send.PartAvg };
MySqlParameter paramPartMax = new MySqlParameter("@PartMax", MySqlDbType.VarChar) { Value = send.PartMax };
MySqlParameter paramPartMin = new MySqlParameter("@PartMin", MySqlDbType.VarChar) { Value = send.PartMin };
MySqlParameter paramAnalysisResult = new MySqlParameter("@AnalysisResult", MySqlDbType.VarChar) { Value = send.AnalysisResult };
MySqlParameter paramCreateBy = new MySqlParameter("@CreateBy", MySqlDbType.VarChar) { Value = currentUserId };
MySqlParameter paramCreateTime = new MySqlParameter("@CreateTime", MySqlDbType.DateTime) { Value = send.CreateTime == null ? System.DateTime.Now : send.CreateTime };
MySqlParameter paramModifyBy = new MySqlParameter("@ModifyBy", MySqlDbType.VarChar) { Value = currentUserId };
MySqlParameter paramModifyTime = new MySqlParameter("@ModifyTime", MySqlDbType.DateTime) { Value = send.ModifyTime == null ? System.DateTime.Now : send.ModifyTime };
MySqlParameter paramIsActive = new MySqlParameter("@IsActive", MySqlDbType.Int16) { Value = 1 };
DataTable dt = MysqlHelper.ExecuteDataTable(connection, "select ValueCode from TestPartValue where RecId <> @RecId and ValueCode = @ValueCode and IsActive > 0 limit 1",
paramRecId, paramValueCode);
if (dt.Rows.Count > 0)
{
OutEntity oex1 = new OutEntity() { ErrorCode = ErrorCode.UnexpectError, ErrorMessage = "当前编号:" + dt.Rows[0][0].ToString() + "已添加" };
return JsonConvert.SerializeObject(oex1);
}
dt = MysqlHelper.ExecuteDataTable(connection, "select RecId from TestPartValue where RecId = @RecId and IsActive > 0 limit 1", paramRecId);
var opertype = "";
if (dt.Rows.Count == 0)
{
opertype = ((int)AppEnum.OperType.New).ToString();
if (string.IsNullOrEmpty(send.RecId))
{
paramRecId.Value = Guid.NewGuid().ToString();
}
paramIsActive.Value = 1;
MysqlHelper.ExecuteNonQuery(connection, "insert into TestPartValue (RecId,ValueCode,ValueName,ReferenceId,ReferenceType,TestPart,TestPartDisplayer,PartAvg,PartMax,PartMin,AnalysisResult,CreateBy,CreateTime,ModifyBy,ModifyTime,IsActive) values (@RecId,@ValueCode,@ValueName,@ReferenceId,@ReferenceType,@TestPart,@TestPartDisplayer,@PartAvg,@PartMax,@PartMin,@AnalysisResult,@CreateBy,@CreateTime,@ModifyBy,@ModifyTime,@IsActive)",
new MySqlParameter[] { paramRecId, paramValueCode, paramValueName, paramReferenceId, paramReferenceType, paramTestPart, paramTestPartDisplayer, paramPartAvg, paramPartMax, paramPartMin, paramAnalysisResult, paramCreateBy, paramCreateTime, paramModifyBy, paramModifyTime, paramIsActive });
}
else
{
opertype = ((int)AppEnum.OperType.Modify).ToString();
MysqlHelper.ExecuteNonQuery(connection, "update TestPartValue set ValueCode = @ValueCode, ValueName = @ValueName, ReferenceId = @ReferenceId, ReferenceType = @ReferenceType, TestPart = @TestPart, TestPartDisplayer = @TestPartDisplayer, PartAvg = @PartAvg, PartMax = @PartMax, PartMin = @PartMin, AnalysisResult = @AnalysisResult, ModifyBy = @ModifyBy, ModifyTime = @ModifyTime,IsActive = @IsActive where RecId = @RecId",
new MySqlParameter[] { paramValueCode, paramValueName, paramReferenceId, paramReferenceType, paramTestPart, paramTestPartDisplayer, paramPartAvg, paramPartMax, paramPartMin, paramAnalysisResult, paramModifyBy, paramModifyTime, paramIsActive, paramRecId });
}
//更新扩展字段
SysDefineExtensionValue.SaveResultForTable(connection, currentUserId, currentClientId, se.SendPair, _onlyTableName, paramRecId.Value.ToString());
//save log
InsertToLog(connection, paramRecId.Value.ToString(), currentUserId, opertype);
//更新池
TestpartvaluePool.Update(LoadResult(connection, paramRecId.Value.ToString()));
tranScope.Complete();
OutEntity oe = new OutEntity() { ErrorCode = ErrorCode.Success, ReturnObj = paramRecId.Value.ToString() };
return JsonConvert.SerializeObject(oe);
}
}
}
}
public static string SaveResultByCode(MySqlConnection connection, string currentUserId, TestpartvalueEntity send)
{
lock(lockobj)
{
MySqlParameter paramRecId = new MySqlParameter("@RecId", MySqlDbType.VarChar) { Value = send.RecId };
MySqlParameter paramValueCode = new MySqlParameter("@ValueCode", MySqlDbType.VarChar) { Value = send.ValueCode };
MySqlParameter paramValueName = new MySqlParameter("@ValueName", MySqlDbType.VarChar) { Value = send.ValueName };
MySqlParameter paramReferenceId = new MySqlParameter("@ReferenceId", MySqlDbType.VarChar) { Value = send.ReferenceId };
MySqlParameter paramReferenceType = new MySqlParameter("@ReferenceType", MySqlDbType.VarChar) { Value = send.ReferenceType };
MySqlParameter paramTestPart = new MySqlParameter("@TestPart", MySqlDbType.VarChar) { Value = send.TestPart };
var TestPartobj = TestpartPool.GetById(send.TestPart);
MySqlParameter paramTestPartDisplayer = new MySqlParameter("@TestPartDisplayer", MySqlDbType.VarChar);
if (TestPartobj != null)
{
paramTestPartDisplayer = new MySqlParameter("@TestPartDisplayer", MySqlDbType.VarChar) { Value = TestPartobj.PartName };
}
MySqlParameter paramPartAvg = new MySqlParameter("@PartAvg", MySqlDbType.VarChar) { Value = send.PartAvg };
MySqlParameter paramPartMax = new MySqlParameter("@PartMax", MySqlDbType.VarChar) { Value = send.PartMax };
MySqlParameter paramPartMin = new MySqlParameter("@PartMin", MySqlDbType.VarChar) { Value = send.PartMin };
MySqlParameter paramAnalysisResult = new MySqlParameter("@AnalysisResult", MySqlDbType.VarChar) { Value = send.AnalysisResult };
MySqlParameter paramCreateBy = new MySqlParameter("@CreateBy", MySqlDbType.VarChar) { Value = currentUserId };
MySqlParameter paramCreateTime = new MySqlParameter("@CreateTime", MySqlDbType.DateTime) { Value = send.CreateTime == null ? System.DateTime.Now : send.CreateTime };
MySqlParameter paramModifyBy = new MySqlParameter("@ModifyBy", MySqlDbType.VarChar) { Value = currentUserId };
MySqlParameter paramModifyTime = new MySqlParameter("@ModifyTime", MySqlDbType.DateTime) { Value = send.ModifyTime == null ? System.DateTime.Now : send.ModifyTime };
MySqlParameter paramIsActive = new MySqlParameter("@IsActive", MySqlDbType.Int16) { Value = 1 };
DataTable dt = MysqlHelper.ExecuteDataTable(connection, "select RecId from TestPartValue where ValueCode = @ValueCode and IsActive > 0 limit 1", paramValueCode);
var opertype = "";
if (dt.Rows.Count == 0)
{
opertype = ((int)AppEnum.OperType.New).ToString();
paramRecId.Value = Guid.NewGuid().ToString();
paramIsActive.Value = 1;
MysqlHelper.ExecuteNonQuery(connection, "insert into TestPartValue (RecId,ValueCode,ValueName,ReferenceId,ReferenceType,TestPart,TestPartDisplayer,PartAvg,PartMax,PartMin,AnalysisResult,CreateBy,CreateTime,ModifyBy,ModifyTime,IsActive) values (@RecId,@ValueCode,@ValueName,@ReferenceId,@ReferenceType,@TestPart,@TestPartDisplayer,@PartAvg,@PartMax,@PartMin,@AnalysisResult,@CreateBy,@CreateTime,@ModifyBy,@ModifyTime,@IsActive)",
new MySqlParameter[] { paramRecId, paramValueCode, paramValueName, paramReferenceId, paramReferenceType, paramTestPart, paramTestPartDisplayer, paramPartAvg, paramPartMax, paramPartMin, paramAnalysisResult, paramCreateBy, paramCreateTime, paramModifyBy, paramModifyTime, paramIsActive });
}
else
{
opertype = ((int)AppEnum.OperType.Modify).ToString();
paramRecId.Value = dt.Rows[0][0].ToString();
MysqlHelper.ExecuteNonQuery(connection, "update TestPartValue set ValueCode = @ValueCode, ValueName = @ValueName, ReferenceId = @ReferenceId, ReferenceType = @ReferenceType, TestPart = @TestPart, TestPartDisplayer = @TestPartDisplayer, PartAvg = @PartAvg, PartMax = @PartMax, PartMin = @PartMin, AnalysisResult = @AnalysisResult, ModifyBy = @ModifyBy,ModifyTime = @ModifyTime,IsActive = @IsActive where RecId = @RecId",
new MySqlParameter[] { paramValueCode, paramValueName, paramReferenceId, paramReferenceType, paramTestPart, paramTestPartDisplayer, paramPartAvg, paramPartMax, paramPartMin, paramAnalysisResult, paramModifyBy, paramModifyTime, paramIsActive, paramRecId });
}
//更新池,由于事物可能未提交,先不更新缓存,在提交后在更新缓存
//TestpartvaluePool.Update(LoadResult(connection, paramRecId.Value.ToString()));
//save log
InsertToLog(connection, paramRecId.Value.ToString(), currentUserId, opertype);
return paramRecId.Value.ToString();
}
}
public static string SaveResultByCode(string currentUserId, TestpartvalueEntity send)
{
string recId = string.Empty;
using (var tranScope = new TransactionScope())
{
string connectionString = AppHelper.GetLinkString();
using (MySqlConnection connection = new MySqlConnection(connectionString))
{
recId = SaveResultByCode(connection, currentUserId, send);
tranScope.Complete();
//更新池
TestpartvaluePool.Update(LoadResult(connection, recId));
}
}
return recId;
}
public static string LoadResult(string currentUserId, string currentClientId, string currentSendParameter)
{
var send = JsonConvert.DeserializeObject(currentSendParameter, typeof(TestpartvalueEntity)) as TestpartvalueEntity;
var data = LoadResult(send.RecId);
var extend = SysDefineExtensionValue.LoadResultByTableNameAndRefrenceId(_onlyTableName, send.RecId, currentUserId);
BaseSendEntity bse = new BaseSendEntity()
{
SendKey = JsonConvert.SerializeObject(data),
SendPair = extend.Any() ? JsonConvert.SerializeObject(extend) : null
};
OutEntity oe = new OutEntity() { ErrorCode = ErrorCode.Success, ReturnObj = JsonConvert.SerializeObject(bse) };
return JsonConvert.SerializeObject(oe);
}
public static string DeleteResult(string currentUserId, string currentClientId, string currentSendParameter)
{
using (var tranScope = new TransactionScope())
{
string connectionString = AppHelper.GetLinkString();
using (MySqlConnection connection = new MySqlConnection(connectionString))
{
JArray listSendID = (JArray)JsonConvert.DeserializeObject(currentSendParameter);
foreach (var send in listSendID)
{
string value = (((Newtonsoft.Json.Linq.JValue)(send))).Value.ToString();
MySqlParameter paramRecId = new MySqlParameter("@RecId", MySqlDbType.VarChar) { Value = value };
MysqlHelper.ExecuteNonQuery(connection, "update TestPartValue set IsActive =0 where RecId=@RecId", paramRecId);
//更新池
TestpartvaluePool.Delete(value);
//save log
InsertToLog(connection, value, currentUserId, ((int)AppEnum.OperType.Delete).ToString());
}
tranScope.Complete();
OutEntity oe = new OutEntity() { ErrorCode = ErrorCode.Success, ReturnObj = JsonConvert.SerializeObject(true) };
return JsonConvert.SerializeObject(oe);
}
}
}
public static string LoadLogResults(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 keyword1 = GetConditionValue(ce, "KeyWord1");
string keyword2 = GetConditionValue(ce, "KeyWord2");
string dateFrom = GetConditionValue(ce, "DateFrom");
string dateTo = GetConditionValue(ce, "DateTo");
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);
int count = 0;
string fromwhere = QueryFromWhere(dateFrom, dtStart, dtEnd, keyword1, keyword2);
DataTable dt = MysqlHelper.GetPager(out count, _log_fields, _log_tableName, fromwhere, se.OrderBy, se.SortOrder, se.PageIndex, se.Rows);
List<TestpartvalueLogEntityExtension> rows = MysqlHelper.DataTableToIList<TestpartvalueLogEntityExtension>(dt) as List<TestpartvalueLogEntityExtension>;
foreach (var row in rows)
{
ConvertSingleData(row);
}
RecordEntity result = new RecordEntity();
result.total = (int)Math.Ceiling(count * 1.0 / se.Rows);
result.page = se.PageIndex;
result.records = se.PageIndex;
result.rows = rows;
OutEntity oe = new OutEntity() { ErrorCode = ErrorCode.Success, ReturnObj = JsonConvert.SerializeObject(result) };
return JsonConvert.SerializeObject(oe);
}
public static string ExportResults(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 keyword1 = GetConditionValue(ce, "KeyWord1");
string keyword2 = GetConditionValue(ce, "KeyWord2");
string dateFrom = GetConditionValue(ce, "DateFrom");
string dateTo = GetConditionValue(ce, "DateTo");
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);
string fromwhere = QueryFromWhere(dateFrom, dtStart, dtEnd, keyword1, keyword2);
string sqlStr = string.Format("select {0} from {1} where 1=1 {2}", _fields, _tableName, fromwhere);
DataTable dt = MysqlHelper.ExecuteDataTable(sqlStr);
List<TestpartvalueEntityExtension> datas = MysqlHelper.DataTableToIList<TestpartvalueEntityExtension>(dt) as List<TestpartvalueEntityExtension>;
HSSFWorkbook hssfworkbook = new HSSFWorkbook();
ISheet sheet1 = hssfworkbook.CreateSheet("Sheet1");
IRow row0 = sheet1.CreateRow(0);
int colIndex = 0;
row0.CreateCell(colIndex).SetCellValue("RecId"); colIndex++;
row0.CreateCell(colIndex).SetCellValue("ValueCode"); colIndex++;
row0.CreateCell(colIndex).SetCellValue("ValueName"); colIndex++;
row0.CreateCell(colIndex).SetCellValue("ReferenceId"); colIndex++;
row0.CreateCell(colIndex).SetCellValue("ReferenceType"); colIndex++;
row0.CreateCell(colIndex).SetCellValue("TestPart"); colIndex++;
row0.CreateCell(colIndex).SetCellValue("TestPartDisplayer"); colIndex++;
row0.CreateCell(colIndex).SetCellValue("PartAvg"); colIndex++;
row0.CreateCell(colIndex).SetCellValue("PartMax"); colIndex++;
row0.CreateCell(colIndex).SetCellValue("PartMin"); colIndex++;
row0.CreateCell(colIndex).SetCellValue("AnalysisResult"); colIndex++;
row0.CreateCell(colIndex).SetCellValue("CreateBy"); colIndex++;
row0.CreateCell(colIndex).SetCellValue("CreateTime"); colIndex++;
row0.CreateCell(colIndex).SetCellValue("ModifyBy"); colIndex++;
row0.CreateCell(colIndex).SetCellValue("ModifyTime"); colIndex++;
row0.CreateCell(colIndex).SetCellValue("IsActive"); colIndex++;
int rowIndex = 1;
foreach (var data in datas)
{
IRow row = sheet1.CreateRow(rowIndex);
colIndex = 0;
row.CreateCell(colIndex).SetCellValue(data.RecId); colIndex++;
row.CreateCell(colIndex).SetCellValue(data.ValueCode); colIndex++;
row.CreateCell(colIndex).SetCellValue(data.ValueName); colIndex++;
row.CreateCell(colIndex).SetCellValue(data.ReferenceId); colIndex++;
row.CreateCell(colIndex).SetCellValue(data.ReferenceType); colIndex++;
row.CreateCell(colIndex).SetCellValue(data.TestPart); colIndex++;
row.CreateCell(colIndex).SetCellValue(data.TestPartDisplayer); colIndex++;
row.CreateCell(colIndex).SetCellValue(data.PartAvg.ToString()); colIndex++;
row.CreateCell(colIndex).SetCellValue(data.PartMax.ToString()); colIndex++;
row.CreateCell(colIndex).SetCellValue(data.PartMin.ToString()); colIndex++;
row.CreateCell(colIndex).SetCellValue(data.AnalysisResult); colIndex++;
row.CreateCell(colIndex).SetCellValue(data.CreateBy); colIndex++;
row.CreateCell(colIndex).SetCellValue(data.CreateTime.ToString()); colIndex++;
row.CreateCell(colIndex).SetCellValue(data.ModifyBy); colIndex++;
row.CreateCell(colIndex).SetCellValue(data.ModifyTime.ToString()); colIndex++;
row.CreateCell(colIndex).SetCellValue(data.IsActive.ToString()); colIndex++;
rowIndex++;
}
//set range border
AppHelper.SetBorder(hssfworkbook, 0, rowIndex, colIndex);
string fileName = string.Format("{0}.xls", Guid.NewGuid());
string xlsPath = string.Format("{0}\\{1}", SystemConst.CurrentExcelPath, fileName);
FileStream fs = new FileStream(xlsPath, FileMode.CreateNew, FileAccess.Write);
hssfworkbook.Write(fs);
fs.Close();
OutEntity oe = new OutEntity() { ErrorCode = ErrorCode.Success, ReturnObj = JsonConvert.SerializeObject(string.Format("{0}{1}", SystemConst.CurrentExcelLinkFolder, fileName)) };
return JsonConvert.SerializeObject(oe);
}
public static string ExportLogResults(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 keyword1 = GetConditionValue(ce, "KeyWord1");
string keyword2 = GetConditionValue(ce, "KeyWord2");
string dateFrom = GetConditionValue(ce, "DateFrom");
string dateTo = GetConditionValue(ce, "DateTo");
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);
string fromwhere = QueryFromWhere(dateFrom, dtStart, dtEnd, keyword1, keyword2);
string sqlStr = string.Format("select {0} from {1} where 1=1 {2}", _log_fields, _log_tableName, fromwhere);
DataTable dt = MysqlHelper.ExecuteDataTable(sqlStr);
List<TestpartvalueLogEntityExtension> datas = MysqlHelper.DataTableToIList<TestpartvalueLogEntityExtension>(dt) as List<TestpartvalueLogEntityExtension>;
HSSFWorkbook hssfworkbook = new HSSFWorkbook();
ISheet sheet1 = hssfworkbook.CreateSheet("Sheet1");
IRow row0 = sheet1.CreateRow(0);
int colIndex = 0;
row0.CreateCell(colIndex).SetCellValue("LogId"); colIndex++;
row0.CreateCell(colIndex).SetCellValue("RecId"); colIndex++;
row0.CreateCell(colIndex).SetCellValue("ValueCode"); colIndex++;
row0.CreateCell(colIndex).SetCellValue("ValueName"); colIndex++;
row0.CreateCell(colIndex).SetCellValue("ReferenceId"); colIndex++;
row0.CreateCell(colIndex).SetCellValue("ReferenceType"); colIndex++;
row0.CreateCell(colIndex).SetCellValue("TestPart"); colIndex++;
row0.CreateCell(colIndex).SetCellValue("TestPartDisplayer"); colIndex++;
row0.CreateCell(colIndex).SetCellValue("PartAvg"); colIndex++;
row0.CreateCell(colIndex).SetCellValue("PartMax"); colIndex++;
row0.CreateCell(colIndex).SetCellValue("PartMin"); colIndex++;
row0.CreateCell(colIndex).SetCellValue("AnalysisResult"); colIndex++;
row0.CreateCell(colIndex).SetCellValue("CreateBy"); colIndex++;
row0.CreateCell(colIndex).SetCellValue("CreateTime"); colIndex++;
row0.CreateCell(colIndex).SetCellValue("ModifyBy"); colIndex++;
row0.CreateCell(colIndex).SetCellValue("ModifyTime"); colIndex++;
row0.CreateCell(colIndex).SetCellValue("IsActive"); colIndex++;
row0.CreateCell(colIndex).SetCellValue("OperTime"); colIndex++;
row0.CreateCell(colIndex).SetCellValue("OperUser"); colIndex++;
row0.CreateCell(colIndex).SetCellValue("OperType"); colIndex++;
row0.CreateCell(colIndex).SetCellValue("OperInfo"); colIndex++;
int rowIndex = 1;
foreach (var data in datas)
{
IRow row = sheet1.CreateRow(rowIndex);
colIndex = 0;
row.CreateCell(colIndex).SetCellValue(data.LogId); colIndex++;
row.CreateCell(colIndex).SetCellValue(data.RecId); colIndex++;
row.CreateCell(colIndex).SetCellValue(data.ValueCode); colIndex++;
row.CreateCell(colIndex).SetCellValue(data.ValueName); colIndex++;
row.CreateCell(colIndex).SetCellValue(data.ReferenceId); colIndex++;
row.CreateCell(colIndex).SetCellValue(data.ReferenceType); colIndex++;
row.CreateCell(colIndex).SetCellValue(data.TestPart); colIndex++;
row.CreateCell(colIndex).SetCellValue(data.TestPartDisplayer); colIndex++;
row.CreateCell(colIndex).SetCellValue(data.PartAvg.ToString()); colIndex++;
row.CreateCell(colIndex).SetCellValue(data.PartMax.ToString()); colIndex++;
row.CreateCell(colIndex).SetCellValue(data.PartMin.ToString()); colIndex++;
row.CreateCell(colIndex).SetCellValue(data.AnalysisResult); colIndex++;
row.CreateCell(colIndex).SetCellValue(data.CreateBy); colIndex++;
row.CreateCell(colIndex).SetCellValue(data.CreateTime.ToString()); colIndex++;
row.CreateCell(colIndex).SetCellValue(data.ModifyBy); colIndex++;
row.CreateCell(colIndex).SetCellValue(data.ModifyTime.ToString()); colIndex++;
row.CreateCell(colIndex).SetCellValue(data.IsActive.ToString()); colIndex++;
row.CreateCell(colIndex).SetCellValue(data.OperTime.ToString()); colIndex++;
row.CreateCell(colIndex).SetCellValue(data.OperUser); colIndex++;
row.CreateCell(colIndex).SetCellValue(data.OperType); colIndex++;
row.CreateCell(colIndex).SetCellValue(data.OperInfo); colIndex++;
rowIndex++;
}
//set range border
AppHelper.SetBorder(hssfworkbook, 0, rowIndex, colIndex);
string fileName = string.Format("{0}.xls", Guid.NewGuid());
string xlsPath = string.Format("{0}\\{1}", SystemConst.CurrentExcelPath, fileName);
FileStream fs = new FileStream(xlsPath, FileMode.CreateNew, FileAccess.Write);
hssfworkbook.Write(fs);
fs.Close();
OutEntity oe = new OutEntity() { ErrorCode = ErrorCode.Success, ReturnObj = JsonConvert.SerializeObject(string.Format("{0}{1}", SystemConst.CurrentExcelLinkFolder, fileName)) };
return JsonConvert.SerializeObject(oe);
}
private static string DealCellValue(IRow row, int index)
{
if (row.GetCell(index) == null)
return "";
return row.GetCell(index).CellType == CellType.Formula ? row.GetCell(index).StringCellValue : row.GetCell(index).ToString();
}
}
}