Я снова здесь

This commit is contained in:
gg12 darfren 2024-05-21 20:51:12 +04:00
parent 99ca054c53
commit ae96bb65a2
9 changed files with 323 additions and 1 deletions

View File

@ -85,5 +85,43 @@ namespace VetClinicBusinessLogic.BusinessLogics
ServicesAnimals = GetServiceAnimals(model.Services)
});
}
public List<VisitGuidesSearchModel> GetMedicineVisitsAndGuidances(List<int> services)
{
List<VisitGuidesSearchModel> ans = new();
List<Tuple<ServiceViewModel, List<Tuple<MedicineViewModel, List<AnimalViewModel>>>>> response =
_serviceStorage.GetReportInfo(new ListAnimalsSearchModel { servicesIds = services });
foreach (var service in response)
{
Dictionary<int, (AnimalViewModel, int)> counter = new();
foreach (var medicine in service.Item2)
{
foreach (var animal in medicine.Item2)
{
if (!counter.ContainsKey(animal.Id))
counter.Add(animal.Id, (animal, 1));
else
{
counter[animal.Id] = (counter[animal.Id].Item1, counter[animal.Id].Item2 + 1);
}
}
}
List<AnimalViewModel> res = new();
foreach (var cnt in counter)
{
if (cnt.Value.Item2 != service.Item2.Count)
continue;
res.Add(cnt.Value.Item1);
}
ans.Add(new ListAnimalsViewModel
{
ServiceName = service.Item1.ServiceName,
Animals = res
});
}
return ans;
}
}
}

View File

