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.
181 lines
8.3 KiB
181 lines
8.3 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using QMAPP.FJC.Entity.Basic;
|
|
using QMFrameWork.Data;
|
|
using System.Data;
|
|
using QMAPP.FJC.Entity.Operation;
|
|
|
|
namespace QMAPP.FJC.DAL.Basic
|
|
{
|
|
/// <summary>
|
|
/// 模块编号:
|
|
/// 作 用:工艺路线下工序顺序操作类
|
|
/// 作 者:闫永刚
|
|
/// 编写日期:2017年08月31日
|
|
///</summary>
|
|
public class ProcessRouteWithWorkCellSeqDAL
|
|
{
|
|
/// <summary>
|
|
/// 获取工艺路线下工序顺序
|
|
/// </summary>
|
|
/// <param name="condition"></param>
|
|
/// <returns></returns>
|
|
public ProcessRouteWithWorkCellSeq GetByCondition(ProcessRouteWithWorkCellSeq condition)
|
|
{
|
|
ProcessRouteWithWorkCellSeq entity = new ProcessRouteWithWorkCellSeq();
|
|
|
|
StringBuilder sql = new StringBuilder();
|
|
sql.Append("select * from T_MD_PROCESS_ROUTE_WORKCELL_SEQ where 1=1 ");
|
|
|
|
List<DataParameter> paraList = new List<DataParameter>();
|
|
|
|
//通过工序获取
|
|
if (string.IsNullOrEmpty(condition.WORKCELL_CODE) == false)
|
|
{
|
|
sql.Append(" and WORKCELL_CODE=@WORKCELL_CODE ");
|
|
paraList.Add(new DataParameter() { ParameterName = "WORKCELL_CODE", DataType = DbType.String, Value = condition.WORKCELL_CODE });
|
|
}
|
|
|
|
//通过前置工序获取
|
|
if (string.IsNullOrEmpty(condition.PRE_WORKCELL_CODE) == false)
|
|
{
|
|
sql.Append(" and PRE_WORKCELL_CODE=@PRE_WORKCELL_CODE ");
|
|
paraList.Add(new DataParameter() { ParameterName = "PRE_WORKCELL_CODE", DataType = DbType.String, Value = condition.PRE_WORKCELL_CODE });
|
|
}
|
|
|
|
List<ProcessRouteWithWorkCellSeq> sqlList = new List<ProcessRouteWithWorkCellSeq>();
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
sqlList = session.GetList<ProcessRouteWithWorkCellSeq>(sql.ToString(), paraList.ToArray()).ToList<ProcessRouteWithWorkCellSeq>();
|
|
}
|
|
|
|
if (sqlList.Count > 0)
|
|
{
|
|
entity = sqlList[0];
|
|
}
|
|
return entity;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据当前工序编码获取前置工序
|
|
/// </summary>
|
|
/// <param name="workcellcode">工序编码</param>
|
|
/// <returns></returns>
|
|
public List<ProcessRouteWithWorkCellSeq> GetPreWorkcell(string workcellcode)
|
|
{
|
|
StringBuilder sql = new StringBuilder();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql.Append("SELECT * FROM [T_MD_PROCESS_ROUTE_WORKCELL_SEQ] WHERE [WORKCELL_CODE]=@workcellcode");
|
|
parameters.Add(new DataParameter("workcellcode", workcellcode));
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
return session.GetList<ProcessRouteWithWorkCellSeq>(sql.ToString(), parameters.ToArray()).ToList();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 判读工序是否为工艺路线的最后一序
|
|
/// </summary>
|
|
/// <param name="routecode">工艺路线编码</param>
|
|
/// <param name="workcellcode">工序编码</param>
|
|
/// <returns></returns>
|
|
public bool EndOfRoute(string routecode, string workcellcode)
|
|
{
|
|
StringBuilder sql = new StringBuilder();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql.Append("SELECT * FROM [T_MD_PROCESS_ROUTE_WORKCELL_SEQ] WHERE [PRE_WORKCELL_CODE] = @workcellcode AND [ROUTE_CODE]=@routecode");
|
|
parameters.Add(new DataParameter("workcellcode", workcellcode));
|
|
parameters.Add(new DataParameter("routecode", routecode));
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
var seqs = session.GetList<ProcessRouteWithWorkCellSeq>(sql.ToString(), parameters.ToArray()).ToList();
|
|
return seqs.Count == 0;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 获取
|
|
/// </summary>
|
|
/// <param name="condition"></param>
|
|
/// <returns></returns>
|
|
public ProcessRouteWithWorkCellSeq GetNextWorkCellBetweenRoute(Product condition)
|
|
{
|
|
ProcessRouteWithWorkCellSeq seq = new ProcessRouteWithWorkCellSeq();
|
|
string sql = string.Format(@"select * from T_MD_PROCESS_ROUTE_WORKCELL_SEQ seq where seq.ROUTE_CODE in
|
|
(select top 1 ROUTE_CODE from (select ROUTE_CODE from T_MD_PROCESS_ROUTE r where 1=1 and FLGDEL=0 and
|
|
not exists
|
|
( select 1 from T_MD_PROCESS_ROUTE_WORKCELL w where r.ROUTE_CODE=w.ROUTE_CODE and w.WORKCELL_CODE='{0}')
|
|
and exists
|
|
(select * from T_MD_MATERIAL_ROUTE mr where mr.ROUTE_CODE=r.ROUTE_CODE and mr.MATERIAL_CODE in
|
|
(select b.MATERIAL_CODE from T_MD_PBOM_ITEM m left join T_MD_PBOM b on m.PBOM_CODE=b.PBOM_CODE where m.MATERIAL_CODE='{1}')
|
|
)
|
|
InterSect
|
|
select ROUTE_CODE from T_MD_PROCESS_ROUTE r2
|
|
where r2.FLGDEL='0' and exists
|
|
( select 1 from T_MD_PROCESS_ROUTE_WORKCELL prw where prw.ROUTE_CODE=r2.ROUTE_CODE and prw.WORKCELL_CODE
|
|
in (select WORKCELL_CODE from T_QT_DAI dai where dai.MATERIAL_TYPE in (select m.MATERIAL_TYPE_CODE from T_MD_MATERIAL m where m.MATERIAL_CODE='{1}'))
|
|
)
|
|
)temp
|
|
) and seq.FLGDEL=0 AND (PRE_WORKCELL_CODE='' OR PRE_WORKCELL_CODE IS NULL )
|
|
and exists(select 1 from T_QT_DAI d where d.WORKCELL_CODE=seq.WORKCELL_CODE and
|
|
d.MATERIAL_TYPE in (select m1.MATERIAL_TYPE_CODE from T_MD_MATERIAL m1 where m1.MATERIAL_CODE='{1}'))"
|
|
, condition.WORKCELL_CODE, condition.MATERIAL_CODE);
|
|
|
|
string sql2 = string.Format("select * from T_MD_PROCESS_ROUTE_WORKCELL_SEQ seq where WORKCELL_CODE =(select max(GMP) from T_MD_PBOM_ITEM where MATERIAL_CODE='{0}')", condition.MATERIAL_CODE);
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
seq = session.Get<ProcessRouteWithWorkCellSeq>(sql.ToString(), new List<DataParameter>().ToArray());
|
|
if (seq == null)
|
|
{
|
|
seq = session.Get<ProcessRouteWithWorkCellSeq>(sql2.ToString(), new List<DataParameter>().ToArray());
|
|
}
|
|
}
|
|
return seq;
|
|
}
|
|
|
|
|
|
public bool InSameRoute(string workcell_A, string workcell_B)
|
|
{
|
|
StringBuilder sql = new StringBuilder();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql.Append("SELECT TOP 1 ROUTE_CODE ");
|
|
sql.Append(" FROM T_MD_PROCESS_ROUTE_WORKCELL ");
|
|
sql.Append(" WHERE WORKCELL_CODE=@workcellA ");
|
|
sql.Append(" OR WORKCELL_CODE=@workcellB ");
|
|
sql.Append(" GROUP BY ROUTE_CODE ");
|
|
sql.Append("HAVING COUNT(*)=2 ");
|
|
|
|
parameters.Add(new DataParameter("workcellA", workcell_A));
|
|
parameters.Add(new DataParameter("workcellB", workcell_B));
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
var route = session.ExecuteSqlScalar(sql.ToString(), parameters.ToArray());
|
|
return !string.IsNullOrEmpty(route + "");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|