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 { /// /// 通用数据处理类 /// /// [HanHe(HHC)] CREATED 2017/9/27 public class GeneralDAL : BaseDAL { #region 获取版本清单 /// /// 根据条件,获取版本信息 /// /// 条件 /// 返回满足条件的历次版本信息 /// [HanHe(HHC)] CREATED 2017/9/27 public List 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(this.DataAccess, cmd, SetVersionEntity); } /// /// 设置版本的实体 /// /// 版本实体 /// 数据集 /// [HanHe(HHC)] CREATED 2017/9/27 private void SetVersionEntity(VersionEntity entity, IDataReader reader) { SetEntityUti(entity, "Code", "Code", reader); SetEntityUti(entity, "Status", "Status", reader); } #endregion #region 获取对象列表 /// /// 根据条件,获取列表信息 /// /// 条件 /// 返回满足条件的对象清单 /// [HanHe(HHC)] CREATED 2017/9/27 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 获取对象实体 /// /// 根据条件,获取对象实体 /// /// 条件 /// 返回满足条件的对象实体 /// [HanHe(HHC)] CREATED 2017/9/27 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 判断记录是否存在 /// /// 判断记录是否存在 /// /// 条件 /// true:存在 false:不存在 /// [HanHe(HHC)] CREATED 2017/9/27 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 判断数据是否存在(简便) /// /// 判断数据是否存在 /// /// /// /// /// 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 } }