guarantor

This commit is contained in:
Дмитрий Блохин 2024-05-27 21:03:42 +04:00
parent 1d49b42cd6
commit 1df5102671
30 changed files with 1199 additions and 270 deletions

View File

@ -8,6 +8,7 @@ namespace Contracts.BindingModels
public int UserId { get; set; } public int UserId { get; set; }
public string Title { get; set; } = string.Empty; public string Title { get; set; } = string.Empty;
public string Country { get; set; } = string.Empty; public string Country { get; set; } = string.Empty;
public Dictionary<int, IWorkerModel> MachineWorker { get; set; } = new(); public DateTime DateCreate { get; set; }
public Dictionary<int, IWorkerModel> MachineWorker { get; set; } = new();
} }
} }

View File

@ -9,7 +9,8 @@ namespace Contracts.BindingModels
public string Title { get; set; } = string.Empty; public string Title { get; set; } = string.Empty;
public string Address { get; set; } = string.Empty; public string Address { get; set; } = string.Empty;
public string Director { get; set; } = string.Empty; public string Director { get; set; } = string.Empty;
public int? ProductionId { get; set; } public DateTime DateCreate { get; set; }
public int? ProductionId { get; set; }
public Dictionary<int, IWorkerModel> WorkshopWorker { get; set; } = new(); public Dictionary<int, IWorkerModel> WorkshopWorker { get; set; } = new();
} }
} }

View File

@ -4,5 +4,6 @@
{ {
public int? Id { get; set; } public int? Id { get; set; }
public string? Login { get; set; } public string? Login { get; set; }
public string? Password { get; set; }
} }
} }

View File

@ -6,6 +6,7 @@
public string? Title { get; set; } public string? Title { get; set; }
public int? UserId { get; set; } public int? UserId { get; set; }
public int? WorkerId { get; set; } public int? WorkerId { get; set; }
public int? WorkshopId { get; set; }
public DateTime? DateFrom { get; set; } public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; } public DateTime? DateTo { get; set; }
} }

View File

@ -14,6 +14,7 @@ namespace Contracts.ViewModels
public string Director { get; set; } = string.Empty; public string Director { get; set; } = string.Empty;
public int UserId { get; set; } public int UserId { get; set; }
public int? ProductionId { get; set; } public int? ProductionId { get; set; }
public string? ProductionName { get; set; }
public Dictionary<int, IWorkerModel>? WorkerWorkshops { get; set; } public Dictionary<int, IWorkerModel>? WorkerWorkshops { get; set; }
} }
} }

View File

@ -23,7 +23,7 @@ namespace DatabaseImplement.Implements
{ {
if (!model.Id.HasValue && string.IsNullOrEmpty(model.Login)) { return null; } if (!model.Id.HasValue && string.IsNullOrEmpty(model.Login)) { return null; }
using var context = new FactoryGoWorkDatabase(); using var context = new FactoryGoWorkDatabase();
return context.Guarantors.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id) || (!string.IsNullOrEmpty(model.Login) && x.Login.Equals(model.Login)))?.GetViewModel; ; return context.Guarantors.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id) || (!string.IsNullOrEmpty(model.Login) && !string.IsNullOrEmpty(model.Password) && x.Login.Equals(model.Login) && x.Password.Equals(model.Password)))?.GetViewModel; ;
} }
public List<GuarantorViewModel> GetFilteredList(GuarantorSearchModel model) public List<GuarantorViewModel> GetFilteredList(GuarantorSearchModel model)

View File

@ -24,7 +24,7 @@ namespace DatabaseImplement.Implements
public MachineViewModel? GetElement(MachineSearchModel model) public MachineViewModel? GetElement(MachineSearchModel model)
{ {
using var context = new FactoryGoWorkDatabase(); using var context = new FactoryGoWorkDatabase();
return context.Machines.Include(p => p.Workers).ThenInclude(p => p.Worker).FirstOrDefault(x => (!string.IsNullOrEmpty(model.Title) && x.Title.Contains(model.Title)) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; return context.Machines.Include(p => p.Workers).ThenInclude(p => p.Worker).FirstOrDefault(x => (!string.IsNullOrEmpty(model.Title) && x.Title.Equals(model.Title)) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
} }
public List<MachineViewModel> GetFilteredList(MachineSearchModel model) public List<MachineViewModel> GetFilteredList(MachineSearchModel model)
@ -35,9 +35,9 @@ namespace DatabaseImplement.Implements
} }
using var context = new FactoryGoWorkDatabase(); using var context = new FactoryGoWorkDatabase();
if (model.DateFrom.HasValue) if (model.DateFrom.HasValue)
return context.Machines.Where(x => x.UserId == model.Id).Where(x => x.DateCreate < model.DateTo && x.DateCreate > model.DateFrom).Select(x => x.GetViewModel).ToList(); return context.Machines.Where(x => x.UserId == model.UserId).Where(x => x.DateCreate <= model.DateTo && x.DateCreate >= model.DateFrom).Select(x => x.GetViewModel).ToList();
else else
return context.Machines.Where(x => x.UserId == model.Id).Select(x => x.GetViewModel).ToList(); return context.Machines.Where(x => x.UserId == model.UserId).Select(x => x.GetViewModel).ToList();
} }
public List<MachineViewModel> GetFullList() public List<MachineViewModel> GetFullList()

View File

@ -22,7 +22,7 @@ namespace DatabaseImplement.Implements
public WorkerViewModel? GetElement(WorkerSearchModel model) public WorkerViewModel? GetElement(WorkerSearchModel model)
{ {
using var context = new FactoryGoWorkDatabase(); using var context = new FactoryGoWorkDatabase();
return context.Workers.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name.Contains(model.Name)) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; return context.Workers.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name.Equals(model.Name)) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
} }
public List<WorkerViewModel> GetFilteredList(WorkerSearchModel model) public List<WorkerViewModel> GetFilteredList(WorkerSearchModel model)
@ -32,7 +32,7 @@ namespace DatabaseImplement.Implements
return new(); return new();
} }
using var context = new FactoryGoWorkDatabase(); using var context = new FactoryGoWorkDatabase();
return context.Workers.Where(x => x.UserId == model.Id).Select(x => x.GetViewModel).ToList(); return context.Workers.Where(x => x.UserId == model.UserId).Select(x => x.GetViewModel).ToList();
} }
public List<WorkerViewModel> GetFullList() public List<WorkerViewModel> GetFullList()

View File

