MoveAllViews

This commit is contained in:
Sergey Kozyrev 2024-05-28 21:41:19 +04:00
parent bdd5f28535
commit da20060b05
25 changed files with 595 additions and 432 deletions

View File

@ -23,7 +23,10 @@ namespace DatabaseImplement.Implements
{
if (!model.Id.HasValue && string.IsNullOrEmpty(model.Login)) { return null; }
using var context = new FactoryGoWorkDatabase();
return context.Implementers.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; ;
if (!string.IsNullOrEmpty(model.Login) && string.IsNullOrEmpty(model.Password))
return context.Implementers.FirstOrDefault(x => x.Login == model.Login)?.GetViewModel;
else
return context.Implementers.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<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model)

View File

@ -0,0 +1,77 @@
using Contracts.BindingModels;
using Contracts.ViewModels;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace ImplementerApp.Controllers
{
public class DetailController : Controller
{
private readonly ILogger<DetailController> _logger;
private readonly ImplementerData _data;
public DetailController(ILogger<DetailController> logger, ImplementerData data)
{
_logger = logger;
_data = data;
}
private bool IsLoggedIn { get { return UserImplementer.user != null; } }
private int UserId { get { return UserImplementer.user!.Id; } }
[HttpGet]
public IActionResult IndexDetail()
{
if (UserImplementer.user != null)
{
var list = _data.GetDetails(UserImplementer.user.Id);
if (list != null)
return View(list);
return View(new List<DetailViewModel>());
}
return RedirectToAction("IndexNonReg");
}
[HttpPost]
public void IndexDetail(int id)
{
if (UserImplementer.user != null)
{
_data.DeleteDetail(id);
}
Response.Redirect("IndexDetail");
}
[HttpGet]
public IActionResult CreateDetail(int id)
{
if (id != 0)
{
var value = _data.GetDetail(id);
if (value != null)
return View(value);
}
return View(new DetailViewModel());
}
[HttpPost]
public IActionResult CreateDetail(DetailBindingModel model)
{
if (model.Id == 0)
{
model.DateCreate = DateTime.Now;
model.UserId = UserImplementer.user!.Id;
if (_data.CreateDetail(model))
return RedirectToAction("IndexDetail");
}
else
{
if (_data.UpdateDetail(model))
return RedirectToAction("IndexDetail");
}
return View();
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View();
}
}
}

View File

