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

347 lines
12 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMAPP.Entity.Sys;
using QMFrameWork.Data;
using System.Data;
namespace QMAPP.DAL.Sys
{
/// <summary>
/// 文件管理数据层
/// 创建者:王丹丹
/// 创建时间:2015-03-17
/// </summary>
public class FileInfoDAL : BaseDAL
{
#region 获取信息
/// <summary>
/// 获取信息
/// </summary>
/// <param name="">条件</param>
/// <returns>*信息</returns>
public FileInfo Get(FileInfo model)
{
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//获取信息
model = session.Get<FileInfo>(model);
}
return model;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取信息
/// <summary>
/// 获取信息
/// </summary>
/// <param name="">条件</param>
/// <returns>*信息</returns>
public IList<FileInfo> GetList(FileType model)
{
IList<FileInfo> list = new List<FileInfo>();
StringBuilder sqlBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//删除基本信息
sqlBuilder.Append(" SELECT FI.PID,FI.FILENAME,FI.FILESTORAGENAME,FI.REMARK, ");
sqlBuilder.Append(" FI.TYPENO,FI.CREATEUSER,FI.CREATEDATE FROM T_QM_FILEINFO FI ");
sqlBuilder.Append(" LEFT JOIN T_QM_FILETYPE FT ON FT.TYPENO=FI.TYPENO ");
sqlBuilder.Append(" WHERE FT.TYPENO=@TYPENO");
parameters.Add(new DataParameter { ParameterName = "TYPENO", DataType = DbType.String, Value = model.TYPENO });
string sql = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
list = session.GetList<FileInfo>(sql, parameters.ToArray());
}
return list;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取列表
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataPage GetList(FileInfo 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 = "CREATEDATE DESC";
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
sql = this.ChangeSqlByDB(sql, session);
page = session.GetDataPage<FileInfo>(sql, parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取查询语句
/// <summary>
/// 获取查询语句
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
private string GetQuerySql(FileInfo condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.Append(" SELECT F.PID,F.FILENAME,F.FILESTORAGENAME,F.REMARK,F.TYPENO,F.CREATEUSER, ");
sqlBuilder.Append(" F.CREATEDATE AS CREATEDATE,C.USERNAME AS CREATEUSERNAME,FT.TYPENAME");
sqlBuilder.Append(" FROM T_QM_FILEINFO F ");
sqlBuilder.Append(" LEFT JOIN T_QM_USER C ON C.USERID=F.CREATEUSER ");
sqlBuilder.Append(" LEFT JOIN T_QM_FILETYPE FT ON FT.TYPENO=F.TYPENO ");
//查询条件
//文件名
if (string.IsNullOrEmpty(condition.FILENAMETXT) == false)
{
whereBuilder.Append(" AND F.FILENAME LIKE @FILENAMETXT");
parameters.Add(new DataParameter { ParameterName = "FILENAMETXT", DataType = DbType.String, Value = "%" + condition.FILENAMETXT + "%" });
}
//文件类型
if (string.IsNullOrEmpty(condition.TYPENO) == false)
{
whereBuilder.Append(" AND F.TYPENO =@TYPENO");
parameters.Add(new DataParameter { ParameterName = "TYPENO", DataType = DbType.String, Value = condition.TYPENO });
}
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 ExistsFileInfo(FileInfo model)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
int count = 0;
try
{
sqlBuilder.Append("SELECT COUNT(PID) FROM T_QM_FILEINFO");
if (string.IsNullOrEmpty(model.PID) == false)
{
whereBuilder.Append(" AND PID =@PID ");
parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = model.PID });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
string sql = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
count = Convert.ToInt32(session.ExecuteSqlScalar(sql, parameters.ToArray()));
}
if (count > 0)
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 插入信息
/// <summary>
/// 插入信息(单表)
/// </summary>
/// <param name="">信息</param>
/// <returns>插入行数</returns>
public int Insert(FileInfo model)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//插入基本信息
count = session.Insert<FileInfo>(model);
}
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 更新信息
/// <summary>
/// 更新信息
/// </summary>
/// <param name=""></param>
/// <returns>更新行数</returns>
public int Update(FileInfo model)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//更新基本信息
count = session.Update<FileInfo>(model);
}
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 删除文件
/// <summary>
/// 删除文件
/// </summary>
/// <param name=""></param>
/// <returns>删除个数</returns>
public int Delete(FileInfo model)
{
StringBuilder sqlBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//删除基本信息
sqlBuilder.Append("DELETE FROM T_QM_FILEINFO ");
sqlBuilder.Append("WHERE PID = @PID ");
parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = model.PID });
string sql = this.ChangeSqlByDB(sqlBuilder.ToString(), 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 DeleteByTypeNo(FileInfo model)
{
StringBuilder sqlBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//删除基本信息
sqlBuilder.Append("DELETE FROM T_QM_FILEINFO ");
sqlBuilder.Append("WHERE TYPENO = @TYPENO ");
parameters.Add(new DataParameter { ParameterName = "TYPENO", DataType = DbType.String, Value = model.TYPENO });
string sql = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
count = session.ExecuteSql(sql, parameters.ToArray());
}
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取导出文件信息
/// <summary>
/// 获取导出文件信息
/// </summary>
/// <param name="model">查询条件</param>
/// <returns>数据</returns>
public DataTable GetExportData(FileInfo model)
{
DataTable dt = null;
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
//构成查询语句
sql = GetQuerySql(model, ref parameters);
sql += " ORDER BY CREATEDATE DESC";
using (IDataSession session = AppDataFactory.CreateMainSession())
{
sql = this.ChangeSqlByDB(sql, session);
dt = session.GetTable(sql, parameters.ToArray());
}
dt.TableName = "FileInfo";
return dt;
}
catch (Exception ex)
{
throw;
}
}
#endregion
}
}