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

323 lines
10 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
{
public class FileTypeDAL : BaseDAL
{
#region 获取信息
/// <summary>
/// 获取信息
/// </summary>
/// <param name="">条件</param>
/// <returns>*信息</returns>
public FileType Get(FileType model)
{
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//获取信息
model = session.Get<FileType>(model);
}
return model;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取列表
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataPage GetList(FileType condition, DataPage page)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetQuerySql(condition, ref parameters);
//分页关键字段及排序
page.KeyName = "TYPENO";
if (string.IsNullOrEmpty(page.SortExpression))
{
page.SortExpression = "UPDATETIME DESC";
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
sql = this.ChangeSqlByDB(sql, session);
page = session.GetDataPage<FileType>(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(FileType condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.Append("SELECT TYPENO,TYPENAME,PARENTTYPENO,CREATEUSER,CREATEDATE,UPDATEUSER,UPDATEDATE ");
sqlBuilder.Append("FROM T_QM_FILETYPE ");
whereBuilder.Append(" AND FLGDEL<>1");
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="user">查询条件</param>
/// <returns>数据</returns>
public DataTable GetExportData(FileType model)
{
DataTable dt = null;
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
//构成查询语句
sql = this.GetQuerySql(model, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
sql = this.ChangeSqlByDB(sql, session);
dt = session.GetTable(sql, parameters.ToArray());
dt.TableName = "FileType";
}
return dt;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 插入信息
/// <summary>
/// 插入信息(单表)
/// </summary>
/// <param name="">信息</param>
/// <returns>插入行数</returns>
public int Insert(FileType model)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//插入基本信息
count = session.Insert<FileType>(model);
}
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 判断文件分类是否存在
/// <summary>
/// 判断文件分类是否存在
/// </summary>
/// <param name="model">信息</param>
/// <returns>true@已存在;fasel@不存在。</returns>
public bool ExistsFileType(FileType model)
{
string typeNo = "";
int count = 0;
string sql = null;
try
{
if (string.IsNullOrEmpty(model.TYPENO) == false)
{
typeNo = model.TYPENO;
}
sql = "SELECT COUNT(*) FROM T_QM_FILETYPE WHERE TYPENO <> @TYPENO AND TYPENAME=@TYPENAME";
using (IDataSession session = AppDataFactory.CreateMainSession())
{
sql = this.ChangeSqlByDB(sql, session);
count = Convert.ToInt32(session.ExecuteSqlScalar(sql, new DataParameter("TYPENO", typeNo), new DataParameter { ParameterName = "TYPENAME", Value = model.TYPENAME }));
}
if (count > 0)
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
throw;
}
}
#endregion
#region 更新信息
/// <summary>
/// 更新信息
/// </summary>
/// <param name=""></param>
/// <returns>更新行数</returns>
public int Update(FileType model)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//更新基本信息
count = session.Update<FileType>(model);
}
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 删除文件类型
/// <summary>
/// 删除
/// </summary>
/// <param name=""></param>
/// <returns>删除个数</returns>
public int Delete(FileType 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_FILETYPE ");
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="condition">条件</param>
/// <returns>同级别菜单列表</returns>
public List<FileType> GetAllList()
{
List<DataParameter> parameters = new List<DataParameter>();
List<FileType> list = null;
StringBuilder sqlBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.Append("SELECT TYPENO,TYPENAME,PARENTTYPENO,CREATEUSER,CREATEDATE,UPDATEUSER,UPDATEDATE ");
sqlBuilder.Append("FROM T_QM_FILETYPE ");
using (IDataSession session = AppDataFactory.CreateMainSession())
{
list = session.GetList<FileType>(sqlBuilder.ToString(), parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
throw;
}
}
#endregion
#region 获取文件类型下拉列表
/// <summary>
/// 获取文件类型下拉列表
/// </summary>
/// <param name="model">查询条件</param>
/// <returns>获取零件拉列表</returns>
public List<FileType> GetCombox()
{
string sql = null;
List<DataParameter> parameters = null;
List<FileType> list = null;
DataQueryHelper queryHelper = new DataQueryHelper();
try
{
sql = "SELECT " + queryHelper.GetSelectColumns<FileType>() + " FROM T_QM_FILETYPE";
parameters = new List<DataParameter>();
using (IDataSession session = AppDataFactory.CreateMainSession())
{
list = session.GetList<FileType>(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
}
}