сделан отчет и заглушка для сотрудника

This commit is contained in:
Альфия Тукаева 2023-04-08 23:40:04 +03:00
parent 15bcd7eb8a
commit c2a3d72fda
19 changed files with 267 additions and 121 deletions

View File

@ -0,0 +1,130 @@
using SchoolContracts.BusinessLogicsContracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SchoolBusinessLogic.BusinessLogics
{
/// <summary>
/// Заглушка для роли сотрудника
/// </summary>
public class EmployeeRoleImitationaLogic
{
private readonly IEmployeeLogic _employeeLogic;
private readonly ILessonLogic _lessonLogic;
private readonly IExpenseLogic _ExpenseLogic;
private readonly ICircleLogic _circleLogic;
private readonly ICircleExpenseLogic _circleExpenseLogic;
public EmployeeRoleImitationaLogic(IEmployeeLogic employeeLogic,
ILessonLogic lessonLogic, IExpenseLogic ExpenseLogic,
ICircleLogic circleLogic, ICircleExpenseLogic circleExpenseLogic)
{
_employeeLogic = employeeLogic;
_lessonLogic = lessonLogic;
_ExpenseLogic = ExpenseLogic;
_circleLogic = circleLogic;
_circleExpenseLogic = circleExpenseLogic;
}
private bool GenerateEmployeeData()
{
if(_employeeLogic.ReadList(null)?.Count != 0 )
{
return false;
}
using (StreamReader sr = new("employees.txt"))
{
string? currentString;
while ((currentString = sr.ReadLine()) != null)
{
var employeeRecData = currentString.Split(',');
_employeeLogic.Create(new()
{
EmployeeEmail = employeeRecData[0],
EmployeePassword = employeeRecData[1],
EmployeeName = employeeRecData[2],
EmployeePhone = employeeRecData[3]
});
}
}
return true;
}
private bool GenerateLessonData()
{
if(_lessonLogic.ReadList(null)?.Count != 0)
{
return false;
}
using (StreamReader sr = new("lessons.txt"))
{
string? currentString;
while ((currentString = sr.ReadLine()) != null)
{
var lessonRecData = currentString.Split(',');
_lessonLogic.Create(new()
{
LessonName = Convert.ToString(lessonRecData[0]),
LessonPrice = Convert.ToDouble(lessonRecData[1])
});
}
}
return true;
}
public bool GenerateExpense()
{
if (_ExpenseLogic.ReadList(null)?.Count != 0)
{
return false;
}
using (StreamReader sr = new("expenses.txt"))
{
string? currentString;
while ((currentString = sr.ReadLine()) != null)
{
var expenseRecData = currentString.Split(',');
_ExpenseLogic.Create(new()
{
ExpenseName = Convert.ToString(expenseRecData[0]),
Sum = Convert.ToDouble(expenseRecData[1]),
Count = Convert.ToInt32(expenseRecData[2]),
EmployeeId = Convert.ToInt32(expenseRecData[3])
});
}
}
return true;
}
public bool GenerateCircleExpense()
{
var ExpenseList = _ExpenseLogic.ReadList(null);
if (ExpenseList == null)
{
return false;
}
if (ExpenseList.Count == 0)
{
return false;
}
var CircleList = _circleLogic.ReadList(null);
if (CircleList == null)
{
return false;
}
if (CircleList.Count == 0)
{
return false;
}
Random rnd = new Random();
for (int i = 0; i < 2; i++)
{
_circleExpenseLogic.Create(new()
{
ExpenseId = rnd.Next(0, ExpenseList.Count),
CircleId = rnd.Next(0, CircleList.Count)
});
}
return true;
}
}
}

View File

@ -1,13 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SchoolBusinessLogic.BusinessLogics
{
public class ReportLessonsLogic
{
}
}

View File

