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

126 lines
5.2 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMFrameWork.Data;
using QMAPP.FJC.Entity.FeedInManage;
using System.Data;
namespace SimulateServiceHost
{
public class GetListTest
{
public DataPage GetList(Epidermis 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 = "UPDATEDATE DESC";
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
page = session.GetDataPage<Epidermis>(sql, parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
return page;
}
}
private string GetQuerySql(Epidermis condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.Append(@"SELECT
M.PID,
M.PRODUCTTYPE,
M.PRODUCTCODE,
M.MACHINENAME,
M.MACHINECODDE,
M.STATUS,
M.CURRENTPROCESS,
M.PRODUCELINE,
M.PRODUCESHIFTNAME,
M.PRODUCESHIFTTCODE,
M.OUTFLAG,
M.USINGSTATE,
M.CAPACITY,
M.USINGCOUNT,
G.USERNAME AS CREATEUSER,
M.CREATEDATE,
K.USERNAME AS UPDATEUSER,
M.UPDATEDATE ");
sqlBuilder.Append("FROM T_AW_PRODUCT M");
sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER G ON G.USERID=M.CREATEUSER ");
sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER K ON K.USERID=M.UPDATEUSER ");
#region 查询条件
if (condition.STARTCREATEDATE != DateTime.MinValue)
{
whereBuilder.Append(" AND M.CREATEDATE >= @STARTCREATEDATE");
parameters.Add(new DataParameter() { DataType = DbType.String, ParameterName = "STARTCREATEDATE", Value = condition.STARTCREATEDATE.Date.ToString("yyyy-MM-dd HH:mm:ss") });
}
if (condition.ENDCREATEDATE != DateTime.MinValue)
{
whereBuilder.Append(" AND M.CREATEDATE < @ENDCREATEDATE");
parameters.Add(new DataParameter() { DataType = DbType.String, ParameterName = "ENDCREATEDATE", Value = condition.ENDCREATEDATE.Date.AddDays(1).ToString("yyyy-MM-dd HH:mm:ss") });
}
if (string.IsNullOrEmpty(condition.PRODUCTTYPE) == false)
{
whereBuilder.Append(" AND M.PRODUCTTYPE = @PRODUCTTYPE");
parameters.Add(new DataParameter { ParameterName = "PRODUCTTYPE", DataType = DbType.String, Value = condition.PRODUCTTYPE });
}
if (string.IsNullOrEmpty(condition.PRODUCTCODE) == false)
{
whereBuilder.Append(" AND M.PRODUCTCODE LIKE '%'+" + "@PRODUCTCODE" + "+'%'");
parameters.Add(new DataParameter { ParameterName = "PRODUCTCODE", DataType = DbType.String, Value = condition.PRODUCTCODE });
}
if (string.IsNullOrEmpty(condition.MACHINECODDE) == false)
{
whereBuilder.Append(" AND M.MACHINECODDE LIKE '%'+" + "@MACHINECODDE" + "+'%'");
parameters.Add(new DataParameter { ParameterName = "MACHINECODDE", DataType = DbType.String, Value = condition.MACHINECODDE });
}
if (string.IsNullOrEmpty(condition.CURRENTPROCESS) == false)
{
whereBuilder.Append(" AND M.CURRENTPROCESS = @CURRENTPROCESS");
parameters.Add(new DataParameter { ParameterName = "CURRENTPROCESS", DataType = DbType.String, Value = condition.CURRENTPROCESS });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
#endregion
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
}
}