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
{
///
/// 模块名称:采集数据借口-状态码配置
/// 作 者:周晓东
/// 编写日期:2010514
/////
public class WorkCellStateDAL:BaseDAL
{
#region 获取信息
///
/// 获取信息
///
/// 条件
/// *信息
public WorkCellState Get(WorkCellState info)
{
string sql = null;
List parameters = new List();
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//获取信息
info = session.Get(info);
}
return info;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取列表
///
/// 获取列表
///
/// 条件
/// 数据页
/// 数据页
public DataPage GetList(WorkCellState condition, DataPage page)
{
string sql = null;
List parameters = new List();
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(sql, parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取查询语句
///
/// 获取查询语句
///
/// 查询条件
/// 参数
/// 查询语句
private string GetQuerySql(WorkCellState condition, ref List parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.Append(" SELECT T.* ,F.FACTORY_NAME ");
sqlBuilder.Append(" FROM T_MD_WORKCELL_STATE 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.STATE_CODE) == false)
{
whereBuilder.Append(" AND STATE_CODE like @STATE_CODE");
parameters.Add(new DataParameter { ParameterName = "STATE_CODE", DataType = DbType.String, Value = "%" + condition.STATE_CODE + "%" });
}
if (string.IsNullOrEmpty(condition.STATE_NAME) == false)
{
whereBuilder.Append(" AND STATE_NAME like @STATE_NAME");
parameters.Add(new DataParameter { ParameterName = "STATE_NAME", DataType = DbType.String, Value = "%" + condition.STATE_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;
}
}
#endregion
#region 插入信息
///
/// 插入信息(单表)
///
/// 信息
/// 插入行数
public int Insert(WorkCellState info)
{
int count=0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
session.OpenTs();
//插入基本信息
count = session.Insert(info);
session.CommitTs();
}
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 更新信息
///
/// 更新信息
///
///
/// 更新行数
public int Update(WorkCellState info)
{
string sql = null;
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
session.OpenTs();
//更新基本信息
count = session.Update(info);
session.CommitTs();
}
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 删除
public int Del(WorkCellState info)
{
StringBuilder sqlBuilder = new StringBuilder();
List parameters = new List();
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//删除基本信息
sqlBuilder.Append("delete from T_MD_WORKCELL_STATE ");
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 GetEntryExitActionList()
{
List parameters = new List();
var sql = "";
try
{
sql = " SELECT ACTION_CODE,ACTION_NAME FROM T_QT_STATEACTION ";
using (IDataSession session = AppDataFactory.CreateMainSession())
{
return session.GetList(sql, parameters.ToArray()).ToList();
}
}
catch (Exception ex)
{
throw ex;
}
}
}
}