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.
394 lines
14 KiB
394 lines
14 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;
|
|
|
|
namespace QMAPP.MD.DAL
|
|
{
|
|
/// <summary>
|
|
/// 模块名称:设备
|
|
/// 作 者:郭兆福
|
|
/// 编写日期:2017年05月10日
|
|
/// </summary>
|
|
public class EquipmentDAL:BaseDAL
|
|
{
|
|
#region 获取信息
|
|
/// <summary>
|
|
/// 获取信息
|
|
/// </summary>
|
|
/// <param name="">条件</param>
|
|
/// <returns>信息</returns>
|
|
public Equipment Get(Equipment model)
|
|
{
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = "SELECT * FROM T_MD_EQUIPMENT WHERE '1'='1'";
|
|
if (string.IsNullOrEmpty(model.PID) == false)
|
|
{
|
|
sql += " AND PID = @PID";
|
|
parameters.Add(new DataParameter("PID", model.PID));
|
|
}
|
|
if (string.IsNullOrEmpty(model.WORKCENTER_CODE) == false)
|
|
{
|
|
sql += " AND EQUIPMENT_CODE = @EQUIPMENT_CODE";
|
|
parameters.Add(new DataParameter("EQUIPMENT_CODE", model.EQUIPMENT_CODE));
|
|
}
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
// 对应多种数据库
|
|
string sqlChange = this.ChangeSqlByDB(sql, session);
|
|
//获取信息
|
|
model = session.Get<Equipment>(sqlChange, parameters.ToArray());
|
|
}
|
|
return model;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 获取列表
|
|
/// <summary>
|
|
/// 获取列表
|
|
/// </summary>
|
|
/// <param name="condition">条件</param>
|
|
/// <param name="page">数据页</param>
|
|
/// <returns>数据页</returns>
|
|
public DataPage GetList(Equipment condition, DataPage page)
|
|
{
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = this.GetQuerySql(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<Equipment>(sqlChange, parameters.ToArray(), page);
|
|
}
|
|
return page;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取列表
|
|
/// </summary>
|
|
/// <param name="condition">条件</param>
|
|
/// <returns>全部集合</returns>
|
|
public List<Equipment> GetList(Equipment condition)
|
|
{
|
|
List<Equipment> list = new List<Equipment>();
|
|
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<Equipment>(sqlChange, parameters.ToArray()).ToList();
|
|
}
|
|
return list;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 获取查询语句
|
|
/// <summary>
|
|
/// 获取查询语句
|
|
/// </summary>
|
|
/// <param name="user">查询条件</param>
|
|
/// <param name="parameters">参数</param>
|
|
/// <returns>查询语句</returns>
|
|
private string GetQuerySql(Equipment condition, ref List<DataParameter> parameters)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
try
|
|
{
|
|
//构成查询语句
|
|
sqlBuilder.AppendLine(" SELECT M.PID ");
|
|
sqlBuilder.AppendLine(" ,M.WORKCENTER_CODE ");
|
|
sqlBuilder.AppendLine(" ,WR.WORKCENTER_NAME ");
|
|
sqlBuilder.AppendLine(" ,M.EQUIPMENT_CODE ");
|
|
sqlBuilder.AppendLine(" ,M.EQUIPMENT_NAME ");
|
|
sqlBuilder.AppendLine(" ,M.FLAG_EQUIPMENT ");
|
|
sqlBuilder.AppendLine(" ,M.EQUIPMENT_TYPE ");
|
|
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_EQUIPMENT M ");
|
|
sqlBuilder.AppendLine(" LEFT JOIN T_MD_WORKCENTER WR ON WR.WORKCENTER_CODE=M.WORKCENTER_CODE ");
|
|
whereBuilder.Append(" AND M.FLGDEL='0'");
|
|
|
|
//查询条件
|
|
//设备编号
|
|
if (string.IsNullOrEmpty(condition.EQUIPMENT_CODE) == false)
|
|
{
|
|
whereBuilder.Append(" AND EQUIPMENT_CODE = @EQUIPMENT_CODE");
|
|
parameters.Add(new DataParameter { ParameterName = "EQUIPMENT_CODE", DataType = DbType.String, Value = condition.EQUIPMENT_CODE });
|
|
}
|
|
//设备名称
|
|
if (string.IsNullOrEmpty(condition.EQUIPMENT_NAME) == false)
|
|
{
|
|
whereBuilder.Append(" AND EQUIPMENT_NAME LIKE @EQUIPMENT_NAME");
|
|
parameters.Add(new DataParameter { ParameterName = "EQUIPMENT_NAME", DataType = DbType.String, Value = EscapeValue(condition.EQUIPMENT_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 ExistsMachineInfo(Equipment 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_EQUIPMENT WHERE PID <> @PID AND EQUIPMENT_CODE=@EQUIPMENT_CODE";
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
// 对应多种数据库
|
|
string sqlChange = this.ChangeSqlByDB(sql, session);
|
|
count = Convert.ToInt32(session.ExecuteSqlScalar(sqlChange, new DataParameter("PID", PID),
|
|
new DataParameter { ParameterName = "EQUIPMENT_CODE", Value = model.EQUIPMENT_CODE }));
|
|
}
|
|
|
|
if (count > 0)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 插入信息
|
|
/// <summary>
|
|
/// 插入信息(单表)
|
|
/// </summary>
|
|
/// <param name="">信息</param>
|
|
/// <returns>插入行数</returns>
|
|
public int Insert(Equipment model)
|
|
{
|
|
int count = 0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//插入基本信息
|
|
count = session.Insert<Equipment>(model);
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 更新信息
|
|
/// <summary>
|
|
/// 更新信息
|
|
/// </summary>
|
|
/// <param name=""></param>
|
|
/// <returns>更新行数</returns>
|
|
public int Update(Equipment model)
|
|
{
|
|
int count = 0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//更新基本信息
|
|
count = session.Update<Equipment>(model);
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 删除信息
|
|
/// <summary>
|
|
/// 删除信息
|
|
/// </summary>
|
|
/// <param name="model">物料号信息(ID)</param>
|
|
/// <returns>删除个数</returns>
|
|
public int Delete(Equipment model,string userId)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
int count = 0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//删除基本信息
|
|
sqlBuilder.Append(" UPDATE T_MD_EQUIPMENT ");
|
|
sqlBuilder.Append(" SET FLGDEL = '1'");
|
|
sqlBuilder.Append(" ,UPDATEUSER = @UPDATEUSER ");
|
|
sqlBuilder.Append(" ,UPDATEDATE = @UPDATEDATE ");
|
|
sqlBuilder.Append(" WHERE PID = @PID ");
|
|
parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = model.PID });
|
|
parameters.Add(new DataParameter { ParameterName = "UPDATEUSER", DataType = DbType.String, Value = userId });
|
|
parameters.Add(new DataParameter { ParameterName = "UPDATEDATE", DataType = DbType.DateTime, Value = DateTime.Now });
|
|
|
|
// 对应多种数据库
|
|
string sqlChange = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
|
|
count = session.ExecuteSql(sqlChange, parameters.ToArray());
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 判断设备是否被用
|
|
/// <summary>
|
|
/// 判断设备是否被用
|
|
/// </summary>
|
|
/// <param name="model">设备</param>
|
|
/// <returns>true:已用;false:未用。</returns>
|
|
public bool IsUsedEquipmentLocCode(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 EQUIPMENT_CODE IN ( ");
|
|
sqlBuilder.Append(" SELECT EQUIPMENT_CODE FROM T_MD_EQUIPMENT ");
|
|
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="condition"></param>
|
|
/// <returns></returns>
|
|
public List<Equipment> GetMaterialList(Equipment condition)
|
|
{
|
|
List<Equipment> list = new List<Equipment>();
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = this.GetQuerySql(condition, ref parameters);
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
string sqlChange = ChangeSqlByDB(sql, session);
|
|
list = session.GetList<Equipment>(sqlChange, parameters.ToArray()).ToList();
|
|
}
|
|
return list;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
RecordExceptionLog(ex, "设备信息-列表");
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|
|
|