From e33f97b19282405ab45b71c0a1f9b2c038851d17 Mon Sep 17 00:00:00 2001 From: Sunny Date: Tue, 30 Apr 2024 16:40:19 +0800 Subject: [PATCH] =?UTF-8?q?*=20=E9=87=8D=E6=9E=84=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=89=A9=E5=B1=95=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SunnyUI/Common/UFile.cs | 121 ++++++++---------------------------- SunnyUI/Common/ULocalize.cs | 23 ++++--- 2 files changed, 43 insertions(+), 101 deletions(-) diff --git a/SunnyUI/Common/UFile.cs b/SunnyUI/Common/UFile.cs index 4216f306..feaa94f7 100644 --- a/SunnyUI/Common/UFile.cs +++ b/SunnyUI/Common/UFile.cs @@ -71,27 +71,22 @@ namespace Sunny.UI /// 打开是否成功 public static bool OpenDialog(ref string filename, string filter = "", string defaultExt = "") { - using (OpenFileDialog od = new OpenFileDialog { Title = "打开" }) - { - try - { - od.FileName = filename; - od.Filter = filter; - } - catch - { - od.Filter = ""; - } + using OpenFileDialog od = new OpenFileDialog { Title = UILocalize.Open }; - od.DefaultExt = defaultExt; - if (od.ShowDialog() == DialogResult.OK) - { - filename = od.FileName; - return true; - } + try + { + od.FileName = filename; + od.Filter = filter; + } + catch + { + od.Filter = ""; } - return false; + od.DefaultExt = defaultExt; + bool isOk = od.ShowDialog() == DialogResult.OK; + if (isOk) filename = od.FileName; + return isOk; } /// @@ -103,27 +98,21 @@ namespace Sunny.UI /// 保存是否成功 public static bool SaveDialog(ref string filename, string filter = "", string defaultExt = "") { - using (SaveFileDialog od = new SaveFileDialog { Title = "保存" }) + using SaveFileDialog od = new SaveFileDialog { Title = UILocalize.Save }; + try { - try - { - od.FileName = filename; - od.Filter = filter; - } - catch - { - od.Filter = ""; - } - - od.DefaultExt = defaultExt; - if (od.ShowDialog() == DialogResult.OK) - { - filename = od.FileName; - return true; - } + od.FileName = filename; + od.Filter = filter; + } + catch + { + od.Filter = ""; } - return false; + od.DefaultExt = defaultExt; + bool isOk = od.ShowDialog() == DialogResult.OK; + if (isOk) filename = od.FileName; + return isOk; } /// @@ -542,52 +531,6 @@ namespace Sunny.UI } } - /// - /// 复制 - /// - /// 源目录 - /// 目标目录 - public static void Copy(string source, string dest) - { - Copy(new DirectoryInfo(source), new DirectoryInfo(dest)); - } - - /// - /// 复制 - /// - /// 源目录 - /// 目标目录 - public static void Copy(DirectoryInfo source, DirectoryInfo dest) - { - if (dest.FullName.StartsWith(source.FullName, StringComparison.CurrentCultureIgnoreCase)) - { - throw new Exception("父目录不能拷贝到子目录!"); - } - - if (!source.Exists) - { - return; - } - - if (!dest.Exists) - { - dest.Create(); - } - - FileInfo[] files = source.GetFiles(); - - foreach (FileInfo file in files) - { - File.Copy(file.FullName, Path.Combine(dest.FullName, file.Name), true); - } - - DirectoryInfo[] dirs = source.GetDirectories(); - foreach (DirectoryInfo dir in dirs) - { - Copy(dir.FullName, Path.Combine(dest.FullName, dir.Name)); - } - } - /// /// 根据完整文件路径获取FileStream /// @@ -605,16 +548,6 @@ namespace Sunny.UI return fileStream; } - /// - /// 检测指定文件是否存在,如果存在则返回true。 - /// - /// 文件的绝对路径 - /// 结果 - public static bool Exists(string filePath) - { - return File.Exists(filePath); - } - /// /// 创建一个文件。 /// @@ -625,7 +558,7 @@ namespace Sunny.UI try { //如果文件不存在则创建该文件 - if (!Exists(filePath)) + if (!File.Exists(filePath)) { //创建一个FileInfo对象 FileInfo file = new FileInfo(filePath); @@ -654,7 +587,7 @@ namespace Sunny.UI try { //如果文件不存在则创建该文件 - if (!Exists(filePath)) + if (!File.Exists(filePath)) { //创建一个FileInfo对象 FileInfo file = new FileInfo(filePath); diff --git a/SunnyUI/Common/ULocalize.cs b/SunnyUI/Common/ULocalize.cs index 0aaea0f4..4f6d48e0 100644 --- a/SunnyUI/Common/ULocalize.cs +++ b/SunnyUI/Common/ULocalize.cs @@ -226,6 +226,9 @@ namespace Sunny.UI /// 清除 /// public static string Clear = "清除"; + + public static string Open = "打开"; + public static string Save = "保存"; } /// @@ -253,13 +256,13 @@ namespace Sunny.UI UILocalize.GridDataSourceException = "The data source must be DataTable or List"; UILocalize.SystemProcessing = "The system is processing, please wait..."; - UILocalize.Monday = "Mon."; - UILocalize.Tuesday = "Tue."; - UILocalize.Wednesday = "Wed."; - UILocalize.Thursday = "Thur."; - UILocalize.Friday = "Fri."; - UILocalize.Saturday = "Sat."; - UILocalize.Sunday = "Sun."; + UILocalize.Monday = "MON"; + UILocalize.Tuesday = "TUE"; + UILocalize.Wednesday = "WED"; + UILocalize.Thursday = "THU"; + UILocalize.Friday = "FRI"; + UILocalize.Saturday = "SAT"; + UILocalize.Sunday = "SUN"; UILocalize.Prev = "Previous"; UILocalize.Next = "Next"; @@ -284,6 +287,9 @@ namespace Sunny.UI UILocalize.Search = "Search"; UILocalize.Clear = "Clear"; + UILocalize.Open = "Open"; + UILocalize.Save = "Save"; + UIStyles.Translate(); } @@ -339,6 +345,9 @@ namespace Sunny.UI UILocalize.Search = "搜索"; UILocalize.Clear = "清除"; + UILocalize.Open = "打开"; + UILocalize.Save = "保存"; + UIStyles.Translate(); } }