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

836 lines
33 KiB

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using QMAPP.DAL;
using QMAPP.MD.Entity;
using QMFrameWork.Data;
namespace QMAPP.MD.DAL
{
/// <summary>
/// 模块名称:工序
/// 作 者:郭兆福
/// 编写日期:2017年05月11日
/// </summary>
public class WorkCellDAL : BaseDAL
{
#region 获取信息
/// <summary>
/// 获取信息
/// </summary>
/// <param name="">条件</param>
/// <returns>信息</returns>
public WorkCell Get(WorkCell model)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = "SELECT * FROM T_MD_WORKCELL WHERE FLGDEL='0' ";
if (string.IsNullOrEmpty(model.PID) == false)
{
sql += " AND PID = @PID";
parameters.Add(new DataParameter("PID", model.PID));
}
if (string.IsNullOrEmpty(model.WORKCELL_CODE) == false)
{
sql += " AND WORKCELL_CODE = @WORKCELL_CODE";
parameters.Add(new DataParameter("WORKCELL_CODE", model.WORKCELL_CODE));
}
if (string.IsNullOrEmpty(model.WORKCENTER_CODE) == false)
{
sql += " AND WORKCENTER_CODE = @WORKCENTER_CODE";
parameters.Add(new DataParameter("WORKCENTER_CODE", model.WORKCENTER_CODE));
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
// 对应多种数据库
string sqlChange = this.ChangeSqlByDB(sql, session);
//获取信息
model = session.Get<WorkCell>(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(WorkCell 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())
{
// 对应多种数据库
string sqlChange = this.ChangeSqlByDB(sql, session);
page = session.GetDataPage<WorkCell>(sqlChange, parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "工序信息-获取列表");
throw ex;
}
}
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <returns>列表</returns>
public List<WorkCell> GetList(WorkCell condition)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
List<WorkCell> listProcessInfo = new List<WorkCell>();
try
{
sql = this.GetQuerySql(condition, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
// 对应多种数据库
string sqlChange = this.ChangeSqlByDB(sql, session);
listProcessInfo = session.GetList<WorkCell>(sqlChange, parameters.ToArray()).ToList();
}
return listProcessInfo;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "工序信息-获取列表");
throw ex;
}
}
#endregion
#region 获取查询语句
/// <summary>
/// 获取查询语句
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
private string GetQuerySql(WorkCell condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.AppendLine(" SELECT M.PID ");
sqlBuilder.AppendLine(" ,M.WORKCELL_CODE ");
sqlBuilder.AppendLine(" ,M.WORKCELL_NAME ");
sqlBuilder.AppendLine(" ,M.WORKCENTER_CODE ");
sqlBuilder.AppendLine(" ,W.WORKCENTER_NAME ");
sqlBuilder.AppendLine(" ,M.FACTORY_CODE ");
sqlBuilder.AppendLine(" ,F.FACTORY_NAME ");
sqlBuilder.AppendLine(" ,M.FLAG_BACKFLUSH ");
sqlBuilder.AppendLine(" ,M.REMARK ");
sqlBuilder.AppendLine(" ,M.CREATEUSER ");
sqlBuilder.AppendLine(" ,M.CREATEDATE ");
sqlBuilder.AppendLine(" ,M.UPDATEUSER ");
sqlBuilder.AppendLine(" ,M.UPDATEDATE ");
sqlBuilder.AppendLine(" FROM T_MD_WORKCELL M ");
sqlBuilder.AppendLine(" LEFT JOIN T_MD_WORKCENTER W ON M.WORKCENTER_CODE=W.WORKCENTER_CODE AND M.FACTORY_CODE=W.FACTORY_CODE");
sqlBuilder.AppendLine(" LEFT JOIN T_MD_FACTORY F ON F.FACTORY_CODE=M.FACTORY_CODE ");
//查询条件
//工序名称
if (string.IsNullOrEmpty(condition.WORKCELL_NAME) == false)
{
whereBuilder.Append(" AND M.WORKCELL_NAME LIKE @WORKCELL_NAME");
parameters.Add(new DataParameter { ParameterName = "WORKCELL_NAME", DataType = DbType.String, Value = EscapeValue(condition.WORKCELL_NAME) + "%" });
}
//工序类别
if (string.IsNullOrEmpty(condition.WORKCELL_CODE) == false)
{
whereBuilder.Append(" AND M.WORKCELL_CODE = @WORKCELL_CODE");
parameters.Add(new DataParameter { ParameterName = "WORKCELL_CODE", DataType = DbType.String, Value = condition.WORKCELL_CODE });
}
//工作中心
if (string.IsNullOrEmpty(condition.WORKCENTER_CODE) == false)
{
whereBuilder.Append(" AND M.WORKCENTER_CODE = @WORKCENTER_CODE");
parameters.Add(new DataParameter { ParameterName = "WORKCENTER_CODE", DataType = DbType.String, Value = condition.WORKCENTER_CODE });
}
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 });
}
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>true:已存在;false:不存在。</returns>
public bool IsExistsWorkCellCodeName(WorkCell model)
{
string PID = "";
int count = 0;
string sql = null;
try
{
if (string.IsNullOrEmpty(model.PID) == false)
{
PID = model.PID;
}
List<DataParameter> paramList = new List<DataParameter>();
sql = "SELECT COUNT(*) FROM T_MD_WORKCELL WHERE PID <> @PID AND FACTORY_CODE=@FACTORY_CODE AND WORKCELL_CODE=@WORKCELL_CODE";
paramList.Add(new DataParameter { ParameterName = "PID", Value = PID });
paramList.Add(new DataParameter { ParameterName = "FACTORY_CODE", Value = model.FACTORY_CODE });
paramList.Add(new DataParameter { ParameterName = "WORKCELL_CODE", Value = model.WORKCELL_CODE });
using (IDataSession session = AppDataFactory.CreateMainSession())
{
// 对应多种数据库
string sqlChange = this.ChangeSqlByDB(sql, session);
count = Convert.ToInt32(session.ExecuteSqlScalar(sqlChange, paramList.ToArray()));
}
return count > 0;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "工序信息-判断编号名称是否存在");
throw ex;
}
}
#endregion
#region 插入信息
/// <summary>
/// 插入信息(单表)
/// </summary>
/// <param name="">信息</param>
/// <returns>插入行数</returns>
public int Insert(WorkCell model)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//插入基本信息
count = session.Insert<WorkCell>(model);
}
return count;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "工序信息-插入信息");
throw ex;
}
}
#endregion
#region 更新信息
/// <summary>
/// 更新信息
/// </summary>
/// <param name=""></param>
/// <returns>更新行数</returns>
public int Update(WorkCell model)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//更新基本信息
count = session.Update<WorkCell>(model);
}
return count;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "工序信息-更新信息");
throw ex;
}
}
#endregion
#region 删除
/// <summary>
/// 删除信息
/// </summary>
/// <param name="model">物料号信息(ID)</param>
/// <returns>删除个数</returns>
public int Delete(WorkCell model)
{
StringBuilder sqlBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//删除基本信息
count = session.Delete<WorkCell>(model);
}
return count;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "工序信息-删除");
throw ex;
}
}
#endregion
#region 工序下拉
/// <summary>
///
/// </summary>
/// <param name="condition"></param>
/// <returns></returns>
public List<WorkCell> GetWorkCellBasicList(WorkCell condition)
{
List<WorkCell> list = new List<WorkCell>();
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetQuerySql(condition, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
// 对应多种数据库
string sqlChange = this.ChangeSqlByDB(sql, session);
list = session.GetList<WorkCell>(sqlChange, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "工序信息-列表");
throw ex;
}
}
#endregion
#region 获取工序下拉列表数据
/// <summary>
/// 获取工序下拉列表数据
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public List<WorkCell> GetWorkCellList(WorkCell model)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
List<WorkCell> list = new List<WorkCell>();
//sql = @" SELECT * FROM T_MD_WORKCELL WHERE FLGDEL = '0' ";
sql = this.GetQuerySql(model, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
sql = this.ChangeSqlByDB(sql, session);
list = session.GetList<WorkCell>(sql, parameters.ToArray()).OrderBy(p=>p.WORKCELL_CODE).ToList();
}
return list;
}
#endregion
#region 工序信息下拉
/// <summary>
///
/// </summary>
/// <param name="condition"></param>
/// <returns></returns>
public List<WorkCell> GetWorkCellWithRouteList(WorkCell model, string routecode)
{
List<WorkCell> list = new List<WorkCell>();
string sql = null;
StringBuilder sqlBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
sqlBuilder.AppendLine("SELECT * FROM T_MD_WORKCELL W ");
sqlBuilder.AppendLine(" LEFT JOIN T_MD_PROCESS_ROUTE_WORKCELL PRW ON PRW.WORKCELL_CODE=W.WORKCELL_CODE ");
sqlBuilder.AppendLine(" LEFT JOIN T_MD_PROCESS_ROUTE PR ON PR.ROUTE_CODE=PRW.ROUTE_CODE ");
sqlBuilder.AppendLine(" WHERE PR.ROUTE_CODE=@ROUTE_CODE");
parameters.Add(new DataParameter { ParameterName = "ROUTE_CODE", DataType = DbType.String, Value = routecode });
sql = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
list = session.GetList<WorkCell>(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "工序信息-下拉列表");
throw ex;
}
}
#endregion
#region 工序信息下拉排序
/// <summary>
///
/// </summary>
/// <param name="condition"></param>
/// <returns></returns>
public List<WorkCell> GetWorkCellWithRouteListSeq(string routecode)
{
List<WorkCell> list = new List<WorkCell>();
string sql = null;
StringBuilder sqlBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
sqlBuilder.AppendLine("with DEPTS as ");
sqlBuilder.AppendLine("( select * from T_MD_PROCESS_ROUTE_WORKCELL_SEQ where ROUTE_CODE=@ROUTE_CODE and PRE_WORKCELL_CODE is null ");
sqlBuilder.AppendLine("union all ");
sqlBuilder.AppendLine("select t.* from T_MD_PROCESS_ROUTE_WORKCELL_SEQ t , DEPTS where DEPTS.WORKCELL_CODE = t.PRE_WORKCELL_CODE ) ");
sqlBuilder.AppendLine("select d.WORKCELL_CODE,(select WORKCELL_NAME from T_MD_WORKCELL where WORKCELL_CODE=d.WORKCELL_CODE) as WORKCELL_NAME from DEPTS d ");
parameters.Add(new DataParameter { ParameterName = "ROUTE_CODE", DataType = DbType.String, Value = routecode });
sql = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
list = session.GetList<WorkCell>(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "工序信息-下拉列表");
throw ex;
}
}
#endregion
#region 判断工序是否完成
/// <summary>
/// 断工序是否完成
/// </summary>
/// <param name="ppCode">计划编码</param>
/// <param name="cellCode">工序</param>
/// <returns>true;完成 false:未完成</returns>
public bool IsWorkCellEnd(string ppCode, string cellCode)
{
try
{
StringBuilder sqlBuilder = new StringBuilder();
//构成查询语句
sqlBuilder.Append(" SELECT COUNT(1) ");
sqlBuilder.Append(" FROM T_QT_DAI C ");
sqlBuilder.Append(" WHERE ");
sqlBuilder.Append(" C.FLGDEL = '0' ");
// 主要采集点
sqlBuilder.Append(" AND C.PIVOTAL = '1' ");
// 采集点状态
sqlBuilder.Append(" AND C.DA_STATUS = '1' ");
sqlBuilder.Append(" AND C.WORKCELL_CODE = @WORKCELL_CODE ");
sqlBuilder.Append(" AND NOT EXISTS ( ");
sqlBuilder.Append(" SELECT 1 ");
sqlBuilder.Append(" FROM T_QT_WIP_DAI_HIS E ");
sqlBuilder.Append(" WHERE ");
sqlBuilder.Append(" E.WORKCELL_CODE = C.WORKCELL_CODE ");
sqlBuilder.Append(" AND E.PP_CODE = @PP_CODE ");
sqlBuilder.Append(" AND E.DA_CODE = C.DA_CODE ) ");
DataParameter[] para = { new DataParameter("WORKCELL_CODE", DbType.String, cellCode), new DataParameter("PP_CODE", DbType.String, ppCode) };
if (null != BaseSession)
{
string sqlChange = ChangeSqlByDB(sqlBuilder.ToString(), BaseSession);
return (Convert.ToInt32(BaseSession.ExecuteSqlScalar(sqlChange, para)) == 0 ? true : false);
}
else
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
string sqlChange = ChangeSqlByDB(sqlBuilder.ToString(), session);
return (Convert.ToInt32(session.ExecuteSqlScalar(sqlChange, para)) == 0 ? true : false);
}
}
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取当前工序的下一工序
/// <summary>
/// 获取当前工序的下一工序
/// </summary>
/// <param name="routeCode">工艺路线</param>
/// <param name="workCellCode">当前工序</param>
/// <returns>工序列表</returns>
public WorkCell GetNextWorkCell(string routeCode,string workCellCode)
{
StringBuilder sqlBuilder = new StringBuilder();
try
{
sqlBuilder.Append(" SELECT ");
// 下一工序
sqlBuilder.Append(GetSqlSelectItem("C"));
sqlBuilder.Append(" FROM T_MD_PROCESS_ROUTE_WORKCELL A ");
sqlBuilder.Append(" ,T_MD_PROCESS_ROUTE_WORKCELL_SEQ B ");
sqlBuilder.Append(" ,T_MD_WORKCELL C ");
sqlBuilder.Append(" WHERE A.WORKCELL_CODE = B.PRE_WORKCELL_CODE "); // 得到当前工序的下一个工序
sqlBuilder.Append(" AND A.ROUTE_CODE = B.ROUTE_CODE ");
sqlBuilder.Append(" AND B.WORKCELL_CODE = C.WORKCELL_CODE "); // 得到下一个工序
sqlBuilder.Append(" AND A.FLGDEL = '0' ");
sqlBuilder.Append(" AND B.FLGDEL = '0' ");
sqlBuilder.Append(" AND C.FLGDEL = '0' ");
sqlBuilder.Append(" AND A.ROUTE_CODE = @ROUTE_CODE ");
sqlBuilder.Append(" AND A.WORKCELL_CODE =@WORKCELL_CODE ");
DataParameter[] para = { new DataParameter("ROUTE_CODE", DbType.String, routeCode), new DataParameter("WORKCELL_CODE", DbType.String, workCellCode) };
if (null != BaseSession)
{
// 对应多种数据库
string sqlChange = this.ChangeSqlByDB(sqlBuilder.ToString(), BaseSession);
return BaseSession.Get<WorkCell>(sqlChange, para);
}
else
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
// 对应多种数据库
string sqlChange = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
return session.Get<WorkCell>(sqlChange, para);
}
}
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 判断是否是第一道工序
/// <summary>
/// 判断是否是第一道工序
/// </summary>
/// <param name="routeCode">工艺路线</param>
/// <param name="workCellCode">当前工序</param>
/// <returns>true:是 false:否</returns>
public bool IsFristWorkCell(string routeCode, string workCellCode)
{
StringBuilder sqlBuilder = new StringBuilder();
try
{
sqlBuilder.Append(" SELECT ");
sqlBuilder.Append(" * ");
sqlBuilder.Append(" FROM T_MD_PROCESS_ROUTE_WORKCELL_SEQ ");
sqlBuilder.Append(" WHERE ROUTE_CODE = @ROUTE_CODE ");
sqlBuilder.Append(" AND WORKCELL_CODE =@WORKCELL_CODE ");
sqlBuilder.Append(" AND FLGDEL = '0' ");
ProcessRouteWorkCellSeq workCellSeq;
DataParameter[] para = { new DataParameter("ROUTE_CODE", DbType.String, routeCode), new DataParameter("WORKCELL_CODE", DbType.String, workCellCode) };
if (null != BaseSession)
{
// 对应多种数据库
string sqlChange = this.ChangeSqlByDB(sqlBuilder.ToString(), BaseSession);
workCellSeq = BaseSession.Get<ProcessRouteWorkCellSeq>(sqlChange, para);
}
else
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
// 对应多种数据库
string sqlChange = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
workCellSeq = session.Get<ProcessRouteWorkCellSeq>(sqlChange, para);
}
}
// 没有数据,或者是前置工序为空 则为第一道工序
if (null == workCellSeq || string.IsNullOrEmpty(workCellSeq.PRE_WORKCELL_CODE) == true)
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 得到检索项目
/// <summary>
/// 得到检索项目
/// </summary>
/// <param name="suffix"></param>
/// <returns></returns>
private string GetSqlSelectItem(string suffix)
{
String[] tableItem = {"PID"
,"WORKCENTER_CODE"
,"WORKCELL_CODE"
,"WORKCELL_NAME"
,"FLAG_BACKFLUSH"
,"REMARK"
,"CREATEUSER"
,"CREATEDATE"
,"UPDATEUSER"
,"UPDATEDATE"
,"FLGDEL"
};
StringBuilder sb = new StringBuilder();
if (String.IsNullOrEmpty(suffix))
{
suffix = ",";
}
else
{
suffix = "," + suffix + ".";
}
foreach (string str in tableItem)
{
sb.Append(suffix).Append(str);
}
return sb.ToString().Substring(1);
}
#endregion
#region 根据工序编码获取工序
/// <summary>
/// 根据工序编码获取工序
/// </summary>
/// <param name="workcellcode"></param>
/// <returns></returns>
public WorkCell GetWorkCellByCode(string workcellcode)
{
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
string sql = "SELECT * FROM [T_MD_WORKCELL] WHERE WORKCELL_CODE=@workcellcode";
var workcell = session.Get<WorkCell>(sql, new DataParameter("workcellcode", workcellcode));
return workcell;
}
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 通过查询条件获取工序
/// <summary>
/// 通过查询条件获取工序
/// </summary>
/// <param name="condition"></param>
/// <returns></returns>
public WorkCell GetByCondition(WorkCell condition)
{
WorkCell entity = new WorkCell();
StringBuilder sql = new StringBuilder();
sql.Append("select * from T_MD_WORKCELL 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 });
}
List<WorkCell> workCellList = new List<WorkCell>();
using (IDataSession session = AppDataFactory.CreateMainSession())
{
workCellList = session.GetList<WorkCell>(sql.ToString(), paraList.ToArray()).ToList<WorkCell>();
}
if (workCellList.Count > 0)
{
entity = workCellList[0];
}
return entity;
}
#endregion
#region 获取下道工序
/// <summary>
/// 获取下道工序
/// </summary>
/// <param name="currentCell"></param>
/// <returns></returns>
public WorkCell GetNextWorkCell(WorkCell currentCell)
{
WorkCell cell = new WorkCell();
string sql = string.Format("select * from T_MD_WORKCELL where WORKCELL_CODE in (select WORKCELL_CODE from T_MD_PROCESS_ROUTE_WORKCELL_SEQ where PRE_WORKCELL_CODE='{0}' ) ", currentCell.WORKCELL_CODE);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
cell = session.Get<WorkCell>(sql, new List<DataParameter>().ToArray());
}
return cell;
}
#endregion
#region 根据物料号获取PBOM表中工作中心
/// <summary>
/// 根据物料号获取PBOM表中工作中心
/// </summary>
/// <param name="materialcode"></param>
/// <returns></returns>
public string GetWorkcenterWithMaterial(string materialcode)
{
string workcentercode="";
StringBuilder sqlBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
sqlBuilder.Append(" SELECT WC.WORKCENTER_CODE ");
sqlBuilder.Append(" FROM T_MD_WORKCELL WC ");
sqlBuilder.Append("LEFT JOIN T_MD_PROCESS_ROUTE_WORKCELL PRW ON PRW.WORKCELL_CODE = WC.WORKCELL_CODE ");
sqlBuilder.Append("LEFT JOIN T_MD_PROCESS_ROUTE PR ON PR.ROUTE_CODE = PRW.ROUTE_CODE ");
sqlBuilder.Append("LEFT JOIN T_MD_MATERIAL_ROUTE MR ON MR.ROUTE_CODE = PR.ROUTE_CODE ");
sqlBuilder.Append("LEFT JOIN T_MD_PBOM P ON P.MATERIAL_CODE = MR.MATERIAL_CODE ");
sqlBuilder.Append(" WHERE P.MATERIAL_CODE = @MATERIAL_CODE");
parameters.Add(new DataParameter { ParameterName = "MATERIAL_CODE", DataType = DbType.String, Value = materialcode });
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
string sqlChange = ChangeSqlByDB(sqlBuilder.ToString(), session);
//获取信息
var temp=session.ExecuteSqlScalar(sqlChange, parameters.ToArray());
if(temp!=null)
workcentercode = temp.ToString();
}
return workcentercode;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "工序信息数据层-根据物料号获取PBOM表中工作中心");
throw ex;
}
}
#endregion
#region 根据工作中心
/// <summary>
/// 工作中心
/// </summary>
/// <param name="materialcode"></param>
/// <returns></returns>
public string GetWorkcenter(string ordertype)
{
string workcentercode = "";
StringBuilder sqlBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
sqlBuilder.Append(" SELECT WORKCENTER ");
sqlBuilder.Append(" FROM T_PP_ORDERINDENTITY ");
sqlBuilder.Append(" WHERE ORDER_TYPE = @ORDER_TYPE");
parameters.Add(new DataParameter { ParameterName = "ORDER_TYPE", DataType = DbType.String, Value = ordertype });
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
string sqlChange = ChangeSqlByDB(sqlBuilder.ToString(), session);
//获取信息
var temp = session.ExecuteSqlScalar(sqlChange, parameters.ToArray());
if (temp != null)
workcentercode = temp.ToString();
}
return workcentercode;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "工序信息数据层-根据物料号获取PBOM表中工作中心");
throw ex;
}
}
#endregion
#region
public List<ProcessRouteWorkCellSeq> GetFirstWorkCell(string pbomcode)
{
List<ProcessRouteWorkCellSeq> list = new List<ProcessRouteWorkCellSeq>();
if (string.IsNullOrEmpty(pbomcode))
{
return list;
}
string sql = string.Format(@"SELECT seq.* FROM T_MD_PBOM pm,T_MD_MATERIAL_ROUTE mr,T_MD_PROCESS_ROUTE_WORKCELL rw,T_MD_PROCESS_ROUTE_WORKCELL_SEQ seq
where pm.PBOM_CODE='{0}' and pm.MATERIAL_CODE=mr.MATERIAL_CODE
and mr.ROUTE_CODE=rw.ROUTE_CODE and rw.WORKCELL_CODE=seq.WORKCELL_CODE
and (seq.PRE_WORKCELL_CODE='' or seq.PRE_WORKCELL_CODE is null)", pbomcode);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
list = session.GetList<ProcessRouteWorkCellSeq>(sql, new List<DataParameter>().ToArray()).ToList<ProcessRouteWorkCellSeq>();
}
return list;
}
#endregion
}
}