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

771 lines
30 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using QMFrameWork.Data;
using QMAPP.Entity;
using QMAPP.FJC.Entity.ProduceManage;
using QMAPP.FJC.Entity.Operation;
using QMFrameWork.Log;
using QMAPP.DAL;
using QMAPP.FJC.Entity.Injection;
namespace QMAPP.FJC.DAL.Operation
{
/// <summary>
/// 模块编号:
/// 作 用:成品信息查询
/// 作 者:郭兆福
/// 编写日期:2018年03月12日
///</summary>
public class ProductEndDAL : BaseDAL
{
/// <summary>
/// 数据会话
/// </summary>
#region 成品信息查询
#region 获取信息
/// <summary>
/// 获取信息
/// </summary>
/// <param name="">条件</param>
/// <returns>*信息</returns>
public ProductEnd Get(ProductEnd model)
{
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//获取信息
model = session.Get<ProductEnd>(model);
}
return model;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取列表(旧)
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
//public DataPage GetList(ProductEnd 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<ProductEnd>(sql, parameters.ToArray(), page);
// }
// return page;
// }
// catch (Exception ex)
// {
// throw ex;
// }
//}
#region 获取列表
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <returns>全部</returns>
//public List<ProductEnd> GetList(ProductEnd condition)
//{
// string sql = null;
// List<ProductEnd> list = new List<ProductEnd>();
// List<DataParameter> parameters = new List<DataParameter>();
// try
// {
// sql = this.GetQuerySql(condition, ref parameters);
// //分页关键字段及排序
// using (IDataSession session = AppDataFactory.CreateMainSession())
// {
// list = session.GetList<ProductEnd>(sql, parameters.ToArray()).ToList();
// }
// return list;
// }
// catch (Exception ex)
// {
// throw ex;
// }
//}
#endregion
#endregion
#region 获取列表(新)
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataPage GetAllList(ProductEnd condition, DataPage page)
{
string sql = null;
string countSql = null;
List<DataParameter> parameters = new List<DataParameter>();
List<ProductEnd> list = new List<ProductEnd>();
try
{
//分页关键字段及排序
page.KeyName = "PID";
if (string.IsNullOrEmpty(page.SortExpression))
{
page.SortExpression = "UPDATEDATE DESC";
}
sql = this.GetPageQuerySql(condition, ref parameters, page);
countSql = this.GetCountQuerySql(condition);
int sum = 0;
using (IDataSession session = AppDataFactory.CreateMainSession())
{
list = session.GetList<ProductEnd>(sql, parameters.ToArray()).ToList<ProductEnd>();
sum = Convert.ToInt32(session.ExecuteSqlScalar(countSql, parameters.ToArray()));
}
page.RecordCount = sum;
page.Result = list;
#region 设置分页属性
if (page.RecordCount == 0)
{
page.PageIndex = 1;
return page;
}
if (page.RecordCount % page.PageSize != 0)
{
page.PageCount = page.RecordCount / page.PageSize + 1;
if (page.PageCount < page.PageIndex)
{
page.PageIndex = page.PageCount;
}
}
else
{
page.PageCount = page.RecordCount / page.PageSize;
}
if (page.PageCount < page.PageIndex)
{
page.PageIndex = page.PageCount;
}
#endregion
return page;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "获取列表错误!"
});
throw ex;
}
}
#endregion
#region 获取查询语句
#region 查询语句
/// <summary>
/// 获取查询语句
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
private string GetQuerySql(ProductEnd condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.Append("SELECT M.PID ");
sqlBuilder.AppendLine(" ,M.PRODUCTTYPE ");
sqlBuilder.AppendLine(" ,M.PRODUCTCODE ");
sqlBuilder.AppendLine(" ,main.MAINCODE ");
sqlBuilder.AppendLine(" ,M.MACHINENAME ");
sqlBuilder.AppendLine(" ,M.MACHINECODDE ");
sqlBuilder.AppendLine(" ,M.MATERIAL_CODE ");
sqlBuilder.AppendLine(" ,MA.MATERIAL_NAME ");
sqlBuilder.AppendLine(" ,M.STATUS ");
sqlBuilder.AppendLine(" ,M.ISPARENT ");
sqlBuilder.AppendLine(" ,MA.HBTYPE AS HB ");
sqlBuilder.AppendLine(" ,MA.COLOR ");
sqlBuilder.AppendLine(" ,M.CURRENTPROCESS ");
sqlBuilder.AppendLine(" ,M.PRODUCELINE ");
sqlBuilder.AppendLine(" ,M.PRODUCESHIFTNAME ");
sqlBuilder.AppendLine(" ,M.PRODUCESHIFTTCODE ");
sqlBuilder.AppendLine(" ,M.OUTFLAG ");
sqlBuilder.AppendLine(" ,M.USINGSTATE ");
sqlBuilder.AppendLine(" ,M.CAPACITY ");
sqlBuilder.AppendLine(" ,M.USINGCOUNT ");
sqlBuilder.AppendLine(" ,M.WORKCELL_CODE ");
sqlBuilder.AppendLine(" ,M.WORKLOC_CODE ");
sqlBuilder.AppendLine(" ,M.WORKCENTER_CODE ");
sqlBuilder.AppendLine(" ,W.WORKCENTER_NAME ");
sqlBuilder.AppendLine(" ,M.TEAM_CODE ");
sqlBuilder.AppendLine(" ,M.ENDOFLINE ");
sqlBuilder.AppendLine(" ,M.MATERIAL_TYPE ");
sqlBuilder.AppendLine(" ,MC.MATERIAL_TYPE_NAME ");
sqlBuilder.AppendLine(" ,M.CREATEUSER ");
sqlBuilder.AppendLine(" ,M.CREATEDATE ");
sqlBuilder.AppendLine(" ,M.UPDATEUSER ");
sqlBuilder.AppendLine(" ,M.UPDATEDATE ");
sqlBuilder.AppendLine(" ,C.USERNAME AS CREATEUSERNAME ");
sqlBuilder.AppendLine(" ,U.USERNAME AS UPDATEUSERNAME ");
sqlBuilder.AppendLine(" ,M.PLAN_NO ");
sqlBuilder.AppendLine(" ,M.VIN ");
sqlBuilder.AppendLine(" ,M.KIN ");
sqlBuilder.AppendLine(" ,M.VWSEQ ");
sqlBuilder.Append("FROM T_AW_PRODUCT M");
sqlBuilder.Append(" LEFT JOIN T_QM_USER C ON C.USERID=M.CREATEUSER ");
sqlBuilder.Append(" LEFT JOIN T_QM_USER U ON U.USERID=M.UPDATEUSER ");
sqlBuilder.Append(" LEFT JOIN T_MD_MATERIAL MA ON MA.MATERIAL_CODE=M.MATERIAL_CODE ");
sqlBuilder.Append(" LEFT JOIN T_MD_MATERIAL_CLASS MC ON MC.MATERIAL_TYPE_CODE=MA.MATERIAL_TYPE_CODE ");
sqlBuilder.Append(" LEFT JOIN T_MD_WORKCENTER W ON W.WORKCENTER_CODE=M.WORKCENTER_CODE ");
sqlBuilder.Append(" LEFT JOIN T_AW_MAIN main ON main.EPIDERMISCODE=M.PRODUCTCODE ");
//查询条件
whereBuilder.Append(" AND MC.MATERIAL_ATTRIBUTE ='2'");
//成品条码
if (string.IsNullOrEmpty(condition.PRODUCTCODE) == false)
{
whereBuilder.Append(" AND M.PRODUCTCODE = @PRODUCTCODE");
parameters.Add(new DataParameter { ParameterName = "PRODUCTCODE", DataType = DbType.String, Value = condition.PRODUCTCODE });
}
//总成条码
if (string.IsNullOrEmpty(condition.MAINCODE) == false)
{
whereBuilder.Append(" AND main.MAINCODE= @MAINCODE");
parameters.Add(new DataParameter { ParameterName = "MAINCODE", DataType = DbType.String, Value = condition.MAINCODE });
}
//颜色
if (string.IsNullOrEmpty(condition.COLOR) == false)
{
whereBuilder.Append(" AND MA.COLOR =@COLOR");
parameters.Add(new DataParameter { ParameterName = "COLOR", DataType = DbType.String, Value = condition.COLOR });
}
//高低配
if (string.IsNullOrEmpty(condition.HB) == false)
{
whereBuilder.Append(" AND MA.HBTYPE =@HB");
parameters.Add(new DataParameter { ParameterName = "HB", DataType = DbType.String, Value = condition.HB });
}
//成品状态
if (string.IsNullOrEmpty(condition.STATUS) == false)
{
whereBuilder.Append(" AND M.STATUS = @STATUS");
parameters.Add(new DataParameter { ParameterName = "STATUS", DataType = DbType.String, Value = condition.STATUS });
}
//物料号
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.WORKCENTER_CODE) == false)
{
whereBuilder.Append(" AND M.WORKCENTER_CODE =@WORKCENTER_CODE");
parameters.Add(new DataParameter { ParameterName = "WORKCENTER_CODE", DataType = DbType.String, Value = condition.WORKCENTER_CODE });
}
if (string.IsNullOrEmpty(condition.VIN) == false)
{
whereBuilder.AppendFormat(" AND M.VIN LIKE '%{0}%' ",condition.VIN);
//parameters.Add(new DataParameter { ParameterName = "VIN", DataType = DbType.String, Value = condition.VIN });
}
if (string.IsNullOrEmpty(condition.KIN) == false)
{
whereBuilder.AppendFormat(" AND M.KIN LIKE '%{0}%' ",condition.KIN);
//parameters.Add(new DataParameter { ParameterName = "KIN", DataType = DbType.String, Value = condition.KIN });
}
if (string.IsNullOrEmpty(condition.STARTCREATEDATE) == false)
{
whereBuilder.Append(" AND M.CREATEDATE >= @STARTCREATEDATE");
parameters.Add(new DataParameter { ParameterName = "STARTCREATEDATE", DataType = DbType.String, Value = condition.STARTCREATEDATE });
}
if (string.IsNullOrEmpty(condition.ENDCREATEDATE) == false)
{
whereBuilder.Append(" AND M.CREATEDATE <= @ENDCREATEDATE");
parameters.Add(new DataParameter { ParameterName = "ENDCREATEDATE", DataType = DbType.String, Value = condition.ENDCREATEDATE });
}
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="parameters"></param>
/// <param name="page"></param>
/// <returns></returns>
private string GetPageQuerySql(ProductEnd condition, ref List<DataParameter> parameters, DataPage page)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
if (page.SortExpression.Contains("CREATEUSER") == false && page.SortExpression.Contains("UPDATEUSER") == false)
{
page.SortExpression = "M." + page.SortExpression;
}
if (page.SortExpression.Contains("CREATEUSER"))
{
page.SortExpression = page.SortExpression.Substring(page.SortExpression.TrimStart().IndexOf(" "));
page.SortExpression = "U.USERNAME " + page.SortExpression;
}
if (page.SortExpression.Contains("UPDATEUSER"))
{
page.SortExpression = page.SortExpression.Substring(page.SortExpression.TrimStart().IndexOf(" "));
page.SortExpression = "U.USERNAME " + page.SortExpression;
}
sqlBuilder.Append("SELECT * FROM (");
sqlBuilder.AppendFormat(@"SELECT top {0} ROW_NUMBER() OVER (ORDER BY {1} ) AS ROWINDEX,", (page.PageIndex * page.PageSize).ToString(), page.SortExpression);
sqlBuilder.Append(@"
M.PID
,M.PRODUCTTYPE
,M.PRODUCTCODE
,main.MAINCODE
,M.MACHINENAME
,M.MACHINECODDE
,M.MATERIAL_CODE
,MA.MATERIAL_NAME
,M.STATUS
,M.ISPARENT
,MA.HBTYPE AS HB
,MA.COLOR
,M.CURRENTPROCESS
,M.PRODUCELINE
,M.PRODUCESHIFTNAME
,M.PRODUCESHIFTTCODE
,M.OUTFLAG
,M.USINGSTATE
,M.CAPACITY
,M.USINGCOUNT
,M.WORKCELL_CODE
,M.WORKLOC_CODE
,M.WORKCENTER_CODE
,W.WORKCENTER_NAME
,M.TEAM_CODE
,M.ENDOFLINE
,M.MATERIAL_TYPE
,MC.MATERIAL_TYPE_NAME
,M.CREATEUSER
,M.CREATEDATE
,M.UPDATEUSER
,M.UPDATEDATE
,C.USERNAME AS CREATEUSERNAME
,U.USERNAME AS UPDATEUSERNAME
,M.PLAN_NO
,M.VIN
,M.KIN
,M.VWSEQ
");
sqlBuilder.Append("FROM T_AW_PRODUCT M");
sqlBuilder.Append(" LEFT JOIN T_QM_USER C ON C.USERID=M.CREATEUSER ");
sqlBuilder.Append(" LEFT JOIN T_QM_USER U ON U.USERID=M.UPDATEUSER ");
sqlBuilder.Append(" LEFT JOIN T_MD_MATERIAL MA ON MA.MATERIAL_CODE=M.MATERIAL_CODE ");
sqlBuilder.Append(" LEFT JOIN T_MD_MATERIAL_CLASS MC ON MC.MATERIAL_TYPE_CODE=MA.MATERIAL_TYPE_CODE ");
sqlBuilder.Append(" LEFT JOIN T_MD_WORKCENTER W ON W.WORKCENTER_CODE=M.WORKCENTER_CODE ");
sqlBuilder.Append(" LEFT JOIN T_AW_MAIN main ON main.EPIDERMISCODE=M.PRODUCTCODE ");
#region 查询条件
//查询条件
whereBuilder.Append(" AND MC.MATERIAL_ATTRIBUTE ='2'");
//成品条码
if (string.IsNullOrEmpty(condition.PRODUCTCODE) == false)
{
whereBuilder.Append(" AND M.PRODUCTCODE = @PRODUCTCODE");
parameters.Add(new DataParameter { ParameterName = "PRODUCTCODE", DataType = DbType.String, Value = condition.PRODUCTCODE });
}
//总成条码
if (string.IsNullOrEmpty(condition.MAINCODE) == false)
{
whereBuilder.Append(" AND main.MAINCODE= @MAINCODE");
parameters.Add(new DataParameter { ParameterName = "MAINCODE", DataType = DbType.String, Value = condition.MAINCODE });
}
//颜色
if (string.IsNullOrEmpty(condition.COLOR) == false)
{
whereBuilder.Append(" AND MA.COLOR =@COLOR");
parameters.Add(new DataParameter { ParameterName = "COLOR", DataType = DbType.String, Value = condition.COLOR });
}
//高低配
if (string.IsNullOrEmpty(condition.HB) == false)
{
whereBuilder.Append(" AND MA.HBTYPE =@HB");
parameters.Add(new DataParameter { ParameterName = "HB", DataType = DbType.String, Value = condition.HB });
}
//成品状态
if (string.IsNullOrEmpty(condition.STATUS) == false)
{
whereBuilder.Append(" AND M.STATUS = @STATUS");
parameters.Add(new DataParameter { ParameterName = "STATUS", DataType = DbType.String, Value = condition.STATUS });
}
//物料号
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.WORKCENTER_CODE) == false)
{
whereBuilder.Append(" AND M.WORKCENTER_CODE =@WORKCENTER_CODE");
parameters.Add(new DataParameter { ParameterName = "WORKCENTER_CODE", DataType = DbType.String, Value = condition.WORKCENTER_CODE });
}
if (string.IsNullOrEmpty(condition.VIN) == false)
{
whereBuilder.AppendFormat(" AND M.VIN_REV LIKE '{0}%' ", new string(condition.VIN.Reverse().ToArray()));
//parameters.Add(new DataParameter { ParameterName = "VIN", DataType = DbType.String, Value = condition.VIN });
}
if (string.IsNullOrEmpty(condition.PLAN_NO) == false)
{
whereBuilder.AppendFormat(" AND M.PLAN_NO_REV LIKE '{0}%' ", new string(condition.PLAN_NO.Reverse().ToArray()));
//parameters.Add(new DataParameter { ParameterName = "VIN", DataType = DbType.String, Value = condition.VIN });
}
//if (string.IsNullOrEmpty(condition.KIN) == false)
//{
// whereBuilder.AppendFormat(" AND M.KIN LIKE '%{0}%' ", condition.KIN);
// //parameters.Add(new DataParameter { ParameterName = "KIN", DataType = DbType.String, Value = condition.KIN });
//}
if (string.IsNullOrEmpty(condition.STARTCREATEDATE) == false)
{
whereBuilder.Append(" AND M.CREATEDATE >= @STARTCREATEDATE");
parameters.Add(new DataParameter { ParameterName = "STARTCREATEDATE", DataType = DbType.String, Value = condition.STARTCREATEDATE });
}
if (string.IsNullOrEmpty(condition.ENDCREATEDATE) == false)
{
whereBuilder.Append(" AND M.CREATEDATE <= @ENDCREATEDATE");
parameters.Add(new DataParameter { ParameterName = "ENDCREATEDATE", DataType = DbType.String, Value = condition.ENDCREATEDATE });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
sqlBuilder.AppendFormat(") QMDATAPAGE1 WHERE ROWINDEX BETWEEN {0} AND {1}", Convert.ToString(page.PageSize * (page.PageIndex - 1) + 1), Convert.ToString(page.PageSize * page.PageIndex));
return sqlBuilder.ToString();
}
#endregion
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 求和语句
/// <summary>
/// 获取求和语句
/// </summary>
/// <param name="condition"></param>
/// <param name="parameters"></param>
/// <returns></returns>
private string GetCountQuerySql(ProductEnd condition)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
sqlBuilder.Append("SELECT count(1) FROM (");
sqlBuilder.AppendFormat(@"SELECT
M.PID
,M.PRODUCTTYPE
,M.PRODUCTCODE
,M.MACHINENAME
,M.MACHINECODDE
,M.MATERIAL_CODE
,MA.MATERIAL_NAME
,M.STATUS
,M.ISPARENT
,MA.HBTYPE AS HB
,MA.COLOR
,M.CURRENTPROCESS
,M.PRODUCELINE
,M.PRODUCESHIFTNAME
,M.PRODUCESHIFTTCODE
,M.OUTFLAG
,M.USINGSTATE
,M.CAPACITY
,M.USINGCOUNT
,M.WORKCELL_CODE
,M.WORKLOC_CODE
,M.WORKCENTER_CODE
,W.WORKCENTER_NAME
,M.TEAM_CODE
,M.ENDOFLINE
,M.MATERIAL_TYPE
,MC.MATERIAL_TYPE_NAME
,M.CREATEUSER
,M.CREATEDATE
,M.UPDATEUSER
,M.UPDATEDATE
,C.USERNAME AS CREATEUSERNAME
,U.USERNAME AS UPDATEUSERNAME ");
sqlBuilder.Append("FROM T_AW_PRODUCT M");
sqlBuilder.Append(" LEFT JOIN T_QM_USER C ON C.USERID=M.CREATEUSER ");
sqlBuilder.Append(" LEFT JOIN T_QM_USER U ON U.USERID=M.UPDATEUSER ");
sqlBuilder.Append(" LEFT JOIN T_MD_MATERIAL MA ON MA.MATERIAL_CODE=M.MATERIAL_CODE ");
sqlBuilder.Append(" LEFT JOIN T_MD_MATERIAL_CLASS MC ON MC.MATERIAL_TYPE_CODE=MA.MATERIAL_TYPE_CODE ");
sqlBuilder.Append(" LEFT JOIN T_MD_WORKCENTER W ON W.WORKCENTER_CODE=M.WORKCENTER_CODE ");
sqlBuilder.Append(" LEFT JOIN T_AW_MAIN main ON main.EPIDERMISCODE=M.PRODUCTCODE ");
#region 查询条件
//查询条件
//成品条码
if (string.IsNullOrEmpty(condition.PRODUCTCODE) == false)
{
whereBuilder.Append(" AND M.PRODUCTCODE = @PRODUCTCODE");
}
//总成条码
if (string.IsNullOrEmpty(condition.MAINCODE) == false)
{
whereBuilder.Append(" AND main.MAINCODE= @MAINCODE");
}
//颜色
if (string.IsNullOrEmpty(condition.COLOR) == false)
{
whereBuilder.Append(" AND MA.COLOR =@COLOR");
}
//高低配
if (string.IsNullOrEmpty(condition.HB) == false)
{
whereBuilder.Append(" AND MA.HBTYPE =@HB");
}
//成品状态
if (string.IsNullOrEmpty(condition.STATUS) == false)
{
whereBuilder.Append(" AND M.STATUS = @STATUS");
}
//物料号
if (string.IsNullOrEmpty(condition.MATERIAL_CODE) == false)
{
whereBuilder.Append(" AND M.MATERIAL_CODE = @MATERIAL_CODE");
}
//工作中心
if (string.IsNullOrEmpty(condition.WORKCENTER_CODE) == false)
{
whereBuilder.Append(" AND M.WORKCENTER_CODE =@WORKCENTER_CODE");
}
if (string.IsNullOrEmpty(condition.VIN) == false)
{
whereBuilder.AppendFormat(" AND M.VIN_REV LIKE '{0}%' ", new string(condition.VIN.Reverse().ToArray()));
//parameters.Add(new DataParameter { ParameterName = "VIN", DataType = DbType.String, Value = condition.VIN });
}
if (string.IsNullOrEmpty(condition.PLAN_NO) == false)
{
whereBuilder.AppendFormat(" AND M.PLAN_NO_REV LIKE '{0}%' ", new string(condition.PLAN_NO.Reverse().ToArray()));
//parameters.Add(new DataParameter { ParameterName = "VIN", DataType = DbType.String, Value = condition.VIN });
}
if (string.IsNullOrEmpty(condition.STARTCREATEDATE) == false)
{
whereBuilder.Append(" AND M.CREATEDATE >= @STARTCREATEDATE");
}
if (string.IsNullOrEmpty(condition.ENDCREATEDATE) == false)
{
whereBuilder.Append(" AND M.CREATEDATE <= @ENDCREATEDATE");
}
//if (string.IsNullOrEmpty(condition.STARTCREATEDATE) == false)
//{
// whereBuilder.Append(" AND main.CREATEDATE >= @STARTCREATEDATE");
//}
//if (string.IsNullOrEmpty(condition.ENDCREATEDATE) == false)
//{
// whereBuilder.Append(" AND main.CREATEDATE <= @ENDCREATEDATE");
//}
whereBuilder.Append(" AND MC.MATERIAL_ATTRIBUTE ='2'");
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
sqlBuilder.Append(" )temp1");
return sqlBuilder.ToString();
}
#endregion
catch (Exception ex)
{
throw ex;
}
}
#endregion
#endregion
#region 获取导出的数据
/// <summary>
/// 获取导出的数据
/// </summary>
/// <param name="user">查询条件</param>
/// <returns>数据</returns>
public DataTable GetExportData(ProductEnd model)
{
DataTable dt = null;
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
//构成查询语句
sql = this.GetQuerySql(model, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
dt = session.GetTable(sql, parameters.ToArray());
dt.TableName = "T_AW_PRODUCT";
}
return dt;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取列表-加载零件列表
/// <summary>
/// 获取列表-加载零件列表
/// </summary>
/// <param name="condition">条件</param>
/// <returns>数据页</returns>
public List<ProductEnd> GetListWithProduct(ProductEnd condition)
{
string sql = null;
List<ProductEnd> list = new List<ProductEnd>();
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetQuerySqlWithProductInfoNew(condition, ref parameters);
//分页关键字段及排序
using (IDataSession session = AppDataFactory.CreateMainSession())
{
list = session.GetList<ProductEnd>(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
throw ex;
}
}
private string GetQuerySqlWithProductInfoNew(ProductEnd condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.Append("SELECT PID,PRODUCTCODE,MACHINECODDE,MACHINENAME ,MATERIAL_CODE ,U.USERNAME AS CREATEUSERNAME,T.CREATEDATE ,(SELECT [MATERIAL_NAME] FROM [T_MD_MATERIAL] where MATERIAL_CODE = t.MATERIAL_CODE) as MATERIAL_NAME FROM T_AW_PRODUCT t ");
sqlBuilder.Append("LEFT JOIN T_QM_USER U ON U.USERID=t.CREATEUSER");
sqlBuilder.Append(" where 1=1 ");
//查询条件
if (string.IsNullOrEmpty(condition.MAINCODE) == false)
{
whereBuilder.Append(" AND T.PID in (select PART_PID from T_QT_PRODUCT_STRUCTURE where PROCESS_CODE=@PRODUCTCODE)");//
parameters.Add(new DataParameter { ParameterName = "PRODUCTCODE", DataType = DbType.String, Value = condition.MAINCODE });
}
sqlBuilder.Append(whereBuilder.ToString());
sqlBuilder.Append(" order by T.CREATEDATE desc ");
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#endregion
}
}