using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using QMAPP.FJC.Entity.FeedInManage;
using QMAPP.FJC.Entity.FileCopy;
using QMFrameWork.Data;
using QMFrameWork.Log;
using System.Data.SqlClient;
namespace QMAPP.FJC.DAL.FileCopy
{
///
/// 模块编号:
/// 作 用:
/// 作 者:王庆男
/// 编写日期:2015年09月08日
///
public class FileCopyRecordDAL
{
#region 获取信息
///
/// 获取信息
///
/// 条件
/// *信息
public FileCopyRecord Get(FileCopyRecord model)
{
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//获取信息
model = session.Get(model);
}
return model;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取列表
///
/// 获取列表
///
/// 条件
/// 数据页
/// 数据页
public DataPage GetList(FileCopyRecord condition, DataPage page)
{
string sql = null;
List parameters = new List();
try
{
sql = this.GetQuerySql(condition, ref parameters);
//分页关键字段及排序
page.KeyName = "RECORD_KEY";
page.SortExpression = "RECORD_COPY_DATETIME DESC";
using (IDataSession session = AppDataFactory.CreateMainSession())
{
page = session.GetDataPage(sql, parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 获取列表
///
/// 条件
/// 数据页
/// 数据页
public List GetList(FileCopyRecord condition)
{
string sql = null;
List parameters = new List();
List list = new List();
try
{
sql = this.GetQuerySql(condition, ref parameters);
//分页关键字段及排序
using (IDataSession session = AppDataFactory.CreateMainSession())
{
list = session.GetList(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取查询语句
///
/// 获取查询语句
///
/// 查询条件
/// 参数
/// 查询语句
private string GetQuerySql(FileCopyRecord condition, ref List parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.Append("SELECT RECORD_KEY,EQUIPMENT_INFO_KEY,RECORD_EQUIPMENT_CODE,RECORD_EQUIPMENT_TYPE_CODE,RECORD_EQUIPMENT_DIRECTORY,RECORD_FILENAME,RECORD_COPY_DATETIME,RECORD_READFLAG,RECORD_KEYWORDS,FILE_LASTWRITETIME,FILE_EXPLANTTIME,FILE_HOSTNAME ");
sqlBuilder.Append("FROM T_AW_FILE_COPY_RECORD ");
//查询条件RECORD_KEYWORDS
if (string.IsNullOrEmpty(condition.RECORD_KEYWORDS) == false)
{
whereBuilder.Append(" AND RECORD_KEYWORDS = @RECORD_KEYWORDS");
parameters.Add(new DataParameter { ParameterName = "RECORD_KEYWORDS", DataType = DbType.String, Value = condition.RECORD_KEYWORDS });
}
if (string.IsNullOrEmpty(condition.RECORD_FILENAME) == false)
{
whereBuilder.Append(" AND RECORD_FILENAME = @RECORD_FILENAME");
parameters.Add(new DataParameter { ParameterName = "RECORD_FILENAME", DataType = DbType.String, Value = condition.RECORD_FILENAME });
}
if (string.IsNullOrEmpty(condition.EQUIPMENT_INFO_KEY) == false)
{
whereBuilder.Append(" AND EQUIPMENT_INFO_KEY = @EQUIPMENT_INFO_KEY");
parameters.Add(new DataParameter { ParameterName = "EQUIPMENT_INFO_KEY", DataType = DbType.String, Value = condition.EQUIPMENT_INFO_KEY });
}
if (string.IsNullOrEmpty(condition.FILE_HOSTNAME) == false)
{
whereBuilder.Append(" AND FILE_HOSTNAME = @FILE_HOSTNAME");
parameters.Add(new DataParameter { ParameterName = "FILE_HOSTNAME", DataType = DbType.String, Value = condition.FILE_HOSTNAME });
}
if (condition.IsOperation)
{
whereBuilder.Append(" AND (FILE_EXPLANTTIME IS NULL OR FILE_EXPLANTTIME 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 信息是否重复
///
/// 判断名称是否存在
///
///
/// true:已存在;fasel:不存在。
public bool ExistsT_AW_FILE_COPY_RECORD(FileCopyRecord model)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
List parameters = new List();
int count = 0;
try
{
sqlBuilder.Append("SELECT COUNT(RECORD_KEY) FROM T_AW_FILE_COPY_RECORD");
if (string.IsNullOrEmpty(model.RECORD_KEY) == false)
{
whereBuilder.Append(" AND RECORD_KEY =@RECORD_KEY ");
parameters.Add(new DataParameter { ParameterName = "RECORD_KEY", DataType = DbType.String, Value = model.RECORD_KEY });
}
//if (string.IsNullOrEmpty(model.) == false)
//{
//whereBuilder.Append(" AND AREACODE=@AREACODE");
//parameters.Add(new DataParameter { ParameterName = "AREACODE", DataType = DbType.String, Value = ""model.AREACODE + "" });
//}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
count = Convert.ToInt32(session.ExecuteSqlScalar(sqlBuilder.ToString(), parameters.ToArray()));
}
if (count > 0)
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 插入信息
///
/// 插入信息(单表)
///
/// 信息
/// 插入行数
public int Insert(FileCopyRecord model)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//插入基本信息
count = session.Insert(model);
}
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 更新信息
///
/// 更新信息
///
///
/// 更新行数
public int Update(FileCopyRecord model)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//更新基本信息
count = session.Update(model);
}
return count;
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 更新信息
///
///
/// 更新行数
public int Update(string EQUIPMENT_INFO_KEY, string RECORD_FILENAME, string FILE_HOSTNAME, string FILE_EXPLANTTIME)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
string strsql = string.Format(@" update T_AW_FILE_COPY_RECORD set FILE_EXPLANTTIME='{0}'
where EQUIPMENT_INFO_KEY ='{1}' and RECORD_FILENAME='{2}' AND FILE_HOSTNAME='{3}'", FILE_EXPLANTTIME, EQUIPMENT_INFO_KEY, RECORD_FILENAME, FILE_HOSTNAME);
//更新基本信息
count = session.ExecuteSql(strsql);
}
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
///
/// 获取条码
///
///
/// 获取条码
public string GetBarcode(string tempbarcode)
{
object result = null;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
DataParameter[] CmdParms = { new DataParameter { ParameterName = "@PR", Value = 43 }
, new DataParameter { ParameterName = "@X1", Value = tempbarcode }};
result = session.ExecuteSqlScalar("PROC_CHARNUMBER", CommandType.StoredProcedure, CmdParms);
}
return result == null ? "" : result
.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
#region 逻辑删除
///
/// 逻辑删除信息
///
///
/// 删除个数
public int Delete(FileCopyRecord model)
{
StringBuilder sqlBuilder = new StringBuilder();
List parameters = new List();
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//删除基本信息
sqlBuilder.Append("UPDATE T_AW_FILE_COPY_RECORD ");
sqlBuilder.Append("SET FLGDEL = '1' ");
sqlBuilder.Append("WHERE RECORD_KEY = @RECORD_KEY ");
parameters.Add(new DataParameter { ParameterName = "RECORD_KEY", DataType = DbType.String, Value = model.RECORD_KEY });
count = session.ExecuteSql(sqlBuilder.ToString(), parameters.ToArray());
}
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
public FileCopyRecord GetLastRecord(string equipmentCode)
{
string sql = null;
List parameters = new List();
List list = new List();
try
{
sql = "SELECT TOP 1 * FROM T_AW_FILE_COPY_RECORD WHERE RECORD_EQUIPMENT_CODE=@equipmentcode ORDER BY RECORD_COPY_DATETIME DESC";
parameters.Add(new DataParameter("equipmentcode", equipmentCode));
//分页关键字段及排序
using (IDataSession session = AppDataFactory.CreateMainSession())
{
return session.Get(sql, parameters.ToArray());
}
}
catch (Exception ex)
{
throw ex;
}
}
}
}