166 lines
5.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using HospitalBusinessLogic.OfficePackage;
using HospitalBusinessLogic.OfficePackage.HelperModels;
using HospitalContracts.BindingModels;
using HospitalContracts.BusinessLogicsContracts;
using HospitalContracts.SearchModels;
using HospitalContracts.StoragesContracts;
using HospitalContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HospitalBusinessLogic.BusinessLogics
{
public class ReportLogic : IReportLogic
{
private readonly IKurseStorage _kurseStorage;
private readonly IMedicinesStorage _medicineStorage;
private readonly IRecipesStorage _recipeStorage;
private readonly AbstractSaveToExcel _saveToExcel;
private readonly AbstractSaveToWord _saveToWord;
private readonly AbstractSaveToPdf _saveToPdf;
public ReportLogic(IKurseStorage kurseStorage, IMedicinesStorage medicineStorage, IRecipesStorage recipeStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
{
_saveToExcel = saveToExcel;
_saveToWord = saveToWord;
_saveToPdf = saveToPdf;
_kurseStorage = kurseStorage;
_medicineStorage = medicineStorage;
_recipeStorage = recipeStorage;
}
public List<ReportKurseMedicinesViewModel> GetKurseMedicines(List<int> Ids)
{
if (Ids == null)
{
return new List<ReportKurseMedicinesViewModel>();
}
var kurses = _kurseStorage.GetFullList();
List<MedicinesViewModel> medicines = new List<MedicinesViewModel>();
foreach (var mId in Ids)
{
var res = _medicineStorage.GetElement(new MedicinesSearchModel { Id = mId });
if (res != null)
{
medicines.Add(res);
}
}
var list = new List<ReportKurseMedicinesViewModel>();
foreach (var medicine in medicines)
{
var record = new ReportKurseMedicinesViewModel
{
MedicinesName = medicine.MedicinesName,
Kurses = new List<Tuple<int, string>>()
};
foreach (var kurse in kurses)
{
if (kurse.KurseMedicines.ContainsKey(medicine.Id))
{
record.Kurses.Add(new Tuple<int, string>(kurse.Id, kurse.Duration));
}
}
list.Add(record);
}
return list;
}
//public List<ReportMembersViewModel> GetMembers(ReportBindingModel model)
//{
// var listAll = new List<ReportMembersViewModel>();
// var listСonferences = _conferenceStorage.GetFilteredList(new ConferenceSearchModel
// {
// OrganiserId = model.OrganiserId,
// DateFrom = model.DateFrom,
// DateTo = model.DateTo
// });
// foreach (var conference in listСonferences)
// {
// foreach (var m in conference.ConferenceMembers.Values)
// {
// listAll.Add(new ReportMembersViewModel
// {
// StartDate = conference.StartDate,
// ConferenceName = conference.ConferenceName,
// MemberFIO = m.MemberFIO
// });
// }
// }
// var listMealPlans = _mealPlanStorage.GetFilteredList(new MealPlanSearchModel
// {
// OrganiserId = model.OrganiserId,
// });
// foreach (var mealPlan in listMealPlans)
// {
// foreach (var mp in mealPlan.MealPlanMembers.Values)
// {
// listAll.Add(new ReportMembersViewModel
// {
// MemberFIO = mp.MemberFIO,
// MealPlanName = mealPlan.MealPlanName,
// MealPlanPrice = mealPlan.MealPlanPrice
// });
// }
// }
// return listAll;
//}
public List<ReportMedicinesViewModel> GetRecipeMedicine(ReportBindingModel model)
{
throw new NotImplementedException();
}
public void SaveMedicinesToExcelFile(ReportBindingModel model)
{
_saveToExcel.CreateReport(new ExcelInfo
{
FileName = model.FileName,
Title = "Список курсов",
KurseMedicines = GetKurseMedicines(model.Ids)
});
}
public void SaveMedicinesToWordFile(ReportBindingModel model)
{
_saveToWord.CreateDoc(new WordInfo
{
FileName = model.FileName,
Title = "Список курсов",
KurseMedicines = GetKurseMedicines(model.Ids)
});
}
//public void SaveMembersToPdfFile(ReportBindingModel model)
//{
// if (model.DateFrom == null)
// {
// throw new ArgumentException("Дата начала не задана");
// }
// if (model.DateTo == null)
// {
// throw new ArgumentException("Дата окончания не задана");
// }
// _saveToPdf.CreateDoc(new PdfInfoOrganiser
// {
// FileName = model.FileName,
// Title = "Список участников",
// DateFrom = model.DateFrom!.Value,
// DateTo = model.DateTo!.Value,
// Members = GetMembers(model)
// });
//}
public void SaveOrdersToPdfFile(ReportBindingModel model)
{
throw new NotImplementedException();
}
}
}