Merge pull request 'Update BusinessLogic and some storages' (#1) from LogicImplementer into main
Reviewed-on: #1
This commit is contained in:
commit
1d49b42cd6
@ -7,7 +7,9 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="DocumentFormat.OpenXml" Version="3.0.2" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
|
||||||
|
<PackageReference Include="PDFsharp-MigraDoc" Version="6.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
84
Course/BusinessLogic/OfficePackage/AbstractSaveToExcel.cs
Normal file
84
Course/BusinessLogic/OfficePackage/AbstractSaveToExcel.cs
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
using BusinessLogic.OfficePackage.HelperEnums;
|
||||||
|
using BusinessLogic.OfficePackage.HelperModels;
|
||||||
|
|
||||||
|
namespace BusinessLogic.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.DressComponents)
|
||||||
|
{
|
||||||
|
InsertCellInWorksheet(new ExcelCellParameters
|
||||||
|
{
|
||||||
|
ColumnName = "A",
|
||||||
|
RowIndex = rowIndex,
|
||||||
|
Text = pc.DressName,
|
||||||
|
StyleInfo = ExcelStyleInfoType.Text
|
||||||
|
});
|
||||||
|
rowIndex++;
|
||||||
|
|
||||||
|
foreach (var (Dress, Count) in pc.Components)
|
||||||
|
{
|
||||||
|
InsertCellInWorksheet(new ExcelCellParameters
|
||||||
|
{
|
||||||
|
ColumnName = "B",
|
||||||
|
RowIndex = rowIndex,
|
||||||
|
Text = Dress,
|
||||||
|
StyleInfo = ExcelStyleInfoType.TextWithBorder
|
||||||
|
});
|
||||||
|
|
||||||
|
InsertCellInWorksheet(new ExcelCellParameters
|
||||||
|
{
|
||||||
|
ColumnName = "C",
|
||||||
|
RowIndex = rowIndex,
|
||||||
|
Text = Count.ToString(),
|
||||||
|
StyleInfo = ExcelStyleInfoType.TextWithBorder
|
||||||
|
});
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void CreateExcel(ExcelInfo info);
|
||||||
|
protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams);
|
||||||
|
protected abstract void MergeCells(ExcelMergeParameters excelParams);
|
||||||
|
protected abstract void SaveExcel(ExcelInfo info);
|
||||||
|
}
|
||||||
|
}
|
48
Course/BusinessLogic/OfficePackage/AbstractSaveToPdf.cs
Normal file
48
Course/BusinessLogic/OfficePackage/AbstractSaveToPdf.cs
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
using BusinessLogic.OfficePackage.HelperEnums;
|
||||||
|
using BusinessLogic.OfficePackage.HelperModels;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace BusinessLogic.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<string> { "2cm", "3cm", "6cm", "4cm", "3cm" });
|
||||||
|
|
||||||
|
CreateRow(new PdfRowParameters
|
||||||
|
{
|
||||||
|
Texts = new List<string> { "Номер", "Дата заказа", "Изделие", "Статус", "Сумма" },
|
||||||
|
Style = "NormalTitle",
|
||||||
|
ParagraphAlignment = PdfParagraphAlignmentType.Center
|
||||||
|
});
|
||||||
|
|
||||||
|
/* foreach (var order in info.Orders)
|
||||||
|
{
|
||||||
|
CreateRow(new PdfRowParameters
|
||||||
|
{
|
||||||
|
Texts = new List<string> { order.Id.ToString(), order.DateCreate.ToShortDateString(), order.DressName, order.Status.ToString(), order.Sum.ToString() },
|
||||||
|
Style = "Normal",
|
||||||
|
ParagraphAlignment = PdfParagraphAlignmentType.Left
|
||||||
|
});
|
||||||
|
}
|
||||||
|
CreateParagraph(new PdfParagraph { Text = $"Итого: {info.Orders.Sum(x => x.Sum)}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Right });
|
||||||
|
*/
|
||||||
|
SavePdf(info);
|
||||||
|
}
|
||||||
|
protected abstract void CreatePdf(PdfInfo info);
|
||||||
|
|
||||||
|
protected abstract void CreateParagraph(PdfParagraph paragraph);
|
||||||
|
|
||||||
|
protected abstract void CreateTable(List<string> columns);
|
||||||
|
|
||||||
|
protected abstract void CreateRow(PdfRowParameters rowParameters);
|
||||||
|
|
||||||
|
protected abstract void SavePdf(PdfInfo info);
|
||||||
|
}
|
||||||
|
}
|
46
Course/BusinessLogic/OfficePackage/AbstractSaveToWord.cs
Normal file
46
Course/BusinessLogic/OfficePackage/AbstractSaveToWord.cs
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
using BusinessLogic.OfficePackage.HelperEnums;
|
||||||
|
using BusinessLogic.OfficePackage.HelperModels;
|
||||||
|
|
||||||
|
namespace BusinessLogic.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.Both
|
||||||
|
}
|
||||||
|
});
|
||||||
|
/*foreach (var dress in info.Dresses)
|
||||||
|
{
|
||||||
|
CreateParagraph(new WordParagraph
|
||||||
|
{
|
||||||
|
Texts = new List<(string, WordTextProperties)>
|
||||||
|
{
|
||||||
|
($"{dress.DressName} - ", new WordTextProperties { Size = "24", Bold = true}),
|
||||||
|
(dress.Price.ToString(), new WordTextProperties { Size = "24" })
|
||||||
|
},
|
||||||
|
TextProperties = new WordTextProperties
|
||||||
|
{
|
||||||
|
Size = "24",
|
||||||
|
JustificationType = WordJustificationType.Both
|
||||||
|
}
|
||||||
|
}) ;
|
||||||
|
|
||||||
|
}*/
|
||||||
|
SaveWord(info);
|
||||||
|
}
|
||||||
|
protected abstract void CreateWord(WordInfo info);
|
||||||
|
protected abstract void CreateParagraph(WordParagraph paragraph);
|
||||||
|
protected abstract void SaveWord(WordInfo info);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
|
||||||
|
namespace BusinessLogic.OfficePackage.HelperEnums
|
||||||
|
{
|
||||||
|
public enum ExcelStyleInfoType
|
||||||
|
{
|
||||||
|
Title,
|
||||||
|
Text,
|
||||||
|
TextWithBorder
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
namespace BusinessLogic.OfficePackage.HelperEnums
|
||||||
|
{
|
||||||
|
public enum PdfParagraphAlignmentType
|
||||||
|
{
|
||||||
|
Center,
|
||||||
|
Left,
|
||||||
|
Right
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
namespace BusinessLogic.OfficePackage.HelperEnums
|
||||||
|
{
|
||||||
|
public enum WordJustificationType
|
||||||
|
{
|
||||||
|
Center,
|
||||||
|
Both
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
|
||||||
|
using BusinessLogic.OfficePackage.HelperEnums;
|
||||||
|
|
||||||
|
namespace BusinessLogic.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; }
|
||||||
|
}
|
||||||
|
}
|
11
Course/BusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs
Normal file
11
Course/BusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
using Contracts.ViewModels;
|
||||||
|
|
||||||
|
namespace BusinessLogic.OfficePackage.HelperModels
|
||||||
|
{
|
||||||
|
public class ExcelInfo
|
||||||
|
{
|
||||||
|
public string FileName { get; set; } = string.Empty;
|
||||||
|
public string Title { get; set; } = string.Empty;
|
||||||
|
//public List<ReportDressComponentViewModel> DressComponents { get; set; } = new();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
|
||||||
|
namespace BusinessLogic.OfficePackage.HelperModels
|
||||||
|
{
|
||||||
|
public class ExcelMergeParameters
|
||||||
|
{
|
||||||
|
public string CellFromName { get; set; } = string.Empty;
|
||||||
|
public string CellToName { get; set; } = string.Empty;
|
||||||
|
public string Merge => $"{CellFromName}:{CellToName}";
|
||||||
|
}
|
||||||
|
}
|
13
Course/BusinessLogic/OfficePackage/HelperModels/PdfInfo.cs
Normal file
13
Course/BusinessLogic/OfficePackage/HelperModels/PdfInfo.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using Contracts.ViewModels;
|
||||||
|
|
||||||
|
namespace BusinessLogic.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<ReportOrdersViewModel> Orders { get; set; } = new();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
using BusinessLogic.OfficePackage.HelperEnums;
|
||||||
|
|
||||||
|
namespace BusinessLogic.OfficePackage.HelperModels
|
||||||
|
{
|
||||||
|
public class PdfParagraph
|
||||||
|
{
|
||||||
|
public string Text { get; set; } = string.Empty;
|
||||||
|
public string Style { get; set; } = string.Empty;
|
||||||
|
public PdfParagraphAlignmentType ParagraphAlignment { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
using BusinessLogic.OfficePackage.HelperEnums;
|
||||||
|
|
||||||
|
namespace BusinessLogic.OfficePackage.HelperModels
|
||||||
|
{
|
||||||
|
public class PdfRowParameters
|
||||||
|
{
|
||||||
|
public List<string> Texts { get; set; } = new();
|
||||||
|
public string Style { get; set; } = string.Empty;
|
||||||
|
public PdfParagraphAlignmentType ParagraphAlignment { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
namespace BusinessLogic.OfficePackage.HelperModels
|
||||||
|
{
|
||||||
|
public class WordInfo
|
||||||
|
{
|
||||||
|
public string FileName { get; set; } = string.Empty;
|
||||||
|
public string Title { get; set; } = string.Empty;
|
||||||
|
//public List<DressViewModel> Dresses { get; set; } = new();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
|
||||||
|
namespace BusinessLogic.OfficePackage.HelperModels
|
||||||
|
{
|
||||||
|
public class WordParagraph
|
||||||
|
{
|
||||||
|
public List<(string, WordTextProperties)> Texts { get; set; } = new();
|
||||||
|
public WordTextProperties? TextProperties { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
using BusinessLogic.OfficePackage.HelperEnums;
|
||||||
|
|
||||||
|
namespace BusinessLogic.OfficePackage.HelperModels
|
||||||
|
{
|
||||||
|
public class WordTextProperties
|
||||||
|
{
|
||||||
|
public string Size { get; set; } = string.Empty;
|
||||||
|
public bool Bold { get; set; }
|
||||||
|
public WordJustificationType JustificationType { get; set; }
|
||||||
|
}
|
||||||
|
}
|
283
Course/BusinessLogic/OfficePackage/Implements/SaveToExcel.cs
Normal file
283
Course/BusinessLogic/OfficePackage/Implements/SaveToExcel.cs
Normal file
@ -0,0 +1,283 @@
|
|||||||
|
using BusinessLogic.OfficePackage.HelperModels;
|
||||||
|
using BusinessLogic.OfficePackage.HelperEnums;
|
||||||
|
using DocumentFormat.OpenXml.Office2010.Excel;
|
||||||
|
using DocumentFormat.OpenXml.Office2013.Excel;
|
||||||
|
using DocumentFormat.OpenXml.Packaging;
|
||||||
|
using DocumentFormat.OpenXml.Spreadsheet;
|
||||||
|
using DocumentFormat.OpenXml;
|
||||||
|
|
||||||
|
namespace BusinessLogic.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<WorkbookStylesPart>();
|
||||||
|
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.TextWithBorder => 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<SharedStringTablePart>().Any()
|
||||||
|
? _spreadsheetDocument.WorkbookPart.GetPartsOfType<SharedStringTablePart>().First()
|
||||||
|
: _spreadsheetDocument.WorkbookPart.AddNewPart<SharedStringTablePart>();
|
||||||
|
|
||||||
|
// Создаем SharedStringTable, если его нет
|
||||||
|
if (_shareStringPart.SharedStringTable == null)
|
||||||
|
{
|
||||||
|
_shareStringPart.SharedStringTable = new SharedStringTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Создаем лист в книгу
|
||||||
|
var worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
|
||||||
|
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<SheetData>();
|
||||||
|
if (sheetData == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ищем строку, либо добавляем ее
|
||||||
|
Row row;
|
||||||
|
if (sheetData.Elements<Row>().Where(r => r.RowIndex! == excelParams.RowIndex).Any())
|
||||||
|
{
|
||||||
|
row = sheetData.Elements<Row>().Where(r => r.RowIndex! == excelParams.RowIndex).First();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
row = new Row() { RowIndex = excelParams.RowIndex };
|
||||||
|
sheetData.Append(row);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ищем нужную ячейку
|
||||||
|
Cell cell;
|
||||||
|
if (row.Elements<Cell>().Where(c => c.CellReference!.Value == excelParams.CellReference).Any())
|
||||||
|
{
|
||||||
|
cell = row.Elements<Cell>().Where(c => c.CellReference!.Value == excelParams.CellReference).First();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Все ячейки должны быть последовательно друг за другом расположены
|
||||||
|
// нужно определить, после какой вставлять
|
||||||
|
Cell? refCell = null;
|
||||||
|
foreach (Cell rowCell in row.Elements<Cell>())
|
||||||
|
{
|
||||||
|
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<SharedStringItem>().Count() - 1).ToString());
|
||||||
|
cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);
|
||||||
|
cell.StyleIndex = GetStyleValue(excelParams.StyleInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void MergeCells(ExcelMergeParameters excelParams)
|
||||||
|
{
|
||||||
|
if (_worksheet == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MergeCells mergeCells;
|
||||||
|
|
||||||
|
if (_worksheet.Elements<MergeCells>().Any())
|
||||||
|
{
|
||||||
|
mergeCells = _worksheet.Elements<MergeCells>().First();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mergeCells = new MergeCells();
|
||||||
|
|
||||||
|
if (_worksheet.Elements<CustomSheetView>().Any())
|
||||||
|
{
|
||||||
|
_worksheet.InsertAfter(mergeCells, _worksheet.Elements<CustomSheetView>().First());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_worksheet.InsertAfter(mergeCells, _worksheet.Elements<SheetData>().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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
114
Course/BusinessLogic/OfficePackage/Implements/SaveToPdf.cs
Normal file
114
Course/BusinessLogic/OfficePackage/Implements/SaveToPdf.cs
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
using BusinessLogic.OfficePackage.HelperEnums;
|
||||||
|
using BusinessLogic.OfficePackage.HelperModels;
|
||||||
|
using MigraDoc.DocumentObjectModel;
|
||||||
|
using MigraDoc.DocumentObjectModel.Tables;
|
||||||
|
using MigraDoc.Rendering;
|
||||||
|
|
||||||
|
namespace BusinessLogic.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,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Создание стилей для документа
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="document"></param>
|
||||||
|
private static void DefineStyles(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 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<string> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
121
Course/BusinessLogic/OfficePackage/Implements/SaveToWord.cs
Normal file
121
Course/BusinessLogic/OfficePackage/Implements/SaveToWord.cs
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
using BusinessLogic.OfficePackage.HelperEnums;
|
||||||
|
using BusinessLogic.OfficePackage.HelperModels;
|
||||||
|
using DocumentFormat.OpenXml;
|
||||||
|
using DocumentFormat.OpenXml.Packaging;
|
||||||
|
using DocumentFormat.OpenXml.Wordprocessing;
|
||||||
|
|
||||||
|
namespace BusinessLogic.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 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -10,5 +10,6 @@ namespace Contracts.SearchModels
|
|||||||
{
|
{
|
||||||
public int? Id { get; set; }
|
public int? Id { get; set; }
|
||||||
public string? Login { get; set; }
|
public string? Login { get; set; }
|
||||||
|
public string? Password { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ namespace Contracts.ViewModels
|
|||||||
public double Cost { get; set; }
|
public double Cost { get; set; }
|
||||||
public int UserId { get; set; }
|
public int UserId { get; set; }
|
||||||
public int? MachineId { get; set; }
|
public int? MachineId { get; set; }
|
||||||
|
public string? MachineName { get; set; }
|
||||||
public Dictionary<int, (IDetailModel, int)> DetailProducts { get; set; } = new();
|
public Dictionary<int, (IDetailModel, int)> DetailProducts { get; set; } = new();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="log4net" Version="2.0.17" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.29" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.29" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.29" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.29" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.29">
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.29">
|
||||||
|
@ -22,7 +22,7 @@ namespace DatabaseImplement.Implements
|
|||||||
public DetailViewModel? GetElement(DetailSearchModel model)
|
public DetailViewModel? GetElement(DetailSearchModel model)
|
||||||
{
|
{
|
||||||
using var context = new FactoryGoWorkDatabase();
|
using var context = new FactoryGoWorkDatabase();
|
||||||
return context.Details.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name.Contains(model.Name)) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
return context.Details.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name.Equals(model.Name)) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<DetailViewModel> GetFilteredList(DetailSearchModel model)
|
public List<DetailViewModel> GetFilteredList(DetailSearchModel model)
|
||||||
@ -33,9 +33,9 @@ namespace DatabaseImplement.Implements
|
|||||||
}
|
}
|
||||||
using var context = new FactoryGoWorkDatabase();
|
using var context = new FactoryGoWorkDatabase();
|
||||||
if (model.DateFrom.HasValue)
|
if (model.DateFrom.HasValue)
|
||||||
return context.Details.Where(x => x.UserId == model.Id).Where(x => x.DateCreate < model.DateTo && x.DateCreate > model.DateFrom).Select(x => x.GetViewModel).ToList();
|
return context.Details.Where(x => x.UserId == model.UserId).Where(x => x.DateCreate <= model.DateTo && x.DateCreate >= model.DateFrom).Select(x => x.GetViewModel).ToList();
|
||||||
else
|
else
|
||||||
return context.Details.Where(x => x.UserId == model.Id).Select(x => x.GetViewModel).ToList();
|
return context.Details.Where(x => x.UserId == model.UserId).Select(x => x.GetViewModel).ToList();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ namespace DatabaseImplement.Implements
|
|||||||
{
|
{
|
||||||
if (!model.Id.HasValue && string.IsNullOrEmpty(model.Login)) { return null; }
|
if (!model.Id.HasValue && string.IsNullOrEmpty(model.Login)) { return null; }
|
||||||
using var context = new FactoryGoWorkDatabase();
|
using var context = new FactoryGoWorkDatabase();
|
||||||
return context.Implementers.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id) || (!string.IsNullOrEmpty(model.Login) && x.Login.Equals(model.Login)))?.GetViewModel; ;
|
return context.Implementers.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id) || (!string.IsNullOrEmpty(model.Login) && !string.IsNullOrEmpty(model.Password) && x.Login.Equals(model.Login) && x.Password.Equals(model.Password)))?.GetViewModel; ;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model)
|
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model)
|
||||||
|
@ -24,7 +24,7 @@ namespace DatabaseImplement.Implements
|
|||||||
public ProductViewModel? GetElement(ProductSearchModel model)
|
public ProductViewModel? GetElement(ProductSearchModel model)
|
||||||
{
|
{
|
||||||
using var context = new FactoryGoWorkDatabase();
|
using var context = new FactoryGoWorkDatabase();
|
||||||
return context.Products.Include(p => p.Details).ThenInclude(p => p.Detail).FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name.Contains(model.Name)) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
return context.Products.Include(p => p.Details).ThenInclude(p => p.Detail).Include(p => p.Machine).FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name.Contains(model.Name)) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ProductViewModel> GetFilteredList(ProductSearchModel model)
|
public List<ProductViewModel> GetFilteredList(ProductSearchModel model)
|
||||||
@ -35,11 +35,11 @@ namespace DatabaseImplement.Implements
|
|||||||
}
|
}
|
||||||
using var context = new FactoryGoWorkDatabase();
|
using var context = new FactoryGoWorkDatabase();
|
||||||
if (model.DetailId.HasValue)
|
if (model.DetailId.HasValue)
|
||||||
return context.Products.Include(p => p.Details).ThenInclude(p => p.Detail).Where(x => x.UserId == model.Id).Where(x => x.Details.FirstOrDefault(y => y.DetailId == model.DetailId) != null).Select(x => x.GetViewModel).ToList();
|
return context.Products.Include(p => p.Details).ThenInclude(p => p.Detail).Include(p => p.Machine).Where(x => x.UserId == model.UserId).Where(x => x.Details.FirstOrDefault(y => y.DetailId == model.DetailId) != null).Select(x => x.GetViewModel).ToList();
|
||||||
else if (model.WorkerId.HasValue)
|
else if (model.WorkerId.HasValue)
|
||||||
return context.Products.Where(p => p.MachineId.HasValue).Include(p => p.Machine).ThenInclude(p => p.Workers).Where(x => x.Machine.Workers.FirstOrDefault(y => y.WorkerId == model.WorkerId) != null).Select(x => x.GetViewModel).ToList();
|
return context.Products.Where(p => p.MachineId.HasValue).Include(p => p.Machine).ThenInclude(p => p.Workers).Where(x => x.Machine.Workers.FirstOrDefault(y => y.WorkerId == model.WorkerId) != null).Select(x => x.GetViewModel).ToList();
|
||||||
else
|
else
|
||||||
return context.Products.Include(p => p.Details).ThenInclude(p => p.Detail).Where(x => x.UserId == model.Id).Select(x => x.GetViewModel).ToList();
|
return context.Products.Include(p => p.Details).ThenInclude(p => p.Detail).Include(p => p.Machine).Where(x => x.UserId == model.UserId).Select(x => x.GetViewModel).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ProductViewModel> GetFullList()
|
public List<ProductViewModel> GetFullList()
|
||||||
|
@ -72,7 +72,7 @@ namespace DatabaseImplement.Models
|
|||||||
return;
|
return;
|
||||||
Name = model.Name;
|
Name = model.Name;
|
||||||
Cost = model.Cost;
|
Cost = model.Cost;
|
||||||
MachineId = model.MachineId;
|
MachineId = model.MachineId == null ? MachineId : model.MachineId;
|
||||||
}
|
}
|
||||||
public ProductViewModel GetViewModel => new()
|
public ProductViewModel GetViewModel => new()
|
||||||
{
|
{
|
||||||
@ -81,7 +81,8 @@ namespace DatabaseImplement.Models
|
|||||||
Cost = Cost,
|
Cost = Cost,
|
||||||
UserId = UserId,
|
UserId = UserId,
|
||||||
DetailProducts = DetailProducts,
|
DetailProducts = DetailProducts,
|
||||||
MachineId= MachineId
|
MachineId= MachineId,
|
||||||
|
MachineName = Machine == null ? null : Machine.Title
|
||||||
};
|
};
|
||||||
public void UpdateDetails(FactoryGoWorkDatabase context, ProductBindingModel model)
|
public void UpdateDetails(FactoryGoWorkDatabase context, ProductBindingModel model)
|
||||||
{
|
{
|
||||||
|
13
Course/ImplemenerLogic/DataToLogic.cs
Normal file
13
Course/ImplemenerLogic/DataToLogic.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using DatabaseImplement.Implements;
|
||||||
|
using BusinessLogic.BusinessLogic;
|
||||||
|
|
||||||
|
namespace ImplemenerLogic
|
||||||
|
{
|
||||||
|
public static class DataToLogic
|
||||||
|
{
|
||||||
|
public static DetailLogic detailLogic()
|
||||||
|
{
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
14
Course/ImplemenerLogic/ImplemenerLogic.csproj
Normal file
14
Course/ImplemenerLogic/ImplemenerLogic.csproj
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\BusinessLogic\BusinessLogic.csproj" />
|
||||||
|
<ProjectReference Include="..\DatabaseImplement\DatabaseImplement.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
@ -5,172 +5,299 @@ using BusinessLogic.BusinessLogic;
|
|||||||
using Contracts.BusinessLogicsContracts;
|
using Contracts.BusinessLogicsContracts;
|
||||||
using Contracts.ViewModels;
|
using Contracts.ViewModels;
|
||||||
using DataModels.Models;
|
using DataModels.Models;
|
||||||
|
using Contracts.BindingModels;
|
||||||
|
using DatabaseImplement.Models;
|
||||||
|
|
||||||
namespace ImplementerApp.Controllers
|
namespace ImplementerApp.Controllers
|
||||||
{
|
{
|
||||||
public class HomeController : Controller
|
public class HomeController : Controller
|
||||||
{
|
{
|
||||||
private readonly ILogger<HomeController> _logger;
|
private readonly ILogger<HomeController> _logger;
|
||||||
private readonly IDetailLogic _detailLogic;
|
private readonly ImplementerData _data;
|
||||||
private readonly IImplementerLogic _userLogic;
|
public HomeController(ILogger<HomeController> logger, ImplementerData data)
|
||||||
private readonly IProductLogic _productLogic;
|
|
||||||
private readonly IProductionLogic _productionLogic;
|
|
||||||
|
|
||||||
|
|
||||||
public HomeController(ILogger<HomeController> logger)
|
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
_data = data;
|
||||||
|
}
|
||||||
|
private bool IsLoggedIn { get {return UserImplementer.user != null; } }
|
||||||
|
private int UserId { get { return UserImplementer.user!.Id; } }
|
||||||
|
public IActionResult IndexNonReg()
|
||||||
|
{
|
||||||
|
if (!IsLoggedIn)
|
||||||
|
return View();
|
||||||
|
return RedirectToAction("Index");
|
||||||
}
|
}
|
||||||
|
|
||||||
public IActionResult Index()
|
public IActionResult Index()
|
||||||
{
|
{
|
||||||
|
if (!IsLoggedIn)
|
||||||
|
return RedirectToAction("IndexNonReg");
|
||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
|
[HttpGet]
|
||||||
public IActionResult Enter()
|
public IActionResult Enter()
|
||||||
{
|
{
|
||||||
|
if (!IsLoggedIn)
|
||||||
return View();
|
return View();
|
||||||
|
return RedirectToAction("Index");
|
||||||
}
|
}
|
||||||
|
[HttpPost]
|
||||||
|
public void Enter(string login, string password)
|
||||||
|
{
|
||||||
|
var user = _data.Login(login, password);
|
||||||
|
if (user != null)
|
||||||
|
{
|
||||||
|
UserImplementer.user = user;
|
||||||
|
Response.Redirect("Index");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpGet]
|
||||||
public IActionResult Register()
|
public IActionResult Register()
|
||||||
{
|
{
|
||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
|
public IActionResult Logout()
|
||||||
|
{
|
||||||
|
UserImplementer.user = null;
|
||||||
|
return RedirectToAction("IndexNonReg");
|
||||||
|
}
|
||||||
|
[HttpPost]
|
||||||
|
public void Register(string name, string login, string email, string password1, string password2)
|
||||||
|
{
|
||||||
|
if (password1 == password2 && _data.Register(new() { Email = email, Login = login, Name = name, Password = password1 }))
|
||||||
|
{
|
||||||
|
Response.Redirect("Index");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpGet]
|
||||||
public IActionResult IndexDetail()
|
public IActionResult IndexDetail()
|
||||||
{
|
{
|
||||||
var details = new List<DetailViewModel>();
|
if (UserImplementer.user != null)
|
||||||
details.Add(new DetailViewModel
|
|
||||||
{
|
{
|
||||||
Id = 1,
|
var list = _data.GetDetails(UserImplementer.user.Id);
|
||||||
Name = "Test",
|
if (list != null)
|
||||||
Cost = 55.5,
|
return View(list);
|
||||||
UserId = 1
|
return View(new List<DetailViewModel>());
|
||||||
});
|
|
||||||
details.Add(new DetailViewModel
|
|
||||||
{
|
|
||||||
Id = 2,
|
|
||||||
Name = "Test1",
|
|
||||||
Cost = 32,
|
|
||||||
UserId = 2
|
|
||||||
});
|
|
||||||
return View(details);
|
|
||||||
}
|
}
|
||||||
public IActionResult CreateDetail()
|
return RedirectToAction("IndexNonReg");
|
||||||
|
}
|
||||||
|
[HttpPost]
|
||||||
|
public void IndexDetail(int id)
|
||||||
{
|
{
|
||||||
|
if (UserImplementer.user != null)
|
||||||
|
{
|
||||||
|
_data.DeleteDetail(id);
|
||||||
|
}
|
||||||
|
Response.Redirect("IndexDetail");
|
||||||
|
}
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult CreateDetail(int id)
|
||||||
|
{
|
||||||
|
if (id != 0)
|
||||||
|
{
|
||||||
|
var value = _data.GetDetail(id);
|
||||||
|
if (value != null)
|
||||||
|
return View(value);
|
||||||
|
}
|
||||||
|
return View(new DetailViewModel());
|
||||||
|
}
|
||||||
|
[HttpPost]
|
||||||
|
public IActionResult CreateDetail(DetailBindingModel model)
|
||||||
|
{
|
||||||
|
if (model.Id == 0)
|
||||||
|
{
|
||||||
|
model.DateCreate = DateTime.Now;
|
||||||
|
model.UserId = UserImplementer.user!.Id;
|
||||||
|
if (_data.CreateDetail(model))
|
||||||
|
return RedirectToAction("IndexDetail");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (_data.UpdateDetail(model))
|
||||||
|
return RedirectToAction("IndexDetail");
|
||||||
|
}
|
||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
|
[HttpGet]
|
||||||
public IActionResult IndexProduct()
|
public IActionResult IndexProduct()
|
||||||
{
|
{
|
||||||
List<ProductViewModel> products = new List<ProductViewModel>
|
if (IsLoggedIn) {
|
||||||
{
|
var products = _data.GetProducts(UserImplementer.user!.Id);
|
||||||
new ProductViewModel
|
|
||||||
{
|
|
||||||
Id = 1,
|
|
||||||
Name = "Изделие 1",
|
|
||||||
Cost = 10.99,
|
|
||||||
UserId = 1,
|
|
||||||
MachineId = 1
|
|
||||||
},
|
|
||||||
new ProductViewModel
|
|
||||||
{
|
|
||||||
Id = 2,
|
|
||||||
Name = "Изделие 2",
|
|
||||||
Cost = 19.99,
|
|
||||||
UserId = 2,
|
|
||||||
MachineId = 2
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return View(products);
|
return View(products);
|
||||||
}
|
}
|
||||||
public IActionResult CreateProduct()
|
return RedirectToAction("IndexNonReg");
|
||||||
{
|
|
||||||
var details = new List<DetailViewModel>();
|
|
||||||
details.Add(new DetailViewModel
|
|
||||||
{
|
|
||||||
Id = 1,
|
|
||||||
Name = "Test",
|
|
||||||
Cost = 55.5,
|
|
||||||
UserId = 1
|
|
||||||
});
|
|
||||||
details.Add(new DetailViewModel
|
|
||||||
{
|
|
||||||
Id = 2,
|
|
||||||
Name = "Test1",
|
|
||||||
Cost = 32,
|
|
||||||
UserId = 2
|
|
||||||
});
|
|
||||||
return View(details);
|
|
||||||
}
|
}
|
||||||
|
[HttpPost]
|
||||||
|
public IActionResult IndexProduct(int id)
|
||||||
|
{
|
||||||
|
_data.DeleteProduct(id);
|
||||||
|
return RedirectToAction("IndexProduct");
|
||||||
|
}
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult CreateProduct(int id)
|
||||||
|
{
|
||||||
|
var details = _data.GetDetails(UserImplementer.user!.Id);
|
||||||
|
ViewBag.AllDetails = details;
|
||||||
|
if (id != 0)
|
||||||
|
{
|
||||||
|
var value = _data.GetProduct(id);
|
||||||
|
if (value != null)
|
||||||
|
return View(value);
|
||||||
|
}
|
||||||
|
return View(new ProductViewModel());
|
||||||
|
}
|
||||||
|
[HttpPost]
|
||||||
|
public IActionResult CreateProduct(int id, string title, int[] detailIds, int[] counts)
|
||||||
|
{
|
||||||
|
ProductBindingModel model = new ProductBindingModel();
|
||||||
|
model.Id = id;
|
||||||
|
model.Name = title;
|
||||||
|
model.UserId = UserImplementer.user!.Id;
|
||||||
|
var details = _data.GetDetails(UserImplementer.user!.Id);
|
||||||
|
double sum = 0;
|
||||||
|
for (int i = 0; i < detailIds.Length; i++)
|
||||||
|
{
|
||||||
|
var detail = details!.FirstOrDefault(x => x.Id == detailIds[i])!;
|
||||||
|
if (counts[i] <= 0)
|
||||||
|
continue;
|
||||||
|
model.ProductDetails[detailIds[i]] = (detail, counts[i]);
|
||||||
|
sum += detail.Cost * counts[i];
|
||||||
|
}
|
||||||
|
if (model.ProductDetails.Count == 0)
|
||||||
|
return RedirectToAction("IndexProduct");
|
||||||
|
model.Cost = sum;
|
||||||
|
if (id != 0)
|
||||||
|
{
|
||||||
|
_data.UpdateProduct(model);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_data.CreateProduct(model);
|
||||||
|
}
|
||||||
|
return RedirectToAction("IndexProduct");
|
||||||
|
}
|
||||||
|
[HttpGet]
|
||||||
public IActionResult IndexProduction()
|
public IActionResult IndexProduction()
|
||||||
{
|
{
|
||||||
List<ProductionViewModel> productionViewModels = new List<ProductionViewModel>
|
if (UserImplementer.user != null)
|
||||||
{
|
{
|
||||||
new ProductionViewModel
|
var productions = _data.GetProductions(UserImplementer.user.Id);
|
||||||
{
|
return View(productions);
|
||||||
Id = 1,
|
|
||||||
Name = "Производство А",
|
|
||||||
Cost = 1000.00,
|
|
||||||
UserId = 1
|
|
||||||
},
|
|
||||||
new ProductionViewModel
|
|
||||||
{
|
|
||||||
Id = 2,
|
|
||||||
Name = "Производство Б",
|
|
||||||
Cost = 1500.00,
|
|
||||||
UserId = 2
|
|
||||||
}
|
}
|
||||||
};
|
return RedirectToAction("IndexNonReg");
|
||||||
return View(productionViewModels);
|
|
||||||
}
|
}
|
||||||
public IActionResult CreateProduction()
|
[HttpPost]
|
||||||
|
public IActionResult IndexProduction(int id)
|
||||||
{
|
{
|
||||||
var details = new List<DetailViewModel>();
|
_data.DeleteProduction(id);
|
||||||
details.Add(new DetailViewModel
|
return RedirectToAction("IndexProduction");
|
||||||
{
|
|
||||||
Id = 1,
|
|
||||||
Name = "Test",
|
|
||||||
Cost = 55.5,
|
|
||||||
UserId = 1
|
|
||||||
});
|
|
||||||
details.Add(new DetailViewModel
|
|
||||||
{
|
|
||||||
Id = 2,
|
|
||||||
Name = "Test1",
|
|
||||||
Cost = 32,
|
|
||||||
UserId = 2
|
|
||||||
});
|
|
||||||
return View(details);
|
|
||||||
}
|
}
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult CreateProduction(int id)
|
||||||
|
{
|
||||||
|
var details = _data.GetDetails(UserImplementer.user!.Id);
|
||||||
|
ViewBag.AllDetails = details;
|
||||||
|
if (id != 0)
|
||||||
|
{
|
||||||
|
var value = _data.GetProduction(id);
|
||||||
|
if (value != null)
|
||||||
|
return View(value);
|
||||||
|
}
|
||||||
|
return View(new ProductionViewModel());
|
||||||
|
}
|
||||||
|
[HttpPost]
|
||||||
|
public IActionResult CreateProduction(int id, string title, int[] detailIds)
|
||||||
|
{
|
||||||
|
ProductionBindingModel model = new ProductionBindingModel();
|
||||||
|
model.Id = id;
|
||||||
|
model.Name = title;
|
||||||
|
model.UserId = UserImplementer.user!.Id;
|
||||||
|
var details = _data.GetDetails(UserImplementer.user!.Id);
|
||||||
|
double sum = 0;
|
||||||
|
for (int i = 0; i < detailIds.Length; i++)
|
||||||
|
{
|
||||||
|
var detail = details!.FirstOrDefault(x => x.Id == detailIds[i])!;
|
||||||
|
model.ProductionDetails[detailIds[i]] = detail;
|
||||||
|
sum += detail.Cost;
|
||||||
|
}
|
||||||
|
model.Cost = sum;
|
||||||
|
bool changed = false;
|
||||||
|
if (model.ProductionDetails.Count > 0)
|
||||||
|
{
|
||||||
|
if (id != 0)
|
||||||
|
{
|
||||||
|
changed = _data.UpdateProduction(model);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
changed = _data.CreateProduction(model);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (changed)
|
||||||
|
return RedirectToAction("IndexProduction");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ViewBag.AllDetails = details;
|
||||||
|
return View(model);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpGet]
|
||||||
public IActionResult Privacy()
|
public IActionResult Privacy()
|
||||||
{
|
{
|
||||||
ImplementerViewModel user = new()
|
if (IsLoggedIn)
|
||||||
|
return View(UserImplementer.user);
|
||||||
|
return RedirectToAction("IndexNonReg");
|
||||||
|
}
|
||||||
|
[HttpPost]
|
||||||
|
public IActionResult Privacy(int id, string login, string email, string password, string name)
|
||||||
{
|
{
|
||||||
Email = "mail@mail.ru",
|
if (!IsLoggedIn)
|
||||||
Login = "Login",
|
return RedirectToAction("IndexNonReg");
|
||||||
Password = "password",
|
ImplementerBindingModel user = new() { Id = id, Login = login, Email = email, Password = password, Name = name };
|
||||||
Name = "User"
|
if (_data.UpdateUser(user))
|
||||||
|
{
|
||||||
};
|
UserImplementer.user = new ImplementerViewModel { Id = id, Login = login, Password = password, Name = name, Email = email };
|
||||||
|
}
|
||||||
return View(user);
|
return View(user);
|
||||||
}
|
}
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult DetailTimeChoose()
|
||||||
|
{
|
||||||
|
if (!IsLoggedIn)
|
||||||
|
return RedirectToAction("IndexNonReg");
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
[HttpPost]
|
||||||
|
public IActionResult SendReport(DateTime startDate, DateTime endDate)
|
||||||
|
{
|
||||||
|
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
[HttpPost]
|
||||||
|
public IActionResult TimeReportWeb(DateTime startDate, DateTime endDate)
|
||||||
|
{
|
||||||
|
if (!IsLoggedIn)
|
||||||
|
return RedirectToAction("IndexNonReg");
|
||||||
|
|
||||||
|
|
||||||
|
HttpContext.Session.SetString("StartDate", startDate.ToString());
|
||||||
|
HttpContext.Session.SetString("EndDate", endDate.ToString());
|
||||||
|
|
||||||
|
return RedirectToAction("DetailTimeReport");
|
||||||
|
}
|
||||||
|
[HttpGet]
|
||||||
public IActionResult DetailTimeReport()
|
public IActionResult DetailTimeReport()
|
||||||
{
|
{
|
||||||
List<DetailTimeReport> detailTimeReports = new List<DetailTimeReport>
|
var startDateStr = HttpContext.Session.GetString("StartDate");
|
||||||
{
|
var endDateStr = HttpContext.Session.GetString("EndDate");
|
||||||
new DetailTimeReport
|
var startDate = DateTime.Parse(startDateStr);
|
||||||
{
|
var endDate = DateTime.Parse(endDateStr).AddDays(1);
|
||||||
DetailName = "Деталь А",
|
|
||||||
Productions = new List<string> { "Производство 1", "Производство 2" },
|
var values = _data.GetTimeReport(startDate, endDate, UserId);
|
||||||
Products = new List<string> { "Машина X", "Машина Y" }
|
|
||||||
},
|
ViewBag.StartDate = startDate;
|
||||||
new DetailTimeReport
|
ViewBag.EndDate = endDate;
|
||||||
{
|
|
||||||
DetailName = "Деталь B",
|
return View(values);
|
||||||
Productions = new List<string> { "Производство 3", "Производство 4" },
|
|
||||||
Products = new List<string> { "Машина Z", "Машина W" }
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return View(detailTimeReports);
|
|
||||||
}
|
}
|
||||||
public IActionResult DetailWorkshopReport()
|
public IActionResult DetailWorkshopReport()
|
||||||
{
|
{
|
||||||
@ -193,28 +320,28 @@ namespace ImplementerApp.Controllers
|
|||||||
{
|
{
|
||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
public IActionResult ProductMachineAdd()
|
[HttpGet]
|
||||||
|
public IActionResult ProductMachineAdd(int id)
|
||||||
{
|
{
|
||||||
List<MachineViewModel> machines = new List<MachineViewModel>
|
if (!IsLoggedIn)
|
||||||
{
|
return RedirectToAction("IndexNonReg");
|
||||||
new MachineViewModel
|
var product = _data.GetProduct(id);
|
||||||
{
|
ViewBag.Product = product;
|
||||||
Id = 1,
|
var machines = _data.GetMachines();
|
||||||
Title = "Токарный станок",
|
|
||||||
Country = "Германия",
|
|
||||||
UserId = 1,
|
|
||||||
WorkerMachines = new()
|
|
||||||
},
|
|
||||||
new MachineViewModel
|
|
||||||
{
|
|
||||||
Id = 2,
|
|
||||||
Title = "Фрезерный станок",
|
|
||||||
Country = "Япония",
|
|
||||||
UserId = 2,
|
|
||||||
WorkerMachines = new()
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return View(machines);
|
return View(machines);
|
||||||
|
}
|
||||||
|
[HttpPost]
|
||||||
|
public IActionResult ProductMachineAdd(int productId, int machineId)
|
||||||
|
{
|
||||||
|
if (!IsLoggedIn)
|
||||||
|
return RedirectToAction("IndexNonReg");
|
||||||
|
var product = _data.GetProduct(productId);
|
||||||
|
if (product == null)
|
||||||
|
return RedirectToAction("Index");
|
||||||
|
ProductBindingModel productBinding = new() { Id = productId, Cost = product.Cost, Name = product.Name, UserId = product.UserId, ProductDetails = product.DetailProducts, MachineId = machineId };
|
||||||
|
_data.UpdateProduct(productBinding);
|
||||||
|
return RedirectToAction("IndexProduct");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||||
|
@ -8,11 +8,14 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="6.0.26" />
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="6.0.26" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\BusinessLogic\BusinessLogic.csproj" />
|
<ProjectReference Include="..\BusinessLogic\BusinessLogic.csproj" />
|
||||||
<ProjectReference Include="..\Contracts\Contracts.csproj" />
|
<ProjectReference Include="..\Contracts\Contracts.csproj" />
|
||||||
|
<ProjectReference Include="..\DatabaseImplement\DatabaseImplement.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
134
Course/ImplementerApp/ImplementerData.cs
Normal file
134
Course/ImplementerApp/ImplementerData.cs
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
using Contracts.BusinessLogicsContracts;
|
||||||
|
using Contracts.ViewModels;
|
||||||
|
using Contracts.BindingModels;
|
||||||
|
using Contracts.StoragesContracts;
|
||||||
|
using Contracts.SearchModels;
|
||||||
|
|
||||||
|
namespace ImplementerApp
|
||||||
|
{
|
||||||
|
public class ImplementerData
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IImplementerLogic _implementerLogic;
|
||||||
|
private readonly IDetailLogic _detailLogic;
|
||||||
|
private readonly IProductionLogic _productionLogic;
|
||||||
|
private readonly IProductLogic _productLogic;
|
||||||
|
private readonly IMachineLogic _machineLogic;
|
||||||
|
|
||||||
|
public ImplementerData(ILogger<ImplementerData> logger, IImplementerLogic implementerLogic, IDetailLogic detailLogic, IProductionLogic productionLogic, IProductLogic productLogic, IMachineLogic machineLogic)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_implementerLogic = implementerLogic;
|
||||||
|
_detailLogic = detailLogic;
|
||||||
|
_productionLogic = productionLogic;
|
||||||
|
_productLogic = productLogic;
|
||||||
|
_machineLogic = machineLogic;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImplementerViewModel? Login(string login, string password)
|
||||||
|
{
|
||||||
|
return _implementerLogic.ReadElement(new()
|
||||||
|
{
|
||||||
|
Login = login,
|
||||||
|
Password = password
|
||||||
|
});
|
||||||
|
}
|
||||||
|
public bool Register(ImplementerBindingModel model)
|
||||||
|
{
|
||||||
|
return _implementerLogic.Create(model);
|
||||||
|
}
|
||||||
|
public bool UpdateUser(ImplementerBindingModel model)
|
||||||
|
{
|
||||||
|
return _implementerLogic.Update(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<DetailViewModel>? GetDetails(int userId)
|
||||||
|
{
|
||||||
|
return _detailLogic.ReadList(new DetailSearchModel() { UserId = userId });
|
||||||
|
}
|
||||||
|
public bool DeleteDetail(int detailId)
|
||||||
|
{
|
||||||
|
return _detailLogic.Delete(new() { Id = detailId });
|
||||||
|
}
|
||||||
|
public bool CreateDetail(DetailBindingModel model)
|
||||||
|
{
|
||||||
|
return _detailLogic.Create(model);
|
||||||
|
}
|
||||||
|
public bool UpdateDetail(DetailBindingModel model)
|
||||||
|
{
|
||||||
|
return _detailLogic.Update(model);
|
||||||
|
}
|
||||||
|
public DetailViewModel? GetDetail(int id)
|
||||||
|
{
|
||||||
|
return _detailLogic.ReadElement(new() { Id= id });
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ProductViewModel>? GetProducts(int userId)
|
||||||
|
{
|
||||||
|
return _productLogic.ReadList(new ProductSearchModel() { UserId = userId });
|
||||||
|
}
|
||||||
|
public ProductViewModel? GetProduct(int id)
|
||||||
|
{
|
||||||
|
return _productLogic.ReadElement(new() { Id = id });
|
||||||
|
}
|
||||||
|
public bool UpdateProduct(ProductBindingModel model)
|
||||||
|
{
|
||||||
|
return _productLogic.Update(model);
|
||||||
|
}
|
||||||
|
public bool DeleteProduct(int productId)
|
||||||
|
{
|
||||||
|
return _productLogic.Delete(new() { Id = productId });
|
||||||
|
}
|
||||||
|
public bool CreateProduct(ProductBindingModel model)
|
||||||
|
{
|
||||||
|
return _productLogic.Create(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ProductionViewModel>? GetProductions(int userId)
|
||||||
|
{
|
||||||
|
return _productionLogic.ReadList(new() { UserId = userId });
|
||||||
|
}
|
||||||
|
public ProductionViewModel? GetProduction(int id)
|
||||||
|
{
|
||||||
|
return _productionLogic.ReadElement(new() { Id = id });
|
||||||
|
}
|
||||||
|
public bool CreateProduction(ProductionBindingModel model)
|
||||||
|
{
|
||||||
|
return _productionLogic.Create(model);
|
||||||
|
}
|
||||||
|
public bool UpdateProduction(ProductionBindingModel model)
|
||||||
|
{
|
||||||
|
return _productionLogic.Update(model);
|
||||||
|
}
|
||||||
|
public bool DeleteProduction(int productionId)
|
||||||
|
{
|
||||||
|
return _productionLogic.Delete(new() { Id = productionId});
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<MachineViewModel>? GetMachines()
|
||||||
|
{
|
||||||
|
return _machineLogic.ReadList(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<DetailTimeReport> GetTimeReport(DateTime? startDate, DateTime? endDate, int UserId)
|
||||||
|
{
|
||||||
|
var details = _detailLogic.ReadList(new() { DateFrom = startDate, DateTo = endDate, UserId = UserId });
|
||||||
|
if (details == null)
|
||||||
|
return new();
|
||||||
|
List<DetailTimeReport> detailTimeReports = new List<DetailTimeReport>();
|
||||||
|
foreach (var detail in details)
|
||||||
|
{
|
||||||
|
var report = new DetailTimeReport();
|
||||||
|
report.DetailName = detail.Name;
|
||||||
|
var products = _productLogic.ReadList(new() { DetailId = detail.Id, UserId = UserId });
|
||||||
|
if (products != null)
|
||||||
|
report.Products = products.Select(p => p.Name).ToList();
|
||||||
|
var productions = _productionLogic.ReadList(new() { DetailId = detail.Id, UserId = UserId });
|
||||||
|
if (productions != null)
|
||||||
|
report.Productions = productions.Select(p => p.Name).ToList();
|
||||||
|
detailTimeReports.Add(report);
|
||||||
|
}
|
||||||
|
return detailTimeReports;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,36 @@
|
|||||||
|
using BusinessLogic.BusinessLogic;
|
||||||
using Contracts.BusinessLogicsContracts;
|
using Contracts.BusinessLogicsContracts;
|
||||||
|
using Contracts.StoragesContracts;
|
||||||
|
using DatabaseImplement.Implements;
|
||||||
|
using ImplementerApp;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
builder.Services.AddControllersWithViews().AddRazorRuntimeCompilation();
|
builder.Services.AddControllersWithViews().AddRazorRuntimeCompilation();
|
||||||
|
|
||||||
|
builder.Logging.SetMinimumLevel(LogLevel.Trace);
|
||||||
|
builder.Logging.AddLog4Net("log4net.config");
|
||||||
|
|
||||||
|
builder.Services.AddTransient<IImplementerStorage, ImplementerStorage>();
|
||||||
|
builder.Services.AddTransient<IDetailStorage, DetailStorage>();
|
||||||
|
builder.Services.AddTransient<IProductStorage, ProductStorage>();
|
||||||
|
builder.Services.AddTransient<IProductionStorage, ProductionStorage>();
|
||||||
|
builder.Services.AddTransient<IMachineStorage, MachineStorage>();
|
||||||
|
builder.Services.AddTransient<IImplementerLogic, ImplementerLogic>();
|
||||||
|
builder.Services.AddTransient<IDetailLogic, DetailLogic>();
|
||||||
|
builder.Services.AddTransient<IProductionLogic, ProductionLogic>();
|
||||||
|
builder.Services.AddTransient<IProductLogic, ProductLogic>();
|
||||||
|
builder.Services.AddTransient<IMachineLogic, MachineLogic>();
|
||||||
|
builder.Services.AddTransient<ImplementerData>();
|
||||||
|
|
||||||
|
builder.Services.AddSession(options =>
|
||||||
|
{
|
||||||
|
options.IdleTimeout = TimeSpan.FromMinutes(30);
|
||||||
|
options.Cookie.HttpOnly = true;
|
||||||
|
options.Cookie.IsEssential = true;
|
||||||
|
});
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
if (!app.Environment.IsDevelopment())
|
if (!app.Environment.IsDevelopment())
|
||||||
@ -16,7 +43,7 @@ app.UseHttpsRedirection();
|
|||||||
app.UseStaticFiles();
|
app.UseStaticFiles();
|
||||||
|
|
||||||
app.UseRouting();
|
app.UseRouting();
|
||||||
|
app.UseSession();
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
|
||||||
app.MapControllerRoute(
|
app.MapControllerRoute(
|
||||||
|
9
Course/ImplementerApp/UserImplementer.cs
Normal file
9
Course/ImplementerApp/UserImplementer.cs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
using Contracts.ViewModels;
|
||||||
|
|
||||||
|
namespace ImplementerApp
|
||||||
|
{
|
||||||
|
public static class UserImplementer
|
||||||
|
{
|
||||||
|
public static ImplementerViewModel? user { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -1,20 +1,57 @@
|
|||||||
@{
|
@using Contracts.ViewModels;
|
||||||
|
@{
|
||||||
ViewData["Title"] = "CreateDetail";
|
ViewData["Title"] = "CreateDetail";
|
||||||
}
|
}
|
||||||
|
@model DetailViewModel;
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<h2 class="display-4">Создание детали</h2>
|
<h2 class="display-4">Деталь</h2>
|
||||||
</div>
|
</div>
|
||||||
<form method="post">
|
<form id="detailForm" method="post">
|
||||||
|
<input type="text" name="id" id="id" value="@Model.Id" hidden="hidden" />
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-4">Название:</div>
|
<div class="col-4">Название:</div>
|
||||||
<div class="col-8"><input type="text" name="title" id="title" /></div>
|
<div class="col-8">
|
||||||
|
<input type="text" name="name" id="name" value="@Model.Name" />
|
||||||
|
<span id="nameError" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-4">Цена:</div>
|
<div class="col-4">Цена:</div>
|
||||||
<div class="col-8"><input type="text" name="cost" id="cost" /></div>
|
<div class="col-8">
|
||||||
|
<input type="text" name="cost" id="cost" value="@Model.Cost" />
|
||||||
|
<span id="costError" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-8"></div>
|
<div class="col-8"></div>
|
||||||
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div>
|
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||||
|
<script>
|
||||||
|
$(document).ready(function () {
|
||||||
|
$('#detailForm').submit(function (event) {
|
||||||
|
var name = $('#name').val();
|
||||||
|
var cost = $('#cost').val();
|
||||||
|
var isValid = true;
|
||||||
|
|
||||||
|
$('#nameError').text('');
|
||||||
|
$('#costError').text('');
|
||||||
|
|
||||||
|
if (name.length < 2 || name.length > 50) {
|
||||||
|
$('#nameError').text('Название должно быть от 2 до 50 символов.');
|
||||||
|
isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isNaN(cost) || cost <= 0) {
|
||||||
|
$('#costError').text('Цена должна быть положительным числом.');
|
||||||
|
isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isValid) {
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
@ -1,17 +1,21 @@
|
|||||||
@using Contracts.ViewModels
|
@using Contracts.ViewModels
|
||||||
|
|
||||||
@model List<DetailViewModel>
|
@model ProductViewModel;
|
||||||
|
|
||||||
@{
|
@{
|
||||||
ViewData["Title"] = "CreateProduct";
|
ViewData["Title"] = "CreateProduct";
|
||||||
|
ViewBag.Details = Model.DetailProducts;
|
||||||
}
|
}
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<h2 class="display-4">Создание изделия</h2>
|
<h2 class="display-4">Создание изделия</h2>
|
||||||
</div>
|
</div>
|
||||||
<form method="post">
|
<form id="productForm" method="post">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-4">Название:</div>
|
<div class="col-4">Название:</div>
|
||||||
<div class="col-8"><input type="text" name="title" id="title" /></div>
|
<div class="col-8">
|
||||||
|
<input type="text" name="title" id="title" value="@Model.Name"/>
|
||||||
|
<span id="titleError" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div>Детали</div>
|
<div>Детали</div>
|
||||||
@ -19,27 +23,40 @@
|
|||||||
<table id="detailsTable" class="display">
|
<table id="detailsTable" class="display">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Выбор</th>
|
|
||||||
<th>Название</th>
|
<th>Название</th>
|
||||||
<th>Количество</th>
|
<th>Количество</th>
|
||||||
|
<th>Стоимость</th>
|
||||||
|
<th>Удалить</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@foreach (var detail in Model)
|
@foreach (var detail in ViewBag.Details)
|
||||||
{
|
{
|
||||||
<tr>
|
<tr data-detail-id="@detail.Value.Item1.Id">
|
||||||
<td>
|
<td>
|
||||||
<input type="checkbox" name="details" value="@detail.Id" />
|
<input type="hidden" name="detailIds" value="@detail.Key" />
|
||||||
|
@detail.Value.Item1.Name
|
||||||
</td>
|
</td>
|
||||||
<td>@detail.Name</td>
|
|
||||||
<td>
|
<td>
|
||||||
<input type="number" name="count" value="0" min="0" class="form-control" />
|
<input type="number" name="counts" value="@detail.Value.Item2" min="0" class="form-control detail-count" data-cost="@detail.Value.Item1.Cost" />
|
||||||
|
</td>
|
||||||
|
<td>@detail.Value.Item1.Cost</td>
|
||||||
|
<td>
|
||||||
|
<button type="button" class="deleteDetail" data-detail-id="@detail.Value.Item1.Id">Удалить</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
<select id="detailSelect" class="form-control">
|
||||||
|
<option value="">Выберите деталь</option>
|
||||||
|
@foreach (var detail in ViewBag.AllDetails)
|
||||||
|
{
|
||||||
|
<option value="@detail.Id" data-cost="@detail.Cost">@detail.Name</option>
|
||||||
|
}
|
||||||
|
</select>
|
||||||
|
<button type="button" id="addDetail" class="btn btn-secondary">Добавить деталь</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-4">Сумма:</div>
|
<div class="col-4">Сумма:</div>
|
||||||
@ -55,6 +72,96 @@
|
|||||||
<script src="https://cdn.datatables.net/1.11.3/js/jquery.dataTables.js"></script>
|
<script src="https://cdn.datatables.net/1.11.3/js/jquery.dataTables.js"></script>
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
$('#detailsTable').DataTable();
|
function updateSum() {
|
||||||
|
var sum = 0;
|
||||||
|
$('#detailsTable tbody tr').each(function () {
|
||||||
|
var count = $(this).find('input[name="counts"]').val();
|
||||||
|
var cost = $(this).find('input[name="counts"]').data('cost');
|
||||||
|
sum += count * cost;
|
||||||
|
});
|
||||||
|
$('#sum').val(sum.toFixed(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).on('click', '.deleteDetail', function () {
|
||||||
|
var row = $(this).closest('tr');
|
||||||
|
row.remove();
|
||||||
|
updateSum();
|
||||||
|
});
|
||||||
|
|
||||||
|
$(document).on('change', '.detail-count', function () {
|
||||||
|
updateSum();
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#addDetail').click(function () {
|
||||||
|
var selectedDetail = $('#detailSelect option:selected');
|
||||||
|
if (selectedDetail.val()) {
|
||||||
|
var detailId = selectedDetail.val();
|
||||||
|
var detailName = selectedDetail.text();
|
||||||
|
var detailCost = selectedDetail.data('cost');
|
||||||
|
|
||||||
|
var exists = false;
|
||||||
|
$('#detailsTable tbody tr').each(function () {
|
||||||
|
if ($(this).data('detail-id') == detailId) {
|
||||||
|
exists = true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (exists) {
|
||||||
|
alert('Эта деталь уже добавлена.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var newRow = `
|
||||||
|
<tr data-detail-id="${detailId}">
|
||||||
|
<td>
|
||||||
|
<input type="hidden" name="detailIds" value="${detailId}" />
|
||||||
|
${detailName}
|
||||||
|
</td>
|
||||||
|
<td><input type="number" name="counts" value="0" min="1" class="form-control detail-count" data-cost="${detailCost}" /></td>
|
||||||
|
<td>${detailCost}</td>
|
||||||
|
<td><button type="button" class="deleteDetail" data-detail-id="${detailId}">Удалить</button></td>
|
||||||
|
</tr>
|
||||||
|
`;
|
||||||
|
$('#detailsTable tbody').append(newRow);
|
||||||
|
|
||||||
|
updateSum();
|
||||||
|
$('#detailSelect').val('');
|
||||||
|
} else {
|
||||||
|
alert('Выберите деталь для добавления');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#productForm').submit(function (event) {
|
||||||
|
var title = $('#title').val();
|
||||||
|
var isValid = true;
|
||||||
|
|
||||||
|
$('#titleError').text('');
|
||||||
|
if (title.length < 2 || title.length > 50) {
|
||||||
|
$('#titleError').text('Название должно быть от 2 до 50 символов.');
|
||||||
|
isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var totalDetails = $('#detailsTable tbody tr').length;
|
||||||
|
if (totalDetails == 0) {
|
||||||
|
alert('Пожалуйста, добавьте хотя бы одну деталь.');
|
||||||
|
isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#detailsTable tbody tr').each(function () {
|
||||||
|
var count = $(this).find('input[name="counts"]').val();
|
||||||
|
if (count < 1) {
|
||||||
|
alert('Количество каждой детали должно быть не менее 1.');
|
||||||
|
isValid = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!isValid) {
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
updateSum();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
@ -1,41 +1,56 @@
|
|||||||
@using Contracts.ViewModels
|
@using Contracts.ViewModels
|
||||||
|
|
||||||
@model List<DetailViewModel>
|
@model ProductionViewModel
|
||||||
|
|
||||||
@{
|
@{
|
||||||
ViewData["Title"] = "CreateProduction";
|
ViewData["Title"] = "CreateProduction";
|
||||||
|
ViewBag.Details = Model.DetailProductions;
|
||||||
}
|
}
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<h2 class="display-4">Создание производства</h2>
|
<h2 class="display-4">Создание производства</h2>
|
||||||
</div>
|
</div>
|
||||||
<form method="post">
|
<form id="productionForm" method="post">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-4">Название:</div>
|
<div class="col-4">Название:</div>
|
||||||
<div class="col-8"><input type="text" name="title" id="title" /></div>
|
<div class="col-8">
|
||||||
|
<input type="text" name="title" id="title" value="@Model.Name" />
|
||||||
|
<span id="titleError" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div>Details</div>
|
<div>Детали</div>
|
||||||
<div class="table-responsive-lg">
|
<div class="table-responsive-lg">
|
||||||
<table id="detailsTable" class="display">
|
<table id="detailsTable" class="display">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Выбор</th>
|
|
||||||
<th>Название</th>
|
<th>Название</th>
|
||||||
|
<th>Стоимость</th>
|
||||||
|
<th>Удалить</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@foreach (var detail in Model)
|
@foreach (var detail in ViewBag.Details)
|
||||||
{
|
{
|
||||||
<tr>
|
<tr data-detail-id="@detail.Value.Id">
|
||||||
<td>
|
<td>
|
||||||
<input type="checkbox" name="details" value="@detail.Id" />
|
<input type="hidden" name="detailIds" value="@detail.Value.Id" />
|
||||||
|
@detail.Value.Name
|
||||||
</td>
|
</td>
|
||||||
<td>@detail.Name</td>
|
<td class="detail-cost" data-cost="@detail.Value.Cost">@detail.Value.Cost</td>
|
||||||
|
<td><button type="button" class="deleteDetail" data-detail-id="@detail.Value.Id">Удалить</button></td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
<select id="detailSelect" class="form-control">
|
||||||
|
<option value="">Выберите деталь</option>
|
||||||
|
@foreach (var detail in ViewBag.AllDetails)
|
||||||
|
{
|
||||||
|
<option value="@detail.Id" data-cost="@detail.Cost">@detail.Name</option>
|
||||||
|
}
|
||||||
|
</select>
|
||||||
|
<button type="button" id="addDetail" class="btn btn-secondary">Добавить деталь</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-4">Сумма:</div>
|
<div class="col-4">Сумма:</div>
|
||||||
@ -51,6 +66,87 @@
|
|||||||
<script src="https://cdn.datatables.net/1.11.3/js/jquery.dataTables.js"></script>
|
<script src="https://cdn.datatables.net/1.11.3/js/jquery.dataTables.js"></script>
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
$('#detailsTable').DataTable();
|
function updateSum() {
|
||||||
|
var sum = 0;
|
||||||
|
$('#detailsTable tbody tr').each(function () {
|
||||||
|
var cost = $(this).find('.detail-cost').data('cost');
|
||||||
|
sum += parseFloat(cost);
|
||||||
|
});
|
||||||
|
$('#sum').val(sum.toFixed(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).on('click', '.deleteDetail', function () {
|
||||||
|
var row = $(this).closest('tr');
|
||||||
|
row.remove();
|
||||||
|
updateSum();
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#addDetail').click(function () {
|
||||||
|
var selectedDetail = $('#detailSelect option:selected');
|
||||||
|
if (selectedDetail.val()) {
|
||||||
|
var detailId = selectedDetail.val();
|
||||||
|
var exists = false;
|
||||||
|
$('#detailsTable tbody tr').each(function () {
|
||||||
|
if ($(this).data('detail-id') == detailId) {
|
||||||
|
exists = true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (exists) {
|
||||||
|
alert('Эта деталь уже добавлена.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var detailName = selectedDetail.text();
|
||||||
|
var detailCost = selectedDetail.data('cost');
|
||||||
|
|
||||||
|
var newRow = `
|
||||||
|
<tr data-detail-id="${detailId}">
|
||||||
|
<td>
|
||||||
|
<input type="hidden" name="detailIds" value="${detailId}" />
|
||||||
|
${detailName}
|
||||||
|
</td>
|
||||||
|
<td class="detail-cost" data-cost="${detailCost}">${detailCost}</td>
|
||||||
|
<td><button type="button" class="deleteDetail" data-detail-id="${detailId}">Удалить</button></td>
|
||||||
|
</tr>
|
||||||
|
`;
|
||||||
|
$('#detailsTable tbody').append(newRow);
|
||||||
|
|
||||||
|
$('.deleteDetail').off('click').on('click', function () {
|
||||||
|
var row = $(this).closest('tr');
|
||||||
|
row.remove();
|
||||||
|
updateSum();
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#detailSelect').val('');
|
||||||
|
|
||||||
|
updateSum();
|
||||||
|
} else {
|
||||||
|
alert('Выберите деталь для добавления');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#productionForm').submit(function (event) {
|
||||||
|
var title = $('#title').val();
|
||||||
|
var isValid = true;
|
||||||
|
|
||||||
|
$('#titleError').text('');
|
||||||
|
if (title.length < 2 || title.length > 50) {
|
||||||
|
$('#titleError').text('Название должно быть от 2 до 50 символов.');
|
||||||
|
isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var totalDetails = $('#detailsTable tbody tr').length;
|
||||||
|
if (totalDetails == 0) {
|
||||||
|
alert('Пожалуйста, добавьте хотя бы одну деталь.');
|
||||||
|
isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isValid) {
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
updateSum();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
76
Course/ImplementerApp/Views/Home/DetailTimeChoose.cshtml
Normal file
76
Course/ImplementerApp/Views/Home/DetailTimeChoose.cshtml
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
@{
|
||||||
|
ViewData["Title"] = "Создание отчета";
|
||||||
|
}
|
||||||
|
|
||||||
|
<div class="text-center">
|
||||||
|
<h2 class="display-4">Создание отчета</h2>
|
||||||
|
</div>
|
||||||
|
<form id="TimeReportWeb" method="post">
|
||||||
|
<div class="row mb-3">
|
||||||
|
<div class="col-4 text-right">
|
||||||
|
<label for="startDate">Дата начала:</label>
|
||||||
|
</div>
|
||||||
|
<div class="col-6">
|
||||||
|
<input type="date" id="startDate" name="startDate" class="form-control" required />
|
||||||
|
<span id="startDateError" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row mb-3">
|
||||||
|
<div class="col-4 text-right">
|
||||||
|
<label for="endDate">Дата окончания:</label>
|
||||||
|
</div>
|
||||||
|
<div class="col-6">
|
||||||
|
<input type="date" id="endDate" name="endDate" class="form-control" required />
|
||||||
|
<span id="endDateError" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row mb-3">
|
||||||
|
<div class="col-6 text-right">
|
||||||
|
<button type="button" id="generateReport" class="btn btn-primary">Создать отчет</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||||
|
<script>
|
||||||
|
$(document).ready(function () {
|
||||||
|
function validateDates() {
|
||||||
|
var startDate = new Date($('#startDate').val());
|
||||||
|
var endDate = new Date($('#endDate').val());
|
||||||
|
var today = new Date();
|
||||||
|
var isValid = true;
|
||||||
|
|
||||||
|
$('#startDateError').text('');
|
||||||
|
$('#endDateError').text('');
|
||||||
|
|
||||||
|
// Проверка, что даты не превосходят сегодняшнюю дату
|
||||||
|
if (startDate > today) {
|
||||||
|
$('#startDateError').text('Дата начала не может быть больше сегодняшней даты.');
|
||||||
|
isValid = false;
|
||||||
|
}
|
||||||
|
if (endDate > today) {
|
||||||
|
$('#endDateError').text('Дата окончания не может быть больше сегодняшней даты.');
|
||||||
|
isValid = false;
|
||||||
|
}
|
||||||
|
// Проверка, что стартовая дата не превосходит конечную дату
|
||||||
|
if (startDate > endDate) {
|
||||||
|
$('#endDateError').text('Дата окончания не может быть раньше даты начала.');
|
||||||
|
isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return isValid;
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#generateReport').click(function () {
|
||||||
|
if (validateDates()) {
|
||||||
|
var formData = $('#TimeReportWeb').serialize();
|
||||||
|
|
||||||
|
$.post('/Home/TimeReportWeb', formData, function (response) {
|
||||||
|
window.location.href = '/Home/DetailTimeReport';
|
||||||
|
}).fail(function () {
|
||||||
|
alert('Произошла ошибка при создании отчета.');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
@ -3,14 +3,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<h1 class="display-4">Приложение "Завод "Иди работать". Исполнитель"</h1>
|
<h1 class="display-4">Главное меню</h1>
|
||||||
<div class="list-group">
|
<div class="list-group">
|
||||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="IndexDetail">Детали</a>
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="IndexDetail">Детали</a>
|
||||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="IndexProduct">Изделия</a>
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="IndexProduct">Изделия</a>
|
||||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="IndexProduction">Производства</a>
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="IndexProduction">Производства</a>
|
||||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Личные данные</a>
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Личные данные</a>
|
||||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="ReportsMenu">Меню отчетов</a>
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="ReportsMenu">Меню отчетов</a>
|
||||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Enter">Вход</a>
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Logout">Выйти</a>
|
||||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Register">Регистрация</a>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
<p>
|
<p>
|
||||||
<a asp-action="CreateDetail">Создать деталь</a>
|
<a asp-action="CreateDetail" asp-route-id="0">Создать деталь</a>
|
||||||
</p>
|
</p>
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<thead>
|
<thead>
|
||||||
@ -57,7 +57,10 @@
|
|||||||
<a asp-action="CreateDetail" asp-route-id="@item.Id" class="btn btn-primary">Изменить</a>
|
<a asp-action="CreateDetail" asp-route-id="@item.Id" class="btn btn-primary">Изменить</a>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<a asp-action="DeleteDetail" asp-route-id="@item.Id" class="btn btn-danger">Удалить</a>
|
<form method="post">
|
||||||
|
<input type="text" title="id" name="id" value="@item.Id" hidden="hidden"/>
|
||||||
|
<input type="submit" class="btn btn-danger" value="Удалить"/>
|
||||||
|
</form>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
|
10
Course/ImplementerApp/Views/Home/IndexNonReg.cshtml
Normal file
10
Course/ImplementerApp/Views/Home/IndexNonReg.cshtml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
@{
|
||||||
|
ViewData["Title"] = "Home Page";
|
||||||
|
}
|
||||||
|
|
||||||
|
<div class="text-center">
|
||||||
|
<div class="list-group">
|
||||||
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Enter">Вход</a>
|
||||||
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Register">Регистрация</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
@ -10,7 +10,6 @@
|
|||||||
<h1 class="display-4">Изделия</h1>
|
<h1 class="display-4">Изделия</h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
ProductMachineAdd
|
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
@{
|
@{
|
||||||
if (Model == null)
|
if (Model == null)
|
||||||
@ -19,7 +18,7 @@ ProductMachineAdd
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
<p>
|
<p>
|
||||||
<a asp-action="CreateProduct">Создать изделие</a>
|
<a asp-action="CreateProduct" asp-route-id="0">Создать изделие</a>
|
||||||
</p>
|
</p>
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<thead>
|
<thead>
|
||||||
@ -33,6 +32,9 @@ ProductMachineAdd
|
|||||||
<th>
|
<th>
|
||||||
Цена
|
Цена
|
||||||
</th>
|
</th>
|
||||||
|
<th>
|
||||||
|
Станок
|
||||||
|
</th>
|
||||||
<th>
|
<th>
|
||||||
Привязка станка к изделию
|
Привязка станка к изделию
|
||||||
</th>
|
</th>
|
||||||
@ -57,6 +59,9 @@ ProductMachineAdd
|
|||||||
<td>
|
<td>
|
||||||
@Html.DisplayFor(modelItem => item.Cost)
|
@Html.DisplayFor(modelItem => item.Cost)
|
||||||
</td>
|
</td>
|
||||||
|
<td>
|
||||||
|
@Html.DisplayFor(modelItem => item.MachineName)
|
||||||
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<a asp-action="ProductMachineAdd" asp-route-id="@item.Id" class="btn btn-primary">Привязать станок</a>
|
<a asp-action="ProductMachineAdd" asp-route-id="@item.Id" class="btn btn-primary">Привязать станок</a>
|
||||||
</td>
|
</td>
|
||||||
@ -64,7 +69,10 @@ ProductMachineAdd
|
|||||||
<a asp-action="CreateProduct" asp-route-id="@item.Id" class="btn btn-primary">Изменить</a>
|
<a asp-action="CreateProduct" asp-route-id="@item.Id" class="btn btn-primary">Изменить</a>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<a asp-action="DeleteProduct" asp-route-id="@item.Id" class="btn btn-danger">Удалить</a>
|
<form method="post">
|
||||||
|
<input type="text" title="id" name="id" value="@item.Id" hidden="hidden" />
|
||||||
|
<input type="submit" class="btn btn-danger" value="Удалить" />
|
||||||
|
</form>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
<p>
|
<p>
|
||||||
<a asp-action="CreateProduction">Создать производство</a>
|
<a asp-action="CreateProduction" asp-route-id="0">Создать производство</a>
|
||||||
</p>
|
</p>
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<thead>
|
<thead>
|
||||||
@ -57,7 +57,10 @@
|
|||||||
<a asp-action="CreateProduction" asp-route-id="@item.Id" class="btn btn-primary">Изменить</a>
|
<a asp-action="CreateProduction" asp-route-id="@item.Id" class="btn btn-primary">Изменить</a>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<a asp-action="Delete" asp-route-id="@item.Id" class="btn btn-danger">Удалить</a>
|
<form method="post">
|
||||||
|
<input type="text" title="id" name="id" value="@item.Id" hidden="hidden" />
|
||||||
|
<input type="submit" class="btn btn-danger" value="Удалить" />
|
||||||
|
</form>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
|
@ -4,25 +4,85 @@
|
|||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<h2 class="display-4">Личные данные</h2>
|
<h2 class="display-4">Личные данные</h2>
|
||||||
</div>
|
</div>
|
||||||
<form method="post">
|
<form id="clientForm" method="post">
|
||||||
|
<input type="text" name="id" id="id" value="@Model.Id" hidden="hidden"/>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-4">Логин:</div>
|
<div class="col-4">Логин:</div>
|
||||||
<div class="col-8"><input type="text" name="login" value="@Model.Login" /></div>
|
<div class="col-8">
|
||||||
|
<input type="text" name="login" id="login" value="@Model.Login" />
|
||||||
|
<span id="loginError" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-4">Почта:</div>
|
<div class="col-4">Почта:</div>
|
||||||
<div class="col-8"><input type="email" name="email" value="@Model.Email" /></div>
|
<div class="col-8">
|
||||||
|
<input type="email" name="email" id="email" value="@Model.Email" />
|
||||||
|
<span id="emailError" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-4">Пароль:</div>
|
<div class="col-4">Пароль:</div>
|
||||||
<div class="col-8"><input type="password" name="password" value="@Model.Password" /></div>
|
<div class="col-8">
|
||||||
|
<input type="password" name="password" id="password" value="@Model.Password" />
|
||||||
|
<span id="passwordError" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-4">ФИО:</div>
|
<div class="col-4">ФИО:</div>
|
||||||
<div class="col-8"><input type="text" name="fio" value="@Model.Name" /></div>
|
<div class="col-8">
|
||||||
|
<input type="text" name="fio" id="fio" value="@Model.Name" />
|
||||||
|
<span id="fioError" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-8"></div>
|
<div class="col-8"></div>
|
||||||
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div>
|
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||||
|
<script>
|
||||||
|
$(document).ready(function () {
|
||||||
|
$('#clientForm').submit(function(event) {
|
||||||
|
var login = $('#login').val();
|
||||||
|
var email = $('#email').val();
|
||||||
|
var password = $('#password').val();
|
||||||
|
var fio = $('#fio').val();
|
||||||
|
var isValid = true;
|
||||||
|
|
||||||
|
$('#loginError').text('');
|
||||||
|
$('#emailError').text('');
|
||||||
|
$('#passwordError').text('');
|
||||||
|
$('#fioError').text('');
|
||||||
|
|
||||||
|
// Валидация логина
|
||||||
|
if (login.length < 5 || login.length > 50) {
|
||||||
|
$('#loginError').text('Логин должен быть от 5 до 50 символов.');
|
||||||
|
isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Валидация почты
|
||||||
|
var emailPattern = /^[a-zA-Z0-9._-]+@@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
|
||||||
|
if (!emailPattern.test(email)) {
|
||||||
|
$('#emailError').text('Неверный формат почты.');
|
||||||
|
isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Валидация пароля
|
||||||
|
if (password.length < 8 || password.length > 20) {
|
||||||
|
$('#passwordError').text('Пароль должен быть от 8 до 20 символов.');
|
||||||
|
isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Валидация ФИО
|
||||||
|
if (fio.length < 2 || fio.length > 20) {
|
||||||
|
$('#fioError').text('ФИО должно быть от 2 до 20 символов.');
|
||||||
|
isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isValid) {
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<h1 class="display-4">Изделие - @ViewBag.Product</h1>
|
<h1 class="display-4">Изделие - @ViewBag.Product.Name</h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
@ -19,8 +19,9 @@
|
|||||||
<div class="card mb-4">
|
<div class="card mb-4">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<h5 class="card-title">@machine.Title</h5>
|
<h5 class="card-title">@machine.Title</h5>
|
||||||
<form asp-controller="Cart" asp-action="AddToCart" method="post">
|
<form asp-action="ProductMachineAdd" method="post">
|
||||||
<input type="hidden" name="productId" value="@machine.Id" />
|
<input type="hidden" name="productId" value="@ViewBag.Product.Id"/>
|
||||||
|
<input type="hidden" name="machineId" value="@machine.Id" />
|
||||||
<button type="submit" class="btn btn-primary">Выбрать</button>
|
<button type="submit" class="btn btn-primary">Выбрать</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
@ -5,29 +5,99 @@
|
|||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<h2 class="display-4">Регистрация</h2>
|
<h2 class="display-4">Регистрация</h2>
|
||||||
</div>
|
</div>
|
||||||
<form method="post">
|
<form id="registerForm" method="post">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-4">Имя:</div>
|
<div class="col-4">Имя:</div>
|
||||||
<div class="col-8"><input type="text" name="name" /></div>
|
<div class="col-8">
|
||||||
|
<input type="text" name="name" id="name" />
|
||||||
|
<span id="nameError" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-4">Логин:</div>
|
<div class="col-4">Логин:</div>
|
||||||
<div class="col-8"><input type="text" name="login" /></div>
|
<div class="col-8">
|
||||||
|
<input type="text" name="login" id="login" />
|
||||||
|
<span id="loginError" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-4">Почта:</div>
|
<div class="col-4">Почта:</div>
|
||||||
<div class="col-8"><input type="email" name="email" /></div>
|
<div class="col-8">
|
||||||
|
<input type="email" name="email" id="email" />
|
||||||
|
<span id="emailError" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-4">Пароль:</div>
|
<div class="col-4">Пароль:</div>
|
||||||
<div class="col-8"><input type="password" name="password1" /></div>
|
<div class="col-8">
|
||||||
|
<input type="password" name="password1" id="password1" />
|
||||||
|
<span id="password1Error" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-4">Повтор пароля:</div>
|
<div class="col-4">Повтор пароля:</div>
|
||||||
<div class="col-8"><input type="password" name="password2" /></div>
|
<div class="col-8">
|
||||||
|
<input type="password" name="password2" id="password2" />
|
||||||
|
<span id="password2Error" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-8"></div>
|
<div class="col-8"></div>
|
||||||
<div class="col-4"><input type="submit" value="Регистрация" class="btn btn-primary" /></div>
|
<div class="col-4"><input type="submit" value="Регистрация" class="btn btn-primary" /></div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||||
|
<script>
|
||||||
|
$(document).ready(function () {
|
||||||
|
$('#registerForm').submit(function(event) {
|
||||||
|
var name = $('#name').val();
|
||||||
|
var login = $('#login').val();
|
||||||
|
var email = $('#email').val();
|
||||||
|
var password1 = $('#password1').val();
|
||||||
|
var password2 = $('#password2').val();
|
||||||
|
var isValid = true;
|
||||||
|
|
||||||
|
$('#nameError').text('');
|
||||||
|
$('#loginError').text('');
|
||||||
|
$('#emailError').text('');
|
||||||
|
$('#password1Error').text('');
|
||||||
|
$('#password2Error').text('');
|
||||||
|
|
||||||
|
// Валидация имени
|
||||||
|
if (name.length < 2 || name.length > 20) {
|
||||||
|
$('#nameError').text('Имя должно быть от 2 до 20 символов.');
|
||||||
|
isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Валидация логина
|
||||||
|
if (login.length < 5 || login.length > 50) {
|
||||||
|
$('#loginError').text('Логин должен быть от 5 до 50 символов.');
|
||||||
|
isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Валидация почты
|
||||||
|
var emailPattern = /^[a-zA-Z0-9._-]+@@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
|
||||||
|
if (!emailPattern.test(email)) {
|
||||||
|
$('#emailError').text('Неверный формат почты.');
|
||||||
|
isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Валидация пароля
|
||||||
|
if (password1.length < 8 || password1.length > 20) {
|
||||||
|
$('#password1Error').text('Пароль должен быть от 8 до 20 символов.');
|
||||||
|
isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Проверка совпадения паролей
|
||||||
|
if (password1 !== password2) {
|
||||||
|
$('#password2Error').text('Пароли не совпадают.');
|
||||||
|
isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isValid) {
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
@ -6,6 +6,6 @@
|
|||||||
<h1 class="display-4">Меню создания отчетов</h1>
|
<h1 class="display-4">Меню создания отчетов</h1>
|
||||||
<div class="list-group">
|
<div class="list-group">
|
||||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="DetailWorkshopReport">Отчет деталь-цех</a>
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="DetailWorkshopReport">Отчет деталь-цех</a>
|
||||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="DetailTimeReport">Отчет по деталям по датам</a>
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="DetailTimeChoose">Отчет по деталям по датам</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
<!DOCTYPE html>
|
@{
|
||||||
|
ViewData["Name"] = UserImplementer.user == null ? "Пользователь" : UserImplementer.user.Name;
|
||||||
|
}
|
||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
@ -13,7 +17,8 @@
|
|||||||
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
|
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<img src="~/images/Work-transformed.png" width="150" height="150" alt="Логотип">
|
<img src="~/images/Work-transformed.png" width="150" height="150" alt="Логотип">
|
||||||
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">Исполнитель</a>
|
<a asp-controller="Home" asp-action="Index">Приложение "Завод "Иди работать". Исполнитель"</a>
|
||||||
|
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Privacy">@ViewData["Name"]</a>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
</header>
|
</header>
|
||||||
|
16
Course/ImplementerApp/log4net.config
Normal file
16
Course/ImplementerApp/log4net.config
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<log4net>
|
||||||
|
<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
|
||||||
|
<file value="c:/temp/GoWorkCourse.log" />
|
||||||
|
<appendToFile value="true" />
|
||||||
|
<maximumFileSize value="100KB" />
|
||||||
|
<maxSizeRollBackups value="2" />
|
||||||
|
<layout type="log4net.Layout.PatternLayout">
|
||||||
|
<conversionPattern value="%date %5level %logger.%method [%line] - MESSAGE: %message%newline %exception" />
|
||||||
|
</layout>
|
||||||
|
</appender>
|
||||||
|
<root>
|
||||||
|
<level value="TRACE" />
|
||||||
|
<appender-ref ref="RollingFile" />
|
||||||
|
</root>
|
||||||
|
</log4net>
|
Loading…
Reference in New Issue
Block a user