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.
462 lines
18 KiB
462 lines
18 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;
|
|
|
|
namespace QMAPP.MD.DAL
|
|
{
|
|
/// <summary>
|
|
/// 模块名称:物料分类
|
|
/// 作 者:郭兆福
|
|
/// 编写日期:2017年05月10日
|
|
/// </summary>
|
|
public class MaterialClassDAL : BaseDAL
|
|
{
|
|
|
|
#region 获取信息
|
|
/// <summary>
|
|
/// 获取信息
|
|
/// </summary>
|
|
/// <param name="">条件</param>
|
|
/// <returns>信息</returns>
|
|
public MaterialClass Get(MaterialClass model)
|
|
{
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = "SELECT * FROM T_MD_MATERIAL_CLASS 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_TYPE_CODE) == false)
|
|
{
|
|
sql += " AND MATERIAL_TYPE_CODE = @MATERIAL_TYPE_CODE";
|
|
parameters.Add(new DataParameter("MATERIAL_TYPE_CODE", model.MATERIAL_TYPE_CODE));
|
|
}
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
string sqlChange = this.ChangeSqlByDB(sql, session);
|
|
//获取信息
|
|
model = session.Get<MaterialClass>(sqlChange, parameters.ToArray());
|
|
}
|
|
return model;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
RecordExceptionLog(ex, "物料号信息数据层-获取信息");
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 获取分页列表
|
|
/// <summary>
|
|
/// 获取分页列表
|
|
/// </summary>
|
|
/// <param name="condition">条件</param>
|
|
/// <param name="page">数据页</param>
|
|
/// <returns>数据页</returns>
|
|
public DataPage GetList(MaterialClass 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<MaterialClass>(sql, parameters.ToArray(), page);
|
|
}
|
|
return page;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
RecordExceptionLog(ex, "物料号类型信息数据层-获取分页列表");
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取列表
|
|
/// </summary>
|
|
/// <param name="condition">条件</param>
|
|
/// <returns>全部集合</returns>
|
|
public List<MaterialClass> GetList(MaterialClass condition)
|
|
{
|
|
List<MaterialClass> list = new List<MaterialClass>();
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = this.GetQuerySql(condition, ref parameters);
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
list = session.GetList<MaterialClass>(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(MaterialClass 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.MATERIAL_TYPE_CODE ");
|
|
sqlBuilder.AppendLine(" ,M.MATERIAL_TYPE_NAME ");
|
|
sqlBuilder.AppendLine(" ,M.MATERIAL_ATTRIBUTE ");
|
|
sqlBuilder.AppendLine(" ,M.LAYER_NUM ");
|
|
sqlBuilder.AppendLine(" ,M.SEQ_NUM ");
|
|
sqlBuilder.AppendLine(" ,M.UP_MATERIAL_TYPE_CODE ");
|
|
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_CLASS M ");
|
|
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.MATERIAL_TYPE_CODE) == false)
|
|
{
|
|
whereBuilder.Append(" AND 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_ATTRIBUTE) == false)
|
|
{
|
|
whereBuilder.Append(" AND MATERIAL_ATTRIBUTE = @MATERIAL_ATTRIBUTE");
|
|
parameters.Add(new DataParameter { ParameterName = "MATERIAL_ATTRIBUTE", DataType = DbType.String, Value = condition.MATERIAL_ATTRIBUTE });
|
|
}
|
|
if (string.IsNullOrEmpty(condition.MaterialAttributes) == false)
|
|
{
|
|
whereBuilder.Append(" AND MATERIAL_ATTRIBUTE IN "+condition.MaterialAttributes+"");
|
|
//parameters.Add(new DataParameter { ParameterName = "MaterialAttributes", DataType = DbType.String, Value = condition.MaterialAttributes });
|
|
}
|
|
if (string.IsNullOrEmpty(condition.UpTypeCodes) == false)
|
|
{
|
|
whereBuilder.Append(" AND UP_MATERIAL_TYPE_CODE IN " + condition.UpTypeCodes + "");
|
|
//parameters.Add(new DataParameter { ParameterName = "MaterialAttributes", DataType = DbType.String, Value = condition.MaterialAttributes });
|
|
}
|
|
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>
|
|
/// <returns>同级别菜单列表</returns>
|
|
public List<MaterialClass> GetSubTreeList(MaterialClass materialclass)
|
|
{
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
List<MaterialClass> list = null;
|
|
string sql = null;
|
|
try
|
|
{
|
|
sql = "SELECT * FROM T_MD_MATERIAL_CLASS WHERE UP_MATERIAL_TYPE_CODE=@UP_MATERIAL_TYPE_CODE";
|
|
parameters.Add(new DataParameter { ParameterName = "UP_MATERIAL_TYPE_CODE", DataType = DbType.String, Value = materialclass.UP_MATERIAL_TYPE_CODE });
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
sql = this.ChangeSqlByDB(sql, session);
|
|
list = session.GetList<MaterialClass>(sql, parameters.ToArray()).ToList();
|
|
}
|
|
|
|
return list;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 物料类型下拉
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="condition"></param>
|
|
/// <returns></returns>
|
|
public List<MaterialClass> GetMaterialClassList(MaterialClass condition)
|
|
{
|
|
List<MaterialClass> list = new List<MaterialClass>();
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = this.GetQuerySql(condition, ref parameters);
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
string sqlChange = ChangeSqlByDB(sql, session);
|
|
list = session.GetList<MaterialClass>(sqlChange, parameters.ToArray()).ToList();
|
|
}
|
|
return list;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
RecordExceptionLog(ex, "物料信息-列表");
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 物料类型下拉(winform注塑下来)
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="condition"></param>
|
|
/// <returns></returns>
|
|
public List<MaterialClass> GetMaterialClassWithType(MaterialClass condition, WorkCell workcellmodel)
|
|
{
|
|
List<MaterialClass> list = new List<MaterialClass>();
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
|
|
sqlBuilder.AppendFormat(@"SELECT DISTINCT MC.*
|
|
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.MATERIAL_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);
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
sql = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
|
|
list = session.GetList<MaterialClass>(sql, parameters.ToArray()).ToList();
|
|
}
|
|
return list;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
RecordExceptionLog(ex, "物料信息-列表");
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
public List<MaterialClass> GetMaterialClassForOrder(string ordertype)
|
|
{
|
|
List<MaterialClass> list = new List<MaterialClass>();
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
|
|
sqlBuilder.AppendFormat(@"SELECT MC.*
|
|
FROM [T_MD_MATERIAL_CLASS] AS MC
|
|
LEFT JOIN [T_PP_ORDERINDENTITY] AS OI
|
|
ON OI.[MATERIALTYPE]=MC.[MATERIAL_TYPE_CODE]
|
|
WHERE OI.ORDER_TYPE='{0}'", ordertype);
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
sql = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
|
|
list = session.GetList<MaterialClass>(sql, parameters.ToArray()).ToList();
|
|
}
|
|
return list;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
RecordExceptionLog(ex, "物料信息-列表");
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 物料类型下拉(winform批量报废)
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="condition"></param>
|
|
/// <returns></returns>
|
|
public List<MaterialClass> GetMaterialClassToMendRecorderWasteForm()
|
|
{
|
|
List<MaterialClass> list = new List<MaterialClass>();
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
//查询父类字段UP_MATERIAL_TYPE_CODE里没有MATERIAL_TYPE_CODE的数据-最底层数据
|
|
sqlBuilder.AppendFormat(@"
|
|
SELECT * FROM [dbo].[T_MD_MATERIAL_CLASS]
|
|
where FLGDEL='0' AND MATERIAL_TYPE_CODE not in
|
|
( SELECT UP_MATERIAL_TYPE_CODE FROM [dbo].[T_MD_MATERIAL_CLASS]
|
|
group by UP_MATERIAL_TYPE_CODE )");
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
sql = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
|
|
list = session.GetList<MaterialClass>(sql, parameters.ToArray()).ToList();
|
|
}
|
|
return list;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
RecordExceptionLog(ex, "物料信息-列表");
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 获取SEQ_NUM最大号
|
|
/// <summary>
|
|
/// 获取信息
|
|
/// </summary>
|
|
/// <param name="">条件</param>
|
|
/// <returns>*信息</returns>
|
|
public MaterialClass GetMaxSeqNum(MaterialClass model)
|
|
{
|
|
try
|
|
{
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
var sql = " SELECT max(seq_num) as seq_num FROM T_MD_MATERIAL_CLASS where UP_MATERIAL_TYPE_CODE='" + model.UP_MATERIAL_TYPE_CODE + "' ";
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
return session.Get<MaterialClass>(sql, parameters.ToArray());
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 插入信息
|
|
/// <summary>
|
|
/// 插入信息(单表)
|
|
/// </summary>
|
|
/// <param name=model"">物料号信息</param>
|
|
/// <returns>插入行数</returns>
|
|
public int Insert(MaterialClass model)
|
|
{
|
|
int count = 0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//插入基本信息
|
|
count = session.Insert<MaterialClass>(model);
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
RecordExceptionLog(ex, "物料号信息数据层-插入信息");
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 删除信息
|
|
/// <summary>
|
|
/// 删除信息
|
|
/// </summary>
|
|
/// <param name="">信息</param>
|
|
/// <returns>插入行数</returns>
|
|
public int Delete(string pid)
|
|
{
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
int count = 0;
|
|
try
|
|
{
|
|
var sql = "delete from T_MD_MATERIAL_CLASS WHERE PID = '" + pid + "'";
|
|
if (this.BaseSession != null)
|
|
{
|
|
//删除基本信息
|
|
count = BaseSession.ExecuteSql(sql, parameters.ToArray());
|
|
}
|
|
else
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//删除基本信息
|
|
count = session.ExecuteSql(sql, parameters.ToArray());
|
|
}
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
RecordExceptionLog(ex, "删除物料类型信息");
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|