@ -12,405 +12,89 @@ namespace ImplementerApp.Controllers
{
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
private readonly ImplementerData _data;
public HomeController(ILogger<HomeController> logger, ImplementerData data)
{
_logger = logger;
_data = data;
}
private bool IsLoggedIn { get { return UserImplementer.user != null; } }
private int UserId { get { return UserImplementer.user!.Id; } }
public IActionResult IndexNonReg()
{
if (!IsLoggedIn)
return View();
return RedirectToAction("Index");
}
public IActionResult Index()
{
if (!IsLoggedIn)
return RedirectToAction("IndexNonReg");
return View();
}
[HttpGet]
public IActionResult Enter()
{
if (!IsLoggedIn)
return View();
return RedirectToAction("Index");
}
[HttpPost]
public void Enter(string login, string password)
{
var user = _data.Login(login, password);
if (user != null)
{
UserImplementer.user = user;
Response.Redirect("Index");
}
}
[HttpGet]
public IActionResult Register()
{
return View();
}
public IActionResult Logout()
{
UserImplementer.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 IndexDetail()
{
if (UserImplementer.user != null)
{
var list = _data.GetDetails(UserImplementer.user.Id);
if (list != null)
return View(list);
return View(new List<DetailViewModel>());
}
return RedirectToAction("IndexNonReg");
}
[HttpPost]
public void IndexDetail(int id)
{
if (UserImplementer.user != null)
{
_data.DeleteDetail(id);
}
Response.Redirect("IndexDetail");
}
[HttpGet]
public IActionResult CreateDetail(int id)
{
if (id != 0)
{
var value = _data.GetDetail(id);
if (value != null)
return View(value);
}
return View(new DetailViewModel());
}
[HttpPost]
public IActionResult CreateDetail(DetailBindingModel model)
{
if (model.Id == 0)
{
model.DateCreate = DateTime.Now;
model.UserId = UserImplementer.user!.Id;
if (_data.CreateDetail(model))
return RedirectToAction("IndexDetail");
}
else
{
if (_data.UpdateDetail(model))
return RedirectToAction("IndexDetail");
}
return View();
}
[HttpGet]
public IActionResult IndexProduct()
{
if (IsLoggedIn) {
var products = _data.GetProducts(UserImplementer.user!.Id);
return View(products);
}
return RedirectToAction("IndexNonReg");
}
[HttpPost]
public IActionResult IndexProduct(int id)
{
_data.DeleteProduct(id);
return RedirectToAction("IndexProduct");
}
[HttpGet]
public IActionResult CreateProduct(int id)
{
var details = _data.GetDetails(UserImplementer.user!.Id);
ViewBag.AllDetails = details;
if (id != 0)
{
var value = _data.GetProduct(id);
if (value != null)
return View(value);
}
return View(new ProductViewModel());
}
[HttpPost]
public IActionResult CreateProduct(int id, string title, int[] detailIds, int[] counts)
{
ProductBindingModel model = new ProductBindingModel();
model.Id = id;
model.Name = title;
model.UserId = UserImplementer.user!.Id;
var details = _data.GetDetails(UserImplementer.user!.Id);
double sum = 0;
for (int i = 0; i < detailIds.Length; i++)
{
var detail = details!.FirstOrDefault(x => x.Id == detailIds[i])!;
if (counts[i] <= 0)
continue;
model.ProductDetails[detailIds[i]] = (detail, counts[i]);
sum += detail.Cost * counts[i];
}
if (model.ProductDetails.Count == 0)
return RedirectToAction("IndexProduct");
model.Cost = sum;
if (id != 0)
{
_data.UpdateProduct(model);
}
else
{
_data.CreateProduct(model);
}
return RedirectToAction("IndexProduct");
}
[HttpGet]
public IActionResult IndexProduction()
{
if (UserImplementer.user != null)
{
var productions = _data.GetProductions(UserImplementer.user.Id);
return View(productions);
}
return RedirectToAction("IndexNonReg");
}
[HttpPost]
public IActionResult IndexProduction(int id)
{
_data.DeleteProduction(id);
return RedirectToAction("IndexProduction");
}
[HttpGet]
public IActionResult CreateProduction(int id)
{
var details = _data.GetDetails(UserImplementer.user!.Id);
ViewBag.AllDetails = details;
if (id != 0)
{
var value = _data.GetProduction(id);
if (value != null)
return View(value);
}
return View(new ProductionViewModel());
}
[HttpPost]
public IActionResult CreateProduction(int id, string title, int[] detailIds)
{
ProductionBindingModel model = new ProductionBindingModel();
model.Id = id;
model.Name = title;
model.UserId = UserImplementer.user!.Id;
var details = _data.GetDetails(UserImplementer.user!.Id);
double sum = 0;
for (int i = 0; i < detailIds.Length; i++)
{
var detail = details!.FirstOrDefault(x => x.Id == detailIds[i])!;
model.ProductionDetails[detailIds[i]] = detail;
sum += detail.Cost;
}
model.Cost = sum;
bool changed = false;
if (model.ProductionDetails.Count > 0)
{
if (id != 0)
{
changed = _data.UpdateProduction(model);
}
else
{
changed = _data.CreateProduction(model);
}
}
if (changed)
return RedirectToAction("IndexProduction");
else
{
ViewBag.AllDetails = details;
return View(model);
}
}
[HttpGet]
public IActionResult Privacy()
{
if (IsLoggedIn)
return View(UserImplementer.user);
return RedirectToAction("IndexNonReg");
}
[HttpPost]
public IActionResult Privacy(int id, string login, string email, string password, string name)
{
if (!IsLoggedIn)
return RedirectToAction("IndexNonReg");
ImplementerBindingModel user = new() { Id = id, Login = login, Email = email, Password = password, Name = name };
if (_data.UpdateUser(user))
{
UserImplementer.user = new ImplementerViewModel { Id = id, Login = login, Password = password, Name = name, Email = email };
}
return View(user);
}
[HttpGet]
public IActionResult DetailTimeChoose()
{
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("DetailTimeReport");
}
[HttpGet]
public IActionResult DetailTimeReport()
{
var startDateStr = HttpContext.Session.GetString("StartDate");
var endDateStr = HttpContext.Session.GetString("EndDate");
var startDate = DateTime.Parse(startDateStr);
var endDate = DateTime.Parse(endDateStr).AddDays(1);
var values = _data.GetTimeReport(startDate, endDate, UserId);
ViewBag.StartDate = startDate;
ViewBag.EndDate = endDate;
return View(values);
}
[HttpPost]
public void DetailTimeMail()
{
var startDateStr = HttpContext.Session.GetString("StartDate");
var endDateStr = HttpContext.Session.GetString("EndDate");
var startDate = DateTime.Parse(startDateStr);
var endDate = DateTime.Parse(endDateStr).AddDays(1);
using (MemoryStream memoryStream = new MemoryStream()) {
_data.SendMailReport(startDate, endDate, UserId, memoryStream);
}
Response.Redirect("DetailTimeReport");
private readonly ILogger<HomeController> _logger;
private readonly ImplementerData _data;
public HomeController(ILogger<HomeController> logger, ImplementerData data)
{
_logger = logger;
_data = data;
}
[HttpGet]
public IActionResult DetailWorkshopChoose()
{
if (!IsLoggedIn)
return RedirectToAction("IndexNonReg");
var details = _data.GetDetails(UserId);
return View(details);
}
[HttpPost]
public IActionResult DetailWorkshopChoose(List<int> selectedItems, string reportType)
{
string value = string.Join("/", selectedItems);
HttpContext.Session.SetString("Details", value);
if (reportType.Equals("default"))
return RedirectToAction("DetailWorkshopReport");
else if (reportType.Equals("excel"))
return RedirectToAction("ExcelGenerate");
else
return RedirectToAction("WordGenerate");
}
public async Task<IActionResult> ExcelGenerate()
{
var value = HttpContext.Session.GetString("Details");
if (value != null)
{
List<int> rawReports = value!.Split('/').Select(x => int.Parse(x)).ToList();
using (MemoryStream memoryStream = new MemoryStream())
{
_data.SaveReportExcel(rawReports, memoryStream);
memoryStream.Seek(0, SeekOrigin.Begin);
var outputStream = new MemoryStream();
await memoryStream.CopyToAsync(outputStream);
outputStream.Seek(0, SeekOrigin.Begin);
return File(outputStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "ReportExcel.xlsx");
}
}
return RedirectToAction("DetailWorkshopChoose");
}
public async Task<IActionResult> WordGenerate()
{
var value = HttpContext.Session.GetString("Details");
if (value != null)
private bool IsLoggedIn { get { return UserImplementer.user != null; } }
private int UserId { get { return UserImplementer.user!.Id; } }
public IActionResult IndexNonReg()
{
if (!IsLoggedIn)
return View();
return RedirectToAction("Index");
}
public IActionResult Index()
{
if (!IsLoggedIn)
return RedirectToAction("IndexNonReg");
return View();
}
[HttpGet]
public IActionResult Enter()
{
if (!IsLoggedIn)
return View();
return RedirectToAction("Index");
}
[HttpPost]
public void Enter(string login, string password)
{
var user = _data.Login(login, password);
if (user != null)
{
List<int> rawReports = value!.Split('/').Select(x => int.Parse(x)).ToList();
using (MemoryStream memoryStream = new MemoryStream())
{
_data.SaveReportWord(rawReports, memoryStream);
memoryStream.Seek(0, SeekOrigin.Begin);
var outputStream = new MemoryStream();
await memoryStream.CopyToAsync(outputStream);
outputStream.Seek(0, SeekOrigin.Begin);
return File(outputStream, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "ReportWord.docx");
}
UserImplementer.user = user;
Response.Redirect("Index");
}
return RedirectToAction("DetailWorkshopChoose");
Response.Redirect("Enter");
}
[HttpGet]
public IActionResult Register()
{
return View();
}
public IActionResult Logout()
{
UserImplementer.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 Privacy()
{
if (IsLoggedIn)
return View(UserImplementer.user);
return RedirectToAction("IndexNonReg");
}
[HttpPost]
public IActionResult Privacy(int id, string login, string email, string password, string name)
{
if (!IsLoggedIn)
return RedirectToAction("IndexNonReg");
ImplementerBindingModel user = new() { Id = id, Login = login, Email = email, Password = password, Name = name };
if (_data.UpdateUser(user))
{
UserImplementer.user = new ImplementerViewModel { Id = id, Login = login, Password = password, Name = name, Email = email };
}
return View(user);
}
[HttpGet]
public IActionResult DetailWorkshopReport()
{
var value = HttpContext.Session.GetString("Details");
if (value != null)
{
List<int> rawReports = value!.Split('/').Select(x => int.Parse(x)).ToList();
var reports = _data.GetWorkshopReports(rawReports);
return View(reports);
}
return View(new List<DetailWorkshopReportViewModel>());
}
public IActionResult ReportsMenu()
{
return View();
}
[HttpGet]
public IActionResult ProductMachineAdd(int id)
{
if (!IsLoggedIn)
return RedirectToAction("IndexNonReg");
var product = _data.GetProduct(id);
ViewBag.Product = product;
var machines = _data.GetMachines();
return View(machines);
}
[HttpPost]
public IActionResult ProductMachineAdd(int productId, int machineId)
{
if (!IsLoggedIn)
return RedirectToAction("IndexNonReg");
var product = _data.GetProduct(productId);
if (product == null)
return RedirectToAction("Index");
ProductBindingModel productBinding = new() { Id = productId, Cost = product.Cost, Name = product.Name, UserId = product.UserId, ProductDetails = product.DetailProducts, MachineId = machineId };
_data.UpdateProduct(productBinding);
return RedirectToAction("IndexProduct");
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View();
}
}
}

View File

@ -0,0 +1,118 @@
using Contracts.BindingModels;
using Contracts.ViewModels;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace ImplementerApp.Controllers
{
public class ProductController : Controller
{
private readonly ILogger<ProductController> _logger;
private readonly ImplementerData _data;
public ProductController(ILogger<ProductController> logger, ImplementerData data)
{
_logger = logger;
_data = data;
}
private bool IsLoggedIn { get { return UserImplementer.user != null; } }
private int UserId { get { return UserImplementer.user!.Id; } }
[HttpGet]
public IActionResult IndexProduct()
{
if (IsLoggedIn)
{
var products = _data.GetProducts(UserImplementer.user!.Id);
return View(products);
}
return RedirectToAction("IndexNonReg");
}
[HttpPost]
public IActionResult IndexProduct(int id)
{
_data.DeleteProduct(id);
return RedirectToAction("IndexProduct");
}
[HttpGet]
public IActionResult CreateProduct(int id)
{
var details = _data.GetDetails(UserImplementer.user!.Id);
ViewBag.AllDetails = details;
if (id != 0)
{
var value = _data.GetProduct(id);
if (value != null)
return View(value);
}
return View(new ProductViewModel());
}
[HttpPost]
public IActionResult CreateProduct(int id, string title, int[] detailIds, int[] counts)
{
ProductBindingModel model = new ProductBindingModel();
model.Id = id;
model.Name = title;
model.UserId = UserImplementer.user!.Id;
var details = _data.GetDetails(UserImplementer.user!.Id);
double sum = 0;
for (int i = 0; i < detailIds.Length; i++)
{
var detail = details!.FirstOrDefault(x => x.Id == detailIds[i])!;
if (counts[i] <= 0)
continue;
model.ProductDetails[detailIds[i]] = (detail, counts[i]);
sum += detail.Cost * counts[i];
}
if (model.ProductDetails.Count == 0)
return RedirectToAction("IndexProduct");
model.Cost = sum;
try
{
if (id != 0)
{
_data.UpdateProduct(model);
}
else
{
_data.CreateProduct(model);
}
}
catch (InvalidOperationException ex)
{
ViewBag.ErrorMessage = "Такое название изделия уже существует";
return View();
}
return RedirectToAction("IndexProduct");
}
[HttpGet]
public IActionResult ProductMachineAdd(int id)
{
if (!IsLoggedIn)
return RedirectToAction("IndexNonReg");
var product = _data.GetProduct(id);
ViewBag.Product = product;
var machines = _data.GetMachines();
return View(machines);
}
[HttpPost]
public IActionResult ProductMachineAdd(int productId, int machineId)
{
if (!IsLoggedIn)
return RedirectToAction("IndexNonReg");
var product = _data.GetProduct(productId);
if (product == null)
return RedirectToAction("Index");
ProductBindingModel productBinding = new() { Id = productId, Cost = product.Cost, Name = product.Name, UserId = product.UserId, ProductDetails = product.DetailProducts, MachineId = machineId };
_data.UpdateProduct(productBinding);
return RedirectToAction("IndexProduct");
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View();
}
}
}

View File

@ -0,0 +1,93 @@
using Contracts.BindingModels;
using Contracts.ViewModels;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace ImplementerApp.Controllers
{
public class ProductionController : Controller
{
private readonly ILogger<ProductionController> _logger;
private readonly ImplementerData _data;
public ProductionController(ILogger<ProductionController> logger, ImplementerData data)
{
_logger = logger;
_data = data;
}
private bool IsLoggedIn { get { return UserImplementer.user != null; } }
private int UserId { get { return UserImplementer.user!.Id; } }
[HttpGet]
public IActionResult IndexProduction()
{
if (UserImplementer.user != null)
{
var productions = _data.GetProductions(UserImplementer.user.Id);
return View(productions);
}
return RedirectToAction("IndexNonReg");
}
[HttpPost]
public IActionResult IndexProduction(int id)
{
_data.DeleteProduction(id);
return RedirectToAction("IndexProduction");
}
[HttpGet]
public IActionResult CreateProduction(int id)
{
var details = _data.GetDetails(UserImplementer.user!.Id);
ViewBag.AllDetails = details;
if (id != 0)
{
var value = _data.GetProduction(id);
if (value != null)
return View(value);
}
return View(new ProductionViewModel());
}
[HttpPost]
public IActionResult CreateProduction(int id, string title, int[] detailIds)
{
ProductionBindingModel model = new ProductionBindingModel();
model.Id = id;
model.Name = title;
model.UserId = UserImplementer.user!.Id;
var details = _data.GetDetails(UserImplementer.user!.Id);
double sum = 0;
for (int i = 0; i < detailIds.Length; i++)
{
var detail = details!.FirstOrDefault(x => x.Id == detailIds[i])!;
model.ProductionDetails[detailIds[i]] = detail;
sum += detail.Cost;
}
model.Cost = sum;
bool changed = false;
if (model.ProductionDetails.Count > 0)
{
if (id != 0)
{
changed = _data.UpdateProduction(model);
}
else
{
changed = _data.CreateProduction(model);
}
}
if (changed)
return RedirectToAction("IndexProduction");
else
{
ViewBag.AllDetails = details;
return View(model);
}
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View();
}
}
}

View File

@ -0,0 +1,153 @@
using Contracts.ViewModels;
using DocumentFormat.OpenXml.Spreadsheet;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace ImplementerApp.Controllers
{
public class ReportController : Controller
{
private readonly ILogger<ReportController> _logger;
private readonly ImplementerData _data;
public ReportController(ILogger<ReportController> logger, ImplementerData data)
{
_logger = logger;
_data = data;
}
private bool IsLoggedIn { get { return UserImplementer.user != null; } }
private int UserId { get { return UserImplementer.user!.Id; } }
[HttpGet]
public IActionResult DetailTimeChoose()
{
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("DetailTimeReport");
}
[HttpGet]
public IActionResult DetailTimeReport()
{
var startDateStr = HttpContext.Session.GetString("StartDate");
var endDateStr = HttpContext.Session.GetString("EndDate");
var startDate = DateTime.Parse(startDateStr);
var endDate = DateTime.Parse(endDateStr).AddDays(1);
var values = _data.GetTimeReport(startDate, endDate, UserId);
ViewBag.StartDate = startDate;
ViewBag.EndDate = endDate;
return View(values);
}
[HttpPost]
public void DetailTimeMail()
{
var startDateStr = HttpContext.Session.GetString("StartDate");
var endDateStr = HttpContext.Session.GetString("EndDate");
var startDate = DateTime.Parse(startDateStr);
var endDate = DateTime.Parse(endDateStr).AddDays(1);
using (MemoryStream memoryStream = new MemoryStream())
{
_data.SendMailReport(startDate, endDate, UserId, memoryStream);
}
Response.Redirect("DetailTimeReport");
}
[HttpGet]
public IActionResult DetailWorkshopChoose()
{
if (!IsLoggedIn)
return RedirectToAction("IndexNonReg");
var details = _data.GetDetails(UserId);
return View(details);
}
[HttpPost]
public IActionResult DetailWorkshopChoose(List<int> selectedItems, string reportType)
{
string value = string.Join("/", selectedItems);
HttpContext.Session.SetString("Details", value);
if (reportType.Equals("default"))
return RedirectToAction("DetailWorkshopReport");
else if (reportType.Equals("excel"))
return RedirectToAction("ExcelGenerate");
else
return RedirectToAction("WordGenerate");
}
public async Task<IActionResult> ExcelGenerate()
{
var value = HttpContext.Session.GetString("Details");
if (value != null)
{
List<int> rawReports = value!.Split('/').Select(x => int.Parse(x)).ToList();
using (MemoryStream memoryStream = new MemoryStream())
{
_data.SaveReportExcel(rawReports, memoryStream);
memoryStream.Seek(0, SeekOrigin.Begin);
var outputStream = new MemoryStream();
await memoryStream.CopyToAsync(outputStream);
outputStream.Seek(0, SeekOrigin.Begin);
return File(outputStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "ReportExcel.xlsx");
}
}
return RedirectToAction("DetailWorkshopChoose");
}
public async Task<IActionResult> WordGenerate()
{
var value = HttpContext.Session.GetString("Details");
if (value != null)
{
List<int> rawReports = value!.Split('/').Select(x => int.Parse(x)).ToList();
using (MemoryStream memoryStream = new MemoryStream())
{
_data.SaveReportWord(rawReports, memoryStream);
memoryStream.Seek(0, SeekOrigin.Begin);
var outputStream = new MemoryStream();
await memoryStream.CopyToAsync(outputStream);
outputStream.Seek(0, SeekOrigin.Begin);
return File(outputStream, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "ReportWord.docx");
}
}
return RedirectToAction("DetailWorkshopChoose");
}
[HttpGet]
public IActionResult DetailWorkshopReport()
{
var value = HttpContext.Session.GetString("Details");
if (value != null)
{
List<int> rawReports = value!.Split('/').Select(x => int.Parse(x)).ToList();
var reports = _data.GetWorkshopReports(rawReports);
return View(reports);
}
return View(new List<DetailWorkshopReportViewModel>());
}
public IActionResult ReportsMenu()
{
return View();
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View();
}
}
}

View File

@ -64,6 +64,10 @@ namespace ImplementerApp
{
return _implementerLogic.Update(model);
}
public bool CheckLogin(string login)
{
return _implementerLogic.ReadElement(new() { Login = login }) == null;
}
public List<DetailViewModel>? GetDetails(int userId)
{

View File

@ -6,7 +6,7 @@
<div class="text-center">
<h2 class="display-4">Деталь</h2>
</div>
<form id="detailForm" method="post">
<form id="detailForm" asp-controller="Detail" method="post">
<input type="text" name="id" id="id" value="@Model.Id" hidden="hidden" />
<div class="row">
<div class="col-4">Название:</div>

View File

@ -18,7 +18,7 @@
return;
}
<p>
<a asp-action="CreateDetail" asp-route-id="0">Создать деталь</a>
<a asp-action="CreateDetail" asp-controller="Detail" asp-route-id="0">Создать деталь</a>
</p>
<table class="table">
<thead>
@ -54,10 +54,10 @@
@Html.DisplayFor(modelItem => item.Cost)
</td>
<td>
<a asp-action="CreateDetail" asp-route-id="@item.Id" class="btn btn-primary">Изменить</a>
<a asp-action="CreateDetail" asp-controller="Detail" asp-route-id="@item.Id" class="btn btn-primary">Изменить</a>
</td>
<td>
<form method="post">
<form asp-controller="Detail" method="post">
<input type="text" title="id" name="id" value="@item.Id" hidden="hidden"/>
<input type="submit" class="btn btn-danger" value="Удалить"/>
</form>

View File

@ -5,7 +5,7 @@
<div class="text-center">
<h2 class="display-4">Вход в приложение</h2>
</div>
<form method="post">
<form asp-controller="Home" method="post">
<div class="row">
<div class="col-4">Логин:</div>
<div class="col-8"><input type="text" name="login" /></div>

View File

@ -5,12 +5,11 @@
<div class="text-center">
<h1 class="display-4">Главное меню</h1>
<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="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="Detail" asp-action="IndexDetail">Детали</a>
<a class="nav-link text-dark" asp-area="" asp-controller="Product" asp-action="IndexProduct">Изделия</a>
<a class="nav-link text-dark" asp-area="" asp-controller="Production" 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="ReportsMenu">Меню отчетов</a>
<a class="nav-link text-dark" asp-area="" asp-controller="Report" asp-action="ReportsMenu">Меню отчетов</a>
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Logout">Выйти</a>
</div>
</div>

View File

@ -4,7 +4,7 @@
<div class="text-center">
<h2 class="display-4">Личные данные</h2>
</div>
<form id="clientForm" method="post">
<form id="clientForm" asp-controller="Home" method="post">
<input type="text" name="id" id="id" value="@Model.Id" hidden="hidden"/>
<div class="row">
<div class="col-4">Логин:</div>
@ -28,9 +28,9 @@
</div>
</div>
<div class="row">
<div class="col-4">ФИО:</div>
<div class="col-4">Имя:</div>
<div class="col-8">
<input type="text" name="fio" id="fio" value="@Model.Name" />
<input type="text" name="name" id="name" value="@Model.Name" />
<span id="fioError" class="text-danger"></span>
</div>
</div>
@ -47,7 +47,7 @@
var login = $('#login').val();
var email = $('#email').val();
var password = $('#password').val();
var fio = $('#fio').val();
var fio = $('#name').val();
var isValid = true;
$('#loginError').text('');

View File

@ -5,7 +5,7 @@
<div class="text-center">
<h2 class="display-4">Регистрация</h2>
</div>
<form id="registerForm" method="post">
<form id="registerForm" asp-controller="Home" method="post">
<div class="row">
<div class="col-4">Имя:</div>
<div class="col-8">
@ -50,6 +50,26 @@
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function () {
$('#login').blur(function () {
var login = $('#login').val();
if (login.length >= 5 && login.length <= 50) {
$.ajax({
url: '@Url.Action("CheckLoginUnique", "YourController")',
type: 'POST',
data: { login: login },
success: function (response) {
if (!response.isUnique) {
$('#loginError').text('Логин уже используется.');
} else {
$('#loginError').text('');
}
},
error: function () {
$('#loginError').text('Ошибка при проверке уникальности логина.');
}
});
}
});
$('#registerForm').submit(function(event) {
var name = $('#name').val();
var login = $('#login').val();
@ -77,7 +97,7 @@
}
// Валидация почты
var emailPattern = /^[a-zA-Z0-9._-]+@@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
if (!emailPattern.test(email)) {
$('#emailError').text('Неверный формат почты.');
isValid = false;
@ -100,4 +120,4 @@
}
});
});
</script>
</script>

View File

@ -9,7 +9,7 @@
<div class="text-center">
<h2 class="display-4">Создание изделия</h2>
</div>
<form id="productForm" method="post">
<form id="productForm" asp-controller="Product" method="post">
<div class="row">
<div class="col-4">Название:</div>
<div class="col-8">

View File

@ -18,7 +18,7 @@
return;
}
<p>
<a asp-action="CreateProduct" asp-route-id="0">Создать изделие</a>
<a asp-action="CreateProduct" asp-controller="Product" asp-route-id="0">Создать изделие</a>
</p>
<table class="table">
<thead>
@ -63,13 +63,13 @@
@Html.DisplayFor(modelItem => item.MachineName)
</td>
<td>
<a asp-action="ProductMachineAdd" asp-route-id="@item.Id" class="btn btn-primary">Привязать станок</a>
<a asp-action="ProductMachineAdd" asp-controller="Product" asp-route-id="@item.Id" class="btn btn-primary">Привязать станок</a>
</td>
<td>
<a asp-action="CreateProduct" asp-route-id="@item.Id" class="btn btn-primary">Изменить</a>
<a asp-action="CreateProduct" asp-controller="Product" asp-route-id="@item.Id" class="btn btn-primary">Изменить</a>
</td>
<td>
<form method="post">
<form method="post" asp-controller="Product">
<input type="text" title="id" name="id" value="@item.Id" hidden="hidden" />
<input type="submit" class="btn btn-danger" value="Удалить" />
</form>

