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

712 lines
27 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMFrameWork.Data;
using QMFrameWork.Log;
using QMAPP.DAL;
using QMAPP.FJC.Entity.Basic;
using System.Data;
using QMAPP.FJC.Entity;
namespace QMAPP.FJC.DAL.Basic
{
public class ProcessRouteDAL : BaseDAL
{
#region 获取信息
/// <summary>
/// 获取信息
/// </summary>
/// <param name="">条件</param>
/// <returns>*信息</returns>
public ProcessRoute Get(ProcessRoute model)
{
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//获取信息
model = session.Get<ProcessRoute>(model);
}
return model;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "工艺路线数据层-获取信息"
});
throw;
}
}
#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())
{
page = session.GetDataPage<ProcessRoute>(sql, parameters.ToArray(), page);
}
return page;
}
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(ProcessRoute condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
sqlBuilder.AppendLine("SELECT T.PID ");
sqlBuilder.AppendLine(" ,T.ROUTE_CODE ");
sqlBuilder.AppendLine(" ,T.ROUTE_NAME ");
sqlBuilder.AppendLine(" ,T.REMARK ");
sqlBuilder.AppendLine(" ,C.USERNAME AS CREATEUSERNAME ");
sqlBuilder.AppendLine(" ,T.CREATEDATE ");
sqlBuilder.AppendLine(" ,U.USERNAME AS UPDATEUSERNAME ");
sqlBuilder.AppendLine(" ,T.UPDATEDATE ");
sqlBuilder.AppendLine(" ,T.FLAGDEL ");
sqlBuilder.AppendLine(" FROM T_BD_PROCESS_ROUTE T "); ;
sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER C ON C.USERID=T.CREATEUSR ");
sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER U ON U.USERID=T.UPDATEUSR ");
whereBuilder.Append(" AND T.FLAGDEL='0'");
//查询条件
//工艺路线编码
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 = 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_BD_PROCESS_ROUTE WHERE PID <> @PID AND ROUTE_CODE=@ROUTE_CODE AND FLAGDEL<>1 ";
using (IDataSession session = AppDataFactory.CreateMainSession())
{
count = Convert.ToInt32(session.ExecuteSqlScalar(sql, new DataParameter("PID", PID),
new DataParameter { ParameterName = "ROUTE_CODE", Value = model.ROUTE_CODE }));
}
if (count > 0)
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "工艺路线数据层-判断工艺路线编号是否存在"
});
throw;
}
}
#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)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "工艺路线数据层-插入信息"
});
throw;
}
}
#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)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "工艺路线数据层-更新信息"
});
throw;
}
}
#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_BD_PROCESS_ROUTE ");
sqlBuilder.Append("SET FLAGDEL = '1'");
sqlBuilder.Append("WHERE PID = @PID");
parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = model.PID });
if (BaseSession != null)
{
//删除基本信息
count = BaseSession.ExecuteSql(sqlBuilder.ToString(), parameters.ToArray());
}
else
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//删除基本信息
count = session.ExecuteSql(sqlBuilder.ToString(), parameters.ToArray());
}
}
return count;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "工艺路线数据层-删除信息"
});
throw;
}
}
#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())
{
page = session.GetDataPage<ProcessRouteWorkCell>(sql, parameters.ToArray(), page);
}
return page;
}
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 GetProcessRouteWorkCellSql(ProcessRouteWorkCell condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
sqlBuilder.AppendLine(@" SELECT A.PID
,A.ROUTE_PID
,B.ROUTE_CODE
,B.ROUTE_NAME
,A.WORKCELL_PID
,C.PROCESSNAME AS WORKCELL_NAME
,A.REMARK
,A.OPT_STANDARD
,A.BACKFLUSH
,A.CREATEUSR
,A.CREATEDATE
,A.UPDATEUSR
,A.UPDATEDATE
,E.USERNAME AS CREATEUSERNAME
,U.USERNAME AS UPDATEUSERNAME
,A.FLAGDEL
,STUFF((SELECT ','+RTRIM(S.PRE_WORKCELL_CODE)+'/'+S.PRE_WORKCELL_NAME FROM
T_BD_PROCESS_ROUTE_WORKCELL_SEQ S
WHERE S.ROUTE_PID=A.ROUTE_PID
AND S.PRW_PID=A.PID
AND FLAGDEL='0' FOR XML PATH('')),1,1,'') AS PARWORKCELLCODE
FROM T_BD_PROCESS_ROUTE_WORKCELL A
LEFT JOIN T_BD_PROCESS_ROUTE B ON B.PID=A.ROUTE_PID
LEFT JOIN T_BD_PROCESSINFO C ON C.PID=A.WORKCELL_PID
LEFT JOIN T_QM_USER E ON E.USERID=A.CREATEUSR
LEFT JOIN T_QM_USER U ON U.USERID=A.UPDATEUSR ");
if (string.IsNullOrEmpty(condition.ROUTE_PID) == false)
{
whereBuilder.Append(" AND A.ROUTE_PID = @ROUTE_PID");
parameters.Add(new DataParameter { ParameterName = "ROUTE_PID", DataType = DbType.String, Value = condition.ROUTE_PID });
}
whereBuilder.Append(" AND A.FLAGDEL<>1 ");
//查询条件
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_BD_PROCESS_ROUTE_WORKCELL T ");
//查询条件
if (string.IsNullOrEmpty(model.ROUTE_PID) == false)
{
whereBuilder.Append(" AND T.ROUTE_PID = @ROUTE_PID");
parameters.Add(new DataParameter { ParameterName = "ROUTE_PID", DataType = DbType.String, Value = model.ROUTE_PID });
}
if (string.IsNullOrEmpty(model.WORKCELL_PID) == false)
{
whereBuilder.Append(" AND T.WORKCELL_PID = @WORKCELL_PID");
parameters.Add(new DataParameter { ParameterName = "WORKCELL_PID", DataType = DbType.String, Value = model.WORKCELL_PID });
}
whereBuilder.Append(" AND T.FLAGDEL<>1 ");
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
count = Convert.ToInt32(session.ExecuteSqlScalar(sqlBuilder.ToString(), parameters.ToArray()));
}
if (count > 0)
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "工艺路线数据层-判断工序编号是否存在"
});
throw;
}
}
#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);
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//插入基本信息
count = session.Insert<ProcessRouteWorkCell>(model);
}
return count;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "工艺路线数据层-插入工序配置信息"
});
throw;
}
}
#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);
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//插入基本信息
count = session.Insert<ProcessRouteWorkCellSeq>(list);
}
return count;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "工艺路线数据层-插入工序与前置工序中间表"
});
throw;
}
}
#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_BD_PROCESS_ROUTE_WORKCELL SET FLAGDEL=@FLAGDEL ");
parameters.Add(new DataParameter() { ParameterName = "FLAGDEL", DataType = DbType.String, Value = EnumGeter.FLAGDEL.YES.GetHashCode().ToString() });
if (string.IsNullOrEmpty(model.ROUTE_PID) == false)
{
whereBuilder.Append(" AND ROUTE_PID=@ROUTE_PID");
parameters.Add(new DataParameter() { ParameterName = "ROUTE_PID", DataType = DbType.String, Value = model.ROUTE_PID });
}
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)
{
//删除基本信息
count = BaseSession.ExecuteSql(sqlBuilder.ToString(), parameters.ToArray());
}
else
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//删除基本信息
count = session.ExecuteSql(sqlBuilder.ToString(), parameters.ToArray());
}
}
return count;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "工艺路线数据层-删除工序配置信息"
});
throw;
}
}
#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_BD_PROCESS_ROUTE_WORKCELL_SEQ SET FLAGDEL=@FLAGDEL ");
parameters.Add(new DataParameter() { ParameterName = "FLAGDEL", DataType = DbType.String, Value = EnumGeter.FLAGDEL.YES.GetHashCode().ToString() });
if (string.IsNullOrEmpty(model.ROUTE_PID) == false)
{
whereBuilder.Append(" AND ROUTE_PID=@ROUTE_PID");
parameters.Add(new DataParameter() { ParameterName = "ROUTE_PID", DataType = DbType.String, Value = model.ROUTE_PID });
}
if (string.IsNullOrEmpty(model.PID) == false)
{
whereBuilder.Append(" AND PRW_PID=@PRW_PID");
parameters.Add(new DataParameter() { ParameterName = "PRW_PID", DataType = DbType.String, Value = model.PID });
}
//查询条件
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
if (BaseSession != null)
{
//删除基本信息
count = BaseSession.ExecuteSql(sqlBuilder.ToString(), parameters.ToArray());
}
else
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//删除基本信息
count = session.ExecuteSql(sqlBuilder.ToString(), parameters.ToArray());
}
}
return count;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "工艺路线数据层-删除工序与前置工序中间表"
});
throw;
}
}
#endregion
#region 获取工艺路线下拉列表
/// <summary>
/// 获取工艺路线列表(下拉列表数据源)
/// </summary>
/// <param name="condition">条件</param>
/// <returns>全部集合</returns>
public List<ProcessRoute> GetProcessRouteList(ProcessRoute condition)
{
List<ProcessRoute> list = new List<ProcessRoute>();
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetQuerySql(condition, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
list = session.GetList<ProcessRoute>(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "工艺路线信息-获取工艺路线列表"
});
throw;
}
}
#endregion
public string GetRouteCodeByWorkcell(string workcellcode)
{
List<DataParameter> parameters = new List<DataParameter>();
StringBuilder sql = new StringBuilder();
sql.AppendLine("SELECT MAX(ROUTE_CODE) FROM T_MD_PROCESS_ROUTE_WORKCELL WHERE WORKCELL_CODE=@workcellcode");
parameters.Add(new DataParameter("workcellcode", workcellcode));
using (var session = AppDataFactory.CreateMainSession())
{
return session.ExecuteSqlScalar(sql.ToString(), parameters.ToArray()) + "";
}
}
}
}