@ -25,7 +25,7 @@ namespace DatabaseImplement.Implements
public WorkshopViewModel? GetElement(WorkshopSearchModel model) public WorkshopViewModel? GetElement(WorkshopSearchModel model)
{ {
using var context = new FactoryGoWorkDatabase(); using var context = new FactoryGoWorkDatabase();
return context.Workshops.Include(x => x.Workers).ThenInclude(x => x.Worker).FirstOrDefault(x => (!string.IsNullOrEmpty(model.Title) && x.Title.Contains(model.Title)) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; return context.Workshops.Include(x => x.Workers).ThenInclude(x => x.Worker).Include(x => x.Production).FirstOrDefault(x => (!string.IsNullOrEmpty(model.Title) && x.Title.Equals(model.Title)) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
} }
public List<WorkshopViewModel> GetFilteredList(WorkshopSearchModel model) public List<WorkshopViewModel> GetFilteredList(WorkshopSearchModel model)
@ -38,9 +38,9 @@ namespace DatabaseImplement.Implements
if (model.DetailId.HasValue) if (model.DetailId.HasValue)
return context.Workshops.Where(x => x.ProductionId.HasValue).Include(x => x.Production).Where(x => x.Production.Details.FirstOrDefault(y => y.DetailId == model.DetailId) != null).Where(x => x.UserId == model.UserId).Select(x => x.GetViewModel).ToList(); return context.Workshops.Where(x => x.ProductionId.HasValue).Include(x => x.Production).Where(x => x.Production.Details.FirstOrDefault(y => y.DetailId == model.DetailId) != null).Where(x => x.UserId == model.UserId).Select(x => x.GetViewModel).ToList();
else if (model.DateFrom.HasValue) else if (model.DateFrom.HasValue)
return context.Workshops.Where(x => x.UserId == model.Id).Where(x => x.DateCreate < model.DateTo && x.DateCreate > model.DateFrom).Select(x => x.GetViewModel).ToList(); return context.Workshops.Where(x => x.UserId == model.UserId).Where(x => x.DateCreate <= model.DateTo && x.DateCreate >= model.DateFrom).Select(x => x.GetViewModel).ToList();
else else
return context.Workshops.Where(x => x.UserId == model.Id).Select(x => x.GetViewModel).ToList(); return context.Workshops.Where(x => x.UserId == model.UserId).Include(x => x.Production).Select(x => x.GetViewModel).ToList();
} }
public List<WorkshopViewModel> GetFullList() public List<WorkshopViewModel> GetFullList()

View File

@ -76,7 +76,7 @@ namespace DatabaseImplement.Models
Title = model.Title; Title = model.Title;
Address = model.Address; Address = model.Address;
Director = model.Director; Director = model.Director;
ProductionId = model.ProductionId; ProductionId = model.ProductionId == null ? ProductionId : model.ProductionId;
} }
public WorkshopViewModel GetViewModel => new() public WorkshopViewModel GetViewModel => new()
{ {
@ -85,6 +85,7 @@ namespace DatabaseImplement.Models
Address = Address, Address = Address,
Director = Director, Director = Director,
ProductionId = ProductionId, ProductionId = ProductionId,
ProductionName = Production == null ? null : Production.Name,
UserId = UserId, UserId = UserId,
WorkerWorkshops = WorkerWorkshops WorkerWorkshops = WorkerWorkshops
}; };

View File

