Vetirinary

This commit is contained in:
danilafilippov7299 2024-05-30 07:33:38 +04:00
parent 2f9be550e0
commit a21ad80f7c
249 changed files with 85030 additions and 0 deletions

View File

@ -1,2 +1,3 @@
# PIbd-22_Filippov_D.S._Bar_CourseWork_veterinary # PIbd-22_Filippov_D.S._Bar_CourseWork_veterinary
Курсовая работа по дисциплине "Разработка профессиональных приложений". Тема курсовой работы: "Ветклиника «Айболит». Работник" Филиппов Д. С.

View File

@ -0,0 +1,126 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VeterinaryContracts.BusinessLogicContracts;
using VeterinaryContracts.BindingModels;
using VeterinaryContracts.SearchModels;
using VeterinaryContracts.StorageContracts;
using VeterinaryContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System.Text.RegularExpressions;
namespace VeterinaryBusinessLogic.BusinessLogic
{
public class DoctorLogic : IDoctorLogic
{
private readonly ILogger _logger;
private readonly IDoctorStorage _doctorStorage;
public DoctorLogic(ILogger<DoctorLogic> logger, IDoctorStorage doctorStorage)
{
_logger = logger;
_doctorStorage = doctorStorage;
}
public List<DoctorViewModel>? ReadList(DoctorSearchModel? model)
{
_logger.LogInformation("ReadList. DoctorFIO:{DoctorFIO}. Id:{ Id}", model?.DoctorFIO, model?.Id);
var list = model == null ? _doctorStorage.GetFullList() : _doctorStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public DoctorViewModel? ReadElement(DoctorSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. DoctorFIO:{DoctorFIO}.Id:{ Id}", model.DoctorFIO, model.Id);
var element = _doctorStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public bool Create(DoctorBindingModel model)
{
CheckModel(model);
if (_doctorStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(DoctorBindingModel model)
{
CheckModel(model);
if (_doctorStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(DoctorBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_doctorStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(DoctorBindingModel model, bool withParams =
true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.DoctorFIO))
{
throw new ArgumentNullException("Нет ФИО кладовщика",
nameof(model.DoctorFIO));
}
if (string.IsNullOrEmpty(model.Login))
{
throw new ArgumentNullException("Нет Login кладовщика",
nameof(model.Login));
}
if (!Regex.IsMatch(model.Login, @"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$"))
{
throw new ArgumentException("Некорретно введен email клиента", nameof(model.Login));
}
if (string.IsNullOrEmpty(model.Password))
{
throw new ArgumentNullException("Нет пароля кладовщика",
nameof(model.Password));
}
_logger.LogInformation("Doctor. DoctorFIO:{DoctorFIO}." +
"Login:{ Login}. Password:{ Password}. Id: { Id} ", model.DoctorFIO, model.Login, model.Password, model.Id);
var element = _doctorStorage.GetElement(new DoctorSearchModel
{
Login = model.Login,
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Кладовщик с таким же логином уже существует");
}
}
}
}

View File

@ -0,0 +1,121 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VeterinaryContracts.BusinessLogicContracts;
using VeterinaryContracts.BindingModels;
using VeterinaryContracts.SearchModels;
using VeterinaryContracts.StorageContracts;
using VeterinaryContracts.ViewModels;
using Microsoft.Extensions.Logging;
using VeterinaryDataModels;
namespace VeterinaryBusinessLogic.BusinessLogic
{
public class DrugLogic : IDrugLogic
{
private readonly ILogger _logger;
private readonly IDrugStorage _drugStorage;
public DrugLogic(ILogger<DrugLogic> logger, IDrugStorage drugStorage)
{
_logger = logger;
_drugStorage = drugStorage;
}
public List<DrugViewModel>? ReadList(DrugSearchModel? model)
{
_logger.LogInformation("ReadList. DrugName:{DrugName}.Id:{ Id}", model?.DrugName, model?.Id);
var list = model == null ? _drugStorage.GetFullList() : _drugStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public DrugViewModel? ReadElement(DrugSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. DrugName:{DrugName}.Id:{ Id}", model.DrugName, model.Id);
var element = _drugStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public bool Create(DrugBindingModel model)
{
CheckModel(model);
if (_drugStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(DrugBindingModel model)
{
CheckModel(model);
if (_drugStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(DrugBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_drugStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(DrugBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.DrugName))
{
throw new ArgumentNullException("Нет названия рекомендации", nameof(model.DrugName));
}
if (model.Count <= 0)
{
throw new ArgumentNullException("Рекомендаций должно быть больше нуля", nameof(model.Count));
}
if (model.Price < 0)
{
throw new ArgumentNullException("Цена рекомендации должна быть больше 0", nameof(model.Price));
}
_logger.LogInformation("Drug. DrugName:{DrugName}.Count:{ Count}.Price:{ Price}. Id: { Id}", model.DrugName,model.Count, model.Price, model.Id);
var element = _drugStorage.GetElement(new DrugSearchModel
{
DrugName = model.DrugName
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Рекомендация с таким названием уже есть");
}
}
public bool MakeSell(DrugBindingModel drug, int count)
{
return _drugStorage.SellDrugs(drug, count);
}
}
}

View File

@ -0,0 +1,114 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VeterinaryContracts.BusinessLogicContracts;
using VeterinaryContracts.BindingModels;
using VeterinaryContracts.SearchModels;
using VeterinaryContracts.StorageContracts;
using VeterinaryContracts.ViewModels;
namespace VeterinaryBusinessLogic.BusinessLogic
{
public class MedicationLogic : IMedicationLogic
{
private readonly ILogger _logger;
private readonly IMedicationStorage _medicationStorage;
public MedicationLogic(ILogger<MedicationLogic> logger, IMedicationStorage medicationStorage)
{
_logger = logger;
_medicationStorage = medicationStorage;
}
public List<MedicationViewModel>? ReadList(MedicationSearchModel? model)
{
_logger.LogInformation("ReadList. MedicationName:{MedicationName}.Id:{ Id}", model?.MedicationName, model?.Id);
var list = model == null ? _medicationStorage.GetFullList() : _medicationStorage.GetFullList()/*GetFilteredList(model)*/;
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public MedicationViewModel? ReadElement(MedicationSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. MedicationName:{MedicationName}.Id:{ Id}", model.MedicationName, model.Id);
var element = _medicationStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public bool Create(MedicationBindingModel model)
{
CheckModel(model);
if (_medicationStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(MedicationBindingModel model)
{
CheckModel(model);
if (_medicationStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(MedicationBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_medicationStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(MedicationBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.MedicationName))
{
throw new ArgumentNullException("Нет названия медикамента",
nameof(model.MedicationName));
}
if (model.Price <= 0)
{
throw new ArgumentNullException("Цена медикамента должна быть больше 0", nameof(model.Price));
}
_logger.LogInformation("Medication. MedicationName:{MedicationName}.Price:{ Price}. Id: { Id}", model.MedicationName, model.Price, model.Id);
var element = _medicationStorage.GetElement(new MedicationSearchModel
{
MedicationName = model.MedicationName
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Медикамент с таким названием уже есть");
}
}
}
}

View File

@ -0,0 +1,120 @@
using Microsoft.Extensions.Logging;
using System.Text.RegularExpressions;
using VeterinaryContracts.BindingModels;
using VeterinaryContracts.BusinessLogicContracts;
using VeterinaryContracts.SearchModels;
using VeterinaryContracts.StorageContracts;
using VeterinaryContracts.ViewModels;
namespace VeterinaryBusinessLogic.BusinessLogic
{
public class OwnerLogic : IOwnerLogic
{
private readonly ILogger _logger;
private readonly IOwnerStorage _ownerStorage;
public OwnerLogic(ILogger<OwnerLogic> logger, IOwnerStorage ownerStorage)
{
_logger = logger;
_ownerStorage = ownerStorage;
}
public List<OwnerViewModel>? ReadList(OwnerSearchModel? model)
{
_logger.LogInformation("ReadList. OwnerFIO:{OwnerFIO}. Id:{ Id}", model?.OwnerFIO, model?.Id);
var list = model == null ? _ownerStorage.GetFullList() : _ownerStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public OwnerViewModel? ReadElement(OwnerSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. OwnerFIO:{OwnerFIO}.Id:{ Id}", model.OwnerFIO, model.Id);
var element = _ownerStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public bool Create(OwnerBindingModel model)
{
CheckModel(model);
if (_ownerStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(OwnerBindingModel model)
{
CheckModel(model);
if (_ownerStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(OwnerBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_ownerStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(OwnerBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.OwnerFIO))
{
throw new ArgumentNullException("Нет ФИО клиента",
nameof(model.OwnerFIO));
}
if (string.IsNullOrEmpty(model.Login))
{
throw new ArgumentNullException("Нет Login клиента",
nameof(model.Login));
}
if (!Regex.IsMatch(model.Login, @"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$"))
{
throw new ArgumentException("Некорретно введен email клиента", nameof(model.Login));
}
if (string.IsNullOrEmpty(model.Password))
{
throw new ArgumentNullException("Нет пароля клиента",
nameof(model.Password));
}
_logger.LogInformation("Owner. OwnerFIO:{OwnerFIO}." +
"Login:{ Login}. Password:{ Password}. Id: { Id} ", model.OwnerFIO, model.Login, model.Password, model.Id);
var element = _ownerStorage.GetElement(new OwnerSearchModel
{
Login = model.Login,
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Клиент с таким логином уже есть");
}
}
}
}

View File

@ -0,0 +1,119 @@
using Microsoft.Extensions.Logging;
using VeterinaryContracts.BindingModels;
using VeterinaryContracts.BusinessLogicContracts;
using VeterinaryContracts.SearchModels;
using VeterinaryContracts.StorageContracts;
using VeterinaryContracts.ViewModels;
namespace VeterinaryBusinessLogic.BusinessLogic
{
public class PetLogic : IPetLogic
{
private readonly ILogger _logger;
private readonly IPetStorage _petStorage;
public PetLogic(ILogger<PetLogic> logger, IPetStorage
petStorage)
{
_logger = logger;
_petStorage = petStorage;
}
public List<PetViewModel>? ReadList(PetSearchModel? model)
{
_logger.LogInformation("ReadList. PetName:{PetName}. Id:{ Id}", model?.PetName, model?.Id);
var list = model == null ? _petStorage.GetFullList() : _petStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public PetViewModel? ReadElement(PetSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. PetName:{PetName}.Id:{ Id}", model.PetName, model.Id);
var element = _petStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public bool Create(PetBindingModel model)
{
CheckModel(model);
if (_petStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(PetBindingModel model)
{
CheckModel(model);
if (_petStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(PetBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_petStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(PetBindingModel model, bool withParams =
true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.PetName))
{
throw new ArgumentNullException("Нет Клички животного",
nameof(model.PetName));
}
if (string.IsNullOrEmpty(model.PetType))
{
throw new ArgumentNullException("Нет Вида животного",
nameof(model.PetType));
}
if (string.IsNullOrEmpty(model.PetBreed))
{
throw new ArgumentNullException("Нет Породы животного",
nameof(model.PetBreed));
}
if (string.IsNullOrEmpty(model.PetGender))
{
throw new ArgumentNullException("Нет Пола животного",
nameof(model.PetGender));
}
_logger.LogInformation("Pet. PetName:{PetName}." +
"PetType:{ PetType}. PetBreed:{ PetBreed}. PetGender:{ PetGender}. Id: { Id} ", model.PetName, model.PetType, model.PetBreed, model.PetGender, model.Id);
var element = _petStorage.GetElement(new PetSearchModel
{
PetName = model.PetName
});
}
}
}

View File

@ -0,0 +1,78 @@
using Microsoft.Extensions.Logging;
using VeterinaryContracts.BindingModels;
using VeterinaryContracts.BusinessLogicContracts;
using VeterinaryContracts.SearchModels;
using VeterinaryContracts.StorageContracts;
using VeterinaryContracts.ViewModels;
namespace VeterinaryBusinessLogic.BusinessLogic
{
public class PurchaseLogic : IPurchaseLogic
{
private readonly ILogger _logger;
private readonly IPurchaseStorage _purchaseStorage;
public PurchaseLogic(ILogger<PurchaseLogic> logger, IPurchaseStorage purchaseStorage)
{
_logger = logger;
_purchaseStorage = purchaseStorage;
}
public PurchaseViewModel? ReadElement(PurchaseSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. Id:{ Id}", model.Id);
var element = _purchaseStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public List<PurchaseViewModel>? ReadList(PurchaseSearchModel? model)
{
_logger.LogInformation("ReadList. Id:{ Id}", model?.Id);
var list = model == null ? _purchaseStorage.GetFullList() : _purchaseStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public bool CreatePurchase(PurchaseBindingModel model)
{
CheckModel(model);
if (_purchaseStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
private void CheckModel(PurchaseBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
//if (model.DateCreate < DateTime.Now)
//{
// throw new ArgumentNullException("Дата прививки не должна быть в прошлом", nameof(model.DateCreate));
//}
_logger.LogInformation("Purchase. DatePuchase: { DatePurchase}. Count:{ Count}. Id: { Id}", model.DateCreate, model.Count, model.Id);
}
}
}

View File

@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VeterinaryBusinessLogic.OfficePackage.Implements;
using VeterinaryContracts.BusinessLogicContracts;
using VeterinaryContracts.BindingModels;
using VeterinaryContracts.StorageContracts;
using VeterinaryContracts.ViewModels;
using VeterinaryContracts.SearchModels;
using VeterinaryBusinessLogic.OfficePackage;
using VeterinaryBusinessLogic.OfficePackage.HelperModels;
namespace VeterinaryBusinessLogic.BusinessLogic
{
public class ReportLogicDoctor : IReportLogicDoctor
{
private readonly IMedicationStorage _medicationStorage;
private readonly AbstractSaveToExcelDoctor _saveToExcel;
private readonly AbstractSaveToWordDoctor _saveToWord;
private readonly AbstractSaveToPdfDoctor _saveToPdf;
public ReportLogicDoctor( IMedicationStorage medicationStorage,
AbstractSaveToExcelDoctor saveToExcel, AbstractSaveToWordDoctor saveToWord, AbstractSaveToPdfDoctor saveToPdf)
{
_medicationStorage = medicationStorage;
_saveToExcel = saveToExcel;
_saveToWord = saveToWord;
_saveToPdf = saveToPdf;
}
public void SavePurchasesToExcelFile(ReportPurchaseMedicationBindingModel model)
{
_saveToExcel.CreateReport(new ExcelInfoDoctor
{
FileName = model.FileName,
Title = "Список покупок по медикаментам",
PurchaseMedications = GetPurchaseMedications(model)
});
}
public void SavePurchasesToWordFile(ReportPurchaseMedicationBindingModel model)
{
_saveToWord.CreateDoc(new WordInfoDoctor
{
FileName = model.FileName,
Title = "Список покупок по медикаментам",
PurchaseMedications = GetPurchaseMedications(model)
});
}
public List<ReportPurchaseMedicationViewModel> GetPurchaseMedications(ReportPurchaseMedicationBindingModel model)
{
return _medicationStorage.GetReportMedicationPurchasesList(new() { medicationsIds = model.Medications });
}
public List<ReportDrugsVisitsViewModel> GetVisitsDrugs(ReportDrugsVisitsBindingModel model)
{
return _medicationStorage.GetReportDrugsVisits(new() { DateFrom = model.DateFrom, DateTo = model.DateTo });
}
public void SaveMedicationsToPdfFile(ReportDrugsVisitsBindingModel model)
{
_saveToPdf.CreateDoc(new PdfInfo
{
FileName = model.FileName,
Title = "Список медикаментов",
DateFrom = model.DateFrom!,
DateTo = model.DateTo!,
ReportDrugsVisits = GetVisitsDrugs(model)
});
}
}
}

View File

@ -0,0 +1,101 @@
using DocumentFormat.OpenXml.EMMA;
using DocumentFormat.OpenXml.Presentation;
using VeterinaryBusinessLogic.OfficePackage;
using VeterinaryBusinessLogic.OfficePackage.HelperModels;
using VeterinaryContracts.BindingModels;
using VeterinaryContracts.BusinessLogicContracts;
using VeterinaryContracts.SearchModels;
using VeterinaryContracts.StorageContracts;
using VeterinaryContracts.ViewModels;
using VeterinaryDatabaseImplement.Implements;
namespace VeterinaryBusinessLogic.BusinessLogic
{
public class ReportLogicOwner : IReportLogicOwner
{
private readonly IPetStorage _petStorage;
private readonly AbstractSaveToExcelOwner _saveToExcel;
private readonly AbstractSaveToWordOwner _saveToWord;
private readonly AbstractSaveToPdfOwner _saveToPdf;
public ReportLogicOwner(IPetStorage petStorage,
AbstractSaveToExcelOwner saveToExcel, AbstractSaveToWordOwner saveToWord, AbstractSaveToPdfOwner saveToPdf)
{
_petStorage = petStorage;
_saveToExcel = saveToExcel;
_saveToWord = saveToWord;
_saveToPdf = saveToPdf;
}
public List<ReportServicesViewModel> GetPetServices(ReportServicesBindingModel model)
{
//List<ReportServicesViewModel> ans = new();
//List<ReportServicesViewModel> response = _serviceStorage.GetReportServices(new ReportPetsSearchModel { servicesIds = services });
//List<ReportPetsViewModel> respons = _petStorage.GetReportServices(new ReportServicesSearchModel { petsIds = pets });
//foreach (var service in response)
//{
// Dictionary<int, (PetViewModel, int)> counter = new();
// foreach (var visit in service.Services)
// {
// foreach (var pet in visit.ServiceMedications)
// {
// if (!counter.ContainsKey(pet.Id))
// counter.Add(pet.Id, (pet, 1));
// else
// {
// counter[pet.Id] = (counter[pet.Id].Item1, counter[pet.Id].Item2 + 1);
// }
// }
// }
// List<PetViewModel> res = new();
// foreach (var cnt in counter)
// {
// if (cnt.Value.Item2 != service.Count)
// continue;
// res.Add(cnt.Value.Item1);
// }
// ans.Add(new ReportPetsViewModel
// {
// ServiceName = service.Item1.ServiceName,
// Animals = res
// });
//}
//return ans;
return _petStorage.GetReportServices(new() { petsIds = model.Pets });
}
public List<ReportVisitsDrugsViewModel> GetVisitsDrugs(ReportVisitsDrugsBindingModel model)
{
return _petStorage.GetReportVisitsDrugs(new() { DateFrom = model.DateFrom, DateTo = model.DateTo });
}
public void SaveServicesToExcelFile(ReportServicesBindingModel model)
{
_saveToExcel.CreateReport(new ExcelInfoOwner
{
FileName = model.FileName,
Title = "Список услуг по животным",
PetServices = GetPetServices(model)
});
}
public void SaveServicesToWordFile(ReportServicesBindingModel model)
{
_saveToWord.CreateDoc(new WordInfoOwner
{
FileName = model.FileName,
Title = "Список услуг по животным",
PetServices = GetPetServices(model)
});
}
public void SavePetsToPdfFile(ReportVisitsDrugsBindingModel model)
{
_saveToPdf.CreateDoc(new PdfInfo
{
FileName = model.FileName,
Title = "Список визитов",
DateFrom = model.DateFrom!,
DateTo = model.DateTo!,
ReportVisitsDrugs = GetVisitsDrugs(model)
});
}
}
}

View File

@ -0,0 +1,105 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VeterinaryContracts.BusinessLogicContracts;
using VeterinaryContracts.BindingModels;
using VeterinaryContracts.SearchModels;
using VeterinaryContracts.StorageContracts;
using VeterinaryContracts.ViewModels;
namespace VeterinaryBusinessLogic.BusinessLogic
{
public class ServiceLogic : IServiceLogic
{
private readonly ILogger _logger;
private readonly IServiceStorage _serviceStorage;
public ServiceLogic(ILogger<ServiceLogic> logger, IServiceStorage serviceStorage)
{
_logger = logger;
_serviceStorage = serviceStorage;
}
public List<ServiceViewModel>? ReadList(ServiceSearchModel? model)
{
_logger.LogInformation("ReadList. ServiceName:{ServiceName}.Id:{ Id}", model?.ServiceName, model?.Id);
var list = model == null ? _serviceStorage.GetFullList() : _serviceStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public ServiceViewModel? ReadElement(ServiceSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. ServiceName:{ServiceName}.Id:{ Id}", model.ServiceName, model.Id);
var element = _serviceStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public bool Create(ServiceBindingModel model)
{
CheckModel(model);
if (_serviceStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(ServiceBindingModel model)
{
CheckModel(model);
if (_serviceStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(ServiceBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_serviceStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(ServiceBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.ServiceName))
{
throw new ArgumentNullException("Нет названия услуги", nameof(model.ServiceName));
}
_logger.LogInformation("Service. ServiceName:{ServiceName} Id: { Id}", model.ServiceName, model.Id);
var element = _serviceStorage.GetElement(new ServiceSearchModel
{
ServiceName = model.ServiceName
});
}
}
}

View File

@ -0,0 +1,131 @@
using Microsoft.Extensions.Logging;
using VeterinaryContracts.BindingModels;
using VeterinaryContracts.BusinessLogicContracts;
using VeterinaryContracts.SearchModels;
using VeterinaryContracts.StorageContracts;
using VeterinaryContracts.ViewModels;
namespace VeterinaryBusinessLogic.BusinessLogic
{
public class VisitLogic : IVisitLogic
{
private readonly ILogger _logger;
private readonly IVisitStorage _visitStorage;
public VisitLogic(ILogger<VisitLogic> logger, IVisitStorage visitStorage)
{
_logger = logger;
_visitStorage = visitStorage;
}
public VisitViewModel? ReadElement(VisitSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. VisitName:{VisitName} Id:{ Id}", model.VisitName, model.Id);
var element = _visitStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public List<VisitViewModel>? ReadList(VisitSearchModel? model)
{
_logger.LogInformation("ReadList. VisitName:{VisitName} Id:{ Id}", model?.VisitName, model?.Id);
var list = model == null ? _visitStorage.GetFullList() : _visitStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public bool Create(VisitBindingModel model)
{
CheckModel(model);
if (_visitStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(VisitBindingModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (string.IsNullOrEmpty(model.VisitName))
{
throw new ArgumentNullException("Нет названия визита", nameof(model.VisitName));
}
var element = _visitStorage.GetElement(new VisitSearchModel
{
VisitName = model.VisitName
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Визит с таким названием уже есть");
}
if (_visitStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(VisitBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_visitStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(VisitBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.VisitName))
{
throw new ArgumentNullException("Нет названия визита", nameof(model.VisitName));
}
if (model.DateVisit == null)
{
throw new ArgumentNullException("Нет времени визита",
nameof(model.DateVisit));
}
if (model.DateVisit <= DateTime.Now)
{
throw new ArgumentNullException("Дата визита не должна быть в прошлом", nameof(model.DateVisit));
}
_logger.LogInformation("Visit. Visit:{NameVisit}. DateVisit:{ DateVisit}. Id: { Id}", model.VisitName, model.DateVisit, model.Id);
var element = _visitStorage.GetElement(new VisitSearchModel
{
VisitName = model.VisitName
});
//if (element != null && element.Id != model.Id)
//{
// throw new InvalidOperationException("Визит с таким названием уже есть");
//}
}
}
}

View File

@ -0,0 +1,64 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VeterinaryContracts.BindingModels;
using VeterinaryContracts.BusinessLogicContracts;
namespace VeterinaryBusinessLogic.MailWorker
{
public abstract class AbstractMailWorker
{
protected string _mailLogin = string.Empty;
protected string _mailPassword = string.Empty;
protected string _smtpClientHost = string.Empty;
protected int _smtpClientPort;
protected string _popHost = string.Empty;
protected int _popPort;
private readonly IDoctorLogic _doctorLogic;
private readonly ILogger _logger;
public AbstractMailWorker(ILogger<AbstractMailWorker> logger, IDoctorLogic doctorLogic)
{
_logger = logger;
_doctorLogic = doctorLogic;
}
public void MailConfig(MailConfigBindingModel config)
{
_mailLogin = config.MailLogin;
_mailPassword = config.MailPassword;
_smtpClientHost = config.SmtpClientHost;
_smtpClientPort = config.SmtpClientPort;
_popHost = config.PopHost;
_popPort = config.PopPort;
_logger.LogDebug("Config: {login}, {password}, {clientHost}, {clientPOrt}, {popHost}, {popPort}", _mailLogin, _mailPassword, _smtpClientHost, _smtpClientPort, _popHost, _popPort);
}
public async void MailSendAsync(MailSendInfoBindingModel info)
{
if (string.IsNullOrEmpty(_mailLogin) || string.IsNullOrEmpty(_mailPassword))
{
return;
}
if (string.IsNullOrEmpty(_smtpClientHost) || _smtpClientPort == 0)
{
return;
}
if (string.IsNullOrEmpty(info.MailAddress) || string.IsNullOrEmpty(info.Subject) || string.IsNullOrEmpty(info.Text))
{
return;
}
_logger.LogDebug("Send Mail: {To}, {Subject}", info.MailAddress, info.Subject);
await SendMailAsync(info);
}
protected abstract Task SendMailAsync(MailSendInfoBindingModel info);
}
}

View File

@ -0,0 +1,50 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Net.Mime;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using VeterinaryContracts.BindingModels;
using VeterinaryContracts.BusinessLogicContracts;
namespace VeterinaryBusinessLogic.MailWorker
{
public class MailKitWorker : AbstractMailWorker
{
public MailKitWorker(ILogger<MailKitWorker> logger, IDoctorLogic doctorLogic) : base(logger, doctorLogic) { }
protected override async Task SendMailAsync(MailSendInfoBindingModel info)
{
using var objMailMessage = new MailMessage();
using var objSmtpClient = new SmtpClient(_smtpClientHost, _smtpClientPort);
try
{
objMailMessage.From = new MailAddress(_mailLogin);
objMailMessage.To.Add(new MailAddress(info.MailAddress));
objMailMessage.Subject = info.Subject;
objMailMessage.Body = info.Text;
objMailMessage.SubjectEncoding = Encoding.UTF8;
objMailMessage.BodyEncoding = Encoding.UTF8;
Attachment attachment = new Attachment("D:\\U on Drive\\4 semester\\RPP2\\Cursovaya\\github\\pdffile.pdf", new ContentType(MediaTypeNames.Application.Pdf));
objMailMessage.Attachments.Add(attachment);
objSmtpClient.UseDefaultCredentials = false;
objSmtpClient.EnableSsl = true;
objSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
objSmtpClient.Credentials = new NetworkCredential(_mailLogin, _mailPassword);
await Task.Run(() => objSmtpClient.Send(objMailMessage));
}
catch (Exception)
{
throw;
}
}
}
}

View File

@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VeterinaryBusinessLogic.OfficePackage.HelperEnums;
using VeterinaryBusinessLogic.OfficePackage.HelperModels;
namespace VeterinaryBusinessLogic.OfficePackage
{
public abstract class AbstractSaveToExcelDoctor
{
public void CreateReport(ExcelInfoDoctor info)
{
CreateExcel(info);
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = 1,
Text = info.Title,
StyleInfo = ExcelStyleInfoType.Title
});
MergeCells(new ExcelMergeParameters
{
CellFromName = "A1",
CellToName = "C1"
});
uint rowIndex = 2;
foreach (var rec in info.PurchaseMedications)
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = rowIndex,
Text = rec.MedicationName,
StyleInfo = ExcelStyleInfoType.Text
});
rowIndex++;
foreach (var medication in rec.Purchases)
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "B",
RowIndex = rowIndex,
Text = medication.DateCreate.ToString(),
StyleInfo = ExcelStyleInfoType.TextWithBroder
});
rowIndex++;
}
rowIndex++;
}
SaveExcel(info);
}
protected abstract void CreateExcel(ExcelInfoDoctor info);
protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams);
protected abstract void MergeCells(ExcelMergeParameters excelParams);
protected abstract void SaveExcel(ExcelInfoDoctor info);
}
}

View File

@ -0,0 +1,67 @@
using VeterinaryBusinessLogic.OfficePackage.HelperEnums;
using VeterinaryBusinessLogic.OfficePackage.HelperModels;
namespace VeterinaryBusinessLogic.OfficePackage
{
public abstract class AbstractSaveToExcelOwner
{
public void CreateReport(ExcelInfoOwner info)
{
CreateExcel(info);
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = 1,
Text = info.Title,
StyleInfo = ExcelStyleInfoType.Title
});
MergeCells(new ExcelMergeParameters
{
CellFromName = "A1",
CellToName = "C1"
});
uint rowIndex = 2;
foreach (var rec in info.PetServices)
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = rowIndex,
Text = rec.PetName,
StyleInfo = ExcelStyleInfoType.Text
});
rowIndex++;
foreach (var animal in rec.Services)
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "B",
RowIndex = rowIndex,
Text = animal.ServiceName,
StyleInfo = ExcelStyleInfoType.TextWithBroder
});
rowIndex++;
}
rowIndex++;
}
SaveExcel(info);
}
protected abstract void CreateExcel(ExcelInfoOwner info);
protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams);
protected abstract void MergeCells(ExcelMergeParameters excelParams);
protected abstract void SaveExcel(ExcelInfoOwner info);
}
}

View File

@ -0,0 +1,22 @@
using VeterinaryBusinessLogic.OfficePackage.HelperModels;
namespace VeterinaryBusinessLogic.OfficePackage
{
public abstract class AbstractSaveToPdf
{
/// Создание pdf-файла
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,72 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VeterinaryBusinessLogic.OfficePackage.HelperEnums;
using VeterinaryBusinessLogic.OfficePackage.HelperModels;
using VeterinaryDatabaseImplement.Implements;
namespace VeterinaryBusinessLogic.OfficePackage
{
public abstract class AbstractSaveToPdfDoctor
{
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> { "4cm", "4cm", "4cm", "4cm" });
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "Дата", "Название медикамента", "Рекомендация ", "Рекомендация" },
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
foreach (var medication in info.ReportDrugsVisits)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "", medication.MedicationName, "", "" },
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
foreach(var visit in medication.Drugs)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string> { visit.DateCreate.ToString(), "", visit.DrugName, "" },
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
}
foreach (var guidance in medication.Visits)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string> { guidance.DateVisit.ToString(), "", "", guidance.VisitName },
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,65 @@
using VeterinaryBusinessLogic.OfficePackage.HelperEnums;
using VeterinaryBusinessLogic.OfficePackage.HelperModels;
namespace VeterinaryBusinessLogic.OfficePackage
{
public abstract class AbstractSaveToPdfOwner
{
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> { "4cm", "4cm", "4cm", "4cm" });
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "Дата", "Животное", "Название визита", "Название рекомендации" },
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
foreach (var pet in info.ReportVisitsDrugs)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "", pet.PetName, "", "" },
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
foreach (var visit in pet.Medicaments)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "", "", visit.MedicationName, "", },
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
}
foreach (var guidance in pet.Purchases)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string> { guidance.DateCreate.ToString(), "", "", guidance.PuchaseName },
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,62 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VeterinaryBusinessLogic.OfficePackage.HelperEnums;
using VeterinaryBusinessLogic.OfficePackage.HelperModels;
namespace VeterinaryBusinessLogic.OfficePackage
{
public abstract class AbstractSaveToWordDoctor
{
public void CreateDoc(WordInfoDoctor info)
{
CreateWord(info);
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24", }) },
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Center
}
});
foreach (var rec in info.PurchaseMedications)
{
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)>
{ (rec.MedicationName, new WordTextProperties { Size = "24", Bold=true})},
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Both
}
});
foreach (var medication in rec.Purchases)
{
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)>
{ (medication.DateCreate.ToString(), new WordTextProperties { Size = "20", Bold=false})},
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Both
}
});
}
}
SaveWord(info);
}
protected abstract void CreateWord(WordInfoDoctor info);
protected abstract void CreateParagraph(WordParagraph paragraph);
protected abstract void SaveWord(WordInfoDoctor info);
}
}

View File

@ -0,0 +1,56 @@
using VeterinaryBusinessLogic.OfficePackage.HelperEnums;
using VeterinaryBusinessLogic.OfficePackage.HelperModels;
namespace VeterinaryBusinessLogic.OfficePackage
{
public abstract class AbstractSaveToWordOwner
{
public void CreateDoc(WordInfoOwner info)
{
CreateWord(info);
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24", }) },
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Center
}
});
foreach (var rec in info.PetServices)
{
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)>
{ (rec.PetName, new WordTextProperties { Size = "24", Bold=true})},
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Both
}
});
foreach (var animal in rec.Services)
{
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)>
{ (animal.ServiceName, new WordTextProperties { Size = "20", Bold=false})},
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Both
}
});
}
}
SaveWord(info);
}
protected abstract void CreateWord(WordInfoOwner info);
protected abstract void CreateParagraph(WordParagraph paragraph);
protected abstract void SaveWord(WordInfoOwner info);
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VeterinaryBusinessLogic.OfficePackage.HelperEnums
{
public enum ExcelStyleInfoType
{
Title,
Text,
TextWithBroder
}
}

View File

@ -0,0 +1,9 @@
namespace VeterinaryBusinessLogic.OfficePackage.HelperEnums
{
public enum PdfParagraphAlignmentType
{
Center,
Left,
Right
}
}

View File

@ -0,0 +1,8 @@
namespace VeterinaryBusinessLogic.OfficePackage.HelperEnums
{
public enum WordJustificationType
{
Center,
Both
}
}

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VeterinaryBusinessLogic.OfficePackage.HelperEnums;
namespace VeterinaryBusinessLogic.OfficePackage.HelperModels
{
public class ExcelCellParameters
{
public string ColumnName { get; set; } = string.Empty;
public uint RowIndex { get; set; }
public string Text { get; set; } = string.Empty;
public string CellReference => $"{ColumnName}{RowIndex}";
public ExcelStyleInfoType StyleInfo { get; set; }
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VeterinaryContracts.ViewModels;
namespace VeterinaryBusinessLogic.OfficePackage.HelperModels
{
public class ExcelInfoDoctor
{
public string FileName { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public List<ReportPurchaseMedicationViewModel> PurchaseMedications { get; set; } = new();
}
}

View File

@ -0,0 +1,11 @@
using VeterinaryContracts.ViewModels;
namespace VeterinaryBusinessLogic.OfficePackage.HelperModels
{
public class ExcelInfoOwner
{
public string FileName { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public List<ReportServicesViewModel> PetServices { get; set; } = new();
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VeterinaryBusinessLogic.OfficePackage.HelperModels
{
public class ExcelMergeParameters
{
public string CellFromName { get; set; } = string.Empty;
public string CellToName { get; set; } = string.Empty;
public string Merge => $"{CellFromName}:{CellToName}";
}
}

View File

@ -0,0 +1,15 @@

using VeterinaryContracts.ViewModels;
namespace VeterinaryBusinessLogic.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<ReportDrugsVisitsViewModel> ReportDrugsVisits { get; set; } = new();
public List<ReportVisitsDrugsViewModel> ReportVisitsDrugs{ get; set; } = new();// возможно надо убрать
}
}

View File

@ -0,0 +1,11 @@
using VeterinaryBusinessLogic.OfficePackage.HelperEnums;
namespace VeterinaryBusinessLogic.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,11 @@
using VeterinaryBusinessLogic.OfficePackage.HelperEnums;
namespace VeterinaryBusinessLogic.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,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VeterinaryContracts.ViewModels;
namespace VeterinaryBusinessLogic.OfficePackage.HelperModels
{
public class WordInfoDoctor
{
public string FileName { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public List<ReportPurchaseMedicationViewModel> PurchaseMedications { get; set; } = new();
}
}

View File

@ -0,0 +1,11 @@
using VeterinaryContracts.ViewModels;
namespace VeterinaryBusinessLogic.OfficePackage.HelperModels
{
public class WordInfoOwner
{
public string FileName { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public List<ReportServicesViewModel> PetServices { get; set; } = new();
}
}

View File

@ -0,0 +1,8 @@
namespace VeterinaryBusinessLogic.OfficePackage.HelperModels
{
public class WordParagraph
{
public List<(string, WordTextProperties)> Texts { get; set; } = new();
public WordTextProperties? TextProperties { get; set; }
}
}

View File

@ -0,0 +1,11 @@
using VeterinaryBusinessLogic.OfficePackage.HelperEnums;
namespace VeterinaryBusinessLogic.OfficePackage.HelperModels
{
public class WordTextProperties
{
public string Size { get; set; } = string.Empty;
public bool Bold { get; set; }
public WordJustificationType JustificationType { get; set; }
}
}

View File

@ -0,0 +1,333 @@
using DocumentFormat.OpenXml.Office2010.Excel;
using DocumentFormat.OpenXml.Office2013.Excel;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
using DocumentFormat.OpenXml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VeterinaryBusinessLogic.OfficePackage.HelperEnums;
using VeterinaryBusinessLogic.OfficePackage.HelperModels;
namespace VeterinaryBusinessLogic.OfficePackage.Implements
{
public class SaveToExcelDoctor : AbstractSaveToExcelDoctor
{
private SpreadsheetDocument? _spreadsheetDocument;
private SharedStringTablePart? _shareStringPart;
private Worksheet? _worksheet;
private static void CreateStyles(WorkbookPart workbookpart)
{
var sp = workbookpart.AddNewPart<WorkbookStylesPart>();
sp.Stylesheet = new Stylesheet();
var fonts = new Fonts() { Count = 2U, KnownFonts = true };
var fontUsual = new Font();
fontUsual.Append(new FontSize() { Val = 12D });
fontUsual.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Theme = 1U });
fontUsual.Append(new FontName() { Val = "Times New Roman" });
fontUsual.Append(new FontFamilyNumbering() { Val = 2 });
fontUsual.Append(new FontScheme() { Val = FontSchemeValues.Minor });
var fontTitle = new Font();
fontTitle.Append(new Bold());
fontTitle.Append(new FontSize() { Val = 14D });
fontTitle.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Theme = 1U });
fontTitle.Append(new FontName() { Val = "Times New Roman" });
fontTitle.Append(new FontFamilyNumbering() { Val = 2 });
fontTitle.Append(new FontScheme() { Val = FontSchemeValues.Minor });
fonts.Append(fontUsual);
fonts.Append(fontTitle);
var fills = new Fills() { Count = 2U };
var fill1 = new Fill();
fill1.Append(new PatternFill() { PatternType = PatternValues.None });
var fill2 = new Fill();
fill2.Append(new PatternFill() { PatternType = PatternValues.Gray125 });
fills.Append(fill1);
fills.Append(fill2);
var borders = new Borders() { Count = 2U };
var borderNoBorder = new Border();
borderNoBorder.Append(new LeftBorder());
borderNoBorder.Append(new RightBorder());
borderNoBorder.Append(new TopBorder());
borderNoBorder.Append(new BottomBorder());
borderNoBorder.Append(new DiagonalBorder());
var borderThin = new Border();
var leftBorder = new LeftBorder() { Style = BorderStyleValues.Thin };
leftBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U });
var rightBorder = new RightBorder() { Style = BorderStyleValues.Thin };
rightBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U });
var topBorder = new TopBorder() { Style = BorderStyleValues.Thin };
topBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U });
var bottomBorder = new BottomBorder() { Style = BorderStyleValues.Thin };
bottomBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U });
borderThin.Append(leftBorder);
borderThin.Append(rightBorder);
borderThin.Append(topBorder);
borderThin.Append(bottomBorder);
borderThin.Append(new DiagonalBorder());
borders.Append(borderNoBorder);
borders.Append(borderThin);
var cellStyleFormats = new CellStyleFormats()
{
Count = 1U
};
var cellFormatStyle = new CellFormat()
{
NumberFormatId = 0U,
FontId = 0U,
FillId = 0U,
BorderId = 0U
};
cellStyleFormats.Append(cellFormatStyle);
var cellFormats = new CellFormats()
{
Count = 3U
};
var cellFormatFont = new CellFormat()
{
NumberFormatId = 0U,
FontId = 0U,
FillId = 0U,
BorderId = 0U,
FormatId = 0U,
ApplyFont = true
};
var cellFormatFontAndBorder = new CellFormat()
{
NumberFormatId = 0U,
FontId = 0U,
FillId = 0U,
BorderId = 1U,
FormatId = 0U,
ApplyFont = true,
ApplyBorder = true
};
var cellFormatTitle = new CellFormat()
{
NumberFormatId = 0U,
FontId = 1U,
FillId = 0U,
BorderId = 0U,
FormatId = 0U,
Alignment = new Alignment()
{
Vertical = VerticalAlignmentValues.Center,
WrapText = true,
Horizontal = HorizontalAlignmentValues.Center
},
ApplyFont = true
};
cellFormats.Append(cellFormatFont);
cellFormats.Append(cellFormatFontAndBorder);
cellFormats.Append(cellFormatTitle);
var cellStyles = new CellStyles() { Count = 1U };
cellStyles.Append(new CellStyle()
{
Name = "Normal",
FormatId = 0U,
BuiltinId = 0U
});
var differentialFormats = new DocumentFormat.OpenXml.Office2013.Excel.DifferentialFormats()
{
Count = 0U
};
var tableStyles = new TableStyles()
{
Count = 0U,
DefaultTableStyle = "TableStyleMedium2",
DefaultPivotStyle = "PivotStyleLight16"
};
var stylesheetExtensionList = new StylesheetExtensionList();
var stylesheetExtension1 = new StylesheetExtension()
{
Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}"
};
stylesheetExtension1.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main");
stylesheetExtension1.Append(new SlicerStyles()
{
DefaultSlicerStyle = "SlicerStyleLight1"
});
var stylesheetExtension2 = new StylesheetExtension()
{
Uri = "{9260A510-F301-46a8-8635-F512D64BE5F5}"
};
stylesheetExtension2.AddNamespaceDeclaration("x15", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main");
stylesheetExtension2.Append(new TimelineStyles()
{
DefaultTimelineStyle = "TimeSlicerStyleLight1"
});
stylesheetExtensionList.Append(stylesheetExtension1);
stylesheetExtensionList.Append(stylesheetExtension2);
sp.Stylesheet.Append(fonts);
sp.Stylesheet.Append(fills);
sp.Stylesheet.Append(borders);
sp.Stylesheet.Append(cellStyleFormats);
sp.Stylesheet.Append(cellFormats);
sp.Stylesheet.Append(cellStyles);
sp.Stylesheet.Append(differentialFormats);
sp.Stylesheet.Append(tableStyles);
sp.Stylesheet.Append(stylesheetExtensionList);
}
private static uint GetStyleValue(ExcelStyleInfoType styleInfo)
{
return styleInfo switch
{
ExcelStyleInfoType.Title => 2U,
ExcelStyleInfoType.TextWithBroder => 1U,
ExcelStyleInfoType.Text => 0U,
_ => 0U,
};
}
protected override void CreateExcel(ExcelInfoDoctor info)
{
_spreadsheetDocument = SpreadsheetDocument.Create(info.FileName, SpreadsheetDocumentType.Workbook);
var workbookpart = _spreadsheetDocument.AddWorkbookPart();
workbookpart.Workbook = new Workbook();
CreateStyles(workbookpart);
_shareStringPart = _spreadsheetDocument.WorkbookPart!.GetPartsOfType<SharedStringTablePart>().Any() ? _spreadsheetDocument.WorkbookPart.GetPartsOfType<SharedStringTablePart>().First() : _spreadsheetDocument.WorkbookPart.AddNewPart<SharedStringTablePart>();
if (_shareStringPart.SharedStringTable == null)
{
_shareStringPart.SharedStringTable = new SharedStringTable();
}
var worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
worksheetPart.Worksheet = new Worksheet(new SheetData());
var sheets = _spreadsheetDocument.WorkbookPart.Workbook.AppendChild(new Sheets());
var sheet = new Sheet()
{
Id = _spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart),
SheetId = 1,
Name = "Лист"
};
sheets.Append(sheet);
_worksheet = worksheetPart.Worksheet;
}
protected override void InsertCellInWorksheet(ExcelCellParameters excelParams)
{
if (_worksheet == null || _shareStringPart == null)
{
return;
}
var sheetData = _worksheet.GetFirstChild<SheetData>();
if (sheetData == null)
{
return;
}
Row row;
if (sheetData.Elements<Row>().Where(r => r.RowIndex! == excelParams.RowIndex).Any())
{
row = sheetData.Elements<Row>().Where(r => r.RowIndex! == excelParams.RowIndex).First();
}
else
{
row = new Row() { RowIndex = excelParams.RowIndex };
sheetData.Append(row);
}
Cell cell;
if (row.Elements<Cell>().Where(c => c.CellReference!.Value == excelParams.CellReference).Any())
{
cell = row.Elements<Cell>().Where(c => c.CellReference!.Value == excelParams.CellReference).First();
}
else
{
Cell? refCell = null;
foreach (Cell rowCell in row.Elements<Cell>())
{
if (string.Compare(rowCell.CellReference!.Value, excelParams.CellReference, true) > 0)
{
refCell = rowCell;
break;
}
}
var newCell = new Cell()
{
CellReference = excelParams.CellReference
};
row.InsertBefore(newCell, refCell);
cell = newCell;
}
_shareStringPart.SharedStringTable.AppendChild(new SharedStringItem(new Text(excelParams.Text)));
_shareStringPart.SharedStringTable.Save();
cell.CellValue = new CellValue((_shareStringPart.SharedStringTable.Elements<SharedStringItem>().Count() - 1).ToString());
cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);
cell.StyleIndex = GetStyleValue(excelParams.StyleInfo);
}
protected override void MergeCells(ExcelMergeParameters excelParams)
{
if (_worksheet == null)
{
return;
}
MergeCells mergeCells;
if (_worksheet.Elements<MergeCells>().Any())
{
mergeCells = _worksheet.Elements<MergeCells>().First();
}
else
{
mergeCells = new MergeCells();
if (_worksheet.Elements<CustomSheetView>().Any())
{
_worksheet.InsertAfter(mergeCells, _worksheet.Elements<CustomSheetView>().First());
}
else
{
_worksheet.InsertAfter(mergeCells, _worksheet.Elements<SheetData>().First());
}
}
var mergeCell = new MergeCell()
{
Reference = new StringValue(excelParams.Merge)
};
mergeCells.Append(mergeCell);
}
protected override void SaveExcel(ExcelInfoDoctor info)
{
if (_spreadsheetDocument == null)
{
return;
}
_spreadsheetDocument.WorkbookPart!.Workbook.Save();
_spreadsheetDocument.Dispose();
}
}
}

