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.
162 lines
5.8 KiB
162 lines
5.8 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using QMAPP.FJC.Entity.Operation;
|
|
using QMFrameWork.Data;
|
|
using QMAPP.DAL;
|
|
using System.Data;
|
|
|
|
namespace QMAPP.FJC.DAL.Operation
|
|
{
|
|
public class InjectionCheckDAL : BaseDAL
|
|
{
|
|
|
|
|
|
#region 插入信息
|
|
/// <summary>
|
|
/// 插入信息(单表)
|
|
/// </summary>
|
|
/// <param name="">信息</param>
|
|
/// <returns>插入行数</returns>
|
|
public int Insert(InjectionCheck model)
|
|
{
|
|
int count = 0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//插入基本信息
|
|
count = session.Insert<InjectionCheck>(model);
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 获取列表
|
|
/// <summary>
|
|
/// 获取列表
|
|
/// </summary>
|
|
/// <param name="condition">条件</param>
|
|
/// <param name="page">数据页</param>
|
|
/// <returns>数据页</returns>
|
|
public DataPage GetList(InjectionCheck condition, DataPage page)
|
|
{
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = this.GetQuerySql(condition, ref parameters);
|
|
//分页关键字段及排序
|
|
page.KeyName = "PID";
|
|
page.SortExpression = "CREATEDATE DESC";
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
page = session.GetDataPage<InjectionCheck>(sql, parameters.ToArray(), page);
|
|
}
|
|
return page;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region 获取查询语句
|
|
/// <summary>
|
|
/// 获取查询语句
|
|
/// </summary>
|
|
/// <param name="user">查询条件</param>
|
|
/// <param name="parameters">参数</param>
|
|
/// <returns>查询语句</returns>
|
|
private string GetQuerySql(InjectionCheck condition, ref List<DataParameter> parameters)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
try
|
|
{
|
|
//构成查询语句
|
|
sqlBuilder.Append("SELECT A.PID,A.PRODUCTCODE,A.PRODUCTTYPE,A.MACHINENAME,A.MACHINECODDE,A.PRODUCEDATE,A.CREATEUSER,A.CREATEDATE,A.UPDATEUSER,A.UPDATEDATE,");
|
|
|
|
//if (condition.INTERNALNUMBER > 0)
|
|
//{
|
|
|
|
//}
|
|
//else
|
|
//{
|
|
// sqlBuilder.Append(" 0 as HAVEINJECTION");
|
|
//}
|
|
sqlBuilder.AppendFormat(" (SELECT COUNT(1) FROM T_AW_INJECTIONRECORDER R WHERE R.MACHINECODDE=A.MACHINECODDE AND DATEDIFF(mi,R.CREATEDATE,A.PRODUCEDATE)<(SELECT CHECKMAXVALUE FROM T_AW_INJECTIONCHECKSET) AND DATEDIFF(mi,R.CREATEDATE,A.PRODUCEDATE)>(SELECT CHECKMINVALUE FROM T_AW_INJECTIONCHECKSET) ) as HAVEINJECTION", condition.INTERNALNUMBER.ToString());
|
|
|
|
sqlBuilder.Append(" FROM T_AW_INJECTIONCHECK A ");
|
|
//whereBuilder.Append(" AND FLGDEL<>1");
|
|
//查询条件
|
|
|
|
whereBuilder.Append(" AND A.CREATEDATE>@CREATEDATESTART ");
|
|
parameters.Add(new DataParameter { ParameterName = "CREATEDATESTART", DataType = DbType.String, Value = condition.CREATEDATESTART.ToString("yyyy-MM-dd HH:mm:ss") });
|
|
|
|
whereBuilder.Append(" AND A.CREATEDATE<@CREATEDATEEND ");
|
|
parameters.Add(new DataParameter { ParameterName = "CREATEDATEEND", DataType = DbType.String, Value = condition.CREATEDATEEND.ToString("yyyy-MM-dd HH:mm:ss") });
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(condition.PRODUCTTYPE) == false)
|
|
{
|
|
whereBuilder.Append(" AND A.PRODUCTTYPE=@PRODUCTTYPE ");
|
|
parameters.Add(new DataParameter { ParameterName = "PRODUCTTYPE", DataType = DbType.String, Value = condition.PRODUCTTYPE });
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(condition.MACHINECODDE) == false)
|
|
{
|
|
whereBuilder.Append(" AND A.MACHINECODDE=@MACHINECODDE ");
|
|
parameters.Add(new DataParameter { ParameterName = "MACHINECODDE", DataType = DbType.String, Value = condition.MACHINECODDE });
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(condition.PRODUCTCODE) == false)
|
|
{
|
|
whereBuilder.Append(" AND A.PRODUCTCODE LIKE '%'+" + "@PRODUCTCODE" + "+'%' ");
|
|
parameters.Add(new DataParameter { ParameterName = "PRODUCTCODE", DataType = DbType.String, Value = condition.PRODUCTCODE });
|
|
}
|
|
|
|
|
|
if (whereBuilder.Length > 0)
|
|
{
|
|
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
|
|
}
|
|
return sqlBuilder.ToString();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
|
|
public int Delete(string pid)
|
|
{
|
|
int count = 0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//插入基本信息
|
|
count = session.Delete<InjectionCheck>(new InjectionCheck() { PID = pid });
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|