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.
428 lines
15 KiB
428 lines
15 KiB
4 years ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
using System.Text;
|
||
|
using QMFrameWork.Data;
|
||
|
using System.Data;
|
||
|
using QMAPP.FJC.Entity.Basic;
|
||
|
using QMFrameWork.Log;
|
||
|
|
||
|
namespace QMAPP.FJC.DAL.Basic
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// 模块编号:M2-3
|
||
|
/// 作 用:班次信息数据层
|
||
|
/// 作 者:王丹丹
|
||
|
/// 编写日期:2015年05月28日
|
||
|
///</summary>
|
||
|
public class ProduceShiftDAL
|
||
|
{
|
||
|
#region 获取信息
|
||
|
/// <summary>
|
||
|
/// 获取信息
|
||
|
/// </summary>
|
||
|
/// <param name="">条件</param>
|
||
|
/// <returns>*信息</returns>
|
||
|
public ProduceShift Get(ProduceShift model)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
//获取信息
|
||
|
model = session.Get<ProduceShift>(model);
|
||
|
}
|
||
|
return model;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogManager.LogHelper.Error(new LogInfo()
|
||
|
{
|
||
|
ErrorInfo = ex,
|
||
|
Tag = ex.StackTrace,
|
||
|
Info = "班次信息数据层-获取信息"
|
||
|
});
|
||
|
throw;
|
||
|
}
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
#region 获取列表
|
||
|
/// <summary>
|
||
|
/// 获取列表
|
||
|
/// </summary>
|
||
|
/// <param name="condition">条件</param>
|
||
|
/// <param name="page">数据页</param>
|
||
|
/// <returns>数据页</returns>
|
||
|
public DataPage GetList(ProduceShift 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<ProduceShift>(sql, parameters.ToArray(), page);
|
||
|
}
|
||
|
return page;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogManager.LogHelper.Error(new LogInfo()
|
||
|
{
|
||
|
ErrorInfo = ex,
|
||
|
Tag = ex.StackTrace,
|
||
|
Info = "班次信息数据层-获取列表"
|
||
|
});
|
||
|
throw;
|
||
|
}
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
#region 获取查询语句
|
||
|
/// <summary>
|
||
|
/// 获取查询语句
|
||
|
/// </summary>
|
||
|
/// <param name="user">查询条件</param>
|
||
|
/// <param name="parameters">参数</param>
|
||
|
/// <returns>查询语句</returns>
|
||
|
private string GetQuerySql(ProduceShift condition, ref List<DataParameter> parameters)
|
||
|
{
|
||
|
StringBuilder sqlBuilder = new StringBuilder();
|
||
|
StringBuilder whereBuilder = new StringBuilder();
|
||
|
try
|
||
|
{
|
||
|
sqlBuilder.AppendLine(" SELECT M.PID ");
|
||
|
sqlBuilder.AppendLine(" ,M.PRODUCESHIFTNAME ");
|
||
|
sqlBuilder.AppendLine(" ,M.PRODUCESHIFTTCODE ");
|
||
|
sqlBuilder.AppendLine(" ,M.PSSTART ");
|
||
|
sqlBuilder.AppendLine(" ,M.PSEND ");
|
||
|
sqlBuilder.AppendLine(" ,M.PRODUCELINE ");
|
||
|
sqlBuilder.AppendLine(" ,W.WORKCENTER_NAME ");
|
||
|
sqlBuilder.AppendLine(" ,M.MEMO ");
|
||
|
sqlBuilder.AppendLine(" ,M.CREATEUSER ");
|
||
|
sqlBuilder.AppendLine(" ,M.CREATEDATE ");
|
||
|
sqlBuilder.AppendLine(" ,M.UPDATEUSER ");
|
||
|
sqlBuilder.AppendLine(" ,M.UPDATEDATE ");
|
||
|
sqlBuilder.AppendLine(" ,C.USERNAME AS CREATEUSERNAME ");
|
||
|
sqlBuilder.AppendLine(" ,U.USERNAME AS UPDATEUSERNAME ");
|
||
|
sqlBuilder.AppendLine(" FROM T_BD_PRODUCESHIFT M ");
|
||
|
sqlBuilder.AppendLine(" LEFT JOIN T_MD_WORKCENTER W ON W.WORKCENTER_CODE=M.PRODUCELINE ");
|
||
|
sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER C ON C.USERID=M.CREATEUSER ");
|
||
|
sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER U ON U.USERID=M.UPDATEUSER ");
|
||
|
|
||
|
|
||
|
//查询条件
|
||
|
//班次编号
|
||
|
if (string.IsNullOrEmpty(condition.PRODUCESHIFTTCODE) == false)
|
||
|
{
|
||
|
whereBuilder.Append(" AND PRODUCESHIFTTCODE LIKE '%'+" + "@PRODUCESHIFTTCODE" + "+'%'");
|
||
|
parameters.Add(new DataParameter { ParameterName = "PRODUCESHIFTTCODE", DataType = DbType.String, Value = condition.PRODUCESHIFTTCODE });
|
||
|
}
|
||
|
//班次名称
|
||
|
if (string.IsNullOrEmpty(condition.PRODUCESHIFTNAME) == false)
|
||
|
{
|
||
|
whereBuilder.Append(" AND PRODUCESHIFTNAME LIKE '%'+" + "@PRODUCESHIFTNAME" + "+'%'");
|
||
|
parameters.Add(new DataParameter { ParameterName = "PRODUCESHIFTNAME", DataType = DbType.String, Value = condition.PRODUCESHIFTNAME });
|
||
|
}
|
||
|
//工作中心
|
||
|
if (string.Equals(condition.PRODUCELINE,"All") == false)
|
||
|
{
|
||
|
whereBuilder.Append(" AND PRODUCELINE = @PRODUCELINE");
|
||
|
parameters.Add(new DataParameter { ParameterName = "PRODUCELINE", DataType = DbType.String, Value = condition.PRODUCELINE + "" });
|
||
|
}
|
||
|
//班次ID(用于校验班次时间)
|
||
|
if (string.IsNullOrEmpty(condition.isNoPID) == false)
|
||
|
{
|
||
|
whereBuilder.Append(" AND PID != @PID ");
|
||
|
parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = condition.isNoPID });
|
||
|
}
|
||
|
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 ExistsProduceShift(ProduceShift model)
|
||
|
{
|
||
|
string PID = "";
|
||
|
int count = 0;
|
||
|
string sql = null;
|
||
|
try
|
||
|
{
|
||
|
if (string.IsNullOrEmpty(model.PID) == false)
|
||
|
{
|
||
|
PID = model.PID;
|
||
|
}
|
||
|
|
||
|
sql = "SELECT COUNT(*) FROM T_BD_PRODUCESHIFT WHERE PID <> @PID AND PRODUCESHIFTTCODE=@PRODUCESHIFTTCODE";
|
||
|
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
count = Convert.ToInt32(session.ExecuteSqlScalar(sql, new DataParameter("PID", PID),
|
||
|
new DataParameter { ParameterName = "PRODUCESHIFTTCODE", Value = model.PRODUCESHIFTTCODE }));
|
||
|
}
|
||
|
|
||
|
if (count > 0)
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogManager.LogHelper.Error(new LogInfo()
|
||
|
{
|
||
|
ErrorInfo = ex,
|
||
|
Tag = ex.StackTrace,
|
||
|
Info = "班次信息数据层-信息是否重复"
|
||
|
});
|
||
|
throw;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 插入信息
|
||
|
/// <summary>
|
||
|
/// 插入信息(单表)
|
||
|
/// </summary>
|
||
|
/// <param name=model"">班次信息</param>
|
||
|
/// <returns>插入行数</returns>
|
||
|
public int Insert(ProduceShift model)
|
||
|
{
|
||
|
int count = 0;
|
||
|
try
|
||
|
{
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
//插入基本信息
|
||
|
count = session.Insert<ProduceShift>(model);
|
||
|
}
|
||
|
return count;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogManager.LogHelper.Error(new LogInfo()
|
||
|
{
|
||
|
ErrorInfo = ex,
|
||
|
Tag = ex.StackTrace,
|
||
|
Info = "班次信息数据层-插入信息"
|
||
|
});
|
||
|
throw;
|
||
|
}
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
#region 更新信息
|
||
|
/// <summary>
|
||
|
/// 更新信息
|
||
|
/// </summary>
|
||
|
/// <param name="model">班次信息</param>
|
||
|
/// <returns>更新行数</returns>
|
||
|
public int Update(ProduceShift model)
|
||
|
{
|
||
|
int count = 0;
|
||
|
try
|
||
|
{
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
//更新基本信息
|
||
|
count = session.Update<ProduceShift>(model);
|
||
|
}
|
||
|
return count;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogManager.LogHelper.Error(new LogInfo()
|
||
|
{
|
||
|
ErrorInfo = ex,
|
||
|
Tag = ex.StackTrace,
|
||
|
Info = "班次信息数据层-更新信息"
|
||
|
});
|
||
|
throw;
|
||
|
}
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
#region 删除
|
||
|
/// <summary>
|
||
|
/// 删除信息
|
||
|
/// </summary>
|
||
|
/// <param name="model">班次信息(ID)</param>
|
||
|
/// <returns>删除个数</returns>
|
||
|
public int Delete(ProduceShift model)
|
||
|
{
|
||
|
StringBuilder sqlBuilder = new StringBuilder();
|
||
|
List<DataParameter> parameters = new List<DataParameter>();
|
||
|
int count = 0;
|
||
|
try
|
||
|
{
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
//删除基本信息
|
||
|
count = session.Delete<ProduceShift>(model);
|
||
|
}
|
||
|
return count;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogManager.LogHelper.Error(new LogInfo()
|
||
|
{
|
||
|
ErrorInfo = ex,
|
||
|
Tag = ex.StackTrace,
|
||
|
Info = "班次信息数据层-删除"
|
||
|
});
|
||
|
throw;
|
||
|
}
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
#region 校验时间
|
||
|
/// <summary>
|
||
|
/// 校验时间
|
||
|
/// </summary>
|
||
|
/// <param name="info"></param>
|
||
|
/// <returns>true:已存在;fasel:不存在。</returns>
|
||
|
public bool ExistsProduceShiftTime(ProduceShift model)
|
||
|
{
|
||
|
string PID = "";
|
||
|
int count = 0;
|
||
|
string sql = null;
|
||
|
try
|
||
|
{
|
||
|
if (string.IsNullOrEmpty(model.PID) == false)
|
||
|
{
|
||
|
PID = model.PID;
|
||
|
}
|
||
|
|
||
|
sql = "SELECT COUNT(*) FROM T_BD_PRODUCESHIFT WHERE PID <> @PID AND PRODUCESHIFTTCODE=@PRODUCESHIFTTCODE";
|
||
|
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
count = Convert.ToInt32(session.ExecuteSqlScalar(sql, new DataParameter("PID", PID),
|
||
|
new DataParameter { ParameterName = "PRODUCESHIFTTCODE", Value = model.PRODUCESHIFTTCODE }));
|
||
|
}
|
||
|
|
||
|
if (count > 0)
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogManager.LogHelper.Error(new LogInfo()
|
||
|
{
|
||
|
ErrorInfo = ex,
|
||
|
Tag = ex.StackTrace,
|
||
|
Info = "班次信息数据层-校验时间"
|
||
|
});
|
||
|
throw;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 获取列表
|
||
|
/// <summary>
|
||
|
/// 获取列表
|
||
|
/// </summary>
|
||
|
/// <param name="condition">条件</param>
|
||
|
/// <param name="page">数据页</param>
|
||
|
/// <returns>数据页</returns>
|
||
|
public List<ProduceShift> GetList(ProduceShift condition)
|
||
|
{
|
||
|
string sql = null;
|
||
|
List<DataParameter> parameters = new List<DataParameter>();
|
||
|
List<ProduceShift> psList = new List<ProduceShift>();
|
||
|
try
|
||
|
{
|
||
|
sql = this.GetQuerySql(condition, ref parameters);
|
||
|
sql = sql + " ORDER BY PRODUCELINE,PRODUCESHIFTTCODE";
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
psList=session.GetList<ProduceShift>(sql, parameters.ToArray()).ToList();
|
||
|
}
|
||
|
return psList;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogManager.LogHelper.Error(new LogInfo()
|
||
|
{
|
||
|
ErrorInfo = ex,
|
||
|
Tag = ex.StackTrace,
|
||
|
Info = "班次信息数据层-获取列表"
|
||
|
});
|
||
|
throw;
|
||
|
}
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
#region 获取班次下拉列表
|
||
|
/// <summary>
|
||
|
/// 获取班次列表(下拉列表数据源)
|
||
|
/// </summary>
|
||
|
/// <param name="condition">条件</param>
|
||
|
/// <returns>全部集合</returns>
|
||
|
public List<ProduceShift> GetProduceShiftList(ProduceShift condition)
|
||
|
{
|
||
|
List<ProduceShift> list = new List<ProduceShift>();
|
||
|
string sql = null;
|
||
|
List<DataParameter> parameters = new List<DataParameter>();
|
||
|
try
|
||
|
{
|
||
|
sql = this.GetQuerySql(condition, ref parameters);
|
||
|
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
list = session.GetList<ProduceShift>(sql, parameters.ToArray()).ToList();
|
||
|
}
|
||
|
return list;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogManager.LogHelper.Error(new LogInfo()
|
||
|
{
|
||
|
ErrorInfo = ex,
|
||
|
Tag = ex.StackTrace,
|
||
|
Info = "班次信息-获取班次列表"
|
||
|
});
|
||
|
throw;
|
||
|
}
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
}
|
||
|
}
|