yzh
2022-06-07 dbda463cdacc6c6101acdf9d58e22450a281b9b0
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
namespace Common
{
    using System;
    using System.Runtime.InteropServices;
    using System.Text.RegularExpressions;
 
    public class DataConverter
    {
        protected DataConverter()
        {
        }
 
        public static DateTime BigIntToDateTime(long inputLong)
        {
            DateTime date = DateTime.Now.Date;
            DateTime.TryParse("1970-01-01", out date);
            double num = ((double)inputLong) / 86400.0;
            return date.AddDays(num);
        }
 
        public static string getDateDotSplit(DateTime? currentTime, string split)
        {
            string str = "待定";
            if (currentTime.HasValue)
            {
                str = string.Concat(new object[] { currentTime.Value.Year, split, currentTime.Value.Month, split, currentTime.Value.Day });
            }
            return str;
        }
 
        public static string IntToStringIP(int ip)
        {
            StructIp ip2 = new StructIp
            {
                _IntIP = ip
            };
            return (ip2._IP.ip1.ToString() + "." + ip2._IP.ip2.ToString() + "." + ip2._IP.ip3.ToString() + "." + ip2._IP.ip4.ToString());
        }
 
        public static int SafeInt32(object objNum)
        {
            if (objNum != null)
            {
                string strNumber = objNum.ToString();
                if (DataValidate.IsNumber(strNumber))
                {
                    if (strNumber.ToString().Length > 9)
                    {
                        return 0x7fffffff;
                    }
                    return int.Parse(strNumber);
                }
            }
            return 0;
        }
 
        public static bool StrToBool(string strValue)
        {
            if (!string.IsNullOrEmpty(strValue))
            {
                strValue = strValue.Trim();
                return (((string.Compare(strValue, "true", true) == 0) || (string.Compare(strValue, "yes", true) == 0)) || (string.Compare(strValue, "1", true) == 0));
            }
            return false;
        }
 
        public static DateTime StrToDateTime(object strValue, DateTime defValue)
        {
            DateTime time;
            if ((strValue == null) || (strValue.ToString().Length > 20))
            {
                return defValue;
            }
            if (!DateTime.TryParse(strValue.ToString(), out time))
            {
                time = defValue;
            }
            return time;
        }
 
        public static decimal StrToDecimal(object strValue)
        {
            if (!(Convert.IsDBNull(strValue) || object.Equals(strValue, null)))
            {
                return StrToDecimal(strValue.ToString());
            }
            return 0M;
        }
 
        public static decimal StrToDecimal(string strValue)
        {
            decimal num;
            decimal.TryParse(strValue, out num);
            return num;
        }
 
        public static decimal StrToDecimal(string input, decimal defaultValue)
        {
            decimal num;
            if (decimal.TryParse(input, out num))
            {
                return num;
            }
            return defaultValue;
        }
 
        public static double StrToDouble(object strValue)
        {
            if (!(Convert.IsDBNull(strValue) || object.Equals(strValue, null)))
            {
                return StrToDouble(strValue.ToString());
            }
            return 0.0;
        }
 
        public static double StrToDouble(string strValue)
        {
            double num;
            double.TryParse(strValue, out num);
            return num;
        }
 
        public static int StrToInt(object strValue)
        {
            if ((((strValue != null) && (strValue.ToString() != string.Empty)) && (strValue.ToString().Length <= 10)) && Regex.IsMatch(strValue.ToString(), "^[0-9]+$"))
            {
                return Convert.ToInt32(strValue.ToString());
            }
            return -1;
        }
 
        public static int StrToInt(object strValue, int defValue)
        {
            if (((strValue != null) && (strValue.ToString() != string.Empty)) && Regex.IsMatch(strValue.ToString(), "^[0-9]+$"))
            {
                return Convert.ToInt32(strValue.ToString());
            }
            return defValue;
        }
 
        public static long StrToInt64(string strValue, long defValue)
        {
            long result = 0L;
            if (long.TryParse(strValue, out result))
            {
                return result;
            }
            return defValue;
        }
 
        public static int StrToPageInt(object strValue, int defValue)
        {
            if (((strValue != null) && (strValue.ToString() != string.Empty)) && Regex.IsMatch(strValue.ToString(), "^[0-9]+$"))
            {
                int num = Convert.ToInt32(strValue.ToString());
                if (num < 1)
                {
                    num = 1;
                }
                return num;
            }
            return defValue;
        }
 
        [StructLayout(LayoutKind.Sequential)]
        private struct IPAdress
        {
            public byte ip1;
            public byte ip2;
            public byte ip3;
            public byte ip4;
        }
 
        [StructLayout(LayoutKind.Explicit)]
        private struct StructIp
        {
            [FieldOffset(0)]
            public int _IntIP;
            [FieldOffset(0)]
            public DataConverter.IPAdress _IP;
        }
    }
}