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

169 lines
5.2 KiB

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 获取信息
/// <summary>
/// 获取信息
/// </summary>
/// <param name="">条件</param>
/// <returns>*信息</returns>
public Capacity Get(Capacity info)
{
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//获取信息
info = session.Get<Capacity>(info);
}
return info;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取列表
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <returns>数据页</returns>
public List<Capacity> GetList(Capacity condition)
{
string sql = null;
List<Capacity> list = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetQuerySql(condition, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
list = session.GetList<Capacity>(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取原数据表
/// <summary>
/// 获取原数据表
/// <param name="condition">条件</param>
/// </summary>
/// <returns>原数据表</returns>
public DataTable GetTable(Capacity condition)
{
string sql = null;
DataTable dt = null;
List<DataParameter> parameters = new List<DataParameter>();
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 保存数据
/// <summary>
/// 保存数据
/// <param name="dt"></param>
/// </summary>
/// <returns>原数据表</returns>
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 获取查询语句
/// <summary>
/// 获取查询语句
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
private string GetQuerySql(Capacity condition, ref List<DataParameter> 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
}
}