From dc2da375cd8b8cc7fb5cb3a3f854cf53e685da9e Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期日, 01 一月 2023 15:37:42 +0800 Subject: [PATCH] 1.1.5 --- /dev/null | 22 ------- DataLoader/MainWindow.xaml.cs | 6 +- DataLoader/CS/Importor.cs | 3 DataLoader/DataLoader.csproj | 2 DataLoader/LoginWin.xaml.cs | 2 DataLoader/Model/NtstWeb.cs | 8 +- DataLoader/Model/Tool.cs | 78 ++++++++++++++++++++++++++ 7 files changed, 89 insertions(+), 32 deletions(-) diff --git a/DataLoader/CS/Importor.cs b/DataLoader/CS/Importor.cs index 51ea5a9..d4eed9d 100644 --- a/DataLoader/CS/Importor.cs +++ b/DataLoader/CS/Importor.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; @@ -10,7 +11,7 @@ { public class Importor { - 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)"; + 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)"; diff --git a/DataLoader/DataLoader.csproj b/DataLoader/DataLoader.csproj index 8459f0e..2e2079f 100644 --- a/DataLoader/DataLoader.csproj +++ b/DataLoader/DataLoader.csproj @@ -88,7 +88,7 @@ <SubType>Code</SubType> </Compile> <Compile Include="CS\Importor.cs" /> - <Compile Include="Model\Main.cs" /> + <Compile Include="Model\Tool.cs" /> <Compile Include="CS\ModelHandler.cs" /> <Compile Include="Model\NtstWeb.cs" /> <Compile Include="CS\PostgreHelper.cs" /> diff --git a/DataLoader/LoginWin.xaml.cs b/DataLoader/LoginWin.xaml.cs index 15df86e..a34d869 100644 --- a/DataLoader/LoginWin.xaml.cs +++ b/DataLoader/LoginWin.xaml.cs @@ -32,7 +32,7 @@ private void Window_Loaded(object sender, RoutedEventArgs e) { - web.Address = Main.BaseDir + "htmls\\login.html"; + web.Address = Tool.BaseDir + "htmls\\login.html"; } } } diff --git a/DataLoader/MainWindow.xaml.cs b/DataLoader/MainWindow.xaml.cs index 99e9fc8..42d3edb 100644 --- a/DataLoader/MainWindow.xaml.cs +++ b/DataLoader/MainWindow.xaml.cs @@ -64,7 +64,7 @@ private void Window_Loaded(object sender, RoutedEventArgs e) { - Main.Owner = this; + Tool.Owner = this; this.btnImport.IsEnabled = false; lvView.DataContext = viewDatas; @@ -85,8 +85,8 @@ if (win != null) win.Close(); this.Show(); - this.tbUid.Text = Main.UserId.ToString() + "锛�" + Main.Uname; - this.tbToken.Text = Main.Token; + this.tbUid.Text = Tool.UserId.ToString() + "锛�" + Tool.Uname; + this.tbToken.Text = Tool.Token; this.btnImport.IsEnabled = true; } diff --git a/DataLoader/Model/Main.cs b/DataLoader/Model/Main.cs deleted file mode 100644 index 1af79c3..0000000 --- a/DataLoader/Model/Main.cs +++ /dev/null @@ -1,22 +0,0 @@ -锘縰sing System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; - -namespace DataLoader.Model -{ - public class Main - { - 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 = ""; - } -} diff --git a/DataLoader/Model/NtstWeb.cs b/DataLoader/Model/NtstWeb.cs index fc67c96..1d5cea5 100644 --- a/DataLoader/Model/NtstWeb.cs +++ b/DataLoader/Model/NtstWeb.cs @@ -21,13 +21,13 @@ { if (uid > 0 && !string.IsNullOrEmpty(token)) { - Main.UserId = uid; - Main.Uname = uname; - Main.Token = token; + Tool.UserId = uid; + Tool.Uname = uname; + Tool.Token = token; owner.Dispatcher.Invoke(new Action(delegate { - Main.Owner.SetLoginInfo(); + Tool.Owner.SetLoginInfo(); })); } } diff --git a/DataLoader/Model/Tool.cs b/DataLoader/Model/Tool.cs new file mode 100644 index 0000000..e9c6a32 --- /dev/null +++ b/DataLoader/Model/Tool.cs @@ -0,0 +1,78 @@ +锘縰sing Npgsql; +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data.Common; +using System.Linq; +using System.Reflection; +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 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; + } + } +} -- Gitblit v1.9.3