Update BusinessLogic and some storages #1
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ 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.UserId).Select(x => x.GetViewModel).ToList();
|
return context.Details.Where(x => x.UserId == model.UserId).Select(x => x.GetViewModel).ToList();
|
||||||
|
|
||||||
|
@ -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.UserId).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)
|
||||||
{
|
{
|
||||||
|
@ -6,6 +6,7 @@ using Contracts.BusinessLogicsContracts;
|
|||||||
using Contracts.ViewModels;
|
using Contracts.ViewModels;
|
||||||
using DataModels.Models;
|
using DataModels.Models;
|
||||||
using Contracts.BindingModels;
|
using Contracts.BindingModels;
|
||||||
|
using DatabaseImplement.Models;
|
||||||
|
|
||||||
namespace ImplementerApp.Controllers
|
namespace ImplementerApp.Controllers
|
||||||
{
|
{
|
||||||
@ -19,6 +20,7 @@ namespace ImplementerApp.Controllers
|
|||||||
_data = data;
|
_data = data;
|
||||||
}
|
}
|
||||||
private bool IsLoggedIn { get {return UserImplementer.user != null; } }
|
private bool IsLoggedIn { get {return UserImplementer.user != null; } }
|
||||||
|
private int UserId { get { return UserImplementer.user!.Id; } }
|
||||||
public IActionResult IndexNonReg()
|
public IActionResult IndexNonReg()
|
||||||
{
|
{
|
||||||
if (!IsLoggedIn)
|
if (!IsLoggedIn)
|
||||||
@ -53,6 +55,11 @@ namespace ImplementerApp.Controllers
|
|||||||
{
|
{
|
||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
|
public IActionResult Logout()
|
||||||
|
{
|
||||||
|
UserImplementer.user = null;
|
||||||
|
return RedirectToAction("IndexNonReg");
|
||||||
|
}
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public void Register(string name, string login, string email, string password1, string password2)
|
public void Register(string name, string login, string email, string password1, string password2)
|
||||||
{
|
{
|
||||||
@ -233,32 +240,66 @@ namespace ImplementerApp.Controllers
|
|||||||
return View(model);
|
return View(model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
[HttpGet]
|
||||||
public IActionResult Privacy()
|
public IActionResult Privacy()
|
||||||
{
|
{
|
||||||
if (IsLoggedIn)
|
if (IsLoggedIn)
|
||||||
return View(UserImplementer.user);
|
return View(UserImplementer.user);
|
||||||
return RedirectToAction("IndexNonReg");
|
return RedirectToAction("IndexNonReg");
|
||||||
}
|
}
|
||||||
public IActionResult DetailTimeReport()
|
[HttpPost]
|
||||||
|
public IActionResult Privacy(int id, string login, string email, string password, string name)
|
||||||
{
|
{
|
||||||
List<DetailTimeReport> detailTimeReports = new List<DetailTimeReport>
|
if (!IsLoggedIn)
|
||||||
{
|
return RedirectToAction("IndexNonReg");
|
||||||
new DetailTimeReport
|
ImplementerBindingModel user = new() { Id = id, Login = login, Email = email, Password = password, Name = name };
|
||||||
{
|
if (_data.UpdateUser(user))
|
||||||
DetailName = "Деталь А",
|
{
|
||||||
Productions = new List<string> { "Производство 1", "Производство 2" },
|
UserImplementer.user = new ImplementerViewModel { Id = id, Login = login, Password = password, Name = name, Email = email };
|
||||||
Products = new List<string> { "Машина X", "Машина Y" }
|
}
|
||||||
},
|
return View(user);
|
||||||
new DetailTimeReport
|
|
||||||
{
|
|
||||||
DetailName = "Деталь B",
|
|
||||||
Productions = new List<string> { "Производство 3", "Производство 4" },
|
|
||||||
Products = new List<string> { "Машина Z", "Машина W" }
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return View(detailTimeReports);
|
|
||||||
}
|
}
|
||||||
public IActionResult DetailWorkshopReport()
|
[HttpGet]
|
||||||
|
public IActionResult DetailTimeChoose()
|
||||||
|
{
|
||||||
|
if (!IsLoggedIn)
|
||||||
|
return RedirectToAction("IndexNonReg");
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
[HttpPost]
|
||||||
|
public IActionResult SendReport(DateTime startDate, DateTime endDate)
|
||||||
|
{
|
||||||
|
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
[HttpPost]
|
||||||
|
public IActionResult TimeReportWeb(DateTime startDate, DateTime endDate)
|
||||||
|
{
|
||||||
|
if (!IsLoggedIn)
|
||||||
|
return RedirectToAction("IndexNonReg");
|
||||||
|
|
||||||
|
|
||||||
|
HttpContext.Session.SetString("StartDate", startDate.ToString());
|
||||||
|
HttpContext.Session.SetString("EndDate", endDate.ToString());
|
||||||
|
|
||||||
|
return RedirectToAction("DetailTimeReport");
|
||||||
|
}
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult DetailTimeReport()
|
||||||
|
{
|
||||||
|
var startDateStr = HttpContext.Session.GetString("StartDate");
|
||||||
|
var endDateStr = HttpContext.Session.GetString("EndDate");
|
||||||
|
var startDate = DateTime.Parse(startDateStr);
|
||||||
|
var endDate = DateTime.Parse(endDateStr).AddDays(1);
|
||||||
|
|
||||||
|
var values = _data.GetTimeReport(startDate, endDate, UserId);
|
||||||
|
|
||||||
|
ViewBag.StartDate = startDate;
|
||||||
|
ViewBag.EndDate = endDate;
|
||||||
|
|
||||||
|
return View(values);
|
||||||
|
}
|
||||||
|
public IActionResult DetailWorkshopReport()
|
||||||
{
|
{
|
||||||
List<DetailWorkshopReportViewModel> detailWorkshopReports = new List<DetailWorkshopReportViewModel>
|
List<DetailWorkshopReportViewModel> detailWorkshopReports = new List<DetailWorkshopReportViewModel>
|
||||||
{
|
{
|
||||||
@ -279,29 +320,29 @@ 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)]
|
||||||
public IActionResult Error()
|
public IActionResult Error()
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
<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="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -13,14 +13,16 @@ namespace ImplementerApp
|
|||||||
private readonly IDetailLogic _detailLogic;
|
private readonly IDetailLogic _detailLogic;
|
||||||
private readonly IProductionLogic _productionLogic;
|
private readonly IProductionLogic _productionLogic;
|
||||||
private readonly IProductLogic _productLogic;
|
private readonly IProductLogic _productLogic;
|
||||||
|
private readonly IMachineLogic _machineLogic;
|
||||||
|
|
||||||
public ImplementerData(ILogger<ImplementerData> logger, IImplementerLogic implementerLogic, IDetailLogic detailLogic, IProductionLogic productionLogic, IProductLogic productLogic)
|
public ImplementerData(ILogger<ImplementerData> logger, IImplementerLogic implementerLogic, IDetailLogic detailLogic, IProductionLogic productionLogic, IProductLogic productLogic, IMachineLogic machineLogic)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_implementerLogic = implementerLogic;
|
_implementerLogic = implementerLogic;
|
||||||
_detailLogic = detailLogic;
|
_detailLogic = detailLogic;
|
||||||
_productionLogic = productionLogic;
|
_productionLogic = productionLogic;
|
||||||
_productLogic = productLogic;
|
_productLogic = productLogic;
|
||||||
|
_machineLogic = machineLogic;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ImplementerViewModel? Login(string login, string password)
|
public ImplementerViewModel? Login(string login, string password)
|
||||||
@ -31,12 +33,10 @@ namespace ImplementerApp
|
|||||||
Password = password
|
Password = password
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Register(ImplementerBindingModel model)
|
public bool Register(ImplementerBindingModel model)
|
||||||
{
|
{
|
||||||
return _implementerLogic.Create(model);
|
return _implementerLogic.Create(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool UpdateUser(ImplementerBindingModel model)
|
public bool UpdateUser(ImplementerBindingModel model)
|
||||||
{
|
{
|
||||||
return _implementerLogic.Update(model);
|
return _implementerLogic.Update(model);
|
||||||
@ -46,7 +46,6 @@ namespace ImplementerApp
|
|||||||
{
|
{
|
||||||
return _detailLogic.ReadList(new DetailSearchModel() { UserId = userId });
|
return _detailLogic.ReadList(new DetailSearchModel() { UserId = userId });
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool DeleteDetail(int detailId)
|
public bool DeleteDetail(int detailId)
|
||||||
{
|
{
|
||||||
return _detailLogic.Delete(new() { Id = detailId });
|
return _detailLogic.Delete(new() { Id = detailId });
|
||||||
@ -68,12 +67,10 @@ namespace ImplementerApp
|
|||||||
{
|
{
|
||||||
return _productLogic.ReadList(new ProductSearchModel() { UserId = userId });
|
return _productLogic.ReadList(new ProductSearchModel() { UserId = userId });
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProductViewModel? GetProduct(int id)
|
public ProductViewModel? GetProduct(int id)
|
||||||
{
|
{
|
||||||
return _productLogic.ReadElement(new() { Id = id });
|
return _productLogic.ReadElement(new() { Id = id });
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool UpdateProduct(ProductBindingModel model)
|
public bool UpdateProduct(ProductBindingModel model)
|
||||||
{
|
{
|
||||||
return _productLogic.Update(model);
|
return _productLogic.Update(model);
|
||||||
@ -106,6 +103,32 @@ namespace ImplementerApp
|
|||||||
public bool DeleteProduction(int productionId)
|
public bool DeleteProduction(int productionId)
|
||||||
{
|
{
|
||||||
return _productionLogic.Delete(new() { Id = 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ using Contracts.BusinessLogicsContracts;
|
|||||||
using Contracts.StoragesContracts;
|
using Contracts.StoragesContracts;
|
||||||
using DatabaseImplement.Implements;
|
using DatabaseImplement.Implements;
|
||||||
using ImplementerApp;
|
using ImplementerApp;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
@ -15,12 +16,20 @@ builder.Services.AddTransient<IImplementerStorage, ImplementerStorage>();
|
|||||||
builder.Services.AddTransient<IDetailStorage, DetailStorage>();
|
builder.Services.AddTransient<IDetailStorage, DetailStorage>();
|
||||||
builder.Services.AddTransient<IProductStorage, ProductStorage>();
|
builder.Services.AddTransient<IProductStorage, ProductStorage>();
|
||||||
builder.Services.AddTransient<IProductionStorage, ProductionStorage>();
|
builder.Services.AddTransient<IProductionStorage, ProductionStorage>();
|
||||||
|
builder.Services.AddTransient<IMachineStorage, MachineStorage>();
|
||||||
builder.Services.AddTransient<IImplementerLogic, ImplementerLogic>();
|
builder.Services.AddTransient<IImplementerLogic, ImplementerLogic>();
|
||||||
builder.Services.AddTransient<IDetailLogic, DetailLogic>();
|
builder.Services.AddTransient<IDetailLogic, DetailLogic>();
|
||||||
builder.Services.AddTransient<IProductionLogic, ProductionLogic>();
|
builder.Services.AddTransient<IProductionLogic, ProductionLogic>();
|
||||||
builder.Services.AddTransient<IProductLogic, ProductLogic>();
|
builder.Services.AddTransient<IProductLogic, ProductLogic>();
|
||||||
|
builder.Services.AddTransient<IMachineLogic, MachineLogic>();
|
||||||
builder.Services.AddTransient<ImplementerData>();
|
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();
|
||||||
|
|
||||||
@ -34,7 +43,7 @@ app.UseHttpsRedirection();
|
|||||||
app.UseStaticFiles();
|
app.UseStaticFiles();
|
||||||
|
|
||||||
app.UseRouting();
|
app.UseRouting();
|
||||||
|
app.UseSession();
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
|
||||||
app.MapControllerRoute(
|
app.MapControllerRoute(
|
||||||
|
@ -1,23 +1,57 @@
|
|||||||
@using Contracts.ViewModels;
|
@using Contracts.ViewModels;
|
||||||
@{
|
@{
|
||||||
ViewData["Title"] = "CreateDetail";
|
ViewData["Title"] = "CreateDetail";
|
||||||
}
|
}
|
||||||
@model DetailViewModel;
|
@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="title" id="title" value="@Model.Id" hidden="hidden"/>
|
<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="name" id="name" value="@Model.Name"/></div>
|
<div class="col-8">
|
||||||
</div>
|
<input type="text" name="name" id="name" value="@Model.Name" />
|
||||||
<div class="row">
|
<span id="nameError" class="text-danger"></span>
|
||||||
<div class="col-4">Цена:</div>
|
</div>
|
||||||
<div class="col-8"><input type="text" name="cost" id="cost" value="@Model.Cost"/></div>
|
</div>
|
||||||
</div>
|
<div class="row">
|
||||||
<div class="row">
|
<div class="col-4">Цена:</div>
|
||||||
<div class="col-8"></div>
|
<div class="col-8">
|
||||||
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div>
|
<input type="text" name="cost" id="cost" value="@Model.Cost" />
|
||||||
</div>
|
<span id="costError" class="text-danger"></span>
|
||||||
</form>
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-8"></div>
|
||||||
|
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||||
|
<script>
|
||||||
|
$(document).ready(function () {
|
||||||
|
$('#detailForm').submit(function (event) {
|
||||||
|
var name = $('#name').val();
|
||||||
|
var 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>
|
||||||
|
@ -9,10 +9,13 @@
|
|||||||
<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>
|
||||||
@ -79,7 +82,7 @@
|
|||||||
$('#sum').val(sum.toFixed(2));
|
$('#sum').val(sum.toFixed(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
$('.deleteDetail').click(function () {
|
$(document).on('click', '.deleteDetail', function () {
|
||||||
var row = $(this).closest('tr');
|
var row = $(this).closest('tr');
|
||||||
row.remove();
|
row.remove();
|
||||||
updateSum();
|
updateSum();
|
||||||
@ -96,34 +99,69 @@
|
|||||||
var detailName = selectedDetail.text();
|
var detailName = selectedDetail.text();
|
||||||
var detailCost = selectedDetail.data('cost');
|
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 = `
|
var newRow = `
|
||||||
<tr data-detail-id="${detailId}">
|
<tr data-detail-id="${detailId}">
|
||||||
<td>
|
<td>
|
||||||
<input type="hidden" name="detailIds" value="${detailId}" />
|
<input type="hidden" name="detailIds" value="${detailId}" />
|
||||||
${detailName}
|
${detailName}
|
||||||
</td>
|
</td>
|
||||||
<td><input type="number" name="counts" value="0" min="0" class="form-control detail-count" data-cost="${detailCost}" /></td>
|
<td><input type="number" name="counts" value="0" min="1" class="form-control detail-count" data-cost="${detailCost}" /></td>
|
||||||
<td>${detailCost}</td>
|
<td>${detailCost}</td>
|
||||||
<td><button type="button" class="deleteDetail" data-detail-id="${detailId}">Удалить</button></td>
|
<td><button type="button" class="deleteDetail" data-detail-id="${detailId}">Удалить</button></td>
|
||||||
</tr>
|
</tr>
|
||||||
`;
|
`;
|
||||||
$('#detailsTable tbody').append(newRow);
|
$('#detailsTable tbody').append(newRow);
|
||||||
|
|
||||||
$('.deleteDetail').off('click').on('click', function () {
|
updateSum();
|
||||||
var row = $(this).closest('tr');
|
|
||||||
row.remove();
|
|
||||||
updateSum();
|
|
||||||
});
|
|
||||||
|
|
||||||
$('.detail-count').off('change').on('change', function () {
|
|
||||||
updateSum();
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#detailSelect').val('');
|
$('#detailSelect').val('');
|
||||||
} else {
|
} else {
|
||||||
alert('Выберите деталь для добавления');
|
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();
|
updateSum();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@ -9,10 +9,13 @@
|
|||||||
<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" value="@Model.Name"/></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>
|
||||||
@ -30,7 +33,7 @@
|
|||||||
{
|
{
|
||||||
<tr data-detail-id="@detail.Value.Id">
|
<tr data-detail-id="@detail.Value.Id">
|
||||||
<td>
|
<td>
|
||||||
<input type="number" hidden="hidden" name="detailIds" value="@detail.Value.Id" />
|
<input type="hidden" name="detailIds" value="@detail.Value.Id" />
|
||||||
@detail.Value.Name
|
@detail.Value.Name
|
||||||
</td>
|
</td>
|
||||||
<td class="detail-cost" data-cost="@detail.Value.Cost">@detail.Value.Cost</td>
|
<td class="detail-cost" data-cost="@detail.Value.Cost">@detail.Value.Cost</td>
|
||||||
@ -72,7 +75,7 @@
|
|||||||
$('#sum').val(sum.toFixed(2));
|
$('#sum').val(sum.toFixed(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
$('.deleteDetail').off('click').on('click', function () {
|
$(document).on('click', '.deleteDetail', function () {
|
||||||
var row = $(this).closest('tr');
|
var row = $(this).closest('tr');
|
||||||
row.remove();
|
row.remove();
|
||||||
updateSum();
|
updateSum();
|
||||||
@ -81,6 +84,7 @@
|
|||||||
$('#addDetail').click(function () {
|
$('#addDetail').click(function () {
|
||||||
var selectedDetail = $('#detailSelect option:selected');
|
var selectedDetail = $('#detailSelect option:selected');
|
||||||
if (selectedDetail.val()) {
|
if (selectedDetail.val()) {
|
||||||
|
var detailId = selectedDetail.val();
|
||||||
var exists = false;
|
var exists = false;
|
||||||
$('#detailsTable tbody tr').each(function () {
|
$('#detailsTable tbody tr').each(function () {
|
||||||
if ($(this).data('detail-id') == detailId) {
|
if ($(this).data('detail-id') == detailId) {
|
||||||
@ -88,22 +92,24 @@
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (exists) { return; }
|
if (exists) {
|
||||||
|
alert('Эта деталь уже добавлена.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var detailId = selectedDetail.val();
|
|
||||||
var detailName = selectedDetail.text();
|
var detailName = selectedDetail.text();
|
||||||
var detailCost = selectedDetail.data('cost');
|
var detailCost = selectedDetail.data('cost');
|
||||||
|
|
||||||
var newRow = `
|
var newRow = `
|
||||||
<tr data-detail-id="${detailId}">
|
<tr data-detail-id="${detailId}">
|
||||||
<td>
|
<td>
|
||||||
<input type="hidden" name="detailIds" value="${detailId}" />
|
<input type="hidden" name="detailIds" value="${detailId}" />
|
||||||
${detailName}
|
${detailName}
|
||||||
</td>
|
</td>
|
||||||
<td class="detail-cost" data-cost="${detailCost}">${detailCost}</td>
|
<td class="detail-cost" data-cost="${detailCost}">${detailCost}</td>
|
||||||
<td><button type="button" class="deleteDetail" data-detail-id="${detailId}">Удалить</button></td>
|
<td><button type="button" class="deleteDetail" data-detail-id="${detailId}">Удалить</button></td>
|
||||||
</tr>
|
</tr>
|
||||||
`;
|
`;
|
||||||
$('#detailsTable tbody').append(newRow);
|
$('#detailsTable tbody').append(newRow);
|
||||||
|
|
||||||
$('.deleteDetail').off('click').on('click', function () {
|
$('.deleteDetail').off('click').on('click', function () {
|
||||||
@ -120,6 +126,27 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#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();
|
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>
|
@ -10,5 +10,7 @@
|
|||||||
<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="Logout">Выйти</a>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -32,6 +32,9 @@
|
|||||||
<th>
|
<th>
|
||||||
Цена
|
Цена
|
||||||
</th>
|
</th>
|
||||||
|
<th>
|
||||||
|
Станок
|
||||||
|
</th>
|
||||||
<th>
|
<th>
|
||||||
Привязка станка к изделию
|
Привязка станка к изделию
|
||||||
</th>
|
</th>
|
||||||
@ -56,6 +59,9 @@
|
|||||||
<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>
|
||||||
|
@ -2,28 +2,87 @@
|
|||||||
ViewData["Title"] = "Privacy Policy";
|
ViewData["Title"] = "Privacy Policy";
|
||||||
}
|
}
|
||||||
<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="login" value="@Model.Id" hidden="hidden"/>
|
<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">
|
||||||
</div>
|
<input type="text" name="login" id="login" value="@Model.Login" />
|
||||||
<div class="row">
|
<span id="loginError" class="text-danger"></span>
|
||||||
<div class="col-4">Почта:</div>
|
</div>
|
||||||
<div class="col-8"><input type="email" name="email" value="@Model.Email" /></div>
|
</div>
|
||||||
</div>
|
<div class="row">
|
||||||
<div class="row">
|
<div class="col-4">Почта:</div>
|
||||||
<div class="col-4">Пароль:</div>
|
<div class="col-8">
|
||||||
<div class="col-8"><input type="password" name="password" value="@Model.Password" /></div>
|
<input type="email" name="email" id="email" value="@Model.Email" />
|
||||||
</div>
|
<span id="emailError" class="text-danger"></span>
|
||||||
<div class="row">
|
</div>
|
||||||
<div class="col-4">ФИО:</div>
|
</div>
|
||||||
<div class="col-8"><input type="text" name="fio" value="@Model.Name" /></div>
|
<div class="row">
|
||||||
</div>
|
<div class="col-4">Пароль:</div>
|
||||||
<div class="row">
|
<div class="col-8">
|
||||||
<div class="col-8"></div>
|
<input type="password" name="password" id="password" value="@Model.Password" />
|
||||||
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div>
|
<span id="passwordError" class="text-danger"></span>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-4">ФИО:</div>
|
||||||
|
<div class="col-8">
|
||||||
|
<input type="text" name="fio" id="fio" value="@Model.Name" />
|
||||||
|
<span id="fioError" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-8"></div>
|
||||||
|
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<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>
|
||||||
|
@ -1,33 +1,103 @@
|
|||||||
@{
|
@{
|
||||||
ViewData["Title"] = "Register";
|
ViewData["Title"] = "Register";
|
||||||
}
|
}
|
||||||
|
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<h2 class="display-4">Регистрация</h2>
|
<h2 class="display-4">Регистрация</h2>
|
||||||
</div>
|
</div>
|
||||||
<form method="post">
|
<form id="registerForm" method="post">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-4">Имя:</div>
|
<div class="col-4">Имя:</div>
|
||||||
<div class="col-8"><input type="text" name="name" /></div>
|
<div class="col-8">
|
||||||
</div>
|
<input type="text" name="name" id="name" />
|
||||||
<div class="row">
|
<span id="nameError" class="text-danger"></span>
|
||||||
<div class="col-4">Логин:</div>
|
</div>
|
||||||
<div class="col-8"><input type="text" name="login" /></div>
|
</div>
|
||||||
</div>
|
<div class="row">
|
||||||
<div class="row">
|
<div class="col-4">Логин:</div>
|
||||||
<div class="col-4">Почта:</div>
|
<div class="col-8">
|
||||||
<div class="col-8"><input type="email" name="email" /></div>
|
<input type="text" name="login" id="login" />
|
||||||
</div>
|
<span id="loginError" class="text-danger"></span>
|
||||||
<div class="row">
|
</div>
|
||||||
<div class="col-4">Пароль:</div>
|
</div>
|
||||||
<div class="col-8"><input type="password" name="password1" /></div>
|
<div class="row">
|
||||||
</div>
|
<div class="col-4">Почта:</div>
|
||||||
<div class="row">
|
<div class="col-8">
|
||||||
<div class="col-4">Повтор пароля:</div>
|
<input type="email" name="email" id="email" />
|
||||||
<div class="col-8"><input type="password" name="password2" /></div>
|
<span id="emailError" class="text-danger"></span>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
</div>
|
||||||
<div class="col-8"></div>
|
<div class="row">
|
||||||
<div class="col-4"><input type="submit" value="Регистрация" class="btn btn-primary" /></div>
|
<div class="col-4">Пароль:</div>
|
||||||
</div>
|
<div class="col-8">
|
||||||
</form>
|
<input type="password" name="password1" id="password1" />
|
||||||
|
<span id="password1Error" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-4">Повтор пароля:</div>
|
||||||
|
<div class="col-8">
|
||||||
|
<input type="password" name="password2" id="password2" />
|
||||||
|
<span id="password2Error" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-8"></div>
|
||||||
|
<div class="col-4"><input type="submit" value="Регистрация" class="btn btn-primary" /></div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||||
|
<script>
|
||||||
|
$(document).ready(function () {
|
||||||
|
$('#registerForm').submit(function(event) {
|
||||||
|
var name = $('#name').val();
|
||||||
|
var login = $('#login').val();
|
||||||
|
var email = $('#email').val();
|
||||||
|
var password1 = $('#password1').val();
|
||||||
|
var password2 = $('#password2').val();
|
||||||
|
var isValid = true;
|
||||||
|
|
||||||
|
$('#nameError').text('');
|
||||||
|
$('#loginError').text('');
|
||||||
|
$('#emailError').text('');
|
||||||
|
$('#password1Error').text('');
|
||||||
|
$('#password2Error').text('');
|
||||||
|
|
||||||
|
// Валидация имени
|
||||||
|
if (name.length < 2 || name.length > 20) {
|
||||||
|
$('#nameError').text('Имя должно быть от 2 до 20 символов.');
|
||||||
|
isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Валидация логина
|
||||||
|
if (login.length < 5 || login.length > 50) {
|
||||||
|
$('#loginError').text('Логин должен быть от 5 до 50 символов.');
|
||||||
|
isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Валидация почты
|
||||||
|
var emailPattern = /^[a-zA-Z0-9._-]+@@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
|
||||||
|
if (!emailPattern.test(email)) {
|
||||||
|
$('#emailError').text('Неверный формат почты.');
|
||||||
|
isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Валидация пароля
|
||||||
|
if (password1.length < 8 || password1.length > 20) {
|
||||||
|
$('#password1Error').text('Пароль должен быть от 8 до 20 символов.');
|
||||||
|
isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Проверка совпадения паролей
|
||||||
|
if (password1 !== password2) {
|
||||||
|
$('#password2Error').text('Пароли не совпадают.');
|
||||||
|
isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isValid) {
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
@ -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>
|
||||||
|
Loading…
Reference in New Issue
Block a user