@ -1,4 +1,5 @@
using Contracts.BusinessLogicsContracts; using Contracts.BindingModels;
using Contracts.BusinessLogicsContracts;
using Contracts.ViewModels; using Contracts.ViewModels;
using GuarantorAPP.Models; using GuarantorAPP.Models;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@ -9,173 +10,280 @@ namespace GuarantorAPP.Controllers
public class HomeController : Controller public class HomeController : Controller
{ {
private readonly ILogger<HomeController> _logger; private readonly ILogger<HomeController> _logger;
private readonly IGuarantorLogic _userLogic; private readonly GuarantorData _data;
private readonly IMachineLogic _machineLogic;
private readonly IWorkerLogic _workerLogic;
private readonly IWorkshopLogic _workshopLogic;
public HomeController(ILogger<HomeController> logger) public HomeController(ILogger<HomeController> logger, GuarantorData data)
{ {
_logger = logger; _logger = logger;
_data = data;
}
private bool IsLoggedIn { get { return UserGuarantor.user != null; } }
private int UserId { get { return UserGuarantor.user!.Id; } }
public IActionResult IndexNonReg()
{
if (!IsLoggedIn)
return View();
return RedirectToAction("Index");
} }
public IActionResult Index() public IActionResult Index()
{ {
if (!IsLoggedIn)
return RedirectToAction("IndexNonReg");
return View(); return View();
} }
public IActionResult Enter() [HttpGet]
{ public IActionResult Enter()
return View(); {
} if (!IsLoggedIn)
return View();
return RedirectToAction("Index");
}
[HttpPost]
public void Enter(string login, string password)
{
var user = _data.Login(login, password);
if (user != null)
{
UserGuarantor.user = user;
Response.Redirect("Index");
}
}
[HttpGet]
public IActionResult Register() public IActionResult Register()
{ {
return View(); return View();
} }
public IActionResult Logout()
{
UserGuarantor.user = null;
return RedirectToAction("IndexNonReg");
}
[HttpPost]
public void Register(string name, string login, string email, string password1, string password2)
{
if (password1 == password2 && _data.Register(new() { Email = email, Login = login, Name = name, Password = password1 }))
{
Response.Redirect("Index");
}
}
[HttpGet]
public IActionResult IndexMachine() public IActionResult IndexMachine()
{ {
List<MachineViewModel> machines = new List<MachineViewModel> if (UserGuarantor.user != null)
{ {
new MachineViewModel var machines = _data.GetMachines(UserGuarantor.user.Id);
{ return View(machines);
Id = 1,
Title = "Токарный станок",
Country = "Китай",
UserId = 1
},
new MachineViewModel
{
Id = 2,
Title = "Фрезерный станок",
Country = "Россия",
UserId = 2
} }
}; return RedirectToAction("IndexNonReg");
return View(machines);
} }
public IActionResult CreateMachine() [HttpPost]
public IActionResult IndexMachine(int id)
{ {
var workers = new List<WorkerViewModel>(); _data.DeleteMachine(id);
workers.Add(new WorkerViewModel return RedirectToAction("IndexMachine");
{ }
Id = 1, [HttpGet]
Name = "Фролов Феодосий Валерьевич", public IActionResult CreateMachine(int id)
Birthday = new DateTime(1989, 03, 29), {
Specialization = "Металлург", var workers = _data.GetWorkers(UserGuarantor.user!.Id);
Salary = 55000, ViewBag.AllWorkers = workers;
UserId = 1 if (id != 0)
}); {
workers.Add(new WorkerViewModel var value = _data.GetMachine(id);
{ if (value != null)
Id = 2, return View(value);
Name = "Медведков Андрей Алексеевич", }
Birthday = new DateTime(2004, 02, 29), return View(new MachineViewModel());
Specialization = "Слесарь", }
Salary = 25000, [HttpPost]
UserId = 2 public IActionResult CreateMachine(int id, string title, int[] workerIds)
}); {
return View(workers); MachineBindingModel model = new MachineBindingModel();
} model.Id = id;
model.Title = title;
model.DateCreate = DateTime.Now;
model.UserId = UserGuarantor.user!.Id;
var workers = _data.GetWorkers(UserGuarantor.user!.Id);
for (int i = 0; i < workerIds.Length; i++)
{
var worker = workers!.FirstOrDefault(x => x.Id == workerIds[i]);
model.MachineWorker[workerIds[i]] = worker;
}
bool changed = false;
if (model.MachineWorker.Count > 0)
{
if (id != 0)
{
changed = _data.UpdateMachine(model);
}
else
{
changed = _data.CreateMachine(model);
}
}
if (changed)
return RedirectToAction("IndexMachine");
else
{
ViewBag.AllWorkers = workers;
return View(model);
}
}
[HttpGet]
public IActionResult IndexWorker() public IActionResult IndexWorker()
{ {
var workers = new List<WorkerViewModel>(); if (UserGuarantor.user != null)
workers.Add(new WorkerViewModel {
{ var list = _data.GetWorkers(UserGuarantor.user.Id);
Id = 1, if (list != null)
Name = "Фролов Феодосий Валерьевич", return View(list);
Birthday = new DateTime(1989, 03, 29), return View(new List<WorkerViewModel>());
Specialization = "Металлург", }
Salary = 55000, return RedirectToAction("IndexNonReg");
UserId = 1
});
workers.Add(new WorkerViewModel
{
Id = 2,
Name = "Медведков Андрей Алексеевич",
Birthday = new DateTime(2004, 02, 29),
Specialization = "Слесарь",
Salary = 25000,
UserId = 2
});
return View(workers);
} }
public IActionResult CreateWorker() [HttpPost]
public void IndexWorker(int id)
{ {
if (UserGuarantor.user != null)
{
_data.DeleteWorker(id);
}
Response.Redirect("IndexWorker");
}
[HttpGet]
public IActionResult CreateWorker(int id)
{
if (id != 0)
{
var value = _data.GetWorker(id);
if (value != null)
return View(value);
}
return View(new WorkerViewModel());
}
[HttpPost]
public IActionResult CreateWorker(WorkerBindingModel model)
{
if (model.Id == 0)
{
model.UserId = UserGuarantor.user!.Id;
if (_data.CreateWorker(model))
return RedirectToAction("IndexWorker");
}
else
{
if (_data.UpdateWorker(model))
return RedirectToAction("IndexWorker");
}
return View(); return View();
} }
[HttpGet]
public IActionResult IndexWorkshop() public IActionResult IndexWorkshop()
{ {
List<WorkshopViewModel> workshops = new List<WorkshopViewModel> if (IsLoggedIn)
{ {
new WorkshopViewModel var workshops = _data.GetWorkshops(UserGuarantor.user!.Id);
{ return View(workshops);
Id = 1, }
Title = "Механический цех", return RedirectToAction("IndexNonReg");
Address = "Ул. Пушкина, колотушкина",
Director = "Главный Андрей цеха",
UserId = 1,
ProductionId = 1,
},
new WorkshopViewModel
{
Id = 2,
Title = "Сварочный цех",
Address = "Ул. Пушкина, колотушкина 22",
Director = "Фрезер Давыд Анатольевич",
UserId = 2,
ProductionId = 2,
}
};
return View(workshops);
} }
public IActionResult CreateWorkshop() [HttpPost]
public IActionResult IndexWorkshop(int id)
{ {
var workers = new List<WorkerViewModel>(); _data.DeleteWorkshop(id);
workers.Add(new WorkerViewModel return RedirectToAction("IndexWorkshop");
{ }
Id = 1, [HttpGet]
Name = "Фролов Феодосий Валерьевич", public IActionResult CreateWorkshop(int id)
Birthday = new DateTime(1989, 03, 29), {
Specialization = "Металлург", var workers = _data.GetWorkers(UserGuarantor.user!.Id);
Salary = 55000, ViewBag.AllWorkers = workers;
UserId = 1 if (id != 0)
}); {
workers.Add(new WorkerViewModel var value = _data.GetWorkshop(id);
{ if (value != null)
Id = 2, return View(value);
Name = "Медведков Андрей Алексеевич", }
Birthday = new DateTime(2004, 02, 29), return View(new WorkshopViewModel());
Specialization = "Слесарь", }
Salary = 25000, [HttpPost]
UserId = 2 public IActionResult CreateWorkshop(int id, string title, int[] workerIds)
}); {
return View(workers); WorkshopBindingModel model = new WorkshopBindingModel();
} model.Id = id;
model.Title = title;
model.DateCreate = DateTime.Now;
model.UserId = UserGuarantor.user!.Id;
var workers = _data.GetWorkers(UserGuarantor.user!.Id);
for (int i = 0; i < workerIds.Length; i++)
{
var worker = workers!.FirstOrDefault(x => x.Id == workerIds[i])!;
model.WorkshopWorker[workerIds[i]] = (worker);
}
if (model.WorkshopWorker.Count == 0)
return RedirectToAction("IndexWorkshop");
if (id != 0)
{
_data.UpdateWorkshop(model);
}
else
{
_data.CreateWorkshop(model);
}
return RedirectToAction("IndexWorkshop");
}
[HttpGet]
public IActionResult Privacy() public IActionResult Privacy()
{ {
GuarantorViewModel user = new() if (IsLoggedIn)
return View(UserGuarantor.user);
return RedirectToAction("IndexNonReg");
}
[HttpPost]
public IActionResult Privacy(int id, string login, string email, string password, string name)
{
if (!IsLoggedIn)
return RedirectToAction("IndexNonReg");
GuarantorBindingModel user = new() { Id = id, Login = login, Email = email, Password = password, Name = name };
if (_data.UpdateUser(user))
{ {
Email = "mailtatar@mail.ru", UserGuarantor.user = new GuarantorViewModel { Id = id, Login = login, Password = password, Name = name, Email = email };
Login = "tatar", }
Password = "password",
Name = "User",
};
return View(user); return View(user);
} }
[HttpGet]
public IActionResult MachineWorkshopTimeChoose()
{
if (!IsLoggedIn)
return RedirectToAction("IndexNonReg");
return View();
}
[HttpPost]
public IActionResult SendReport(DateTime startDate, DateTime endDate)
{
return Ok();
}
[HttpPost]
public IActionResult TimeReportWeb(DateTime startDate, DateTime endDate)
{
if (!IsLoggedIn)
return RedirectToAction("IndexNonReg");
HttpContext.Session.SetString("StartDate", startDate.ToString());
HttpContext.Session.SetString("EndDate", endDate.ToString());
return RedirectToAction("MachineWorkshopTimeReport");
}
[HttpGet]
public IActionResult MachineWorkshopTimeReport() public IActionResult MachineWorkshopTimeReport()
{ {
List<MachineWorkshopTimeReport> machineWorkshopTimeReports = new List<MachineWorkshopTimeReport> var startDateStr = HttpContext.Session.GetString("StartDate");
{ var endDateStr = HttpContext.Session.GetString("EndDate");
new MachineWorkshopTimeReport var startDate = DateTime.Parse(startDateStr);
{ var endDate = DateTime.Parse(endDateStr).AddDays(1);
WorkshopName = "Цех А",
Machines = new List<string> { "Фрезерный станок", "Токарный станок" } var values = _data.GetTimeReport(startDate, endDate, UserId);
}, ViewBag.StartDate = startDate;
new MachineWorkshopTimeReport ViewBag.EndDate = endDate;
{ return View(values);
WorkshopName = "Цех В",
Machines = new List<string> { "Станок А", "Станок В" }
}
};
return View(machineWorkshopTimeReports);
} }
public IActionResult WorkerProductReport() public IActionResult WorkerProductReport()
{ {
@ -198,26 +306,27 @@ namespace GuarantorAPP.Controllers
{ {
return View(); return View();
} }
public IActionResult WorkshopProductionAdd() [HttpGet]
public IActionResult WorkshopProductionAdd(int id)
{ {
List<ProductionViewModel> production = new List<ProductionViewModel> if (!IsLoggedIn)
{ return RedirectToAction("IndexNonReg");
new ProductionViewModel var workshop = _data.GetWorkshop(id);
{ ViewBag.Workshop = workshop;
Id = 1, var productions = _data.GetProductions();
Name = "Производство старое", return View(productions);
Cost = 1, }
UserId = 1, [HttpPost]
}, public IActionResult WorkshopProductionAdd(int workshopId, int productionId)
new ProductionViewModel {
{ if (!IsLoggedIn)
Id = 2, return RedirectToAction("IndexNonReg");
Name = "Производство новое", var workshop = _data.GetWorkshop(workshopId);
Cost = 2, if (workshop == null)
UserId = 2, return RedirectToAction("Index");
} WorkshopBindingModel workshopBinding = new() { Id = workshopId, Title = workshop.Title, Address = workshop.Address, Director = workshop.Director, UserId = workshop.UserId, ProductionId = workshop.ProductionId, WorkshopWorker = workshop.WorkerWorkshops };
}; _data.UpdateWorkshop(workshopBinding);
return View(production); return RedirectToAction("IndexWorkshop");
} }
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error() public IActionResult Error()

View File

@ -7,7 +7,13 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BusinessLogic\BusinessLogic.csproj" />
<ProjectReference Include="..\Contracts\Contracts.csproj" /> <ProjectReference Include="..\Contracts\Contracts.csproj" />
<ProjectReference Include="..\DatabaseImplement\DatabaseImplement.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -0,0 +1,132 @@
using Contracts.BindingModels;
using Contracts.BusinessLogicsContracts;
using Contracts.SearchModels;
using Contracts.ViewModels;
namespace GuarantorAPP
{
public class GuarantorData
{
private readonly ILogger _logger;
private readonly IGuarantorLogic _guarantorLogic;
private readonly IWorkerLogic _workerLogic;
private readonly IMachineLogic _machineLogic;
private readonly IWorkshopLogic _workshopLogic;
private readonly IProductionLogic _productionLogic;
public GuarantorData(ILogger logger, IGuarantorLogic guarantorLogic, IWorkerLogic workerLogic, IMachineLogic machineLogic, IWorkshopLogic workshopLogic, IProductionLogic productionLogic)
{
_logger = logger;
_guarantorLogic = guarantorLogic;
_workerLogic = workerLogic;
_machineLogic = machineLogic;
_workshopLogic = workshopLogic;
_productionLogic = productionLogic;
}
public GuarantorViewModel? Login(string login, string password)
{
return _guarantorLogic.ReadElement(new()
{
Login = login,
Password = password
});
}
public bool Register(GuarantorBindingModel model)
{
return _guarantorLogic.Create(model);
}
public bool UpdateUser(GuarantorBindingModel model)
{
return _guarantorLogic.Update(model);
}
public List<WorkerViewModel>? GetWorkers(int userId)
{
return _workerLogic.ReadList(new WorkerSearchModel() { UserId = userId });
}
public bool DeleteWorker(int workerId)
{
return _workerLogic.Delete(new() { Id = workerId });
}
public bool CreateWorker(WorkerBindingModel model)
{
return _workerLogic.Create(model);
}
public bool UpdateWorker(WorkerBindingModel model)
{
return _workerLogic.Update(model);
}
public WorkerViewModel? GetWorker(int id)
{
return _workerLogic.ReadElement(new() { Id = id });
}
public List<WorkshopViewModel>? GetWorkshops(int userId)
{
return _workshopLogic.ReadList(new WorkshopSearchModel() { UserId = userId });
}
public WorkshopViewModel? GetWorkshop(int id)
{
return _workshopLogic.ReadElement(new() { Id = id });
}
public bool UpdateWorkshop(WorkshopBindingModel model)
{
return _workshopLogic.Update(model);
}
public bool DeleteWorkshop(int workshopId)
{
return _workshopLogic.Delete(new() { Id = workshopId });
}
public bool CreateWorkshop(WorkshopBindingModel model)
{
return _workshopLogic.Create(model);
}
public List<MachineViewModel>? GetMachines(int userId)
{
return _machineLogic.ReadList(new() { UserId = userId });
}
public MachineViewModel? GetMachine(int id)
{
return _machineLogic.ReadElement(new() { Id = id });
}
public bool CreateMachine(MachineBindingModel model)
{
return _machineLogic.Create(model);
}
public bool UpdateMachine(MachineBindingModel model)
{
return _machineLogic.Update(model);
}
public bool DeleteMachine(int machineId)
{
return _machineLogic.Delete(new() { Id = machineId });
}
public List<ProductionViewModel>? GetProductions()
{
return _productionLogic.ReadList(null);
}
public List<MachineWorkshopTimeReport> GetTimeReport(DateTime? startDate, DateTime? endDate, int UserId)
{
var workshops = _workshopLogic.ReadList(new() { DateFrom = startDate, DateTo = endDate, UserId = UserId });
if (workshops == null)
return new();
List<MachineWorkshopTimeReport> machineWorkshopTimeReports = new List<MachineWorkshopTimeReport>();
foreach (var workshop in workshops)
{
var report = new MachineWorkshopTimeReport();
report.WorkshopName = workshop.Title;
var machines = _machineLogic.ReadList(new() { WorkshopId = workshop.Id, UserId = UserId });
if (machines != null)
report.Machines = machines.Select(p => p.Title).ToList();
machineWorkshopTimeReports.Add(report);
}
return machineWorkshopTimeReports;
}
}
}

View File

@ -1,7 +1,35 @@
using BusinessLogic.BusinessLogic;
using Contracts.BusinessLogicsContracts;
using Contracts.StoragesContracts;
using DatabaseImplement.Implements;
using GuarantorAPP;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllersWithViews(); builder.Services.AddControllersWithViews();
builder.Logging.SetMinimumLevel(LogLevel.Trace);
builder.Logging.AddLog4Net("log4net.config");
builder.Services.AddTransient<IGuarantorStorage, GuarantorStorage>();
builder.Services.AddTransient<IWorkerStorage, WorkerStorage>();
builder.Services.AddTransient<IWorkshopStorage, WorkshopStorage>();
builder.Services.AddTransient<IMachineStorage, MachineStorage>();
builder.Services.AddTransient<IProductionStorage, ProductionStorage>();
builder.Services.AddTransient<IGuarantorLogic, GuarantorLogic>();
builder.Services.AddTransient<IWorkerLogic, WorkerLogic>();
builder.Services.AddTransient<IWorkshopLogic, WorkshopLogic>();
builder.Services.AddTransient<IMachineLogic, MachineLogic>();
builder.Services.AddTransient<IProductionLogic, ProductionLogic>();
builder.Services.AddTransient<GuarantorData>();
builder.Services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromMinutes(30);
options.Cookie.HttpOnly = true;
options.Cookie.IsEssential = true;
});
var app = builder.Build(); var app = builder.Build();
if (!app.Environment.IsDevelopment()) if (!app.Environment.IsDevelopment())
@ -15,10 +43,11 @@ app.UseStaticFiles();
app.UseRouting(); app.UseRouting();
app.UseSession();
app.UseAuthorization(); app.UseAuthorization();
app.MapControllerRoute( app.MapControllerRoute(
name: "default", name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}"); pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run(); app.Run();

View File

@ -0,0 +1,9 @@
using Contracts.ViewModels;
namespace GuarantorAPP
{
public static class UserGuarantor
{
public static GuarantorViewModel? user { get; set; }
}
}

View File

@ -1,20 +1,163 @@
@{ @using Contracts.ViewModels;
@model MachineViewModel;
@{
ViewData["Title"] = "CreateMachine"; ViewData["Title"] = "CreateMachine";
ViewBag.Workers = Model.WorkerMachines;
} }
<div class="text-center"> <div class="text-center">
<h2 class="display-4">Создание станка</h2> <h2 class="display-4">Создание станка</h2>
</div> </div>
<form method="post"> <form id="machineForm" method="post">
<div class="row"> <div class="row">
<div class="col-4">Название:</div> <div class="col-4">Название станка:</div>
<div class="col-8"><input type="text" name="title" id="title" /></div> <div class="col-8">
</div> <input type="text" name="title" id="title" value="@Model.Title" />
<div class="row"> <span id="titleError" class="text-danger"></span>
<div class="col-4">Страна производства:</div> </div>
<div class="col-8"><input type="text" name="country" id="country" /></div> </div>
</div> <div class="row">
<div class="row"> <div class="col-4">Страна производитель:</div>
<div class="col-8"></div> <div class="col-8">
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div> <input type="text" name="country" id="country" value="@Model.Country" />
</div> <span id="countryError" class="text-danger"></span>
</form> </div>
</div>
<div class="container">
<div>Работники, управляющие станком</div>
<div class="table-responsive-lg">
<table id="workersTable" class="display">
<thead>
<tr>
<th>Имя</th>
<th>Должность</th>
<th>Зарплата</th>
<th>Удалить</th>
</tr>
</thead>
<tbody>
@foreach (var worker in ViewBag.Workers)
{
<tr data-worker-id="@worker.Value.Id">
<td>
<input type="hidden" name="workerIds" value="@worker.Key" />
@worker.Value.Name
</td>
<td>@worker.Value.Position</td>
<td class="worker-salary" data-salary="@worker.Value.Salary">@worker.Value.Salary</td>
<td><button type="button" class="deleteWorker" data-worker-id="@worker.Value.Id">Удалить</button></td>
</tr>
}
</tbody>
</table>
</div>
<select id="workerSelect" class="form-control">
<option value="">Выберите работника</option>
@foreach (var worker in ViewBag.AllWorkers)
{
<option value="@worker.Id" data-salary="@worker.Salary">@worker.Name</option>
}
</select>
<button type="button" id="addWorker" class="btn btn-secondary">Добавить работника</button>
</div>
<div class="row">
<div class="col-4">Общая зарплата:</div>
<div class="col-8"><input type="text" id="totalSalary" name="totalSalary" readonly /></div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div>
</div>
</form>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.datatables.net/1.11.3/js/jquery.dataTables.js"></script>
<script>
$(document).ready(function () {
function updateTotalSalary() {
var totalSalary = 0;
$('#workersTable tbody tr').each(function () {
var salary = $(this).find('.worker-salary').data('salary');
totalSalary += parseFloat(salary);
});
$('#totalSalary').val(totalSalary.toFixed(2));
}
$(document).on('click', '.deleteWorker', function () {
var row = $(this).closest('tr');
row.remove();
updateTotalSalary();
});
$('#addWorker').click(function () {
var selectedWorker = $('#workerSelect option:selected');
if (selectedWorker.val()) {
var workerId = selectedWorker.val();
var exists = false;
$('#workersTable tbody tr').each(function () {
if ($(this).data('worker-id') == workerId) {
exists = true;
return false;
}
});
if (exists) {
alert('Этот работник уже добавлен.');
return;
}
var workerName = selectedWorker.text();
var workerSalary = selectedWorker.data('salary');
var workerPosition = selectedWorker.data('position');
var newRow = `
<tr data-worker-id="${workerId}">
<td>
<input type="hidden" name="workerIds" value="${workerId}" />
${workerName}
</td>
<td>${workerPosition}</td>
<td class="worker-salary" data-salary="${workerSalary}">${workerSalary}</td>
<td><button type="button" class="deleteWorker" data-worker-id="${workerId}">Удалить</button></td>
</tr>
`;
$('#workersTable tbody').append(newRow);
$('#workerSelect').val('');
updateTotalSalary();
} else {
alert('Выберите работника для добавления');
}
});
$('#machineForm').submit(function (event) {
var title = $('#title').val();
var country = $('#country').val();
var isValid = true;
$('#titleError').text('');
$('#countryError').text('');
if (title.length < 2 || title.length > 50) {
$('#titleError').text('Название станка должно быть от 2 до 50 символов.');
isValid = false;
}
if (country.length < 2 || country.length > 50) {
$('#countryError').text('Страна производитель должна быть от 2 до 50 символов.');
isValid = false;
}
var totalWorkers = $('#workersTable tbody tr').length;
if (totalWorkers == 0) {
alert('Пожалуйста, добавьте хотя бы одного работника.');
isValid = false;
}
if (!isValid) {
event.preventDefault();
}
});
updateTotalSalary();
});
</script>

View File

@ -1,28 +1,85 @@
@{ @using Contracts.ViewModels;
@{
ViewData["Title"] = "CreateWorker"; ViewData["Title"] = "CreateWorker";
} }
@model WorkerViewModel;
<div class="text-center"> <div class="text-center">
<h2 class="display-4">Создание работника</h2> <h2 class="display-4">работник</h2>
</div> </div>
<form method="post"> <form id="workerForm" method="post">
<div class="row"> <input type="text" name="id" id="id" value="@Model.Id" hidden="hidden" />
<div class="col-4">Имя:</div> <div class="row">
<div class="col-8"><input type="text" name="name" id="name" /></div> <div class="col-4">Имя работника:</div>
</div> <div class="col-8">
<div class="row"> <input type="text" name="name" id="name" value="@Model.Name" />
<div class="col-4">Дата рождения:</div> <span id="nameError" class="text-danger"></span>
<div class="col-8"><input type="text" name="birthday" id="birthday" /></div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-4">Специальность:</div> <div class="col-4">Дата рождения:</div>
<div class="col-8"><input type="text" name="specialization" id="specialization" /></div> <div class="col-8">
</div> <input type="date" name="birthday" id="birthday" value="@Model.Birthday.ToString("yyyy-MM-dd")" />
<div class="row"> <span id="birthdayError" class="text-danger"></span>
<div class="col-4">Зарплата:</div> </div>
<div class="col-8"><input type="text" name="salary" id="salary" /></div> </div>
</div> <div class="row">
<div class="row"> <div class="col-4">Специальность:</div>
<div class="col-8"></div> <div class="col-8">
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div> <input type="text" name="specialization" id="specialization" value="@Model.Specialization" />
</div> <span id="specializationError" class="text-danger"></span>
</form> </div>
</div>
<div class="row">
<div class="col-4">Заработная плата:</div>
<div class="col-8">
<input type="text" name="salary" id="salary" value="@Model.Salary" />
<span id="salaryError" class="text-danger"></span>
</div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div>
</div>
</form>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function () {
$('#detailForm').submit(function (event) {
var name = $('#name').val();
var birthday = $('#birthday').val();
var specialization = $('#specialization').val();
var salary = $('#salary').val();
var isValid = true;
$('#nameError').text('');
$('#birthdayError').text('');
$('#specializationError').text('');
$('#salaryError').text('');
if (name.length < 2 || name.length > 50) {
$('#nameError').text('Имя работника должно быть от 2 до 50 символов.');
isValid = false;
}
if (!Date.parse(birthday)) {
$('#birthdayError').text('Введите корректную дату рождения.');
isValid = false;
}
if (specialization.length < 2 || specialization.length > 50) {
$('#specializationError').text('Специальность должна быть от 2 до 50 символов.');
isValid = false;
}
if (isNaN(salary) || salary <= 0) {
$('#salaryError').text('Заработная плата должна быть положительным числом.');
isValid = false;
}
if (!isValid) {
event.preventDefault();
}
});
});
</script>

View File

@ -1,24 +1,187 @@
@{ @using Contracts.ViewModels;
@model WorkshopViewModel;
@{
ViewData["Title"] = "CreateWorkshop"; ViewData["Title"] = "CreateWorkshop";
ViewBag.Workers = Model.WorkerWorkshops;
} }
<div class="text-center"> <div class="text-center">
<h2 class="display-4">Создание цеха</h2> <h2 class="display-4">Создание цеха</h2>
</div> </div>
<form method="post"> <form id="workshopForm" method="post">
<div class="row"> <div class="row">
<div class="col-4">Название:</div> <div class="col-4">Название цеха:</div>
<div class="col-8"><input type="text" name="title" id="title" /></div> <div class="col-8">
</div> <input type="text" name="title" id="title" value="@Model.Title" />
<div class="row"> <span id="titleError" class="text-danger"></span>
<div class="col-4">Адрес цеха:</div> </div>
<div class="col-8"><input type="text" name="address" id="address" /></div> </div>
</div> <div class="row">
<div class="row"> <div class="col-4">Адрес цеха:</div>
<div class="col-4">Директор цеха:</div> <div class="col-8">
<div class="col-8"><input type="text" name="director" id="director" /></div> <input type="text" name="address" id="address" value="@Model.Address" />
</div> <span id="addressError" class="text-danger"></span>
<div class="row"> </div>
<div class="col-8"></div> </div>
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div> <div class="row">
</div> <div class="col-4">ФИО директора цеха:</div>
</form> <div class="col-8">
<input type="text" name="director" id="director" value="@Model.Director" />
<span id="directorError" class="text-danger"></span>
</div>
</div>
<div class="row">
<div class="col-4">Название продукции:</div>
<div class="col-8">
<input type="text" name="productionName" id="productionName" value="@Model.ProductionName" />
<span id="productionNameError" class="text-danger"></span>
</div>
</div>
<div class="container">
<div>Работники цеха</div>
<div class="table-responsive-lg">
<table id="workersTable" class="display">
<thead>
<tr>
<th>Имя</th>
<th>Должность</th>
<th>Зарплата</th>
<th>Удалить</th>
</tr>
</thead>
<tbody>
@foreach (var worker in ViewBag.Workers)
{
<tr data-worker-id="@worker.Value.Id">
<td>
<input type="hidden" name="workerIds" value="@worker.Key" />
@worker.Value.Name
</td>
<td>@worker.Value.Position</td>
<td>@worker.Value.Salary</td>
<td>
<button type="button" class="deleteWorker" data-worker-id="@worker.Value.Id">Удалить</button>
</td>
</tr>
}
</tbody>
</table>
</div>
<select id="workerSelect" class="form-control">
<option value="">Выберите работника</option>
@foreach (var worker in ViewBag.AllWorkers)
{
<option value="@worker.Id">@worker.Name</option>
}
</select>
<button type="button" id="addWorker" class="btn btn-secondary">Добавить работника</button>
</div>
<div class="row">
<div class="col-4">Общая зарплата:</div>
<div class="col-8"><input type="text" id="totalSalary" name="totalSalary" readonly /></div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div>
</div>
</form>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.datatables.net/1.11.3/js/jquery.dataTables.js"></script>
<script>
$(document).ready(function () {
function updateTotalSalary() {
var totalSalary = 0;
$('#workersTable tbody tr').each(function () {
var salary = $(this).find('td:eq(2)').text();
totalSalary += parseFloat(salary);
});
$('#totalSalary').val(totalSalary.toFixed(2));
}
$(document).on('click', '.deleteWorker', function () {
var row = $(this).closest('tr');
row.remove();
updateTotalSalary();
});
$('#addWorker').click(function () {
var selectedWorker = $('#workerSelect option:selected');
if (selectedWorker.val()) {
var workerId = selectedWorker.val();
var workerName = selectedWorker.text();
var workerData = selectedWorker.data('worker');
var workerPosition = workerData.Position;
var workerSalary = workerData.Salary;
var exists = false;
$('#workersTable tbody tr').each(function () {
if ($(this).data('worker-id') == workerId) {
exists = true;
return false;
}
});
if (exists) {
alert('Этот работник уже добавлен.');
return;
}
var newRow = `
<tr data-worker-id="${workerId}">
<td>
<input type="hidden" name="workerIds" value="${workerId}" />
${workerName}
</td>
<td>${workerPosition}</td>
<td>${workerSalary}</td>
<td><button type="button" class="deleteWorker" data-worker-id="${workerId}">Удалить</button></td>
</tr>
`;
$('#workersTable tbody').append(newRow);
updateTotalSalary();
$('#workerSelect').val('');
} else {
alert('Выберите работника для добавления');
}
});
$('#workshopForm').submit(function (event) {
var title = $('#title').val();
var address = $('#address').val();
var director = $('#director').val();
var isValid = true;
$('#titleError').text('');
$('#addressError').text('');
$('#directorError').text('');
if (title.length < 2 || title.length > 50) {
$('#titleError').text('Название цеха должно быть от 2 до 50 символов.');
isValid = false;
}
if (address.length < 5 || address.length > 100) {
$('#addressError').text('Адрес цеха должен быть от 5 до 100 символов.');
isValid = false;
}
if (director.length < 5 || director.length > 100) {
$('#directorError').text('ФИО директора должно быть от 5 до 100 символов.');
isValid = false;
}
var totalWorkers = $('#workersTable tbody tr').length;
if (totalWorkers == 0) {
alert('Пожалуйста, добавьте хотя бы одного работника.');
isValid = false;
}
if (!isValid) {
event.preventDefault();
}
});
updateTotalSalary();
});
</script>

View File

@ -3,13 +3,12 @@
} }
<div class="text-center"> <div class="text-center">
<h1 class="display-4">Приложение "Завод "Иди работать". Исполнитель"</h1> <h1 class="display-4">Главное меню</h1>
<div class="list-group"> <div class="list-group">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="IndexDetail">Станки</a> <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="IndexDetail">Станки</a>
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="IndexProduct">Работники</a> <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="IndexProduct">Работники</a>
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="IndexProduction">Цеха</a> <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="IndexProduction">Цеха</a>
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Личные данные</a> <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Личные данные</a>
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Enter">Вход</a> <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Logout">Выйти</a>
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Register">Регистрация</a>
</div> </div>
</div> </div>

