namespace SHJX.Service.Control.Service { public class TemplateService : ITemplateService { private readonly IDataManager _dataManager; private readonly ReadConfigUtil _readConfig; public TemplateService(IDataManager dataManager, ReadConfigUtil readConfig) { _dataManager = dataManager; _readConfig = readConfig; } public List GetData() where T : class { return _dataManager.Query().ToList(); } public List GetSampleDetailsByState() { return _dataManager.Query().Where(it => it.TaskStatus.Equals(DetailState.New)).ToList(); } public List GetSampleDetailsByTemplate() { if (string.IsNullOrWhiteSpace(_readConfig.TemplateFilePath)) { UMessageBox.Error("模板路径为空,无法进行保存与导入!"); return null; } if (!File.Exists(_readConfig.TemplateFilePath)) { UMessageBox.Error("本地模板不存在!"); return null; } return _readConfig.TemplateFilePath.ReadExcel().ConvertToList(); } public void SaveTemplate(List details) { if (string.IsNullOrWhiteSpace(_readConfig.TemplateFilePath)) { UMessageBox.Error($"导出模板失败,模板路径为空!"); return; } DataTable dt = new("Template"); dt.Columns.Add("节点名称", Type.GetType("System.String")!); dt.Columns.Add("详细描述", Type.GetType("System.String")!); dt.Columns.Add("取样体积", Type.GetType("System.Double")!); dt.Columns.Add("取样倍数", Type.GetType("System.Double")!); dt.Columns.Add("样品类型", Type.GetType("System.String")!); dt.Columns.Add("酸碱性", Type.GetType("System.String")!); dt.Columns.Add("是否标定", Type.GetType("System.Boolean")!); details.ForEach(item => { dt.Rows.Add(item.NodeName, item.DetailInfo, item.SampleVolume, item.SampleMultiple, item.SampleType, item.AcidBaseProp, item.IsCalibration); }); dt.ConvertToExcel(_readConfig.TemplateFilePath); } public bool UpdateSampleDetails(List details) { return _dataManager.Update(details) > 0; } } }