* 重构文件扩展类
This commit is contained in:
parent
5715d13fac
commit
e33f97b192
@ -71,27 +71,22 @@ namespace Sunny.UI
|
|||||||
/// <returns>打开是否成功</returns>
|
/// <returns>打开是否成功</returns>
|
||||||
public static bool OpenDialog(ref string filename, string filter = "", string defaultExt = "")
|
public static bool OpenDialog(ref string filename, string filter = "", string defaultExt = "")
|
||||||
{
|
{
|
||||||
using (OpenFileDialog od = new OpenFileDialog { Title = "打开" })
|
using OpenFileDialog od = new OpenFileDialog { Title = UILocalize.Open };
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
od.FileName = filename;
|
|
||||||
od.Filter = filter;
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
od.Filter = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
od.DefaultExt = defaultExt;
|
try
|
||||||
if (od.ShowDialog() == DialogResult.OK)
|
{
|
||||||
{
|
od.FileName = filename;
|
||||||
filename = od.FileName;
|
od.Filter = filter;
|
||||||
return true;
|
}
|
||||||
}
|
catch
|
||||||
|
{
|
||||||
|
od.Filter = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
od.DefaultExt = defaultExt;
|
||||||
|
bool isOk = od.ShowDialog() == DialogResult.OK;
|
||||||
|
if (isOk) filename = od.FileName;
|
||||||
|
return isOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -103,27 +98,21 @@ namespace Sunny.UI
|
|||||||
/// <returns>保存是否成功</returns>
|
/// <returns>保存是否成功</returns>
|
||||||
public static bool SaveDialog(ref string filename, string filter = "", string defaultExt = "")
|
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;
|
||||||
od.FileName = filename;
|
}
|
||||||
od.Filter = filter;
|
catch
|
||||||
}
|
{
|
||||||
catch
|
od.Filter = "";
|
||||||
{
|
|
||||||
od.Filter = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
od.DefaultExt = defaultExt;
|
|
||||||
if (od.ShowDialog() == DialogResult.OK)
|
|
||||||
{
|
|
||||||
filename = od.FileName;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
od.DefaultExt = defaultExt;
|
||||||
|
bool isOk = od.ShowDialog() == DialogResult.OK;
|
||||||
|
if (isOk) filename = od.FileName;
|
||||||
|
return isOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -542,52 +531,6 @@ namespace Sunny.UI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 复制
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="source">源目录</param>
|
|
||||||
/// <param name="dest">目标目录</param>
|
|
||||||
public static void Copy(string source, string dest)
|
|
||||||
{
|
|
||||||
Copy(new DirectoryInfo(source), new DirectoryInfo(dest));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 复制
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="source">源目录</param>
|
|
||||||
/// <param name="dest">目标目录</param>
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 根据完整文件路径获取FileStream
|
/// 根据完整文件路径获取FileStream
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -605,16 +548,6 @@ namespace Sunny.UI
|
|||||||
return fileStream;
|
return fileStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 检测指定文件是否存在,如果存在则返回true。
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="filePath">文件的绝对路径</param>
|
|
||||||
/// <returns>结果</returns>
|
|
||||||
public static bool Exists(string filePath)
|
|
||||||
{
|
|
||||||
return File.Exists(filePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 创建一个文件。
|
/// 创建一个文件。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -625,7 +558,7 @@ namespace Sunny.UI
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
//如果文件不存在则创建该文件
|
//如果文件不存在则创建该文件
|
||||||
if (!Exists(filePath))
|
if (!File.Exists(filePath))
|
||||||
{
|
{
|
||||||
//创建一个FileInfo对象
|
//创建一个FileInfo对象
|
||||||
FileInfo file = new FileInfo(filePath);
|
FileInfo file = new FileInfo(filePath);
|
||||||
@ -654,7 +587,7 @@ namespace Sunny.UI
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
//如果文件不存在则创建该文件
|
//如果文件不存在则创建该文件
|
||||||
if (!Exists(filePath))
|
if (!File.Exists(filePath))
|
||||||
{
|
{
|
||||||
//创建一个FileInfo对象
|
//创建一个FileInfo对象
|
||||||
FileInfo file = new FileInfo(filePath);
|
FileInfo file = new FileInfo(filePath);
|
||||||
|
@ -226,6 +226,9 @@ namespace Sunny.UI
|
|||||||
/// 清除
|
/// 清除
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string Clear = "清除";
|
public static string Clear = "清除";
|
||||||
|
|
||||||
|
public static string Open = "打开";
|
||||||
|
public static string Save = "保存";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -253,13 +256,13 @@ namespace Sunny.UI
|
|||||||
UILocalize.GridDataSourceException = "The data source must be DataTable or List";
|
UILocalize.GridDataSourceException = "The data source must be DataTable or List";
|
||||||
UILocalize.SystemProcessing = "The system is processing, please wait...";
|
UILocalize.SystemProcessing = "The system is processing, please wait...";
|
||||||
|
|
||||||
UILocalize.Monday = "Mon.";
|
UILocalize.Monday = "MON";
|
||||||
UILocalize.Tuesday = "Tue.";
|
UILocalize.Tuesday = "TUE";
|
||||||
UILocalize.Wednesday = "Wed.";
|
UILocalize.Wednesday = "WED";
|
||||||
UILocalize.Thursday = "Thur.";
|
UILocalize.Thursday = "THU";
|
||||||
UILocalize.Friday = "Fri.";
|
UILocalize.Friday = "FRI";
|
||||||
UILocalize.Saturday = "Sat.";
|
UILocalize.Saturday = "SAT";
|
||||||
UILocalize.Sunday = "Sun.";
|
UILocalize.Sunday = "SUN";
|
||||||
|
|
||||||
UILocalize.Prev = "Previous";
|
UILocalize.Prev = "Previous";
|
||||||
UILocalize.Next = "Next";
|
UILocalize.Next = "Next";
|
||||||
@ -284,6 +287,9 @@ namespace Sunny.UI
|
|||||||
UILocalize.Search = "Search";
|
UILocalize.Search = "Search";
|
||||||
UILocalize.Clear = "Clear";
|
UILocalize.Clear = "Clear";
|
||||||
|
|
||||||
|
UILocalize.Open = "Open";
|
||||||
|
UILocalize.Save = "Save";
|
||||||
|
|
||||||
UIStyles.Translate();
|
UIStyles.Translate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -339,6 +345,9 @@ namespace Sunny.UI
|
|||||||
UILocalize.Search = "搜索";
|
UILocalize.Search = "搜索";
|
||||||
UILocalize.Clear = "清除";
|
UILocalize.Clear = "清除";
|
||||||
|
|
||||||
|
UILocalize.Open = "打开";
|
||||||
|
UILocalize.Save = "保存";
|
||||||
|
|
||||||
UIStyles.Translate();
|
UIStyles.Translate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user