View File

@ -19,7 +19,7 @@
return; return;
} }
<p> <p>
<a asp-action="CreateMachine">Создать станок</a> <a asp-action="CreateMachine" asp-route-id="0">Создать станок</a>
</p> </p>
<table class="table"> <table class="table">
<thead> <thead>
@ -58,7 +58,10 @@
<a asp-action="CreateMachine" asp-route-id="@item.Id" class="btn btn-primary">Изменить</a> <a asp-action="CreateMachine" asp-route-id="@item.Id" class="btn btn-primary">Изменить</a>
</td> </td>
<td> <td>
<a asp-action="Delete" asp-route-id="@item.Id" class="btn btn-danger">Удалить</a> <form method="post">
<input type="text" title="id" name="id" value="@item.Id" hidden="hidden" />
<input type="submit" class="btn btn-danger" value="Удалить" />
</form>
</td> </td>
</tr> </tr>
} }

View File

@ -0,0 +1,10 @@
@{
ViewData["Title"] = "Home Page";
}
<div class="text-center">
<div class="list-group">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Enter">Вход</a>
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Register">Регистрация</a>
</div>
</div>

View File

@ -19,7 +19,7 @@
return; return;
} }
<p> <p>
<a asp-action="CreateWorker">Создать работника</a> <a asp-action="CreateWorker" asp-route-id="0">Создать работника</a>
</p> </p>
<table class="table"> <table class="table">
<thead> <thead>
@ -70,7 +70,10 @@
<a asp-action="CreateWorker" asp-route-id="@item.Id" class="btn btn-primary">Изменить</a> <a asp-action="CreateWorker" asp-route-id="@item.Id" class="btn btn-primary">Изменить</a>
</td> </td>
<td> <td>
<a asp-action="Delete" asp-route-id="@item.Id" class="btn btn-danger">Удалить</a> <form method="post">
<input type="text" title="id" name="id" value="@item.Id" hidden="hidden"/>
<input type="submit" class="btn btn-danger" value="Удалить"/>
</form>
</td> </td>
</tr> </tr>
} }