@ -1,51 +1,54 @@
using Microsoft.Extensions.Logging;
using Microsoft.Identity.Client;
using SchoolContracts.BusinessLogicsContracts;
using SchoolContracts.StoragesContracts;
using SchoolContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SchoolDatabaseImplement.Models;
using SchoolDataModels.Models;
using SchoolContracts.BindingModel;
namespace SchoolContracts.BusinessLogics
{
public class ReportLogic : IReportLogic
{
private readonly ICircleStorage _circleStorage;
private readonly ILogger _logger;
private readonly ICircleExpenseStorage _circleExpenseStorage;
private readonly IExpenseStorage _expenseStorage;
/// <summary>
/// Получение списка кружков с указанием списка затрат по ним
/// </summary>
/// <returns></returns>
public List<ReportViewModel> GetCircles()
public ReportLogic(ILogger logger, ICircleStorage circleStorage,
ICircleExpenseStorage circleExpenseStorage)
{
var expenses = _expenseStorage.GetFullList();
var circles = _circleStorage.GetFullList();
var list = new List<ReportViewModel>();
foreach(var circle in circles)
{
var record = new ReportViewModel
{
CircleNumber = circle.Id,
Expenses = new List<ReportExpensesViewModel>(),
CircleCount = 0
};
foreach (var expense in expenses)
{
}
list.Add(record);
}
return list;
_logger = logger;
_circleStorage = circleStorage;
_circleExpenseStorage = circleExpenseStorage;
}
/// <summary>
/// Получение списка занятий за определенный период
/// получение занятий по кружку
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public List<ReportCircleLessonsViewModel> GetLessonCircles(ReportBindingModel model)
{
return _circleStorage.GetLessonCircles(new() { SelectedCirclesIds = model.SelectedCircles});
}
/// <summary>
/// получение затрат кружку
/// </summary>
public List<ReportExpensesInCirclesViewModel> GetExpenses (ReportBindingModel model)
{
return _circleExpenseStorage.GetExpensesInCircles(new() { DateFrom = model.DateFrom, DateTo = model.DateTo });
}
public void SaveComponentsToWordFile(ReportBindingModel model)
{
throw new NotImplementedException();
}
public void SaveManufactureComponentToExcelFile(ReportBindingModel model)
{
throw new NotImplementedException();
}
public void SaveOrdersToPdfFile(ReportBindingModel model)
{
throw new NotImplementedException();
}
}
}

View File

@ -13,7 +13,6 @@ namespace SchoolContracts.BindingModel
public DateTime DateStart { get; set; } = DateTime.Now;
public int ClientId { get; set; }
public int LessonId { get; set; }
public double Remains { get; set; }
}
}

View File

@ -12,5 +12,7 @@ namespace SchoolContracts.BindingModels
public int Id { get; set; }
public double Sum { get; set;}
public string ExpenseName { get; set;}
public int Count { get; set; }
public int EmployeeId { get; set; }
}
}

View File

@ -12,16 +12,16 @@ namespace SchoolContracts.BusinessLogicsContracts
public interface IReportLogic
{
/// <summary>
/// Получение списка кружков
/// Получение списка кружков по занятиям
/// </summary>
/// <returns></returns>
List<ReportCirclesViewModel> GetCircles(ReportBindingModel model);
List<ReportCircleLessonsViewModel> GetLessonCircles(ReportBindingModel model);
/// <summary>
/// Получение списка затрат за определенный период
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
//List<ReportOrdersViewModel> GetExpenses(ReportBindingModel model);
List<ReportExpensesInCirclesViewModel> GetExpenses(ReportBindingModel model);
/// <summary>
/// Сохранение компонент в файл-Word
/// </summary>

View File

@ -9,5 +9,7 @@ namespace SchoolContracts.SearchModel
public class CircleExpenseSearchModel
{
public int? Id { get; set; }
public DateTime? DateTo { get; set; }
public DateTime? DateFrom { get; set; }
}
}

View File

@ -18,5 +18,6 @@ namespace SchoolContracts.StoragesContracts
CircleExpenseViewModel? Insert(CircleExpenseBindingModel model);
CircleExpenseViewModel? Update(CircleExpenseBindingModel model);
CircleExpenseViewModel? Delete(CircleExpenseBindingModel model);
List<ReportExpensesInCirclesViewModel> GetExpensesInCircles(CircleExpenseSearchModel model);
}
}

View File

@ -12,5 +12,7 @@ namespace SchoolContracts.ViewModels
public int Id { get; set; }
public string ExpenseName { get; set; }
public double Sum { get; set; }
public int Count { get; set; }
public int EmployeeId { get; set; }
}
}

