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

1159 lines
49 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMAPP.MD.Entity;
using QMFrameWork.Data;
using QMFrameWork.Log;
using System.Data;
using QMAPP.DAL;
using QMAPP.FJC.Entity.Basic;
namespace QMAPP.MD.DAL
{
/// <summary>
/// 模块名称:物料
/// 作 者:郭兆福
/// 编写日期:2017年05月10日
/// </summary>
public class MaterialDAL : BaseDAL
{
#region 获取信息
/// <summary>
/// 获取信息
/// </summary>
/// <param name="">条件</param>
/// <returns>信息</returns>
public Material Get(Material model)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = "SELECT * FROM T_MD_MATERIAL WHERE '1'='1'";
if (string.IsNullOrEmpty(model.PID) == false)
{
sql += " AND PID = @PID";
parameters.Add(new DataParameter("PID", model.PID));
}
if (string.IsNullOrEmpty(model.MATERIAL_CODE) == false)
{
sql += " AND MATERIAL_CODE = @MATERIAL_CODE";
parameters.Add(new DataParameter("MATERIAL_CODE", model.MATERIAL_CODE));
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
string sqlChange = this.ChangeSqlByDB(sql, session);
//获取信息
model = session.Get<Material>(sqlChange, parameters.ToArray());
}
return model;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "物料号信息数据层-获取信息");
throw ex;
}
}
public Material GetMaterial(string materialcode)
{
List<DataParameter> parameters = new List<DataParameter>();
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
sqlBuilder.AppendLine(" SELECT M.PID ");
sqlBuilder.AppendLine(" ,M.MATERIAL_CODE ");
sqlBuilder.AppendLine(" ,M.MATERIAL_NAME ");
sqlBuilder.AppendLine(" ,M.MATERIAL_SHORT ");
sqlBuilder.AppendLine(" ,M.MATERIAL_COMP ");
sqlBuilder.AppendLine(" ,M.MATERIAL_TYPE_CODE ");
sqlBuilder.AppendLine(" ,T.MATERIAL_TYPE_NAME ");
sqlBuilder.AppendLine(" ,T.MATERIAL_ATTRIBUTE ");
sqlBuilder.AppendLine(" ,M.UNIT_CODE ");
sqlBuilder.AppendLine(" ,M.OUTSOURCE ");
sqlBuilder.AppendLine(" ,M.COLOR ");
sqlBuilder.AppendLine(" ,M.HBTYPE ");
sqlBuilder.AppendLine(" ,M.STD_QTY ");
sqlBuilder.AppendLine(" ,M.REMARK ");
sqlBuilder.AppendLine(" ,M.FLGDEL ");
sqlBuilder.AppendLine(" ,M.CREATEUSER ");
sqlBuilder.AppendLine(" ,M.CREATEDATE ");
sqlBuilder.AppendLine(" ,M.UPDATEUSER ");
sqlBuilder.AppendLine(" ,M.UPDATEDATE ");
sqlBuilder.AppendLine(" ,M.IMAGE_PATH ");
sqlBuilder.AppendLine(" FROM T_MD_MATERIAL M ");
sqlBuilder.AppendLine(" LEFT JOIN T_MD_MATERIAL_CLASS T ON M.MATERIAL_TYPE_CODE = T.MATERIAL_TYPE_CODE ");
whereBuilder.Append(" AND M.FLGDEL='0'");
whereBuilder.Append(" AND M.MATERIAL_CODE = @materialcode");
parameters.Add(new DataParameter { ParameterName = "materialcode", DataType = DbType.String, Value = materialcode });
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
string sql = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
return session.Get<Material>(sql, parameters.ToArray());
}
}
catch (Exception ex)
{
RecordExceptionLog(ex, "物料信息-下拉列表");
throw ex;
}
}
/// <summary>
/// 获取信息
/// </summary>
/// <param name="">条件</param>
/// <returns>*信息</returns>
public Material GetWithAnyFormate(string materialcode)
{
try
{
string sql = "SELECT * FROM [T_MD_MATERIAL] WHERE REPLACE(REPLACE(REPLACE([MATERIAL_CODE],'.',''),' ',''),'-','')=@materialcode";
List<DataParameter> parameters = new List<DataParameter>();
materialcode = materialcode.Replace(".", "").Replace("-", "").Replace(" ", "");
parameters.Add(new DataParameter("materialcode", materialcode));
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//获取信息
var info = session.Get<Material>(sql, parameters.ToArray());
return info;
}
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取分页列表
/// <summary>
/// 获取分页列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataPage GetList(Material 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 = "MATERIAL_CODE DESC";
}
#endregion
using (IDataSession session = AppDataFactory.CreateMainSession())
{
page = session.GetDataPage<Material>(sql, parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "物料号信息数据层-获取分页列表");
throw ex;
}
}
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <returns>全部集合</returns>
public List<Material> GetList(Material condition)
{
List<Material> list = new List<Material>();
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetQuerySql(condition, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
list = session.GetList<Material>(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "物料号信息数据层-获取列表"
});
throw;
}
}
#endregion
#region 获取查询语句
/// <summary>
/// 获取查询语句
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
private string GetQuerySql(Material condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
sqlBuilder.AppendLine(" SELECT M.PID ");
sqlBuilder.AppendLine(" ,M.FACTORY_CODE ");
sqlBuilder.AppendLine(" ,F.FACTORY_NAME ");
sqlBuilder.AppendLine(" ,M.PROJECTCODE ");
sqlBuilder.AppendLine(" ,P.PROJECT_NAME ");
sqlBuilder.AppendLine(" ,M.MATERIAL_CODE ");
sqlBuilder.AppendLine(" ,M.MATERIAL_NAME ");
sqlBuilder.AppendLine(" ,M.MATERIAL_SHORT ");
sqlBuilder.AppendLine(" ,M.MATERIAL_COMP ");
sqlBuilder.AppendLine(" ,M.MATERIAL_TYPE_CODE ");
sqlBuilder.AppendLine(" ,T.MATERIAL_TYPE_NAME ");
sqlBuilder.AppendLine(" ,M.UNIT_CODE ");
sqlBuilder.AppendLine(" ,M.OUTSOURCE ");
sqlBuilder.AppendLine(" ,M.COLOR ");
sqlBuilder.AppendLine(" ,M.HBTYPE ");
sqlBuilder.AppendLine(" ,M.STD_QTY ");
sqlBuilder.AppendLine(" ,M.REMARK ");
sqlBuilder.AppendLine(" ,M.FLGDEL ");
sqlBuilder.AppendLine(" ,C.USERNAME AS CREATEUSERNAME ");
sqlBuilder.AppendLine(" ,M.CREATEUSER ");
sqlBuilder.AppendLine(" ,M.CREATEDATE ");
sqlBuilder.AppendLine(" ,M.UPDATEUSER ");
sqlBuilder.AppendLine(" ,M.UPDATEDATE ");
sqlBuilder.AppendLine(" ,M.IMAGE_PATH ");
sqlBuilder.AppendLine(" FROM T_MD_MATERIAL M ");
sqlBuilder.AppendLine(" LEFT JOIN T_MD_MATERIAL_CLASS T ON M.MATERIAL_TYPE_CODE = T.MATERIAL_TYPE_CODE ");
sqlBuilder.AppendLine(" LEFT JOIN T_MD_PROJECT P ON P.PROJECT_CODE= M.PROJECTCODE ");
sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER C ON C.USERID = M.CREATEUSER ");
sqlBuilder.AppendLine(" LEFT JOIN T_MD_FACTORY F ON F.FACTORY_CODE=M.FACTORY_CODE ");
whereBuilder.Append(" AND M.FLGDEL='0'");
//查询条件
//工厂
if (string.IsNullOrEmpty(condition.FACTORY_CODE) == false)
{
whereBuilder.Append(" AND M.FACTORY_CODE = @FACTORY_CODE");
parameters.Add(new DataParameter { ParameterName = "FACTORY_CODE", DataType = DbType.String, Value = condition.FACTORY_CODE });
}
if (string.IsNullOrEmpty(condition.PROJECTCODE) == false)
{
whereBuilder.Append(" AND M.PROJECTCODE = @PROJECTCODE");
parameters.Add(new DataParameter { ParameterName = "PROJECTCODE", DataType = DbType.String, Value = condition.PROJECTCODE });
}
//物料名称
if (string.IsNullOrEmpty(condition.MATERIAL_NAME) == false)
{
whereBuilder.Append(" AND MATERIAL_NAME LIKE @MATERIAL_NAME");
parameters.Add(new DataParameter { ParameterName = "MATERIAL_NAME", DataType = DbType.String, Value = EscapeValue(condition.MATERIAL_NAME) + "%" });
}
//物料号
if (string.IsNullOrEmpty(condition.MATERIAL_CODE) == false)
{
whereBuilder.Append(" AND MATERIAL_CODE = @MATERIAL_CODE");
parameters.Add(new DataParameter { ParameterName = "MATERIAL_CODE", DataType = DbType.String, Value = condition.MATERIAL_CODE });
}
if (string.IsNullOrEmpty(condition.MaterialCodes) == false)
{
whereBuilder.Append(" AND M.MATERIAL_CODE in " + condition.MaterialCodes + "");
}
//厂家
if (string.IsNullOrEmpty(condition.MATERIAL_COMP) == false)
{
whereBuilder.Append(" AND MATERIAL_COMP = @MATERIAL_COMP ");
parameters.Add(new DataParameter { ParameterName = "MATERIAL_COMP", DataType = DbType.String, Value = condition.MATERIAL_COMP });
}
//类别
if (string.IsNullOrEmpty(condition.MATERIAL_TYPE_CODE) == false)
{
whereBuilder.Append(" AND M.MATERIAL_TYPE_CODE = @MATERIAL_TYPE_CODE ");
parameters.Add(new DataParameter { ParameterName = "MATERIAL_TYPE_CODE", DataType = DbType.String, Value = condition.MATERIAL_TYPE_CODE });
}
//颜色
if (string.IsNullOrEmpty(condition.COLOR) == false)
{
whereBuilder.Append(" AND M.COLOR = @COLOR ");
parameters.Add(new DataParameter { ParameterName = "COLOR", DataType = DbType.String, Value = condition.COLOR });
}
//高低配
if (string.IsNullOrEmpty(condition.HBTYPE) == false)
{
whereBuilder.Append(" AND M.HBTYPE = @HBTYPE ");
parameters.Add(new DataParameter { ParameterName = "HBTYPE", DataType = DbType.String, Value = condition.HBTYPE });
}
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 ExistsMateriel(Material model)
{
string PID = "";
int count = 0;
string sql = null;
try
{
if (string.IsNullOrEmpty(model.PID) == false)
{
PID = model.PID;
}
sql = "SELECT COUNT(*) FROM T_MD_MATERIAL WHERE PID <> @PID AND FACTORY_CODE=@FACTORY_CODE AND MATERIAL_CODE=@MATERIAL_CODE";
using (IDataSession session = AppDataFactory.CreateMainSession())
{
string sqlChange = ChangeSqlByDB(sql, session);
count = Convert.ToInt32(session.ExecuteSqlScalar(sqlChange, new DataParameter("PID", PID),
new DataParameter { ParameterName = "FACTORY_CODE", Value = model.FACTORY_CODE },
new DataParameter { ParameterName = "MATERIAL_CODE", Value = model.MATERIAL_CODE }));
}
if (count > 0)
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
RecordExceptionLog(ex, "物料号信息数据层-判断名称是否存在");
throw ex;
}
}
#endregion
#region 插入信息
/// <summary>
/// 插入信息(单表)
/// </summary>
/// <param name=model"">物料号信息</param>
/// <returns>插入行数</returns>
public int Insert(Material model)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//插入基本信息
count = session.Insert<Material>(model);
}
return count;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "物料号信息数据层-插入信息");
throw ex;
}
}
#endregion
#region 更新信息
/// <summary>
/// 更新信息
/// </summary>
/// <param name="model">物料号信息</param>
/// <returns>更新行数</returns>
public int Update(Material model)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//更新基本信息
count = session.Update<Material>(model);
}
return count;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "物料号信息数据层-更新信息");
throw ex;
}
}
#endregion
#region 删除信息
/// <summary>
/// 删除信息
/// </summary>
/// <param name="model">物料号信息(ID)</param>
/// <returns>删除个数</returns>
public int Delete(Material model)
{
StringBuilder sqlBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//删除基本信息
sqlBuilder.Append("UPDATE T_MD_MATERIAL ");
sqlBuilder.Append("SET FLGDEL = '1'");
sqlBuilder.Append("WHERE PID = @PID");
parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = model.PID });
string sqlChange = ChangeSqlByDB(sqlBuilder.ToString(), session);
count = session.ExecuteSql(sqlChange, parameters.ToArray());
}
return count;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "物料号信息数据层-删除信息");
throw ex;
}
}
#endregion
#region 物料号是否使用(删除校验)
/// <summary>
/// 物料号是否使用
/// </summary>
/// <param name="info"></param>
/// <returns>true:已使用;fasel:未使用。</returns>
public bool IsUsing(string[] pid)
{
int count = 0;
StringBuilder sqlBuilder = new StringBuilder();
try
{
List<DataParameter> paramList = new List<DataParameter>();
sqlBuilder.AppendLine(" SELECT COUNT(*) FROM ");
sqlBuilder.AppendLine(" (SELECT MATERIAL_CODE FROM T_MD_PBOM ");
sqlBuilder.AppendLine(" UNION ");
sqlBuilder.AppendLine(" SELECT MATERIAL_CODE FROM T_MD_PBOM_ITEM) T2 ");
sqlBuilder.AppendLine(" WHERE EXISTS (SELECT 1 ");
sqlBuilder.AppendLine(" FROM T_MD_MATERIAL T WHERE T.MATERIAL_CODE = T2.MATERIAL_CODE AND T.PID ");
for(int i = 0 ; i < pid.Length; i++)
{
if (i == 0)
{
sqlBuilder.AppendLine("IN ( ");
}
else
{
sqlBuilder.AppendLine(",");
}
string param = "PID" + i.ToString();
sqlBuilder.Append("@"+param);
paramList.Add(new DataParameter(param, DbType.String ,pid[i]));
if ( i == pid.Length - 1)
{
sqlBuilder.AppendLine("))");
}
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
string sqlChange = ChangeSqlByDB(sqlBuilder.ToString(), session);
count = Convert.ToInt32(session.ExecuteSqlScalar(sqlChange,paramList.ToArray()));
}
return count == 0 ? false : true;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "物料号信息数据层-物料号是否使用");
throw ex;
}
}
#endregion
#region 物料信息下拉
/// <summary>
///
/// </summary>
/// <param name="condition"></param>
/// <returns></returns>
public List<Material> GetMaterialList(Material condition)
{
List<Material> list = new List<Material>();
List<DataParameter> parameters = new List<DataParameter>();
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
sqlBuilder.AppendLine(" SELECT M.PID ");
sqlBuilder.AppendLine(" ,M.FACTORY_CODE ");
sqlBuilder.AppendLine(" ,F.FACTORY_NAME ");
sqlBuilder.AppendLine(" ,M.PROJECTCODE ");
sqlBuilder.AppendLine(" ,P.PROJECT_NAME ");
sqlBuilder.AppendLine(" ,M.MATERIAL_CODE ");
sqlBuilder.AppendLine(" ,M.MATERIAL_NAME ");
sqlBuilder.AppendLine(" ,M.MATERIAL_SHORT ");
sqlBuilder.AppendLine(" ,M.MATERIAL_COMP ");
sqlBuilder.AppendLine(" ,M.MATERIAL_TYPE_CODE ");
sqlBuilder.AppendLine(" ,T.MATERIAL_TYPE_NAME ");
sqlBuilder.AppendLine(" ,M.UNIT_CODE ");
sqlBuilder.AppendLine(" ,M.OUTSOURCE ");
sqlBuilder.AppendLine(" ,M.COLOR ");
sqlBuilder.AppendLine(" ,M.HBTYPE ");
sqlBuilder.AppendLine(" ,M.STD_QTY ");
sqlBuilder.AppendLine(" ,M.REMARK ");
sqlBuilder.AppendLine(" ,M.FLGDEL ");
sqlBuilder.AppendLine(" ,M.WEIGHT ");
sqlBuilder.AppendLine(" ,M.CREATEUSER ");
sqlBuilder.AppendLine(" ,M.CREATEDATE ");
sqlBuilder.AppendLine(" ,M.UPDATEUSER ");
sqlBuilder.AppendLine(" ,M.UPDATEDATE ");
sqlBuilder.AppendLine(" FROM T_MD_MATERIAL M ");
sqlBuilder.AppendLine(" LEFT JOIN T_MD_MATERIAL_CLASS T ON M.MATERIAL_TYPE_CODE = T.MATERIAL_TYPE_CODE ");
sqlBuilder.AppendLine(" LEFT JOIN T_PP_ORDERINDENTITY AS I ON I.MATERIALTYPE=M.MATERIAL_TYPE_CODE ");
sqlBuilder.AppendLine(" LEFT JOIN T_MD_FACTORY F ON F.FACTORY_CODE=M.FACTORY_CODE ");
sqlBuilder.AppendLine(" LEFT JOIN T_MD_PROJECT P ON P.PROJECT_CODE= M.PROJECTCODE ");
whereBuilder.Append(" AND M.FLGDEL='0'");
//查询条件
//工厂
if (string.IsNullOrEmpty(condition.FACTORY_CODE) == false)
{
whereBuilder.Append(" AND M.FACTORY_CODE = @FACTORY_CODE");
parameters.Add(new DataParameter { ParameterName = "FACTORY_CODE", DataType = DbType.String, Value = condition.FACTORY_CODE });
}
if (string.IsNullOrEmpty(condition.PROJECTCODE) == false)
{
whereBuilder.Append(" AND M.PROJECTCODE = @PROJECTCODE");
parameters.Add(new DataParameter { ParameterName = "PROJECTCODE", DataType = DbType.String, Value = condition.PROJECTCODE });
}
//物料名称
if (string.IsNullOrEmpty(condition.MATERIAL_TYPE_CODE) == false)
{
whereBuilder.Append(" AND M.MATERIAL_TYPE_CODE = @MATERIAL_TYPE_CODE");
parameters.Add(new DataParameter { ParameterName = "MATERIAL_TYPE_CODE", DataType = DbType.String, Value = condition.MATERIAL_TYPE_CODE });
}
if (string.IsNullOrEmpty(condition.MATERIAL_CODE) == false)
{
whereBuilder.Append(" AND M.MATERIAL_CODE like @MATERIAL_CODE");
parameters.Add(new DataParameter { ParameterName = "MATERIAL_CODE", DataType = DbType.String, Value = "%"+condition.MATERIAL_CODE+"%" });
}
if (string.IsNullOrEmpty(condition.MATERIAL_NAME) == false)
{
whereBuilder.Append(" AND M.MATERIAL_NAME like @MATERIAL_NAME");
parameters.Add(new DataParameter { ParameterName = "MATERIAL_NAME", DataType = DbType.String, Value = "%" + condition.MATERIAL_NAME + "%" });
}
if (string.IsNullOrEmpty(condition.PROJECTCODE) == false)
{
whereBuilder.Append(" AND M.PROJECTCODE = @PROJECTCODE");
parameters.Add(new DataParameter { ParameterName = "PROJECTCODE", DataType = DbType.String, Value = condition.PROJECTCODE });
}
if (string.IsNullOrEmpty(condition.ORDER_TYPE) == false)
{
whereBuilder.Append(" AND I.ORDER_TYPE = @ORDER_TYPE");
parameters.Add(new DataParameter { ParameterName = "ORDER_TYPE", DataType = DbType.String, Value = condition.ORDER_TYPE });
}
if (string.IsNullOrEmpty(condition.HBTYPE) == false)
{
whereBuilder.AppendFormat(" AND charindex(M.HBTYPE,'{0}')>0 ", condition.HBTYPE);
}
if (string.IsNullOrEmpty(condition.COLOR) == false)
{
whereBuilder.Append(" AND M.COLOR = @COLOR");
parameters.Add(new DataParameter { ParameterName = "COLOR", DataType = DbType.String, Value = condition.COLOR });
}
if (string.IsNullOrEmpty(condition.MATERIAL_ATTRIBUTE) == false)
{
whereBuilder.Append(" AND T.MATERIAL_ATTRIBUTE = @MATERIAL_ATTRIBUTE");
parameters.Add(new DataParameter { ParameterName = "MATERIAL_ATTRIBUTE", DataType = DbType.String, Value = condition.MATERIAL_ATTRIBUTE });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
string sql = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
list = session.GetList<Material>(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "物料信息-列表");
throw ex;
}
}
#endregion
#region 物料信息下拉(FIS)
/// <summary>
///
/// </summary>
/// <param name="condition"></param>
/// <returns></returns>
public List<Material> GetNewMaterialList(Material condition, WorkCell workcellmodel)
{
List<Material> list = new List<Material>();
string sql = null;
StringBuilder sqlBuilder = new StringBuilder();
sqlBuilder.AppendFormat(@"SELECT DISTINCT M.*
FROM T_MD_WORKCELL WC ,T_MD_PROCESS_ROUTE_WORKCELL PRW,T_MD_PROCESS_ROUTE PR
,T_MD_MATERIAL_ROUTE MR
,T_MD_PBOM MP
,T_MD_MATERIAL M
,T_MD_MATERIAL_CLASS MC
WHERE WC.WORKCENTER_CODE IN (SELECT DISTINCT WORKCENTER FROM T_PP_ORDERINDENTITY WHERE ORDER_TYPE='{0}' ) AND
WC.WORKCELL_CODE=PRW.WORKCELL_CODE and PRW.ROUTE_CODE=PR.ROUTE_CODE
AND PR.ROUTE_CODE=MR.ROUTE_CODE
and MR.MATERIAL_CODE=MP.PBOM_CODE
AND MP.MATERIAL_CODE=M.MATERIAL_CODE
AND M.MATERIAL_TYPE_CODE=MC.MATERIAL_TYPE_CODE
AND MC.MATERIAL_ATTRIBUTE='1'", workcellmodel.WORKCELL_CODE);
List<DataParameter> parameters = new List<DataParameter>();
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//parameters.Add(new DataParameter { ParameterName = "WORKCENTER_CODE", DataType = DbType.String, Value = workcellmodel.WORKCENTER_CODE });
sql = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
list = session.GetList<Material>(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "物料信息-列表");
throw ex;
}
}
public List<Material> GetNewMaterialList(string ordertype)
{
List<Material> list = new List<Material>();
string sql = null;
StringBuilder sqlBuilder = new StringBuilder();
// sqlBuilder.AppendFormat(@"SELECT DISTINCT M.*
// FROM [T_MD_MATERIAL] AS M
// LEFT JOIN [T_MD_PBOM] AS B
// ON B.[MATERIAL_CODE]=M.[MATERIAL_CODE]
// LEFT JOIN [T_PP_ORDERINDENTITY] AS I
// ON I.[MATERIALTYPE]=M.[MATERIAL_TYPE_CODE]
// WHERE I.[ORDER_TYPE]='{0}'
// AND B.[PBOM_CODE] IS NOT NULL", ordertype);
sqlBuilder.AppendFormat(@"SELECT DISTINCT M.*
FROM [T_MD_MATERIAL] AS M
LEFT JOIN [T_PP_ORDERINDENTITY] AS I
ON I.[MATERIALTYPE]=M.[MATERIAL_TYPE_CODE]
WHERE I.[ORDER_TYPE]='{0}'", ordertype);
List<DataParameter> parameters = new List<DataParameter>();
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//parameters.Add(new DataParameter { ParameterName = "WORKCENTER_CODE", DataType = DbType.String, Value = workcellmodel.WORKCENTER_CODE });
sql = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
list = session.GetList<Material>(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "物料信息-列表");
throw ex;
}
}
public List<Material> GetInjectMaterialList(string ordertype)
{
List<Material> list = new List<Material>();
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
// sqlBuilder.AppendFormat(@"SELECT DISTINCT M.*
// FROM [T_MD_MATERIAL] AS M
// LEFT JOIN [T_MD_MATERIAL] AS B
// ON B.[MATERIAL_CODE]=M.[MATERIAL_CODE]
// LEFT JOIN [T_PP_ORDERINDENTITY] AS I
// ON I.[MATERIALTYPE]=M.[MATERIAL_TYPE_CODE]
// WHERE I.[ORDER_TYPE]='{0}'
// ", ordertype);
sqlBuilder.AppendFormat(@"SELECT DISTINCT M.*
FROM [T_MD_MATERIAL] AS M
LEFT JOIN [T_MD_MATERIAL] AS B
ON B.[MATERIAL_CODE]=M.[MATERIAL_CODE]
LEFT JOIN [T_PP_ORDERINDENTITY] AS I
ON I.[MATERIALTYPE]=M.[MATERIAL_TYPE_CODE] ");
//物料名称
if (string.IsNullOrEmpty(ordertype) == false)
{
whereBuilder.Append(" AND I.ORDER_TYPE = @ORDER_TYPE");
parameters.Add(new DataParameter { ParameterName = "ORDER_TYPE", DataType = DbType.String, Value = ordertype });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
sqlBuilder.Append(" ORDER BY M.[MATERIAL_CODE]");
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//parameters.Add(new DataParameter { ParameterName = "WORKCENTER_CODE", DataType = DbType.String, Value = workcellmodel.WORKCENTER_CODE });
sql = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
list = session.GetList<Material>(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "物料信息-列表");
throw ex;
}
}
#endregion
#region 物料信息下拉通过materialclass
/// <summary>
/// 物料信息下拉通过materialclass
/// </summary>
/// <param name="condition"></param>
/// <returns></returns>
public List<Material> GetMaterialListByClass(MaterialClass condition)
{
List<Material> list = new List<Material>();
List<DataParameter> parameters = new List<DataParameter>();
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
sqlBuilder.AppendLine(" SELECT M.PID ");
sqlBuilder.AppendLine(" ,M.MATERIAL_CODE ");
sqlBuilder.AppendLine(" ,M.MATERIAL_NAME ");
sqlBuilder.AppendLine(" ,M.MATERIAL_COMP ");
sqlBuilder.AppendLine(" ,M.MATERIAL_TYPE_CODE ");
sqlBuilder.AppendLine(" ,T.MATERIAL_TYPE_NAME ");
sqlBuilder.AppendLine(" ,T.MATERIAL_ATTRIBUTE ");
sqlBuilder.AppendLine(" ,M.UNIT_CODE ");
sqlBuilder.AppendLine(" ,M.OUTSOURCE ");
sqlBuilder.AppendLine(" ,M.COLOR ");
sqlBuilder.AppendLine(" ,M.HBTYPE ");
sqlBuilder.AppendLine(" ,M.STD_QTY ");
sqlBuilder.AppendLine(" ,M.REMARK ");
sqlBuilder.AppendLine(" ,M.FLGDEL ");
sqlBuilder.AppendLine(" ,M.CREATEUSER ");
sqlBuilder.AppendLine(" ,M.CREATEDATE ");
sqlBuilder.AppendLine(" ,M.UPDATEUSER ");
sqlBuilder.AppendLine(" ,M.UPDATEDATE ");
sqlBuilder.AppendLine(" FROM T_MD_MATERIAL M ");
sqlBuilder.AppendLine(" LEFT JOIN T_MD_MATERIAL_CLASS T ON M.MATERIAL_TYPE_CODE = T.MATERIAL_TYPE_CODE ");
whereBuilder.Append(" AND M.FLGDEL='0'");
//查询条件
if (string.IsNullOrEmpty(condition.MATERIAL_ATTRIBUTE) == false)
{
whereBuilder.Append(" AND T.MATERIAL_ATTRIBUTE = @MATERIAL_ATTRIBUTE");
parameters.Add(new DataParameter { ParameterName = "MATERIAL_ATTRIBUTE", DataType = DbType.String, Value = condition.MATERIAL_ATTRIBUTE });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
string sql = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
list = session.GetList<Material>(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "物料信息-下拉列表");
throw ex;
}
}
#endregion
#region PBOM头物料信息下拉
/// <summary>
/// PBOM头物料信息下拉
/// </summary>
/// <param name="condition"></param>
/// <returns></returns>
public List<Material> GetPbomMaterialList(Material condition)
{
List<Material> list = new List<Material>();
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetPbomMaterialQuerySql(ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
list = session.GetList<Material>(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取PBOM头物料查询语句
/// <summary>
/// 获取PBOM头物料查询语句
/// </summary>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
private string GetPbomMaterialQuerySql(ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
sqlBuilder.AppendLine(" SELECT M.PID ");
sqlBuilder.AppendLine(" ,M.MATERIAL_CODE ");
sqlBuilder.AppendLine(" ,M.MATERIAL_NAME ");
sqlBuilder.AppendLine(" FROM T_MD_MATERIAL M ");
sqlBuilder.AppendLine(" JOIN T_MD_PBOM T ON M.MATERIAL_CODE = T.MATERIAL_CODE AND T.FLGDEL='0' ");
whereBuilder.Append(" AND M.FLGDEL='0'");
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="model"></param>
/// <returns></returns>
public MaterialCodeInit GetProductType(string materialtype)
{
string sql = null;
MaterialCodeInit model = new MaterialCodeInit();
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = "SELECT * FROM T_BD_MATERIALCODEINIT WHERE MATERIAL_TYPE = @MATERIAL_TYPE";
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//获取信息
parameters.Add(new DataParameter { ParameterName = "MATERIAL_TYPE", DataType = DbType.String, Value = materialtype });
model = session.Get<MaterialCodeInit>(sql, parameters.ToArray());
}
return model;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "信息数据层-获取信息"
});
throw;
}
}
//批量报废查询工作中心
public MaterialCodeInit GetProductTypeWorkCenter(string materialCode)
{
string sql = null;
MaterialCodeInit model = new MaterialCodeInit();
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = "SELECT top 1 * FROM T_BD_MATERIALCODEINIT WHERE MATERIAL_TYPE = (SELECT MATERIAL_TYPE_CODE FROM T_MD_MATERIAL WHERE MATERIAL_CODE = @materialCode)";
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//获取信息
parameters.Add(new DataParameter { ParameterName = "materialCode", DataType = DbType.String, Value = materialCode });
model = session.Get<MaterialCodeInit>(sql, parameters.ToArray());
}
return model;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "信息数据层-获取信息"
});
throw;
}
}
#endregion
#region 获取信息(产品档案)
/// <summary>
/// 获取信息(产品档案)
/// </summary>
/// <param name="">条件</param>
/// <returns>*信息</returns>
public List<Material> GetMaterialInfo(Material condition)
{
string sql = null;
List<Material> list = new List<Material>();
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetQuerySql(condition, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//获取信息
list = session.GetList<Material>(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "物料本体-获取信息"
});
throw;
}
}
#endregion
#region 获取门板计划使用的物料号
/// <summary>
/// 获取门板计划使用的物料号
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
public List<Material> GetMaterialDoorPlan(Material info)
{
string sql = null;
List<Material> list = new List<Material>();
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
try
{
sqlBuilder.AppendLine(" SELECT DISTINCT M.* ");
sqlBuilder.AppendLine(" FROM [T_MD_MATERIAL] AS M ");
sqlBuilder.AppendLine(" LEFT JOIN [T_MD_PBOM] AS B ");
sqlBuilder.AppendLine(" ON B.[MATERIAL_CODE]=M.[MATERIAL_CODE] ");
sqlBuilder.AppendLine(" LEFT JOIN [T_PP_ORDERINDENTITY] AS I ");
sqlBuilder.AppendLine(" ON I.[MATERIALTYPE]=M.[MATERIAL_TYPE_CODE] ");
whereBuilder.Append("AND B.[PBOM_CODE] IS NOT NULL");
//查询条件
if (string.IsNullOrEmpty(info.ORDER_TYPE) == false)
{
whereBuilder.Append(" AND I.ORDER_TYPE = @ORDER_TYPE");
parameters.Add(new DataParameter { ParameterName = "ORDER_TYPE", DataType = DbType.String, Value = info.ORDER_TYPE });
}
//颜色
if (string.IsNullOrEmpty(info.COLOR) == false && info.COLOR != "undefined")
{
whereBuilder.Append(" AND M.COLOR = @COLOR ");
parameters.Add(new DataParameter { ParameterName = "COLOR", DataType = DbType.String, Value = info.COLOR });
}
//高低配
if (string.IsNullOrEmpty(info.HBTYPE) == false && info.HBTYPE != "undefined")
{
whereBuilder.Append(" AND M.HBTYPE LIKE '%'+@HBTYPE+'%' ");
parameters.Add(new DataParameter { ParameterName = "HBTYPE", DataType = DbType.String, Value = info.HBTYPE });
}
//物料号
if (string.IsNullOrEmpty(info.MaterialCodes) == false)
{
whereBuilder.Append(" AND M.MATERIAL_TYPE_CODE not in " + info.MaterialCodes + "");
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
sqlBuilder.AppendLine(" ORDER BY M.MATERIAL_CODE");
using (IDataSession session = AppDataFactory.CreateMainSession())
{
sql = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
list = session.GetList<Material>(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "物料号信息数据层-获取信息");
throw ex;
}
}
#endregion
#region 获取物料信息list
/// <summary>
/// 获取物料信息
/// </summary>
/// <param name="">条件</param>
/// <returns>*信息</returns>
public List<Material> GetMaterialInfoList(Material condition)
{
string sql = null;
List<Material> materiallist=new List<Material>();
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetQuerySql(condition, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//获取信息
materiallist = session.GetList<Material>(sql, parameters.ToArray()).ToList();
}
return materiallist;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "物料本体-获取信息"
});
throw;
}
}
#endregion
public OrderIndentity GetOrderInfo(OrderIndentity model)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = "SELECT * FROM T_PP_ORDERINDENTITY WHERE '1'='1'";
if (string.IsNullOrEmpty(model.ORDER_TYPE) == false)
{
sql += " AND ORDER_TYPE = @ORDER_TYPE";
parameters.Add(new DataParameter("ORDER_TYPE", model.ORDER_TYPE));
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
string sqlChange = this.ChangeSqlByDB(sql, session);
//获取信息
model = session.Get<OrderIndentity>(sqlChange, parameters.ToArray());
}
return model;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "物料号信息数据层-获取信息");
throw ex;
}
}
/// <summary>
/// 成都注塑打码
/// </summary>
/// <param name="condition"></param>
/// <returns></returns>
public List<Material> GetMaterialInfoListBy(Material condition)
{
List<Material> list = new List<Material>();
string sql = null;
StringBuilder sqlBuilder = new StringBuilder();
sqlBuilder.AppendFormat(@"select * from T_MD_MATERIAL M
left join T_MD_MATERIAL_CLASS ma on ma.MATERIAL_TYPE_CODE=M.MATERIAL_TYPE_CODE
where MATERIAL_CODE !='{0}'
and M.COLOR=(select COLOR from T_MD_MATERIAL where MATERIAL_CODE='{0}')
and M.HBTYPE=(select HBTYPE from T_MD_MATERIAL where MATERIAL_CODE='{0}')
and ma.UP_MATERIAL_TYPE_CODE in
(select UP_MATERIAL_TYPE_CODE from T_MD_MATERIAL_CLASS
where MATERIAL_TYPE_CODE=
(select MATERIAL_TYPE_CODE from T_MD_MATERIAL where MATERIAL_CODE='{0}'))", condition.MATERIAL_CODE);
List<DataParameter> parameters = new List<DataParameter>();
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
sql = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
list = session.GetList<Material>(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "物料信息-成都注塑打码列表");
throw ex;
}
}
}
}