using Microsoft.Office.Interop.Excel; using NPOI.SS.UserModel; using System.Data; using System.Net; using System.Text.RegularExpressions; using YieldChain.Helpers; using YLErp.BLL; using YLErp.Commons; using YLErp.DBModels; using YLErp.DBModels.Consts; using YLErp.DBModels.Enums; using YLErp.Models; using YLErp.Modules.EodModule; using YLErp.Modules.SuperviseReportModule.SAC.Common; using YLErp.Modules.SuperviseReportModule.SAC.Model; using static YLErp.ConsGlobal; using static YLErp.DBModels.Consts.ConsReport; namespace YLErp.Modules.SuperviseReportModule.SAC.Service { class ReportSwapTerminationService : ReportBaseService { public ReportSwapTerminationService(OptUserInfo optUser) : base(optUser) { } protected override string _excelDataSourcePath => "交易相关\\"; protected override string _excelDataSourceFileName => "import_SwapTermination_template.xlsx"; protected override DataFlagsEnum BusiDataType => DataFlagsEnum.A1006; private List? _validOperationType = null; public override List ValidOperationType { get { _validOperationType ??= new List() { OptFlagsEnum.A, OptFlagsEnum.U, OptFlagsEnum.D, }; return _validOperationType; } } protected override SuperviseReportTypeEnum ReportType => SuperviseReportTypeEnum.SAC_SwapDurationManagement; readonly List noteList = new(); IEnumerable SACReportNotesCache = null; IEnumerable SACReportNotesCache_confirmation = null; protected override BodyModel GenerateBody(out bool noData, out List fileList) { fileList = new List(); var model = new BodyModel(); SACReportNotesCache = base.InitReportNotes(ReportType); SACReportNotesCache_confirmation = base.InitReportNotes(SuperviseReportTypeEnum.SAC_OptionConfirmation); var dataList = new List(); if (_reqInfo.DataSource.HasFlag(SAC_ReportDataSourceEnum.Template)) { dataList = GetSwapDurationManagementModel(ref fileList); } if ((PS.Config.ErpElement.SAC_ReportDataSource & SAC_ReportDataSourceEnum.System) == SAC_ReportDataSourceEnum.System) { var cacheKey = $"{BusiDataType}"; var nextDate = _reqInfo.ReportDate.AddDays(1); using (var db = new YLContext()) { dataList.AddRange(GetOptionTerminationSettlementFromDb(db, cacheKey, nextDate)); } } var subsystemDataList = loadSubsystemDataSource(fileList, AddSubsystemNote); if (subsystemDataList != null && subsystemDataList.Count > 0) { dataList.AddRange(subsystemDataList); } noData = dataList.Count == 0; model.SwapDurationManagement = dataList; return model; } private List GetOptionTerminationSettlementFromDb(YLContext db, string cacheKey, DateTime nextDate) { // 所有的交易了结事件 var valueDate = _reqInfo.ReportDate; var unwindEventList = (from a in db.swap_event join b in (from sfe in db.swap_flow_event group sfe by new { sfe.EventId, sfe.UnwindDate } into g select new { EventId = g.Key.EventId, UnwindDate = g.Key.UnwindDate }) on a.id equals b.EventId into leftJoin from b in leftJoin.DefaultIfEmpty() where a.EventType == 2 && b.UnwindDate.HasValue && b.UnwindDate.Value == valueDate.Date select new { swapTradeId = a.SwapTradeId, valueDate = b.UnwindDate, eventData = a.EventData, }).ToList(); if (unwindEventList == null || unwindEventList.Count == 0) { return new List(); } var tradeIds = unwindEventList.Select(O => O.swapTradeId).Distinct().ToList(); List dataList = new List(); // 查找交易事件 var query = (from t in db.trade.Where(O => O.TradeType == "收益互换") join cico in db.ClientCashInCashOut.Where(O => O.Action == "系统操作-平仓费") on t.id equals cico.TradeId join tr in db.trade_contract_r.Where(O => O.Type == "交易确认书" && O.IsValid) on t.id equals tr.TradeId join esp in db.eod_swap_position.Where(O => O.ValueDate.Date == _reqInfo.ReportDate.Date && !O.Invalid && O.PositionType > 0) on t.id equals esp.SwapTradeId where tradeIds.Contains(t.id) select new { tradeValid = t.ValueStatus != "InValid", tradeContractRValid = tr.IsValid, t.id, t.ClientId, t.OriginalStockEqvNotional, t.UnderlyingCode, tr.ContractCode, esp.PositionType, esp.PosiNotionalValue, esp.PosiQuantity, esp.PosiGrossPrice, cico.Money }).ToArray(); Dictionary> metaDic = DbContext.TradeMeta .Where(O => tradeIds.Contains(O.TradeId)).AsEnumerable().GroupBy(O => O.TradeId).ToDictionary(K => K.Key, V => V.ToDictionary(K1 => K1.MetaKey, V1 => V1.MetaValue)); foreach (var item in query.GroupBy(O => O.ContractCode).ToDictionary(K => K.Key, V => V.ToList())) { // 交易确认书编号 var confirmationNo = item.Key; var value = item.Value.First(); if (metaDic.ContainsKey(value.id)) { var metaInfo = metaDic[value.id]; if (metaInfo.ContainsKey(ConsTradeMetaKey.TradingPlace) && TradingPlaceMap[metaInfo[ConsTradeMetaKey.TradingPlace]] == "1") //跳过交易场所为报价系统的交易; { continue; } } var info = new SwapDurationManagementModel(); //info.TradeId = item.Key.id.ToString(); info.DurationEventNO = "0000"; info.DurationOperationDate = valueDate.ToString("yyyy-MM-dd"); info.ConfirmationNo = confirmationNo; info.OperationType = OptFlagsEnum.A; List notes = base.GetReportNotes(ReportType, $"_{info.ConfirmationNo.Replace("_", "-")}_", true); var note = notes.FirstOrDefault(O => O.IsValid && O.InfoTag.Contains(formatInfoTag(info)) && O.InfoCache.Contains(info.DurationOperationDate)); if (info.OperationType != _operationType) { continue; } switch (info.OperationType) { case OptFlagsEnum.A: note = new SACReportNotes() { IsValid = true, }; break; case OptFlagsEnum.U: note.IsValid = true; break; case OptFlagsEnum.D: note.IsValid = false; break; } if (info.OperationType != OptFlagsEnum.A) { info.BizID = note.BizId; } info.DurationOperationType = "2"; var positionTypeList = item.Value.Select(o => o.PositionType).ToList(); if (positionTypeList.Contains(1) && positionTypeList.Contains(2)) { info.SwapType = "3"; } else if (positionTypeList.Contains(1)) { info.SwapType = "1"; } else if (positionTypeList.Contains(2)) { info.SwapType = "2"; } //info.TerminationAmount = currentStockEqvNotional.ToString("0.00"); info.Balance = item.Value.Sum(O => O.PosiNotionalValue).ToString(); // 本次支付金额 info.AmountPaidThisTime = item.Value.Sum(O => O.Money).ToString(); var clientBalanceDailies = (from t in db.ClientBalanceDaily where t.ClientId == value.ClientId && t.BalanceDate == valueDate select new { t.ToDayRemainFund, t.TotalNominal, t.RoundedPositionPnl }); if (clientBalanceDailies != null) { var first = clientBalanceDailies.First(); if (first.TotalNominal != 0) { var marginRate = (first.ToDayRemainFund + first.RoundedPositionPnl) * 100 / first.TotalNominal; if (marginRate > 100) { info.MarginRatio = "100"; } else { info.MarginRatio = marginRate?.ToString("0.00"); } } } var list = item.Value.Select(O => O.id).Distinct().ToList(); var eventDataList = unwindEventList.Where(O => list.Contains(O.swapTradeId)).Select(O => O.eventData).ToList(); if (eventDataList != null && eventDataList.Count > 0) { double closeNotionalSum = 0; foreach (var ed in eventDataList) { try { // 假设 eventData 是 JSON 字符串,尝试解析并获取 CloseNotionalValue var jsonDoc = System.Text.Json.JsonDocument.Parse(ed); if (jsonDoc.RootElement.TryGetProperty("CloseNotionalValue", out var closeNotionalElement)) { if (closeNotionalElement.ValueKind == System.Text.Json.JsonValueKind.Number) { closeNotionalSum += closeNotionalElement.GetDouble(); } else if (closeNotionalElement.ValueKind == System.Text.Json.JsonValueKind.String) { if (double.TryParse(closeNotionalElement.GetString(), out double val)) { closeNotionalSum += val; } } } } catch { // 忽略解析错误,避免影响主流程 } } info.ChangeAmount = closeNotionalSum.ToString("0.00"); } #region 持仓明细 if (double.TryParse(info.Balance, out var temp) && temp > 0) { var currentPosition = new CurrentPositionDetailModel(); currentPosition.UndrlygAssetCode = value.UnderlyingCode; var codeInfo = DataCacheProvider.GetUnderlyingDataSource().GetData(value.UnderlyingCode); currentPosition.UndrlygAssetTradgPlc = string.IsNullOrWhiteSpace(codeInfo.MarketName) ? "其他" : codeInfo.MarketName; if (SwapUndrlygAssetDtldTypeMap.TryGetValue( ConsGlobal.InstrumentType.GetDesc(codeInfo.UnderlyingInstrumentType), out var AssetDtldType)) { currentPosition.UndrlygAssetDtldType = AssetDtldType; } else { currentPosition.UndrlygAssetDtldType = UndrlygAssetDtldTypeMap["其他标的"]; } currentPosition.UndrlygAssetName = codeInfo.UnderlyingName; currentPosition.InvestorPosition = info.SwapType; currentPosition.UndrlygAssetAmt = value.PosiQuantity.ToString("0"); currentPosition.ContractMultiplier = codeInfo.ContractSize.ToString("0"); currentPosition.UndrlygAssetPrice = value.PosiGrossPrice.ToString("0.##"); currentPosition.NotinalPrincipleAmt = value.PosiNotionalValue.ToString("0.##"); info.CurrentPositionDetails = new List() { currentPosition }; } #endregion info.ExceID = base.formatExceID(); ReportStatus.AddCacheInfo(cacheKey, confirmationNo); foreach (var swapTradeId in list) { ReportStatus.AddCacheInfo($"{cacheKey}_{info.ConfirmationNo}_{_operationType}", swapTradeId.ToString()); } dataList.Add(info); note.id = 0; note.ExceId = info.ExceID; note.InfoCache = $"{{\"Tag\":\"{info.ConfirmationNo}\",\"ValueDate\":\"{info.DurationOperationDate}\",\"DurationEventNO\":\"{info.DurationEventNO}\",\"Source\":\"System\"}}"; note.CreateTime = DateTime.Now; note.FileTag = FileTag; note.ReportType = ReportType; note.ReportDate = valueDate; note.InfoTag = formatInfoTag(info, true); note.OptTime = note.CreateTime; note.RetCode = ""; note.RetMsg = ""; note.ReportResponse = false; note.BizId = ""; note.DataId = ""; note.changeStatus = false; noteList.Add(note); } return dataList; } public bool AddSubsystemNote(SwapDurationManagementModel model, List fileList, string tag) { SACReportNotes note = base .GetReportNotes(ReportType, formatInfoTag(model, true), dataSource: SACReportNotesCache) .FirstOrDefault(); //参数true要加,要不A和D会查到同一条记录,在D时候,就会和A相同的数据 var isExtensionTime = model.DurationOperationType == ConsReport.SwapOperationTypeMap["展期"]; var date = DateTime.MinValue; if (isExtensionTime) { DateTime.TryParse(model.RenewalDate, out date); } else { DateTime.TryParse(model.DurationOperationDate, out date); } if (note == null) { if (isExtensionTime) { var oldDateStr = ""; var oldData = base.GetReportNotes(SuperviseReportTypeEnum.SAC_OptionConfirmation, $"A1005_{model.ConfirmationNo.Replace("_", "-")}_成交_A", dataSource: SACReportNotesCache_confirmation).FirstOrDefault(); oldDateStr = Regex.Match(oldData?.InfoCache ?? "", "(?<=DueDate\":\")[^\"]+(?=\")").Value; if (DateTime.TryParse(oldDateStr, out var oldDate)) { oldDateStr = $",\"OldMaturityDate\":\"{oldDate.ToString("yyyy-MM-dd")}\""; } note = new SACReportNotes() { InfoCache = $"{{\"Tag\":\"{model.ConfirmationNo}\"{oldDateStr},\"NewMaturityDate\":\"{date.ToString("yyyy-MM-dd")}\",\"DurationEventNO\":\"{model.DurationEventNO}\",\"Source\":\"Subsystem\",\"SubFileTag\":\"{tag}\",\"ExceID\":\"{model.ExceID}\"}}", IsValid = true, }; } else { note = new SACReportNotes() { InfoCache = $"{{\"Tag\":\"{model.ConfirmationNo}\",\"ValueDate\":\"{date.ToString("yyyy-MM-dd")}\",\"DurationEventNO\":\"{model.DurationEventNO}\",\"Source\":\"Subsystem\",\"SubFileTag\":\"{tag}\",\"ExceID\":\"{model.ExceID}\"}}", IsValid = true, }; } } else { switch (_operationType) { case OptFlagsEnum.A: return false; //新增数据已报送,跳过 case OptFlagsEnum.U: if (isExtensionTime) { var oldDateStr = ""; var oldData = base.GetReportNotes(SuperviseReportTypeEnum.SAC_OptionConfirmation, $"A1005_{model.ConfirmationNo.Replace("_", "-")}_成交_A", dataSource: SACReportNotesCache_confirmation).FirstOrDefault(); oldDateStr = Regex.Match(oldData?.InfoCache ?? "", "(?<=DueDate\":\")[^\"]+(?=\")").Value; if (DateTime.TryParse(oldDateStr, out var oldDate)) { oldDateStr = $",\"OldMaturityDate\":\"{oldDate.ToString("yyyy-MM-dd")}\""; } note.InfoCache = $"{{\"Tag\":\"{model.ConfirmationNo}\"{oldDateStr},\"NewMaturityDate\":\"{date.ToString("yyyy-MM-dd")}\",\"DurationEventNO\":\"{model.DurationEventNO}\",\"Source\":\"Subsystem\",\"SubFileTag\":\"{tag}\",\"ExceID\":\"{model.ExceID}\"}}"; } else { note.InfoCache = $"{{\"Tag\":\"{model.ConfirmationNo}\",\"ValueDate\":\"{date.ToString("yyyy-MM-dd")}\",\"DurationEventNO\":\"{model.DurationEventNO}\",\"Source\":\"Subsystem\",\"SubFileTag\":\"{tag}\",\"ExceID\":\"{model.ExceID}\"}}"; } note.IsValid = true; break; case OptFlagsEnum.D: note.IsValid = false; break; case OptFlagsEnum.NONE: default: throw new ServiceException("未知操作类型"); } } if (!string.IsNullOrWhiteSpace(model.SwapDurationManagementAtt)) { fileList.Add(model.SwapDurationManagementAtt); } var extensionTimeInfo = isExtensionTime ? "-" : ""; model.ExceID = base.formatExceID(SACReportNotesCache); note.id = 0; note.ExceId = model.ExceID; note.CreateTime = DateTime.Now; note.FileTag = FileTag; note.ReportType = ReportType; note.ReportDate = _reqInfo.ReportDate; note.InfoTag = formatInfoTag(model, true, extensionTimeInfo); note.OptTime = note.CreateTime; note.RetCode = ""; note.RetMsg = ""; note.ReportResponse = false; note.BizId = ""; note.changeStatus = false; noteList.Add(note); return true; } private List GetSwapDurationManagementModel(ref List fileList) { fileList = new List(); var result = new List(); if (_excelDataSource != null && _excelDataSource.Tables.Contains("互换交易存续期明细")) { var sourcePath = Path.Combine(_excelDataSourceRootPath, "附件"); var dt = _excelDataSource.Tables["互换交易存续期明细"]; for (var i = 1; i < dt.Rows.Count; i++) { if (string.IsNullOrWhiteSpace(dt.Rows[i][0]?.ToString())) { //第一列空白说明数据结束了; break; } var optType = OptFlagsEnum.NONE; switch (dt.Rows[i][1]?.ToString()) { case "0": case "A": case "首次": optType = OptFlagsEnum.A; break; case "1": case "U": case "变更": optType = OptFlagsEnum.U; break; case "2": case "D": case "废止": optType = OptFlagsEnum.D; break; } if (optType != _operationType) { continue; } var model = new SwapDurationManagementModel { ConfirmationNo = GetDataSetValue(dt, i, 0), OperationType = optType, SwapType = ConsReport.SwapTypeMap[GetDataSetValue(dt, i, 2)], DurationEventNO = GetDataSetValue(dt, i, 3), DurationOperationType = ConsReport.SwapOperationTypeMap[GetDataSetValue(dt, i, 4)], DurationOperationDate = GetDataSetValue(dt, i, 5), RenewalDate = GetDataSetValue(dt, i, 6), DefaultingParty = ConsReport.FillPartyMap[GetDataSetValue(dt, i, 7)], DefaultEvent = GetDataSetValue(dt, i, 8), ChangeAmount = GetDataSetValue(dt, i, 9), Balance = GetDataSetValue(dt, i, 10), AmountPaidThisTime = GetDataSetValue(dt, i, 11), MarginRatio = GetDataSetValue(dt, i, 12), SwapDurationManagementAtt = GetDataSetValue(dt, i, 13), Blank1 = GetDataSetValue(dt, i, 14), Blank2 = GetDataSetValue(dt, i, 15) }; var isExtensionTime = model.DurationOperationType == ConsReport.SwapOperationTypeMap["展期"]; var date = DateTime.MinValue; if (isExtensionTime) { DateTime.TryParse(model.RenewalDate, out date); } else { DateTime.TryParse(model.DurationOperationDate, out date); } var cacheValue = $"{model.ConfirmationNo}_{model.DurationEventNO}_"; if (ReportStatus.CheckCacheInfo(CacheKey, cacheValue)) { continue; } if (!string.IsNullOrWhiteSpace(model.SwapDurationManagementAtt)) { var path = Path.Combine(sourcePath, model.SwapDurationManagementAtt); if (!ReportStatus.CheckFileLength(path)) { break; } fileList.Add(path); } var extensionTimeInfo = isExtensionTime ? "-" : ""; List notes = base.GetReportNotes(ReportType, $"_{model.ConfirmationNo.Replace("_", "-")}_", true, SACReportNotesCache); //永远查找现有成功报送了结的新增记录,而不是修改; var note = notes.LastOrDefault(O => O.IsValid && O.InfoTag.Contains(formatInfoTag(model, extensionTimeInfo: extensionTimeInfo)) && O.InfoCache.Contains(date.ToString("yyyy-MM-dd"))); if (note == null && _operationType == OptFlagsEnum.A) { if (isExtensionTime) { var oldDateStr = ""; var oldData = base.GetReportNotes(SuperviseReportTypeEnum.SAC_OptionConfirmation, $"A1005_{model.ConfirmationNo.Replace("_", "-")}_成交_A", dataSource: SACReportNotesCache_confirmation).FirstOrDefault(); oldDateStr = Regex.Match(oldData?.InfoCache ?? "", "(?<=DueDate\":\")[^\"]+(?=\")").Value; if (DateTime.TryParse(oldDateStr, out var oldDate)) { oldDateStr = $",\"OldMaturityDate\":\"{oldDate.ToString("yyyy-MM-dd")}\""; } note = new SACReportNotes() { InfoCache = $"{{\"Tag\":\"{model.ConfirmationNo}\"{oldDateStr},\"NewMaturityDate\":\"{date.ToString("yyyy-MM-dd")}\",\"DurationEventNO\":\"{model.DurationEventNO}\",\"Source\":\"Template\"}}", IsValid = true, }; } else { note = new SACReportNotes() { InfoCache = $"{{\"Tag\":\"{model.ConfirmationNo}\",\"ValueDate\":\"{date.ToString("yyyy-MM-dd")}\",\"DurationEventNO\":\"{model.DurationEventNO}\",\"Source\":\"Template\"}}", IsValid = true, }; } } else { if (note == null) { continue; } switch (_operationType) { case OptFlagsEnum.A: continue; //新增数据已报送,跳过 case OptFlagsEnum.U: note.IsValid = true; break; case OptFlagsEnum.D: note.IsValid = false; break; case OptFlagsEnum.NONE: default: throw new ServiceException("未知操作类型"); } note.InfoCache = Regex.Replace(note.InfoCache, "(?<=NewMaturityDate\":\")[^\"]+ (?= \")", date.ToString("yyyy-MM-dd")); } model.CurrentPositionDetails = GetCurrentPositionDetailsModel(model.ConfirmationNo); if (model.OperationType != OptFlagsEnum.A) { model.BizID = note.BizId; } model.ExceID = base.formatExceID(SACReportNotesCache); result.Add(model); ReportStatus.AddCacheInfo(CacheKey, cacheValue); note.id = 0; note.ExceId = model.ExceID; note.CreateTime = DateTime.Now; note.FileTag = FileTag; note.ReportType = ReportType; note.ReportDate = _reqInfo.ReportDate; note.InfoTag = formatInfoTag(model, true, extensionTimeInfo); note.OptTime = note.CreateTime; note.RetCode = ""; note.RetMsg = ""; note.ReportResponse = false; note.BizId = ""; note.DataId = ""; note.changeStatus = false; noteList.Add(note); } } return result; } private List GetCurrentPositionDetailsModel(string confirmationNo) { var result = new List(); if (_excelDataSource != null && _excelDataSource.Tables.Contains("合约持仓明细")) { var dt = _excelDataSource.Tables["合约持仓明细"]; for (var i = 1; i < dt.Rows.Count; i++) { if (string.IsNullOrWhiteSpace(dt.Rows[i][0]?.ToString())) { //第一列空白说明数据结束了; break; } if (dt.Rows[i][0]?.ToString().Trim() != confirmationNo) { continue; } var model = new CurrentPositionDetailModel { UndrlygAssetCode = GetDataSetValue(dt, i, 1), UndrlygAssetDtldType = ConsReport.SwapUndrlygAssetDtldTypeMap[GetDataSetValue(dt, i, 2)], UndrlygAssetName = GetDataSetValue(dt, i, 3), UndrlygAssetTradgPlc = GetDataSetValue(dt, i, 4), UndrlygAssetPrice = GetDataSetValue(dt, i, 5), InvestorPosition = ConsReport.SwapTypeMap[GetDataSetValue(dt, i, 6)], UndrlygAssetAmt = GetDataSetValue(dt, i, 7), ContractMultiplier = GetDataSetValue(dt, i, 8), NotinalPrincipleAmt = GetDataSetValue(dt, i, 9), Blank1 = GetDataSetValue(dt, i, 10), Blank2 = GetDataSetValue(dt, i, 11) }; result.Add(model); } } return result; } private string formatInfoTag(SwapDurationManagementModel model, bool suffixType = false, string extensionTimeInfo = "") { var result = $"{BusiDataType}_{model.ConfirmationNo.Replace("_", "-")}_{(string.IsNullOrWhiteSpace(extensionTimeInfo) ? "了结" : $"_{extensionTimeInfo}_展期")}_{model.DurationEventNO}_"; if (suffixType) { result = $"{result}{_operationType}"; } return result; } protected override string _changeCodeOfInfoTag(string infoTag, string newCode, out string originalCode) { var arr = infoTag.Split('_'); if (arr.Length != 5 && arr.Length != 6) { throw new ServiceException($"InfoTag信息不匹配:{infoTag}"); } originalCode = arr[1]; arr[1] = newCode.Replace("_", "-"); return string.Join("_", arr); } protected override List CheckBodyValue(BodyModel model, out bool checkStatus) { var result = new List(); if (model?.SwapDurationManagement != null) { var helper = new CheckHelper(); var positionhelper = new CheckHelper(); for (var i = 0; i < model.SwapDurationManagement.Count; i++) { var listRoot = new List(); var item = model.SwapDurationManagement[i]; if (item.IgnoreCheck) { continue; } helper.ExecuteCheck(item, (name, value, msg) => { listRoot.Add(new SacInfo(name, value, msg)); }); if (item.CurrentPositionDetails != null) { for (var j = 0; j < item.CurrentPositionDetails.Count; j++) { var attList = new List(); var attItem = item.CurrentPositionDetails[j]; positionhelper.ExecuteCheck(attItem, (name, value, msg) => { attList.Add(new SacInfo(name, value, msg)); }); if (attList.Count > 0) { var temp = new SacInfo("CurrentPositionDetails", j) { SubMaps = new List(attList) }; listRoot.Add(temp); } } } if (listRoot.Count > 0) { var errMsg = new SacInfo("SwapDurationManagement", i) { FieldValue = item.ConfirmationNo, SubMaps = new List(listRoot) }; result.Add(errMsg); } } } checkStatus = result.Count > 0; return result; } public override bool BeforeOfGenerated(out string errMsg) { errMsg = ""; foreach (var file in xmlAttachmentList) { try { File.Delete(file); } catch (Exception e) { LogFactory.GetLogger().Error(e); } } for (var i = 0; i < noteList.Count; i++) { base.SaveReportNotes(noteList[i]); } return true; } } }