diff --git a/.DS_Store b/.DS_Store index 4c1b65d..6c1bb6c 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/AutoRepairShop/AutoRepairShopBusinessLogic/AutoRepairShopBusinessLogic.csproj b/AutoRepairShop/AutoRepairShopBusinessLogic/AutoRepairShopBusinessLogic.csproj index 26ae577..ea9b788 100644 --- a/AutoRepairShop/AutoRepairShopBusinessLogic/AutoRepairShopBusinessLogic.csproj +++ b/AutoRepairShop/AutoRepairShopBusinessLogic/AutoRepairShopBusinessLogic.csproj @@ -7,7 +7,9 @@ + + diff --git a/AutoRepairShop/AutoRepairShopBusinessLogic/BusinessLogic/ClientLogic.cs b/AutoRepairShop/AutoRepairShopBusinessLogic/BusinessLogic/ClientLogic.cs index 12f8ec8..8ffe2fb 100644 --- a/AutoRepairShop/AutoRepairShopBusinessLogic/BusinessLogic/ClientLogic.cs +++ b/AutoRepairShop/AutoRepairShopBusinessLogic/BusinessLogic/ClientLogic.cs @@ -45,7 +45,6 @@ namespace AutoRepairShopBusinessLogic.BusinessLogic } return true; } - public ClientViewModel? ReadElement(ClientSearchModel model) { if (model == null) diff --git a/AutoRepairShop/AutoRepairShopBusinessLogic/BusinessLogic/WorkLogic.cs b/AutoRepairShop/AutoRepairShopBusinessLogic/BusinessLogic/WorkLogic.cs index 68773d8..4736c51 100644 --- a/AutoRepairShop/AutoRepairShopBusinessLogic/BusinessLogic/WorkLogic.cs +++ b/AutoRepairShop/AutoRepairShopBusinessLogic/BusinessLogic/WorkLogic.cs @@ -93,8 +93,36 @@ namespace AutoRepairShopBusinessLogic.BusinessLogic return false; } return true; + } + public bool UpdateStatus(WorkBindingModel model) + { + CheckModel(model); + if (_workStorage.UpdateStatus(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool DeleteClientFromWork(WorkBindingModel model) + { + CheckModel(model); + if (_workStorage.DeleteClientFromWork(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + }public bool DeleteTaskFromWork(WorkBindingModel model) + { + CheckModel(model); + if (_workStorage.DeleteTaskFromWork(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; } - private void CheckModel(WorkBindingModel model, bool withParams = true) { if (model == null) diff --git a/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs b/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs new file mode 100644 index 0000000..e74dbbb --- /dev/null +++ b/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs @@ -0,0 +1,230 @@ +using AutoRepairShopBusinessLogic.OfficePackage.HelperEnums; +using AutoRepairShopBusinessLogic.OfficePackage.HelperModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoRepairShopBusinessLogic.OfficePackage +{ + public abstract class AbstractSaveToExcel + { + /* + public abstract class AbstractSaveToExcelEmployee + { + public byte[]? CreateReport(ExcelInfo info) + { + CreateExcel(info); + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = 1, + Text = info.Title, + StyleInfo = ExcelStyleInfoType.Title + }); + + MergeCells(new ExcelMergeParameters + { + CellFromName = "A1", + CellToName = "C1" + }); + + uint rowIndex = 2; + foreach (var client in info.WorkClient) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = client.Name, + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + foreach (var paymeant in client.Values) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = rowIndex, + Text = "Номер оплаты:", + StyleInfo = ExcelStyleInfoType.TextWithBroder, + + }); + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "c", + RowIndex = rowIndex, + StyleInfo = ExcelStyleInfoType.TextWithBroder, + + }); + + MergeCells(new ExcelMergeParameters + { + CellFromName = $"B{rowIndex}", + CellToName = $"C{rowIndex}" + }); + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "D", + RowIndex = rowIndex, + Text = paymeant.ClientID.ToString(), + StyleInfo = ExcelStyleInfoType.TextWithBroder + }); + + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "E", + RowIndex = rowIndex, + Text = "В количестве:", + StyleInfo = ExcelStyleInfoType.TextWithBroder, + + }); + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "F", + RowIndex = rowIndex, + StyleInfo = ExcelStyleInfoType.TextWithBroder, + + }); + + MergeCells(new ExcelMergeParameters + { + CellFromName = $"E{rowIndex}", + CellToName = $"F{rowIndex}" + }); + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "G", + RowIndex = rowIndex, + Text = paymeant.ProducCount.ToString(), + StyleInfo = ExcelStyleInfoType.TextWithBroder + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "H", + RowIndex = rowIndex, + Text = "Статус оплаты:", + StyleInfo = ExcelStyleInfoType.TextWithBroder + }); + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "I", + RowIndex = rowIndex, + StyleInfo = ExcelStyleInfoType.TextWithBroder, + + }); + + MergeCells(new ExcelMergeParameters + { + CellFromName = $"H{rowIndex}", + CellToName = $"I{rowIndex}" + }); + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "J", + RowIndex = rowIndex, + Text = paymeant.PaymeantStatus.ToString(), + StyleInfo = ExcelStyleInfoType.TextWithBroder + }); + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "k", + RowIndex = rowIndex, + StyleInfo = ExcelStyleInfoType.TextWithBroder + }); + + MergeCells(new ExcelMergeParameters + { + CellFromName = $"J{rowIndex}", + CellToName = $"K{rowIndex}" + }); + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "L", + RowIndex = rowIndex, + Text = "Сумма:", + StyleInfo = ExcelStyleInfoType.TextWithBroder + }); + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "M", + RowIndex = rowIndex, + Text = paymeant.ProductSum.ToString(), + StyleInfo = ExcelStyleInfoType.TextWithBroder + }); + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "N", + RowIndex = rowIndex, + Text = "ID Клиента:", + StyleInfo = ExcelStyleInfoType.TextWithBroder + }); + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "O", + RowIndex = rowIndex, + StyleInfo = ExcelStyleInfoType.TextWithBroder + }); + + + MergeCells(new ExcelMergeParameters + { + CellFromName = $"N{rowIndex}", + CellToName = $"O{rowIndex}" + }); + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "P", + RowIndex = rowIndex, + Text = paymeant.ClientID.ToString(), + StyleInfo = ExcelStyleInfoType.TextWithBroder + }); + rowIndex++; + } + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = "Итого:", + StyleInfo = ExcelStyleInfoType.Title + }); + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = client.Total.ToString(), + StyleInfo = ExcelStyleInfoType.Title + }); + rowIndex++; + } + + var document = SaveExcel(info); + return document; + } + + protected abstract void CreateExcel(ExcelInfo info); + + protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams); + + protected abstract void MergeCells(ExcelMergeParameters excelParams); + + protected abstract byte[]? SaveExcel(ExcelInfo info); + }*/ + } +} \ No newline at end of file diff --git a/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/AbstractSaveToPdf.cs b/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/AbstractSaveToPdf.cs new file mode 100644 index 0000000..63847d9 --- /dev/null +++ b/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/AbstractSaveToPdf.cs @@ -0,0 +1,90 @@ +using AutoRepairShopBusinessLogic.OfficePackage.HelperEnums; +using AutoRepairShopBusinessLogic.OfficePackage.HelperModels; +using PdfSharp.Pdf; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoRepairShopBusinessLogic.OfficePackage +{ + public abstract class AbstractSaveToPdf + { + /* public PdfDocument CreateDoc(PdfInfo info) + { + CreatePdf(info); + + CreateParagraph(new PdfParagraph + { + Text = info.Title, + Style = "NormalTitle", + alignmentType = PdfParagraphAlignmentType.Center, + }); + CreateParagraph(new PdfParagraph + { + Text = $"{info.DateFrom.ToShortDateString()}", + Style = "Normal", + alignmentType = PdfParagraphAlignmentType.Right + }); + + foreach (var product in info.WorkClients) + { + CreateParagraph(new PdfParagraph + { + Text = product.ProductName, + Style = "Normal", + alignmentType = PdfParagraphAlignmentType.Left, + }); + CreateTable(new List { "2cm", "4cm", "4cm", "4cm", "2cm" }); + + CreateRow(new PdfRowParameters + { + Text = new List { "Оплата №", "Статус", "Количество товара", "Сумма", "ID Клиента" }, + Style = "NormalTittle", + alignmentType = PdfParagraphAlignmentType.Center, + }); + + foreach (var paymeant in product.Values) + { + CreateRow(new PdfRowParameters + { + Text = new List { + paymeant.PaymeantID.ToString(), + paymeant.PaymeantStatus.ToString(), + paymeant.ProducCount.ToString(), + paymeant.ProductSum.ToString(), + paymeant.ClientID.ToString(), + }, + Style = "Normal", + alignmentType = PdfParagraphAlignmentType.Left, + }); + } + CreateParagraph(new PdfParagraph + { + Text = $"Итого: {product.Total}\t", + Style = "Normal", + alignmentType = PdfParagraphAlignmentType.Right + }); + } + + var document = SavePdf(info); + return document; + } + + // Создание файла + protected abstract void CreatePdf(PdfInfo info); + + // Создание параграфа с текстом + protected abstract void CreateParagraph(PdfParagraph paragraph); + + // Создание таблицы + protected abstract void CreateTable(List columns); + + // Создание и заполнение строки + protected abstract void CreateRow(PdfRowParameters rowParameters); + + // Сохранение файла + protected abstract PdfDocument SavePdf(PdfInfo info); */ + } +} diff --git a/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/AbstractSaveToWord.cs new file mode 100644 index 0000000..2ca3142 --- /dev/null +++ b/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -0,0 +1,78 @@ +using AutoRepairShopBusinessLogic.OfficePackage.HelperEnums; +using AutoRepairShopBusinessLogic.OfficePackage.HelperModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoRepairShopBusinessLogic.OfficePackage +{ + /* public abstract class AbstractSaveToWord + { + public byte[]? CreateDoc(WordInfo info) + { + CreateWord(info); + + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24", }) }, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Center + } + }); + + foreach (var data in info.WorkClients) + { + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> { (data.ProductName, new WordTextProperties { Bold = true, Size = "24", }) }, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Center + } + }); + foreach (var paymeant in data.Values) + { + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> { ($"Оплата №:{paymeant.PaymeantID}/В количестве:{paymeant.ProducCount}/" + + $"Cтатус:{paymeant.PaymeantStatus}/Сумма:{paymeant.ProductSum}/ID Клиента:{paymeant.ClientID}", + new WordTextProperties { Bold = false, Size = "24", }) }, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Both + } + }); + } + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> { ($"Итого:{data.Total}", + new WordTextProperties { Bold = true, Size = "24", }) }, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Both + } + }); + } + + + var document = SaveWord(info); + return document; + } + + // Создание doc-файла + protected abstract void CreateWord(WordInfo info); + + // Создание абзаца с текстом + protected abstract void CreateParagraph(WordParagraph paragraph); + + // Сохранение файла + protected abstract byte[]? SaveWord(WordInfo info); + }*/ +} diff --git a/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs b/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs new file mode 100644 index 0000000..d2f6b3f --- /dev/null +++ b/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoRepairShopBusinessLogic.OfficePackage.HelperEnums +{ + public enum ExcelStyleInfoType + { + Title, + Text, + TextWithBroder + } +} diff --git a/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs b/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs new file mode 100644 index 0000000..5bc18bf --- /dev/null +++ b/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoRepairShopBusinessLogic.OfficePackage.HelperEnums +{ + public enum PdfParagraphAlignmentType + { + Center, + Left, + Right, + } +} diff --git a/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/HelperEnums/WordJustificationType.cs b/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/HelperEnums/WordJustificationType.cs new file mode 100644 index 0000000..82a2328 --- /dev/null +++ b/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/HelperEnums/WordJustificationType.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoRepairShopBusinessLogic.OfficePackage.HelperEnums +{ + public enum WordJustificationType + { + Center, + Both + } +} diff --git a/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/HelperModels/ClientPoints.cs b/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/HelperModels/ClientPoints.cs new file mode 100644 index 0000000..07102dd --- /dev/null +++ b/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/HelperModels/ClientPoints.cs @@ -0,0 +1,25 @@ +using AutoRepairShopDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoRepairShopBusinessLogic.OfficePackage.HelperModels +{ + public class ClientPoints + { + public int ClientId { get; set; } + public int WorkId { get; set; } + public string ClientName { get; set; } + public int Points { get; set; } + + public ClientPoints(int clientId, int workId, string clientName, int points) + { + ClientId = clientId; + WorkId = workId; + ClientName = clientName; + Points = points; + } + } +} diff --git a/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs b/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs new file mode 100644 index 0000000..779c5f3 --- /dev/null +++ b/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs @@ -0,0 +1,18 @@ +using AutoRepairShopBusinessLogic.OfficePackage.HelperEnums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoRepairShopBusinessLogic.OfficePackage.HelperModels +{ + public class ExcelCellParameters + { + public string ColumnName { get; set; } = string.Empty; + public uint RowIndex { get; set; } + public string Text { get; set; } = string.Empty; + public string CellReference => $"{ColumnName}{RowIndex}"; + public ExcelStyleInfoType StyleInfo { get; set; } + } +} diff --git a/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs b/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs new file mode 100644 index 0000000..b21da41 --- /dev/null +++ b/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs @@ -0,0 +1,15 @@ +using AutoRepairShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoRepairShopBusinessLogic.OfficePackage.HelperModels +{ + public class ExcelInfo + { + public string Title { get; set; } = string.Empty; + public List WorksClient { get; set; } = new(); + } +} diff --git a/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs b/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs new file mode 100644 index 0000000..d350746 --- /dev/null +++ b/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoRepairShopBusinessLogic.OfficePackage.HelperModels +{ + public class ExcelMergeParameters + { + public string CellFromName { get; set; } = string.Empty; + + public string CellToName { get; set; } = string.Empty; + + public string Merge => $"{CellFromName}:{CellToName}"; + } +} diff --git a/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs b/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs new file mode 100644 index 0000000..a8e8c8f --- /dev/null +++ b/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs @@ -0,0 +1,18 @@ +using AutoRepairShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoRepairShopBusinessLogic.OfficePackage.HelperModels +{ + public class PdfInfo + { + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + public DateTime DateFrom { get; set; } + public List WorkClients { get; set; } = new(); + public List WorkTasks { get; set; } = new(); + } +} \ No newline at end of file diff --git a/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs b/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs new file mode 100644 index 0000000..5129a82 --- /dev/null +++ b/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs @@ -0,0 +1,16 @@ +using AutoRepairShopBusinessLogic.OfficePackage.HelperEnums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoRepairShopBusinessLogic.OfficePackage.HelperModels +{ + public class PdfParagraph + { + public string Text { get; set; } = string.Empty; + public string Style { get; set; } = string.Empty; + public PdfParagraphAlignmentType alignmentType { get; set; } + } +} diff --git a/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs b/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs new file mode 100644 index 0000000..751379f --- /dev/null +++ b/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs @@ -0,0 +1,16 @@ +using AutoRepairShopBusinessLogic.OfficePackage.HelperEnums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoRepairShopBusinessLogic.OfficePackage.HelperModels +{ + public class PdfRowParameters + { + public List Text { get; set; } = new(); + public string Style { get; set; } = string.Empty; + public PdfParagraphAlignmentType alignmentType { get; set; } + } +} diff --git a/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/HelperModels/WordInfo.cs b/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/HelperModels/WordInfo.cs new file mode 100644 index 0000000..9519b51 --- /dev/null +++ b/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/HelperModels/WordInfo.cs @@ -0,0 +1,16 @@ +using AutoRepairShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoRepairShopBusinessLogic.OfficePackage.HelperModels +{ + public class WordInfo + { + public string Title { get; set; } = string.Empty; + public List WorkClients { get; set; } = new(); + public List WorkTasks { get; set; } = new(); + } +} diff --git a/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs b/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs new file mode 100644 index 0000000..a615442 --- /dev/null +++ b/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoRepairShopBusinessLogic.OfficePackage.HelperModels +{ + public class WordParagraph + { + public List<(string, WordTextProperties)> Texts { get; set; } = new(); + public WordTextProperties? TextProperties { get; set; } + } +} diff --git a/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs b/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs new file mode 100644 index 0000000..73d7db7 --- /dev/null +++ b/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs @@ -0,0 +1,16 @@ +using AutoRepairShopBusinessLogic.OfficePackage.HelperEnums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoRepairShopBusinessLogic.OfficePackage.HelperModels +{ + public class WordTextProperties + { + public string Size { get; set; } = string.Empty; + public bool Bold { get; set; } + public WordJustificationType JustificationType { get; set; } + } +} diff --git a/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/Implements/SaveToExcel.cs b/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/Implements/SaveToExcel.cs new file mode 100644 index 0000000..3bef30d --- /dev/null +++ b/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/Implements/SaveToExcel.cs @@ -0,0 +1,298 @@ +using AutoRepairShopBusinessLogic.OfficePackage.HelperEnums; +using AutoRepairShopBusinessLogic.OfficePackage.HelperModels; +using Microsoft.Extensions.Primitives; +using MigraDoc.DocumentObjectModel.Tables; +using MigraDoc.DocumentObjectModel; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using static AutoRepairShopBusinessLogic.OfficePackage.AbstractSaveToExcel; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Spreadsheet; +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Office2013.Excel; +using DocumentFormat.OpenXml.Office2010.Excel; + +namespace AutoRepairShopBusinessLogic.OfficePackage.Implements +{ + internal class SaveToExcel : AbstractSaveToExcel + { + /* private SpreadsheetDocument? _spreadsheetDocument; + + private SharedStringTablePart? _shareStringPart; + + private Worksheet? _worksheet; + + private MemoryStream _mem = new MemoryStream(); + + // Настройка стилей для файла + private static void CreateStyles(WorkbookPart workbookpart) + { + var sp = workbookpart.AddNewPart(); + sp.Stylesheet = new Stylesheet(); + + var fonts = new Fonts() { Count = 2U, KnownFonts = true }; + + var fontUsual = new Font(); + fontUsual.Append(new FontSize() { Val = 12D }); + fontUsual.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Theme = 1U }); + fontUsual.Append(new FontName() { Val = "Times New Roman" }); + fontUsual.Append(new FontFamilyNumbering() { Val = 2 }); + fontUsual.Append(new FontScheme() { Val = FontSchemeValues.Minor }); + + var fontTitle = new Font(); + fontTitle.Append(new Bold()); + fontTitle.Append(new FontSize() { Val = 14D }); + fontTitle.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Theme = 1U }); + fontTitle.Append(new FontName() { Val = "Times New Roman" }); + fontTitle.Append(new FontFamilyNumbering() { Val = 2 }); + fontTitle.Append(new FontScheme() { Val = FontSchemeValues.Minor }); + + fonts.Append(fontUsual); + fonts.Append(fontTitle); + + var fills = new Fills() { Count = 2U }; + + var fill1 = new Fill(); + fill1.Append(new PatternFill() { PatternType = PatternValues.None }); + + var fill2 = new Fill(); + fill2.Append(new PatternFill() { PatternType = PatternValues.Gray125 }); + + fills.Append(fill1); + fills.Append(fill2); + + var borders = new Borders() { Count = 2U }; + + var borderNoBorder = new Border(); + borderNoBorder.Append(new LeftBorder()); + borderNoBorder.Append(new RightBorder()); + borderNoBorder.Append(new TopBorder()); + borderNoBorder.Append(new BottomBorder()); + borderNoBorder.Append(new DiagonalBorder()); + + var borderThin = new Border(); + + var leftBorder = new LeftBorder() { Style = BorderStyleValues.Thin }; + leftBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U }); + + var rightBorder = new RightBorder() { Style = BorderStyleValues.Thin }; + rightBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U }); + + var topBorder = new TopBorder() { Style = BorderStyleValues.Thin }; + topBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U }); + + var bottomBorder = new BottomBorder() { Style = BorderStyleValues.Thin }; + bottomBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U }); + + borderThin.Append(leftBorder); + borderThin.Append(rightBorder); + borderThin.Append(topBorder); + borderThin.Append(bottomBorder); + borderThin.Append(new DiagonalBorder()); + + borders.Append(borderNoBorder); + borders.Append(borderThin); + + var cellStyleFormats = new CellStyleFormats() { Count = 1U }; + var cellFormatStyle = new CellFormat() { NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 0U }; + + cellStyleFormats.Append(cellFormatStyle); + + var cellFormats = new CellFormats() { Count = 3U }; + var cellFormatFont = new CellFormat() { NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 0U, FormatId = 0U, ApplyFont = true }; + var cellFormatFontAndBorder = new CellFormat() { NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 1U, FormatId = 0U, ApplyFont = true, ApplyBorder = true }; + var cellFormatTitle = new CellFormat() { NumberFormatId = 0U, FontId = 1U, FillId = 0U, BorderId = 0U, FormatId = 0U, Alignment = new Alignment() { Vertical = VerticalAlignmentValues.Center, WrapText = true, Horizontal = HorizontalAlignmentValues.Center }, ApplyFont = true }; + + cellFormats.Append(cellFormatFont); + cellFormats.Append(cellFormatFontAndBorder); + cellFormats.Append(cellFormatTitle); + + var cellStyles = new CellStyles() { Count = 1U }; + + cellStyles.Append(new CellStyle() { Name = "Normal", FormatId = 0U, BuiltinId = 0U }); + + var differentialFormats = new DocumentFormat.OpenXml.Office2013.Excel.DifferentialFormats() { Count = 0U }; + + var tableStyles = new TableStyles() { Count = 0U, DefaultTableStyle = "TableStyleMedium2", DefaultPivotStyle = "PivotStyleLight16" }; + + var stylesheetExtensionList = new StylesheetExtensionList(); + + var stylesheetExtension1 = new StylesheetExtension() { Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}" }; + stylesheetExtension1.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"); + stylesheetExtension1.Append(new SlicerStyles() { DefaultSlicerStyle = "SlicerStyleLight1" }); + + var stylesheetExtension2 = new StylesheetExtension() { Uri = "{9260A510-F301-46a8-8635-F512D64BE5F5}" }; + stylesheetExtension2.AddNamespaceDeclaration("x15", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main"); + stylesheetExtension2.Append(new TimelineStyles() { DefaultTimelineStyle = "TimeSlicerStyleLight1" }); + + stylesheetExtensionList.Append(stylesheetExtension1); + stylesheetExtensionList.Append(stylesheetExtension2); + + sp.Stylesheet.Append(fonts); + sp.Stylesheet.Append(fills); + sp.Stylesheet.Append(borders); + sp.Stylesheet.Append(cellStyleFormats); + sp.Stylesheet.Append(cellFormats); + sp.Stylesheet.Append(cellStyles); + sp.Stylesheet.Append(differentialFormats); + sp.Stylesheet.Append(tableStyles); + sp.Stylesheet.Append(stylesheetExtensionList); + } + + // Получение номера стиля из типа + private static uint GetStyleValue(ExcelStyleInfoType styleInfo) + { + return styleInfo switch + { + ExcelStyleInfoType.Title => 2U, + ExcelStyleInfoType.TextWithBroder => 1U, + ExcelStyleInfoType.Text => 0U, + _ => 0U, + }; + } + + protected override void CreateExcel(ExcelInfoEmployee info) + { + _spreadsheetDocument = SpreadsheetDocument.Create(_mem, SpreadsheetDocumentType.Workbook); + // Создаем книгу (в ней хранятся листы) + var workbookpart = _spreadsheetDocument.AddWorkbookPart(); + workbookpart.Workbook = new Workbook(); + + CreateStyles(workbookpart); + + // Получаем/создаем хранилище текстов для книги + _shareStringPart = _spreadsheetDocument.WorkbookPart!.GetPartsOfType().Any() + ? _spreadsheetDocument.WorkbookPart.GetPartsOfType().First() + : _spreadsheetDocument.WorkbookPart.AddNewPart(); + + // Создаем SharedStringTable, если его нет + if (_shareStringPart.SharedStringTable == null) + { + _shareStringPart.SharedStringTable = new SharedStringTable(); + } + + // Создаем лист в книгу + var worksheetPart = workbookpart.AddNewPart(); + worksheetPart.Worksheet = new Worksheet(new SheetData()); + + // Добавляем лист в книгу + var sheets = _spreadsheetDocument.WorkbookPart.Workbook.AppendChild(new Sheets()); + var sheet = new Sheet() + { + Id = _spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart), + SheetId = 1, + Name = "Лист" + }; + sheets.Append(sheet); + + _worksheet = worksheetPart.Worksheet; + } + + protected override void InsertCellInWorksheet(ExcelCellParameters excelParams) + { + if (_worksheet == null || _shareStringPart == null) + { + return; + } + var sheetData = _worksheet.GetFirstChild(); + if (sheetData == null) + { + return; + } + + // Ищем строку, либо добавляем ее + Row row; + if (sheetData.Elements().Where(r => r.RowIndex! == excelParams.RowIndex).Any()) + { + row = sheetData.Elements().Where(r => r.RowIndex! == excelParams.RowIndex).First(); + } + else + { + row = new Row() { RowIndex = excelParams.RowIndex }; + sheetData.Append(row); + } + + // Ищем нужную ячейку + Cell cell; + if (row.Elements().Where(c => c.CellReference!.Value == excelParams.CellReference).Any()) + { + cell = row.Elements().Where(c => c.CellReference!.Value == excelParams.CellReference).First(); + } + else + { + // Все ячейки должны быть последовательно друг за другом расположены + // нужно определить, после какой вставлять + Cell? refCell = null; + foreach (Cell rowCell in row.Elements()) + { + if (string.Compare(rowCell.CellReference!.Value, excelParams.CellReference, true) > 0) + { + refCell = rowCell; + break; + } + } + + var newCell = new Cell() { CellReference = excelParams.CellReference }; + row.InsertBefore(newCell, refCell); + + cell = newCell; + } + + // вставляем новый текст + _shareStringPart.SharedStringTable.AppendChild(new SharedStringItem(new Text(excelParams.Text))); + _shareStringPart.SharedStringTable.Save(); + + cell.CellValue = new CellValue((_shareStringPart.SharedStringTable.Elements().Count() - 1).ToString()); + cell.DataType = new EnumValue(CellValues.SharedString); + cell.StyleIndex = GetStyleValue(excelParams.StyleInfo); + } + + protected override void MergeCells(ExcelMergeParameters excelParams) + { + if (_worksheet == null) + { + return; + } + MergeCells mergeCells; + + if (_worksheet.Elements().Any()) + { + mergeCells = _worksheet.Elements().First(); + } + else + { + mergeCells = new MergeCells(); + + if (_worksheet.Elements().Any()) + { + _worksheet.InsertAfter(mergeCells, _worksheet.Elements().First()); + } + else + { + _worksheet.InsertAfter(mergeCells, _worksheet.Elements().First()); + } + } + + var mergeCell = new MergeCell() + { + Reference = new StringValue(excelParams.Merge) + }; + mergeCells.Append(mergeCell); + } + + protected override byte[]? SaveExcel(ExcelInfo info) + { + if (_spreadsheetDocument == null) + { + return null; + } + _spreadsheetDocument.WorkbookPart!.Workbook.Save(); + _spreadsheetDocument.Dispose(); + return _mem.ToArray(); + } + */ + } +} diff --git a/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/Implements/SaveToPdf.cs b/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/Implements/SaveToPdf.cs new file mode 100644 index 0000000..7c94d1a --- /dev/null +++ b/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/Implements/SaveToPdf.cs @@ -0,0 +1,113 @@ +using AutoRepairShopBusinessLogic.OfficePackage.HelperEnums; +using AutoRepairShopBusinessLogic.OfficePackage.HelperModels; +using MigraDoc.DocumentObjectModel; +using MigraDoc.Rendering; +using MigraDoc.DocumentObjectModel.Tables; +using PdfSharp.Pdf; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoRepairShopBusinessLogic.OfficePackage.Implements +{ + public class SaveToPdf : AbstractSaveToPdf + { + /* + private Document? _document; + private Section? _section; + private Table? _table; + + // Типы выравнивания + private static ParagraphAlignment GetParagraphAlignment(PdfParagraphAlignmentType type) + { + return type switch + { + PdfParagraphAlignmentType.Center => ParagraphAlignment.Center, + PdfParagraphAlignmentType.Left => ParagraphAlignment.Left, + PdfParagraphAlignmentType.Right => ParagraphAlignment.Right, + _ => ParagraphAlignment.Justify + }; + } + + private static void DefineStyle(Document document) + { + var style = document.Styles["Normal"]; + style.Font.Name = "Times New Roman"; + style.Font.Size = 14; + style = document.Styles.AddStyle("NormalTitle", "Normal"); + style.Font.Bold = true; + } + + protected override void CreateParagraph(PdfParagraph pdfParagraph) + { + if (_section == null) + { + return; + } + var paragraph = _section.AddParagraph(pdfParagraph.Text); + paragraph.Format.SpaceAfter = "1cm"; + paragraph.Format.Alignment = GetParagraphAlignment(pdfParagraph.alignmentType); + paragraph.Style = pdfParagraph.Style; + } + + protected override void CreatePdf(PdfInfo info) + { + _document = new Document(); + DefineStyle(_document); + // Ссылка на первую секцию + _section = _document.AddSection(); + } + + protected override void CreateRow(PdfRowParameters rowParameters) + { + if (_table == null) + { + return; + } + var row = _table.AddRow(); + for (int i = 0; i < rowParameters.Text.Count; ++i) + { + // заполнение ячейки (добавление параграфа в ячейку) + row.Cells[i].AddParagraph(rowParameters.Text[i]); + if (!string.IsNullOrEmpty(rowParameters.Style)) + { + row.Cells[i].Style = rowParameters.Style; + } + Unit borderWidth = 0.5; + row.Cells[i].Borders.Left.Width = borderWidth; + row.Cells[i].Borders.Right.Width = borderWidth; + row.Cells[i].Borders.Top.Width = borderWidth; + row.Cells[i].Borders.Bottom.Width = borderWidth; + + row.Cells[i].Format.Alignment = GetParagraphAlignment(rowParameters.alignmentType); + row.Cells[i].VerticalAlignment = VerticalAlignment.Center; + } + } + + protected override void CreateTable(List columns) + { + if (_document == null) + { + return; + } + _table = _document.LastSection.AddTable(); + foreach (var elem in columns) + { + _table.AddColumn(elem); + } + } + + protected override PdfDocument SavePdf(PdfInfo info) + { + var renderer = new PdfDocumentRenderer(true) + { + Document = _document, + }; + renderer.RenderDocument(); + renderer.PdfDocument.Save(info.FileName); + return renderer.PdfDocument; + }*/ + } +} diff --git a/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/Implements/SaveToWord.cs b/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/Implements/SaveToWord.cs new file mode 100644 index 0000000..813b45a --- /dev/null +++ b/AutoRepairShop/AutoRepairShopBusinessLogic/OfficePackage/Implements/SaveToWord.cs @@ -0,0 +1,133 @@ +using AutoRepairShopBusinessLogic.OfficePackage.HelperEnums; +using AutoRepairShopBusinessLogic.OfficePackage.HelperModels; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Wordprocessing; +using DocumentFormat.OpenXml; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoRepairShopBusinessLogic.OfficePackage.Implements +{ + /* public class SaveToWord : AbstractSaveToWord + { + private WordprocessingDocument? _wordDocument; + + private Body? _docBody; + + private MemoryStream _mem = new MemoryStream(); + + // Получение типа выравнивания + private static JustificationValues GetJustificationValues(WordJustificationType type) + { + return type switch + { + WordJustificationType.Both => JustificationValues.Both, + WordJustificationType.Center => JustificationValues.Center, + _ => JustificationValues.Left, + }; + } + + // Настройки страницы + private static SectionProperties CreateSectionProperties() + { + var properties = new SectionProperties(); + + var pageSize = new PageSize + { + Orient = PageOrientationValues.Portrait + }; + + properties.AppendChild(pageSize); + + return properties; + } + + // Задание форматирования для абзаца + private static ParagraphProperties? CreateParagraphProperties(WordTextProperties? paragraphProperties) + { + if (paragraphProperties == null) + { + return null; + } + + var properties = new ParagraphProperties(); + + properties.AppendChild(new Justification() + { + Val = GetJustificationValues(paragraphProperties.JustificationType) + }); + + properties.AppendChild(new SpacingBetweenLines + { + LineRule = LineSpacingRuleValues.Auto + }); + + properties.AppendChild(new Indentation()); + + var paragraphMarkRunProperties = new ParagraphMarkRunProperties(); + if (!string.IsNullOrEmpty(paragraphProperties.Size)) + { + paragraphMarkRunProperties.AppendChild(new FontSize { Val = paragraphProperties.Size }); + } + properties.AppendChild(paragraphMarkRunProperties); + + return properties; + } + + protected override void CreateWord(WordInfo info) + { + _wordDocument = WordprocessingDocument.Create(_mem, WordprocessingDocumentType.Document); + MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart(); + mainPart.Document = new Document(); + _docBody = mainPart.Document.AppendChild(new Body()); + } + + protected override void CreateParagraph(WordParagraph paragraph) + { + if (_docBody == null || paragraph == null) + { + return; + } + var docParagraph = new Paragraph(); + + docParagraph.AppendChild(CreateParagraphProperties(paragraph.TextProperties)); + + foreach (var run in paragraph.Texts) + { + var docRun = new Run(); + + var properties = new RunProperties(); + properties.AppendChild(new FontSize { Val = run.Item2.Size }); + if (run.Item2.Bold) + { + properties.AppendChild(new Bold()); + } + docRun.AppendChild(properties); + + docRun.AppendChild(new Text { Text = run.Item1, Space = SpaceProcessingModeValues.Preserve }); + + docParagraph.AppendChild(docRun); + } + + _docBody.AppendChild(docParagraph); + } + + protected override byte[]? SaveWord(WordInfo info) + { + if (_docBody == null || _wordDocument == null) + { + return null; + } + _docBody.AppendChild(CreateSectionProperties()); + + _wordDocument.MainDocumentPart!.Document.Save(); + + _wordDocument.Dispose(); + + return _mem.ToArray(); + } + }*/ +} diff --git a/AutoRepairShop/AutoRepairShopClientApp/APIClient.cs b/AutoRepairShop/AutoRepairShopClientApp/APIClient.cs index 2c7b908..379f459 100644 --- a/AutoRepairShop/AutoRepairShopClientApp/APIClient.cs +++ b/AutoRepairShop/AutoRepairShopClientApp/APIClient.cs @@ -1,4 +1,5 @@ using AutoRepairShopContracts.ViewModels; +using AutoRepairShopDatabaseImplement.Models; using Newtonsoft.Json; using System.Net.Http.Headers; using System.Text; @@ -13,8 +14,7 @@ namespace AutoRepairShopClientApp { _manager.BaseAddress = new Uri(configuration["IPAddress"]); _manager.DefaultRequestHeaders.Accept.Clear(); - _manager.DefaultRequestHeaders.Accept.Add(new - MediaTypeWithQualityHeaderValue("application/json")); + _manager.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); } public static T? GetRequest(string requestUrl) { diff --git a/AutoRepairShop/AutoRepairShopClientApp/Controllers/HomeController.cs b/AutoRepairShop/AutoRepairShopClientApp/Controllers/HomeController.cs index ed7bf7d..7e697d0 100644 --- a/AutoRepairShop/AutoRepairShopClientApp/Controllers/HomeController.cs +++ b/AutoRepairShop/AutoRepairShopClientApp/Controllers/HomeController.cs @@ -1,11 +1,14 @@ using AutoRepairShopClientApp.Models; using AutoRepairShopContracts.BindingModels; using AutoRepairShopContracts.BusinessLogicsContracts; +using AutoRepairShopContracts.SearchModels; using AutoRepairShopContracts.ViewModels; using AutoRepairShopDatabaseImplement.Models; using AutoRepairShopDataModels.Models; using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; using System.Diagnostics; +using System.Threading.Tasks; namespace AutoRepairShopClientApp.Controllers { @@ -24,17 +27,41 @@ namespace AutoRepairShopClientApp.Controllers { return Redirect("~/Home/Enter"); } - return View(APIClient.GetRequest>($"api/main/getworks?managerId={APIClient.Manager.Id}")); + return View(APIClient.GetRequest>, List>>>>($"api/main/getworks?managerId={APIClient.Manager.Id}")); } [HttpGet] - public IActionResult Tasks(int Id) + public IActionResult TaskInfo(int Id, int? Status) + { + if (Id == 0 || Id == null) + { + return Redirect("~/Home/Index"); + } + if (APIClient.Manager == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Tasks = APIClient.GetRequest>>("api/task/gettasklist"); + ViewBag.Clients = APIClient.GetRequest>>("api/client/getclientlist"); + return View(APIClient.GetRequest>, List>>>($"api/main/getworksbyid?Id={Id}")); + + } + [HttpGet] + public IActionResult Tasks() { if (APIClient.Manager == null) { return Redirect("~/Home/Enter"); } - return View(APIClient.GetRequest($"api/main/getworksbyid?Id={Id}")); - + return View(APIClient.GetRequest>>($"api/task/GetTaskList")); + } + [HttpGet] + public IActionResult Clients() + { + if (APIClient.Manager == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest>>($"api/client/GetClientList")); } [HttpGet] public IActionResult Privacy() @@ -124,15 +151,15 @@ namespace AutoRepairShopClientApp.Controllers Response.Redirect("Enter"); return; } - + public IActionResult Create() { - ViewBag.Tasks = APIClient.GetRequest>("api/task/gettasklist"); - ViewBag.Clients = APIClient.GetRequest>("api/client/getclientlist"); + ViewBag.Tasks = APIClient.GetRequest>>("api/task/gettasklist"); + ViewBag.Clients = APIClient.GetRequest>>("api/client/getclientlist"); return View(); } [HttpPost] - public void Create(int Points,List task, List client) + public void Create(int Points, List task, List client) { if (APIClient.Manager == null) { @@ -144,21 +171,138 @@ namespace AutoRepairShopClientApp.Controllers Points = Points, DateCreate = DateTime.Now.ToUniversalTime() }; - APIClient.PostRequest("api/main/creatework", workModel); + var lastWork = APIClient.GetRequest($"api/main/GetLastWork?managerId={APIClient.Manager.Id}"); + var taskStrings = task.Select(id => new List { JsonConvert.SerializeObject(id.ToString()) }).ToList(); + var clientStrings = client.Select(id => new List { JsonConvert.SerializeObject(id.ToString()) }).ToList(); + + APIClient.PostRequest("api/main/addToWork", Tuple.Create(lastWork.Id, taskStrings, clientStrings, Points)); Response.Redirect("Index"); return; } - /* [HttpGet] - public IActionResult Mails() - { - if (APIClient.Manager == null) - { - return Redirect("~/Home/Enter"); - } - return View(APIClient.GetRequest>($"api/client/getmessages?clientId={APIClient.Manager.Id}")); - }*/ + [HttpPost] + public void TaskInfo(int Id, int? Points, List task, List client) + { + if (APIClient.Manager == null) + { + throw new Exception("Ошибка входа!"); + } + var workModel = new WorkBindingModel + { + Id = Id, + ManagerId = APIClient.Manager.Id + }; + if (Points.HasValue) + { + workModel.Points = Points.Value; + } + APIClient.PostRequest("api/main/updateWork", workModel); + var taskStrings = task.Select(id => new List { JsonConvert.SerializeObject(id.ToString()) }).ToList(); + var clientStrings = client.Select(id => new List { JsonConvert.SerializeObject(id.ToString()) }).ToList(); + + APIClient.PostRequest("api/main/addToWork", Tuple.Create(Id, taskStrings, clientStrings, Points.Value)); + Response.Redirect("Index"); + return; + } + public IActionResult DeleteClient(int workId, string clientId) + { + if (APIClient.Manager == null) + { + return Redirect("~/Home/Enter"); + } + string clientIdWithoutQuotes = clientId.Replace("\"", ""); + int clientIdInt = int.Parse(clientIdWithoutQuotes); + APIClient.PostRequest("api/main/DeleteClientFromWork", Tuple.Create(workId, clientIdInt)); + Response.Redirect("Index"); + return View(); + } + public IActionResult DeleteTask(int workId, string taskId) + { + if (APIClient.Manager == null) + { + return Redirect("~/Home/Enter"); + } + string taskIdWithoutQuotes = taskId.Replace("\"", ""); + int taskIdInt = int.Parse(taskIdWithoutQuotes); + APIClient.PostRequest("api/main/DeleteTaskFromWork", Tuple.Create(workId, taskIdInt)); + Response.Redirect("Index"); + return View(); + } + public IActionResult StatusDone(int Id) + { + if (APIClient.Manager == null) + { + return Redirect("~/Home/Enter"); + } + var result = APIClient.GetRequest>, List>>>($"api/main/getworksbyid?Id={Id}"); + + int totalPoints = result.Item2; + List> clients = result.Item6; + int clientCount = clients.Count; + int pointsPerClient = clientCount > 0 ? totalPoints / clientCount : 0; + var clientPointsList = new List>(); + foreach (var client in clients) + { + if (client.Count > 0) + { + string actualClientId = client[0]; + string clientIdWithoutQuotes = actualClientId.Replace("\"", ""); + int actualClientIdInt = Convert.ToInt32(clientIdWithoutQuotes); + + clientPointsList.Add(new Tuple(actualClientIdInt, pointsPerClient)); + } + } + + APIClient.PostRequest("api/main/givePointsToClient", clientPointsList); + APIClient.PostRequest("api/main/workDone", Tuple.Create(Id, DateTime.Now.ToUniversalTime())); + return View(); + } + public IActionResult CreateTask() + { + return View(); + } + [HttpPost] + public void CreateTask(int Points, string Description, DateTime Date) + { + if (APIClient.Manager == null) + { + throw new Exception("Ошибка входа!"); + } + var taskModel = new TaskBindingModel + { + Points = Points, + Description = Description, + DateImplement = Date.ToUniversalTime() + }; + APIClient.PostRequest("api/main/createtask", taskModel); + + Response.Redirect("Index"); + return; + } + public IActionResult CreateClient() + { + return View(); + } + [HttpPost] + public void CreateClient(int Points, string FIO, string Job, string Email) + { + if (APIClient.Manager == null) + { + throw new Exception("Ошибка входа!"); + } + var clientModel = new ClientBindingModel + { + Points = Points, + ClientFIO = FIO, + JobTitle = Job, + Email = Email + }; + APIClient.PostRequest("api/main/createclient", clientModel); + + Response.Redirect("Index"); + return; + } } } \ No newline at end of file diff --git a/AutoRepairShop/AutoRepairShopClientApp/Views/Home/Clients.cshtml b/AutoRepairShop/AutoRepairShopClientApp/Views/Home/Clients.cshtml new file mode 100644 index 0000000..befa863 --- /dev/null +++ b/AutoRepairShop/AutoRepairShopClientApp/Views/Home/Clients.cshtml @@ -0,0 +1,54 @@ +@using AutoRepairShopContracts.ViewModels +@model List> +@{ + ViewData["Title"] = "Клиенты"; +} + +
+

Клиенты

+
+
+ @{ + if (Model == null) + { +

Авторизируйтесь

+ return; + } + } +

+ Создать клиента +

+ + + + + + + + + + + @foreach (var item in Model) + { + var clientId = item.Item1; + var FIO = item.Item2; + var Job = item.Item3; + var Email = item.Item4; + var Points = item.Item5; + + + + + + + + } + +
ФИОДолжностьEmailБаллы
@FIO + @Job + + @Email + + @Points +
+
diff --git a/AutoRepairShop/AutoRepairShopClientApp/Views/Home/Create.cshtml b/AutoRepairShop/AutoRepairShopClientApp/Views/Home/Create.cshtml index 43feca6..38a7714 100644 --- a/AutoRepairShop/AutoRepairShopClientApp/Views/Home/Create.cshtml +++ b/AutoRepairShop/AutoRepairShopClientApp/Views/Home/Create.cshtml @@ -1,4 +1,5 @@ -@{ +@using AutoRepairShopContracts.ViewModels +@{ ViewData["Title"] = "Create"; }
@@ -6,34 +7,53 @@
-
Задание:
-
+
Задание:
+
-
Клиент:
-
+
Клиент:
+
-
Баллы:
-
-
+
Баллы: 0
+ +

-
-
+
+
+ + diff --git a/AutoRepairShop/AutoRepairShopClientApp/Views/Home/CreateClient.cshtml b/AutoRepairShop/AutoRepairShopClientApp/Views/Home/CreateClient.cshtml new file mode 100644 index 0000000..6cfcb64 --- /dev/null +++ b/AutoRepairShop/AutoRepairShopClientApp/Views/Home/CreateClient.cshtml @@ -0,0 +1,37 @@ + + @using AutoRepairShopContracts.ViewModels +@{ + ViewData["Title"] = "Создать задание"; +} +
+

Создание заказа

+
+
+
+
ФИО:
+
+ +
+
+
+
+
Должность:
+
+ +
+
+
+
+
Email:
+
+
+
+
Баллы:
+
+
+
+
+
+
+ +
\ No newline at end of file diff --git a/AutoRepairShop/AutoRepairShopClientApp/Views/Home/CreateTask.cshtml b/AutoRepairShop/AutoRepairShopClientApp/Views/Home/CreateTask.cshtml new file mode 100644 index 0000000..deaa016 --- /dev/null +++ b/AutoRepairShop/AutoRepairShopClientApp/Views/Home/CreateTask.cshtml @@ -0,0 +1,32 @@ +@using AutoRepairShopContracts.ViewModels +@{ + ViewData["Title"] = "Создать задание"; +} +
+

Создание заказа

+
+
+
+
Описание:
+
+ +
+
+
+
+
Дата необходимого выполнения:
+
+ +
+
+
+
+
Баллы:
+
+
+
+
+
+
+ +
\ No newline at end of file diff --git a/AutoRepairShop/AutoRepairShopClientApp/Views/Home/DeleteClient.cshtml b/AutoRepairShop/AutoRepairShopClientApp/Views/Home/DeleteClient.cshtml new file mode 100644 index 0000000..e1dd794 --- /dev/null +++ b/AutoRepairShop/AutoRepairShopClientApp/Views/Home/DeleteClient.cshtml @@ -0,0 +1,5 @@ +@* + For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 +*@ +@{ +} diff --git a/AutoRepairShop/AutoRepairShopClientApp/Views/Home/DeleteTask.cshtml b/AutoRepairShop/AutoRepairShopClientApp/Views/Home/DeleteTask.cshtml new file mode 100644 index 0000000..e1dd794 --- /dev/null +++ b/AutoRepairShop/AutoRepairShopClientApp/Views/Home/DeleteTask.cshtml @@ -0,0 +1,5 @@ +@* + For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 +*@ +@{ +} diff --git a/AutoRepairShop/AutoRepairShopClientApp/Views/Home/Enter.cshtml b/AutoRepairShop/AutoRepairShopClientApp/Views/Home/Enter.cshtml index 636c82c..70eda56 100644 --- a/AutoRepairShop/AutoRepairShopClientApp/Views/Home/Enter.cshtml +++ b/AutoRepairShop/AutoRepairShopClientApp/Views/Home/Enter.cshtml @@ -6,15 +6,15 @@
-
Логин:
-
+
Логин:

+
-
Пароль:
-
+
Пароль:

+
-
+
\ No newline at end of file diff --git a/AutoRepairShop/AutoRepairShopClientApp/Views/Home/Index.cshtml b/AutoRepairShop/AutoRepairShopClientApp/Views/Home/Index.cshtml index c7c9054..70c65c1 100644 --- a/AutoRepairShop/AutoRepairShopClientApp/Views/Home/Index.cshtml +++ b/AutoRepairShop/AutoRepairShopClientApp/Views/Home/Index.cshtml @@ -1,53 +1,77 @@ @using AutoRepairShopContracts.ViewModels -@model List +@model List>, List>>> @{ - ViewData["Title"] = "Home Page"; + ViewData["Title"] = "Home Page"; } +
-

Работы

+

Работы

- @{ - if (Model == null) - { -

Авторизируйтесь

- return; - } -

- Создать работу -

- - - - - - - - - - - - @foreach (var item in Model) - { - - - - - - - - } - -
НомерБаллыДата полученияДата выполненияПросмотр
- @Html.DisplayFor(modelItem => item.Id) - - @Html.DisplayFor(modelItem => item.Points) - - @Html.DisplayFor(modelItem => item.DateCreate) - - @Html.DisplayFor(modelItem => item.DateImplement) - - Посмотреть задания -
- } -
\ No newline at end of file + @{ + if (Model == null) + { +

Авторизируйтесь

+ return; + } + } +

+ Создать работу +

+ + + + + + + + + + + + + @foreach (var item in Model) + { + var workId = item.Item1; + var Points = item.Item2; + var DateCreate = item.Item3; + var DateImplement = item.Item4; + var color = "red"; + if(@DateImplement != "Не выполнено"){ + color = "green"; + } + var taskInfo = item.Item5; + var clientInfo = item.Item6; + + + + + + + + + + } + +
НомерБаллыДата полученияДата выполненияКлиентыУправление
@workId + @Html.DisplayFor(modelItem => Points) + + @Html.DisplayFor(modelItem => DateCreate) + + @Html.DisplayFor(modelItem => DateImplement) + + @if (clientInfo.Any()) + { +

+ @foreach (var client in clientInfo) + { + @string.Join(", ", client[0]) +
+ } +

+ } +
+ Посмотреть задания
+ Завершить +
+ diff --git a/AutoRepairShop/AutoRepairShopClientApp/Views/Home/Privacy.cshtml b/AutoRepairShop/AutoRepairShopClientApp/Views/Home/Privacy.cshtml index 9a8e3f2..9c5102b 100644 --- a/AutoRepairShop/AutoRepairShopClientApp/Views/Home/Privacy.cshtml +++ b/AutoRepairShop/AutoRepairShopClientApp/Views/Home/Privacy.cshtml @@ -9,12 +9,12 @@
Логин:
-
Пароль:
-
@@ -24,7 +24,6 @@
-
+
\ No newline at end of file diff --git a/AutoRepairShop/AutoRepairShopClientApp/Views/Home/Register.cshtml b/AutoRepairShop/AutoRepairShopClientApp/Views/Home/Register.cshtml index 13589c9..1e0be50 100644 --- a/AutoRepairShop/AutoRepairShopClientApp/Views/Home/Register.cshtml +++ b/AutoRepairShop/AutoRepairShopClientApp/Views/Home/Register.cshtml @@ -7,19 +7,18 @@ ViewData["Title"] = "Register";
Логин:
-
+
Пароль:
-
+
ФИО:
-
+
-
+
diff --git a/AutoRepairShop/AutoRepairShopClientApp/Views/Home/StatusDone.cshtml b/AutoRepairShop/AutoRepairShopClientApp/Views/Home/StatusDone.cshtml new file mode 100644 index 0000000..7ec06a1 --- /dev/null +++ b/AutoRepairShop/AutoRepairShopClientApp/Views/Home/StatusDone.cshtml @@ -0,0 +1,9 @@ +@* + For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 +*@ +@{ +} + \ No newline at end of file diff --git a/AutoRepairShop/AutoRepairShopClientApp/Views/Home/TaskInfo.cshtml b/AutoRepairShop/AutoRepairShopClientApp/Views/Home/TaskInfo.cshtml new file mode 100644 index 0000000..83f85d7 --- /dev/null +++ b/AutoRepairShop/AutoRepairShopClientApp/Views/Home/TaskInfo.cshtml @@ -0,0 +1,106 @@ +@using AutoRepairShopContracts.ViewModels +@model Tuple>, List>> +@{ + ViewData["Title"] = "Задания"; + + var workId = Model.Item1; + var Points = Model.Item2; + var DateCreate = Model.Item3; + var DateImplement = Model.Item4; + var taskInfo = Model.Item5; + var clientInfo = Model.Item6; + + var pointOnPerson = clientInfo.Count() == 0 ? Points : (Points / clientInfo.Count()); +} +

Задания для работы #@workId

+ + +

Баллы: @Points

+

Дата создания: @DateCreate

+

Дата выполнения: @DateImplement

+ +

Задания:

+ + +

Клиенты:

+
    + @foreach (var client in clientInfo) + { +
  • + ФИО: + @string.Join(", ", client[1]) + - + +@pointOnPerson баллов добавлено + Удалить

  • + } +
+ +
+

Добавить

+
+ +
+
Задание:
+
+ +
+
+
+
Клиент:
+
+ +
+
+
+
Баллы:
+ +
+
+
+
+
+
+ +
+ \ No newline at end of file diff --git a/AutoRepairShop/AutoRepairShopClientApp/Views/Home/Tasks.cshtml b/AutoRepairShop/AutoRepairShopClientApp/Views/Home/Tasks.cshtml index ad2f219..8c15480 100644 --- a/AutoRepairShop/AutoRepairShopClientApp/Views/Home/Tasks.cshtml +++ b/AutoRepairShop/AutoRepairShopClientApp/Views/Home/Tasks.cshtml @@ -1,45 +1,53 @@ -@using AutoRepairShopDataModels.Models -@model AutoRepairShopContracts.ViewModels.WorkViewModel -@using Newtonsoft.Json +@using AutoRepairShopContracts.ViewModels +@model List> +@{ + ViewData["Title"] = "Задания"; +} - - - - - - Tasks Page - - -

Tasks for Work # @Model.Id

- -

Points: @Model.Points

-

Date Created: @Model.DateCreate

-

Date Implemented: @Model.DateImplement

-

Manager ID: @Model.ManagerId

- -

Tasks:

-
    - @foreach (var taskEntry in Model.WorkTasks) +
    +

    Задания

    +
    +
    + @{ + if (Model == null) { - var taskId = taskEntry.Key; - var taskInfo = taskEntry.Value; - var taskModel = taskInfo.Item1; - var taskDescription = taskModel != null ? taskModel.Description : "No description available"; - -
  • - Task ID: @taskId
    - Description: @taskDescription -
  • +

    Авторизируйтесь

    + return; } -
- -

Clients:

-
    - @foreach (var client in Model.WorkClients) - { -
  • Client ID: @client.Key
  • - } -
- - + } +

+ Создать задание +

+ + + + + + + + + + + @foreach (var item in Model) + { + var taskId = item.Item1; + var Points = item.Item2; + var DateImplement = item.Item3; + var Description = item.Item4; + + + + + + + } + +
НомерБаллыДата необходимого выполненияОписание работы
@taskId + @Points + + @DateImplement + + @Description +
+ diff --git a/AutoRepairShop/AutoRepairShopClientApp/Views/Shared/_Layout.cshtml b/AutoRepairShop/AutoRepairShopClientApp/Views/Shared/_Layout.cshtml index f7dd142..a5b3756 100644 --- a/AutoRepairShop/AutoRepairShopClientApp/Views/Shared/_Layout.cshtml +++ b/AutoRepairShop/AutoRepairShopClientApp/Views/Shared/_Layout.cshtml @@ -14,7 +14,7 @@