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

607 lines
21 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMFrameWork.Data;
using QMAPP.FJC.Entity.Basic;
using QMAPP.DAL;
using QMFrameWork.Log;
using System.Data;
namespace QMAPP.FJC.DAL.Basic
{
public class BomHdrDAL : BaseDAL
{
#region 获取信息
/// <summary>
/// 获取信息
/// </summary>
/// <param name="">条件</param>
/// <returns>信息</returns>
public BomHdr Get(BomHdr model)
{
StringBuilder sqlBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//获取信息
model = session.Get<BomHdr>(model);
}
return model;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "Bom信息维护数据层-获取信息"
});
throw;
}
}
#endregion
#region 获取列表
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataPage GetList(BomHdr condition, DataPage page)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetQuerySql(condition, ref parameters);
#region 排序
//分页关键字段及排序
page.KeyName = "PID";
if (string.IsNullOrEmpty(page.SortExpression))
{
page.SortExpression = "UPDATEDATE DESC";
}
#endregion
using (IDataSession session = AppDataFactory.CreateMainSession())
{
page = session.GetDataPage<BomHdr>(sql, parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "Bom信息维护数据层-获取列表"
});
throw;
}
}
#endregion
#region 获取查询语句
/// <summary>
/// 获取查询语句
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
private string GetQuerySql(BomHdr condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.AppendLine(" SELECT B.PID ");
sqlBuilder.AppendLine(" ,B.MATERIAL_CODE ");
sqlBuilder.AppendLine(" ,M.MATERIALNAME AS MATERIAL_NAME");
sqlBuilder.AppendLine(" ,B.DESCRIBE_TEXT ");
sqlBuilder.AppendLine(" ,B.DEL_FLG ");
sqlBuilder.AppendLine(" ,B.BOM_VERSION ");
sqlBuilder.AppendLine(" ,B.NODE_TYPE ");
sqlBuilder.AppendLine(" ,B.CREATEUSR ");
sqlBuilder.AppendLine(" ,B.CREATEDATE ");
sqlBuilder.AppendLine(" ,B.UPDATEUSR ");
sqlBuilder.AppendLine(" ,B.FLAGDEL ");
sqlBuilder.AppendLine(" ,B.UPDATEDATE ");
sqlBuilder.AppendLine(" ,C.USERNAME AS CREATEUSERNAME ");
sqlBuilder.AppendLine(" ,U.USERNAME AS UPDATEUSERNAME ");
sqlBuilder.AppendLine(" FROM T_BD_BOM_HDR B ");
sqlBuilder.AppendLine(" LEFT JOIN T_BD_MATERIALINFO M ON M.MATERIALNO=B.MATERIAL_CODE ");
sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER C ON C.USERID=B.CREATEUSR ");
sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER U ON U.USERID=B.UPDATEUSR ");
whereBuilder.Append(" AND B.FLAGDEL='0'");
//查询条件
//BOM
if (string.IsNullOrEmpty(condition.DEL_FLG) == false)
{
whereBuilder.Append(" AND B.DEL_FLG= @DEL_FLG ");
parameters.Add(new DataParameter { ParameterName = "DEL_FLG", DataType = DbType.String, Value = condition.DEL_FLG });
}
//物料号
if (string.IsNullOrEmpty(condition.MATERIAL_CODE) == false)
{
whereBuilder.Append(" AND B.MATERIAL_CODE LIKE @MATERIAL_CODE ");
parameters.Add(new DataParameter { ParameterName = "MATERIAL_CODE", DataType = DbType.String, Value = "%" + condition.MATERIAL_CODE + "%" });
}
//BOM版本
if (string.IsNullOrEmpty(condition.BOM_VERSION) == false)
{
whereBuilder.Append(" AND B.BOM_VERSION= @BOM_VERSION ");
parameters.Add(new DataParameter { ParameterName = "BOM_VERSION", DataType = DbType.String, Value = condition.BOM_VERSION });
}
//BOM类型
if (string.IsNullOrEmpty(condition.NODE_TYPE) == false)
{
whereBuilder.Append(" AND B.NODE_TYPE= @NODE_TYPE ");
parameters.Add(new DataParameter { ParameterName = "NODE_TYPE", DataType = DbType.String, Value = condition.NODE_TYPE });
}
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="info"></param>
/// <returns>true:已存在;fasel:不存在。</returns>
public bool ExistsBomHdr(BomHdr model)
{
string PID = "";
int count = 0;
List<DataParameter> parameters = new List<DataParameter>();
StringBuilder sqlBuilder = new StringBuilder();
try
{
if (string.IsNullOrEmpty(model.PID) == false)
{
PID = model.PID;
}
sqlBuilder.Append(" SELECT COUNT(*) FROM T_BD_BOM_HDR WHERE PID <> @PID AND MATERIAL_CODE =@MATERIAL_CODE ");
parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = model.PID });
parameters.Add(new DataParameter { ParameterName = "MATERIAL_CODE", DataType = DbType.String, Value = model.MATERIAL_CODE });
if (this.BaseSession != null)
{
count = Convert.ToInt32(BaseSession.ExecuteSqlScalar(sqlBuilder.ToString(), parameters.ToArray()));
}
else
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
count = Convert.ToInt32(session.ExecuteSqlScalar(sqlBuilder.ToString(), parameters.ToArray()));
}
}
if (count > 0)
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "Bom信息维护数据层-信息是否重复"
});
throw;
}
}
#endregion
#region 插入信息
/// <summary>
/// 插入信息(单表)
/// </summary>
/// <param name="">信息</param>
/// <returns>插入行数</returns>
public int Insert(BomHdr model)
{
int count = 0;
try
{
if (this.BaseSession != null)
{
//插入基本信息
count = BaseSession.Insert<BomHdr>(model);
}
else
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//插入基本信息
count = session.Insert<BomHdr>(model);
}
}
return count;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "Bom信息维护数据层-插入信息"
});
throw;
}
}
#endregion
#region 删除Bom信息
/// <summary>
/// 删除信息
/// </summary>
/// <param name="model">Bom信息(ID)</param>
/// <returns>删除个数</returns>
public int DeleteBomHdr(BomHdr model)
{
StringBuilder sqlBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
int count = 0;
try
{
if (this.BaseSession != null)
{
//删除基本信息
count = BaseSession.Delete<BomHdr>(model);
}
else
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//删除基本信息
count = session.Delete<BomHdr>(model);
}
}
return count;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "Bom信息维护数据层-删除Bom信息"
});
throw;
}
}
#endregion
#region Bom信息下拉
/// <summary>
///
/// </summary>
/// <param name="condition"></param>
/// <returns></returns>
public List<BomHdr> GetBomHdrList(BomHdr condition)
{
List<BomHdr> list = new List<BomHdr>();
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetQuerySql(condition, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
list = session.GetList<BomHdr>(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "BOM信息-列表"
});
throw;
}
}
#endregion
#region 配置BOM明细
#region 获取BOM明细列表
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataPage BomHdrConfigList(BomDetail condition, DataPage page)
{
string sql = "";
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetBomDetailListSql(condition, ref parameters);
//分页关键字段及排序
page.KeyName = "PID";
if (string.IsNullOrEmpty(page.SortExpression))
{
page.SortExpression = "UPDATEDATE DESC";
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
page = session.GetDataPage<BomDetail>(sql, parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "Bom信息维护数据层-获取列表"
});
throw;
}
}
#endregion
#region 获取查询语句
/// <summary>
/// 获取查询语句
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
private string GetBomDetailListSql(BomDetail condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.AppendLine(" SELECT B.PID ");
sqlBuilder.AppendLine(" ,B.BOM_HDR_PID ");
sqlBuilder.AppendLine(" ,B.ITEM_CODE ");
sqlBuilder.AppendLine(" ,B.MATERIAL_CODE ");
sqlBuilder.AppendLine(" ,B.MATERIAL_LAYER ");
sqlBuilder.AppendLine(" ,B.IS_ASSY ");
sqlBuilder.AppendLine(" ,B.UNIT_CODE ");
sqlBuilder.AppendLine(" ,B.ITEM_QTY ");
sqlBuilder.AppendLine(" ,B.REMARK ");
sqlBuilder.AppendLine(" ,B.FLAGDEL ");
sqlBuilder.AppendLine(" ,B.CREATEUSR ");
sqlBuilder.AppendLine(" ,B.CREATEDATE ");
sqlBuilder.AppendLine(" ,B.UPDATEUSR ");
sqlBuilder.AppendLine(" ,B.UPDATEDATE ");
sqlBuilder.AppendLine(" ,C.USERNAME AS CREATEUSERNAME ");
sqlBuilder.AppendLine(" ,U.USERNAME AS UPDATEUSERNAME ");
sqlBuilder.AppendLine(" FROM T_BD_BOM_DETAIL B ");
sqlBuilder.AppendLine(" LEFT JOIN T_BD_BOM_HDR BH ON BH.PID=B.BOM_HDR_PID ");
sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER C ON C.USERID=B.CREATEUSR ");
sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER U ON U.USERID=B.UPDATEUSR ");
//查询条件
if (string.IsNullOrEmpty(condition.BOM_HDR_PID) == false)
{
whereBuilder.Append(" AND BH.PID= @BOM_HDR_PID ");
parameters.Add(new DataParameter { ParameterName = "BOM_HDR_PID", DataType = DbType.String, Value = condition.BOM_HDR_PID });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取Bom明细列表
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public List<BomDetail> BomDetailList(BomDetail condition)
{
string sql = "";
List<DataParameter> parameters = new List<DataParameter>();
List<BomDetail> list = new List<BomDetail>();
try
{
sql = this.GetBomDetailListSql(condition, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
list = session.GetList<BomDetail>(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "Bom信息维护数据层-获取Bom明细列表"
});
throw;
}
}
#endregion
#region 插入Bom明细信息
/// <summary>
/// 插入信息(单表)
/// </summary>
/// <param name="">信息</param>
/// <returns>插入行数</returns>
public int InsertBomDetail(BomDetail model)
{
int count = 0;
try
{
if (this.BaseSession != null)
{
//插入基本信息
count = BaseSession.Insert<BomDetail>(model);
}
else
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//插入基本信息
count = session.Insert<BomDetail>(model);
}
}
return count;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "Bom信息维护数据层-插入Bom明细信息"
});
throw;
}
}
#endregion
#region 获取Bom明细
/// <summary>
/// 获取Bom明细
/// </summary>
/// <param name="">条件</param>
/// <returns>*信息</returns>
public BomDetail GetBomDetail(BomDetail model)
{
List<DataParameter> parameters = new List<DataParameter>();
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//获取信息
model = session.Get<BomDetail>(model);
}
return model;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "Bom信息维护数据层-获取Bom明细"
});
throw;
}
}
#endregion
#region 删除Bom明细
/// <summary>
/// 删除信息
/// </summary>
/// <param name="model">Bom信息(ID)</param>
/// <returns>删除个数</returns>
public int DeleteBomDetail(BomDetail model)
{
StringBuilder sqlBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
StringBuilder whereBuilder = new StringBuilder();
int count = 0;
try
{
//构成查询语句
sqlBuilder.AppendLine(" DELETE FROM T_BD_BOM_DETAIL ");
if (string.IsNullOrEmpty(model.PID) == false)
{
whereBuilder.Append(" AND PID=@PID ");
parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = model.PID });
}
if (string.IsNullOrEmpty(model.BOM_HDR_PID) == false)
{
whereBuilder.Append(" AND BOM_HDR_PID=@BOM_HDR_PID ");
parameters.Add(new DataParameter { ParameterName = "BOM_HDR_PID", DataType = DbType.String, Value = model.BOM_HDR_PID });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
if (this.BaseSession != null)
{
//删除基本信息
count = BaseSession.ExecuteSql(sqlBuilder.ToString(), parameters.ToArray());
}
else
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//删除基本信息
count = session.ExecuteSql(sqlBuilder.ToString(), parameters.ToArray());
}
}
return count;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "Bom信息维护数据层-删除"
});
throw;
}
}
#endregion
#endregion
}
}