View File

@ -0,0 +1,328 @@
using DocumentFormat.OpenXml.Office2010.Excel;
using DocumentFormat.OpenXml.Office2013.Excel;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
using DocumentFormat.OpenXml;
using VeterinaryBusinessLogic.OfficePackage.HelperEnums;
using VeterinaryBusinessLogic.OfficePackage.HelperModels;
namespace VeterinaryBusinessLogic.OfficePackage.Implements
{
public class SaveToExcelOwner : AbstractSaveToExcelOwner
{
private SpreadsheetDocument? _spreadsheetDocument;
private SharedStringTablePart? _shareStringPart;
private Worksheet? _worksheet;
private static void CreateStyles(WorkbookPart workbookpart)
{
var sp = workbookpart.AddNewPart<WorkbookStylesPart>();
sp.Stylesheet = new Stylesheet();
var fonts = new Fonts() { Count = 2U, KnownFonts = true };
var fontUsual = new Font();
fontUsual.Append(new FontSize() { Val = 12D });
fontUsual.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Theme = 1U });
fontUsual.Append(new FontName() { Val = "Times New Roman" });
fontUsual.Append(new FontFamilyNumbering() { Val = 2 });
fontUsual.Append(new FontScheme() { Val = FontSchemeValues.Minor });
var fontTitle = new Font();
fontTitle.Append(new Bold());
fontTitle.Append(new FontSize() { Val = 14D });
fontTitle.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Theme = 1U });
fontTitle.Append(new FontName() { Val = "Times New Roman" });
fontTitle.Append(new FontFamilyNumbering() { Val = 2 });
fontTitle.Append(new FontScheme() { Val = FontSchemeValues.Minor });
fonts.Append(fontUsual);
fonts.Append(fontTitle);
var fills = new Fills() { Count = 2U };
var fill1 = new Fill();
fill1.Append(new PatternFill() { PatternType = PatternValues.None });
var fill2 = new Fill();
fill2.Append(new PatternFill() { PatternType = PatternValues.Gray125 });
fills.Append(fill1);
fills.Append(fill2);
var borders = new Borders() { Count = 2U };
var borderNoBorder = new Border();
borderNoBorder.Append(new LeftBorder());
borderNoBorder.Append(new RightBorder());
borderNoBorder.Append(new TopBorder());
borderNoBorder.Append(new BottomBorder());
borderNoBorder.Append(new DiagonalBorder());
var borderThin = new Border();
var leftBorder = new LeftBorder() { Style = BorderStyleValues.Thin };
leftBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U });
var rightBorder = new RightBorder() { Style = BorderStyleValues.Thin };
rightBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U });
var topBorder = new TopBorder() { Style = BorderStyleValues.Thin };
topBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U });
var bottomBorder = new BottomBorder() { Style = BorderStyleValues.Thin };
bottomBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U });
borderThin.Append(leftBorder);
borderThin.Append(rightBorder);
borderThin.Append(topBorder);
borderThin.Append(bottomBorder);
borderThin.Append(new DiagonalBorder());
borders.Append(borderNoBorder);
borders.Append(borderThin);
var cellStyleFormats = new CellStyleFormats()
{
Count = 1U
};
var cellFormatStyle = new CellFormat()
{
NumberFormatId = 0U,
FontId = 0U,
FillId = 0U,
BorderId = 0U
};
cellStyleFormats.Append(cellFormatStyle);
var cellFormats = new CellFormats()
{
Count = 3U
};
var cellFormatFont = new CellFormat()
{
NumberFormatId = 0U,
FontId = 0U,
FillId = 0U,
BorderId = 0U,
FormatId = 0U,
ApplyFont = true
};
var cellFormatFontAndBorder = new CellFormat()
{
NumberFormatId = 0U,
FontId = 0U,
FillId = 0U,
BorderId = 1U,
FormatId = 0U,
ApplyFont = true,
ApplyBorder = true
};
var cellFormatTitle = new CellFormat()
{
NumberFormatId = 0U,
FontId = 1U,
FillId = 0U,
BorderId = 0U,
FormatId = 0U,
Alignment = new Alignment()
{
Vertical = VerticalAlignmentValues.Center,
WrapText = true,
Horizontal = HorizontalAlignmentValues.Center
},
ApplyFont = true
};
cellFormats.Append(cellFormatFont);
cellFormats.Append(cellFormatFontAndBorder);
cellFormats.Append(cellFormatTitle);
var cellStyles = new CellStyles() { Count = 1U };
cellStyles.Append(new CellStyle()
{
Name = "Normal",
FormatId = 0U,
BuiltinId = 0U
});
var differentialFormats = new DocumentFormat.OpenXml.Office2013.Excel.DifferentialFormats()
{
Count = 0U
};
var tableStyles = new TableStyles()
{
Count = 0U,
DefaultTableStyle = "TableStyleMedium2",
DefaultPivotStyle = "PivotStyleLight16"
};
var stylesheetExtensionList = new StylesheetExtensionList();
var stylesheetExtension1 = new StylesheetExtension()
{
Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}"
};
stylesheetExtension1.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main");
stylesheetExtension1.Append(new SlicerStyles()
{
DefaultSlicerStyle = "SlicerStyleLight1"
});
var stylesheetExtension2 = new StylesheetExtension()
{
Uri = "{9260A510-F301-46a8-8635-F512D64BE5F5}"
};
stylesheetExtension2.AddNamespaceDeclaration("x15", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main");
stylesheetExtension2.Append(new TimelineStyles()
{
DefaultTimelineStyle = "TimeSlicerStyleLight1"
});
stylesheetExtensionList.Append(stylesheetExtension1);
stylesheetExtensionList.Append(stylesheetExtension2);
sp.Stylesheet.Append(fonts);
sp.Stylesheet.Append(fills);
sp.Stylesheet.Append(borders);
sp.Stylesheet.Append(cellStyleFormats);
sp.Stylesheet.Append(cellFormats);
sp.Stylesheet.Append(cellStyles);
sp.Stylesheet.Append(differentialFormats);
sp.Stylesheet.Append(tableStyles);
sp.Stylesheet.Append(stylesheetExtensionList);
}
private static uint GetStyleValue(ExcelStyleInfoType styleInfo)
{
return styleInfo switch
{
ExcelStyleInfoType.Title => 2U,
ExcelStyleInfoType.TextWithBroder => 1U,
ExcelStyleInfoType.Text => 0U,
_ => 0U,
};
}
protected override void CreateExcel(ExcelInfoOwner info)
{
_spreadsheetDocument = SpreadsheetDocument.Create(info.FileName, SpreadsheetDocumentType.Workbook);
var workbookpart = _spreadsheetDocument.AddWorkbookPart();
workbookpart.Workbook = new Workbook();
CreateStyles(workbookpart);
_shareStringPart = _spreadsheetDocument.WorkbookPart!.GetPartsOfType<SharedStringTablePart>().Any() ? _spreadsheetDocument.WorkbookPart.GetPartsOfType<SharedStringTablePart>().First() : _spreadsheetDocument.WorkbookPart.AddNewPart<SharedStringTablePart>();
if (_shareStringPart.SharedStringTable == null)
{
_shareStringPart.SharedStringTable = new SharedStringTable();
}
var worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
worksheetPart.Worksheet = new Worksheet(new SheetData());
var sheets = _spreadsheetDocument.WorkbookPart.Workbook.AppendChild(new Sheets());
var sheet = new Sheet()
{
Id = _spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart),
SheetId = 1,
Name = "Лист"
};
sheets.Append(sheet);
_worksheet = worksheetPart.Worksheet;
}
protected override void InsertCellInWorksheet(ExcelCellParameters excelParams)
{
if (_worksheet == null || _shareStringPart == null)
{
return;
}
var sheetData = _worksheet.GetFirstChild<SheetData>();
if (sheetData == null)
{
return;
}
Row row;
if (sheetData.Elements<Row>().Where(r => r.RowIndex! == excelParams.RowIndex).Any())
{
row = sheetData.Elements<Row>().Where(r => r.RowIndex! == excelParams.RowIndex).First();
}
else
{
row = new Row() { RowIndex = excelParams.RowIndex };
sheetData.Append(row);
}
Cell cell;
if (row.Elements<Cell>().Where(c => c.CellReference!.Value == excelParams.CellReference).Any())
{
cell = row.Elements<Cell>().Where(c => c.CellReference!.Value == excelParams.CellReference).First();
}
else
{
Cell? refCell = null;
foreach (Cell rowCell in row.Elements<Cell>())
{
if (string.Compare(rowCell.CellReference!.Value, excelParams.CellReference, true) > 0)
{
refCell = rowCell;
break;
}
}
var newCell = new Cell()
{
CellReference = excelParams.CellReference
};
row.InsertBefore(newCell, refCell);
cell = newCell;
}
_shareStringPart.SharedStringTable.AppendChild(new SharedStringItem(new Text(excelParams.Text)));
_shareStringPart.SharedStringTable.Save();
cell.CellValue = new CellValue((_shareStringPart.SharedStringTable.Elements<SharedStringItem>().Count() - 1).ToString());
cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);
cell.StyleIndex = GetStyleValue(excelParams.StyleInfo);
}
protected override void MergeCells(ExcelMergeParameters excelParams)
{
if (_worksheet == null)
{
return;
}
MergeCells mergeCells;
if (_worksheet.Elements<MergeCells>().Any())
{
mergeCells = _worksheet.Elements<MergeCells>().First();
}
else
{
mergeCells = new MergeCells();
if (_worksheet.Elements<CustomSheetView>().Any())
{
_worksheet.InsertAfter(mergeCells, _worksheet.Elements<CustomSheetView>().First());
}
else
{
_worksheet.InsertAfter(mergeCells, _worksheet.Elements<SheetData>().First());
}
}
var mergeCell = new MergeCell()
{
Reference = new StringValue(excelParams.Merge)
};
mergeCells.Append(mergeCell);
}
protected override void SaveExcel(ExcelInfoOwner info)
{
if (_spreadsheetDocument == null)
{
return;
}
_spreadsheetDocument.WorkbookPart!.Workbook.Save();
_spreadsheetDocument.Dispose();
}
}
}