View File

@ -18,6 +18,6 @@ namespace SchoolContracts.ViewModels
/// <summary>
/// Занятия в кружке
/// </summary>
public List<ReportLessonCirclesViewModel> CircleLessons { get; set; } = new();
public List<ReportLessonCirclesViewModel> Lessons { get; set; } = new();
}
}

View File

@ -7,12 +7,18 @@ using System.Threading.Tasks;
namespace SchoolContracts.ViewModels
{
public class ReportExpensesViewModel
public class ReportExpensesInCirclesViewModel
{
[DisplayName("Название затраты")]
public string ExpenseName { get; set; } = string.Empty;
[DisplayName("Сумма")]
public double Sum { get; set; }
[DisplayName("Номер кружка")]
public int CircleId { get; set; }
[DisplayName("Имя сотрудника")]
public string EmployeeName { get; set; }
[DisplayName("Кол-во затрат")]
public int Count { get; set; }
}
}

View File

@ -7,17 +7,21 @@ using System.Threading.Tasks;
namespace SchoolContracts.ViewModels
{
/// <summary>
/// Модель для получения всех занятий по кружку для отчета
/// Модель для получения одного занятия для отчета
/// </summary>
public class ReportLessonCircleViewModel
public class ReportLessonCirclesViewModel
{
/// <summary>
/// Номер кружка
/// Номер занятия
/// </summary>
public int CircleId { get; set; }
public int LessonId { get; set; }
/// <summary>
/// Занятия в кружке
/// Имя сотрудника
/// </summary>
public List<ReportCircleLessonsViewModel> CircleLessons { get; set; } = new();
public string EmployeeName{ get; set; } = string.Empty;
/// <summary>
/// Стоимость
/// </summary>
public double Sum { get; set; }
}
}

View File

@ -1,24 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SchoolContracts.ViewModels
{
public class ReportViewModel
{
[DisplayName("Имя кружка")]
public int CircleNumber { get; set; }
[DisplayName("Дата записи")]
public DateTime Date { get; set; }
[DisplayName("Сумма затрат")]
public double Sum { get; set; }
[DisplayName("Кол-во занятий")]
public int CircleCount { get; set; }
[DisplayName("Название затраты")]
public List<ReportExpensesViewModel> Expenses{ get; set; }
}
}

View File

@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace SchoolDataModels.Models
{
/// <summary>
/// Затрата на кружок
/// Затраты
/// </summary>
public interface IExpenseModel : IId
{
@ -19,5 +19,13 @@ namespace SchoolDataModels.Models
/// Название
/// </summary>
public string ExpenseName { get; }
/// <summary>
/// количество
/// </summary>
public int Count { get; set; }
/// <summary>
/// Id сотрудника
/// </summary>
public int EmployeeId { get; set; }
}
}

View File

