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.
358 lines
14 KiB
358 lines
14 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using QMFrameWork.Data;
|
|
using QMAPP.Entity.Sys;
|
|
using System.Data;
|
|
|
|
namespace QMAPP.DAL.Sys
|
|
{
|
|
/// <summary>
|
|
/// 支持交互问题类型数据层对象
|
|
/// 创建者:wangyf
|
|
/// 创建日期:2014.03.30
|
|
/// </summary>
|
|
public class SIProblemTypeDAL : BaseDAL
|
|
{
|
|
#region 获取信息
|
|
/// <summary>
|
|
/// 获取信息
|
|
/// </summary>
|
|
/// <param name="">条件</param>
|
|
/// <returns>*信息</returns>
|
|
public SIProblemType Get(SIProblemType model)
|
|
{
|
|
string sql = null;
|
|
StringBuilder sb = new StringBuilder();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
SIProblemType r = new SIProblemType();
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//获取角色信息
|
|
sb.Append(" SELECT PID,PTYPENAME,SDEPT,SUSER,REMARK,ZPTYPE.CREATEDATE,ZPTYPE.UPDATEDATE,QMUSER.USERNAME AS SUserName, ");
|
|
sb.Append(" ZPTYPE.CREATEUSER,ZPTYPE.UPDATEUSER,ORGA.ORGADESC AS SOrgaDesc");
|
|
sb.Append(" FROM T_QM_ZPTYPE ZPTYPE LEFT JOIN T_QM_USER QMUSER ON ZPTYPE.SUSER = QMUSER.USERID ");
|
|
sb.Append(" LEFT JOIN T_QM_ORGANIZATION ORGA ON ZPTYPE.SDEPT = ORGA.ORGAID WHERE ZPTYPE.PID=@PIDT ");
|
|
parameters.Add(new DataParameter { ParameterName = "PIDT", DataType = DbType.String, Value = model.PID });
|
|
sql = this.ChangeSqlByDB(sb.ToString(), session);
|
|
r = session.Get<SIProblemType>(sql, parameters.ToArray());
|
|
}
|
|
return r;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 获取列表
|
|
/// <summary>
|
|
/// 获取列表
|
|
/// </summary>
|
|
/// <param name="condition">条件</param>
|
|
/// <param name="page">数据页</param>
|
|
/// <returns>数据页</returns>
|
|
public DataPage GetList(SIProblemType 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())
|
|
{
|
|
sql = this.ChangeSqlByDB(sql, session);
|
|
page = session.GetDataPage<SIProblemType>(sql, parameters.ToArray(), page);
|
|
}
|
|
return page;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 判断类型名称是否已经存在
|
|
/// <summary>
|
|
/// 判断类型名称是否已经存在
|
|
/// </summary>
|
|
/// <returns>验证结果</returns>
|
|
public bool CheckProblemTypeNameExist(SIProblemType condition)
|
|
{
|
|
string sql = null;
|
|
StringBuilder sb = new StringBuilder();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sb.Append(" SELECT COUNT(*) FROM T_QM_ZPTYPE WHERE FLGDEL = 0 AND PTYPENAME = @PTYPENAME ");
|
|
|
|
parameters.Add(new DataParameter { ParameterName = "PTYPENAME", DataType = DbType.String, Value = condition.PTypeName });
|
|
|
|
if (!string.IsNullOrEmpty(condition.PID))
|
|
{
|
|
sb.Append(" AND PID <> @PID ");
|
|
parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = condition.PID });
|
|
}
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
sql = this.ChangeSqlByDB(sb.ToString(), session);
|
|
return Convert.ToInt32(session.ExecuteSqlScalar(sql, parameters.ToArray())) > 0;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 获取查询语句
|
|
/// <summary>
|
|
/// 获取查询语句
|
|
/// </summary>
|
|
/// <param name="user">查询条件</param>
|
|
/// <param name="parameters">参数</param>
|
|
/// <returns>查询语句</returns>
|
|
private string GetQuerySql(SIProblemType condition, ref List<DataParameter> parameters)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
try
|
|
{
|
|
//构成查询语句
|
|
sqlBuilder.Append(" SELECT PID,PTYPENAME,SDEPT,SUSER,REMARK,ZPTYPE.CREATEDATE,ZPTYPE.UPDATEDATE,QMUSER.USERNAME AS SUserName, ");
|
|
sqlBuilder.Append(" ORGA.ORGADESC AS SOrgaDesc, ");
|
|
sqlBuilder.Append(" (SELECT USERNAME FROM T_QM_USER CUSER WHERE CUSER.USERID = ZPTYPE.CREATEUSER) AS CREATEUSER, ");
|
|
sqlBuilder.Append(" (SELECT USERNAME FROM T_QM_USER CUSER WHERE CUSER.USERID = ZPTYPE.UPDATEUSER) AS UPDATEUSER ");
|
|
sqlBuilder.Append(" FROM T_QM_ZPTYPE ZPTYPE LEFT OUTER JOIN T_QM_USER QMUSER ON ZPTYPE.SUSER = QMUSER.USERID ");
|
|
sqlBuilder.Append(" LEFT JOIN T_QM_ORGANIZATION ORGA ON ZPTYPE.SDEPT = ORGA.ORGAID ");
|
|
sqlBuilder.Append(" WHERE ZPTYPE.FLGDEL = '0' ");
|
|
|
|
if (!string.IsNullOrEmpty(condition.PTypeName))
|
|
{
|
|
sqlBuilder.Append(" AND PTYPENAME LIKE '%" + condition.PTypeName + "%' ");
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(condition.SDept))
|
|
{
|
|
sqlBuilder.Append(" AND SDEPT = @SDEPT ");
|
|
parameters.Add(new DataParameter { ParameterName = "SDEPT", DataType = DbType.String, Value = condition.SDept });
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(condition.SUser))
|
|
{
|
|
sqlBuilder.Append(" AND QMUSER.USERID = @SUSER ");
|
|
parameters.Add(new DataParameter { ParameterName = "SUSER", DataType = DbType.String, Value = condition.SUser });
|
|
}
|
|
|
|
return sqlBuilder.ToString();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 插入信息
|
|
|
|
/// <summary>
|
|
/// 插入信息(单表)
|
|
/// </summary>
|
|
/// <param name="">信息</param>
|
|
/// <returns>插入行数</returns>
|
|
public int Insert(SIProblemType model)
|
|
{
|
|
int count = 0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//插入基本信息
|
|
count = session.Insert<SIProblemType>(model);
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 更新信息
|
|
/// <summary>
|
|
/// 更新信息
|
|
/// </summary>
|
|
/// <param name=""></param>
|
|
/// <returns>更新行数</returns>
|
|
public int Update(SIProblemType model)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
int count = 0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
string sql = " UPDATE T_QM_ZPTYPE SET PTYPENAME=@PTYPENAME,SUSER=@SUSER,REMARK=@REMARK,SDEPT=@SDEPT,UPDATEUSER=@UPDATEUSER,UPDATEDATE=@UPDATEDATE WHERE PID=@PID ";
|
|
|
|
string updateUser = "";
|
|
string updateRemark = "";
|
|
//处理人不为空时
|
|
if (!string.IsNullOrEmpty(model.SUser))
|
|
{
|
|
updateUser = model.SUser;
|
|
}
|
|
//备注不为空时
|
|
if (!string.IsNullOrEmpty(model.Remark))
|
|
{
|
|
updateRemark = model.Remark;
|
|
}
|
|
parameters.Add(new DataParameter { ParameterName = "SUSER", DataType = DbType.String, Value = updateUser });
|
|
parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = model.PID });
|
|
parameters.Add(new DataParameter { ParameterName = "PTYPENAME", DataType = DbType.String, Value = model.PTypeName });
|
|
parameters.Add(new DataParameter { ParameterName = "SDEPT", DataType = DbType.String, Value = model.SDept });
|
|
parameters.Add(new DataParameter { ParameterName = "REMARK", DataType = DbType.String, Value = updateRemark });
|
|
parameters.Add(new DataParameter { ParameterName = "UPDATEUSER", DataType = DbType.String, Value = model.UpdateUser});
|
|
parameters.Add(new DataParameter { ParameterName = "UPDATEDATE", DataType = DbType.DateTime, Value = model.UpdateDate });
|
|
//更新基本信息
|
|
sql = this.ChangeSqlByDB(sql, session);
|
|
count = session.ExecuteSql(sql, parameters.ToArray());
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 逻辑删除
|
|
/// <summary>
|
|
/// 逻辑删除信息
|
|
/// </summary>
|
|
/// <param name=""></param>
|
|
/// <returns>删除个数</returns>
|
|
public int Delete(SIProblemType model)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
int count = 0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//删除基本信息
|
|
string sql = " UPDATE T_QM_ZPTYPE SET FLGDEL=@FLGDEL WHERE PID=@PID ";
|
|
parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = model.PID });
|
|
parameters.Add(new DataParameter { ParameterName = "FLGDEL", DataType = DbType.String, Value = model.FlgDel });
|
|
//更新基本信息
|
|
sql = this.ChangeSqlByDB(sql, session);
|
|
count = session.ExecuteSql(sql, parameters.ToArray());
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 获取导出的数据
|
|
/// <summary>
|
|
/// 获取导出的数据
|
|
/// </summary>
|
|
/// <param name="user">查询条件</param>
|
|
/// <returns>数据</returns>
|
|
public DataTable GetExportData(SIProblemType entity)
|
|
{
|
|
DataTable dt = null;
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
|
|
try
|
|
{
|
|
dt = new DataTable();
|
|
|
|
sql = this.GetExportSql(entity, ref parameters);
|
|
sql += " ORDER BY UPDATEDATE DESC";
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
dt = session.GetTable(sql, parameters.ToArray());
|
|
}
|
|
return dt;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region 获取导出查询语句
|
|
|
|
/// <summary>
|
|
/// 获取导出查询语句
|
|
/// </summary>
|
|
/// <param name="user">查询条件</param>
|
|
/// <param name="parameters">参数</param>
|
|
/// <returns>查询语句</returns>
|
|
private string GetExportSql(SIProblemType condition, ref List<DataParameter> parameters)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
|
|
try
|
|
{
|
|
sqlBuilder.Append(" SELECT PID,PTYPENAME,REMARK,ZPTYPE.CREATEDATE,ZPTYPE.UPDATEDATE,QMUSER.USERNAME AS SUserName,ORGA.ORGADESC AS SOrgaDesc, ");
|
|
sqlBuilder.Append(" (SELECT USERNAME FROM T_QM_USER CUSER WHERE CUSER.USERID = ZPTYPE.CREATEUSER) AS CREATEUSER, ");
|
|
sqlBuilder.Append(" (SELECT USERNAME FROM T_QM_USER CUSER WHERE CUSER.USERID = ZPTYPE.UPDATEUSER) AS UPDATEUSER ");
|
|
sqlBuilder.Append(" FROM T_QM_ZPTYPE ZPTYPE LEFT OUTER JOIN T_QM_USER QMUSER ON ZPTYPE.SUSER = QMUSER.USERID ");
|
|
sqlBuilder.Append(" LEFT JOIN T_QM_ORGANIZATION ORGA ON ZPTYPE.SDEPT = ORGA.ORGAID ");
|
|
sqlBuilder.Append(" WHERE ZPTYPE.FLGDEL = '0' ");
|
|
|
|
if (!string.IsNullOrEmpty(condition.PTypeName))
|
|
{
|
|
sqlBuilder.Append(" AND PTYPENAME LIKE '%" + condition.PTypeName + "%' ");
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(condition.SDept))
|
|
{
|
|
sqlBuilder.Append(" AND SDEPT = @SDEPT ");
|
|
parameters.Add(new DataParameter { ParameterName = "SDEPT", DataType = DbType.String, Value = condition.SDept });
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(condition.SUser))
|
|
{
|
|
sqlBuilder.Append(" AND SUSER = @SUSER ");
|
|
parameters.Add(new DataParameter { ParameterName = "SUSER", DataType = DbType.String, Value = condition.SUser });
|
|
}
|
|
|
|
return sqlBuilder.ToString();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
}
|
|
|