From 70103f344de2c7fe3971ba13d7cd688dee2fb63b Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期日, 01 一月 2023 16:51:37 +0800 Subject: [PATCH] 1 --- DataLoader/Model/ViewData.cs | 2 + DataLoader/CS/Importor.cs | 48 +++++++++++++++++++++-- DataLoader/Model/Tool.cs | 65 +++----------------------------- 3 files changed, 52 insertions(+), 63 deletions(-) diff --git a/DataLoader/CS/Importor.cs b/DataLoader/CS/Importor.cs index 1dcb6a8..c91bd8d 100644 --- a/DataLoader/CS/Importor.cs +++ b/DataLoader/CS/Importor.cs @@ -28,14 +28,14 @@ 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) + public static string GetFilePathByGuid(string guid) { - string sql = "select count(*) from lf.sys_meta_file where guid=@guid"; + string sql = "select path from lf.sys_meta_file where guid = @guid limit"; + DbParameter dp = new NpgsqlParameter("@guid", guid); + object obj = Helper.GetScalar(sql, dp); - int rows = Helper.GetCount(sql, dp); - - return rows; + return obj == null ? null : obj.ToString(); } public static int InsertMeta(SysMeta meta) @@ -60,6 +60,44 @@ public static void Import(ObservableCollection<ViewData> viewDatas, string source, string target) { string[] files = Directory.GetFiles(source); + foreach (string file in files) + { + ViewData vd = new ViewData(); + viewDatas.Add(vd); + + + } + + for (int i = 0, c = files.Length; i < c; i++) + { + ViewData vd = new ViewData(); + vd.ID = i + 1; + vd.FilePath = files[i]; + vd.Status = "鍑嗗"; + viewDatas.Add(vd); + + SetSysMeta(vd); + } + } + + private static void SetSysMeta(ViewData vd) + { + FileInfo fi = new FileInfo(vd.FilePath); + + vd.Meta = new SysMeta(); + vd.Meta.name = fi.Name; + vd.Meta.dirid = 0; + vd.Meta.depid = 0; + vd.Meta.verid = 0; + vd.Meta.type = "File"; + vd.Meta.sizes = Tool.SizeToMb(fi.Length); + vd.Meta.cs = null; + vd.Meta.scale = null; + vd.Meta.resolution = null; + vd.Meta.gather = DateTime.Now; + vd.Meta.batch = null; + vd.Meta.descr = null; + vd.Meta.create_user = Tool.UserId; } } } diff --git a/DataLoader/Model/Tool.cs b/DataLoader/Model/Tool.cs index 4f3b08c..631f0ed 100644 --- a/DataLoader/Model/Tool.cs +++ b/DataLoader/Model/Tool.cs @@ -79,67 +79,16 @@ return list; } - /*//2a0befb05146cd30213ee4b95038aca0 - public static String getFileMd5(String filePath) + public static double SizeToMb(long size) { - FileStream fis = null; - try + if (size < 1050) { - 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); + return 0.001; } - catch (Exception ex) - { - return null; - } - finally - { - try - { - if (null != fis) - { - fis.Dispose(); - } - } - catch (Exception ex) - { - // - } - } + + String str = string.Format("{0:F3}", size / 1024.0 / 1024.0); + + return Double.Parse(str); } - - 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); - }*/ } } diff --git a/DataLoader/Model/ViewData.cs b/DataLoader/Model/ViewData.cs index 8cd7dee..5f1ec30 100644 --- a/DataLoader/Model/ViewData.cs +++ b/DataLoader/Model/ViewData.cs @@ -76,5 +76,7 @@ PropertyChanged(this, new PropertyChangedEventArgs(propName)); } } + + public SysMeta Meta { set; get; } } } -- Gitblit v1.9.3