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

781 lines
30 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMAPP.FJC.Entity.Operation;
using QMFrameWork.Data;
using System.Data;
using QMAPP.Entity;
namespace QMAPP.FJC.DAL.Produce
{
/// <summary>
/// 模块名称:
/// 作 者:
/// 编写日期:2017年09月06日
/// </summary>
public class ProductDAL
{
#region 获取信息
/// <summary>
/// 获取信息
/// </summary>
/// <param name="">条件</param>
/// <returns>*信息</returns>
public Product Get(Product info)
{
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//获取信息
info = session.Get<Product>(info);
}
return info;
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 根据产品条码和物料号查询
/// </summary>
/// <param name="productcode">产品条码</param>
/// <param name="materialcode">物料号</param>
/// <returns></returns>
public Product GetByCode(string productcode, string materialcode)
{
StringBuilder sql = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql.AppendLine("SELECT P.* ");
sql.AppendLine(" ,WL.[WORKLOC_NAME] ");
sql.AppendLine(" ,MA.MATERIAL_NAME ");
sql.AppendLine(" ,WC.WORKCELL_NAME ");
sql.AppendLine(" FROM [T_AW_PRODUCT] AS P WITH(NOLOCK)");
sql.AppendLine(" LEFT JOIN [T_MD_WORKLOC] AS WL ");
sql.AppendLine(" ON WL.[WORKLOC_CODE]=P.[WORKLOC_CODE] ");
sql.AppendLine(" LEFT JOIN [T_MD_WORKCELL] AS WC ");
sql.AppendLine(" ON WC.[WORKCELL_CODE]=P.[WORKCELL_CODE]");
sql.AppendLine(" LEFT JOIN [T_MD_MATERIAL] AS MA ");
sql.AppendLine(" ON P.MATERIAL_CODE=MA.MATERIAL_CODE ");
sql.AppendLine(" WHERE [PRODUCTCODE]=@productcode AND P.[MATERIAL_CODE]=@materialcode");
parameters.Add(new DataParameter("productcode", productcode));
parameters.Add(new DataParameter("materialcode", materialcode));
using (IDataSession session = AppDataFactory.CreateMainSession())
{
return session.Get<Product>(sql.ToString(), parameters.ToArray());
}
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 根据产品条码查询最原始产品信息
/// </summary>
/// <param name="productcode">产品条码</param>
/// <returns></returns>
public Product GetByCode(string productcode)
{
StringBuilder sql = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql.AppendLine("SELECT P.* ");
sql.AppendLine(" ,WL.[WORKLOC_NAME] ");
sql.AppendLine(" ,MA.MATERIAL_NAME ");
sql.AppendLine(" ,WC.WORKCELL_NAME ");
sql.AppendLine(" FROM [T_AW_PRODUCT] AS P WITH(NOLOCK) ");
sql.AppendLine(" LEFT JOIN [T_MD_WORKLOC] AS WL ");
sql.AppendLine(" ON WL.[WORKLOC_CODE]=P.[WORKLOC_CODE] ");
sql.AppendLine(" LEFT JOIN [T_MD_WORKCELL] AS WC ");
sql.AppendLine(" ON WC.[WORKCELL_CODE]=P.[WORKCELL_CODE]");
sql.AppendLine(" LEFT JOIN [T_MD_MATERIAL] AS MA ");
sql.AppendLine(" ON P.MATERIAL_CODE=MA.MATERIAL_CODE ");
sql.AppendLine(" WHERE [PRODUCTCODE]=@productcode ORDER BY P.[CREATEDATE] ASC");
parameters.Add(new DataParameter("productcode", productcode));
using (IDataSession session = AppDataFactory.CreateMainSession())
{
return session.Get<Product>(sql.ToString(), parameters.ToArray());
}
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 根据产品主键查询产品信息
/// </summary>
/// <param name="PID"></param>
/// <returns></returns>
public Product GetByPID(string PID)
{
StringBuilder sql = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql.AppendLine("SELECT P.* ");
sql.AppendLine(" ,WL.[WORKLOC_NAME] ");
sql.AppendLine(" ,MA.MATERIAL_NAME ");
sql.AppendLine(" ,WC.WORKCELL_NAME ");
sql.AppendLine(" FROM [T_AW_PRODUCT] AS P WITH(NOLOCK) ");
sql.AppendLine(" LEFT JOIN [T_MD_WORKLOC] AS WL ");
sql.AppendLine(" ON WL.[WORKLOC_CODE]=P.[WORKLOC_CODE] ");
sql.AppendLine(" LEFT JOIN [T_MD_WORKCELL] AS WC ");
sql.AppendLine(" ON WC.[WORKCELL_CODE]=P.[WORKCELL_CODE]");
sql.AppendLine(" LEFT JOIN [T_MD_MATERIAL] AS MA ");
sql.AppendLine(" ON P.MATERIAL_CODE=MA.MATERIAL_CODE ");
sql.AppendLine(" WHERE P.[PID]=@pid ");
using (IDataSession session = AppDataFactory.CreateMainSession())
{
parameters.Add(new DataParameter("pid", PID));
return session.Get<Product>(sql.ToString(), parameters.ToArray());
}
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 根据产品主键查询产品信息(事务)
/// </summary>
/// <param name="PID"></param>
/// <returns></returns>
public Product GetByPID(string PID, IDataSession session)
{
StringBuilder sql = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql.AppendLine("SELECT P.* ");
sql.AppendLine(" ,WL.[WORKLOC_NAME] ");
sql.AppendLine(" ,MA.MATERIAL_NAME ");
sql.AppendLine(" ,WC.WORKCELL_NAME ");
sql.AppendLine(" FROM [T_AW_PRODUCT] AS P WITH(NOLOCK) ");
sql.AppendLine(" LEFT JOIN [T_MD_WORKLOC] AS WL ");
sql.AppendLine(" ON WL.[WORKLOC_CODE]=P.[WORKLOC_CODE] ");
sql.AppendLine(" LEFT JOIN [T_MD_WORKCELL] AS WC ");
sql.AppendLine(" ON WC.[WORKCELL_CODE]=P.[WORKCELL_CODE]");
sql.AppendLine(" LEFT JOIN [T_MD_MATERIAL] AS MA ");
sql.AppendLine(" ON P.MATERIAL_CODE=MA.MATERIAL_CODE ");
sql.AppendLine(" WHERE P.[PID]=@pid ");
parameters.Add(new DataParameter("pid", PID));
return session.Get<Product>(sql.ToString(), parameters.ToArray());
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 根据产品条码和物料号查询
/// </summary>
/// <param name="productcode">产品条码</param>
/// <param name="materialcode">物料号</param>
/// <returns></returns>
public Product GetByCode(string productcode, string materialcode,IDataSession session)
{
StringBuilder sql = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql.AppendLine("SELECT P.* ");
sql.AppendLine(" ,WL.[WORKLOC_NAME] ");
sql.AppendLine(" ,MA.MATERIAL_NAME ");
sql.AppendLine(" ,WC.WORKCELL_NAME ");
sql.AppendLine(" FROM [T_AW_PRODUCT] AS P WITH(NOLOCK) ");
sql.AppendLine(" LEFT JOIN [T_MD_WORKLOC] AS WL ");
sql.AppendLine(" ON WL.[WORKLOC_CODE]=P.[WORKLOC_CODE] ");
sql.AppendLine(" LEFT JOIN [T_MD_WORKCELL] AS WC ");
sql.AppendLine(" ON WC.[WORKCELL_CODE]=P.[WORKCELL_CODE]");
sql.AppendLine(" LEFT JOIN [T_MD_MATERIAL] AS MA ");
sql.AppendLine(" ON P.MATERIAL_CODE=MA.MATERIAL_CODE ");
sql.AppendLine(" WHERE [PRODUCTCODE]=@productcode AND P.[MATERIAL_CODE]=@materialcode");
parameters.Add(new DataParameter("productcode", productcode));
parameters.Add(new DataParameter("materialcode", materialcode));
return session.Get<Product>(sql.ToString(), parameters.ToArray());
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 根据条码获取最新产品信息
/// </summary>
/// <param name="productcode">产品条码</param>
/// <returns></returns>
public Product GetNewestProduct(string productcode)
{
StringBuilder sql = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql.AppendLine("SELECT P.* ");
sql.AppendLine(" ,WL.[WORKLOC_NAME] ");
sql.AppendLine(" ,MA.MATERIAL_NAME ");
sql.AppendLine(" ,WC.WORKCELL_NAME ");
sql.AppendLine(" FROM [T_AW_PRODUCT] AS P WITH(NOLOCK) ");
sql.AppendLine(" LEFT JOIN [T_MD_WORKLOC] AS WL ");
sql.AppendLine(" ON WL.[WORKLOC_CODE]=P.[WORKLOC_CODE] ");
sql.AppendLine(" LEFT JOIN [T_MD_WORKCELL] AS WC ");
sql.AppendLine(" ON WC.[WORKCELL_CODE]=P.[WORKCELL_CODE]");
sql.AppendLine(" LEFT JOIN [T_MD_MATERIAL] AS MA ");
sql.AppendLine(" ON P.MATERIAL_CODE=MA.MATERIAL_CODE ");
sql.AppendLine(" WHERE [PRODUCTCODE]=@productcode ORDER BY P.[CREATEDATE] DESC");
parameters.Add(new DataParameter("productcode", productcode));
using (IDataSession session = AppDataFactory.CreateMainSession())
{
return session.Get<Product>(sql.ToString(), parameters.ToArray());
}
}
catch (Exception ex)
{
throw ex;
}
}
public Product GetNewestProductCell(string productcode, string cell)
{
StringBuilder sql = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql.AppendLine("SELECT P.* ");
sql.AppendLine(" ,WL.[WORKLOC_NAME] ");
sql.AppendLine(" ,MA.MATERIAL_NAME ");
sql.AppendLine(" ,WC.WORKCELL_NAME ");
sql.AppendLine(" FROM [T_AW_PRODUCT] AS P WITH(NOLOCK) ");
sql.AppendLine(" LEFT JOIN [T_MD_WORKLOC] AS WL ");
sql.AppendLine(" ON WL.[WORKLOC_CODE]=P.[WORKLOC_CODE] ");
sql.AppendLine(" LEFT JOIN [T_MD_WORKCELL] AS WC ");
sql.AppendLine(" ON WC.[WORKCELL_CODE]=P.[WORKCELL_CODE]");
sql.AppendLine(" LEFT JOIN [T_MD_MATERIAL] AS MA ");
sql.AppendLine(" ON P.MATERIAL_CODE=MA.MATERIAL_CODE ");
sql.AppendLine(" WHERE [PRODUCTCODE]=@productcode and P.[WORKCELL_CODE] = @cell ORDER BY P.[CREATEDATE] DESC");
parameters.Add(new DataParameter("productcode", productcode));
parameters.Add(new DataParameter("cell", cell));
using (IDataSession session = AppDataFactory.CreateMainSession())
{
return session.Get<Product>(sql.ToString(), parameters.ToArray());
}
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 根据条码获取最新产品信息
/// </summary>
/// <param name="productcode">产品条码</param>
/// <returns></returns>
public Product GetNewestProductByOrderNO(string fiscode)
{
StringBuilder sql = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql.AppendLine("SELECT P.* ");
sql.AppendLine(" ,WL.[WORKLOC_NAME] ");
sql.AppendLine(" ,MA.MATERIAL_NAME ");
sql.AppendLine(" ,WC.WORKCELL_NAME ");
sql.AppendLine(" FROM [T_AW_PRODUCT] AS P WITH(NOLOCK) ");
sql.AppendLine(" LEFT JOIN [T_MD_WORKLOC] AS WL ");
sql.AppendLine(" ON WL.[WORKLOC_CODE]=P.[WORKLOC_CODE] ");
sql.AppendLine(" LEFT JOIN [T_MD_WORKCELL] AS WC ");
sql.AppendLine(" ON WC.[WORKCELL_CODE]=P.[WORKCELL_CODE]");
sql.AppendLine(" LEFT JOIN [T_MD_MATERIAL] AS MA ");
sql.AppendLine(" ON P.MATERIAL_CODE=MA.MATERIAL_CODE ");
sql.AppendLine(" WHERE P.[PLAN_NO]=@fiscode ORDER BY P.[CREATEDATE] DESC");
parameters.Add(new DataParameter("fiscode", fiscode));
using (IDataSession session = AppDataFactory.CreateMainSession())
{
return session.Get<Product>(sql.ToString(), parameters.ToArray());
}
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 获取指定工序下状态为未使用的产品信息
/// </summary>
/// <param name="productcode">产品条码</param>
/// <returns></returns>
public Product GetUnusedProduct(string productcode,string workcellcode)
{
StringBuilder sql = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql.Append("SELECT * FROM [T_AW_PRODUCT] WITH(NOLOCK) WHERE [PRODUCTCODE]=@productcode AND [WORKCELL_CODE]=@workcellcode AND [USINGCOUNT] < [CAPACITY] ORDER BY [CREATEDATE] DESC");
parameters.Add(new DataParameter("productcode", productcode));
parameters.Add(new DataParameter("workcellcode", workcellcode));
using (IDataSession session = AppDataFactory.CreateMainSession())
{
return session.Get<Product>(sql.ToString(), parameters.ToArray());
}
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 获取指定工位下状态为未使用完的上料信息
/// </summary>
/// <param name="p"></param>
/// <param name="adaptmaterials"></param>
public List<Product> GetUsingMaterial(string workloccode)
{
StringBuilder sql = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql.AppendLine("SELECT P.* ");
sql.AppendLine(" ,MC.[UP_MATERIAL_TYPE_CODE] AS [PARENT_MATERIAL_TYPE] ");
sql.AppendLine(" FROM [T_AW_PRODUCT] AS P WITH(NOLOCK) ");
sql.AppendLine(" LEFT JOIN [T_MD_MATERIAL_CLASS] AS MC WITH(NOLOCK) ");
sql.AppendLine(" ON P.[MATERIAL_TYPE] = MC.MATERIAL_TYPE_CODE ");
sql.AppendLine(" WHERE [WORKLOC_CODE]=@workloccode ");
sql.AppendLine(" AND [USINGSTATE] <> '2' ");
sql.AppendLine(" AND [CAPACITY]>1 ");
sql.AppendLine(" ORDER BY P.[CREATEDATE] DESC ");
//sql.Append("SELECT * FROM [T_AW_PRODUCT] WHERE [WORKLOC_CODE]= AND [USINGSTATE] <> '2' AND [CAPACITY]>1 ORDER BY [CREATEDATE] DESC");
parameters.Add(new DataParameter("workloccode", workloccode));
using (IDataSession session = AppDataFactory.CreateMainSession())
{
return session.GetList<Product>(sql.ToString(), parameters.ToArray()).ToList();
}
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取列表
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataPage GetList(Product 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<Product>(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(Product condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.Append("SELECT PID,PRODUCTTYPE,PRODUCTCODE,PRODUCTSOURCE,MACHINENAME,MACHINECODDE,STATUS,ISPARENT,CURRENTPROCESS,PRODUCELINE,PRODUCESHIFTNAME,PRODUCESHIFTTCODE,OUTFLAG,USINGSTATE,CAPACITY,USINGCOUNT,CREATEUSER,CREATEDATE,UPDATEUSER,UPDATEDATE,MATERIAL_CODE,WORKCELL_CODE,WORKLOC_CODE,WORKCENTER_CODE,TEAM_CODE,PLAN_NO,PLAN_ID ");
sqlBuilder.Append("FROM T_AW_PRODUCT WITH(NOLOCK) ");
whereBuilder.Append(" AND FLGDEL<> '1' ");
//查询条件
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="user">查询条件</param>
/// <returns>数据</returns>
public DataTable GetExportData(Product info)
{
DataTable dt = null;
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
//构成查询语句
sql = this.GetQuerySql(info, 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="info"></param>
/// <returns>true:已存在;fasel:不存在。</returns>
public bool Exists(Product info)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
int count = 0;
try
{
sqlBuilder.Append("SELECT COUNT(0) FROM T_AW_PRODUCT WITH(NOLOCK) ");
if (info.PID == null)
{
info.PID = "";
}
whereBuilder.Append(" AND PID <> @PID ");
parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = info.PID });
//添加进行无重复字段判断代码
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
count = Convert.ToInt32(session.ExecuteSqlScalar(sqlBuilder.ToString(), parameters.ToArray()));
}
return count > 0;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 插入信息
/// <summary>
/// 插入信息(单表)
/// </summary>
/// <param name="">信息</param>
/// <returns>插入行数</returns>
public int Insert(Product info)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//插入基本信息
count = session.Insert<Product>(info);
}
return count;
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 插入信息(事务)
/// </summary>
/// <param name="product">产品信息</param>
/// <param name="session">数据会话</param>
/// <returns>插入行数</returns>
public int Insert(Product product, IDataSession session)
{
int count = 0;
try
{
//插入基本信息
count = session.Insert<Product>(product);
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 更新信息
/// <summary>
/// 更新信息
/// </summary>
/// <param name=""></param>
/// <returns>更新行数</returns>
public int Update(Product info)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//更新基本信息
count = session.Update<Product>(info);
}
return count;
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 更新信息(事务)
/// </summary>
/// <param name="info">产品信息</param>
/// <param name="session">数据会话</param>
/// <returns></returns>
public int Update(Product info, IDataSession session)
{
int count = 0;
try
{
//更新基本信息
count = session.Update<Product>(info);
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 逻辑删除
/// <summary>
/// 逻辑删除信息
/// </summary>
/// <param name=""></param>
/// <returns>删除个数</returns>
public int Delete(Product info)
{
StringBuilder sqlBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//删除基本信息
sqlBuilder.Append("UPDATE T_AW_PRODUCT ");
sqlBuilder.Append("SET FLGDEL = '1' ");
sqlBuilder.Append("WHERE PID = @PID ");
parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = info.PID });
count = session.ExecuteSql(sqlBuilder.ToString(), parameters.ToArray());
}
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 导入
public ImportMessage GetImportData(List<Product> list)
{
ImportMessage em = new ImportMessage();
List<DataParameter> parameters = new List<DataParameter>();
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//设置祖先对象数据会话
session.OpenTs();
foreach (Product info in list)
{
if (info.IsNewInfo)
{
//插入信息
int count = session.Insert<Product>(info);
em.insertNum++;
}
else
{
//更新信息
int count = session.Update<Product>(info);
em.updateNum++;
}
}
session.CommitTs();
}
}
catch (Exception ex)
{
throw ex;
}
return em;
}
#endregion
public string GetMaxCode(string materialtype,DateTime date)
{
StringBuilder sql = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql.AppendLine("SELECT ISNULL(MAX(RIGHT(PRODUCTCODE,6)),0) ");
sql.AppendLine(" FROM T_AW_PRODUCT WITH(NOLOCK) ");
sql.AppendLine(" WHERE MATERIAL_TYPE=@materialtype");
sql.AppendLine(" AND DATEDIFF(DAY,CREATEDATE,@date)=0");
//sql.Append("SELECT * FROM [T_AW_PRODUCT] WHERE [WORKLOC_CODE]= AND [USINGSTATE] <> '2' AND [CAPACITY]>1 ORDER BY [CREATEDATE] DESC");
parameters.Add(new DataParameter("materialtype", materialtype));
parameters.Add(new DataParameter("date", date.Date));
using (IDataSession session = AppDataFactory.CreateMainSession())
{
return session.ExecuteSqlScalar(sql.ToString(), parameters.ToArray()).ToString();
}
}
catch (Exception ex)
{
throw ex;
}
}
public Product GetProductByPart(string partpid)
{
StringBuilder sql = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql.Append("SELECT * FROM T_AW_PRODUCT WITH(NOLOCK) WHERE PID=(SELECT PRODUCT_PID FROM T_QT_PRODUCT_STRUCTURE WITH(NOLOCK) WHERE PART_PID=@partpid)");
parameters.Add(new DataParameter("partpid", partpid));
using (IDataSession session = AppDataFactory.CreateMainSession())
{
return session.Get<Product>(sql.ToString(), parameters.ToArray());
}
}
catch (Exception ex)
{
throw ex;
}
}
public Product GetProductByPartID(string partid)
{
StringBuilder sql = new StringBuilder();
Product model = new Product();
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql.AppendLine("SELECT P.* ");
sql.AppendLine(" ,WL.[WORKLOC_NAME] ");
sql.AppendLine(" ,MA.MATERIAL_NAME ");
sql.AppendLine(" ,WC.WORKCELL_NAME ");
sql.AppendLine(" FROM [T_AW_PRODUCT] AS P WITH(NOLOCK)");
sql.AppendLine(" LEFT JOIN [T_MD_WORKLOC] AS WL ");
sql.AppendLine(" ON WL.[WORKLOC_CODE]=P.[WORKLOC_CODE] ");
sql.AppendLine(" LEFT JOIN [T_MD_WORKCELL] AS WC ");
sql.AppendLine(" ON WC.[WORKCELL_CODE]=P.[WORKCELL_CODE]");
sql.AppendLine(" LEFT JOIN [T_MD_MATERIAL] AS MA ");
sql.AppendLine(" ON P.MATERIAL_CODE=MA.MATERIAL_CODE ");
sql.AppendLine(" WHERE P.PRODUCTCODE=(SELECT PROCESS_CODE ");
sql.AppendLine(" FROM T_QT_PRODUCT_STRUCTURE WITH(NOLOCK) ");
sql.AppendLine(" WHERE PART_PID=@partid) ");
sql.AppendLine(" ORDER BY P.CREATEDATE DESC ");
parameters.Add(new DataParameter("partid", partid));
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//获取信息
model = session.Get<Product>(sql.ToString(), parameters.ToArray());
}
return model;
}
catch (Exception ex)
{
throw ex;
}
}
}
}