|
@@ -10,6 +10,7 @@ using System.Collections;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Data;
|
|
|
using System.Drawing;
|
|
|
+using System.IO;
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
namespace OTSIncAReportApp.OTSTemplateDesigner
|
|
@@ -684,6 +685,19 @@ namespace OTSIncAReportApp.OTSTemplateDesigner
|
|
|
Bitmap bitmap = (Bitmap)Image.FromFile(filePath).Clone();
|
|
|
pictureBox7.Image.Dispose();
|
|
|
pictureBox7.Image = (Image)bitmap.Clone();
|
|
|
+
|
|
|
+ if (!IsPathWithinDirectory(filePath, System.IO.Directory.GetCurrentDirectory() + "\\Config\\ReportTemplate"))
|
|
|
+ {
|
|
|
+ //Console.WriteLine("图片路径在指定的文件夹内。");
|
|
|
+ CopyPicture(filePath, System.IO.Directory.GetCurrentDirectory() + "\\Config\\ReportTemplate\\");
|
|
|
+ }
|
|
|
+ //else
|
|
|
+ //{
|
|
|
+ // Console.WriteLine("图片路径不在指定的文件夹内。");
|
|
|
+ //}
|
|
|
+
|
|
|
+
|
|
|
+ //CopyPicture(filePath, System.IO.Directory.GetCurrentDirectory() + "\\Config\\ReportTemplate\\");
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
@@ -692,6 +706,49 @@ namespace OTSIncAReportApp.OTSTemplateDesigner
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ /// <summary>
|
|
|
+ /// 复制图片指定路径
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="sourceImagePath">源图片路径</param>
|
|
|
+ /// <param name="targetFolderPath">目标文件夹路径(确保文件夹存在,否则需要创建它)</param>
|
|
|
+ private void CopyPicture(string sourceImagePath,string targetFolderPath)
|
|
|
+ {
|
|
|
+
|
|
|
+ // 构造目标图片路径(如果图片名要改变,可以在这里指定新的名字)
|
|
|
+ string targetImagePath = Path.Combine(targetFolderPath, Path.GetFileName(sourceImagePath));
|
|
|
+
|
|
|
+ // 确保目标文件夹存在
|
|
|
+ if (!Directory.Exists(targetFolderPath))
|
|
|
+ {
|
|
|
+ Directory.CreateDirectory(targetFolderPath);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 复制图片到目标路径
|
|
|
+ try
|
|
|
+ {
|
|
|
+ File.Copy(sourceImagePath, targetImagePath, true); // 第三个参数为true表示如果目标文件已存在,则覆盖它
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ MessageBox.Show("图片复制失败:"+ ex.Message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static bool IsPathWithinDirectory(string filePath, string directoryPath)
|
|
|
+ {
|
|
|
+ // 确保directoryPath以目录分隔符结尾
|
|
|
+ if (!directoryPath.EndsWith(Path.DirectorySeparatorChar.ToString()))
|
|
|
+ {
|
|
|
+ directoryPath += Path.DirectorySeparatorChar;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 使用Path.GetFullPath来规范化路径,这样可以处理相对路径和当前目录等
|
|
|
+ string fullPath = Path.GetFullPath(filePath);
|
|
|
+ string fullDirectoryPath = Path.GetFullPath(directoryPath);
|
|
|
+
|
|
|
+ // 判断fullPath是否以fullDirectoryPath为前缀
|
|
|
+ return fullPath.StartsWith(fullDirectoryPath, StringComparison.OrdinalIgnoreCase);
|
|
|
+ }
|
|
|
|
|
|
private void ck_kllb_fjzt_CheckedChanged(object sender, EventArgs e)
|
|
|
{
|