using HanHe.Utility.Data;
|
using HH.WMS.Common.MagicModel;
|
using HH.WMS.Entitys.Common;
|
using System;
|
using System.Collections.Generic;
|
using System.Data;
|
using System.Data.Common;
|
using System.Data.OracleClient;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace HH.WMS.DAL.Common
|
{
|
/// <summary>
|
/// 通用数据处理类
|
/// </summary>
|
/// <history>[HanHe(HHC)] CREATED 2017/9/27</history>
|
public class GeneralDAL : BaseDAL
|
{
|
#region 获取版本清单
|
/// <summary>
|
/// 根据条件,获取版本信息
|
/// </summary>
|
/// <param name="queryEntity">条件</param>
|
/// <returns>返回满足条件的历次版本信息</returns>
|
/// <history>[HanHe(HHC)] CREATED 2017/9/27</history>
|
public List<VersionEntity> GetVersions(MagicQueryEntity queryEntity)
|
{
|
// 组织sql
|
string where, orderBy,tbName;
|
string sql = MagicDataAccess.GetMagic_Page_Model(queryEntity, out where, out orderBy, out tbName);
|
|
// 执行查询
|
DbCommand cmd = DataAccess.GetSqlStringCommand(sql);
|
return DataAccessExtensive.ExecuteListEntity<VersionEntity>(this.DataAccess, cmd, SetVersionEntity);
|
}
|
|
/// <summary>
|
/// 设置版本的实体
|
/// </summary>
|
/// <param name="entity">版本实体</param>
|
/// <param name="reader">数据集</param>
|
/// <history>[HanHe(HHC)] CREATED 2017/9/27</history>
|
private void SetVersionEntity(VersionEntity entity, IDataReader reader)
|
{
|
SetEntityUti(entity, "Code", "Code", reader);
|
SetEntityUti(entity, "Status", "Status", reader);
|
}
|
#endregion
|
|
#region 获取对象列表
|
/// <summary>
|
/// 根据条件,获取列表信息
|
/// </summary>
|
/// <param name="queryEntity">条件</param>
|
/// <returns>返回满足条件的对象清单</returns>
|
/// <history>[HanHe(HHC)] CREATED 2017/9/27</history>
|
public DataTable GetList(MagicQueryEntity queryEntity)
|
{
|
// 组织sql
|
string where, orderBy,tbName;
|
string sql = MagicDataAccess.GetMagic_Page_Model(queryEntity, out where, out orderBy, out tbName);
|
|
DbCommand cmd;
|
// 不分页
|
if (!queryEntity.isPageing)
|
cmd = DataAccess.GetSqlStringCommand(sql);
|
else
|
{
|
// 分页
|
cmd = DataAccess.GetStoredProcCommand("prc_query");
|
this.DataAccess.AddInParameter(cmd, "TableName", ComDbType.CHAR, sql);
|
this.DataAccess.AddInParameter(cmd, "WhereStr", ComDbType.CHAR, where);
|
this.DataAccess.AddInParameter(cmd, "OrderByStr", ComDbType.CHAR, orderBy);
|
this.DataAccess.AddInParameter(cmd, "PageSize", ComDbType.INT, queryEntity.pageSize);
|
this.DataAccess.AddInParameter(cmd, "PageIndex", ComDbType.INT, queryEntity.pageIndex);
|
this.DataAccess.AddOutParameter(cmd, "TotalPage", ComDbType.INT, 4);
|
this.DataAccess.AddOutParameter(cmd, "TotalRecord", ComDbType.INT, 4);
|
|
//如果是oracle 增加特性
|
if (!string.IsNullOrEmpty(Now_dbType) && Now_dbType.Equals("ORACLE"))
|
{
|
//处理游标类型 因DbType无游标类型,游标类型单独处理
|
ComDbType.AddOrcOutParameter(cmd, "v_cur", OracleType.Cursor);
|
}
|
}
|
// 执行查询
|
return DataAccessExtensive.ExecuteDataTable(this.DataAccess, cmd, null);
|
}
|
#endregion
|
|
#region 获取对象实体
|
/// <summary>
|
/// 根据条件,获取对象实体
|
/// </summary>
|
/// <param name="queryEntity">条件</param>
|
/// <returns>返回满足条件的对象实体</returns>
|
/// <history>[HanHe(HHC)] CREATED 2017/9/27</history>
|
public DataTable GetEntity(MagicQueryEntity queryEntity)
|
{
|
// 组织sql
|
string where, orderBy, tbName;
|
string sql = MagicDataAccess.GetMagic_Page_Model(queryEntity, out where, out orderBy, out tbName);
|
|
// 执行查询
|
DbCommand cmd = DataAccess.GetSqlStringCommand(sql);
|
return DataAccessExtensive.ExecuteDataTable(this.DataAccess, cmd, null);
|
}
|
#endregion
|
|
#region 判断记录是否存在
|
/// <summary>
|
/// 判断记录是否存在
|
/// </summary>
|
/// <param name="queryEntity">条件</param>
|
/// <returns>true:存在 false:不存在</returns>
|
/// <history>[HanHe(HHC)] CREATED 2017/9/27</history>
|
public bool CheckExists(MagicQueryEntity queryEntity)
|
{
|
// 组织sql
|
string where, orderBy, tbName;
|
string sql = MagicDataAccess.GetMagic_Page_Model(queryEntity, out where, out orderBy, out tbName);
|
|
// 执行查询
|
DbCommand cmd = DataAccess.GetSqlStringCommand(sql);
|
object obj = DataAccess.ExecuteScalar(cmd);
|
return obj != null;
|
}
|
#endregion
|
|
#region 判断数据是否存在(简便)
|
/// <summary>
|
/// 判断数据是否存在
|
/// </summary>
|
/// <param name="tableName"></param>
|
/// <param name="columnName"></param>
|
/// <param name="value"></param>
|
/// <returns></returns>
|
public bool Exists(string tableName, string columnName, string value)
|
{
|
string strSql = "SELECT " + columnName + " FROM " + tableName + " where " + columnName + " ='" + value + "'";
|
// 执行查询
|
DbCommand cmd = DataAccess.GetSqlStringCommand(strSql);
|
object obj = DataAccess.ExecuteScalar(cmd);
|
return obj != null;
|
}
|
#endregion
|
}
|
}
|