diff --git a/ShipyardBusinessLogic/OfficePackage/AbstarctSaveToExcel.cs b/ShipyardBusinessLogic/OfficePackage/AbstarctSaveToExcel.cs
new file mode 100644
index 0000000..ab6c5ef
--- /dev/null
+++ b/ShipyardBusinessLogic/OfficePackage/AbstarctSaveToExcel.cs
@@ -0,0 +1,103 @@
+using ShipyardBusinessLogic.OfficePackage.HelperEnums;
+using ShipyardBusinessLogic.OfficePackage.HelperModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ShipyardBusinessLogic.OfficePackage
+{
+ public abstract class AbstractSaveToExcel
+ {
+ ///
+ /// Создание отчета
+ ///
+ ///
+ public void 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 pc in info.ShipComponents)
+ {
+ InsertCellInWorksheet(new ExcelCellParameters
+ {
+ ColumnName = "A",
+ RowIndex = rowIndex,
+ Text = pc.ShipName,
+ StyleInfo = ExcelStyleInfoType.Text
+ });
+ rowIndex++;
+ foreach (var component in pc.Components)
+ {
+ InsertCellInWorksheet(new ExcelCellParameters
+ {
+ ColumnName = "B",
+ RowIndex = rowIndex,
+ Text = component.Item1,
+ StyleInfo =
+ ExcelStyleInfoType.TextWithBroder
+ });
+ InsertCellInWorksheet(new ExcelCellParameters
+ {
+ ColumnName = "C",
+ RowIndex = rowIndex,
+ Text = component.Item2.ToString(),
+ StyleInfo =
+ ExcelStyleInfoType.TextWithBroder
+ });
+ rowIndex++;
+ }
+ InsertCellInWorksheet(new ExcelCellParameters
+ {
+ ColumnName = "A",
+ RowIndex = rowIndex,
+ Text = "Итого",
+ StyleInfo = ExcelStyleInfoType.Text
+ });
+ InsertCellInWorksheet(new ExcelCellParameters
+ {
+ ColumnName = "C",
+ RowIndex = rowIndex,
+ Text = pc.TotalCount.ToString(),
+ StyleInfo = ExcelStyleInfoType.Text
+ });
+ rowIndex++;
+ }
+ SaveExcel(info);
+ }
+ ///
+ /// Создание excel-файла
+ ///
+ ///
+ protected abstract void CreateExcel(ExcelInfo info);
+ ///
+ /// Добавляем новую ячейку в лист
+ ///
+ ///
+ protected abstract void InsertCellInWorksheet(ExcelCellParameters
+ excelParams);
+ ///
+ /// Объединение ячеек
+ ///
+ ///
+ protected abstract void MergeCells(ExcelMergeParameters excelParams);
+ ///
+ /// Сохранение файла
+ ///
+ ///
+ protected abstract void SaveExcel(ExcelInfo info);
+ }
+}
diff --git a/ShipyardBusinessLogic/OfficePackage/AbstractSaveToPdf.cs b/ShipyardBusinessLogic/OfficePackage/AbstractSaveToPdf.cs
new file mode 100644
index 0000000..b1984d4
--- /dev/null
+++ b/ShipyardBusinessLogic/OfficePackage/AbstractSaveToPdf.cs
@@ -0,0 +1,80 @@
+using ShipyardBusinessLogic.OfficePackage.HelperEnums;
+using ShipyardBusinessLogic.OfficePackage.HelperModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ShipyardBusinessLogic.OfficePackage
+{
+ public abstract class AbstractSaveToPdf
+ {
+ public void CreateDoc(PdfInfo info)
+ {
+ CreatePdf(info);
+ CreateParagraph(new PdfParagraph
+ {
+ Text = info.Title,
+ Style = "NormalTitle",
+ ParagraphAlignment = PdfParagraphAlignmentType.Center
+ });
+ CreateParagraph(new PdfParagraph
+ {
+ Text = $"с{info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}",
+ Style = "Normal",
+ ParagraphAlignment = PdfParagraphAlignmentType.Center
+ });
+ CreateTable(new List { "2cm", "3cm", "6cm", "3cm", "3cm" });
+ CreateRow(new PdfRowParameters
+ {
+ Texts = new List { "Номер", "Дата заказа", "Изделие", "Сумма", "Статус" },
+ Style = "NormalTitle",
+ ParagraphAlignment = PdfParagraphAlignmentType.Center
+ });
+ foreach (var order in info.Orders)
+ {
+ CreateRow(new PdfRowParameters
+ {
+ Texts = new List { order.Id.ToString(), order.DateCreate.ToShortDateString(), order.ShipName, order.Sum.ToString(), order.OrderStatus.ToString()},
+ Style = "Normal",
+ ParagraphAlignment = PdfParagraphAlignmentType.Left
+ });
+ }
+ CreateParagraph(new PdfParagraph
+ {
+ Text = $"Итого: {info.Orders.Sum(x => x.Sum)}\t",
+ Style = "Normal",
+ ParagraphAlignment = PdfParagraphAlignmentType.Right
+ });
+ SavePdf(info);
+ }
+ ///
+ /// Создание doc-файла
+ ///
+ ///
+ 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 void SavePdf(PdfInfo info);
+ }
+}
diff --git a/ShipyardBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/ShipyardBusinessLogic/OfficePackage/AbstractSaveToWord.cs
new file mode 100644
index 0000000..f3afc9b
--- /dev/null
+++ b/ShipyardBusinessLogic/OfficePackage/AbstractSaveToWord.cs
@@ -0,0 +1,58 @@
+using ShipyardBusinessLogic.OfficePackage.HelperEnums;
+using ShipyardBusinessLogic.OfficePackage.HelperModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ShipyardBusinessLogic.OfficePackage
+{
+ public abstract class AbstractSaveToWord
+ {
+ public void 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 ship in info.Ships)
+ {
+ CreateParagraph(new WordParagraph
+ {
+ Texts = new List<(string, WordTextProperties)> { (ship.ShipName, new WordTextProperties { Size = "24", Bold = true}),
+ (" - цена " + ship.Price.ToString(), new WordTextProperties { Size = "24"})
+ },
+ TextProperties = new WordTextProperties
+ {
+ Size = "24",
+ JustificationType = WordJustificationType.Both,
+ }
+ });
+ }
+ SaveWord(info);
+ }
+ ///
+ /// Создание doc-файла
+ ///
+ ///
+ protected abstract void CreateWord(WordInfo info);
+ ///
+ /// Создание абзаца с текстом
+ ///
+ ///
+ ///
+ protected abstract void CreateParagraph(WordParagraph paragraph);
+ ///
+ /// Сохранение файла
+ ///
+ ///
+ protected abstract void SaveWord(WordInfo info);
+ }
+}
diff --git a/ShipyardBusinessLogic/OfficePackage/ExcelCellParameters.cs b/ShipyardBusinessLogic/OfficePackage/ExcelCellParameters.cs
new file mode 100644
index 0000000..a28bb69
--- /dev/null
+++ b/ShipyardBusinessLogic/OfficePackage/ExcelCellParameters.cs
@@ -0,0 +1,18 @@
+using ShipyardBusinessLogic.OfficePackage.HelperEnums;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ShipyardBusinessLogic.OfficePackage.HelperEnums
+{
+ 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/ShipyardBusinessLogic/OfficePackage/ExcelInfo.cs b/ShipyardBusinessLogic/OfficePackage/ExcelInfo.cs
new file mode 100644
index 0000000..115af12
--- /dev/null
+++ b/ShipyardBusinessLogic/OfficePackage/ExcelInfo.cs
@@ -0,0 +1,20 @@
+using ShipyardContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ShipyardBusinessLogic.OfficePackage.HelperModels
+{
+ public class ExcelInfo
+ {
+ public string FileName { get; set; } = string.Empty;
+ public string Title { get; set; } = string.Empty;
+ public List ShipComponents
+ {
+ get;
+ set;
+ } = new();
+ }
+}
diff --git a/ShipyardBusinessLogic/OfficePackage/ExcelMergeParameters.cs b/ShipyardBusinessLogic/OfficePackage/ExcelMergeParameters.cs
new file mode 100644
index 0000000..a6c4974
--- /dev/null
+++ b/ShipyardBusinessLogic/OfficePackage/ExcelMergeParameters.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ShipyardBusinessLogic.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/ShipyardBusinessLogic/OfficePackage/ExcelStyleInfoType.cs b/ShipyardBusinessLogic/OfficePackage/ExcelStyleInfoType.cs
new file mode 100644
index 0000000..83397e1
--- /dev/null
+++ b/ShipyardBusinessLogic/OfficePackage/ExcelStyleInfoType.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ShipyardBusinessLogic.OfficePackage.HelperEnums
+{
+ public enum ExcelStyleInfoType
+ {
+ Title,
+ Text,
+ TextWithBroder
+ }
+}
diff --git a/ShipyardBusinessLogic/OfficePackage/Implements/SaveToExcel.cs b/ShipyardBusinessLogic/OfficePackage/Implements/SaveToExcel.cs
new file mode 100644
index 0000000..3eba73c
--- /dev/null
+++ b/ShipyardBusinessLogic/OfficePackage/Implements/SaveToExcel.cs
@@ -0,0 +1,326 @@
+using DocumentFormat.OpenXml;
+using DocumentFormat.OpenXml.Office2010.Excel;
+using DocumentFormat.OpenXml.Office2013.Excel;
+using DocumentFormat.OpenXml.Packaging;
+using DocumentFormat.OpenXml.Spreadsheet;
+using ShipyardBusinessLogic.OfficePackage.HelperEnums;
+using ShipyardBusinessLogic.OfficePackage.HelperModels;
+
+namespace ShipyardBusinessLogic.OfficePackage.Implements
+{
+ public class SaveToExcel : AbstractSaveToExcel
+ {
+ private SpreadsheetDocument? _spreadsheetDocument;
+ private SharedStringTablePart? _shareStringPart;
+ private Worksheet? _worksheet;
+ ///
+ /// Настройка стилей для файла
+ ///
+ ///
+ 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(ExcelInfo info)
+ {
+ _spreadsheetDocument = SpreadsheetDocument.Create(info.FileName,
+ 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 void SaveExcel(ExcelInfo info)
+ {
+ if (_spreadsheetDocument == null)
+ {
+ return;
+ }
+ _spreadsheetDocument.WorkbookPart!.Workbook.Save();
+ _spreadsheetDocument.Dispose();
+ }
+ }
+}
diff --git a/ShipyardBusinessLogic/OfficePackage/Implements/SaveToPdf.cs b/ShipyardBusinessLogic/OfficePackage/Implements/SaveToPdf.cs
new file mode 100644
index 0000000..28c9f9a
--- /dev/null
+++ b/ShipyardBusinessLogic/OfficePackage/Implements/SaveToPdf.cs
@@ -0,0 +1,102 @@
+using ShipyardBusinessLogic.OfficePackage.HelperEnums;
+using ShipyardBusinessLogic.OfficePackage.HelperModels;
+using MigraDoc.DocumentObjectModel;
+using MigraDoc.DocumentObjectModel.Tables;
+using MigraDoc.Rendering;
+
+
+namespace ShipyardBusinessLogic.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 DefineStyles(Document document)
+ {
+ //FontResolver resolver = new FontResolver();
+ 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 CreatePdf(PdfInfo info)
+ {
+ _document = new Document();
+ DefineStyles(_document);
+ _section = _document.AddSection();
+ }
+ 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.ParagraphAlignment);
+ paragraph.Style = pdfParagraph.Style;
+ }
+ protected override void CreateTable(List columns)
+ {
+ if (_document == null)
+ {
+ return;
+ }
+ _table = _document.LastSection.AddTable();
+ foreach (var elem in columns)
+ {
+ _table.AddColumn(elem);
+ }
+ }
+ protected override void CreateRow(PdfRowParameters rowParameters)
+ {
+ if (_table == null)
+ {
+ return;
+ }
+ var row = _table.AddRow();
+ for (int i = 0; i < rowParameters.Texts.Count; ++i)
+ {
+ row.Cells[i].AddParagraph(rowParameters.Texts[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.ParagraphAlignment);
+ row.Cells[i].VerticalAlignment = VerticalAlignment.Center;
+ }
+ }
+ protected override void SavePdf(PdfInfo info)
+ {
+ var renderer = new PdfDocumentRenderer(true)
+ {
+ Document = _document
+ };
+ renderer.RenderDocument();
+ renderer.PdfDocument.Save(info.FileName);
+ }
+ }
+}
diff --git a/ShipyardBusinessLogic/OfficePackage/Implements/SaveToWord.cs b/ShipyardBusinessLogic/OfficePackage/Implements/SaveToWord.cs
new file mode 100644
index 0000000..4620081
--- /dev/null
+++ b/ShipyardBusinessLogic/OfficePackage/Implements/SaveToWord.cs
@@ -0,0 +1,132 @@
+using DocumentFormat.OpenXml;
+using DocumentFormat.OpenXml.Packaging;
+using DocumentFormat.OpenXml.Wordprocessing;
+using ShipyardBusinessLogic.OfficePackage.HelperEnums;
+using ShipyardBusinessLogic.OfficePackage.HelperModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection.Metadata;
+using System.Text;
+using System.Threading.Tasks;
+using DocumentFormat.OpenXml;
+using DocumentFormat.OpenXml.Packaging;
+using DocumentFormat.OpenXml.Wordprocessing;
+
+using static System.Net.Mime.MediaTypeNames;
+using Text = DocumentFormat.OpenXml.Wordprocessing.Text;
+
+namespace ShipyardBusinessLogic.OfficePackage.Implements
+{
+ public class SaveToWord : AbstractSaveToWord
+ {
+ private WordprocessingDocument? _wordDocument;
+ private Body? _docBody;
+ ///
+ /// Получение типа выравнивания
+ ///
+ ///
+ ///
+ 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(info.FileName, WordprocessingDocumentType.Document);
+ MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart();
+ mainPart.Document = new DocumentFormat.OpenXml.Wordprocessing.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 void SaveWord(WordInfo info)
+ {
+ if (_docBody == null || _wordDocument == null)
+ {
+ return;
+ }
+ _docBody.AppendChild(CreateSectionProperties());
+ _wordDocument.MainDocumentPart!.Document.Save();
+ _wordDocument.Dispose();
+ }
+ }
+}
diff --git a/ShipyardBusinessLogic/OfficePackage/PdfInfo.cs b/ShipyardBusinessLogic/OfficePackage/PdfInfo.cs
new file mode 100644
index 0000000..ed3a63a
--- /dev/null
+++ b/ShipyardBusinessLogic/OfficePackage/PdfInfo.cs
@@ -0,0 +1,18 @@
+using ShipyardContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ShipyardBusinessLogic.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 DateTime DateTo { get; set; }
+ public List Orders { get; set; } = new();
+ }
+}
diff --git a/ShipyardBusinessLogic/OfficePackage/PdfParagraph.cs b/ShipyardBusinessLogic/OfficePackage/PdfParagraph.cs
new file mode 100644
index 0000000..114d8c8
--- /dev/null
+++ b/ShipyardBusinessLogic/OfficePackage/PdfParagraph.cs
@@ -0,0 +1,16 @@
+using ShipyardBusinessLogic.OfficePackage.HelperEnums;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ShipyardBusinessLogic.OfficePackage.HelperModels
+{
+ public class PdfParagraph
+ {
+ public string Text { get; set; } = string.Empty;
+ public string Style { get; set; } = string.Empty;
+ public PdfParagraphAlignmentType ParagraphAlignment { get; set; }
+ }
+}
diff --git a/ShipyardBusinessLogic/OfficePackage/PdfParagraphAlignmentType.cs b/ShipyardBusinessLogic/OfficePackage/PdfParagraphAlignmentType.cs
new file mode 100644
index 0000000..4fc6d7a
--- /dev/null
+++ b/ShipyardBusinessLogic/OfficePackage/PdfParagraphAlignmentType.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ShipyardBusinessLogic.OfficePackage.HelperEnums
+{
+ public enum PdfParagraphAlignmentType
+ {
+ Center,
+ Left,
+ Right
+ }
+}
diff --git a/ShipyardBusinessLogic/OfficePackage/PdfRowParameters.cs b/ShipyardBusinessLogic/OfficePackage/PdfRowParameters.cs
new file mode 100644
index 0000000..da94610
--- /dev/null
+++ b/ShipyardBusinessLogic/OfficePackage/PdfRowParameters.cs
@@ -0,0 +1,16 @@
+using ShipyardBusinessLogic.OfficePackage.HelperEnums;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ShipyardBusinessLogic.OfficePackage.HelperModels
+{
+ public class PdfRowParameters
+ {
+ public List Texts { get; set; } = new();
+ public string Style { get; set; } = string.Empty;
+ public PdfParagraphAlignmentType ParagraphAlignment { get; set; }
+ }
+}
diff --git a/ShipyardBusinessLogic/OfficePackage/WordInfo.cs b/ShipyardBusinessLogic/OfficePackage/WordInfo.cs
new file mode 100644
index 0000000..18414ac
--- /dev/null
+++ b/ShipyardBusinessLogic/OfficePackage/WordInfo.cs
@@ -0,0 +1,16 @@
+using ShipyardContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ShipyardBusinessLogic.OfficePackage.HelperModels
+{
+ public class WordInfo
+ {
+ public string FileName { get; set; } = string.Empty;
+ public string Title { get; set; } = string.Empty;
+ public List Ships { get; set; } = new();
+ }
+}
diff --git a/ShipyardBusinessLogic/OfficePackage/WordJustificationType.cs b/ShipyardBusinessLogic/OfficePackage/WordJustificationType.cs
new file mode 100644
index 0000000..1f93fc7
--- /dev/null
+++ b/ShipyardBusinessLogic/OfficePackage/WordJustificationType.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ShipyardBusinessLogic.OfficePackage.HelperEnums
+{
+ public enum WordJustificationType
+ {
+ Center,
+ Both
+ }
+}
diff --git a/ShipyardBusinessLogic/OfficePackage/WordParagraph.cs b/ShipyardBusinessLogic/OfficePackage/WordParagraph.cs
new file mode 100644
index 0000000..1d4770d
--- /dev/null
+++ b/ShipyardBusinessLogic/OfficePackage/WordParagraph.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ShipyardBusinessLogic.OfficePackage.HelperModels
+{
+ public class WordParagraph
+ {
+ public List<(string, WordTextProperties)> Texts { get; set; } = new();
+ public WordTextProperties? TextProperties { get; set; }
+ }
+}
diff --git a/ShipyardBusinessLogic/OfficePackage/WordTextProperties.cs b/ShipyardBusinessLogic/OfficePackage/WordTextProperties.cs
new file mode 100644
index 0000000..0ff1e80
--- /dev/null
+++ b/ShipyardBusinessLogic/OfficePackage/WordTextProperties.cs
@@ -0,0 +1,16 @@
+using ShipyardBusinessLogic.OfficePackage.HelperEnums;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ShipyardBusinessLogic.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/ShipyardContracts/BindingModels/ReportBindingModel.cs b/ShipyardContracts/BindingModels/ReportBindingModel.cs
new file mode 100644
index 0000000..49774aa
--- /dev/null
+++ b/ShipyardContracts/BindingModels/ReportBindingModel.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ShipyardContracts.BindingModels
+{
+ public class ReportBindingModel
+ {
+ public string FileName { get; set; } = string.Empty;
+ public DateTime? DateFrom { get; set; }
+ public DateTime? DateTo { get; set; }
+ }
+}
diff --git a/ShipyardContracts/SearchModels/OrderSearchModel.cs b/ShipyardContracts/SearchModels/OrderSearchModel.cs
index f72af32..1f9af2a 100644
--- a/ShipyardContracts/SearchModels/OrderSearchModel.cs
+++ b/ShipyardContracts/SearchModels/OrderSearchModel.cs
@@ -3,5 +3,8 @@
public class OrderSearchModel
{
public int? Id { get; set; }
+ public DateTime? DateFrom { get; set; }
+ public DateTime? DateTo { get; set; }
+
}
}
\ No newline at end of file
diff --git a/ShipyardContracts/ViewModels/ReportOrdersViewModel.cs b/ShipyardContracts/ViewModels/ReportOrdersViewModel.cs
new file mode 100644
index 0000000..edf3f42
--- /dev/null
+++ b/ShipyardContracts/ViewModels/ReportOrdersViewModel.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ShipyardContracts.ViewModels
+{
+ public class ReportOrdersViewModel
+ {
+ public int Id { get; set; }
+ public DateTime DateCreate { get; set; }
+ public string ShipName { get; set; }
+ public double Sum { get; set; }
+ public string OrderStatus { get; set; } = string.Empty;
+ }
+}
diff --git a/ShipyardContracts/ViewModels/ReportShipComponentViewModel.cs b/ShipyardContracts/ViewModels/ReportShipComponentViewModel.cs
new file mode 100644
index 0000000..0253fed
--- /dev/null
+++ b/ShipyardContracts/ViewModels/ReportShipComponentViewModel.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ShipyardContracts.ViewModels
+{
+ public class ReportShipComponentViewModel
+ {
+ public string ShipName { get; set; } = string.Empty;
+ public int TotalCount { get; set; }
+ public List> Components { get; set; } = new();
+ }
+}
diff --git a/ShipyardDatabaseImplement/OrderStorage.cs b/ShipyardDatabaseImplement/OrderStorage.cs
index f46b100..7835d1a 100644
--- a/ShipyardDatabaseImplement/OrderStorage.cs
+++ b/ShipyardDatabaseImplement/OrderStorage.cs
@@ -1,4 +1,5 @@
-using ShipyardContracts.BindingModels;
+using Microsoft.EntityFrameworkCore;
+using ShipyardContracts.BindingModels;
using ShipyardContracts.SearchModels;
using ShipyardContracts.StoragesContracts;
using ShipyardContracts.ViewModels;
@@ -17,19 +18,21 @@ namespace ShipyardDatabaseImplement.Implements
{
using var context = new ShipyardDataBase();
return context.Orders
- .Select(x => AccessShipStorage(x.GetViewModel))
+ .Include(x => x.Ship).Select(x => x.GetViewModel)
.ToList();
}
public List GetFilteredList(OrderSearchModel model)
{
- if (!model.Id.HasValue)
- {
- return new();
- }
using var context = new ShipyardDataBase();
return context.Orders
- .Where(x => x.Id == model.Id)
- .Select(x => AccessShipStorage(x.GetViewModel))
+ .Where(x => (
+ (!model.Id.HasValue || x.Id == model.Id) &&
+ (!model.DateFrom.HasValue || x.DateCreate >= model.DateFrom) &&
+ (!model.DateTo.HasValue || x.DateCreate <= model.DateTo)
+ )
+ )
+ .Include(x => x.Ship)
+ .Select(x => x.GetViewModel)
.ToList();
}
public OrderViewModel? GetElement(OrderSearchModel model)
@@ -39,19 +42,19 @@ namespace ShipyardDatabaseImplement.Implements
return null;
}
using var context = new ShipyardDataBase();
- return AccessShipStorage(context.Orders.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel);
+ return context.Orders.Include(x => x.Ship).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
}
public OrderViewModel? Insert(OrderBindingModel model)
{
- var newOrder = Order.Create(model);
+ using var context = new ShipyardDataBase();
+ var newOrder = Order.Create(model, context);
if (newOrder == null)
{
return null;
}
- using var context = new ShipyardDataBase();
context.Orders.Add(newOrder);
context.SaveChanges();
- return AccessShipStorage(newOrder.GetViewModel);
+ return newOrder.GetViewModel;
}
public OrderViewModel? Update(OrderBindingModel model)
{
@@ -64,7 +67,7 @@ namespace ShipyardDatabaseImplement.Implements
}
order.Update(model);
context.SaveChanges();
- return AccessShipStorage(order.GetViewModel);
+ return order.GetViewModel;
}
public OrderViewModel? Delete(OrderBindingModel model)
{
@@ -75,25 +78,9 @@ namespace ShipyardDatabaseImplement.Implements
{
context.Orders.Remove(element);
context.SaveChanges();
- return AccessShipStorage(element.GetViewModel);
+ return element.GetViewModel;
}
return null;
}
-
- public static OrderViewModel AccessShipStorage(OrderViewModel model)
- {
- if (model == null)
- return null;
- using var context = new ShipyardDataBase();
- foreach (var manufacture in context.Ships)
- {
- if (manufacture.Id == model.ShipId)
- {
- model.ShipName = manufacture.ShipName;
- break;
- }
- }
- return model;
- }
}
}
\ No newline at end of file
diff --git a/ShipyardFileImplement/OrderStorage.cs b/ShipyardFileImplement/OrderStorage.cs
index 1122256..536e8c6 100644
--- a/ShipyardFileImplement/OrderStorage.cs
+++ b/ShipyardFileImplement/OrderStorage.cs
@@ -1,89 +1,93 @@
-using ShipyardContracts.BindingModels;
-using ShipyardContracts.SearchModels;
-using ShipyardContracts.StoragesContracts;
-using ShipyardContracts.ViewModels;
-using ShipyardFileImplement.Models;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace ShipyardFileImplement.Implements
-{
- public class OrderStorage : IOrderStorage
- {
- private readonly DataFileSingleton source;
- public OrderStorage()
- {
- source = DataFileSingleton.GetInstance();
- }
- public List GetFullList()
- {
- return source.Orders.Select(x => AccessShipStorage(x.GetViewModel)).ToList();
- }
- public List GetFilteredList(OrderSearchModel model)
- {
- if (!model.Id.HasValue)
- {
- return new();
- }
- return source.Orders
- .Where(x => x.Id == model.Id)
- .Select(x => AccessShipStorage(x.GetViewModel))
- .ToList();
- }
- public OrderViewModel? GetElement(OrderSearchModel model)
- {
- if (!model.Id.HasValue)
- {
- return null;
- }
- return AccessShipStorage(source.Orders.FirstOrDefault(
- x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel
- );
- }
- public OrderViewModel? Insert(OrderBindingModel model)
- {
- model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1;
- var newOrder = Order.Create(model);
- if (newOrder == null)
- {
- return null;
- }
- source.Orders.Add(newOrder);
- source.SaveOrders();
- return AccessShipStorage(newOrder.GetViewModel);
- }
- public OrderViewModel? Update(OrderBindingModel model)
- {
- var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
- if (order == null)
- {
- return null;
- }
- order.Update(model);
- source.SaveOrders();
- return AccessShipStorage(order.GetViewModel);
- }
- public OrderViewModel? Delete(OrderBindingModel model)
- {
- var element = source.Orders.FirstOrDefault(x => x.Id ==
- model.Id);
- if (element != null)
- {
- source.Orders.Remove(element);
- source.SaveOrders();
- return AccessShipStorage(element.GetViewModel);
- }
- return null;
- }
- public OrderViewModel? AccessShipStorage(OrderViewModel model)
- {
- if (model == null)
- return null;
- model = source.Ships.Where(x => x.Id == model.ShipId).FirstOrDefault();
- return model;
- }
- }
+using ShipyardContracts.BindingModels;
+using ShipyardContracts.SearchModels;
+using ShipyardContracts.StoragesContracts;
+using ShipyardContracts.ViewModels;
+using ShipyardFileImplement.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ShipyardFileImplement.Implements
+{
+ public class OrderStorage : IOrderStorage
+ {
+ private readonly DataFileSingleton source;
+ public OrderStorage()
+ {
+ source = DataFileSingleton.GetInstance();
+ }
+ public List GetFullList()
+ {
+ return source.Orders.Select(x => AccessShipStorage(x.GetViewModel)).ToList();
+ }
+ public List GetFilteredList(OrderSearchModel model)
+ {
+
+ return source.Orders
+ .Where(x => (
+ (!model.Id.HasValue || x.Id == model.Id) &&
+ (!model.DateFrom.HasValue || x.DateCreate >= model.DateFrom) &&
+ (!model.DateTo.HasValue || x.DateCreate <= model.DateTo)
+ )
+ )
+ .Select(x => AccessShipStorage(x.GetViewModel))
+ .ToList();
+ }
+ public OrderViewModel? GetElement(OrderSearchModel model)
+ {
+ if (!model.Id.HasValue)
+ {
+ return null;
+ }
+ return AccessShipStorage(source.Orders.FirstOrDefault(
+ x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel
+ );
+ }
+ public OrderViewModel? Insert(OrderBindingModel model)
+ {
+ model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1;
+ var newOrder = Order.Create(model);
+ if (newOrder == null)
+ {
+ return null;
+ }
+ source.Orders.Add(newOrder);
+ source.SaveOrders();
+ return AccessShipStorage(newOrder.GetViewModel);
+ }
+ public OrderViewModel? Update(OrderBindingModel model)
+ {
+ var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
+ if (order == null)
+ {
+ return null;
+ }
+ order.Update(model);
+ source.SaveOrders();
+ return AccessShipStorage(order.GetViewModel);
+ }
+ public OrderViewModel? Delete(OrderBindingModel model)
+ {
+ var element = source.Orders.FirstOrDefault(x => x.Id ==
+ model.Id);
+ if (element != null)
+ {
+ source.Orders.Remove(element);
+ source.SaveOrders();
+ return AccessShipStorage(element.GetViewModel);
+ }
+ return null;
+ }
+ public OrderViewModel? AccessShipStorage(OrderViewModel model)
+ {
+ if (model == null)
+ return null;
+ var ship = source.Ships.FirstOrDefault(x => x.Id == model.Id);
+ if (ship != null)
+ model.ShipName = ship.ShipName;
+ return model;
+ }
+ }
}
\ No newline at end of file
diff --git a/ShipyardListImplement/OrderStorage.cs b/ShipyardListImplement/OrderStorage.cs
index dc37dd6..cbc7c10 100644
--- a/ShipyardListImplement/OrderStorage.cs
+++ b/ShipyardListImplement/OrderStorage.cs
@@ -24,13 +24,12 @@ namespace ShipyardListImplement
public List GetFilteredList(OrderSearchModel model)
{
var result = new List();
- if (!model.Id.HasValue)
- {
- return result;
- }
+
foreach (var order in _source.Orders)
{
- if (order.Id == model.Id)
+ if ((!model.Id.HasValue || order.Id == model.Id) &&
+ (!model.DateFrom.HasValue || order.DateCreate >= model.DateFrom)
+ && (!model.DateTo.HasValue || order.DateCreate <= model.DateTo))
{
result.Add(AccessShipStorage(order.GetViewModel));
}
diff --git a/ShipyardView/FormComponent.Designer.cs b/ShipyardView/FormComponent.Designer.cs
new file mode 100644
index 0000000..1d1be47
--- /dev/null
+++ b/ShipyardView/FormComponent.Designer.cs
@@ -0,0 +1,118 @@
+namespace ShipyardView
+{
+ partial class FormComponent
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ textBoxName = new TextBox();
+ textBoxCost = new TextBox();
+ buttonCancel = new Button();
+ ButtonSave = new Button();
+ labelName = new Label();
+ labelCost = new Label();
+ SuspendLayout();
+ //
+ // textBoxName
+ //
+ textBoxName.Location = new Point(326, 42);
+ textBoxName.Name = "textBoxName";
+ textBoxName.Size = new Size(171, 27);
+ textBoxName.TabIndex = 0;
+ //
+ // textBoxCost
+ //
+ textBoxCost.Location = new Point(329, 100);
+ textBoxCost.Name = "textBoxCost";
+ textBoxCost.Size = new Size(168, 27);
+ textBoxCost.TabIndex = 1;
+ //
+ // buttonCancel
+ //
+ buttonCancel.Location = new Point(429, 158);
+ buttonCancel.Name = "buttonCancel";
+ buttonCancel.Size = new Size(94, 29);
+ buttonCancel.TabIndex = 2;
+ buttonCancel.Text = "отмена";
+ buttonCancel.UseVisualStyleBackColor = true;
+ buttonCancel.Click += ButtonCancel_Click;
+ //
+ // ButtonSave
+ //
+ ButtonSave.Location = new Point(312, 158);
+ ButtonSave.Name = "ButtonSave";
+ ButtonSave.Size = new Size(94, 29);
+ ButtonSave.TabIndex = 3;
+ ButtonSave.Text = "сохранить";
+ ButtonSave.UseVisualStyleBackColor = true;
+ ButtonSave.Click += ButtonSave_Click;
+ //
+ // labelName
+ //
+ labelName.AutoSize = true;
+ labelName.Location = new Point(235, 42);
+ labelName.Name = "labelName";
+ labelName.Size = new Size(75, 20);
+ labelName.TabIndex = 4;
+ labelName.Text = "название";
+ //
+ // labelCost
+ //
+ labelCost.AutoSize = true;
+ labelCost.Location = new Point(249, 103);
+ labelCost.Name = "labelCost";
+ labelCost.Size = new Size(43, 20);
+ labelCost.TabIndex = 5;
+ labelCost.Text = "цена";
+ //
+ // FormComponent
+ //
+ AutoScaleDimensions = new SizeF(8F, 20F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(800, 210);
+ Controls.Add(labelCost);
+ Controls.Add(labelName);
+ Controls.Add(ButtonSave);
+ Controls.Add(buttonCancel);
+ Controls.Add(textBoxCost);
+ Controls.Add(textBoxName);
+ Name = "FormComponent";
+ Text = "Form1";
+ Load += FormComponent_Load;
+ ResumeLayout(false);
+ PerformLayout();
+ }
+
+ #endregion
+
+ private TextBox textBoxName;
+ private TextBox textBoxCost;
+ private Button buttonCancel;
+ private Button ButtonSave;
+ private Label labelName;
+ private Label labelCost;
+ }
+}
\ No newline at end of file
diff --git a/ShipyardView/FormComponents.Designer.cs b/ShipyardView/FormComponents.Designer.cs
new file mode 100644
index 0000000..6f4970c
--- /dev/null
+++ b/ShipyardView/FormComponents.Designer.cs
@@ -0,0 +1,114 @@
+namespace ShipyardView
+{
+ partial class FormComponents
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ ButtonAdd = new Button();
+ ButtonUpd = new Button();
+ ButtonDel = new Button();
+ ButtonRef = new Button();
+ dataGridView = new DataGridView();
+ ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
+ SuspendLayout();
+ //
+ // ButtonAdd
+ //
+ ButtonAdd.Location = new Point(678, 34);
+ ButtonAdd.Name = "ButtonAdd";
+ ButtonAdd.Size = new Size(94, 47);
+ ButtonAdd.TabIndex = 0;
+ ButtonAdd.Text = "добавить";
+ ButtonAdd.UseVisualStyleBackColor = true;
+ ButtonAdd.Click += ButtonAdd_Click;
+ //
+ // ButtonUpd
+ //
+ ButtonUpd.Location = new Point(678, 106);
+ ButtonUpd.Name = "ButtonUpd";
+ ButtonUpd.Size = new Size(94, 45);
+ ButtonUpd.TabIndex = 1;
+ ButtonUpd.Text = "изменить";
+ ButtonUpd.UseVisualStyleBackColor = true;
+ ButtonUpd.Click += ButtonUpd_Click;
+ //
+ // ButtonDel
+ //
+ ButtonDel.Location = new Point(678, 176);
+ ButtonDel.Name = "ButtonDel";
+ ButtonDel.Size = new Size(94, 51);
+ ButtonDel.TabIndex = 2;
+ ButtonDel.Text = "удалить";
+ ButtonDel.UseVisualStyleBackColor = true;
+ ButtonDel.Click += ButtonDel_Click;
+ //
+ // ButtonRef
+ //
+ ButtonRef.Location = new Point(678, 262);
+ ButtonRef.Name = "ButtonRef";
+ ButtonRef.Size = new Size(94, 49);
+ ButtonRef.TabIndex = 3;
+ ButtonRef.Text = "обновить";
+ ButtonRef.UseVisualStyleBackColor = true;
+ ButtonRef.Click += ButtonRef_Click;
+ //
+ // dataGridView
+ //
+ dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ dataGridView.Location = new Point(12, 22);
+ dataGridView.Name = "dataGridView";
+ dataGridView.RowHeadersWidth = 51;
+ dataGridView.RowTemplate.Height = 29;
+ dataGridView.Size = new Size(622, 416);
+ dataGridView.TabIndex = 4;
+ //
+ // FormComponents
+ //
+ AutoScaleDimensions = new SizeF(8F, 20F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(800, 450);
+ Controls.Add(dataGridView);
+ Controls.Add(ButtonRef);
+ Controls.Add(ButtonDel);
+ Controls.Add(ButtonUpd);
+ Controls.Add(ButtonAdd);
+ Name = "FormComponents";
+ Text = "FormComponents";
+ Load += FormComponents_Load;
+ ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private Button ButtonAdd;
+ private Button ButtonUpd;
+ private Button ButtonDel;
+ private Button ButtonRef;
+ private DataGridView dataGridView;
+ }
+}
\ No newline at end of file
diff --git a/ShipyardView/FormCreateOrder.Designer.cs b/ShipyardView/FormCreateOrder.Designer.cs
new file mode 100644
index 0000000..209cfff
--- /dev/null
+++ b/ShipyardView/FormCreateOrder.Designer.cs
@@ -0,0 +1,143 @@
+namespace ShipyardView
+{
+ partial class FormCreateOrder
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ textBoxCount = new TextBox();
+ textBoxSum = new TextBox();
+ ComboBoxManufacture = new ComboBox();
+ ButtonCancel = new Button();
+ ButtonSave = new Button();
+ labelItem = new Label();
+ labelcount = new Label();
+ labeltotal = new Label();
+ SuspendLayout();
+ //
+ // textBoxCount
+ //
+ textBoxCount.Location = new Point(455, 56);
+ textBoxCount.Name = "textBoxCount";
+ textBoxCount.Size = new Size(125, 27);
+ textBoxCount.TabIndex = 1;
+ textBoxCount.TextChanged += textBoxCount_TextChanged;
+ //
+ // textBoxSum
+ //
+ textBoxSum.Location = new Point(377, 109);
+ textBoxSum.Name = "textBoxSum";
+ textBoxSum.ReadOnly = true;
+ textBoxSum.Size = new Size(125, 27);
+ textBoxSum.TabIndex = 2;
+ //
+ // ComboBoxManufacture
+ //
+ ComboBoxManufacture.FormattingEnabled = true;
+ ComboBoxManufacture.Location = new Point(271, 55);
+ ComboBoxManufacture.Name = "ComboBoxManufacture";
+ ComboBoxManufacture.Size = new Size(151, 28);
+ ComboBoxManufacture.TabIndex = 3;
+ ComboBoxManufacture.SelectedIndexChanged += ComboBoxManufacture_SelectedIndexChanged;
+ //
+ // ButtonCancel
+ //
+ ButtonCancel.Location = new Point(440, 168);
+ ButtonCancel.Name = "ButtonCancel";
+ ButtonCancel.Size = new Size(94, 29);
+ ButtonCancel.TabIndex = 4;
+ ButtonCancel.Text = "отмена";
+ ButtonCancel.UseVisualStyleBackColor = true;
+ ButtonCancel.Click += ButtonCancel_Click;
+ //
+ // ButtonSave
+ //
+ ButtonSave.Location = new Point(307, 168);
+ ButtonSave.Name = "ButtonSave";
+ ButtonSave.Size = new Size(94, 29);
+ ButtonSave.TabIndex = 5;
+ ButtonSave.Text = "сохранить";
+ ButtonSave.UseVisualStyleBackColor = true;
+ ButtonSave.Click += ButtonSave_Click;
+ //
+ // labelItem
+ //
+ labelItem.AutoSize = true;
+ labelItem.Location = new Point(271, 22);
+ labelItem.Name = "labelItem";
+ labelItem.Size = new Size(67, 20);
+ labelItem.TabIndex = 6;
+ labelItem.Text = "корабль";
+ //
+ // labelcount
+ //
+ labelcount.AutoSize = true;
+ labelcount.Location = new Point(455, 22);
+ labelcount.Name = "labelcount";
+ labelcount.Size = new Size(88, 20);
+ labelcount.TabIndex = 7;
+ labelcount.Text = "количество";
+ //
+ // labeltotal
+ //
+ labeltotal.AutoSize = true;
+ labeltotal.Location = new Point(307, 112);
+ labeltotal.Name = "labeltotal";
+ labeltotal.Size = new Size(51, 20);
+ labeltotal.TabIndex = 8;
+ labeltotal.Text = "итого:";
+ //
+ // FormCreateOrder
+ //
+ AutoScaleDimensions = new SizeF(8F, 20F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(800, 209);
+ Controls.Add(labeltotal);
+ Controls.Add(labelcount);
+ Controls.Add(labelItem);
+ Controls.Add(ButtonSave);
+ Controls.Add(ButtonCancel);
+ Controls.Add(ComboBoxManufacture);
+ Controls.Add(textBoxSum);
+ Controls.Add(textBoxCount);
+ Name = "FormCreateOrder";
+ Text = "FormCreateOrder";
+ Load += FormCreateOrder_Load;
+ ResumeLayout(false);
+ PerformLayout();
+ }
+
+ #endregion
+ private TextBox textBoxCount;
+ private TextBox textBoxSum;
+ private ComboBox ComboBoxManufacture;
+ private Button ButtonCancel;
+ private Button ButtonSave;
+ private Label labelItem;
+ private Label labelcount;
+ private Label labeltotal;
+ }
+}
\ No newline at end of file
diff --git a/ShipyardView/FormMain.Designer.cs b/ShipyardView/FormMain.Designer.cs
new file mode 100644
index 0000000..b03acd6
--- /dev/null
+++ b/ShipyardView/FormMain.Designer.cs
@@ -0,0 +1,215 @@
+namespace ShipyardView
+{
+ partial class FormMain
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ dataGridView = new DataGridView();
+ ShipId = new DataGridViewTextBoxColumn();
+ ButtonRef = new Button();
+ ButtonCreateOrder = new Button();
+ ButtonTakeOrderInWork = new Button();
+ ButtonOrderReady = new Button();
+ ButtonIssuedOrder = new Button();
+ menuStrip1 = new MenuStrip();
+ ReportstoolStrip = new ToolStripMenuItem();
+ ComponentListToolStripMenuItem = new ToolStripMenuItem();
+ ComponentsShipToolStripMenuItem = new ToolStripMenuItem();
+ OrderListToolStripMenuItem = new ToolStripMenuItem();
+ GuidesToolStripMenuItem = new ToolStripMenuItem();
+ ShipsToolStripMenuItem = new ToolStripMenuItem();
+ ComponentsToolStripMenuItem = new ToolStripMenuItem();
+ ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
+ menuStrip1.SuspendLayout();
+ SuspendLayout();
+ //
+ // dataGridView
+ //
+ dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ dataGridView.Location = new Point(0, 117);
+ dataGridView.Name = "dataGridView";
+ dataGridView.RowHeadersWidth = 51;
+ dataGridView.RowTemplate.Height = 29;
+ dataGridView.Size = new Size(1000, 387);
+ dataGridView.TabIndex = 0;
+ //
+ // ShipId
+ //
+ ShipId.MinimumWidth = 6;
+ ShipId.Name = "ShipId";
+ ShipId.Width = 125;
+ //
+ // ButtonRef
+ //
+ ButtonRef.Location = new Point(1079, 429);
+ ButtonRef.Name = "ButtonRef";
+ ButtonRef.Size = new Size(94, 34);
+ ButtonRef.TabIndex = 3;
+ ButtonRef.Text = "обновить";
+ ButtonRef.UseVisualStyleBackColor = true;
+ ButtonRef.Click += ButtonRef_Click;
+ //
+ // ButtonCreateOrder
+ //
+ ButtonCreateOrder.Location = new Point(1027, 94);
+ ButtonCreateOrder.Name = "ButtonCreateOrder";
+ ButtonCreateOrder.Size = new Size(146, 43);
+ ButtonCreateOrder.TabIndex = 5;
+ ButtonCreateOrder.Text = "создать";
+ ButtonCreateOrder.UseVisualStyleBackColor = true;
+ ButtonCreateOrder.Click += ButtonCreateOrder_Click;
+ //
+ // ButtonTakeOrderInWork
+ //
+ ButtonTakeOrderInWork.Location = new Point(1027, 143);
+ ButtonTakeOrderInWork.Name = "ButtonTakeOrderInWork";
+ ButtonTakeOrderInWork.Size = new Size(146, 47);
+ ButtonTakeOrderInWork.TabIndex = 6;
+ ButtonTakeOrderInWork.Text = "выполняется";
+ ButtonTakeOrderInWork.UseVisualStyleBackColor = true;
+ ButtonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click;
+ //
+ // ButtonOrderReady
+ //
+ ButtonOrderReady.Location = new Point(1027, 196);
+ ButtonOrderReady.Name = "ButtonOrderReady";
+ ButtonOrderReady.Size = new Size(146, 36);
+ ButtonOrderReady.TabIndex = 7;
+ ButtonOrderReady.Text = "заказ готов";
+ ButtonOrderReady.UseVisualStyleBackColor = true;
+ ButtonOrderReady.Click += ButtonOrderReady_Click;
+ //
+ // ButtonIssuedOrder
+ //
+ ButtonIssuedOrder.Location = new Point(1027, 238);
+ ButtonIssuedOrder.Name = "ButtonIssuedOrder";
+ ButtonIssuedOrder.Size = new Size(146, 35);
+ ButtonIssuedOrder.TabIndex = 8;
+ ButtonIssuedOrder.Text = "заказ отдан";
+ ButtonIssuedOrder.UseVisualStyleBackColor = true;
+ ButtonIssuedOrder.Click += ButtonIssuedOrder_Click;
+ //
+ // menuStrip1
+ //
+ menuStrip1.ImageScalingSize = new Size(20, 20);
+ menuStrip1.Items.AddRange(new ToolStripItem[] { ReportstoolStrip, GuidesToolStripMenuItem });
+ menuStrip1.Location = new Point(0, 0);
+ menuStrip1.Name = "menuStrip1";
+ menuStrip1.Size = new Size(1185, 28);
+ menuStrip1.TabIndex = 10;
+ menuStrip1.Text = "menuStrip1";
+ //
+ // ReportstoolStrip
+ //
+ ReportstoolStrip.DropDownItems.AddRange(new ToolStripItem[] { ComponentListToolStripMenuItem, ComponentsShipToolStripMenuItem, OrderListToolStripMenuItem });
+ ReportstoolStrip.Name = "ReportstoolStrip";
+ ReportstoolStrip.Size = new Size(71, 24);
+ ReportstoolStrip.Text = "отчеты";
+ //
+ // ComponentListToolStripMenuItem
+ //
+ ComponentListToolStripMenuItem.Name = "ComponentListToolStripMenuItem";
+ ComponentListToolStripMenuItem.Size = new Size(275, 26);
+ ComponentListToolStripMenuItem.Text = "список кораблей";
+ ComponentListToolStripMenuItem.Click += ComponentListToolStripMenuItem_Click;
+ //
+ // ComponentsShipToolStripMenuItem
+ //
+ ComponentsShipToolStripMenuItem.Name = "ComponentsShipToolStripMenuItem";
+ ComponentsShipToolStripMenuItem.Size = new Size(275, 26);
+ ComponentsShipToolStripMenuItem.Text = "компоненты по кораблям";
+ ComponentsShipToolStripMenuItem.Click += ComponentsShipToolStripMenuItem_Click;
+ //
+ // OrderListToolStripMenuItem
+ //
+ OrderListToolStripMenuItem.Name = "OrderListToolStripMenuItem";
+ OrderListToolStripMenuItem.Size = new Size(275, 26);
+ OrderListToolStripMenuItem.Text = "список заказов";
+ OrderListToolStripMenuItem.Click += OrderListToolStripMenuItem_Click;
+ //
+ // GuidesToolStripMenuItem
+ //
+ GuidesToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ShipsToolStripMenuItem, ComponentsToolStripMenuItem });
+ GuidesToolStripMenuItem.Name = "GuidesToolStripMenuItem";
+ GuidesToolStripMenuItem.Size = new Size(115, 24);
+ GuidesToolStripMenuItem.Text = "справочники";
+ //
+ // ShipsToolStripMenuItem
+ //
+ ShipsToolStripMenuItem.Name = "ShipsToolStripMenuItem";
+ ShipsToolStripMenuItem.Size = new Size(224, 26);
+ ShipsToolStripMenuItem.Text = "корабли";
+ ShipsToolStripMenuItem.Click += ShipsToolStripMenuItem_Click;
+ //
+ // ComponentsToolStripMenuItem
+ //
+ ComponentsToolStripMenuItem.Name = "ComponentsToolStripMenuItem";
+ ComponentsToolStripMenuItem.Size = new Size(224, 26);
+ ComponentsToolStripMenuItem.Text = "компоненты";
+ ComponentsToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click;
+ //
+ // FormMain
+ //
+ AutoScaleDimensions = new SizeF(8F, 20F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(1185, 516);
+ Controls.Add(ButtonIssuedOrder);
+ Controls.Add(ButtonOrderReady);
+ Controls.Add(ButtonTakeOrderInWork);
+ Controls.Add(ButtonCreateOrder);
+ Controls.Add(ButtonRef);
+ Controls.Add(menuStrip1);
+ Controls.Add(dataGridView);
+ Name = "FormMain";
+ Text = "FormMain";
+ Load += FormMain_Load;
+ ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
+ menuStrip1.ResumeLayout(false);
+ menuStrip1.PerformLayout();
+ ResumeLayout(false);
+ PerformLayout();
+ }
+
+ #endregion
+
+ private DataGridView dataGridView;
+ private Button ButtonRef;
+ private Button ButtonCreateOrder;
+ private Button ButtonTakeOrderInWork;
+ private Button ButtonOrderReady;
+ private Button ButtonIssuedOrder;
+ private DataGridViewTextBoxColumn ShipId;
+ private MenuStrip menuStrip1;
+ private ToolStripMenuItem ReportstoolStrip;
+ private ToolStripMenuItem ComponentListToolStripMenuItem;
+ private ToolStripMenuItem ComponentsShipToolStripMenuItem;
+ private ToolStripMenuItem OrderListToolStripMenuItem;
+ private ToolStripMenuItem GuidesToolStripMenuItem;
+ private ToolStripMenuItem ShipsToolStripMenuItem;
+ private ToolStripMenuItem ComponentsToolStripMenuItem;
+ }
+}
\ No newline at end of file
diff --git a/ShipyardView/FormMain.cs b/ShipyardView/FormMain.cs
index ada1fa0..fbfa087 100644
--- a/ShipyardView/FormMain.cs
+++ b/ShipyardView/FormMain.cs
@@ -1,5 +1,6 @@
using Microsoft.Extensions.Logging;
using ShipyardContracts.BindingModels;
+using ShipyardContracts.BusinessLogicContracts;
using ShipyardContracts.BusinessLogicsContracts;
using ShipyardDataModels.Enums;
using ShipyardView;
@@ -11,11 +12,13 @@ namespace ShipyardView
{
private readonly ILogger _logger;
private readonly IOrderLogic _orderLogic;
- public FormMain(ILogger logger, IOrderLogic orderLogic)
+ private readonly IReportLogic _reportLogic;
+ public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic)
{
InitializeComponent();
_logger = logger;
_orderLogic = orderLogic;
+ _reportLogic = reportLogic;
}
private void FormMain_Load(object sender, EventArgs e)
{
@@ -161,9 +164,36 @@ namespace ShipyardView
};
}
- private void shipToolStripMenuItem_Click(object sender, EventArgs e)
+ private void ComponentListToolStripMenuItem_Click(object sender, EventArgs e)
{
+ using var dialog = new SaveFileDialog { Filter = "docx|*.docx" };
+ if (dialog.ShowDialog() == DialogResult.OK)
+ {
+ _reportLogic.SaveShipsToWordFile(new ReportBindingModel
+ {
+ FileName = dialog.FileName
+ });
+ MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK,
+ MessageBoxIcon.Information);
+ }
+ }
+ private void ComponentsShipToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormReportShipComponents));
+ if (service is FormReportShipComponents form)
+ {
+ form.ShowDialog();
+ }
+ }
+
+ private void OrderListToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders));
+ if (service is FormReportOrders form)
+ {
+ form.ShowDialog();
+ }
}
}
}
\ No newline at end of file
diff --git a/ShipyardView/FormReportOrders.Designer.cs b/ShipyardView/FormReportOrders.Designer.cs
new file mode 100644
index 0000000..2ab61ed
--- /dev/null
+++ b/ShipyardView/FormReportOrders.Designer.cs
@@ -0,0 +1,102 @@
+namespace ShipyardView
+{
+ partial class FormReportOrders
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ panelReport = new Panel();
+ buttonToPDF = new Button();
+ MakeButton = new Button();
+ dateTimePickerTo = new DateTimePicker();
+ dateTimePickerFrom = new DateTimePicker();
+ SuspendLayout();
+ //
+ // panelReport
+ //
+ panelReport.Location = new Point(12, 80);
+ panelReport.Name = "panelReport";
+ panelReport.Size = new Size(944, 394);
+ panelReport.TabIndex = 0;
+ //
+ // buttonToPDF
+ //
+ buttonToPDF.Location = new Point(785, 38);
+ buttonToPDF.Name = "buttonToPDF";
+ buttonToPDF.Size = new Size(94, 29);
+ buttonToPDF.TabIndex = 3;
+ buttonToPDF.Text = "в PDF";
+ buttonToPDF.UseVisualStyleBackColor = true;
+ buttonToPDF.Click += ButtonToPdf_Click;
+ //
+ // MakeButton
+ //
+ MakeButton.Location = new Point(581, 30);
+ MakeButton.Name = "MakeButton";
+ MakeButton.Size = new Size(122, 44);
+ MakeButton.TabIndex = 2;
+ MakeButton.Text = "сформировать";
+ MakeButton.UseVisualStyleBackColor = true;
+ MakeButton.Click += MakeButton_Click;
+ //
+ // dateTimePickerTo
+ //
+ dateTimePickerTo.Location = new Point(287, 37);
+ dateTimePickerTo.Name = "dateTimePickerTo";
+ dateTimePickerTo.Size = new Size(250, 27);
+ dateTimePickerTo.TabIndex = 1;
+ //
+ // dateTimePickerFrom
+ //
+ dateTimePickerFrom.Location = new Point(12, 37);
+ dateTimePickerFrom.Name = "dateTimePickerFrom";
+ dateTimePickerFrom.Size = new Size(250, 27);
+ dateTimePickerFrom.TabIndex = 0;
+ //
+ // FormReportOrders
+ //
+ AutoScaleDimensions = new SizeF(8F, 20F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(968, 486);
+ Controls.Add(buttonToPDF);
+ Controls.Add(MakeButton);
+ Controls.Add(dateTimePickerFrom);
+ Controls.Add(dateTimePickerTo);
+ Controls.Add(panelReport);
+ Name = "FormReportOrders";
+ Text = "FormReportOrders";
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private Panel panelReport;
+ private DateTimePicker dateTimePickerTo;
+ private DateTimePicker dateTimePickerFrom;
+ private Button buttonToPDF;
+ private Button MakeButton;
+ }
+}
\ No newline at end of file
diff --git a/ShipyardView/FormReportOrders.cs b/ShipyardView/FormReportOrders.cs
new file mode 100644
index 0000000..5df64f9
--- /dev/null
+++ b/ShipyardView/FormReportOrders.cs
@@ -0,0 +1,92 @@
+using Microsoft.Extensions.Logging;
+using ShipyardContracts.BindingModels;
+using ShipyardContracts.BusinessLogicContracts;
+using Microsoft.Reporting.WinForms;
+
+namespace ShipyardView
+{
+ public partial class FormReportOrders : Form
+ {
+ private readonly ReportViewer reportViewer;
+ private readonly ILogger _logger;
+ private readonly IReportLogic _logic;
+ public FormReportOrders(ILogger logger, IReportLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = logic;
+ reportViewer = new ReportViewer
+ {
+ Dock = DockStyle.Fill
+ };
+ reportViewer.LocalReport.LoadReportDefinition(new FileStream("ReportOrder.rdlc", FileMode.Open));
+ panelReport.Controls.Add(reportViewer);
+ }
+
+ private void MakeButton_Click(object sender, EventArgs e)
+ {
+ if (dateTimePickerFrom.Value.Date >= dateTimePickerTo.Value.Date)
+ {
+ MessageBox.Show("Дата начала должна быть меньше даты окончания",
+ "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ try
+ {
+ var dataSource = _logic.GetOrders(new ReportBindingModel
+ {
+ DateFrom = dateTimePickerFrom.Value,
+ DateTo = dateTimePickerTo.Value
+ });
+ var source = new ReportDataSource("DataSetOrders", dataSource);
+ reportViewer.LocalReport.DataSources.Clear();
+ reportViewer.LocalReport.DataSources.Add(source);
+ var parameters = new[] { new ReportParameter("ReportParameterPeriod", $"c {dateTimePickerFrom.Value.ToShortDateString()} по {dateTimePickerTo.Value.ToShortDateString()}") };
+ reportViewer.LocalReport.SetParameters(parameters);
+ reportViewer.RefreshReport();
+ _logger.LogInformation("Загрузка списка заказов на период {From}-{ To}", dateTimePickerFrom.Value.ToShortDateString(),
+ dateTimePickerTo.Value.ToShortDateString());
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки списка заказов на период");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void ButtonToPdf_Click(object sender, EventArgs e)
+ {
+ if (dateTimePickerFrom.Value.Date >= dateTimePickerTo.Value.Date)
+ {
+ MessageBox.Show("Дата начала должна быть меньше даты окончания",
+ "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ using var dialog = new SaveFileDialog
+ {
+ Filter = "pdf|*.pdf"
+ };
+ if (dialog.ShowDialog() == DialogResult.OK)
+ {
+ try
+ {
+ _logic.SaveOrdersToPdfFile(new ReportBindingModel
+ {
+ FileName = dialog.FileName,
+ DateFrom = dateTimePickerFrom.Value,
+ DateTo = dateTimePickerTo.Value
+ });
+ _logger.LogInformation("Сохранение списка заказов на период { From}-{ To}", dateTimePickerFrom.Value.ToShortDateString(),
+ dateTimePickerTo.Value.ToShortDateString());
+ MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка сохранения списка заказов на период");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+
+ }
+}
diff --git a/ShipyardView/FormReportShipComponents.Designer.cs b/ShipyardView/FormReportShipComponents.Designer.cs
new file mode 100644
index 0000000..d6cd552
--- /dev/null
+++ b/ShipyardView/FormReportShipComponents.Designer.cs
@@ -0,0 +1,101 @@
+namespace ShipyardView
+{
+ partial class FormReportShipComponents
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ dataGridView = new DataGridView();
+ ComponentColumn = new DataGridViewTextBoxColumn();
+ ShipColumn = new DataGridViewTextBoxColumn();
+ CountColumn = new DataGridViewTextBoxColumn();
+ buttonSave = new Button();
+ ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
+ SuspendLayout();
+ //
+ // dataGridView
+ //
+ dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
+ dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ dataGridView.Columns.AddRange(new DataGridViewColumn[] { ComponentColumn, ShipColumn, CountColumn });
+ dataGridView.Location = new Point(12, 93);
+ dataGridView.Name = "dataGridView";
+ dataGridView.RowHeadersWidth = 51;
+ dataGridView.RowTemplate.Height = 29;
+ dataGridView.Size = new Size(908, 343);
+ dataGridView.TabIndex = 0;
+ //
+ // ComponentColumn
+ //
+ ComponentColumn.HeaderText = "компонент";
+ ComponentColumn.MinimumWidth = 6;
+ ComponentColumn.Name = "ComponentColumn";
+ //
+ // ShipColumn
+ //
+ ShipColumn.HeaderText = "корабль";
+ ShipColumn.MinimumWidth = 6;
+ ShipColumn.Name = "ShipColumn";
+ //
+ // CountColumn
+ //
+ CountColumn.HeaderText = "количество";
+ CountColumn.MinimumWidth = 6;
+ CountColumn.Name = "CountColumn";
+ //
+ // buttonSave
+ //
+ buttonSave.Location = new Point(352, 12);
+ buttonSave.Name = "buttonSave";
+ buttonSave.Size = new Size(189, 46);
+ buttonSave.TabIndex = 1;
+ buttonSave.Text = "сохранить в excel";
+ buttonSave.UseVisualStyleBackColor = true;
+ buttonSave.Click += SaveButton_Click;
+ //
+ // FormReportShipComponents
+ //
+ AutoScaleDimensions = new SizeF(8F, 20F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(932, 464);
+ Controls.Add(buttonSave);
+ Controls.Add(dataGridView);
+ Name = "FormReportShipComponents";
+ Text = "FormReportShipComponents";
+ Load += FormReportShipComponents_Load;
+ ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private DataGridView dataGridView;
+ private Button buttonSave;
+ private DataGridViewTextBoxColumn ComponentColumn;
+ private DataGridViewTextBoxColumn ShipColumn;
+ private DataGridViewTextBoxColumn CountColumn;
+ }
+}
\ No newline at end of file
diff --git a/ShipyardView/FormReportShipComponents.cs b/ShipyardView/FormReportShipComponents.cs
new file mode 100644
index 0000000..5c4f7d1
--- /dev/null
+++ b/ShipyardView/FormReportShipComponents.cs
@@ -0,0 +1,84 @@
+using Microsoft.Extensions.Logging;
+using ShipyardContracts.BindingModels;
+using ShipyardContracts.BusinessLogicContracts;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace ShipyardView
+{
+ public partial class FormReportShipComponents : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IReportLogic _logic;
+ public FormReportShipComponents(
+ ILogger logger, IReportLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = logic;
+
+ }
+
+ private void SaveButton_Click(object sender, EventArgs e)
+ {
+ using var dialog = new SaveFileDialog
+ {
+ Filter = "xlsx|*.xlsx"
+ };
+ if (dialog.ShowDialog() == DialogResult.OK)
+ {
+ try
+ {
+ _logic.SaveShipComponentToExcelFile(
+ new ReportBindingModel
+ {
+ FileName = dialog.FileName
+ });
+ _logger.LogInformation("Сохранение списка компьютеров по компонентам");
+ MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка сохранения списка компьютеров по компонентам");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+
+ private void FormReportShipComponents_Load(object sender, EventArgs e)
+ {
+ try
+ {
+ var dict = _logic.GetShipComponent();
+ if (dict != null)
+ {
+ dataGridView.Rows.Clear();
+ foreach (var elem in dict)
+ {
+ dataGridView.Rows.Add(new object[] { elem.ShipName, "", "" });
+ foreach (var listElem in elem.Components)
+ {
+ dataGridView.Rows.Add(new object[] { "", listElem.Item1, listElem.Item2 });
+ }
+ dataGridView.Rows.Add(new object[] { "Итого", "", elem.TotalCount });
+ dataGridView.Rows.Add(Array.Empty | | |