管道基础大数据平台系统开发-【CS】-ExportMap
13693261870
2023-01-01 550e65b657f0eccd513ba91339fb8f0ea3f9fa02
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
using Npgsql;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.Common;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
 
namespace DataLoader.Model
{
    public class Tool
    {
        public static MainWindow Owner = null;
 
        public static readonly string BaseDir = AppDomain.CurrentDomain.BaseDirectory;
 
        public static int UserId = 0;
 
        public static string Uname = "";
 
        public static string Token = "";
 
        public static char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
 
        public static string FormatBytes(long bytes)
        {
            string[] Suffix = { "Byte", "KB", "MB", "GB", "TB" };
 
            int i = 0;
            double dblSByte = bytes;
            if (bytes > 1024)
                for (i = 0; (bytes / 1024) > 0; i++, bytes /= 1024)
                    dblSByte = bytes / 1024.0;
 
            return String.Format("{0:0.##}{1}", dblSByte, Suffix[i]);
        }
 
        public static string GetSetting(string key)
        {
            if (!ConfigurationManager.AppSettings.AllKeys.Contains(key))
            {
                return null;
            }
 
            return ConfigurationManager.AppSettings[key];
        }
 
        public static List<DbParameter> GetParams<T>(string sql, T t)
        {
            List<DbParameter> list = new List<DbParameter>();
            Type tType = typeof(T);
            BindingFlags flags = BindingFlags.Public | BindingFlags.IgnoreCase | BindingFlags.Instance;
 
            int start = sql.IndexOf("@");
            while (start != -1)
            {
                int end = sql.IndexOf(",", start);
                if (end == -1) end = sql.IndexOf(")", start);
                if (end == -1) end = sql.IndexOf(" ", start);
                if (end == -1) end = sql.Length;
 
                string name = sql.Substring(start + 1, end - start - 1);
                PropertyInfo pi = tType.GetProperty(name, flags);
                if (pi != null)
                {
                    object value = pi.GetValue(t, null);
                    DbParameter dp = new NpgsqlParameter("@" + name, value);
                    list.Add(dp);
                }
 
                start = sql.IndexOf("@", end);
            }
 
            return list;
        }
 
        /*//2a0befb05146cd30213ee4b95038aca0
        public static String getFileMd5(String filePath)
        {
            FileStream fis = null;
            try
            {
                MessageDigest md = MessageDigest.getInstance("MD5");
 
                fis = new FileStream(new File(filePath));
                FileChannel fChannel = fis.getChannel();
                Byte[] buffer =new Byte[1024 * 1024];
 
                while (fChannel.read(buffer) != -1)
                {
                    buffer.flip();
                    md.update(buffer);
                    buffer.compact();
                }
                byte[] b = md.digest();
 
                return byteToHexString(b);
            }
            catch (Exception ex)
            {
                return null;
            }
            finally
            {
                try
                {
                    if (null != fis)
                    {
                        fis.Dispose();
                    }
                }
                catch (Exception ex)
                {
                    //
                }
            }
        }
 
        public static String byteToHexString(byte[] tmp)
        {
            // 每个字节用 16 进制表示的话,使用两个字符,
            char[] str = new char[16 * 2];
 
            int k = 0;
            for (int i = 0; i < 16; i++)
            {
                // 转换成 16 进制字符的转换
                byte byte0 = tmp[i];
 
                // 取字节中高 4 位的数字转换
                str[k++] = HEX_DIGITS[byte0 >> 4 & 0xf];
 
                // >>> 为逻辑右移,将符号位一起右移, 取字节中低 4 位的数字转换
                str[k++] = HEX_DIGITS[byte0 & 0xf];
            }
 
            return new String(str);
        }*/
    }
}