View File

@ -19,7 +19,7 @@
return; return;
} }
<p> <p>
<a asp-action="CreateWorkshop">Создать цех</a> <a asp-action="CreateWorkshop" asp-route-id="0">Создать цех</a>
</p> </p>
<table class="table"> <table class="table">
<thead> <thead>
@ -37,10 +37,16 @@
Директор цеха Директор цеха
</th> </th>
<th> <th>
Изменить работника Работник
</th> </th>
<th> <th>
Удалить работника Привязка производства к цеху
</th>
<th>
Изменить цех
</th>
<th>
Удалить цех
</th> </th>
</tr> </tr>
</thead> </thead>
@ -60,11 +66,17 @@
<td> <td>
@Html.DisplayFor(modelItem => item.Director) @Html.DisplayFor(modelItem => item.Director)
</td> </td>
<th>
@Html.DisplayFor(modelItem => item.ProductionName)
</th>
<td> <td>
<a asp-action="CreateWorkshop" asp-route-id="@item.Id" class="btn btn-primary">Изменить</a> <a asp-action="CreateWorkshop" asp-route-id="@item.Id" class="btn btn-primary">Изменить</a>
</td> </td>
<td> <td>
<a asp-action="Delete" asp-route-id="@item.Id" class="btn btn-danger">Удалить</a> <form method="post">
<input type="text" title="id" name="id" value="@item.Id" hidden="hidden" />
<input type="submit" class="btn btn-danger" value="Удалить" />
</form>
</td> </td>
</tr> </tr>
} }

