管道基础大数据平台系统开发-【CS】-ExportMap
13693261870
2023-01-01 550e65b657f0eccd513ba91339fb8f0ea3f9fa02
1.1.7
已添加1个文件
已修改5个文件
199 ■■■■■ 文件已修改
DataLoader/CS/Importor.cs 48 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DataLoader/CS/MD5Helper.cs 60 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DataLoader/DataLoader.csproj 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DataLoader/MainWindow.xaml 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
DataLoader/MainWindow.xaml.cs 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DataLoader/Model/Tool.cs 67 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DataLoader/CS/Importor.cs
@@ -1,23 +1,65 @@
using DataLoader.Model;
using Npgsql;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data.Common;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace DataLoader.CS
{
    public class Importor
    {
        private static PostgreHelper _ph = null;
        public static PostgreHelper Helper
        {
            get
            {
                if (_ph == null) _ph = new PostgreHelper(DbEnum.langfang);
                return _ph;
            }
        }
        private static readonly string insertMeta = "insert into lf.sys_meta(name, dirid, depid, verid, type, sizes, cs, scale, resolution, gather, batch, descr, create_user) values  @name, @dirid, @depid, @verid, @type, @sizes, @cs, @scale, @resolution, @gather, @batch, @descr, @create_user) returning id";
        private static readonly string insertMetaFile = "insert into lf.sys_meta_file(name, metaid, fileid, guid, path, sizes, create_user) values (@name, @metaid, @fileid, @guid, @path, @sizes, @create_user)";
        public static int CountFilesByGuid(string guid)
        {
            string sql = "select count(*) from lf.sys_meta_file where guid=@guid";
            DbParameter dp = new NpgsqlParameter("@guid", guid);
            int rows = Helper.GetCount(sql, dp);
            return rows;
        }
        public static int InsertMeta(SysMeta meta)
        {
            // string sql = "INSERT INTO public.data_files(mid, guid, name, ext, path, subs, remark) VALUES (@mid, @guid, @name, @ext, @path, @subs, @remark) returning id";
            List<DbParameter> list = Tool.GetParams<SysMeta>(insertMeta, meta);
            object obj = Helper.GetScalar(insertMeta, list.ToArray());
            return obj == null ? 0 : Convert.ToInt32(obj);
        }
        public static int InsertMetaFile(SysMetaFile metaFile)
        {
            List<DbParameter> list = Tool.GetParams<SysMetaFile>(insertMetaFile, metaFile);
            object obj = Helper.ExecuteNonQuery(insertMetaFile, list.ToArray());
            return obj == null ? 0 : Convert.ToInt32(obj);
        }
        public static void Import(ObservableCollection<ViewData> viewDatas, string source, string target)
        {
            string[] files = Directory.GetFiles(source);
        }
    }
}
DataLoader/CS/MD5Helper.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace DataLoader.CS
{
    public class MD5Helper
    {
        /// <summary>
        /// æ–‡ä»¶MD5校验
        /// </summary>
        /// <param name="pathName">文件绝对路径</param>
        /// <returns>MD5校验码</returns>
        public static string getMD5Hash(string pathName)
        {
            try
            {
                FileStream oFileStream = new FileStream(pathName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                MD5CryptoServiceProvider oMD5Hasher = new MD5CryptoServiceProvider();
                byte[] arrbytHashValue = oMD5Hasher.ComputeHash(oFileStream); // è®¡ç®—指定Stream å¯¹è±¡çš„哈希值
                oFileStream.Close();
                // ç”±ä»¥è¿žå­—符分隔的十六进制对构成的String,其中每一对表示value ä¸­å¯¹åº”的元素;例如“F-2C-4A”
                string strHashData = BitConverter.ToString(arrbytHashValue);
                return strHashData.Replace("-", "").ToLower(); // æ›¿æ¢-
            }
            catch (Exception ex)
            {
                return "";
            }
        }
        /// <summary>
        /// å­—节数组校验
        /// </summary>
        /// <param name="buffer">待字节数组</param>
        /// <returns>MD5校验码</returns>
        public static string getMD5Hash(byte[] buffer)
        {
            MD5CryptoServiceProvider oMD5Hasher = new MD5CryptoServiceProvider();
            try
            {
                // è®¡ç®—指定Stream å¯¹è±¡çš„哈希值,由以连字符分隔的十六进制对构成的String,其中每一对表示value ä¸­å¯¹åº”的元素;例如“F-2C-4A”
                byte[] arrbytHashValue = oMD5Hasher.ComputeHash(buffer);
                string strHashData = BitConverter.ToString(arrbytHashValue);
                return strHashData.Replace("-", "").ToLower(); // æ›¿æ¢-
            }
            catch (Exception ex)
            {
                return "";
            }
        }
    }
}
DataLoader/DataLoader.csproj
@@ -88,6 +88,7 @@
      <SubType>Code</SubType>
    </Compile>
    <Compile Include="CS\Importor.cs" />
    <Compile Include="CS\MD5Helper.cs" />
    <Compile Include="Model\Tool.cs" />
    <Compile Include="CS\ModelHandler.cs" />
    <Compile Include="Model\NtstWeb.cs" />
DataLoader/MainWindow.xaml
@@ -51,7 +51,7 @@
        <TextBox x:Name="tbToken" Grid.Row="0" Grid.Column="3"  Style="{StaticResource tb}" IsReadOnly="True"/>
        <Button Grid.Row="0" Grid.Column="4" Content="登 å½•" Style="{StaticResource btn}" Click="Login_MouseLeftButtonDown"/>
        <Label Grid.Row="1" Grid.Column="0" Content="源目录:" VerticalAlignment="Center" HorizontalAlignment="Right" />
        <Label Grid.Row="1" Grid.Column="0" Content="数据目录:" VerticalAlignment="Center" HorizontalAlignment="Right" />
        <TextBox x:Name="tbSource" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="3" Style="{StaticResource tb}" Text="{Binding Path=SourcePath, Mode=TwoWay}"/>
        <Button x:Name="btnSource" Grid.Row="1" Grid.Column="4" Content="选 æ‹©" Style="{StaticResource btn}" Click="Source_MouseLeftButtonDown"/>
DataLoader/MainWindow.xaml.cs
@@ -69,8 +69,10 @@
            this.btnImport.IsEnabled = false;
            lvView.DataContext = viewDatas;
            lvView.SetBinding(ListView.ItemsSourceProperty, new Binding());
        }
            String file = "E:\\data\\mpt\\A4mpt20131125.mpt";
            string md5 = MD5Helper.getMD5Hash(file);
        }
        // ç™»å½•
        private void Login_MouseLeftButtonDown(object sender, RoutedEventArgs e)
@@ -123,6 +125,23 @@
        // å¯¼å…¥
        private void Import_MouseLeftButtonDown(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(SourcePath) || !Directory.Exists(SourcePath))
            {
                MessageBox.Show("请选择数据目录!");
                return;
            }
            if (string.IsNullOrEmpty(TargetPath) || !Directory.Exists(TargetPath))
            {
                MessageBox.Show("请选择入库目录!");
                return;
            }
            string[] files = Directory.GetFiles(SourcePath);
            if (null == files || files.Length == 0)
            {
                MessageBox.Show("数据目录下没有文件!");
                return;
            }
            viewDatas.Clear();
            Dispatcher.Invoke(new Action(delegate
DataLoader/Model/Tool.cs
@@ -3,8 +3,10 @@
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;
@@ -22,6 +24,8 @@
        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)
        {
@@ -74,5 +78,68 @@
            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);
        }*/
    }
}