View File

@ -19,7 +19,7 @@
<div class="card mb-4">
<div class="card-body">
<h5 class="card-title">@machine.Title</h5>
<form asp-action="ProductMachineAdd" method="post">
<form asp-action="ProductMachineAdd" asp-controller="Product" method="post">
<input type="hidden" name="productId" value="@ViewBag.Product.Id"/>
<input type="hidden" name="machineId" value="@machine.Id" />
<button type="submit" class="btn btn-primary">Выбрать</button>

View File

@ -9,7 +9,7 @@
<div class="text-center">
<h2 class="display-4">Создание производства</h2>
</div>
<form id="productionForm" method="post">
<form id="productionForm" asp-controller="Production" method="post">
<div class="row">
<div class="col-4">Название:</div>
<div class="col-8">

View File

@ -18,7 +18,7 @@
return;
}
<p>
<a asp-action="CreateProduction" asp-route-id="0">Создать производство</a>
<a asp-action="CreateProduction" asp-controller="Production" asp-route-id="0">Создать производство</a>
</p>
<table class="table">
<thead>
@ -54,10 +54,10 @@
@Html.DisplayFor(modelItem => item.Cost)
</td>
<td>
<a asp-action="CreateProduction" asp-route-id="@item.Id" class="btn btn-primary">Изменить</a>
<a asp-action="CreateProduction" asp-controller="Production" asp-route-id="@item.Id" class="btn btn-primary">Изменить</a>
</td>
<td>
<form method="post">
<form asp-controller="Production" method="post">
<input type="text" title="id" name="id" value="@item.Id" hidden="hidden" />
<input type="submit" class="btn btn-danger" value="Удалить" />
</form>