View File

@ -0,0 +1,76 @@
@{
ViewData["Title"] = "Создание отчета";
}
<div class="text-center">
<h2 class="display-4">Создание отчета</h2>
</div>
<form id="TimeReportWeb" method="post">
<div class="row mb-3">
<div class="col-4 text-right">
<label for="startDate">Дата начала:</label>
</div>
<div class="col-6">
<input type="date" id="startDate" name="startDate" class="form-control" required />
<span id="startDateError" class="text-danger"></span>
</div>
</div>
<div class="row mb-3">
<div class="col-4 text-right">
<label for="endDate">Дата окончания:</label>
</div>
<div class="col-6">
<input type="date" id="endDate" name="endDate" class="form-control" required />
<span id="endDateError" class="text-danger"></span>
</div>
</div>
<div class="row mb-3">
<div class="col-6 text-right">
<button type="button" id="generateReport" class="btn btn-primary">Создать отчет</button>
</div>
</div>
</form>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function () {
function validateDates() {
var startDate = new Date($('#startDate').val());
var endDate = new Date($('#endDate').val());
var today = new Date();
var isValid = true;
$('#startDateError').text('');
$('#endDateError').text('');
// Проверка, что даты не превосходят сегодняшнюю дату
if (startDate > today) {
$('#startDateError').text('Дата начала не может быть больше сегодняшней даты.');
isValid = false;
}
if (endDate > today) {
$('#endDateError').text('Дата окончания не может быть больше сегодняшней даты.');
isValid = false;
}
// Проверка, что стартовая дата не превосходит конечную дату
if (startDate > endDate) {
$('#endDateError').text('Дата окончания не может быть раньше даты начала.');
isValid = false;
}
return isValid;
}
$('#generateReport').click(function () {
if (validateDates()) {
var formData = $('#TimeReportWeb').serialize();
$.post('/Home/TimeReportWeb', formData, function (response) {
window.location.href = '/Home/MachineWorkshopTimeReport';
}).fail(function () {
alert('Произошла ошибка при создании отчета.');
});
}
});
});
</script>

