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 获取信息
///
/// 获取信息
///
/// 条件
/// *信息
public FileType Get(FileType model)
{
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//获取信息
model = session.Get(model);
}
return model;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取列表
///
/// 获取列表
///
/// 条件
/// 数据页
/// 数据页
public DataPage GetList(FileType condition, DataPage page)
{
string sql = null;
List parameters = new List();
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(sql, parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取查询语句
///
/// 获取查询语句
///
/// 查询条件
/// 参数
/// 查询语句
private string GetQuerySql(FileType condition, ref List 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 获取导出的数据
///
/// 获取导出的数据
///
/// 查询条件
/// 数据
public DataTable GetExportData(FileType model)
{
DataTable dt = null;
string sql = null;
List parameters = new List();
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 插入信息
///
/// 插入信息(单表)
///
/// 信息
/// 插入行数
public int Insert(FileType model)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//插入基本信息
count = session.Insert(model);
}
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 判断文件分类是否存在
///
/// 判断文件分类是否存在
///
/// 信息
/// true@已存在;fasel@不存在。
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 更新信息
///
/// 更新信息
///
///
/// 更新行数
public int Update(FileType model)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//更新基本信息
count = session.Update(model);
}
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 删除文件类型
///
/// 删除
///
///
/// 删除个数
public int Delete(FileType model)
{
StringBuilder sqlBuilder = new StringBuilder();
List parameters = new List();
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 获取文件类型树菜单列表
///
/// 获取文件类型树菜单列表
///
/// 条件
/// 同级别菜单列表
public List GetAllList()
{
List parameters = new List();
List 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(sqlBuilder.ToString(), parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
throw;
}
}
#endregion
#region 获取文件类型下拉列表
///
/// 获取文件类型下拉列表
///
/// 查询条件
/// 获取零件拉列表
public List GetCombox()
{
string sql = null;
List parameters = null;
List list = null;
DataQueryHelper queryHelper = new DataQueryHelper();
try
{
sql = "SELECT " + queryHelper.GetSelectColumns() + " FROM T_QM_FILETYPE";
parameters = new List();
using (IDataSession session = AppDataFactory.CreateMainSession())
{
list = session.GetList(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
}
}