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
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace HH.WMS.Common
{
    public static class DBFun
    {
        public static string dbType = ConfigurationManager.ConnectionStrings["DataType"].ToString();
        public static DBTYPE Now_dbType
        {
            get
            {
                if (dbType.Equals("MYSQL"))
                    return DBTYPE.MYSQL;
                if (dbType.Equals("MSSQL"))
                    return DBTYPE.MSSQL;
                if (dbType.Equals("ORACLE"))
                    return DBTYPE.ORACLE;
                return DBTYPE.ORTHER;
            }
        }
        public static string GetDate()
        {
            switch (Now_dbType)
            {
                case DBTYPE.MYSQL: return " now() ";
                case DBTYPE.MSSQL: return " getDate() ";
                case DBTYPE.ORACLE: return " SYSDATE ";
                default: return "";
            }
        }
        public static string StringToTime(string time)
        {
            switch (Now_dbType)
            {
                case DBTYPE.MYSQL: return "str_to_date('" + time + "', '%Y-%m-%d %H:%i:%s')";
                case DBTYPE.MSSQL: return " convert(datetime,'" + time + "') ";
                case DBTYPE.ORACLE: return " to_date('" + time + "','yyyy-mm-dd hh24:mi:ss')  ";
                default: return "";
            }
        }
        public static string StringAddDay(string time, int day)
        {
            switch (Now_dbType)
            {
                case DBTYPE.MYSQL: return "date_add('" + time + "',interval " + day + " day)";
                case DBTYPE.MSSQL: return " convert(datetime,'" + time + "')+" + day;
                //case DBTYPE.ORACLE: return " SYSDATE() ";
                default: return "";
            }
        }
        public enum DBTYPE
        {
            MYSQL,
            MSSQL,
            ORACLE,
            ORTHER
        }
 
        public static string Guid()
        {
            switch (Now_dbType)
            {
                case DBTYPE.MYSQL: return " UUID() ";
                case DBTYPE.MSSQL: return " NEWID() ";
                //case DBTYPE.ORACLE: return " SYSDATE() ";
                default: return "";
            }
        }
    }
}