View File

@ -1,6 +1,88 @@
@{ @{
ViewData["Title"] = "Privacy Policy"; ViewData["Title"] = "Privacy Policy";
} }
<h1>@ViewData["Title"]</h1> <div class="text-center">
<h2 class="display-4">Личные данные</h2>
</div>
<form id="clientForm" method="post">
<input type="text" name="id" id="id" value="@Model.Id" hidden="hidden" />
<div class="row">
<div class="col-4">Логин:</div>
<div class="col-8">
<input type="text" name="login" id="login" value="@Model.Login" />
<span id="loginError" class="text-danger"></span>
</div>
</div>
<div class="row">
<div class="col-4">Почта:</div>
<div class="col-8">
<input type="email" name="email" id="email" value="@Model.Email" />
<span id="emailError" class="text-danger"></span>
</div>
</div>
<div class="row">
<div class="col-4">Пароль:</div>
<div class="col-8">
<input type="password" name="password" id="password" value="@Model.Password" />
<span id="passwordError" class="text-danger"></span>
</div>
</div>
<div class="row">
<div class="col-4">ФИО:</div>
<div class="col-8">
<input type="text" name="fio" id="fio" value="@Model.Name" />
<span id="fioError" class="text-danger"></span>
</div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div>
</div>
</form>
<p>Use this page to detail your site's privacy policy.</p> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function () {
$('#clientForm').submit(function (event) {
var login = $('#login').val();
var email = $('#email').val();
var password = $('#password').val();
var fio = $('#fio').val();
var isValid = true;
$('#loginError').text('');
$('#emailError').text('');
$('#passwordError').text('');
$('#fioError').text('');
// Валидация логина
if (login.length < 5 || login.length > 50) {
$('#loginError').text('Логин должен быть от 5 до 50 символов.');
isValid = false;
}
// Валидация почты
var emailPattern = /^[a-zA-Z0-9._-]+@@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
if (!emailPattern.test(email)) {
$('#emailError').text('Неверный формат почты.');
isValid = false;
}
// Валидация пароля
if (password.length < 8 || password.length > 20) {
$('#passwordError').text('Пароль должен быть от 8 до 20 символов.');
isValid = false;
}
// Валидация ФИО
if (fio.length < 2 || fio.length > 20) {
$('#fioError').text('ФИО должно быть от 2 до 20 символов.');
isValid = false;
}
if (!isValid) {
event.preventDefault();
}
});
});
</script>