View File

@ -0,0 +1,108 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VeterinaryBusinessLogic.OfficePackage.HelperEnums;
using VeterinaryBusinessLogic.OfficePackage.HelperModels;
using MigraDoc.DocumentObjectModel;
using MigraDoc.DocumentObjectModel.Tables;
using MigraDoc.Rendering;
using VeterinaryBusinessLogic.OfficePackage;
namespace VeterinaryBusinessLogic.OfficePackage.Implements
{
public class SaveToPdfDoctor : AbstractSaveToPdfDoctor
{
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.Right => 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

@ -0,0 +1,101 @@
using MigraDoc.DocumentObjectModel;
using MigraDoc.Rendering;
using MigraDoc.DocumentObjectModel.Tables;
using VeterinaryBusinessLogic.OfficePackage.HelperEnums;
using VeterinaryBusinessLogic.OfficePackage.HelperModels;
namespace VeterinaryBusinessLogic.OfficePackage.Implements
{
public class SaveToPdfOwner : AbstractSaveToPdfOwner
{
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.Right => 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

@ -0,0 +1,117 @@
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
using DocumentFormat.OpenXml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VeterinaryBusinessLogic.OfficePackage.HelperEnums;
using VeterinaryBusinessLogic.OfficePackage.HelperModels;
namespace VeterinaryBusinessLogic.OfficePackage.Implements
{
public class SaveToWordDoctor : AbstractSaveToWordDoctor
{
private WordprocessingDocument? _wordDocument;
private Body? _docBody;
// получение типов выравнивания
private static JustificationValues GetJustificationValues(WordJustificationType type)
{
return type switch
{
WordJustificationType.Both => JustificationValues.Both,
WordJustificationType.Center => JustificationValues.Center,
_ => JustificationValues.Left,
};
}
// настройки страницы
private static SectionProperties CreateSectionProperties()
{
var properties = new SectionProperties();
var pageSize = new PageSize
{
Orient = PageOrientationValues.Portrait
};
properties.AppendChild(pageSize);
return properties;
}
// задание форматирования для абзаца
private static ParagraphProperties? CreateParagraphProperties(WordTextProperties? paragraphProperties)
{
if (paragraphProperties == null)
{
return null;
}
var properties = new ParagraphProperties();
properties.AppendChild(new Justification()
{
Val =
GetJustificationValues(paragraphProperties.JustificationType)
});
properties.AppendChild(new SpacingBetweenLines
{
LineRule = LineSpacingRuleValues.Auto
});
properties.AppendChild(new Indentation());
var paragraphMarkRunProperties = new ParagraphMarkRunProperties();
if (!string.IsNullOrEmpty(paragraphProperties.Size))
{
paragraphMarkRunProperties.AppendChild(new FontSize
{
Val =
paragraphProperties.Size
});
}
properties.AppendChild(paragraphMarkRunProperties);
return properties;
}
protected override void CreateWord(WordInfoDoctor info)
{
_wordDocument = WordprocessingDocument.Create(info.FileName,
WordprocessingDocumentType.Document);
MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart();
mainPart.Document = new Document();
_docBody = mainPart.Document.AppendChild(new Body());
}
protected override void CreateParagraph(WordParagraph paragraph)
{
if (_docBody == null || paragraph == null)
{
return;
}
var docParagraph = new Paragraph();
docParagraph.AppendChild(CreateParagraphProperties(paragraph.TextProperties));
foreach (var run in paragraph.Texts)
{
var docRun = new Run();
var properties = new RunProperties();
properties.AppendChild(new FontSize { Val = run.Item2.Size });
if (run.Item2.Bold)
{
properties.AppendChild(new Bold());
}
docRun.AppendChild(properties);
docRun.AppendChild(new Text
{
Text = run.Item1,
Space =
SpaceProcessingModeValues.Preserve
});
docParagraph.AppendChild(docRun);
}
_docBody.AppendChild(docParagraph);
}
protected override void SaveWord(WordInfoDoctor info)
{
if (_docBody == null || _wordDocument == null)
{
return;
}
_docBody.AppendChild(CreateSectionProperties());
_wordDocument.MainDocumentPart!.Document.Save();
_wordDocument.Dispose();
}
}
}

View File

@ -0,0 +1,113 @@
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
using VeterinaryBusinessLogic.OfficePackage.HelperEnums;
using VeterinaryBusinessLogic.OfficePackage.HelperModels;
namespace VeterinaryBusinessLogic.OfficePackage.Implements
{
public class SaveToWordOwner : AbstractSaveToWordOwner
{
private WordprocessingDocument? _wordDocument;
private Body? _docBody;
private static JustificationValues
GetJustificationValues(WordJustificationType type)
{
return type switch
{
WordJustificationType.Both => JustificationValues.Both,
WordJustificationType.Center => JustificationValues.Center,
_ => JustificationValues.Left,
};
}
private static SectionProperties CreateSectionProperties()
{
var properties = new SectionProperties();
var pageSize = new PageSize
{
Orient = PageOrientationValues.Portrait
};
properties.AppendChild(pageSize);
return properties;
}
private static ParagraphProperties?
CreateParagraphProperties(WordTextProperties? paragraphProperties)
{
if (paragraphProperties == null)
{
return null;
}
var properties = new ParagraphProperties();
properties.AppendChild(new Justification()
{
Val =
GetJustificationValues(paragraphProperties.JustificationType)
});
properties.AppendChild(new SpacingBetweenLines
{
LineRule = LineSpacingRuleValues.Auto
});
properties.AppendChild(new Indentation());
var paragraphMarkRunProperties = new ParagraphMarkRunProperties();
if (!string.IsNullOrEmpty(paragraphProperties.Size))
{
paragraphMarkRunProperties.AppendChild(new FontSize
{
Val =
paragraphProperties.Size
});
}
properties.AppendChild(paragraphMarkRunProperties);
return properties;
}
protected override void CreateWord(WordInfoOwner info)
{
_wordDocument = WordprocessingDocument.Create(info.FileName,
WordprocessingDocumentType.Document);
MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart();
mainPart.Document = new Document();
_docBody = mainPart.Document.AppendChild(new Body());
}
protected override void CreateParagraph(WordParagraph paragraph)
{
if (_docBody == null || paragraph == null)
{
return;
}
var docParagraph = new Paragraph();
docParagraph.AppendChild(CreateParagraphProperties(paragraph.TextProperties));
foreach (var run in paragraph.Texts)
{
var docRun = new Run();
var properties = new RunProperties();
properties.AppendChild(new FontSize { Val = run.Item2.Size });
if (run.Item2.Bold)
{
properties.AppendChild(new Bold());
}
docRun.AppendChild(properties);
docRun.AppendChild(new Text
{
Text = run.Item1,
Space =
SpaceProcessingModeValues.Preserve
});
docParagraph.AppendChild(docRun);
}
_docBody.AppendChild(docParagraph);
}
protected override void SaveWord(WordInfoOwner info)
{
if (_docBody == null || _wordDocument == null)
{
return;
}
_docBody.AppendChild(CreateSectionProperties());
_wordDocument.MainDocumentPart!.Document.Save();
_wordDocument.Dispose();
}
}
}

View File

@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DocumentFormat.OpenXml" Version="3.0.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\VeterinaryContracts\VeterinaryContracts.csproj" />
<ProjectReference Include="..\VeterinaryDatabaseImplement\VeterinaryDatabaseImplement.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VeterinaryDataModels.Models;
namespace VeterinaryContracts.BindingModels
{
public class DoctorBindingModel : IDoctorModel
{
public int Id { get; set; }
public string DoctorFIO { get; set; } = string.Empty;
public string Login { get; set; } = string.Empty;
public string Password { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VeterinaryDataModels.Models;
namespace VeterinaryContracts.BindingModels
{
public class DrugBindingModel : IDrugModel
{
public int Id { get; set; }
public string DrugName { get; set; } = string.Empty;
public int Count { get; set; }
public double Price { get; set; }
public Dictionary<int, IServiceModel> DrugServices
{
get;
set;
} = new();
public int DoctorId { get; set; }
public DateTime DateCreate { get; set; }
}
}

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VeterinaryContracts.BindingModels
{
public class MailConfigBindingModel
{
public string MailLogin { get; set; } = string.Empty;
public string MailPassword { get; set; } = string.Empty;
public string SmtpClientHost { get; set; } = string.Empty;
public int SmtpClientPort { get; set; }
public string PopHost { get; set; } = string.Empty;
public int PopPort { get; set; }
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VeterinaryContracts.BindingModels
{
public class MailSendInfoBindingModel
{
public string MailAddress { get; set; } = string.Empty;
public string Subject { get; set; } = string.Empty;
public string Text { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VeterinaryDataModels.Models;
namespace VeterinaryContracts.BindingModels
{
public class MedicationBindingModel : IMedicationModel
{
public int Id { get; set; }
public string MedicationName { get; set; } = string.Empty;
public double Price { get; set; }
public Dictionary<int, IPetModel> MedicationPets
{
get;
set;
} = new();
public int DoctorId { get; set; }
}
}

View File

@ -0,0 +1,12 @@
using VeterinaryDataModels.Models;
namespace VeterinaryContracts.BindingModels
{
public class OwnerBindingModel : IOwnerModel
{
public int Id { get; set; }
public string OwnerFIO { get; set; } = string.Empty;
public string Login { get; set; } = string.Empty;
public string Password { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,19 @@
using VeterinaryDataModels.Models;
namespace VeterinaryContracts.BindingModels
{
public class PetBindingModel : IPetModel
{
public int Id { get; set; }
public int OwnerId { get; set; }
public int MedicationId { get; set; }
public string PetName { get; set; } = string.Empty;
public string PetType { get; set;} = string.Empty;
public string PetBreed { get; set; } = string.Empty;
public string PetGender { get; set; } = string.Empty;
public Dictionary<int, IVisitModel> VisitPets { get; set; } = new();
public Dictionary<int, IPurchaseModel> PurchasePets { get; set; } = new();
}
}

View File

@ -0,0 +1,16 @@
using VeterinaryDataModels.Models;
namespace VeterinaryContracts.BindingModels
{
public class PurchaseBindingModel : IPurchaseModel
{
public int Id { get; set; }
public int OwnerId { get; set; }
public string PuchaseName { get; set; } = String.Empty;
public int DrugId { get; set; }
public int Count { get; set; }
public double Sum { get; set; }
public DateTime DateCreate { get; set; }
public Dictionary<int, IPetModel> PurchasePet { get; set; } = new();
}
}

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VeterinaryContracts.BindingModels
{
public class ReportDrugsVisitsBindingModel
{
public string FileName { get; set; } = string.Empty;
//public List<int> Medications { get; set; } = new();
public DateTime DateFrom { get; set; }
public DateTime DateTo { get; set; }
public int? DoctorId { get; set; }
public string? Email { get; set; }
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VeterinaryContracts.BindingModels
{
public class ReportPurchaseMedicationBindingModel
{
public string FileName { get; set; } = string.Empty;
public List<int> Medications { get; set; } = new();
}
}

View File

@ -0,0 +1,8 @@
namespace VeterinaryContracts.BindingModels
{
public class ReportServicesBindingModel
{
public string FileName { get; set; } = string.Empty;
public List<int> Pets { get; set; } = new();
}
}

View File

@ -0,0 +1,12 @@
namespace VeterinaryContracts.BindingModels
{
public class ReportVisitsDrugsBindingModel
{
public string FileName { get; set; } = string.Empty;
//public List<int> Pets { get; set; } = new();
public DateTime DateFrom { get; set; }
public DateTime DateTo { get; set; }
public int? OwnerId { get; set; }
public string? Email { get; set; }
}
}

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VeterinaryDataModels.Models;
namespace VeterinaryContracts.BindingModels
{
public class ServiceBindingModel : IServiceModel
{
public int Id { get; set; }
public string ServiceName { get; set; } = string.Empty;
public int VisitId { get; set; }
public int DoctorId { get; set; }
public Dictionary<int, IMedicationModel> ServiceMedications
{
get;
set;
} = new();
}
}

View File

@ -0,0 +1,15 @@
using VeterinaryDataModels.Models;
namespace VeterinaryContracts.BindingModels
{
public class VisitBindingModel : IVisitModel
{
public int Id { get; set; }
public int OwnerId { get; set; }
public int DoctorId { get; set; }
public int ServiceId { get; set; }
public string VisitName { get; set; } = string.Empty;
public DateTime DateVisit { get; set; }
public Dictionary<int, IPetModel> VisitPet { get; set; } = new();
}
}

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VeterinaryContracts.BindingModels;
using VeterinaryContracts.ViewModels;
using VeterinaryContracts.SearchModels;
namespace VeterinaryContracts.BusinessLogicContracts
{
public interface IDoctorLogic
{
List<DoctorViewModel>? ReadList(DoctorSearchModel? model);
DoctorViewModel? ReadElement(DoctorSearchModel model);
bool Create(DoctorBindingModel model);
bool Update(DoctorBindingModel model);
bool Delete(DoctorBindingModel model);
}
}

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VeterinaryContracts.BindingModels;
using VeterinaryContracts.ViewModels;
using VeterinaryContracts.SearchModels;
using VeterinaryDataModels;
namespace VeterinaryContracts.BusinessLogicContracts
{
public interface IDrugLogic
{
List<DrugViewModel>? ReadList(DrugSearchModel? model);
DrugViewModel? ReadElement(DrugSearchModel model);
bool Create(DrugBindingModel model);
bool Update(DrugBindingModel model);
bool Delete(DrugBindingModel model);
bool MakeSell(DrugBindingModel model, int count);
}
}

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VeterinaryContracts.BindingModels;
using VeterinaryContracts.ViewModels;
using VeterinaryContracts.SearchModels;
namespace VeterinaryContracts.BusinessLogicContracts
{
public interface IMedicationLogic
{
List<MedicationViewModel>? ReadList(MedicationSearchModel? model);
MedicationViewModel? ReadElement(MedicationSearchModel model);
bool Create(MedicationBindingModel model);
bool Update(MedicationBindingModel model);
bool Delete(MedicationBindingModel model);
}
}

View File

@ -0,0 +1,16 @@
using VeterinaryContracts.BindingModels;
using VeterinaryContracts.SearchModels;
using VeterinaryContracts.ViewModels;
namespace VeterinaryContracts.BusinessLogicContracts
{
public interface IOwnerLogic
{
List<OwnerViewModel>? ReadList(OwnerSearchModel? model);
OwnerViewModel? ReadElement(OwnerSearchModel model);
bool Create(OwnerBindingModel model);
bool Update(OwnerBindingModel model);
bool Delete(OwnerBindingModel model);
}
}

View File

@ -0,0 +1,15 @@
using VeterinaryContracts.BindingModels;
using VeterinaryContracts.SearchModels;
using VeterinaryContracts.ViewModels;
namespace VeterinaryContracts.BusinessLogicContracts
{
public interface IPetLogic
{
List<PetViewModel>? ReadList(PetSearchModel? model);
PetViewModel? ReadElement(PetSearchModel model);
bool Create(PetBindingModel model);
bool Update(PetBindingModel model);
bool Delete(PetBindingModel model);
}
}

View File

@ -0,0 +1,13 @@
using VeterinaryContracts.BindingModels;
using VeterinaryContracts.SearchModels;
using VeterinaryContracts.ViewModels;
namespace VeterinaryContracts.BusinessLogicContracts
{
public interface IPurchaseLogic
{
List<PurchaseViewModel>? ReadList(PurchaseSearchModel? model);
PurchaseViewModel? ReadElement(PurchaseSearchModel model);
bool CreatePurchase(PurchaseBindingModel model);
}
}

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VeterinaryContracts.BindingModels;
using VeterinaryContracts.ViewModels;
namespace VeterinaryContracts.BusinessLogicContracts
{
public interface IReportLogicDoctor
{
List<ReportDrugsVisitsViewModel> GetVisitsDrugs(ReportDrugsVisitsBindingModel model);
List<ReportPurchaseMedicationViewModel> GetPurchaseMedications(ReportPurchaseMedicationBindingModel model);
void SavePurchasesToWordFile(ReportPurchaseMedicationBindingModel model);
void SavePurchasesToExcelFile(ReportPurchaseMedicationBindingModel model);
void SaveMedicationsToPdfFile(ReportDrugsVisitsBindingModel model);
}
}

View File

@ -0,0 +1,14 @@
using VeterinaryContracts.BindingModels;
using VeterinaryContracts.ViewModels;
namespace VeterinaryContracts.BusinessLogicContracts
{
public interface IReportLogicOwner
{
List<ReportServicesViewModel> GetPetServices(ReportServicesBindingModel model);
List<ReportVisitsDrugsViewModel> GetVisitsDrugs(ReportVisitsDrugsBindingModel model);
void SaveServicesToWordFile(ReportServicesBindingModel model);
void SaveServicesToExcelFile(ReportServicesBindingModel model);
void SavePetsToPdfFile(ReportVisitsDrugsBindingModel model);
}
}

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VeterinaryContracts.BindingModels;
using VeterinaryContracts.ViewModels;
using VeterinaryContracts.SearchModels;
namespace VeterinaryContracts.BusinessLogicContracts
{
public interface IServiceLogic
{
List<ServiceViewModel>? ReadList(ServiceSearchModel? model);
ServiceViewModel? ReadElement(ServiceSearchModel model);
bool Create(ServiceBindingModel model);
bool Update(ServiceBindingModel model);
bool Delete(ServiceBindingModel model);
}
}

View File

@ -0,0 +1,15 @@
using VeterinaryContracts.BindingModels;
using VeterinaryContracts.SearchModels;
using VeterinaryContracts.ViewModels;
namespace VeterinaryContracts.BusinessLogicContracts
{
public interface IVisitLogic
{
List<VisitViewModel>? ReadList(VisitSearchModel? model);
VisitViewModel? ReadElement(VisitSearchModel model);
bool Create(VisitBindingModel model);
bool Update(VisitBindingModel model);
bool Delete(VisitBindingModel model);
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VeterinaryContracts.SearchModels
{
public class DoctorSearchModel
{
public int? Id { get; set; }
public string? DoctorFIO { get; set; }
public string? Login { get; set; }
public string? Password { get; set; }
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VeterinaryContracts.SearchModels
{
public class DrugSearchModel
{
public int? Id { get; set; }
public string? DrugName { get; set; }
public int? DoctorId { get; set; }
public DateTime? DateCreate { get; set; }
}
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VeterinaryContracts.SearchModels
{
public class ListPurchasesSearchModel
{
public List<int>? medicationsIds { get; set; }
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VeterinaryContracts.SearchModels
{
public class MedicationSearchModel
{
public int? Id { get; set; }
public string? MedicationName { get; set; } = string.Empty;
public int? DoctorId { get; set; }
public double? Price { get; set; }
}
}

View File

@ -0,0 +1,10 @@
namespace VeterinaryContracts.SearchModels
{
public class OwnerSearchModel
{
public int? Id { get; set; }
public string? OwnerFIO { get; set; }
public string? Login { get; set; }
public string? Password { get; set; }
}
}

View File

@ -0,0 +1,12 @@
namespace VeterinaryContracts.SearchModels
{
public class PetSearchModel
{
public int? Id { get; set; }
public int? OwnerId { get; set; }
public string? PetName { get; set; }
public string? PetType { get; set; }
public string? PetBreed { get; set; }
public string? PetGender { get; set; }
}
}

View File

@ -0,0 +1,10 @@
namespace VeterinaryContracts.SearchModels
{
public class PurchaseSearchModel
{
public int? Id { get; set; }
public int? OwnerId { get; set; }
public int? DrugId { get; set; }
public DateTime? DateCreate { get; set; }
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VeterinaryContracts.SearchModels
{
public class ReportDrugsVisitsSearchModel
{
public List<int>? medicationsIds { get; set; }
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
}
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VeterinaryContracts.SearchModels
{
public class ReportPetsSearchModel
{
public List<int>? servicesIds { get; set; }
}
}

View File

@ -0,0 +1,7 @@
namespace VeterinaryContracts.SearchModels
{
public class ReportServicesSearchModel
{
public List<int>? petsIds { get; set; }
}
}

View File

@ -0,0 +1,9 @@
namespace VeterinaryContracts.SearchModels
{
public class ReportVisitsDrugsSearchModel
{
public List<int>? petsIds { get; set; }
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VeterinaryContracts.SearchModels
{
public class ServiceSearchModel
{
public int? Id { get; set; }
public string? ServiceName { get; set; }
public int VisitId { get; set; }
public int DoctorId { get; set; }
}
}

View File

@ -0,0 +1,11 @@
namespace VeterinaryContracts.SearchModels
{
public class VisitSearchModel
{
public int? Id { get; set; }
public int? OwnerId { get; set; }
public int? DoctorId { get; set; }
public string? VisitName { get; set; }
public DateTime? DateVisit { get; set; }
}
}

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VeterinaryContracts.BindingModels;
using VeterinaryContracts.ViewModels;
using VeterinaryContracts.SearchModels;
namespace VeterinaryContracts.StorageContracts
{
public interface IDoctorStorage
{
List<DoctorViewModel> GetFullList();
List<DoctorViewModel> GetFilteredList(DoctorSearchModel model);
DoctorViewModel? GetElement(DoctorSearchModel model);
DoctorViewModel? Insert(DoctorBindingModel model);
DoctorViewModel? Update(DoctorBindingModel model);
DoctorViewModel? Delete(DoctorBindingModel model);
}
}

View File

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VeterinaryContracts.BindingModels;
using VeterinaryContracts.ViewModels;
using VeterinaryContracts.SearchModels;
using VeterinaryDataModels;
namespace VeterinaryContracts.StorageContracts
{
public interface IDrugStorage
{
List<DrugViewModel> GetFullList();
List<DrugViewModel> GetFilteredList(DrugSearchModel model);
DrugViewModel? GetElement(DrugSearchModel model);
DrugViewModel? Insert(DrugBindingModel model);
DrugViewModel? Update(DrugBindingModel model);
DrugViewModel? Delete(DrugBindingModel model);
public bool SellDrugs(DrugBindingModel model, int count);
}
}

View File

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VeterinaryContracts.BindingModels;
using VeterinaryContracts.ViewModels;
using VeterinaryContracts.SearchModels;
namespace VeterinaryContracts.StorageContracts
{
public interface IMedicationStorage
{
List<MedicationViewModel> GetFullList();
List<MedicationViewModel> GetFilteredList(MedicationSearchModel model);
MedicationViewModel? GetElement(MedicationSearchModel model);
MedicationViewModel? Insert(MedicationBindingModel model);
MedicationViewModel? Update(MedicationBindingModel model);
MedicationViewModel? Delete(MedicationBindingModel model);
List<ReportPurchaseMedicationViewModel> GetReportMedicationPurchasesList(ListPurchasesSearchModel model);
List<ReportDrugsVisitsViewModel> GetReportDrugsVisits(ReportDrugsVisitsSearchModel model);
}
}

View File

@ -0,0 +1,16 @@
using VeterinaryContracts.BindingModels;
using VeterinaryContracts.SearchModels;
using VeterinaryContracts.ViewModels;
namespace VeterinaryContracts.StorageContracts
{
public interface IOwnerStorage
{
List<OwnerViewModel> GetFullList();
List<OwnerViewModel> GetFilteredList(OwnerSearchModel model);
OwnerViewModel? GetElement(OwnerSearchModel model);
OwnerViewModel? Insert(OwnerBindingModel model);
OwnerViewModel? Update(OwnerBindingModel model);
OwnerViewModel? Delete(OwnerBindingModel model);
}
}

View File

@ -0,0 +1,18 @@
using VeterinaryContracts.BindingModels;
using VeterinaryContracts.SearchModels;
using VeterinaryContracts.ViewModels;
namespace VeterinaryContracts.StorageContracts
{
public interface IPetStorage
{
List<PetViewModel> GetFullList();
List<PetViewModel> GetFilteredList(PetSearchModel model);
List<ReportServicesViewModel> GetReportServices(ReportServicesSearchModel model);
List<ReportVisitsDrugsViewModel> GetReportVisitsDrugs(ReportVisitsDrugsSearchModel model);
PetViewModel? GetElement(PetSearchModel model);
PetViewModel? Insert(PetBindingModel model);
PetViewModel? Update(PetBindingModel model);
PetViewModel? Delete(PetBindingModel model);
}
}

View File

@ -0,0 +1,14 @@
using VeterinaryContracts.BindingModels;
using VeterinaryContracts.SearchModels;
using VeterinaryContracts.ViewModels;
namespace VeterinaryContracts.StorageContracts
{
public interface IPurchaseStorage
{
List<PurchaseViewModel> GetFullList();
List<PurchaseViewModel> GetFilteredList(PurchaseSearchModel model);
PurchaseViewModel? GetElement(PurchaseSearchModel model);
PurchaseViewModel? Insert(PurchaseBindingModel model);
}
}

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VeterinaryContracts.BindingModels;
using VeterinaryContracts.ViewModels;
using VeterinaryContracts.SearchModels;
namespace VeterinaryContracts.StorageContracts
{
public interface IServiceStorage
{
List<ServiceViewModel> GetFullList();
List<ServiceViewModel> GetFilteredList(ServiceSearchModel model);
//List<ReportServicesViewModel> GetReportServices(ReportPetsSearchModel model);
ServiceViewModel? GetElement(ServiceSearchModel model);
ServiceViewModel? Insert(ServiceBindingModel model);
ServiceViewModel? Update(ServiceBindingModel model);
ServiceViewModel? Delete(ServiceBindingModel model);
}
}

View File

@ -0,0 +1,16 @@
using VeterinaryContracts.BindingModels;
using VeterinaryContracts.SearchModels;
using VeterinaryContracts.ViewModels;
namespace VeterinaryContracts.StorageContracts
{
public interface IVisitStorage
{
List<VisitViewModel> GetFullList();
List<VisitViewModel> GetFilteredList(VisitSearchModel model);
VisitViewModel? GetElement(VisitSearchModel model);
VisitViewModel? Insert(VisitBindingModel model);
VisitViewModel? Update(VisitBindingModel model);
VisitViewModel? Delete(VisitBindingModel model);
}
}

View File

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\VeterinaryDataModels\VeterinaryDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VeterinaryDataModels.Models;
namespace VeterinaryContracts.ViewModels
{
public class DoctorViewModel : IDoctorModel
{
public int Id { get; set; }
[DisplayName("ФИО кладовщика")]
public string DoctorFIO { get; set; } = string.Empty;
[DisplayName("Логин (эл. почта) кладовщика")]
public string Login { get; set; } = string.Empty;
[DisplayName("Пароль")]
public string Password { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VeterinaryDataModels.Models;
namespace VeterinaryContracts.ViewModels
{
public class DrugViewModel : IDrugModel
{
public int Id { get; set; }
[DisplayName("Название рекомендации")]
public string DrugName { get; set; } = string.Empty;
[DisplayName("Количество")]
public int Count { get; set; }
[DisplayName("Цена рекомендации")]
public double Price { get; set; }
[DisplayName("Дата создания")]
public DateTime DateCreate { get; set; }
public Dictionary<int, IServiceModel> DrugServices
{
get;
set;
} = new();
public int DoctorId { get; set; }
}
}

View File

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VeterinaryDataModels.Models;
namespace VeterinaryContracts.ViewModels
{
public class MedicationViewModel : IMedicationModel
{
public int Id { get; set; }
[DisplayName("Название медикамента")]
public string MedicationName { get; set; } = string.Empty;
[DisplayName("Цена")]
public double Price { get; set; }
public int DoctorId { get; set; }
public Dictionary<int, IPetModel> MedicationPets
{
get;
set;
} = new();
}
}

View File

@ -0,0 +1,16 @@
using System.ComponentModel;
using VeterinaryDataModels.Models;
namespace VeterinaryContracts.ViewModels
{
public class OwnerViewModel : IOwnerModel
{
public int Id { get; set; }
[DisplayName("ФИО хозяина")]
public string OwnerFIO { get; set; } = string.Empty;
[DisplayName("Логин (эл. почта)")]
public string Login { get; set; } = string.Empty;
[DisplayName("Пароль")]
public string Password { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,22 @@
using System.ComponentModel;
using VeterinaryDataModels.Models;
namespace VeterinaryContracts.ViewModels
{
public class PetViewModel : IPetModel
{
public int Id { get; set; }
[DisplayName("Хозяин")]
public int OwnerId { get; set; }
[DisplayName("Имя")]
public string PetName { get; set; } = string.Empty;
[DisplayName("Вид")]
public string PetType { get; set; } = string.Empty;
[DisplayName("Порода")]
public string PetBreed { get; set; } = string.Empty;
[DisplayName("Пол")]
public string PetGender { get; set; } = string.Empty;
public Dictionary<int, IVisitModel> VisitPets { get; set; } = new();
public Dictionary<int, IPurchaseModel> PurchasePets { get; set; } = new();
}
}

View File

@ -0,0 +1,24 @@
using System.ComponentModel;
using VeterinaryDataModels.Models;
namespace VeterinaryContracts.ViewModels
{
public class PurchaseViewModel : IPurchaseModel
{
public int Id { get; set; }
[DisplayName("Хозяин")]
public int OwnerId { get; set; }
public int DrugId { get; set; }
[DisplayName("Рекомендация")]
public string PuchaseName { get; set; }
[DisplayName("Прививка")]
public string DrugName { get; set; } = string.Empty;
[DisplayName("Количество")]
public int Count { get; set; }
[DisplayName("Сумма")]
public double Sum { get; set; }
[DisplayName("Дата прививки")]
public DateTime DateCreate { get; set; }
public Dictionary<int, IPetModel> PurchasePet { get; set; } = new();
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VeterinaryContracts.ViewModels
{
public class ReportDrugsVisitsViewModel
{
public string MedicationName { get; set; } = string.Empty;
public List<VisitViewModel> Visits { get; set; }
public List<DrugViewModel> Drugs { get; set; }
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VeterinaryContracts.ViewModels
{
public class ReportPetsViewModel
{
public string ServiceName { get; set; } = string.Empty;
public List<PetViewModel> Pets { get; set; } = new();
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VeterinaryContracts.ViewModels
{
public class ReportPurchaseMedicationViewModel
{
public string MedicationName { get; set; } = string.Empty;
public List<PurchaseViewModel> Purchases { get; set; } = new();
}
}

View File

@ -0,0 +1,8 @@
namespace VeterinaryContracts.ViewModels
{
public class ReportServicesViewModel
{
public string PetName { get; set; } = string.Empty;
public List<ServiceViewModel> Services { get; set; } = new();
}
}

View File

@ -0,0 +1,9 @@
namespace VeterinaryContracts.ViewModels
{
public class ReportVisitsDrugsViewModel
{
public string PetName { get; set; } = string.Empty;
public List<MedicationViewModel> Medicaments { get; set; }
public List<PurchaseViewModel> Purchases { get; set; }
}
}

View File

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VeterinaryDataModels.Models;
namespace VeterinaryContracts.ViewModels
{
public class ServiceViewModel : IServiceModel
{
public int Id { get; set; }
[DisplayName("Название услуги")]
public string ServiceName { get; set; } = string.Empty;
public int VisitId { get; set; }
public int DoctorId { get; set; }
[DisplayName("Визит")]
public string VisitName { get; set; } = string.Empty;
public Dictionary<int, IMedicationModel> ServiceMedications
{
get;
set;
} = new();
}
}

View File

@ -0,0 +1,20 @@
using System.ComponentModel;
using VeterinaryDataModels.Models;
namespace VeterinaryContracts.ViewModels
{
public class VisitViewModel : IVisitModel
{
public int Id { get; set; }
public int OwnerId { get; set; }
public int DoctorId { get; set; }
[DisplayName("Название визита")]
public string VisitName { get; set; } = string.Empty;
[DisplayName("Врач")]
public string DoctorName { get; set; } = string.Empty;
[DisplayName("Дата визита")]
public int ServiceId { get; set; }
public DateTime DateVisit { get; set; }
public Dictionary<int, IPetModel> VisitPet { get; set; } = new();
}
}

Some files were not shown because too many files have changed in this diff Show More