@ -44,6 +44,27 @@ namespace SchoolDatabaseImplements.Implements
return null;
}
public List<ReportExpensesInCirclesViewModel> GetExpensesInCircles(CircleExpenseSearchModel model)
{
if (model.DateFrom == null || model.DateTo == null)
{
return new();
}
using var context = new SchoolDatabase();
return context.CircleExpenses.Include(x => x.Circle)
.Include(x => x.Expense)
.ThenInclude(x => x.Employee)
.Select(x => new ReportExpensesInCirclesViewModel()
{
EmployeeName = x.Expense.Employee.EmployeeName,
CircleId = x.Circle.Id,
ExpenseName = x.Expense.ExpenseName,
Count = x.Expense.Count,
Sum= x.Expense.Sum
})
.ToList();
}
public List<CircleExpenseViewModel> GetFilteredList(CircleExpenseSearchModel model)
{
using var context = new SchoolDatabase();

View File

@ -26,22 +26,11 @@ namespace SchoolDatabaseImplement.Implements
public List<CircleViewModel> GetFilteredList(CircleSearchModel model)
{
using var context = new SchoolDatabase();
if (model.DateFrom.HasValue && model.DateTo.HasValue) // если не ищем по айдишнику, значит ищем по диапазону дат
{
return context.Circles
.Where(x => model.DateFrom <= x.DateStart.Date && x.DateStart <= model.DateTo)
.Where(x => x.Id == model.Id)
.Include(x => x.Client)
.Select(x => x.GetViewModel)
.ToList();
}
if (model.ClientId.HasValue)
{
return context.Circles
.Where(x => x.Client.Id == model.ClientId)
.Select(x => x.GetViewModel)
.ToList();
}
return new();
}
public CircleViewModel? GetElement(CircleSearchModel model)
{
@ -93,7 +82,11 @@ namespace SchoolDatabaseImplement.Implements
}
return null;
}
/// <summary>
/// Получение списка занятий по выбранному кружку
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public List<ReportCircleLessonsViewModel> GetLessonCircles(CircleSearchModel model)
{
if (model.SelectedCirclesIds == null)
@ -102,26 +95,23 @@ namespace SchoolDatabaseImplement.Implements
}
using var context = new SchoolDatabase();
return context.Circles
.Where(c => model.SelectedCirclesIds.Contains(c.Id))
.Select(c => new ReportCircleLessonsViewModel()
.Where(x => model.SelectedCirclesIds.Contains(x.Id))
.Select(x => new ReportCircleLessonsViewModel()
{
CircleLessons = GetCircleLessons(context, new() { Id = c.Id })
})
.ToList();
}
/// <summary>
/// Получение списка занятий по выбранному кружку
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
private static List<ReportLessonCirclesViewModel> GetCircleLessons(SchoolDatabase context, CircleSearchModel model)
{
return context.Circles
.Include(wir => wir.CircleLessons)
.Where(wir => wir.Id == model.Id)
.Select(wir => new ReportLessonCirclesViewModel()
{
LessonId = wir.CircleLessons.Id
CircleId= x.Id,
Lessons = context.CircleLessons
.Include(x => x.Lesson)
.ThenInclude(x => x.Employee)
.Where(x => x.CircleId == x.Id)
.Select(x => new ReportLessonCirclesViewModel()
{
LessonId = x.Circle.Id,
EmployeeName = x.Lesson.Employee.EmployeeName,
Sum = x.Lesson.LessonPrice
})
.ToList()
})
.ToList();
}

View File

@ -2,6 +2,7 @@
using SchoolContracts.BindingModel;
using SchoolContracts.BindingModels;
using SchoolContracts.ViewModels;
using SchoolDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

View File

@ -23,6 +23,8 @@ namespace SchoolDatabaseImplement.Models
[Required]
public string EmployeeName { get; set; } = string.Empty;
[ForeignKey("EmployeeId")]
public virtual List<Expense> Expenses { get; set; } = new();
[ForeignKey("EmployeeId")]
public virtual List<Lesson> Lessons { get; set; } = new();
public static Employee? Create(EmployeeBindingModel model)
{
@ -51,9 +53,13 @@ namespace SchoolDatabaseImplement.Models
EmployeePhone = model.EmployeePhone;
}
public ExpenseViewModel GetViewModel => new()
public EmployeeViewModel GetViewModel => new()
{
Id = Id
Id = Id,
EmployeeName = EmployeeName,
EmployeeEmail = EmployeeEmail,
EmployeePassword = EmployeePassword,
EmployeePhone = EmployeePhone
};
}

View File

@ -18,9 +18,15 @@ namespace SchoolDatabaseImplement.Models
public string ExpenseName { get; private set; } = string.Empty;
[Required]
public double Sum { get; private set; }
[Required]
public int Count { get; private set; }
public int EmployeeId { get; private set; }
public int CircleId { get; private set; }
[ForeignKey("ExpenseId")]
public virtual List<CircleExpense> CircleExpenses { get; set; } = new();
public static Expense? Create(ExpenseBindingModel model)
[ForeignKey("ExpenseId")]
public virtual Employee Employee { get; set; } = new();
public static Expense? Create(SchoolDatabase context, ExpenseBindingModel model)
{
if (model == null)
{
@ -30,7 +36,9 @@ namespace SchoolDatabaseImplement.Models
{
Id = model.Id,
ExpenseName = model.ExpenseName,
Sum = model.Sum
Sum = model.Sum,
Count = model.Count,
Employee = context.Employees.First(x => x.Id == model.EmployeeId)
};
}
public void Update(ExpenseBindingModel model)