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

373 lines
13 KiB

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
{
/// <summary>
/// 模块编号:
/// 作 用:
/// 作 者:王庆男
/// 编写日期:2015年09月08日
///</summary>
public class FileCopyRecordDAL
{
#region 获取信息
/// <summary>
/// 获取信息
/// </summary>
/// <param name="">条件</param>
/// <returns>*信息</returns>
public FileCopyRecord Get(FileCopyRecord model)
{
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//获取信息
model = session.Get<FileCopyRecord>(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(FileCopyRecord condition, DataPage page)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
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<FileCopyRecord>(sql, parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public List<FileCopyRecord> GetList(FileCopyRecord condition)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
List<FileCopyRecord> list = new List<FileCopyRecord>();
try
{
sql = this.GetQuerySql(condition, ref parameters);
//分页关键字段及排序
using (IDataSession session = AppDataFactory.CreateMainSession())
{
list = session.GetList<FileCopyRecord>(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取查询语句
/// <summary>
/// 获取查询语句
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
private string GetQuerySql(FileCopyRecord condition, ref List<DataParameter> 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<RECORD_COPY_DATETIME)");
}
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 ExistsT_AW_FILE_COPY_RECORD(FileCopyRecord model)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
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 插入信息
/// <summary>
/// 插入信息(单表)
/// </summary>
/// <param name="">信息</param>
/// <returns>插入行数</returns>
public int Insert(FileCopyRecord model)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//插入基本信息
count = session.Insert<FileCopyRecord>(model);
}
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 更新信息
/// <summary>
/// 更新信息
/// </summary>
/// <param name=""></param>
/// <returns>更新行数</returns>
public int Update(FileCopyRecord model)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//更新基本信息
count = session.Update<FileCopyRecord>(model);
}
return count;
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 更新信息
/// </summary>
/// <param name=""></param>
/// <returns>更新行数</returns>
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
/// <summary>
/// 获取条码
/// </summary>
/// <param name=""></param>
/// <returns>获取条码</returns>
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 逻辑删除
/// <summary>
/// 逻辑删除信息
/// </summary>
/// <param name=""></param>
/// <returns>删除个数</returns>
public int Delete(FileCopyRecord model)
{
StringBuilder sqlBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
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<DataParameter> parameters = new List<DataParameter>();
List<FileCopyRecord> list = new List<FileCopyRecord>();
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<FileCopyRecord>(sql, parameters.ToArray());
}
}
catch (Exception ex)
{
throw ex;
}
}
}
}