jt
2021-06-10 5d0d028456874576560552f5a5c4e8b801786f11
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
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
    }
}