using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMAPP.FJC.Entity.Basic;
using QMFrameWork.Data;
using System.Data;
namespace QMAPP.FJC.DAL.Basic
{
public class CapacityDAL
{
#region 获取信息
///
/// 获取信息
///
/// 条件
/// *信息
public Capacity Get(Capacity info)
{
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//获取信息
info = session.Get(info);
}
return info;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取列表
///
/// 获取列表
///
/// 条件
/// 数据页
public List GetList(Capacity condition)
{
string sql = null;
List list = null;
List parameters = new List();
try
{
sql = this.GetQuerySql(condition, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
list = session.GetList(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取原数据表
///
/// 获取原数据表
/// 条件
///
/// 原数据表
public DataTable GetTable(Capacity condition)
{
string sql = null;
DataTable dt = null;
List parameters = new List();
try
{
sql = GetQuerySql(condition, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//dt = session.GetTableWithSchema(sql, "T_BD_CAPACITY", parameters.ToArray());
}
return dt;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 保存数据
///
/// 保存数据
///
///
/// 原数据表
public void Save(DataTable dt)
{
DateTime nowTime;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//nowTime = session.GetNowDataTime();
nowTime = DateTime.Now;
foreach (DataRow row in dt.Rows)
{
if (row.RowState == DataRowState.Unchanged)
continue;
if (row.RowState == DataRowState.Added)
{
row["CREATEDATA"] = nowTime;
row["UPDATEDATA"] = nowTime;
row["FLGDEL"] = "0";
}
if (row.RowState == DataRowState.Modified)
{
row["UPDATEDATA"] = nowTime;
}
}
session.UpdateTable(dt);
}
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取查询语句
///
/// 获取查询语句
///
/// 查询条件
/// 参数
/// 查询语句
private string GetQuerySql(Capacity condition, ref List parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.Append("SELECT PID,SHIFT_PID,WORKCENTER_PID,CAPACITY,CREATEUSER,CREATEDATA,UPDATEUSER,UPDATEDATA,FLGDEL ");
sqlBuilder.Append("FROM T_BD_CAPACITY ");
if (!string.IsNullOrWhiteSpace(condition.WORKCENTER_PID))
{
whereBuilder.AppendLine(" AND WORKCENTER_PID=@workcenterid");
parameters.Add(new DataParameter("workcenterid", condition.WORKCENTER_PID));
}
//查询条件
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
}
}