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.
429 lines
16 KiB
429 lines
16 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Data;
|
|
using System.Text;
|
|
using QMFrameWork.Data;
|
|
using QMAPP.Entity;
|
|
using QMAPP.MD.Entity;
|
|
using QMAPP.DAL;
|
|
|
|
namespace QMAPP.MD.DAL
|
|
{
|
|
/// <summary>
|
|
/// 模块名称:采集数据借口
|
|
/// 作 者:QMMES
|
|
/// 编写日期:2017年09月05日
|
|
/// </summary>
|
|
public class DaiDAL:BaseDAL
|
|
{
|
|
#region 获取信息
|
|
/// <summary>
|
|
/// 获取信息
|
|
/// </summary>
|
|
/// <param name="">条件</param>
|
|
/// <returns>*信息</returns>
|
|
public Dai Get(Dai info)
|
|
{
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//获取信息
|
|
info = session.Get<Dai>(info);
|
|
//获取明细信息
|
|
//sql = "SELECT * FROM T_QT_DAI_DATA WHERE DA_CODE = @DA_CODE";
|
|
//parameters.Add(new DataParameter("DA_CODE", info.DA_CODE));
|
|
//info.Details = session.GetList<DaiData>(sql, parameters.ToArray()).ToList();
|
|
}
|
|
return info;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 根据采集点编码获得采集点相关信息
|
|
/// </summary>
|
|
/// <param name="">条件</param>
|
|
/// <returns>*信息</returns>
|
|
public Dai GetDaiByDaCode(string daCode)
|
|
{
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
Dai info = new Dai {DA_CODE = daCode};
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
|
|
//获取信息
|
|
string daiChangeSql = ChangeSqlByDB(GetDaiInfoSql(info,ref parameters),session);
|
|
info = session.Get<Dai>(daiChangeSql, parameters.ToArray());
|
|
if (null == info)
|
|
{
|
|
throw new Exception("没有找到相应的采集点!");
|
|
}
|
|
parameters.Clear();
|
|
//获取明细信息
|
|
//sql = "SELECT * FROM T_QT_DAI_DATA WHERE DA_CODE = @DA_CODE";
|
|
//parameters.Add(new DataParameter("DA_CODE", info.DA_CODE));
|
|
//string detailChangeSql = ChangeSqlByDB(sql,session);
|
|
//info.Details = session.GetList<DaiData>(detailChangeSql, parameters.ToArray()).ToList();
|
|
}
|
|
return info;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 获取列表
|
|
/// <summary>
|
|
/// 获取列表
|
|
/// </summary>
|
|
/// <param name="condition">条件</param>
|
|
/// <param name="page">数据页</param>
|
|
/// <returns>数据页</returns>
|
|
public DataPage GetList(Dai condition, DataPage page)
|
|
{
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = this.GetQuerySql(condition, ref parameters);
|
|
//分页关键字段及排序
|
|
page.KeyName = "PID";
|
|
if (string.IsNullOrEmpty(page.SortExpression))
|
|
page.SortExpression = "UPDATEDATE DESC";
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
page = session.GetDataPage<Dai>(sql, parameters.ToArray(), page);
|
|
}
|
|
return page;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 获取查询语句
|
|
/// <summary>
|
|
/// 获取查询语句
|
|
/// </summary>
|
|
/// <param name="user">查询条件</param>
|
|
/// <param name="parameters">参数</param>
|
|
/// <returns>查询语句</returns>
|
|
private string GetQuerySql(Dai condition, ref List<DataParameter> parameters)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
try
|
|
{
|
|
//构成查询语句
|
|
sqlBuilder.Append(" SELECT T.* ,F.FACTORY_NAME ");
|
|
sqlBuilder.Append(" FROM T_QT_DAI T ");
|
|
sqlBuilder.Append(" LEFT JOIN T_MD_FACTORY F ON F.FACTORY_CODE=T.FACTORY_CODE ");
|
|
//查询条件
|
|
//工厂
|
|
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.DA_CODE) == false)
|
|
{
|
|
whereBuilder.Append(" AND DA_CODE like @DA_CODE");
|
|
parameters.Add(new DataParameter { ParameterName = "DA_CODE", DataType = DbType.String, Value = "%"+ condition.DA_CODE+"%" });
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(condition.DA_NAME) == false)
|
|
{
|
|
whereBuilder.Append(" AND DA_NAME like @DA_NAME");
|
|
parameters.Add(new DataParameter { ParameterName = "DA_NAME", DataType = DbType.String, Value = "%" + condition.DA_NAME + "%" });
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(condition.WORKCELL_CODE) == false)
|
|
{
|
|
whereBuilder.Append(" AND WORKCELL_CODE = @WORKCELL_CODE");
|
|
parameters.Add(new DataParameter { ParameterName = "WORKCELL_CODE", DataType = DbType.String, Value = condition.WORKCELL_CODE });
|
|
}
|
|
|
|
if (whereBuilder.Length > 0)
|
|
{
|
|
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
|
|
}
|
|
return sqlBuilder.ToString();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 获取查询语句
|
|
/// </summary>
|
|
/// <param name="user">查询条件</param>
|
|
/// <param name="parameters">参数</param>
|
|
/// <returns>查询语句</returns>
|
|
private string GetDaiInfoSql(Dai condition, ref List<DataParameter> parameters)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
try
|
|
{
|
|
//构成查询语句
|
|
sqlBuilder.Append("SELECT");
|
|
sqlBuilder.Append(" A.PID");
|
|
sqlBuilder.Append(" , A.WORKCELL_CODE");
|
|
sqlBuilder.Append(" , B.WORKCELL_NAME");
|
|
sqlBuilder.Append(" , A.EQUIPMENT_CODE");
|
|
sqlBuilder.Append(" , C.EQUIPMENT_NAME");
|
|
sqlBuilder.Append(" , A.DA_CODE");
|
|
sqlBuilder.Append(" , A.DA_NAME");
|
|
sqlBuilder.Append(" , A.DA_STATUS");
|
|
sqlBuilder.Append(" , A.MATERIAL_CODE");
|
|
sqlBuilder.Append(" , A.MATERIAL_TYPE");
|
|
sqlBuilder.Append(" , A.ANALYZE_CODE");
|
|
sqlBuilder.Append(" , A.DATA_TYPE");
|
|
sqlBuilder.Append(" , A.STATE_CODE");
|
|
sqlBuilder.Append(" , A.DA_SEQ");
|
|
sqlBuilder.Append(" , A.PIVOTAL");
|
|
sqlBuilder.Append(" , A.DA_MODEL");
|
|
sqlBuilder.Append(" , A.ISPROCESSCODE");
|
|
sqlBuilder.Append(" , A.REMARK");
|
|
sqlBuilder.Append(" , A.CREATEUSER");
|
|
sqlBuilder.Append(" , A.CREATEDATE");
|
|
sqlBuilder.Append(" , A.UPDATEUSER");
|
|
sqlBuilder.Append(" , A.UPDATEDATE");
|
|
sqlBuilder.Append(" , A.FLGDEL ");
|
|
sqlBuilder.Append(" FROM ");
|
|
sqlBuilder.Append(" T_QT_DAI A ");
|
|
sqlBuilder.Append(" LEFT JOIN T_MD_WORKCELL B ");
|
|
sqlBuilder.Append(" ON A.WORKCELL_CODE = B.WORKCELL_CODE ");
|
|
sqlBuilder.Append(" AND B.FLGDEL = '0' ");
|
|
sqlBuilder.Append(" LEFT JOIN T_MD_EQUIPMENT C ");
|
|
sqlBuilder.Append(" ON A.EQUIPMENT_CODE = C.EQUIPMENT_CODE ");
|
|
sqlBuilder.Append(" AND C.FLGDEL = '0'");
|
|
whereBuilder.Append(" AND A.FLGDEL = '0' ");
|
|
//查询条件
|
|
//采集点编码
|
|
if (string.IsNullOrEmpty(condition.DA_CODE) == false)
|
|
{
|
|
whereBuilder.Append(" AND A.DA_CODE = @DA_CODE");
|
|
parameters.Add(new DataParameter { ParameterName = "DA_CODE", DataType = DbType.String, Value = condition.DA_CODE });
|
|
}
|
|
//主键
|
|
if (string.IsNullOrEmpty(condition.PID) == false)
|
|
{
|
|
whereBuilder.Append(" AND A.PID = @PID");
|
|
parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = condition.PID });
|
|
}
|
|
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 Exists(Dai info)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
int count = 0;
|
|
try
|
|
{
|
|
sqlBuilder.Append("SELECT COUNT(0) FROM T_QT_DAI");
|
|
if (info.PID==null)
|
|
{
|
|
info.PID = "";
|
|
}
|
|
whereBuilder.Append(" AND PID <> @PID ");
|
|
parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = info.PID });
|
|
|
|
//添加进行无重复字段判断代码
|
|
|
|
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()));
|
|
}
|
|
return count > 0;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 插入信息
|
|
/// <summary>
|
|
/// 插入信息(单表)
|
|
/// </summary>
|
|
/// <param name="">信息</param>
|
|
/// <returns>插入行数</returns>
|
|
public int Insert(Dai info)
|
|
{
|
|
int count=0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
session.OpenTs();
|
|
//插入基本信息
|
|
count = session.Insert<Dai>(info);
|
|
//插入明细
|
|
//if (info.Details != null)
|
|
// session.Insert<DaiData>(info.Details);
|
|
session.CommitTs();
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 更新信息
|
|
/// <summary>
|
|
/// 更新信息
|
|
/// </summary>
|
|
/// <param name=""></param>
|
|
/// <returns>更新行数</returns>
|
|
public int Update(Dai info)
|
|
{
|
|
string sql = null;
|
|
int count = 0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
session.OpenTs();
|
|
//更新基本信息
|
|
count = session.Update<Dai>(info);
|
|
////更新明细信息
|
|
//sql = "DELETE FROM T_QT_DAI_DATA WHERE DA_CODE = @DA_CODE";
|
|
//session.ExecuteSql(sql, new DataParameter("DA_CODE", info.PID));
|
|
//if (info.Details != null)
|
|
// session.Insert<DaiData>(info.Details);
|
|
session.CommitTs();
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 逻辑删除
|
|
/// <summary>
|
|
/// 逻辑删除信息
|
|
/// </summary>
|
|
/// <param name=""></param>
|
|
/// <returns>删除个数</returns>
|
|
public int Delete(Dai info)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
int count = 0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//删除基本信息
|
|
sqlBuilder.Append("UPDATE T_QT_DAI ");
|
|
sqlBuilder.Append("SET FLGDEL = '1' ");
|
|
sqlBuilder.Append("WHERE PID = @PID ");
|
|
parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = info.PID });
|
|
count = session.ExecuteSql(sqlBuilder.ToString(), parameters.ToArray());
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
public int Del(Dai info)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
int count = 0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//删除基本信息
|
|
sqlBuilder.Append("delete from T_QT_DAI ");
|
|
sqlBuilder.Append("WHERE PID = @PID ");
|
|
parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = info.PID });
|
|
count = session.ExecuteSql(sqlBuilder.ToString(), parameters.ToArray());
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
//获取状态码的下拉框
|
|
public List<Dai> GetWorkCellStateCodeList(string workCellCode)
|
|
{
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
var sql = "";
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(workCellCode))
|
|
{
|
|
sql = " SELECT STATE_CODE,STATE_NAME FROM T_MD_WORKCELL_STATE group by STATE_CODE,STATE_NAME";
|
|
}
|
|
else
|
|
{
|
|
sql = " SELECT STATE_CODE,STATE_NAME FROM T_MD_WORKCELL_STATE where WORKCELL_CODE='" + workCellCode + "' ";
|
|
}
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
return session.GetList<Dai>(sql, parameters.ToArray()).ToList();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|