From 550e65b657f0eccd513ba91339fb8f0ea3f9fa02 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期日, 01 一月 2023 16:18:05 +0800 Subject: [PATCH] 1.1.7 --- DataLoader/MainWindow.xaml.cs | 21 +++++ DataLoader/CS/Importor.cs | 48 +++++++++++ DataLoader/MainWindow.xaml | 2 DataLoader/CS/MD5Helper.cs | 60 +++++++++++++++ DataLoader/DataLoader.csproj | 1 DataLoader/Model/Tool.cs | 67 ++++++++++++++++ 6 files changed, 194 insertions(+), 5 deletions(-) diff --git a/DataLoader/CS/Importor.cs b/DataLoader/CS/Importor.cs index d4eed9d..1dcb6a8 100644 --- a/DataLoader/CS/Importor.cs +++ b/DataLoader/CS/Importor.cs @@ -1,23 +1,65 @@ 锘縰sing 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); } } } diff --git a/DataLoader/CS/MD5Helper.cs b/DataLoader/CS/MD5Helper.cs new file mode 100644 index 0000000..4738a4b --- /dev/null +++ b/DataLoader/CS/MD5Helper.cs @@ -0,0 +1,60 @@ +锘縰sing 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锛屽叾涓瘡涓�瀵硅〃绀簐alue 涓搴旂殑鍏冪礌锛涗緥濡傗�淔-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锛屽叾涓瘡涓�瀵硅〃绀簐alue 涓搴旂殑鍏冪礌锛涗緥濡傗�淔-2C-4A鈥� + byte[] arrbytHashValue = oMD5Hasher.ComputeHash(buffer); + string strHashData = BitConverter.ToString(arrbytHashValue); + + return strHashData.Replace("-", "").ToLower(); // 鏇挎崲- + } + catch (Exception ex) + { + return ""; + } + } + } +} diff --git a/DataLoader/DataLoader.csproj b/DataLoader/DataLoader.csproj index 2e2079f..1605825 100644 --- a/DataLoader/DataLoader.csproj +++ b/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" /> diff --git a/DataLoader/MainWindow.xaml b/DataLoader/MainWindow.xaml index 0896b2d..a232dd1 100644 --- a/DataLoader/MainWindow.xaml +++ b/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"/> diff --git a/DataLoader/MainWindow.xaml.cs b/DataLoader/MainWindow.xaml.cs index 42d3edb..587b2fe 100644 --- a/DataLoader/MainWindow.xaml.cs +++ b/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 diff --git a/DataLoader/Model/Tool.cs b/DataLoader/Model/Tool.cs index e9c6a32..4f3b08c 100644 --- a/DataLoader/Model/Tool.cs +++ b/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); + }*/ } } -- Gitblit v1.9.3