diff --git a/AutoWeightServer/Center/DeviceCenter.cs b/AutoWeightServer/Center/DeviceCenter.cs index 83276cd..ed865d6 100644 --- a/AutoWeightServer/Center/DeviceCenter.cs +++ b/AutoWeightServer/Center/DeviceCenter.cs @@ -318,7 +318,7 @@ namespace EC.AutoWeightServer.Center return; YkPosManager.InitPrinter(); - var bmpPath = Path.Combine(Directory.GetCurrentDirectory(), Path.Combine("Img", "logo.bmp")); + var bmpPath = Path.Combine(CommonUtil.GetWorkDirectory(), Path.Combine("Img", "logo.bmp")); YkPosManager.SetAlign(1);//居中 YkPosManager.PrintRasterBmp(new StringBuilder(bmpPath));//打印图片 diff --git a/AutoWeightServer/UI/FrmMainServer.cs b/AutoWeightServer/UI/FrmMainServer.cs index 9deb630..3aa2140 100644 --- a/AutoWeightServer/UI/FrmMainServer.cs +++ b/AutoWeightServer/UI/FrmMainServer.cs @@ -994,7 +994,7 @@ namespace EC.AutoWeightServer.UI private void CheckPhotoSaveCycle() { var now = DateTime.Now; - var workPath = Directory.GetCurrentDirectory(); + var workPath = CommonUtil.GetWorkDirectory(); var capDir = new DirectoryInfo(Path.Combine(workPath, "cap")); if (!capDir.Exists) return; diff --git a/EC.Service/Transport/PhotoService.cs b/EC.Service/Transport/PhotoService.cs index f89e028..061a7f9 100644 --- a/EC.Service/Transport/PhotoService.cs +++ b/EC.Service/Transport/PhotoService.cs @@ -1,5 +1,6 @@ using EC.Entity.Transport; using EC.Service.Base; +using EC.Utils; using System; using System.IO; @@ -39,7 +40,7 @@ namespace EC.Service.Transport public static string GetSaveImagePath(string license) { var now = DateTime.Now; - var workPath = Directory.GetCurrentDirectory(); + var workPath = CommonUtil.GetWorkDirectory(); var subPath = Path.Combine(new string[] { "cap", now.ToString("yyyy"), now.ToString("MM"), now.ToString("dd") }); //var subPath = Path.Combine("cap", now.ToString("yyyy-MM-dd")); var fileFolder = Path.Combine(workPath, subPath); diff --git a/EC.Utils/CommonUtil.cs b/EC.Utils/CommonUtil.cs index 6fb16c4..8f9fd6d 100644 --- a/EC.Utils/CommonUtil.cs +++ b/EC.Utils/CommonUtil.cs @@ -2,6 +2,7 @@ using Newtonsoft.Json.Linq; using System; using System.IO; +using System.Reflection; using System.Text.RegularExpressions; namespace EC.Utils @@ -216,5 +217,14 @@ namespace EC.Utils return null; } } + + private static string workDirectory; + + public static string GetWorkDirectory() + { + workDirectory = string.IsNullOrEmpty(workDirectory) ? Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) :workDirectory; + return workDirectory; + } + } } \ No newline at end of file