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

433 lines
15 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMFrameWork.Data;
using QMAPP.MD.Entity;
using QMFrameWork.Log;
using System.Data;
using QMAPP.DAL;
namespace QMAPP.MD.DAL
{
/// <summary>
/// 模块名称:班次
/// 作 者:郭兆福
/// 编写日期:2017年05月17日
/// </summary>
public class ShiftDAL:BaseDAL
{
#region 获取信息
/// <summary>
/// 获取信息
/// </summary>
/// <param name="">条件</param>
/// <returns>*信息</returns>
public Shift__ Get(Shift__ model)
{
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//获取信息
model = session.Get<Shift__>(model);
}
return model;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "班次信息数据层-获取信息");
throw ex;
}
}
/// <summary>
/// 根据条件得到班次名称
/// </summary>
/// <param name="condition">条件</param>
/// <returns>班次名称</returns>
public string GetShiftName(Shift__ condition)
{
string shiftName = "";
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetQuerySql(condition, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
// 对应多种数据库
string sqlChange = this.ChangeSqlByDB(sql, session);
Shift__ model = session.Get<Shift__>(sqlChange, parameters.ToArray());
if (null != model)
{
shiftName = model.SHIFT_NAME;
}
}
return shiftName;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "班次信息数据层 - 获取班次名称");
throw ex;
}
}
#endregion
#region 获取列表
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataPage GetList(Shift__ 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())
{
// 对应多种数据库
string sqlChange = this.ChangeSqlByDB(sql, session);
page = session.GetDataPage<Shift__>(sqlChange, parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "班次信息数据层-获取列表");
throw ex;
}
}
#endregion
#region 获取查询语句
/// <summary>
/// 获取查询语句
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
private string GetQuerySql(Shift__ condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
sqlBuilder.AppendLine(" SELECT M.PID ");
sqlBuilder.AppendLine(" ,M.FACTORY_CODE ");
sqlBuilder.AppendLine(" ,F.FACTORY_NAME ");
sqlBuilder.AppendLine(" ,M.SHIFT_NAME ");
sqlBuilder.AppendLine(" ,M.SHIFT_CODE ");
sqlBuilder.AppendLine(" ,M.WORK_START_TIME ");
sqlBuilder.AppendLine(" ,M.WORK_END_TIME ");
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_QT_SHIFT M ");
sqlBuilder.AppendLine(" LEFT JOIN T_MD_FACTORY F ON M.FACTORY_CODE=F.FACTORY_CODE ");
//查询条件
whereBuilder.Append(" AND M.FLGDEL = '0'");
//班次编号
if (string.IsNullOrEmpty(condition.FACTORY_CODE) == false)
{
whereBuilder.Append(" AND M.FACTORY_CODE = @FACTORY_CODE");
parameters.Add(new DataParameter { ParameterName = "FACTORY_CODE", DataType = DbType.String, Value = condition.FACTORY_CODE });
}
//班次编号
if (string.IsNullOrEmpty(condition.SHIFT_CODE) == false)
{
whereBuilder.Append(" AND M.SHIFT_CODE = @SHIFT_CODE");
parameters.Add(new DataParameter { ParameterName = "SHIFT_CODE", DataType = DbType.String, Value = condition.SHIFT_CODE });
}
//班次名称
if (string.IsNullOrEmpty(condition.SHIFT_NAME) == false)
{
whereBuilder.Append(" AND M.SHIFT_NAME LIKE @SHIFT_NAME");
parameters.Add(new DataParameter { ParameterName = "SHIFT_NAME", DataType = DbType.String, Value = EscapeValue(condition.SHIFT_NAME)+"%" });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
//sqlBuilder.AppendLine(" order by M.SHIFT_CODE ");
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
/// <summary>
/// 获取全部用户
/// </summary>
/// <param name="condition">获取条件</param>
/// <returns>用户信息列表</returns>
public List<Shift__> GetAllShift(Shift__ condition)
{
string sql = null;
List<Shift__> list;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetQuerySql(condition, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//sql = "SELECT * FROM T_QT_SHIFT ORDER BY SHIFT_CODE ";
list = session.GetList<Shift__>(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
throw;
}
}
#region 信息是否重复
/// <summary>
/// 信息是否重复
/// </summary>
/// <param name="info"></param>
/// <returns>true:已存在;fasel:不存在。</returns>
public bool ExistsShift(Shift__ model)
{
string PID = "";
int count = 0;
string sql = null;
try
{
if (string.IsNullOrEmpty(model.PID) == false)
{
PID = model.PID;
}
sql = "SELECT COUNT(*) FROM T_QT_SHIFT WHERE PID <> @PID AND SHIFT_CODE=@SHIFT_CODE AND FACTORY_CODE=@FACTORY_CODE";
using (IDataSession session = AppDataFactory.CreateMainSession())
{
// 对应多种数据库
string sqlChange = this.ChangeSqlByDB(sql, session);
count = Convert.ToInt32(session.ExecuteSqlScalar(sqlChange,
new DataParameter("PID", PID),
new DataParameter("SHIFT_CODE", model.SHIFT_CODE),
new DataParameter("FACTORY_CODE", model.FACTORY_CODE)));
}
return count > 0;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "班次信息数据层-信息是否重复表");
throw ex;
}
}
#endregion
#region 插入信息
/// <summary>
/// 插入信息(单表)
/// </summary>
/// <param name=model"">班次信息</param>
/// <returns>插入行数</returns>
public int Insert(Shift__ model)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//插入基本信息
count = session.Insert<Shift__>(model);
}
return count;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "班次信息数据层-插入信息");
throw ex;
}
}
#endregion
#region 更新信息
/// <summary>
/// 更新信息
/// </summary>
/// <param name="model">班次信息</param>
/// <returns>更新行数</returns>
public int Update(Shift__ model)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//更新基本信息
count = session.Update<Shift__>(model);
}
return count;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "班次信息数据层-更新信息");
throw ex;
}
}
#endregion
#region 删除
/// <summary>
/// 删除信息
/// </summary>
/// <param name="model">班次信息(ID)</param>
/// <returns>删除个数</returns>
public int Delete(Shift__ model)
{
StringBuilder sqlBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//删除基本信息
count = session.Delete<Shift__>(model);
}
return count;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "班次信息数据层-删除信息");
throw ex;
}
}
#endregion
#region 校验时间
/// <summary>
/// 校验时间
/// </summary>
/// <param name="info"></param>
/// <returns>true:已存在;fasel:不存在。</returns>
public bool ExistsShiftTime(Shift__ model)
{
string PID = "";
int count = 0;
string sql = null;
try
{
if (string.IsNullOrEmpty(model.PID) == false)
{
PID = model.PID;
}
sql = "SELECT COUNT(*) FROM T_QT_SHIFT WHERE PID <> @PID AND SHIFT_CODE=@SHIFT_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 = "SHIFT_CODE", Value = model.SHIFT_CODE }));
}
if (count > 0)
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
RecordExceptionLog(ex, "班次信息数据层-校验时间");
throw ex;
}
}
#endregion
#region 获取列表
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public List<Shift__> GetList(Shift__ condition)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
List<Shift__> psList = new List<Shift__>();
try
{
sql = this.GetQuerySql(condition, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
// 对应多种数据库
string sqlChange = this.ChangeSqlByDB(sql, session);
psList = session.GetList<Shift__>(sqlChange, parameters.ToArray()).ToList();
}
return psList;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "班次信息数据层-获取列表");
throw ex;
}
}
#endregion
#region 物料信息下拉
/// <summary>
///
/// </summary>
/// <param name="condition"></param>
/// <returns></returns>
public List<Shift__> GetShiftList(Shift__ condition)
{
List<Shift__> list = new List<Shift__>();
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<Shift__>(sqlChange, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "物料信息-列表");
throw ex;
}
}
#endregion
}
}