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.
973 lines
39 KiB
973 lines
39 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.MD.Entity.View;
|
|
|
|
|
|
namespace QMAPP.MD.DAL
|
|
{
|
|
/// <summary>
|
|
/// 模块名称:工艺路线
|
|
/// 作 者:郭兆福
|
|
/// 编写日期:2017年05月12日
|
|
/// </summary>
|
|
public class ProcessRouteDAL : BaseDAL
|
|
{
|
|
#region 获取信息
|
|
/// <summary>
|
|
/// 获取信息
|
|
/// </summary>
|
|
/// <param name="">条件</param>
|
|
/// <returns>*信息</returns>
|
|
public ProcessRoute Get(ProcessRoute model)
|
|
{
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = "SELECT * FROM T_MD_PROCESS_ROUTE WHERE FLGDEL='0' ";
|
|
if (string.IsNullOrEmpty(model.PID) == false)
|
|
{
|
|
sql += " AND PID = @PID";
|
|
parameters.Add(new DataParameter("PID", model.PID));
|
|
}
|
|
if (string.IsNullOrEmpty(model.ROUTE_CODE) == false)
|
|
{
|
|
sql += " AND ROUTE_CODE = @ROUTE_CODE";
|
|
parameters.Add(new DataParameter("ROUTE_CODE", model.ROUTE_CODE));
|
|
}
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
// 对应多种数据库
|
|
string sqlChange = this.ChangeSqlByDB(sql, session);
|
|
//获取信息
|
|
model = session.Get<ProcessRoute>(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(ProcessRoute 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";
|
|
}
|
|
//else
|
|
//{
|
|
// //按照标题排序
|
|
// if (page.SortExpression.IndexOf("AREA") > -1)
|
|
// {
|
|
// page.SortExpression = page.SortExpression.Replace("PROCESSTYPETXT", "PROCESSTYPE");
|
|
// }
|
|
// if (page.SortExpression.IndexOf("MATERIALTYPETXT") > -1)
|
|
// {
|
|
// page.SortExpression = page.SortExpression.Replace("MATERIALTYPETXT", "MATERIALTYPE");
|
|
// }
|
|
//}
|
|
#endregion
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
// 对应多种数据库
|
|
string sqlChange = this.ChangeSqlByDB(sql, session);
|
|
page = session.GetDataPage<ProcessRoute>(sqlChange, parameters.ToArray(), page);
|
|
}
|
|
return page;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
RecordExceptionLog(ex, "工艺路线数据层-获取列表");
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 获取查询语句
|
|
/// <summary>
|
|
/// 获取查询语句
|
|
/// </summary>
|
|
/// <param name="user">查询条件</param>
|
|
/// <param name="parameters">参数</param>
|
|
/// <returns>查询语句</returns>
|
|
private string GetQuerySql(ProcessRoute condition, ref List<DataParameter> parameters)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
try
|
|
{
|
|
sqlBuilder.AppendLine("SELECT T.PID ");
|
|
sqlBuilder.AppendLine(" ,T.FACTORY_CODE ");
|
|
sqlBuilder.AppendLine(" ,F.FACTORY_NAME ");
|
|
sqlBuilder.AppendLine(" ,T.ROUTE_CODE ");
|
|
sqlBuilder.AppendLine(" ,T.ROUTE_NAME ");
|
|
sqlBuilder.AppendLine(" ,T.EFF_DATE ");
|
|
sqlBuilder.AppendLine(" ,T.EXP_DATE ");
|
|
sqlBuilder.AppendLine(" ,T.ROUTE_VER ");
|
|
sqlBuilder.AppendLine(" ,T.REMARK ");
|
|
sqlBuilder.AppendLine(" ,T.CREATEDATE ");
|
|
sqlBuilder.AppendLine(" ,T.UPDATEDATE ");
|
|
sqlBuilder.AppendLine(" ,T.FLGDEL ");
|
|
sqlBuilder.AppendLine(" FROM T_MD_PROCESS_ROUTE T ");;
|
|
sqlBuilder.AppendLine(" LEFT JOIN T_MD_FACTORY F ON F.FACTORY_CODE=T.FACTORY_CODE ");
|
|
|
|
|
|
whereBuilder.Append(" AND T.FLGDEL='0'");
|
|
//查询条件
|
|
//工厂
|
|
if (string.IsNullOrEmpty(condition.FACTORY_CODE) == false)
|
|
{
|
|
whereBuilder.Append(" AND T.FACTORY_CODE = @FACTORY_CODE ");
|
|
parameters.Add(new DataParameter { ParameterName = "FACTORY_CODE", DataType = DbType.String, Value = condition.FACTORY_CODE });
|
|
}
|
|
//工艺路线编码
|
|
if (string.IsNullOrEmpty(condition.ROUTE_CODE) == false)
|
|
{
|
|
whereBuilder.Append(" AND T.ROUTE_CODE = @ROUTE_CODE ");
|
|
parameters.Add(new DataParameter { ParameterName = "ROUTE_CODE", DataType = DbType.String, Value = condition.ROUTE_CODE });
|
|
}
|
|
//工艺路线名称
|
|
if (string.IsNullOrEmpty(condition.ROUTE_NAME) == false)
|
|
{
|
|
whereBuilder.Append(" AND T.ROUTE_NAME LIKE @ROUTE_NAME");
|
|
parameters.Add(new DataParameter { ParameterName = "ROUTE_NAME", DataType = DbType.String, Value = base.EscapeValue(condition.ROUTE_NAME) + "%" });
|
|
}
|
|
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 ExistsProcessRoute(ProcessRoute 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_PROCESS_ROUTE WHERE PID <> @PID AND FACTORY_CODE=@FACTORY_CODE AND ROUTE_CODE=@ROUTE_CODE AND FLGDEL = '0' ";
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
// 对应多种数据库
|
|
string sqlChange = this.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 = "ROUTE_CODE", Value = model.ROUTE_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(ProcessRoute model)
|
|
{
|
|
int count = 0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//插入基本信息
|
|
count = session.Insert<ProcessRoute>(model);
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
RecordExceptionLog(ex, "工艺路线数据层-插入信息");
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 更新信息
|
|
/// <summary>
|
|
/// 更新信息
|
|
/// </summary>
|
|
/// <param name="model">工艺路线</param>
|
|
/// <returns>更新行数</returns>
|
|
public int Update(ProcessRoute model)
|
|
{
|
|
int count = 0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//更新基本信息
|
|
count = session.Update<ProcessRoute>(model);
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
RecordExceptionLog(ex, "工艺路线数据层-更新信息");
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 删除信息
|
|
/// <summary>
|
|
/// 删除信息
|
|
/// </summary>
|
|
/// <param name="model">工艺路线(ID)</param>
|
|
/// <returns>删除个数</returns>
|
|
public int Delete(ProcessRoute model)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
int count = 0;
|
|
try
|
|
{
|
|
|
|
sqlBuilder.Append("UPDATE T_MD_PROCESS_ROUTE ");
|
|
sqlBuilder.Append("SET FLGDEL = '1'");
|
|
sqlBuilder.Append("WHERE PID = @PID");
|
|
parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = model.PID });
|
|
if (BaseSession != null)
|
|
{
|
|
// 对应多种数据库
|
|
string sqlChange = this.ChangeSqlByDB(sqlBuilder.ToString(), BaseSession);
|
|
//删除基本信息
|
|
count = BaseSession.ExecuteSql(sqlChange, parameters.ToArray());
|
|
}
|
|
else
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
// 对应多种数据库
|
|
string sqlChange = this.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="condition">条件</param>
|
|
/// <param name="page">数据页</param>
|
|
/// <returns>数据页</returns>
|
|
public DataPage GetProcessRouteWorkCellData(ProcessRouteWorkCell condition, DataPage page)
|
|
{
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = this.GetProcessRouteWorkCellSql(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<ProcessRouteWorkCell>(sqlChange, parameters.ToArray(), page);
|
|
}
|
|
return page;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
RecordExceptionLog(ex, "工艺路线数据层-获取列表");
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 获取查询语句
|
|
/// <summary>
|
|
/// 获取查询语句
|
|
/// </summary>
|
|
/// <param name="user">查询条件</param>
|
|
/// <param name="parameters">参数</param>
|
|
/// <returns>查询语句</returns>
|
|
private string GetProcessRouteWorkCellSql(ProcessRouteWorkCell condition, ref List<DataParameter> parameters)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
try
|
|
{
|
|
sqlBuilder.AppendLine(@" SELECT A.PID
|
|
,B.ROUTE_CODE
|
|
,B.ROUTE_NAME
|
|
,C.WORKCELL_CODE
|
|
,C.WORKCELL_NAME
|
|
,A.REMARK
|
|
,A.VER_NUM
|
|
,A.FLAG_QC
|
|
,A.CREATEUSER
|
|
,A.CREATEDATE
|
|
,A.UPDATEUSER
|
|
,A.UPDATEDATE
|
|
,A.FLGDEL
|
|
,STUFF((SELECT ','+RTRIM(S.PRE_WORKCELL_CODE)+'/'+S1.WORKCELL_NAME FROM
|
|
T_MD_PROCESS_ROUTE_WORKCELL_SEQ S
|
|
LEFT JOIN T_MD_WORKCELL S1
|
|
ON S.PRE_WORKCELL_CODE = S1.WORKCELL_CODE
|
|
AND S1.FLGDEL = '0'
|
|
WHERE S.ROUTE_CODE=A.ROUTE_CODE
|
|
AND S.WORKCELL_CODE=A.WORKCELL_CODE
|
|
AND S.FLGDEL='0' FOR XML PATH('')),1,1,'') AS PRE_WORKCELL_CODE
|
|
FROM T_MD_PROCESS_ROUTE_WORKCELL A
|
|
LEFT JOIN T_MD_PROCESS_ROUTE B ON B.ROUTE_CODE=A.ROUTE_CODE
|
|
LEFT JOIN T_MD_WORKCELL C ON C.WORKCELL_CODE=A.WORKCELL_CODE ");
|
|
if (string.IsNullOrEmpty(condition.ROUTE_CODE) == false)
|
|
{
|
|
whereBuilder.Append(" AND A.ROUTE_CODE = @ROUTE_CODE");
|
|
parameters.Add(new DataParameter { ParameterName = "ROUTE_CODE", DataType = DbType.String, Value = condition.ROUTE_CODE });
|
|
}
|
|
whereBuilder.Append(" AND A.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="info"></param>
|
|
/// <returns>true:已存在;fasel:不存在。</returns>
|
|
public bool ExistsProcess(ProcessRouteWorkCell model)
|
|
{
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
int count = 0;
|
|
try
|
|
{
|
|
sqlBuilder.Append("SELECT COUNT(*) FROM T_MD_PROCESS_ROUTE_WORKCELL T ");
|
|
//查询条件
|
|
if (string.IsNullOrEmpty(model.ROUTE_CODE) == false)
|
|
{
|
|
whereBuilder.Append(" AND T.ROUTE_CODE = @ROUTE_CODE");
|
|
parameters.Add(new DataParameter { ParameterName = "ROUTE_CODE", DataType = DbType.String, Value = model.ROUTE_CODE });
|
|
}
|
|
if (string.IsNullOrEmpty(model.WORKCELL_CODE) == false)
|
|
{
|
|
whereBuilder.Append(" AND T.WORKCELL_CODE = @WORKCELL_CODE");
|
|
parameters.Add(new DataParameter { ParameterName = "WORKCELL_CODE", DataType = DbType.String, Value = model.WORKCELL_CODE });
|
|
}
|
|
whereBuilder.Append(" AND T.FLGDEL = '0' ");
|
|
if (whereBuilder.Length > 0)
|
|
{
|
|
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
|
|
}
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
// 对应多种数据库
|
|
string sqlChange = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
|
|
count = Convert.ToInt32(session.ExecuteSqlScalar(sqlChange, parameters.ToArray()));
|
|
}
|
|
|
|
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 InsertProcessRouteWorkCell(ProcessRouteWorkCell model)
|
|
{
|
|
int count = 0;
|
|
try
|
|
{
|
|
if (BaseSession != null)
|
|
{
|
|
//插入基本信息
|
|
count = BaseSession.Insert<ProcessRouteWorkCell>(model);
|
|
}
|
|
else
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//插入基本信息
|
|
count = session.Insert<ProcessRouteWorkCell>(model);
|
|
}
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
RecordExceptionLog(ex, "工艺路线数据层-插入工序配置信息");
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 插入工序与前置工序中间表
|
|
/// <summary>
|
|
/// 插入工序与前置工序中间表
|
|
/// </summary>
|
|
/// <param name=model"">工序配置信息</param>
|
|
/// <returns>插入行数</returns>
|
|
public int InsertProcessRouteWorkCellSeq(List<ProcessRouteWorkCellSeq> list)
|
|
{
|
|
int count = 0;
|
|
try
|
|
{
|
|
if (BaseSession != null)
|
|
{
|
|
//插入基本信息
|
|
count = BaseSession.Insert<ProcessRouteWorkCellSeq>(list);
|
|
}
|
|
else
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//插入基本信息
|
|
count = session.Insert<ProcessRouteWorkCellSeq>(list);
|
|
}
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
RecordExceptionLog(ex, "工艺路线数据层-插入工序与前置工序中间表");
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 删除工序配置信息
|
|
/// <summary>
|
|
/// 删除工序配置信息
|
|
/// </summary>
|
|
/// <param name="model">工序配置信息(ID)</param>
|
|
/// <returns>删除个数</returns>
|
|
public int DeleteProcessRouteWorkCell(ProcessRouteWorkCell model)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
int count = 0;
|
|
try
|
|
{
|
|
sqlBuilder.Append(" UPDATE T_MD_PROCESS_ROUTE_WORKCELL SET FLGDEL=@FLGDEL ");
|
|
parameters.Add(new DataParameter() { ParameterName = "FLGDEL", DataType = DbType.String, Value ="1"});
|
|
|
|
if (string.IsNullOrEmpty(model.ROUTE_CODE) == false)
|
|
{
|
|
whereBuilder.Append(" AND ROUTE_CODE=@ROUTE_CODE");
|
|
parameters.Add(new DataParameter() { ParameterName = "ROUTE_CODE", DataType = DbType.String, Value = model.ROUTE_CODE });
|
|
}
|
|
if (string.IsNullOrEmpty(model.PID) == false)
|
|
{
|
|
whereBuilder.Append(" AND PID=@PID");
|
|
parameters.Add(new DataParameter() { ParameterName = "PID", DataType = DbType.String, Value = model.PID });
|
|
}
|
|
//查询条件
|
|
if (whereBuilder.Length > 0)
|
|
{
|
|
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
|
|
}
|
|
|
|
if (BaseSession != null)
|
|
{
|
|
// 对应多种数据库
|
|
string sqlChange = this.ChangeSqlByDB(sqlBuilder.ToString(), BaseSession);
|
|
//删除基本信息
|
|
count = BaseSession.ExecuteSql(sqlChange, parameters.ToArray());
|
|
}
|
|
else
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
// 对应多种数据库
|
|
string sqlChange = this.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="model">工序配置信息(ID)</param>
|
|
/// <returns>删除个数</returns>
|
|
public int DeleteProcessRouteWorkCellSeq(ProcessRouteWorkCell model)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
int count = 0;
|
|
try
|
|
{
|
|
sqlBuilder.Append(" UPDATE T_MD_PROCESS_ROUTE_WORKCELL_SEQ SET FLGDEL=@FLGDEL ");
|
|
parameters.Add(new DataParameter() { ParameterName = "FLGDEL", DataType = DbType.String, Value = "1"});
|
|
if (string.IsNullOrEmpty(model.ROUTE_CODE) == false)
|
|
{
|
|
whereBuilder.Append(" AND ROUTE_CODE=@ROUTE_CODE");
|
|
parameters.Add(new DataParameter() { ParameterName = "ROUTE_CODE", DataType = DbType.String, Value = model.ROUTE_CODE });
|
|
}
|
|
if (string.IsNullOrEmpty(model.WORKCELL_CODE) == false)
|
|
{
|
|
whereBuilder.Append(" AND WORKCELL_CODE=@WORKCELL_CODE");
|
|
parameters.Add(new DataParameter() { ParameterName = "WORKCELL_CODE", DataType = DbType.String, Value = model.WORKCELL_CODE });
|
|
}
|
|
//查询条件
|
|
if (whereBuilder.Length > 0)
|
|
{
|
|
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
|
|
}
|
|
|
|
if (BaseSession != null)
|
|
{
|
|
// 对应多种数据库
|
|
string sqlChange = this.ChangeSqlByDB(sqlBuilder.ToString(), BaseSession);
|
|
//删除基本信息
|
|
count = BaseSession.ExecuteSql(sqlChange, parameters.ToArray());
|
|
}
|
|
else
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
// 对应多种数据库
|
|
string sqlChange = this.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="condition">条件</param>
|
|
/// <returns>全部集合</returns>
|
|
public List<ProcessRoute> GetRouteList(ProcessRoute condition)
|
|
{
|
|
List<ProcessRoute> list = new List<ProcessRoute>();
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = this.GetQuerySql(condition, ref parameters);
|
|
sql = sql + " ORDER BY UPDATEDATE DESC ";
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
// 对应多种数据库
|
|
string sqlChange = this.ChangeSqlByDB(sql, session);
|
|
list = session.GetList<ProcessRoute>(sqlChange, parameters.ToArray()).ToList();
|
|
}
|
|
return list;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 获取工艺路线工序列表无分页
|
|
/// <summary>
|
|
/// 获取工艺路线工序列表无分页
|
|
/// </summary>
|
|
/// <param name="condition">条件</param>
|
|
/// <param name="page">数据页</param>
|
|
/// <returns>数据页</returns>
|
|
public List<ProcessRouteWorkCell> GetProcessRouteWorkCellData(ProcessRouteWorkCell condition)
|
|
{
|
|
string sql = null;
|
|
List<ProcessRouteWorkCell> list = new List<ProcessRouteWorkCell>();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = this.GetProcessRouteWorkCellSql(condition, ref parameters);
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
// 对应多种数据库
|
|
string sqlChange = this.ChangeSqlByDB(sql, session);
|
|
list = session.GetList<ProcessRouteWorkCell>(sqlChange, parameters.ToArray()).ToList();
|
|
}
|
|
return list;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
RecordExceptionLog(ex, "工艺路线数据层-获取工艺路线工序列表");
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 根据工序获得工艺路线
|
|
/// <summary>
|
|
/// 根据工序获得工艺路线
|
|
/// </summary>
|
|
/// <param name="workCellCode">工序编码</param>
|
|
/// <returns>工艺路线</returns>
|
|
public ProcessRoute GetProcessRouteByWorkCell(string workCellCode)
|
|
{
|
|
ProcessRoute route = new ProcessRoute();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
sqlBuilder.Append(" SELECT ");
|
|
sqlBuilder.Append(GetSqlSelectItem("A"));
|
|
sqlBuilder.Append(" FROM ");
|
|
sqlBuilder.Append(" T_MD_PROCESS_ROUTE A ");
|
|
sqlBuilder.Append(" LEFT JOIN T_MD_PROCESS_ROUTE_WORKCELL B ");
|
|
sqlBuilder.Append(" ON A.ROUTE_CODE = B.ROUTE_CODE AND B.FLGDEL = '0' ");
|
|
sqlBuilder.Append(" WHERE ");
|
|
sqlBuilder.Append(" B.WORKCELL_CODE = @WORKCELL_CODE ");
|
|
sqlBuilder.Append(" AND A.FLGDEL = '0' ");
|
|
|
|
parameters.Add(new DataParameter("WORKCELL_CODE",DbType.String,workCellCode));
|
|
if (null != BaseSession)
|
|
{
|
|
// 对应多种数据库
|
|
string sqlChange = this.ChangeSqlByDB(sqlBuilder.ToString(), BaseSession);
|
|
route = BaseSession.Get<ProcessRoute>(sqlChange, parameters.ToArray());
|
|
}
|
|
else
|
|
{
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
// 对应多种数据库
|
|
string sqlChange = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
|
|
route = session.Get<ProcessRoute>(sqlChange, parameters.ToArray());
|
|
}
|
|
}
|
|
return route;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
RecordExceptionLog(ex, "工艺路线数据层-根据工序获取工艺路线");
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 得到检索项目
|
|
/// <summary>
|
|
/// 得到检索项目
|
|
/// </summary>
|
|
/// <param name="suffix"></param>
|
|
/// <returns></returns>
|
|
private string GetSqlSelectItem(string suffix)
|
|
{
|
|
String[] tableItem = {"PID"
|
|
,"ROUTE_CODE"
|
|
,"ROUTE_NAME"
|
|
,"EFF_DATE"
|
|
,"EXP_DATE"
|
|
,"ROUTE_VER"
|
|
,"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 根据BOM和工序定位工艺路线
|
|
/// <summary>
|
|
/// 根据BOM和工序定位工艺路线
|
|
/// </summary>
|
|
/// <param name="bomcode"></param>
|
|
/// <param name="workcellcode"></param>
|
|
/// <returns></returns>
|
|
public RouteLocation LocateRoute(string bomcode, string workcellcode)
|
|
{
|
|
StringBuilder sql = new StringBuilder();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
/*
|
|
sql.AppendLine("SELECT R.[ROUTE_CODE] AS [RouteCode] ");
|
|
sql.AppendLine(" ,R.[ROUTE_NAME] AS [RouteName] ");
|
|
sql.AppendLine(" ,MR.[MATERIAL_CODE] AS [BomCode] ");
|
|
sql.AppendLine(" FROM [T_MD_PROCESS_ROUTE_WORKCELL] AS RW ");
|
|
sql.AppendLine(" LEFT JOIN [T_MD_MATERIAL_ROUTE] AS MR ");
|
|
sql.AppendLine(" ON RW.[ROUTE_CODE]=MR.[ROUTE_CODE] ");
|
|
sql.AppendLine(" LEFT JOIN [T_MD_PROCESS_ROUTE] AS R ");
|
|
sql.AppendLine(" ON RW.[ROUTE_CODE]=R.[ROUTE_CODE] ");
|
|
sql.AppendLine(" WHERE [MATERIAL_CODE]=@bomcode ");
|
|
sql.AppendLine(" AND [WORKCELL_CODE]=@workcellcode ");
|
|
*/
|
|
sql.AppendLine("SELECT R.[ROUTE_CODE] AS [RouteCode] ");
|
|
sql.AppendLine(" ,R.[ROUTE_NAME] AS [RouteName] ");
|
|
sql.AppendLine(" ,P.[PBOM_CODE] AS [BomCode] ");
|
|
sql.AppendLine(" FROM [T_MD_PROCESS_ROUTE] AS R ");
|
|
sql.AppendLine(" LEFT JOIN [T_MD_MATERIAL_ROUTE] AS MR ");
|
|
sql.AppendLine(" ON R.[ROUTE_CODE]=MR.[ROUTE_CODE] ");
|
|
sql.AppendLine(" LEFT JOIN [T_MD_PBOM] AS P ");
|
|
sql.AppendLine(" ON P.[MATERIAL_CODE]=MR.[MATERIAL_CODE] ");
|
|
sql.AppendLine(" WHERE EXISTS(SELECT 1 ");
|
|
sql.AppendLine(" FROM [T_MD_PROCESS_ROUTE_WORKCELL] AS RW ");
|
|
sql.AppendLine(" WHERE RW.[ROUTE_CODE]=R.[ROUTE_CODE] ");
|
|
sql.AppendLine(" AND RW.[WORKCELL_CODE]=@workcellcode ) ");
|
|
sql.AppendLine(" AND P.PBOM_CODE=@bomcode ");
|
|
|
|
parameters.Add(new DataParameter("bomcode", bomcode));
|
|
parameters.Add(new DataParameter("workcellcode", workcellcode));
|
|
|
|
using (var session = AppDataFactory.CreateMainSession())
|
|
{
|
|
var route = session.Get<RouteLocation>(sql.ToString(), parameters.ToArray());
|
|
return route;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 根据工序定位工艺路线
|
|
/// <summary>
|
|
/// 根据工序定位工艺路线
|
|
/// </summary>
|
|
/// <param name="workcellcode"></param>
|
|
/// <returns></returns>
|
|
public RouteLocation LocateRoute(string workcellcode)
|
|
{
|
|
StringBuilder sql = new StringBuilder();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql.AppendLine("SELECT R.[ROUTE_CODE] AS [RouteCode] ");
|
|
sql.AppendLine(" ,R.[ROUTE_NAME] AS [RouteName] ");
|
|
sql.AppendLine(" ,'' AS [BomCode] ");
|
|
sql.AppendLine(" FROM [T_MD_PROCESS_ROUTE_WORKCELL] AS RW ");
|
|
sql.AppendLine(" LEFT JOIN [T_MD_PROCESS_ROUTE] AS R ");
|
|
sql.AppendLine(" ON RW.[ROUTE_CODE]=R.[ROUTE_CODE] ");
|
|
sql.AppendLine(" WHERE [WORKCELL_CODE]=@workcellcode ");
|
|
|
|
parameters.Add(new DataParameter("workcellcode", workcellcode));
|
|
|
|
using (var session = AppDataFactory.CreateMainSession())
|
|
{
|
|
var route = session.Get<RouteLocation>(sql.ToString(), parameters.ToArray());
|
|
return route;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 根据物料定位工艺路线
|
|
/// <summary>
|
|
/// 根据物料定位工艺路线
|
|
/// </summary>
|
|
/// <param name="workcellcode"></param>
|
|
/// <returns></returns>
|
|
public ProcessRoute RouteWithMaterial(string material)
|
|
{
|
|
StringBuilder sql = new StringBuilder();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql.AppendLine("SELECT *");
|
|
sql.AppendLine(" FROM T_MD_PROCESS_ROUTE AS PR ");
|
|
sql.AppendLine(" LEFT JOIN T_MD_MATERIAL_ROUTE AS MR ");
|
|
sql.AppendLine(" ON PR.ROUTE_CODE=MR.ROUTE_CODE ");
|
|
sql.AppendLine(" LEFT JOIN T_MD_MATERIAL AS M ");
|
|
sql.AppendLine(" ON MR.MATERIAL_CODE=M.MATERIAL_CODE ");
|
|
sql.AppendLine(" WHERE MR.MATERIAL_CODE=@material ");
|
|
|
|
parameters.Add(new DataParameter("material", material));
|
|
|
|
using (var session = AppDataFactory.CreateMainSession())
|
|
{
|
|
var route = session.Get<ProcessRoute>(sql.ToString(), parameters.ToArray());
|
|
return route;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
public ProcessRoute GetRouteByMachine(string machinecode)
|
|
{
|
|
StringBuilder sql = new StringBuilder();
|
|
sql.AppendLine("SELECT * ");
|
|
sql.AppendLine(" FROM T_MD_PROCESS_ROUTE ");
|
|
sql.AppendLine(" WHERE ROUTE_CODE=(SELECT ROUTE_CODE ");
|
|
sql.AppendLine(" FROM T_MD_PROCESS_ROUTE_WORKCELL ");
|
|
sql.AppendLine(" WHERE WORKCELL_CODE=(SELECT WORKCELL_CODE ");
|
|
sql.AppendLine(" FROM T_MD_WORKLOC ");
|
|
sql.AppendLine(" WHERE WORKLOC_CODE=(SELECT WORKLOC_CODE ");
|
|
sql.AppendLine(" FROM T_BD_MACHINEINFO ");
|
|
sql.AppendLine(" WHERE MACHINECODDE=@machinecode)))");
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
parameters.Add(new DataParameter("machinecode", machinecode));
|
|
try
|
|
{
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
return session.Get<ProcessRoute>(sql.ToString(), parameters.ToArray());
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogManager.LogHelper.Error(new LogInfo()
|
|
{
|
|
ErrorInfo = ex,
|
|
Tag = ex.StackTrace,
|
|
Info = "工艺路线信息-获取工艺路线列表"
|
|
});
|
|
throw;
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
|