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

492 lines
18 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMAPP.MD.Entity;
using QMFrameWork.Data;
using QMFrameWork.Log;
using System.Data;
using QMAPP.DAL;
namespace QMAPP.MD.DAL
{
/// <summary>
/// 模块名称:班组信息
/// 作 者:郭兆福
/// 编写日期:2017年05月17日
/// </summary>
public class TeamDAL : BaseDAL
{
#region 获取信息
/// <summary>
/// 获取信息
/// </summary>
/// <param name="">条件</param>
/// <returns>*信息</returns>
public Team Get(Team model)
{
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//获取信息
model = session.Get<Team>(model);
}
return model;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "班组信息数据层 - 获取信息");
throw ex;
}
}
/// <summary>
/// 根据检索条件得到班组名称
/// </summary>
/// <param name="condition">条件</param>
/// <returns>班组名称</returns>
public string GetTeamName(Team condition)
{
string teamName = "";
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);
Team model = session.Get<Team>(sqlChange, parameters.ToArray());
if (null != model)
{
teamName = model.TEAM_NAME;
}
}
return teamName;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "班组信息数据层 - 获取班组名称");
throw ex;
}
}
#endregion
#region 获取列表
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataPage GetList(Team condition, DataPage page)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetQuerySql(condition, ref parameters);
#region 排序
//分页关键字段及排序
page.KeyName = "PID";
if (string.IsNullOrEmpty(page.SortExpression))
{
page.SortExpression = "UPDATEDATE DESC";
}
#endregion
using (IDataSession session = AppDataFactory.CreateMainSession())
{
// 对应多种数据库
string sqlChange = this.ChangeSqlByDB(sql, session);
page = session.GetDataPage<Team>(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(Team condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
sqlBuilder.AppendLine(@" SELECT T.PID
,T.FACTORY_CODE
,F.FACTORY_NAME
,T.DEPT_CODE
,T.TEAM_CODE
,T.TEAM_NAME
,T.TEAM_LEADER
,T.REMARK
,T.CREATEUSER
,T.CREATEDATE
,T.UPDATEUSER
,T.UPDATEDATE
,T.FLGDEL
FROM T_QT_TEAM T
LEFT JOIN T_MD_FACTORY F
ON T.FACTORY_CODE = F.FACTORY_CODE
");
//查询条件
whereBuilder.Append(" AND T.FLGDEL = '0'");
//班组编号
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.TEAM_CODE) == false)
{
whereBuilder.Append(" AND T.TEAM_CODE = @TEAM_CODE");
parameters.Add(new DataParameter { ParameterName = "TEAM_CODE", DataType = DbType.String, Value = condition.TEAM_CODE });
}
//班组名称
if (string.IsNullOrEmpty(condition.TEAM_NAME) == false)
{
whereBuilder.Append(" AND T.TEAM_NAME LIKE @TEAM_NAME");
parameters.Add(new DataParameter { ParameterName = "TEAM_NAME", DataType = DbType.String, Value = EscapeValue(condition.TEAM_NAME) + "%" });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
//sqlBuilder.AppendLine(" order by T.TEAM_CODE ");
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
/// <summary>
/// 获取全部用户
/// </summary>
/// <param name="condition">获取条件</param>
/// <returns>用户信息列表</returns>
public List<Team> GetAllTeam(Team condition)
{
string sql = null;
List<Team> list = null;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
sql = "SELECT * FROM T_QT_TEAM ";
if (!string.IsNullOrEmpty(condition.FACTORY_CODE))
{
sql += " where FACTORY_CODE = '"+condition.FACTORY_CODE+"'" ;
}
sql += " ORDER BY TEAM_CODE ";
list = session.GetList<Team>(sql, new List<DataParameter>().ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
throw;
}
}
#region 判断班组是否存在
/// <summary>
/// 判断名称是否存在
/// </summary>
/// <param name="info"></param>
/// <returns>true:已存在;false:不存在。</returns>
public bool ExistsTeam(Team 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_TEAM WHERE PID <> @PID AND TEAM_CODE=@TEAM_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("TEAM_CODE", model.TEAM_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(Team model)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//插入基本信息
count = session.Insert<Team>(model);
}
return count;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "班组信息数据层 - 班组信息数据层-插入信息");
throw ex;
}
}
#endregion
#region 更新信息
/// <summary>
/// 更新信息
/// </summary>
/// <param name="model">班组信息</param>
/// <returns>更新行数</returns>
public int Update(Team model)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//更新基本信息
count = session.Update<Team>(model);
}
return count;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "班组信息数据层 - 更新信息");
throw ex;
}
}
#endregion
#region 删除信息
/// <summary>
/// 删除信息
/// </summary>
/// <param name="model">班组信息(ID)</param>
/// <returns>删除个数</returns>
public int Delete(Team model)
{
StringBuilder sqlBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//删除基本信息
count = session.Delete<Team>(model);
}
return count;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "班组信息数据层 - 删除信息");
throw ex;
}
}
#endregion
// #region 班组是否使用
// /// <summary>
// /// 班组是否使用
// /// </summary>
// /// <param name="info"></param>
// /// <returns>true:已使用;fasel:未使用。</returns>
// public bool IsUsing(Team model)
// {
// int count = 0;
// StringBuilder sqlBuilder = new StringBuilder();
// try
// {
// sqlBuilder.AppendLine(" SELECT COUNT(*) FROM T_QT_TEAM_MEMBER T WHERE T.TEAM_PID=@TEAMID ");
// using (IDataSession session = AppDataFactory.CreateMainSession())
// {
// count = Convert.ToInt32(session.ExecuteSqlScalar(sqlBuilder.ToString(),
// new DataParameter { ParameterName = "TEAMID", Value = model.PID }));
// }
// if (count > 0)
// {
// return true;
// }
// else
// {
// return false;
// }
// }
// catch (Exception ex)
// {
// throw ex;
// }
// }
// #endregion
// #region 获取班组人员列表
// /// <summary>
// /// 获取班组人员列表
// /// </summary>
// /// <param name="condition">条件</param>
// /// <param name="page">数据页</param>
// /// <returns>数据页</returns>
// public DataPage GetTeamWorkerList(TeamMember condition, DataPage page)
// {
// string sql = null;
// List<DataParameter> parameters = new List<DataParameter>();
// try
// {
// sql = this.GetTeamWorkerQuerySql(condition, ref parameters);
// #region 排序
// //分页关键字段及排序
// page.KeyName = "PID";
// if (string.IsNullOrEmpty(page.SortExpression))
// {
// page.SortExpression = "UPDATEDATE DESC";
// }
// #endregion
// using (IDataSession session = AppDataFactory.CreateMainSession())
// {
// page = session.GetDataPage<TeamMember>(sql, parameters.ToArray(), page);
// }
// return page;
// }
// catch (Exception ex)
// {
// throw ex;
// }
// }
// /// <summary>
// /// 获取列表
// /// </summary>
// /// <param name="condition">条件</param>
// /// <returns>全部集合</returns>
// public List<TeamMember> GetTeamWorker(TeamMember condition)
// {
// List<TeamMember> list = new List<TeamMember>();
// string sql = null;
// List<DataParameter> parameters = new List<DataParameter>();
// try
// {
// sql = this.GetTeamWorkerQuerySql(condition, ref parameters);
// using (IDataSession session = AppDataFactory.CreateMainSession())
// {
// list = session.GetList<TeamMember>(sql, parameters.ToArray()).ToList();
// }
// return list;
// }
// 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 GetTeamWorkerQuerySql(TeamMember condition, ref List<DataParameter> parameters)
// {
// StringBuilder sqlBuilder = new StringBuilder();
// StringBuilder whereBuilder = new StringBuilder();
// try
// {
// sqlBuilder.AppendLine(@" SELECT T.PID
// ,T.MEMBER_CODE
// ,T.MEMBER_NAME
// ,T.WORK_STATION
// ,T.TEAM_PID
// ,T.CREATEUSR
// ,T.CREATEDATE
// ,T.UPDATEDATE
// ,T.FLAGDEL
// FROM T_QT_TEAM_MEMBER T ");
// //查询条件
// //班组主键
// if (string.IsNullOrEmpty(condition.TEAM_PID) == false)
// {
// whereBuilder.Append(" AND T.TEAM_PID = @TEAMID ");
// parameters.Add(new DataParameter { ParameterName = "TEAMID", DataType = DbType.String, Value = condition.TEAM_PID });
// }
// if (whereBuilder.Length > 0)
// {
// sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
// }
// return sqlBuilder.ToString();
// }
// catch (Exception ex)
// {
// throw ex;
// }
// }
// #endregion
}
}