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

633 lines
24 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 WorkLocDAL : BaseDAL
{
#region 获取信息
/// <summary>
/// 获取信息
/// </summary>
/// <param name="">条件</param>
/// <returns>信息</returns>
public WorkLoc Get(WorkLoc model)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = "SELECT * FROM T_MD_WORKLOC WHERE FLGDEL='0' ";
if (string.IsNullOrEmpty(model.PID) == false)
{
sql += " AND PID = @PID";
parameters.Add(new DataParameter("PID", model.PID));
}
if (string.IsNullOrEmpty(model.WORKLOC_CODE) == false)
{
sql += " AND WORKLOC_CODE = @WORKLOC_CODE";
parameters.Add(new DataParameter("WORKLOC_CODE", model.WORKLOC_CODE));
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
// 对应多种数据库
string sqlChange = this.ChangeSqlByDB(sql, session);
//获取信息
model = session.Get<WorkLoc>(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(WorkLoc 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<WorkLoc>(sqlChange, parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "工位信息-获取列表");
throw ex;
}
}
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <returns>列表</returns>
public List<WorkLoc> GetList(WorkLoc condition)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
List<WorkLoc> listProcessInfo = new List<WorkLoc>();
try
{
sql = this.GetQuerySql(condition, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
// 对应多种数据库
string sqlChange = this.ChangeSqlByDB(sql, session);
listProcessInfo = session.GetList<WorkLoc>(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(WorkLoc condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.AppendLine(" SELECT M.PID ");
sqlBuilder.AppendLine(" ,M.WORKLOC_CODE ");
sqlBuilder.AppendLine(" ,M.WORKLOC_NAME ");
sqlBuilder.AppendLine(" ,M.WORKCELL_CODE ");
sqlBuilder.AppendLine(" ,W.WORKCELL_NAME ");
sqlBuilder.AppendLine(" ,M.WORKCENTER_CODE ");
sqlBuilder.AppendLine(" ,M.FACTORY_CODE ");
sqlBuilder.AppendLine(" ,C.WORKCENTER_NAME ");
sqlBuilder.AppendLine(" ,F.FACTORY_NAME ");
sqlBuilder.AppendLine(" ,M.REMARK ");
sqlBuilder.AppendLine(" ,M.CREATEUSER ");
sqlBuilder.AppendLine(" ,M.CREATEDATE ");
sqlBuilder.AppendLine(" ,M.UPDATEUSER ");
sqlBuilder.AppendLine(" ,M.UPDATEDATE ");
sqlBuilder.AppendLine(" ,M.FLGDEL ");
sqlBuilder.AppendLine(" FROM T_MD_WORKLOC M ");
sqlBuilder.AppendLine(" LEFT JOIN T_MD_WORKCELL W ON M.WORKCELL_CODE=W.WORKCELL_CODE ");
sqlBuilder.AppendLine(" LEFT JOIN T_MD_WORKCENTER C ON C.WORKCENTER_CODE=M.WORKCENTER_CODE AND C.FACTORY_CODE=M.FACTORY_CODE");
sqlBuilder.AppendLine(" LEFT JOIN T_MD_FACTORY F ON F.FACTORY_CODE=M.FACTORY_CODE ");
//查询条件
//工位
if (string.IsNullOrEmpty(condition.WORKLOC_CODE) == false)
{
whereBuilder.Append(" AND M.WORKLOC_CODE = @WORKLOC_CODE");
parameters.Add(new DataParameter { ParameterName = "WORKLOC_CODE", DataType = DbType.String, Value = condition.WORKLOC_CODE });
}
//工序
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.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.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 });
}
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 IsExistsWorkLocCode(WorkLoc 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_WORKLOC WHERE PID <> @PID AND FACTORY_CODE=@FACTORY_CODE AND WORKLOC_CODE=@WORKLOC_CODE";
paramList.Add(new DataParameter { ParameterName = "PID", Value = model.PID });
paramList.Add(new DataParameter { ParameterName = "FACTORY_CODE", Value = model.FACTORY_CODE });
paramList.Add(new DataParameter { ParameterName = "WORKLOC_CODE", Value = model.WORKLOC_CODE });
using (IDataSession session = AppDataFactory.CreateMainSession())
{
// 对应多种数据库
string sqlChange = this.ChangeSqlByDB(sql, session);
count = Convert.ToInt32(session.ExecuteSqlScalar(sqlChange, paramList.ToArray()));
}
return count == 0 ? false : true;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "工位信息-判断编号名称是否存在");
throw ex;
}
}
#endregion
#region 判断工位编号是否被用
/// <summary>
/// 判断工位编号是否被用
/// </summary>
/// <param name="model">工位</param>
/// <returns>true:已用;false:未用。</returns>
public bool IsUsedWorkLocCode(string[] pid)
{
int count = 0;
StringBuilder sqlBuilder = new StringBuilder();
try
{
List<DataParameter> paramList = new List<DataParameter>();
sqlBuilder.Append(" SELECT COUNT(*) FROM T_MD_WORKCELL_EQUIPMENT WHERE FLGDEL = '0' ");
sqlBuilder.Append(" AND WORKLOC_CODE IN ( ");
sqlBuilder.Append(" SELECT WORKLOC_CODE FROM T_MD_WORKLOC ");
for (int i = 0; i < pid.Length; i++)
{
if (i == 0)
{
sqlBuilder.Append(" WHERE PID IN (");
}
else
{
sqlBuilder.Append(" ,");
}
string param = "PID" + i.ToString();
sqlBuilder.Append(" @").Append(param);
paramList.Add(new DataParameter(param,DbType.String,pid[i]));
if (i == pid.Length - 1)
{
sqlBuilder.Append(" ) ");
}
}
sqlBuilder.Append(" ) ");
using (IDataSession session = AppDataFactory.CreateMainSession())
{
// 对应多种数据库
string sqlChange = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
count = Convert.ToInt32(session.ExecuteSqlScalar(sqlChange, paramList.ToArray()));
}
return count == 0 ? false : true;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "工位信息-判断编号是否被用");
throw ex;
}
}
#endregion
#region 插入信息
/// <summary>
/// 插入信息(单表)
/// </summary>
/// <param name="">信息</param>
/// <returns>插入行数</returns>
public int Insert(WorkLoc model)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//插入基本信息
count = session.Insert<WorkLoc>(model);
}
return count;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "工位信息-插入信息");
throw ex;
}
}
#endregion
#region 更新信息
/// <summary>
/// 更新信息
/// </summary>
/// <param name=""></param>
/// <returns>更新行数</returns>
public int Update(WorkLoc model)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//更新基本信息
count = session.Update<WorkLoc>(model);
}
return count;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "工位信息-更新信息");
throw ex;
}
}
#endregion
#region 删除
/// <summary>
/// 删除信息
/// </summary>
/// <param name="model">物料号信息(ID)</param>
/// <returns>删除个数</returns>
public int Delete(WorkLoc model)
{
StringBuilder sqlBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//删除基本信息
count = session.Delete<WorkLoc>(model);
}
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 GetWorkLocEquipmentList(WorkCellEquipment condition, DataPage page)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetWorkLocEquipmentQuerySql(condition, ref parameters);
#region 排序
//分页关键字段及排序
page.KeyName = "PID";
page.SortExpression = "UPDATEDATE DESC";
#endregion
using (IDataSession session = AppDataFactory.CreateMainSession())
{
// 对应多种数据库
string sqlChange = this.ChangeSqlByDB(sql, session);
page = session.GetDataPage<WorkCellEquipment>(sqlChange, parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "工位设备-获取列表");
throw ex;
}
}
/// <summary>
/// 获取查询语句
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
private string GetWorkLocEquipmentQuerySql(WorkCellEquipment condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.AppendLine(" SELECT M.PID ");
sqlBuilder.AppendLine(" ,M.WORKLOC_CODE ");
sqlBuilder.AppendLine(" ,M.EQUIPMENT_CODE ");
sqlBuilder.AppendLine(" ,E.EQUIPMENT_NAME ");
sqlBuilder.AppendLine(" ,M.CREATEUSER ");
sqlBuilder.AppendLine(" ,M.CREATEDATE ");
sqlBuilder.AppendLine(" ,M.UPDATEUSER ");
sqlBuilder.AppendLine(" ,M.UPDATEDATE ");
sqlBuilder.AppendLine(" ,M.FLGDEL ");
sqlBuilder.AppendLine(" FROM T_MD_WORKCELL_EQUIPMENT M ");
sqlBuilder.AppendLine(" JOIN T_MD_EQUIPMENT E ON M.EQUIPMENT_CODE = E.EQUIPMENT_CODE AND E.FLGDEL ='0'");
//查询条件
//工位
if (string.IsNullOrEmpty(condition.WORKLOC_CODE) == false)
{
whereBuilder.Append(" AND M.WORKLOC_CODE = @WORKLOC_CODE");
parameters.Add(new DataParameter { ParameterName = "WORKLOC_CODE", DataType = DbType.String, Value = condition.WORKLOC_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;
}
}
/// <summary>
/// 插入信息(单表)
/// </summary>
/// <param name="model">信息</param>
/// <returns>插入行数</returns>
public int InsertWorkLocEquip(WorkCellEquipment model)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//插入基本信息
count = session.Insert<WorkCellEquipment>(model);
}
return count;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "工位设备-插入信息");
throw ex;
}
}
/// <summary>
/// 判断工位编号是否重复
/// </summary>
/// <param name="model">工位</param>
/// <returns>true:已存在;false:不存在。</returns>
public bool IsExistsWorkLocEquip(WorkCellEquipment 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_EQUIPMENT WHERE PID <> @PID AND WORKLOC_CODE = @WORKLOC_CODE AND EQUIPMENT_CODE = @EQUIPMENT_CODE";
paramList.Add(new DataParameter { ParameterName = "PID", Value = model.PID });
paramList.Add(new DataParameter { ParameterName = "WORKLOC_CODE", Value = model.WORKLOC_CODE });
paramList.Add(new DataParameter { ParameterName = "EQUIPMENT_CODE", Value = model.EQUIPMENT_CODE });
using (IDataSession session = AppDataFactory.CreateMainSession())
{
// 对应多种数据库
string sqlChange = this.ChangeSqlByDB(sql, session);
count = Convert.ToInt32(session.ExecuteSqlScalar(sqlChange, paramList.ToArray()));
}
return count == 0 ? false : true;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "工位设备-判断工位设备是否存在");
throw ex;
}
}
/// <summary>
/// 删除信息
/// </summary>
/// <param name="model">物料号信息(ID)</param>
/// <returns>删除个数</returns>
public int DeleteWorkLocEquip(WorkCellEquipment model)
{
StringBuilder sqlBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//删除基本信息
count = session.Delete<WorkCellEquipment>(model);
}
return count;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "工位设备信息-删除");
throw ex;
}
}
#endregion
#region 工位信息下拉
/// <summary>
///
/// </summary>
/// <param name="condition"></param>
/// <returns></returns>
public List<WorkLoc> GetWorkLocFromWorkCellList(WorkLoc model, string routecode)
{
List<WorkLoc> list = new List<WorkLoc>();
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_WORKLOC ");
sqlBuilder.AppendLine(" WHERE WORKCELL_CODE=@routecode");
parameters.Add(new DataParameter { ParameterName = "routecode", DataType = DbType.String, Value = routecode });
sql = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
list = session.GetList<WorkLoc>(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "工位信息-下拉列表");
throw ex;
}
}
public List<WorkLoc> GetWorkLocFromWorkCenterCodeList(string workCenterCode)
{
List<WorkLoc> list = new List<WorkLoc>();
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_WORKLOC ");
sqlBuilder.AppendLine(" where WORKCELL_CODE in ( select WORKCELL_CODE from T_MD_WORKCELL where WORKCENTER_CODE=@workCenterCode)");
parameters.Add(new DataParameter { ParameterName = "workCenterCode", DataType = DbType.String, Value = workCenterCode });
sql = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
list = session.GetList<WorkLoc>(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<WorkLoc> GetWorkCellFromWorkLocList(WorkLoc model, string routecode)
{
List<WorkLoc> list = new List<WorkLoc>();
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_WORKLOC ");
sqlBuilder.AppendLine(" WHERE WORKLOC_CODE=@routecode");
parameters.Add(new DataParameter { ParameterName = "routecode", DataType = DbType.String, Value = routecode });
sql = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
list = session.GetList<WorkLoc>(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "工序信息");
throw ex;
}
}
#endregion
}
}