View File

@ -3,31 +3,101 @@
} }
<div class="text-center"> <div class="text-center">
<h2 class="display-4">Регистрация</h2> <h2 class="display-4">Регистрация</h2>
</div> </div>
<form method="post"> <form id="registerForm" method="post">
<div class="row"> <div class="row">
<div class="col-4">Имя:</div> <div class="col-4">Имя:</div>
<div class="col-8"><input type="text" name="name" /></div> <div class="col-8">
</div> <input type="text" name="name" id="name" />
<div class="row"> <span id="nameError" class="text-danger"></span>
<div class="col-4">Логин:</div> </div>
<div class="col-8"><input type="text" name="login" /></div> </div>
</div> <div class="row">
<div class="row"> <div class="col-4">Логин:</div>
<div class="col-4">Почта:</div> <div class="col-8">
<div class="col-8"><input type="email" name="email" /></div> <input type="text" name="login" id="login" />
</div> <span id="loginError" class="text-danger"></span>
<div class="row"> </div>
<div class="col-4">Пароль:</div> </div>
<div class="col-8"><input type="password" name="password1" /></div> <div class="row">
</div> <div class="col-4">Почта:</div>
<div class="row"> <div class="col-8">
<div class="col-4">Повтор пароля:</div> <input type="email" name="email" id="email" />
<div class="col-8"><input type="password" name="password2" /></div> <span id="emailError" class="text-danger"></span>
</div> </div>
<div class="row"> </div>
<div class="col-8"></div> <div class="row">
<div class="col-4"><input type="submit" value="Регистрация" class="btn btn-primary" /></div> <div class="col-4">Пароль:</div>
</div> <div class="col-8">
</form> <input type="password" name="password1" id="password1" />
<span id="password1Error" class="text-danger"></span>
</div>
</div>
<div class="row">
<div class="col-4">Повтор пароля:</div>
<div class="col-8">
<input type="password" name="password2" id="password2" />
<span id="password2Error" class="text-danger"></span>
</div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Регистрация" class="btn btn-primary" /></div>
</div>
</form>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function () {
$('#registerForm').submit(function (event) {
var name = $('#name').val();
var login = $('#login').val();
var email = $('#email').val();
var password1 = $('#password1').val();
var password2 = $('#password2').val();
var isValid = true;
$('#nameError').text('');
$('#loginError').text('');
$('#emailError').text('');
$('#password1Error').text('');
$('#password2Error').text('');
// Валидация имени
if (name.length < 2 || name.length > 20) {
$('#nameError').text('Имя должно быть от 2 до 20 символов.');
isValid = false;
}
// Валидация логина
if (login.length < 5 || login.length > 50) {
$('#loginError').text('Логин должен быть от 5 до 50 символов.');
isValid = false;
}
// Валидация почты
var emailPattern = /^[a-zA-Z0-9._-]+@@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
if (!emailPattern.test(email)) {
$('#emailError').text('Неверный формат почты.');
isValid = false;
}
// Валидация пароля
if (password1.length < 8 || password1.length > 20) {
$('#password1Error').text('Пароль должен быть от 8 до 20 символов.');
isValid = false;
}
// Проверка совпадения паролей
if (password1 !== password2) {
$('#password2Error').text('Пароли не совпадают.');
isValid = false;
}
if (!isValid) {
event.preventDefault();
}
});
});
</script>

View File

@ -5,8 +5,7 @@
<div class="text-center"> <div class="text-center">
<h1 class="display-4">Меню создания отчетов</h1> <h1 class="display-4">Меню создания отчетов</h1>
<div class="list-group"> <div class="list-group">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="IndexMachine">Станки</a> <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="WorkerProductReport">Отчет работник-изделие</a>
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="IndexWorker">Работники</a> <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="MachineWorkshopTimeChoose">Отчет по станкам и цехам по датам</a>
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="IndexWorkshop">Цеха</a>
</div> </div>
</div> </div>

View File

@ -7,7 +7,7 @@
} }
<div class="text-center"> <div class="text-center">
<h1 class="display-4">Цех - @ViewBag.Workshop</h1> <h1 class="display-4">Цех - @ViewBag.Workshop.Name</h1>
</div> </div>
<div class="container"> <div class="container">
@ -19,8 +19,9 @@
<div class="card mb-4"> <div class="card mb-4">
<div class="card-body"> <div class="card-body">
<h5 class="card-title">@production.Name</h5> <h5 class="card-title">@production.Name</h5>
<form asp-controller="Cart" asp-action="AddToCart" method="post"> <form asp-action="WorkshopProductionAdd" method="post">
<input type="hidden" name="workshopId" value="@production.Id" /> <input type="hidden" name="workshopId" value="@ViewBag.Workshop.Id" />
<input type="hidden" name="productionId" value="@production.Id"/>
<button type="submit" class="btn btn-primary">Выбрать</button> <button type="submit" class="btn btn-primary">Выбрать</button>
</form> </form>
</div> </div>

View File

@ -1,4 +1,7 @@
<!DOCTYPE html> @{
ViewData["Name"] = UserGuarantor.user == null ? "Пользователь" : UserGuarantor.user.Name;
}
<!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
@ -13,7 +16,8 @@
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3"> <nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container-fluid"> <div class="container-fluid">
<img src="~/images/Work-transformed.png" width="150" height="150" alt="Логотип"> <img src="~/images/Work-transformed.png" width="150" height="150" alt="Логотип">
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">Поручитель</a> <a asp-controller="Home" asp-action="Index">Приложение "Завод "Иди работать". Поручитель"</a>
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Privacy">@ViewData["Name"]</a>
</div> </div>
</nav> </nav>
</header> </header>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8" ?>
<log4net>
<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
<file value="c:/temp/GoWorkCourse.log" />
<appendToFile value="true" />
<maximumFileSize value="100KB" />
<maxSizeRollBackups value="2" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %5level %logger.%method [%line] - MESSAGE: %message%newline %exception" />
</layout>
</appender>
<root>
<level value="TRACE" />
<appender-ref ref="RollingFile" />
</root>
</log4net>