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
/*------------------------------------------------------------------
-- COPYRIGHT (C) 2011-2022  Hanhe
-- ALL RIGHTS RESERVED.
-- Hanhe
-- CREATE DATE: 2010/07/27
-- CREATE MAN:    wz
-- 系统参数配置表
-- MODIFY HISTORY:
-- MODIFY DATE:
-- MODIFY MAN:    
-- MODIFY DESC:
-- MODIFY DATE:
-- MODIFY MAN:    
-- MODIFY DESC:
---------------------------------------------------------------------*/
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Common;
using System.Data;
using HanHe.Utility.Data;
using HH.WMS.Entitys.Common;
 
 
namespace HH.WMS.DAL.Func
{
    public class CommonDAL : BaseDAL
    {
        
        #region 判断数据库中是否存在某张表
        /// <summary>
        /// 判断数据库中是否存在某张表
        /// </summary>
        /// <param name="TableName">表名</param>
        /// <returns>存在返回true,失败返回false</returns>
        /// <history>[HanHe(ZMM)] CREATED 2015/11/04</history>
        public bool ExsistTable(string TableName)
        {
            string Sql = "select count(*) from sysobjects where id = object_id(N'[" + TableName + "]') and OBJECTPROPERTY(id, N'IsUserTable') = 1";
            DbCommand cmd = DataAccess.GetSqlStringCommand(Sql);
            object obj = DataAccess.ExecuteScalar(cmd);
            if (Convert.ToInt32(obj) > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        #endregion
        
        
        #region 获取/设置全局参数
        /// <summary>
        /// 获取全局参数
        /// </summary>
        /// <param name="strKey">参数键</param>
        /// <returns>参数值</returns>
        /// <history>[HanHe(HHC)] CREATED 2016/09/29</history>
        public string GetGlobalVar(string strKey)
        {
            string strSql = @"SELECT CN_S_VALUE FROM TN_TASK_GLOBALVAR WHERE CN_S_KEY='{0}' ";
            strSql = string.Format(strSql, strKey);
 
            DbCommand cmd = DataAccess.GetSqlStringCommand(strSql);
            object obj = DataAccess.ExecuteScalar(cmd);
            if (null != obj)
            {
                return obj.ToString();
            }
            return "";
        }
 
        /// <summary>
        /// 设置全局参数
        /// </summary>
        /// <param name="strKey">参数键</param>
        /// <param name="strValue">参数值</param>
        /// <param name="trans">事务</param>
        /// <returns>true:成功  false:失败</returns>
        /// <history>[HanHe(HHC)] CREATED 2016/09/29</history>
        public bool SetGlobalVar(string strKey, string strValue, DbTransaction trans = null)
        {
            SqlExecuteResult result = new SqlExecuteResult();
            try
            {
                string strSql = @"DECLARE NUM NUMBER; 
                              BEGIN
                                SELECT COUNT(1) INTO NUM FROM TN_TASK_GLOBALVAR WHERE CN_S_KEY='{0}'; 
                                IF NUM>0 THEN
                                    UPDATE TN_TASK_GLOBALVAR SET CN_S_VALUE='{1}' WHERE CN_S_KEY='{0}' ;
                                ELSE 
                                    INSERT INTO TN_TASK_GLOBALVAR(CN_S_KEY,CN_S_VALUE) VALUES('{0}', '{1}');
                                END IF;
                              END;";
                strSql = string.Format(strSql, strKey, strValue);
 
                DbCommand cmd = DataAccess.GetSqlStringCommand(strSql);
                result = ExecuteCommand(cmd, trans);
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Exception = ex;
            }
            return result.Success;
        }
        #endregion
 
    }
}