View File

@ -5,7 +5,7 @@
<div class="text-center">
<h2 class="display-4">Создание отчета</h2>
</div>
<form id="TimeReportWeb" method="post">
<form id="TimeReportWeb" asp-controller="Report" method="post">
<div class="row mb-3">
<div class="col-4 text-right">
<label for="startDate">Дата начала:</label>
@ -74,8 +74,8 @@
if (validateDates()) {
var formData = $('#TimeReportWeb').serialize();
$.post('/Home/TimeReportWeb', formData, function (response) {
window.location.href = '/Home/DetailTimeReport';
$.post('/Report/TimeReportWeb', formData, function (response) {
window.location.href = '/Report/DetailTimeReport';
}).fail(function () {
alert('Произошла ошибка при создании отчета.');
});

View File

@ -10,7 +10,7 @@
<h1 class="display-4">Список деталей в диапазоне времени</h1>
</div>
<form asp-action="DetailTimeMail" method="post">
<form asp-action="DetailTimeMail" asp-controller="Report" method="post">
<button type="submit" class="btn btn-primary">Отправить отчет на почту</button>
</form>

View File

@ -7,7 +7,7 @@
<h2>Выберите детали для отчета</h2>
<form asp-controller="Home" asp-action="DetailWorkshopChoose" method="post" onsubmit="return validateForm()">
<form asp-controller="Report" asp-action="DetailWorkshopChoose" method="post" onsubmit="return validateForm()">
<table class="table">
<thead>
<tr>

View File

@ -5,7 +5,7 @@
<div class="text-center">
<h1 class="display-4">Меню создания отчетов</h1>
<div class="list-group">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="DetailWorkshopChoose">Отчет деталь-цех</a>
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="DetailTimeChoose">Отчет по деталям по датам</a>
<a class="nav-link text-dark" asp-area="" asp-controller="Report" asp-action="DetailWorkshopChoose">Отчет деталь-цех</a>
<a class="nav-link text-dark" asp-area="" asp-controller="Report" asp-action="DetailTimeChoose">Отчет по деталям по датам</a>
</div>
</div>

View File

@ -17,7 +17,9 @@
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container-fluid">
<img src="~/images/Work-transformed.png" width="150" height="150" alt="Логотип">
<a asp-controller="Home" asp-action="Index">Приложение "Завод "Иди работать". Исполнитель"</a>
<a asp-controller="Home" asp-action="Index" class="custom-link">
<h1>Приложение "Завод "Иди работать". Исполнитель"</h1>
</a>
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Privacy">@ViewData["Name"]</a>
</div>
</nav>

View File

@ -15,4 +15,14 @@ html {
body {
margin-bottom: 60px;
}
.custom-link {
color: inherit;
text-decoration: none;
}
.custom-link:hover {
text-decoration: none;
color: inherit;
}