@ -0,0 +1,105 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VetClinicBusinessLogic.OfficePackage.HelperEnums;
using VetClinicBusinessLogic.OfficePackage.HelperModels;
using VetClinicDataBaseImplement.Implements;
namespace VetClinicBusinessLogic.OfficePackage
{
public abstract class AbstractSaveToPdfPharmacist
{
public void CreateDoc(PdfInfo info)
{
CreatePdf(info);
CreateParagraph(new PdfParagraph
{
Text = info.Title,
Style =
"NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
CreateParagraph(new PdfParagraph
{
Text = $"с { info.DateFrom.ToShortDateString() } по { info.DateTo.ToShortDateString() }", Style
= "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
CreateTable(new List<string> { "2cm", "3cm", "6cm", "3cm" });
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "Номер", "Дата заказа", "Изделие",
"Сумма" },
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
foreach (var medicine in info.Medicines)
{
CreateParagraph(new PdfParagraph
{
Text = medicine.MedicineName,
Style
= "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
CreateParagraph(new PdfParagraph
{
Text = "Визиты",
Style
= "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});
CreateTable(new List<string> { "4cm", "4cm", "6cm" });
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "Номер", "Дата визита", "Навзание визита"},
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
foreach(var visit in medicine.Visits)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string> { visit.Id.ToString(), visit.DateVisit.ToString(), visit.NameVisit},
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
}
CreateParagraph(new PdfParagraph
{
Text = "Рекомендации",
Style
= "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
CreateTable(new List<string> { "4cm", "4cm", "6cm" });
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "Номер", "Дата рекомендации", "Название услуги" },
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
foreach (var guidance in medicine.Guidances)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string> { guidance.Id.ToString(), guidance.Date.ToString(), guidance.ServiceName },
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
}
}
SavePdf(info);
}
protected abstract void CreatePdf(PdfInfo info);
protected abstract void CreateParagraph(PdfParagraph paragraph);
protected abstract void CreateTable(List<string> columns);
protected abstract void CreateRow(PdfRowParameters rowParameters);
protected abstract void SavePdf(PdfInfo info);
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VetClinicBusinessLogic.OfficePackage.HelperEnums
{
public enum PdfParagraphAlignmentType
{
Center,
Left,
Rigth
}
}

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VetClinicDataBaseImplement.Implements;
namespace VetClinicBusinessLogic.OfficePackage.HelperModels
{
public class PdfInfo
{
public string FileName { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public DateTime DateFrom { get; set; }
public DateTime DateTo { get; set; }
public List<VisitsGuidesViewModel> Medicines { get; set; } = new();
}
}

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VetClinicBusinessLogic.OfficePackage.HelperEnums;
namespace VetClinicBusinessLogic.OfficePackage.HelperModels
{
public class PdfParagraph
{
public string Text { get; set; } = string.Empty;
public string Style { get; set; } = string.Empty;
public PdfParagraphAlignmentType ParagraphAlignment { get; set; }
}
}

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VetClinicBusinessLogic.OfficePackage.HelperEnums;
namespace VetClinicBusinessLogic.OfficePackage.HelperModels
{
public class PdfRowParameters
{
public List<string> Texts { get; set; } = new();
public string Style { get; set; } = string.Empty;
public PdfParagraphAlignmentType ParagraphAlignment { get; set; }
}
}

View File

@ -0,0 +1,107 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VetClinicBusinessLogic.OfficePackage.HelperEnums;
using VetClinicBusinessLogic.OfficePackage.HelperModels;
using MigraDoc.DocumentObjectModel;
using MigraDoc.DocumentObjectModel.Tables;
using MigraDoc.Rendering;
namespace VetClinicBusinessLogic.OfficePackage.Implements
{
public class SaveToPdfPharmacist : AbstractSaveToPdfPharmacist
{
private Document? _document;
private Section? _section;
private Table? _table;
private static ParagraphAlignment
GetParagraphAlignment(PdfParagraphAlignmentType type)
{
return type switch
{
PdfParagraphAlignmentType.Center => ParagraphAlignment.Center,
PdfParagraphAlignmentType.Left => ParagraphAlignment.Left,
PdfParagraphAlignmentType.Rigth => ParagraphAlignment.Right,
_ => ParagraphAlignment.Justify,
};
}
/// <summary>
/// Создание стилей для документа
/// </summary>
/// <param name="document"></param>
private static void DefineStyles(Document document)
{
var style = document.Styles["Normal"];
style.Font.Name = "Times New Roman";
style.Font.Size = 14;
style = document.Styles.AddStyle("NormalTitle", "Normal");
style.Font.Bold = true;
}
protected override void CreatePdf(PdfInfo info)
{
_document = new Document();
DefineStyles(_document);
_section = _document.AddSection();
}
protected override void CreateParagraph(PdfParagraph pdfParagraph)
{
if (_section == null)
{
return;
}
var paragraph = _section.AddParagraph(pdfParagraph.Text);
paragraph.Format.SpaceAfter = "1cm";
paragraph.Format.Alignment =
GetParagraphAlignment(pdfParagraph.ParagraphAlignment);
paragraph.Style = pdfParagraph.Style;
}
protected override void CreateTable(List<string> columns)
{
if (_document == null)
{
return;
}
_table = _document.LastSection.AddTable();
foreach (var elem in columns)
{
_table.AddColumn(elem);
}
}
protected override void CreateRow(PdfRowParameters rowParameters)
{
if (_table == null)
{
return;
}
var row = _table.AddRow();
for (int i = 0; i < rowParameters.Texts.Count; ++i)
{
row.Cells[i].AddParagraph(rowParameters.Texts[i]);
if (!string.IsNullOrEmpty(rowParameters.Style))
{
row.Cells[i].Style = rowParameters.Style;
}
Unit borderWidth = 0.5;
row.Cells[i].Borders.Left.Width = borderWidth;
row.Cells[i].Borders.Right.Width = borderWidth;
row.Cells[i].Borders.Top.Width = borderWidth;
row.Cells[i].Borders.Bottom.Width = borderWidth;
row.Cells[i].Format.Alignment =
GetParagraphAlignment(rowParameters.ParagraphAlignment);
row.Cells[i].VerticalAlignment = VerticalAlignment.Center;
}
}
protected override void SavePdf(PdfInfo info)
{
var renderer = new PdfDocumentRenderer(true)
{
Document = _document
};
renderer.RenderDocument();
renderer.PdfDocument.Save(info.FileName);
}
}
}

View File

@ -16,6 +16,7 @@
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.NETCore.App" Version="2.1.30" />
<PackageReference Include="NPOI" Version="2.7.0" />
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
</ItemGroup>
<ItemGroup>

View File

@ -5,13 +5,16 @@ using System.Text;
using System.Threading.Tasks;
using VetClinicContracts.BindingModels;
using VetClinicContracts.ViewModels;
using VetClinicDataBaseImplement.Implements;
namespace VetClinicContracts.BusinessLogicsContracts
{
public interface IReportLogicPharmacist //Будет дорабатываться
public interface IReportLogicPharmacist
{
List<ListAnimalsViewModel> GetServiceAnimals(List<int> services);
void SaveAnimalsToWordFile(ListAnimalsBindingModel model);
void SaveAnimalsToExcelFile(ListAnimalsBindingModel model);
List<ListAnimalsViewModel> GetMedicineVisitsAndGuidances(List<int> services);
void SaveMedicinesToPdfFile(VisitsGuidesBindingModel model);
}
}