天津投入产出系统后端
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.
 
 
 
 
 
 

726 lines
27 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMAPP.DAL;
using QMFrameWork.Data;
using QMAPP.FJC.Entity.Operation;
using System.Data;
using QMFrameWork.Log;
using QMAPP.Entity;
namespace QMAPP.FJC.DAL.Operation
{
/// <summary>
/// 抽检
/// 郭兆福
/// 20180529
/// </summary>
public class ProductCheckDAL : BaseDAL
{
#region 获取信息
/// <summary>
/// 获取信息
/// </summary>
/// <param name="">条件</param>
/// <returns>信息</returns>
public ProductCheck Get(ProductCheck model)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = "SELECT * FROM T_AW_PRODUCTCHECK WHERE '1'='1'";
if (string.IsNullOrEmpty(model.PID) == false)
{
sql += " AND PID = @PID";
parameters.Add(new DataParameter("PID", model.PID));
}
if (string.IsNullOrEmpty(model.PRODUCTCODE) == false)
{
sql += " AND PRODUCTCODE = @PRODUCTCODE";
parameters.Add(new DataParameter("PRODUCTCODE", model.PRODUCTCODE));
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
string sqlChange = this.ChangeSqlByDB(sql, session);
//获取信息
model = session.Get<ProductCheck>(sqlChange, parameters.ToArray());
}
return model;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "信息数据层-获取信息");
throw ex;
}
}
#endregion
#region 获取列表
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataPage GetList(ProductCheck condition, DataPage page)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetQuerySql(condition, ref parameters);
//分页关键字段及排序
page.KeyName = "PID";
if (string.IsNullOrEmpty(page.SortExpression))
{
page.SortExpression = "CREATEDATE DESC";
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
page = session.GetDataPage<ProductCheck>(sql, parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public List<ProductCheck> GetList(string[] idarray)
{
StringBuilder sql = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql.AppendLine("SELECT * FROM T_AW_PRODUCTCHECK");
sql.Append(" WHERE PID IN (");
for (int i=0;i<idarray.Length;i++)
{
sql.AppendFormat(i > 0 ? ",@id{0}" : "@id{0}", i);
parameters.Add(new DataParameter(string.Format("id{0}", i), idarray[i]));
}
sql.AppendLine(")");
sql.AppendLine(" ORDER BY CREATEDATE ASC");
using (IDataSession session = AppDataFactory.CreateMainSession())
{
return session.GetList<ProductCheck>(sql.ToString(), parameters.ToArray()).ToList();
}
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取查询语句
/// <summary>
/// 获取查询语句
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
private string GetQuerySql(ProductCheck condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.AppendLine(" SELECT P.PID,");
sqlBuilder.AppendLine(" P.PRODUCTCODE,");
sqlBuilder.AppendLine(" P.MATERIAL_CODE,");
sqlBuilder.AppendLine(" M.MATERIAL_NAME,");
sqlBuilder.AppendLine(" P.CHECKRESULT,");
sqlBuilder.AppendLine(" P.CREATEDATE,");
sqlBuilder.AppendLine(" P.PRODUCTCHECKTYPE,");
sqlBuilder.AppendLine(" C.USERNAME AS CREATEUSERNAME, ");
//sqlBuilder.AppendLine(" A.CREATEDATE AS PRODUCEDATE,");
sqlBuilder.AppendLine(" P.CREATEUSER");
sqlBuilder.AppendLine(" FROM T_AW_PRODUCTCHECK P");
sqlBuilder.AppendLine(" LEFT JOIN T_MD_MATERIAL M on M.MATERIAL_CODE=P.MATERIAL_CODE ");
//sqlBuilder.AppendLine(" LEFT JOIN T_AW_PRODUCT A on A.PRODUCTCODE=P.PRODUCTCODE ");
sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER C ON C.USERID=P.CREATEUSER ");
//查询条件
if (string.IsNullOrEmpty(condition.MATERIAL_CODE) == false)
{
whereBuilder.Append(" AND P.MATERIAL_CODE LIKE '%'+" + "@MATERIAL_CODE" + "+'%'");
parameters.Add(new DataParameter { ParameterName = "MATERIAL_CODE", DataType = DbType.String, Value = condition.MATERIAL_CODE });
}
if (string.IsNullOrEmpty(condition.CHECKRESULT) == false)
{
whereBuilder.Append(" AND P.CHECKRESULT=@CHECKRESULT ");
parameters.Add(new DataParameter { ParameterName = "CHECKRESULT", DataType = DbType.String, Value = condition.CHECKRESULT });
}
if (string.IsNullOrEmpty(condition.PRODUCTCHECKTYPE) == false)
{
whereBuilder.Append(" AND P.PRODUCTCHECKTYPE=@PRODUCTCHECKTYPE ");
parameters.Add(new DataParameter { ParameterName = "PRODUCTCHECKTYPE", DataType = DbType.String, Value = condition.PRODUCTCHECKTYPE });
}
if (string.IsNullOrEmpty(condition.PRODUCTCODE) == false)
{
whereBuilder.Append(" AND P.PRODUCTCODE LIKE '%'+" + "@PRODUCTCODE" + "+'%' ");
parameters.Add(new DataParameter { ParameterName = "PRODUCTCODE", DataType = DbType.String, Value = condition.PRODUCTCODE });
}
//时间
if (condition.CREATEDATESTART != DateTime.MinValue)
{
whereBuilder.Append(" AND P.CREATEDATE>@CREATEDATESTART ");
parameters.Add(new DataParameter { ParameterName = "CREATEDATESTART", DataType = DbType.String, Value = condition.CREATEDATESTART.ToString("yyyy-MM-dd HH:mm:ss") });
}
if (condition.CREATEDATEEND != DateTime.MinValue)
{
whereBuilder.Append(" AND P.CREATEDATE<@CREATEDATEEND ");
parameters.Add(new DataParameter { ParameterName = "CREATEDATEEND", DataType = DbType.String, Value = condition.CREATEDATEEND.ToString("yyyy-MM-dd HH:mm:ss") });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取配置表列表
/// <summary>
/// 获取配置表列表
/// </summary>
/// <param name="condition"></param>
/// <param name="page"></param>
/// <returns></returns>
public CheckWithMaterial GetCheckWithMaterial(CheckWithMaterial condition)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetQuerySqlCheck(condition, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
condition = session.Get<CheckWithMaterial>(sql, parameters.ToArray());
}
return condition;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取配置表信息
/// <summary>
/// 获取配置表信息
/// </summary>
/// <param name="">条件</param>
/// <returns>*信息</returns>
public List<CheckWithMaterial> GetCheckWithMaterialInfo(CheckWithMaterial condition)
{
string sql = null;
List<CheckWithMaterial> materiallist = new List<CheckWithMaterial>();
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetQuerySqlCheck(condition, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//获取信息
materiallist = session.GetList<CheckWithMaterial>(sql, parameters.ToArray()).ToList();
}
return materiallist;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "物料本体-获取信息"
});
throw;
}
}
#endregion
#region 确认保存时是否已存在
/// <summary>
/// 确认保存时是否已存在
/// 存在则更新,不存在插入
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public CheckValueItem GetDetailInfo(CheckValueItem model)
{
string sql = null;
//int count = 0;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetCheckValueItemSql(model, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//count = Convert.ToInt32(session.GetTable(sql, parameters.ToArray()).Rows.Count);
model = session.Get<CheckValueItem>(sql, parameters.ToArray());
}
return model;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "信息数据层-获取信息"
});
throw;
}
}
#endregion
#region 插入信息 T_AW_CHECKVALUEITEM表
/// <summary>
/// 插入信息 T_AW_CHECKVALUEITEM表
/// </summary>
/// <param name="list"></param>
/// <returns></returns>
public int InsertCheckValue(List<CheckValueItem> list)
{
ImportMessage em = new ImportMessage();
int count = 0;
List<DataParameter> parameters = new List<DataParameter>();
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//设置祖先对象数据会话
session.OpenTs();
foreach (CheckValueItem info in list)
{
count = session.Insert<CheckValueItem>(info);
}
session.CommitTs();
}
}
catch (Exception ex)
{
throw ex;
}
return count;
}
#endregion
#region 更新T_AW_CHECKVALUEITEM信息
/// <summary>
/// 更新T_AW_CHECKVALUEITEM信息
/// </summary>
/// <param name=""></param>
/// <returns>更新行数</returns>
public int UpdateCheckValue(List<CheckValueItem> list)
{
ImportMessage em = new ImportMessage();
int count = 0;
List<DataParameter> parameters = new List<DataParameter>();
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//设置祖先对象数据会话
session.OpenTs();
foreach (CheckValueItem info in list)
{
count = session.Update<CheckValueItem>(info);
}
session.CommitTs();
}
}
catch (Exception ex)
{
throw ex;
}
return count;
}
#endregion
#region 插入信息(T_AW_PRODUCTCHECK)
/// <summary>
/// 插入信息(T_AW_PRODUCTCHECK)
/// </summary>
/// <param name="">信息</param>
/// <returns>插入行数</returns>
public int InsertProductCheck(ProductCheck model)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//插入基本信息
count = session.Insert<ProductCheck>(model);
}
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 更新信息(T_AW_PRODUCTCHECK)
/// <summary>
/// 更新信息(T_AW_PRODUCTCHECK)
/// </summary>
/// <param name="">信息</param>
/// <returns>行数</returns>
public int UpdateProductCheck(ProductCheck model)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//插入基本信息
count = session.Update<ProductCheck>(model);
}
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取T_AW_CHECKVALUEITEM查询语句
/// <summary>
/// 获取T_AW_CHECKVALUEITEM查询语句
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
private string GetCheckValueItemSql(CheckValueItem condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.AppendLine(" SELECT C.PID,");
sqlBuilder.AppendLine(" C.PRODUCTCHECK_PID,");
sqlBuilder.AppendLine(" C.CHECKITEMCODE,");
sqlBuilder.AppendLine(" C.INPUTVALUE,");
sqlBuilder.AppendLine(" C.CREATEDATE,");
sqlBuilder.AppendLine(" C.CREATEUSER");
sqlBuilder.AppendLine(" FROM T_AW_CHECKVALUEITEM C");
//查询条件
if (string.IsNullOrEmpty(condition.PRODUCTCHECK_PID) == false)
{
whereBuilder.Append(" AND C.PRODUCTCHECK_PID =@PRODUCTCHECK_PID");
parameters.Add(new DataParameter { ParameterName = "PRODUCTCHECK_PID", DataType = DbType.String, Value = condition.PRODUCTCHECK_PID });
}
if (string.IsNullOrEmpty(condition.CHECKITEMCODE) == false)
{
whereBuilder.Append(" AND C.CHECKITEMCODE =@CHECKITEMCODE");
parameters.Add(new DataParameter { ParameterName = "CHECKITEMCODE", DataType = DbType.String, Value = condition.CHECKITEMCODE });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取T_AW_CHECKWITHMATERIAL查询语句
/// <summary>
/// 获取T_AW_CHECKWITHMATERIAL查询语句
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
private string GetQuerySqlCheck(CheckWithMaterial condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
if (string.IsNullOrEmpty(condition.PRODUCTCHECK_PID) == true)
{
sqlBuilder.AppendLine(" SELECT P.PID,");
sqlBuilder.AppendLine(" P.MATERIAL_TYPE_CODE,");
sqlBuilder.AppendLine(" P.CHECKITEMCODE,");
sqlBuilder.AppendLine(" P.CHECKITEMNAME,");
sqlBuilder.AppendLine(" P.STANDERDVALUE_DOWN,");
sqlBuilder.AppendLine(" P.STANDERDVALUE_UPPER,");
//sqlBuilder.AppendLine(" C.INPUTVALUE,");
sqlBuilder.AppendLine(" P.INPUTTYPE");
sqlBuilder.AppendLine(" FROM T_AW_CHECKWITHMATERIAL P");
sqlBuilder.AppendLine(" LEFT JOIN T_MD_MATERIAL M on M.MATERIAL_TYPE_CODE=P.MATERIAL_TYPE_CODE ");
//sqlBuilder.AppendLine(" LEFT JOIN T_AW_CHECKVALUEITEM C on C.CHECKITEMCODE=P.CHECKITEMCODE ");
}
else {
sqlBuilder.AppendLine(" SELECT P.PID,");
sqlBuilder.AppendLine(" P.MATERIAL_TYPE_CODE,");
sqlBuilder.AppendLine(" P.CHECKITEMCODE,");
sqlBuilder.AppendLine(" P.CHECKITEMNAME,");
sqlBuilder.AppendLine(" P.STANDERDVALUE_DOWN,");
sqlBuilder.AppendLine(" P.STANDERDVALUE_UPPER,");
sqlBuilder.AppendLine(" C.INPUTVALUE,");
sqlBuilder.AppendLine(" U.USERNAME AS CREATEUSERNAME,");
sqlBuilder.AppendLine(" C.CREATEDATE,");
sqlBuilder.AppendLine(" P.INPUTTYPE");
sqlBuilder.AppendLine(" FROM T_AW_CHECKWITHMATERIAL P");
sqlBuilder.AppendLine(" LEFT JOIN T_MD_MATERIAL M on M.MATERIAL_TYPE_CODE=P.MATERIAL_TYPE_CODE ");
sqlBuilder.AppendLine(" LEFT JOIN T_AW_CHECKVALUEITEM C on C.CHECKITEMCODE=P.CHECKITEMCODE ");
sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER U ON U.USERID=C.CREATEUSER");
}
//查询条件
if (string.IsNullOrEmpty(condition.MATERIAL_CODE) == false)
{
whereBuilder.Append(" AND M.MATERIAL_CODE =@MATERIAL_CODE");
parameters.Add(new DataParameter { ParameterName = "MATERIAL_CODE", DataType = DbType.String, Value = condition.MATERIAL_CODE });
}
if (string.IsNullOrEmpty(condition.CHECKITEMCODE) == false)
{
whereBuilder.Append(" AND P.CHECKITEMCODE =@CHECKITEMCODE");
parameters.Add(new DataParameter { ParameterName = "CHECKITEMCODE", DataType = DbType.String, Value = condition.CHECKITEMCODE });
}
if (string.IsNullOrEmpty(condition.PRODUCTCHECK_PID) == false)
{
whereBuilder.Append(" AND C.PRODUCTCHECK_PID =@PRODUCTCHECK_PID");
parameters.Add(new DataParameter { ParameterName = "PRODUCTCHECK_PID", DataType = DbType.String, Value = condition.PRODUCTCHECK_PID });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 删除
/// <summary>
/// 删除
/// </summary>
/// <param name="pid"></param>
/// <returns></returns>
public int Delete(string pid)
{
int count = 0;
int i =0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//删除基本信息
count = session.Delete<ProductCheck>(new ProductCheck() { PID = pid });
i = DeleteCheckValue(pid);
}
return count;
}
catch (Exception ex)
{
throw ex;
}
}
private int DeleteCheckValue(string pid)
{
string sql = null;
int i = 0;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = "DELETE FROM T_AW_CHECKVALUEITEM WHERE '1'='1'";
if (string.IsNullOrEmpty(pid) == false)
{
sql += " AND PRODUCTCHECK_PID = @PID";
parameters.Add(new DataParameter("PID", pid));
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
string sqlChange = this.ChangeSqlByDB(sql, session);
//获取信息
i = session.ExecuteSql(sqlChange, parameters.ToArray());
}
return i;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "信息数据层-删除信息");
throw ex;
}
}
#endregion
#region 获取列表输入值
/// <summary>
/// 获取列表输入值
/// </summary>
/// <param name="condition">条件</param>
/// <returns>列表</returns>
public List<InputValue> GetInputValueList(InputValue condition)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
List<InputValue> listProcessInfo = new List<InputValue>();
try
{
sql = "SELECT * FROM T_AW_INPUTVALUE WHERE '1'='1'";
if (string.IsNullOrEmpty(condition.CHECKITEMCODE) == false)
{
sql += " AND CHECKITEMCODE = @CHECKITEMCODE";
parameters.Add(new DataParameter("CHECKITEMCODE", condition.CHECKITEMCODE));
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
// 对应多种数据库
string sqlChange = this.ChangeSqlByDB(sql, session);
listProcessInfo = session.GetList<InputValue>(sqlChange, parameters.ToArray()).ToList();
}
return listProcessInfo;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "信息-获取列表");
throw ex;
}
}
#endregion
#region 获取详细信息
/// <summary>
///
/// </summary>
/// <param name="condition"></param>
/// <returns></returns>
public List<CheckWithMaterial> GetProductCheckItemList(CheckWithMaterial condition)
{
string sql = null;
List<CheckWithMaterial> list = new List<CheckWithMaterial>();
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetQuerySqlCheck(condition, ref parameters);
//分页关键字段及排序
using (IDataSession session = AppDataFactory.CreateMainSession())
{
list = session.GetList<CheckWithMaterial>(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
public List<CheckWithMaterial> GetCheckItems(string materialtype)
{
StringBuilder sql = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql.AppendLine("SELECT * FROM T_AW_CHECKWITHMATERIAL");
sql.AppendLine(" WHERE MATERIAL_TYPE_CODE=@materialtype");
sql.AppendLine(" ORDER BY CHECKITEMCODE");
parameters.Add(new DataParameter("materialtype", materialtype));
using (IDataSession session = AppDataFactory.CreateMainSession())
{
return session.GetList<CheckWithMaterial>(sql.ToString(), parameters.ToArray()).ToList();
}
}
catch (Exception ex)
{
throw ex;
}
}
public List<CheckValueItem> GetCheckValueItems(string[] idarray)
{
StringBuilder sql = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql.AppendLine("SELECT * FROM T_AW_CHECKVALUEITEM");
sql.Append(" WHERE PRODUCTCHECK_PID IN (");
for (int i = 0; i < idarray.Length; i++)
{
sql.AppendFormat(i > 0 ? ",@id{0}" : "@id{0}", i);
parameters.Add(new DataParameter(string.Format("id{0}", i), idarray[i]));
}
sql.AppendLine(")");
sql.AppendLine(" ORDER BY CREATEDATE ASC");
using (IDataSession session = AppDataFactory.CreateMainSession())
{
return session.GetList<CheckValueItem>(sql.ToString(), parameters.ToArray()).ToList();
}
}
catch (Exception ex)
{
throw ex;
}
}
}
}