From 110ec415604f9b1a8c0507c0fe7d8629fff6fb8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=A1=D0=B5=D1=80?= =?UTF-8?q?=D0=B3=D1=83=D0=BD=D0=BE=D0=B2?= Date: Fri, 17 Nov 2023 09:56:34 +0400 Subject: [PATCH] fix --- .../CustomComponents/CustomComponents.csproj | 2 + Library/CustomComponents/LegendPosition.cs | 10 - Library/CustomComponents/LineChartConfig.cs | 17 - Library/CustomComponents/MergeCells.cs | 14 - .../BigTextComponent.Designer.cs | 0 .../BigTextComponent.cs | 0 .../DiagramComponent.Designer.cs | 0 .../DiagramComponent.cs | 3 +- .../MyNonVisualComponents/LegendPosition.cs | 10 + .../MyNonVisualComponents/LineChartConfig.cs | 17 + .../MyNonVisualComponents/MergeCells.cs | 14 + .../TableComponent.Designer.cs | 0 .../TableComponent.cs | 3 +- .../DateTextBox.Designer.cs | 0 .../{ => MyVisualComponents}/DateTextBox.cs | 0 .../{ => MyVisualComponents}/DateTextBox.resx | 0 .../DropDownList.Designer.cs | 0 .../{ => MyVisualComponents}/DropDownList.cs | 0 .../DropDownList.resx | 0 .../ListBoxObjects.Designer.cs | 0 .../ListBoxObjects.cs | 0 .../ListBoxObjects.resx | 0 .../WordHistogramm.Designer.cs | 36 ++ .../WordHistogramm.cs | 88 +++++ .../WordTableComponent.Designer.cs | 36 ++ .../WordTableComponent.cs | 166 ++++++++++ .../WordTableHeaderComponent.Designer.cs | 36 ++ .../WordTableHeaderComponent.cs | 243 ++++++++++++++ .../BooksForm.Designer.cs | 72 ++++ .../ZhelovanovVisualComponents/BooksForm.cs | 69 ++++ .../ZhelovanovVisualComponents/BooksForm.resx | 60 ++++ .../TableComponent.Designer.cs | 63 ++++ .../TableComponent.cs | 109 +++++++ .../TableComponent.resx | 60 ++++ .../TextBoxComponent.Designer.cs | 71 ++++ .../TextBoxComponent.cs | 129 ++++++++ .../TextBoxComponent.resx | 60 ++++ Library/Library.sln | 22 +- .../BusinessLogics/BookLogic.cs | 60 ++++ .../BusinessLogics/GenreLogic.cs | 61 ++++ .../LibraryBusinessLogic.csproj | 13 + .../BindingModels/BookBindingModel.cs | 15 + .../BindingModels/GenreBindingModel.cs | 8 + .../BusinessLogicsContracts/IBookLogic.cs | 12 + .../BusinessLogicsContracts/IGenreLogic.cs | 12 + .../LibraryContracts/LibraryContracts.csproj | 9 + .../StorageContracts/IBookStorage.cs | 16 + .../StorageContracts/IGenreStorage.cs | 16 + .../ViewModels/BookViewModel.cs | 37 +++ .../ViewModels/GenreViewModel.cs | 9 + .../Implements/BookStorage.cs | 120 +++++++ .../Implements/GenreStorage.cs | 121 +++++++ .../LibraryDatabase.cs | 27 ++ .../LibraryDatabaseImplement.csproj | 23 ++ .../20231116200005_InitialCreate.Designer.cs | 79 +++++ .../20231116200005_InitialCreate.cs | 54 +++ .../LibraryDatabaseModelSnapshot.cs | 76 +++++ .../LibraryDatabaseImplement/Models/Book.cs | 38 +++ .../LibraryDatabaseImplement/Models/Genre.cs | 17 + Library/LibraryView/FormBook.Designer.cs | 167 ++++++++++ Library/LibraryView/FormBook.cs | 128 ++++++++ Library/LibraryView/FormBook.resx | 60 ++++ Library/LibraryView/FormMain.Designer.cs | 95 ++++++ Library/LibraryView/FormMain.cs | 307 ++++++++++++++++++ Library/LibraryView/FormMain.resx | 72 ++++ Library/LibraryView/FormManual.Designer.cs | 85 +++++ Library/LibraryView/FormManual.cs | 113 +++++++ Library/LibraryView/FormManual.resx | 66 ++++ Library/LibraryView/FormSecond.Designer.cs | 6 + Library/LibraryView/FormSecond.cs | 3 +- Library/LibraryView/FormSecond.resx | 9 + Library/LibraryView/LibraryView.csproj | 7 + 72 files changed, 3305 insertions(+), 46 deletions(-) delete mode 100644 Library/CustomComponents/LegendPosition.cs delete mode 100644 Library/CustomComponents/LineChartConfig.cs delete mode 100644 Library/CustomComponents/MergeCells.cs rename Library/CustomComponents/{ => MyNonVisualComponents}/BigTextComponent.Designer.cs (100%) rename Library/CustomComponents/{ => MyNonVisualComponents}/BigTextComponent.cs (100%) rename Library/CustomComponents/{ => MyNonVisualComponents}/DiagramComponent.Designer.cs (100%) rename Library/CustomComponents/{ => MyNonVisualComponents}/DiagramComponent.cs (97%) create mode 100644 Library/CustomComponents/MyNonVisualComponents/LegendPosition.cs create mode 100644 Library/CustomComponents/MyNonVisualComponents/LineChartConfig.cs create mode 100644 Library/CustomComponents/MyNonVisualComponents/MergeCells.cs rename Library/CustomComponents/{ => MyNonVisualComponents}/TableComponent.Designer.cs (100%) rename Library/CustomComponents/{ => MyNonVisualComponents}/TableComponent.cs (98%) rename Library/CustomComponents/{ => MyVisualComponents}/DateTextBox.Designer.cs (100%) rename Library/CustomComponents/{ => MyVisualComponents}/DateTextBox.cs (100%) rename Library/CustomComponents/{ => MyVisualComponents}/DateTextBox.resx (100%) rename Library/CustomComponents/{ => MyVisualComponents}/DropDownList.Designer.cs (100%) rename Library/CustomComponents/{ => MyVisualComponents}/DropDownList.cs (100%) rename Library/CustomComponents/{ => MyVisualComponents}/DropDownList.resx (100%) rename Library/CustomComponents/{ => MyVisualComponents}/ListBoxObjects.Designer.cs (100%) rename Library/CustomComponents/{ => MyVisualComponents}/ListBoxObjects.cs (100%) rename Library/CustomComponents/{ => MyVisualComponents}/ListBoxObjects.resx (100%) create mode 100644 Library/CustomComponents/ZhelovanovNonVisualComponents/WordHistogramm.Designer.cs create mode 100644 Library/CustomComponents/ZhelovanovNonVisualComponents/WordHistogramm.cs create mode 100644 Library/CustomComponents/ZhelovanovNonVisualComponents/WordTableComponent.Designer.cs create mode 100644 Library/CustomComponents/ZhelovanovNonVisualComponents/WordTableComponent.cs create mode 100644 Library/CustomComponents/ZhelovanovNonVisualComponents/WordTableHeaderComponent.Designer.cs create mode 100644 Library/CustomComponents/ZhelovanovNonVisualComponents/WordTableHeaderComponent.cs create mode 100644 Library/CustomComponents/ZhelovanovVisualComponents/BooksForm.Designer.cs create mode 100644 Library/CustomComponents/ZhelovanovVisualComponents/BooksForm.cs create mode 100644 Library/CustomComponents/ZhelovanovVisualComponents/BooksForm.resx create mode 100644 Library/CustomComponents/ZhelovanovVisualComponents/TableComponent.Designer.cs create mode 100644 Library/CustomComponents/ZhelovanovVisualComponents/TableComponent.cs create mode 100644 Library/CustomComponents/ZhelovanovVisualComponents/TableComponent.resx create mode 100644 Library/CustomComponents/ZhelovanovVisualComponents/TextBoxComponent.Designer.cs create mode 100644 Library/CustomComponents/ZhelovanovVisualComponents/TextBoxComponent.cs create mode 100644 Library/CustomComponents/ZhelovanovVisualComponents/TextBoxComponent.resx create mode 100644 Library/LibraryBusinessLogic/BusinessLogics/BookLogic.cs create mode 100644 Library/LibraryBusinessLogic/BusinessLogics/GenreLogic.cs create mode 100644 Library/LibraryBusinessLogic/LibraryBusinessLogic.csproj create mode 100644 Library/LibraryContracts/BindingModels/BookBindingModel.cs create mode 100644 Library/LibraryContracts/BindingModels/GenreBindingModel.cs create mode 100644 Library/LibraryContracts/BusinessLogicsContracts/IBookLogic.cs create mode 100644 Library/LibraryContracts/BusinessLogicsContracts/IGenreLogic.cs create mode 100644 Library/LibraryContracts/LibraryContracts.csproj create mode 100644 Library/LibraryContracts/StorageContracts/IBookStorage.cs create mode 100644 Library/LibraryContracts/StorageContracts/IGenreStorage.cs create mode 100644 Library/LibraryContracts/ViewModels/BookViewModel.cs create mode 100644 Library/LibraryContracts/ViewModels/GenreViewModel.cs create mode 100644 Library/LibraryDatabaseImplement/Implements/BookStorage.cs create mode 100644 Library/LibraryDatabaseImplement/Implements/GenreStorage.cs create mode 100644 Library/LibraryDatabaseImplement/LibraryDatabase.cs create mode 100644 Library/LibraryDatabaseImplement/LibraryDatabaseImplement.csproj create mode 100644 Library/LibraryDatabaseImplement/Migrations/20231116200005_InitialCreate.Designer.cs create mode 100644 Library/LibraryDatabaseImplement/Migrations/20231116200005_InitialCreate.cs create mode 100644 Library/LibraryDatabaseImplement/Migrations/LibraryDatabaseModelSnapshot.cs create mode 100644 Library/LibraryDatabaseImplement/Models/Book.cs create mode 100644 Library/LibraryDatabaseImplement/Models/Genre.cs create mode 100644 Library/LibraryView/FormBook.Designer.cs create mode 100644 Library/LibraryView/FormBook.cs create mode 100644 Library/LibraryView/FormBook.resx create mode 100644 Library/LibraryView/FormMain.Designer.cs create mode 100644 Library/LibraryView/FormMain.cs create mode 100644 Library/LibraryView/FormMain.resx create mode 100644 Library/LibraryView/FormManual.Designer.cs create mode 100644 Library/LibraryView/FormManual.cs create mode 100644 Library/LibraryView/FormManual.resx diff --git a/Library/CustomComponents/CustomComponents.csproj b/Library/CustomComponents/CustomComponents.csproj index 844a19c..decd6b5 100644 --- a/Library/CustomComponents/CustomComponents.csproj +++ b/Library/CustomComponents/CustomComponents.csproj @@ -9,7 +9,9 @@ + + diff --git a/Library/CustomComponents/LegendPosition.cs b/Library/CustomComponents/LegendPosition.cs deleted file mode 100644 index 6d087e5..0000000 --- a/Library/CustomComponents/LegendPosition.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace CustomComponents -{ - public enum LegendPosition - { - Left, - Top, - Right, - Botton, - } -} \ No newline at end of file diff --git a/Library/CustomComponents/LineChartConfig.cs b/Library/CustomComponents/LineChartConfig.cs deleted file mode 100644 index 2de6ab0..0000000 --- a/Library/CustomComponents/LineChartConfig.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Microsoft.Office.Interop.Excel; - -namespace CustomComponents -{ - public class LineChartConfig - { - public string FilePath { get; set; } - - public string Header { get; set; } - - public string ChartTitle { get; set; } - - public Dictionary> Values { get; set; } - - public LegendPosition LegendPosition { get; set; } - } -} \ No newline at end of file diff --git a/Library/CustomComponents/MergeCells.cs b/Library/CustomComponents/MergeCells.cs deleted file mode 100644 index efe8802..0000000 --- a/Library/CustomComponents/MergeCells.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace CustomComponents -{ - public class MergeCells - { - public string Heading; - public int[] CellIndexes; - - public MergeCells(string heading, int[] cellIndexes) - { - Heading = heading; - CellIndexes = cellIndexes; - } - } -} \ No newline at end of file diff --git a/Library/CustomComponents/BigTextComponent.Designer.cs b/Library/CustomComponents/MyNonVisualComponents/BigTextComponent.Designer.cs similarity index 100% rename from Library/CustomComponents/BigTextComponent.Designer.cs rename to Library/CustomComponents/MyNonVisualComponents/BigTextComponent.Designer.cs diff --git a/Library/CustomComponents/BigTextComponent.cs b/Library/CustomComponents/MyNonVisualComponents/BigTextComponent.cs similarity index 100% rename from Library/CustomComponents/BigTextComponent.cs rename to Library/CustomComponents/MyNonVisualComponents/BigTextComponent.cs diff --git a/Library/CustomComponents/DiagramComponent.Designer.cs b/Library/CustomComponents/MyNonVisualComponents/DiagramComponent.Designer.cs similarity index 100% rename from Library/CustomComponents/DiagramComponent.Designer.cs rename to Library/CustomComponents/MyNonVisualComponents/DiagramComponent.Designer.cs diff --git a/Library/CustomComponents/DiagramComponent.cs b/Library/CustomComponents/MyNonVisualComponents/DiagramComponent.cs similarity index 97% rename from Library/CustomComponents/DiagramComponent.cs rename to Library/CustomComponents/MyNonVisualComponents/DiagramComponent.cs index 31ded74..9453688 100644 --- a/Library/CustomComponents/DiagramComponent.cs +++ b/Library/CustomComponents/MyNonVisualComponents/DiagramComponent.cs @@ -1,11 +1,12 @@ using System.ComponentModel; using System.IO; using System.Runtime.InteropServices; +using CustomComponents.MyNonVisualComponents; using Excel = Microsoft.Office.Interop.Excel; namespace CustomComponents { - public partial class DiagramComponent : Component + public partial class DiagramComponent : Component { public DiagramComponent() { diff --git a/Library/CustomComponents/MyNonVisualComponents/LegendPosition.cs b/Library/CustomComponents/MyNonVisualComponents/LegendPosition.cs new file mode 100644 index 0000000..b62986a --- /dev/null +++ b/Library/CustomComponents/MyNonVisualComponents/LegendPosition.cs @@ -0,0 +1,10 @@ +namespace CustomComponents.MyNonVisualComponents +{ + public enum LegendPosition + { + Left, + Top, + Right, + Botton, + } +} \ No newline at end of file diff --git a/Library/CustomComponents/MyNonVisualComponents/LineChartConfig.cs b/Library/CustomComponents/MyNonVisualComponents/LineChartConfig.cs new file mode 100644 index 0000000..737cad2 --- /dev/null +++ b/Library/CustomComponents/MyNonVisualComponents/LineChartConfig.cs @@ -0,0 +1,17 @@ +using Microsoft.Office.Interop.Excel; + +namespace CustomComponents.MyNonVisualComponents +{ + public class LineChartConfig + { + public string FilePath { get; set; } + + public string Header { get; set; } + + public string ChartTitle { get; set; } + + public Dictionary> Values { get; set; } + + public LegendPosition LegendPosition { get; set; } + } +} \ No newline at end of file diff --git a/Library/CustomComponents/MyNonVisualComponents/MergeCells.cs b/Library/CustomComponents/MyNonVisualComponents/MergeCells.cs new file mode 100644 index 0000000..8f9135b --- /dev/null +++ b/Library/CustomComponents/MyNonVisualComponents/MergeCells.cs @@ -0,0 +1,14 @@ +namespace CustomComponents.MyNonVisualComponents +{ + public class MergeCells + { + public string Heading; + public int[] CellIndexes; + + public MergeCells(string heading, int[] cellIndexes) + { + Heading = heading; + CellIndexes = cellIndexes; + } + } +} \ No newline at end of file diff --git a/Library/CustomComponents/TableComponent.Designer.cs b/Library/CustomComponents/MyNonVisualComponents/TableComponent.Designer.cs similarity index 100% rename from Library/CustomComponents/TableComponent.Designer.cs rename to Library/CustomComponents/MyNonVisualComponents/TableComponent.Designer.cs diff --git a/Library/CustomComponents/TableComponent.cs b/Library/CustomComponents/MyNonVisualComponents/TableComponent.cs similarity index 98% rename from Library/CustomComponents/TableComponent.cs rename to Library/CustomComponents/MyNonVisualComponents/TableComponent.cs index 8d35652..4065c98 100644 --- a/Library/CustomComponents/TableComponent.cs +++ b/Library/CustomComponents/MyNonVisualComponents/TableComponent.cs @@ -1,9 +1,10 @@ using System.ComponentModel; +using CustomComponents.MyNonVisualComponents; using Excel = Microsoft.Office.Interop.Excel; namespace CustomComponents { - public partial class TableComponent : Component + public partial class TableComponent : Component { char[] colIndex = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' }; diff --git a/Library/CustomComponents/DateTextBox.Designer.cs b/Library/CustomComponents/MyVisualComponents/DateTextBox.Designer.cs similarity index 100% rename from Library/CustomComponents/DateTextBox.Designer.cs rename to Library/CustomComponents/MyVisualComponents/DateTextBox.Designer.cs diff --git a/Library/CustomComponents/DateTextBox.cs b/Library/CustomComponents/MyVisualComponents/DateTextBox.cs similarity index 100% rename from Library/CustomComponents/DateTextBox.cs rename to Library/CustomComponents/MyVisualComponents/DateTextBox.cs diff --git a/Library/CustomComponents/DateTextBox.resx b/Library/CustomComponents/MyVisualComponents/DateTextBox.resx similarity index 100% rename from Library/CustomComponents/DateTextBox.resx rename to Library/CustomComponents/MyVisualComponents/DateTextBox.resx diff --git a/Library/CustomComponents/DropDownList.Designer.cs b/Library/CustomComponents/MyVisualComponents/DropDownList.Designer.cs similarity index 100% rename from Library/CustomComponents/DropDownList.Designer.cs rename to Library/CustomComponents/MyVisualComponents/DropDownList.Designer.cs diff --git a/Library/CustomComponents/DropDownList.cs b/Library/CustomComponents/MyVisualComponents/DropDownList.cs similarity index 100% rename from Library/CustomComponents/DropDownList.cs rename to Library/CustomComponents/MyVisualComponents/DropDownList.cs diff --git a/Library/CustomComponents/DropDownList.resx b/Library/CustomComponents/MyVisualComponents/DropDownList.resx similarity index 100% rename from Library/CustomComponents/DropDownList.resx rename to Library/CustomComponents/MyVisualComponents/DropDownList.resx diff --git a/Library/CustomComponents/ListBoxObjects.Designer.cs b/Library/CustomComponents/MyVisualComponents/ListBoxObjects.Designer.cs similarity index 100% rename from Library/CustomComponents/ListBoxObjects.Designer.cs rename to Library/CustomComponents/MyVisualComponents/ListBoxObjects.Designer.cs diff --git a/Library/CustomComponents/ListBoxObjects.cs b/Library/CustomComponents/MyVisualComponents/ListBoxObjects.cs similarity index 100% rename from Library/CustomComponents/ListBoxObjects.cs rename to Library/CustomComponents/MyVisualComponents/ListBoxObjects.cs diff --git a/Library/CustomComponents/ListBoxObjects.resx b/Library/CustomComponents/MyVisualComponents/ListBoxObjects.resx similarity index 100% rename from Library/CustomComponents/ListBoxObjects.resx rename to Library/CustomComponents/MyVisualComponents/ListBoxObjects.resx diff --git a/Library/CustomComponents/ZhelovanovNonVisualComponents/WordHistogramm.Designer.cs b/Library/CustomComponents/ZhelovanovNonVisualComponents/WordHistogramm.Designer.cs new file mode 100644 index 0000000..44cf84d --- /dev/null +++ b/Library/CustomComponents/ZhelovanovNonVisualComponents/WordHistogramm.Designer.cs @@ -0,0 +1,36 @@ +namespace KOP_Labs.NonVisualComponents +{ + partial class WordHistogramm + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + } + + #endregion + } +} diff --git a/Library/CustomComponents/ZhelovanovNonVisualComponents/WordHistogramm.cs b/Library/CustomComponents/ZhelovanovNonVisualComponents/WordHistogramm.cs new file mode 100644 index 0000000..59dafbd --- /dev/null +++ b/Library/CustomComponents/ZhelovanovNonVisualComponents/WordHistogramm.cs @@ -0,0 +1,88 @@ +using Aspose.Words; +using Aspose.Words.Drawing; +using Aspose.Words.Drawing.Charts; +using KOP_Labs.Classes; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace KOP_Labs.NonVisualComponents +{ + public partial class WordHistogramm : Component + { + public WordHistogramm() + { + InitializeComponent(); + } + + public WordHistogramm(IContainer container) + { + container.Add(this); + + InitializeComponent(); + } + + public void CreateHistogramm(MyHistogramm myHistogramm) + { + if(!CheckData(myHistogramm._dataList)) { + return; + } + Document doc = new Document(); + DocumentBuilder builder = new DocumentBuilder(doc); + + Aspose.Words.Font font = builder.Font; + font.Size = 14; + font.Bold = true; + font.Color = System.Drawing.Color.Black; + font.Name = "Times New Roman"; + + ParagraphFormat paragraphFormat = builder.ParagraphFormat; + paragraphFormat.FirstLineIndent = 8; + paragraphFormat.SpaceAfter = 24; + paragraphFormat.Alignment = ParagraphAlignment.Center; + paragraphFormat.KeepTogether = true; + + builder.Writeln(myHistogramm._fileHeader); + + Shape shape = builder.InsertChart(ChartType.Column, 500, 270); + Chart chart = shape.Chart; + chart.Title.Text = myHistogramm._fileHeader; + ChartSeriesCollection seriesColl = chart.Series; + + seriesColl.Clear(); + + string[] categories = new string[] { myHistogramm._dataList[0]._nameData }; + + + foreach (var data in myHistogramm._dataList) + { + seriesColl.Add(data._nameData, categories, new double[] { data._data }); + } + + ChartLegend legend = chart.Legend; + + legend.Position = (LegendPosition)myHistogramm._legends; + legend.Overlay = true; + + + doc.Save(myHistogramm._filePath); + + } + private bool CheckData(List data) + { + foreach (var _data in data) + { + if (string.IsNullOrEmpty(_data._data.ToString())) + { + return false; + } + } + + return true; + } + } +} diff --git a/Library/CustomComponents/ZhelovanovNonVisualComponents/WordTableComponent.Designer.cs b/Library/CustomComponents/ZhelovanovNonVisualComponents/WordTableComponent.Designer.cs new file mode 100644 index 0000000..591b1a8 --- /dev/null +++ b/Library/CustomComponents/ZhelovanovNonVisualComponents/WordTableComponent.Designer.cs @@ -0,0 +1,36 @@ +namespace KOP_Labs.NonVisualComponents +{ + partial class WordTableComponent + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + } + + #endregion + } +} diff --git a/Library/CustomComponents/ZhelovanovNonVisualComponents/WordTableComponent.cs b/Library/CustomComponents/ZhelovanovNonVisualComponents/WordTableComponent.cs new file mode 100644 index 0000000..d5e9aaa --- /dev/null +++ b/Library/CustomComponents/ZhelovanovNonVisualComponents/WordTableComponent.cs @@ -0,0 +1,166 @@ + +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.ExtendedProperties; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Spreadsheet; +using DocumentFormat.OpenXml.Wordprocessing; + +using KOP_Labs.Classes; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; +using static System.Windows.Forms.VisualStyles.VisualStyleElement; +using Bold = DocumentFormat.OpenXml.Wordprocessing.Bold; +using BottomBorder = DocumentFormat.OpenXml.Wordprocessing.BottomBorder; +using LeftBorder = DocumentFormat.OpenXml.Wordprocessing.LeftBorder; +using RightBorder = DocumentFormat.OpenXml.Wordprocessing.RightBorder; +using Run = DocumentFormat.OpenXml.Wordprocessing.Run; +using RunProperties = DocumentFormat.OpenXml.Wordprocessing.RunProperties; +using Table = DocumentFormat.OpenXml.Wordprocessing.Table; +using Text = DocumentFormat.OpenXml.Wordprocessing.Text; +using TopBorder = DocumentFormat.OpenXml.Wordprocessing.TopBorder; + +namespace KOP_Labs.NonVisualComponents +{ + public partial class WordTableComponent : Component + { + private WordprocessingDocument? _wordDocument; + + private Body? _docBody; + + public WordTableComponent() + { + InitializeComponent(); + } + + public WordTableComponent(IContainer container) + { + container.Add(this); + + InitializeComponent(); + } + + public void CreateDoc(MyTable myTable) + { + if(!CheckData(myTable._dataList)) return; + _wordDocument = WordprocessingDocument.Create(myTable._filePath, WordprocessingDocumentType.Document); + MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart(); + + mainPart.Document = new Document(); + _docBody = mainPart.Document.AppendChild(new Body()); + _wordDocument.Close(); + + using (WordprocessingDocument doc = WordprocessingDocument.Open(myTable._filePath, true)) + { + + var mainDoc = doc.MainDocumentPart.Document; + mainPart.Document = new Document(); + Body body = mainPart.Document.AppendChild(new Body()); + + Paragraph headerParagraph = new Paragraph(); + + Run headerRun = new Run(new Text(myTable._fileHeader)); + RunProperties runProperties = new RunProperties(); + Bold bold = new Bold(); + runProperties.Append(bold); + + headerRun.Append(runProperties); + + headerParagraph.Append(headerRun); + + Table table = new Table(); + + TableProperties props = new TableProperties( + new TableBorders( + new TopBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new BottomBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new LeftBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new RightBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new InsideHorizontalBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new InsideVerticalBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + } + )); + + table.AppendChild(props); + for (var i = 0; i < myTable._dataList.Count; i++) + { + var tr = new TableRow(); + + for (var j = 0; j < myTable._dataList[i].Length; j++) + { + var tc = new TableCell(); + + tc.Append(new TableCellProperties(new TableCellWidth + { + Type = TableWidthUnitValues.Dxa, + Width = "2000" + } + )); + + tc.Append(new Paragraph(new Run(new Text(myTable._dataList[i][0, j])))); + + tr.Append(tc); + } + + table.Append(tr); + } + + + + mainDoc.Body.Append(headerParagraph); + mainDoc.Body.Append(table); + + + mainDoc.Save(); + } + + + + } + + private bool CheckData(List data) + { + for (int i = 0; i < data.Count; i++) + { + for (int j = 0; j < data[i].Length; j++) + { + if (data[i][0, j] == null) { + return false; + } + } + } + + return true; + } + } + } + + \ No newline at end of file diff --git a/Library/CustomComponents/ZhelovanovNonVisualComponents/WordTableHeaderComponent.Designer.cs b/Library/CustomComponents/ZhelovanovNonVisualComponents/WordTableHeaderComponent.Designer.cs new file mode 100644 index 0000000..c236ad5 --- /dev/null +++ b/Library/CustomComponents/ZhelovanovNonVisualComponents/WordTableHeaderComponent.Designer.cs @@ -0,0 +1,36 @@ +namespace KOP_Labs.NonVisualComponents +{ + partial class WordTableHeaderComponent + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + } + + #endregion + } +} diff --git a/Library/CustomComponents/ZhelovanovNonVisualComponents/WordTableHeaderComponent.cs b/Library/CustomComponents/ZhelovanovNonVisualComponents/WordTableHeaderComponent.cs new file mode 100644 index 0000000..856e7d0 --- /dev/null +++ b/Library/CustomComponents/ZhelovanovNonVisualComponents/WordTableHeaderComponent.cs @@ -0,0 +1,243 @@ +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml; +using KOP_Labs.Classes; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using DocumentFormat.OpenXml.Wordprocessing; + +namespace KOP_Labs.NonVisualComponents +{ + public partial class WordTableHeaderComponent : Component + { + private WordprocessingDocument? _wordDocument; + + private Body? _docBody; + public WordTableHeaderComponent() + { + InitializeComponent(); + } + + public WordTableHeaderComponent(IContainer container) + { + container.Add(this); + + InitializeComponent(); + } + + public void CreateDoc(MyTableWithHead myTable) + { + if (!CheckData(myTable._dataList)) return; + _wordDocument = WordprocessingDocument.Create(myTable._filePath, WordprocessingDocumentType.Document); + MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart(); + + mainPart.Document = new Document(); + + _docBody = mainPart.Document.AppendChild(new Body()); + _wordDocument.Close(); + + using (WordprocessingDocument doc = WordprocessingDocument.Open(myTable._filePath, true)) + { + + var mainDoc = doc.MainDocumentPart.Document; + mainPart.Document = new Document(); + Body body = mainPart.Document.AppendChild(new Body()); + + + Paragraph headerParagraph = new Paragraph(); + Run headerRun = new Run(new Text(myTable._fileHeader)); + + RunProperties runProperties = new RunProperties(); + Bold bold = new Bold(); + runProperties.Append(bold); + headerRun.Append(runProperties); + + headerParagraph.Append(headerRun); + + + Table table = new Table(); + + TableProperties props = new TableProperties( + new TableBorders( + new TopBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new BottomBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new LeftBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new RightBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new InsideHorizontalBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new InsideVerticalBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + } + )); + + table.AppendChild(props); + + var _tr = new TableRow(); + + int indexHeaderHeigh = 0; + int indexHeaderWidth = 0; + + foreach (var item in myTable._columnsSettings) + { + _tr.Append(new TableRowProperties(new TableRowHeight + { + Val = Convert.ToUInt32(myTable._heightRow[indexHeaderHeigh]) + })); + + var tc = new TableCell(); + + tc.Append(new TableCellProperties(new TableCellWidth + { + Type = TableWidthUnitValues.Dxa, + Width = myTable._widthCol[indexHeaderWidth].ToString(), + } + )); + + if (string.IsNullOrEmpty(myTable._columnsSettings[indexHeaderWidth]._nameField) || + string.IsNullOrEmpty(myTable._columnsSettings[indexHeaderWidth]._nameColumn)) + { + return; + } + + Paragraph tableHeader = new(); + + var Run = new Run(); + + var headerProperties = new RunProperties(); + + headerProperties.Append(new Bold()); + + Run.AppendChild(headerProperties); + + Run.AppendChild(new Text(item.Value._nameColumn)); + + tableHeader.AppendChild(Run); + + tc.Append(tableHeader); + + _tr.Append(tc); + + indexHeaderWidth++; + } + + table.Append(_tr); + + + indexHeaderHeigh++; + indexHeaderWidth = 0; + + + + for (int i = 0; i < myTable._dataList.Count; i++) + { + var tr = new TableRow(); + + + foreach (var item in myTable._columnsSettings) + { + tr.Append(new TableRowProperties(new TableRowHeight + { + Val = Convert.ToUInt32(myTable._heightRow[indexHeaderHeigh]) + })); + + var tc = new TableCell(); + + tc.Append(new TableCellProperties(new TableCellWidth + { + Type = TableWidthUnitValues.Dxa, + Width = myTable._widthCol[indexHeaderWidth].ToString(), + } + )); + + + foreach (var val in myTable._dataList[i].GetType().GetProperties()) + { + if (val.Name == item.Value._nameField) + { + var newParagraph = new Paragraph(); + + var newRun = new Run(); + + var runPropertiesInd = new RunProperties(); + + if (indexHeaderWidth == 0) + { + runPropertiesInd.Append(new Bold()); + } + + newRun.AppendChild(runPropertiesInd); + + newRun.AppendChild(new Text(val.GetValue(myTable._dataList[i]).ToString())); + + newParagraph.AppendChild(newRun); + + tc.Append(newParagraph); + + break; + } + } + + tr.Append(tc); + + indexHeaderWidth++; + } + + indexHeaderWidth = 0; + + table.Append(tr); + } + + + + mainDoc.Body.Append(headerParagraph); + + mainDoc.Body.Append(table); + + mainDoc.Save(); + } + } + + private bool CheckData(List dataList) + { + foreach (var data in dataList) + { + foreach (var value in data.GetType().GetProperties()) + { + + if (string.IsNullOrEmpty(value.GetValue(data).ToString())) + { + return false; + } + } + } + + return true; + } + + } +} diff --git a/Library/CustomComponents/ZhelovanovVisualComponents/BooksForm.Designer.cs b/Library/CustomComponents/ZhelovanovVisualComponents/BooksForm.Designer.cs new file mode 100644 index 0000000..817f04c --- /dev/null +++ b/Library/CustomComponents/ZhelovanovVisualComponents/BooksForm.Designer.cs @@ -0,0 +1,72 @@ +namespace KOP_Labs +{ + partial class BooksForm + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + groupBoxComponent = new GroupBox(); + listBoxComponent = new ListBox(); + groupBoxComponent.SuspendLayout(); + SuspendLayout(); + // + // groupBoxComponent + // + groupBoxComponent.Controls.Add(listBoxComponent); + groupBoxComponent.Location = new Point(19, 28); + groupBoxComponent.Name = "groupBoxComponent"; + groupBoxComponent.Size = new Size(517, 183); + groupBoxComponent.TabIndex = 0; + groupBoxComponent.TabStop = false; + groupBoxComponent.Text = "Компонент"; + // + // listBoxComponent + // + listBoxComponent.FormattingEnabled = true; + listBoxComponent.ItemHeight = 20; + listBoxComponent.Location = new Point(24, 35); + listBoxComponent.Name = "listBoxComponent"; + listBoxComponent.Size = new Size(476, 124); + listBoxComponent.TabIndex = 0; + listBoxComponent.SelectedIndexChanged += listBoxComponent_SelectedIndexChanged; + // + // BooksForm + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(groupBoxComponent); + Name = "BooksForm"; + Size = new Size(563, 258); + groupBoxComponent.ResumeLayout(false); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBoxComponent; + private ListBox listBoxComponent; + } +} diff --git a/Library/CustomComponents/ZhelovanovVisualComponents/BooksForm.cs b/Library/CustomComponents/ZhelovanovVisualComponents/BooksForm.cs new file mode 100644 index 0000000..d8fb97c --- /dev/null +++ b/Library/CustomComponents/ZhelovanovVisualComponents/BooksForm.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace KOP_Labs +{ + public partial class BooksForm : UserControl + { + public BooksForm() + { + InitializeComponent(); + } + + public string? SelectedValue + { + get + { + if (listBoxComponent.SelectedItem == null) + { + return null; + } + return listBoxComponent.SelectedItem.ToString()!; + } + set + { + if (value != null && !listBoxComponent.Items.Contains(value)) + { + return; + } + listBoxComponent.SelectedItem = value; + } + } + + private event EventHandler? _selectChanged; + + public event EventHandler SelectChanged + { + add { _selectChanged += value; } + remove { _selectChanged -= value; } + } + + public void FillValues(string values) + { + if (values == null || values.Length == 0) + { + return; + } + listBoxComponent.Items.Add(values); + } + + + + public void ClearList() + { + listBoxComponent.Items.Clear(); + } + + private void listBoxComponent_SelectedIndexChanged(object sender, EventArgs e) + { + _selectChanged?.Invoke(this, e); + } + } +} diff --git a/Library/CustomComponents/ZhelovanovVisualComponents/BooksForm.resx b/Library/CustomComponents/ZhelovanovVisualComponents/BooksForm.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Library/CustomComponents/ZhelovanovVisualComponents/BooksForm.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Library/CustomComponents/ZhelovanovVisualComponents/TableComponent.Designer.cs b/Library/CustomComponents/ZhelovanovVisualComponents/TableComponent.Designer.cs new file mode 100644 index 0000000..8443de6 --- /dev/null +++ b/Library/CustomComponents/ZhelovanovVisualComponents/TableComponent.Designer.cs @@ -0,0 +1,63 @@ +namespace KOP_Labs +{ + partial class TableComponent + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(36, 29); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(300, 188); + dataGridView.TabIndex = 0; + dataGridView.SelectionChanged += SelectionChanged; + dataGridView.RowHeadersVisible = false; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + // + // TableComponent + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(dataGridView); + Name = "TableComponent"; + Size = new Size(542, 301); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + } +} diff --git a/Library/CustomComponents/ZhelovanovVisualComponents/TableComponent.cs b/Library/CustomComponents/ZhelovanovVisualComponents/TableComponent.cs new file mode 100644 index 0000000..353ea81 --- /dev/null +++ b/Library/CustomComponents/ZhelovanovVisualComponents/TableComponent.cs @@ -0,0 +1,109 @@ +using KOP_Labs.Classes; +using System; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace KOP_Labs +{ + public partial class TableComponent : UserControl + { + public event EventHandler TaskHandler; + public int indexRow; + public int IndexRow + { + get + { + return indexRow; + } + set + { + + indexRow = value; + + } + } + public TableComponent() + { + InitializeComponent(); + } + public void TableConfiguration(int countCol, List parameters) + { + if (parameters.Count != parameters.Count) { return; } + for (int i = 0; i < countCol; i++) + { + DataGridViewColumn column = new DataGridViewColumn(); + column.Name = parameters[i]._name; + column.HeaderText = parameters[i]._header; + column.Width = parameters[i]._width; + column.Visible = parameters[i]._isVisual; + column.CellTemplate = new DataGridViewTextBoxCell(); + + dataGridView.Columns.Add(column); + + } + } + public void ClearRows() + { + dataGridView.Rows.Clear(); + } + public void AddRow(T newObject) + { + DataGridViewRow row = (DataGridViewRow)dataGridView.Rows[0].Clone(); + + foreach (var prop in newObject.GetType().GetProperties()) + { + object value = prop.GetValue(newObject); + + row.Cells[dataGridView.Columns[prop.Name].Index].Value = value; + } + + dataGridView.Rows.Add(row); + } + + public T GetSelectedObject() where T : new() + { + if (dataGridView.SelectedCells.Count == 0) + { + return new T(); + } + + int rowIndex = dataGridView.SelectedCells[0].RowIndex; + var targetObject = new T(); + Type objectType = typeof(T); + PropertyInfo[] properties = objectType.GetProperties(); + + foreach (PropertyInfo property in properties) + { + DataGridViewCell selectedCell = dataGridView.Rows[rowIndex].Cells[property.Name]; + + object cellValue = selectedCell.Value; + + if (cellValue != null && property.CanWrite) + { + object convertedValue = Convert.ChangeType(cellValue, property.PropertyType); + property.SetValue(targetObject, convertedValue); + } + } + + return targetObject; + } + private void SelectionChanged(object sender, EventArgs e) + { + var element = sender as DataGridView; + if (dataGridView.SelectedRows.Count == 0) + { + return; + } + IndexRow = element.SelectedRows[0].Index; + TaskHandler?.Invoke(this, e); + } + } +} diff --git a/Library/CustomComponents/ZhelovanovVisualComponents/TableComponent.resx b/Library/CustomComponents/ZhelovanovVisualComponents/TableComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Library/CustomComponents/ZhelovanovVisualComponents/TableComponent.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Library/CustomComponents/ZhelovanovVisualComponents/TextBoxComponent.Designer.cs b/Library/CustomComponents/ZhelovanovVisualComponents/TextBoxComponent.Designer.cs new file mode 100644 index 0000000..b9b5f16 --- /dev/null +++ b/Library/CustomComponents/ZhelovanovVisualComponents/TextBoxComponent.Designer.cs @@ -0,0 +1,71 @@ +namespace KOP_Labs +{ + partial class TextBoxComponent + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + textBox = new TextBox(); + checkBox1 = new CheckBox(); + SuspendLayout(); + // + // textBox + // + textBox.Location = new Point(141, 73); + textBox.Name = "textBox"; + textBox.Size = new Size(125, 27); + textBox.TabIndex = 0; + textBox.TextChanged += TextBox_TextChanged; + // + // checkBox1 + // + checkBox1.AutoSize = true; + checkBox1.Location = new Point(34, 73); + checkBox1.Name = "checkBox1"; + checkBox1.Size = new Size(101, 24); + checkBox1.TabIndex = 1; + checkBox1.Text = "checkBox1"; + checkBox1.UseVisualStyleBackColor = true; + checkBox1.CheckedChanged += CheckBox_CheckedChanged; + // + // TextBoxComponent + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(checkBox1); + Controls.Add(textBox); + Name = "TextBoxComponent"; + Size = new Size(439, 252); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private TextBox textBox; + private CheckBox checkBox1; + } +} diff --git a/Library/CustomComponents/ZhelovanovVisualComponents/TextBoxComponent.cs b/Library/CustomComponents/ZhelovanovVisualComponents/TextBoxComponent.cs new file mode 100644 index 0000000..4fa13fa --- /dev/null +++ b/Library/CustomComponents/ZhelovanovVisualComponents/TextBoxComponent.cs @@ -0,0 +1,129 @@ +using DocumentFormat.OpenXml.Drawing.Diagrams; +using KOP_Labs.Exceptions; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using static System.Windows.Forms.VisualStyles.VisualStyleElement.Button; + +namespace KOP_Labs +{ + public partial class TextBoxComponent : UserControl + { + + public TextBoxComponent() + { + InitializeComponent(); + Error = string.Empty; + } + + public string Error { get; private set; } + + public float? Value + { + get + { + if (checkBox1.Checked) + { + return null; + } + if (CheckValue()) + { + return float.Parse(textBox.Text); + } + + return null; + + + } + set + { + + + if (value == null) + { + checkBox1.Checked = true; + } + textBox.Text = value.ToString(); + + + } + } + private EventHandler checkChanged; + public event EventHandler CheckChanged + { + add + { + checkChanged += value; + } + remove + { + checkChanged -= value; + } + } + + private void CheckBox_CheckedChanged(object sender, EventArgs e) + { + Error = string.Empty; + if (checkBox1.Checked) + { + textBox.Enabled = false; + textBox.Text = string.Empty; + } + else + { + textBox.Enabled = true; + + } + checkChanged?.Invoke(sender, e); + } + + private EventHandler valueChanged; + public event EventHandler ValueChanged + { + add + { + valueChanged += value; + } + remove + { + valueChanged -= value; + } + } + + public bool CheckValue() + + { + Error = string.Empty; + if (!checkBox1.Checked && (string.IsNullOrEmpty(textBox.Text))) + { + + Error = "Пусто!"; + return false; + + } + if (!checkBox1.Checked && !float.TryParse(textBox.Text, out float floatValue)) + { + + Error = "Не тот тип!"; + + return false; + } + + return true; + + } + private void TextBox_TextChanged(object sender, EventArgs e) + { + + valueChanged?.Invoke(sender, e); + } + + + } +} diff --git a/Library/CustomComponents/ZhelovanovVisualComponents/TextBoxComponent.resx b/Library/CustomComponents/ZhelovanovVisualComponents/TextBoxComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Library/CustomComponents/ZhelovanovVisualComponents/TextBoxComponent.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Library/Library.sln b/Library/Library.sln index 57ade83..06f6164 100644 --- a/Library/Library.sln +++ b/Library/Library.sln @@ -3,9 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.5.33530.505 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibraryView", "LibraryView\LibraryView.csproj", "{50CEADA7-BB8C-41AB-BAB5-F29DF48E581F}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibraryView", "LibraryView\LibraryView.csproj", "{50CEADA7-BB8C-41AB-BAB5-F29DF48E581F}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CustomComponents", "CustomComponents\CustomComponents.csproj", "{F6B42349-8FB3-4D68-8757-D26DAD2F0992}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CustomComponents", "CustomComponents\CustomComponents.csproj", "{F6B42349-8FB3-4D68-8757-D26DAD2F0992}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibraryBusinessLogic", "LibraryBusinessLogic\LibraryBusinessLogic.csproj", "{215533AD-E311-4527-B8F6-C9F3708FDA0B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibraryContracts", "LibraryContracts\LibraryContracts.csproj", "{26F921C2-4336-4123-ABC6-3916BF341224}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibraryDatabaseImplement", "LibraryDatabaseImplement\LibraryDatabaseImplement.csproj", "{B0677916-A9E7-48E6-961A-75C6ACFF2546}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -21,6 +27,18 @@ Global {F6B42349-8FB3-4D68-8757-D26DAD2F0992}.Debug|Any CPU.Build.0 = Debug|Any CPU {F6B42349-8FB3-4D68-8757-D26DAD2F0992}.Release|Any CPU.ActiveCfg = Release|Any CPU {F6B42349-8FB3-4D68-8757-D26DAD2F0992}.Release|Any CPU.Build.0 = Release|Any CPU + {215533AD-E311-4527-B8F6-C9F3708FDA0B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {215533AD-E311-4527-B8F6-C9F3708FDA0B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {215533AD-E311-4527-B8F6-C9F3708FDA0B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {215533AD-E311-4527-B8F6-C9F3708FDA0B}.Release|Any CPU.Build.0 = Release|Any CPU + {26F921C2-4336-4123-ABC6-3916BF341224}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {26F921C2-4336-4123-ABC6-3916BF341224}.Debug|Any CPU.Build.0 = Debug|Any CPU + {26F921C2-4336-4123-ABC6-3916BF341224}.Release|Any CPU.ActiveCfg = Release|Any CPU + {26F921C2-4336-4123-ABC6-3916BF341224}.Release|Any CPU.Build.0 = Release|Any CPU + {B0677916-A9E7-48E6-961A-75C6ACFF2546}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B0677916-A9E7-48E6-961A-75C6ACFF2546}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B0677916-A9E7-48E6-961A-75C6ACFF2546}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B0677916-A9E7-48E6-961A-75C6ACFF2546}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Library/LibraryBusinessLogic/BusinessLogics/BookLogic.cs b/Library/LibraryBusinessLogic/BusinessLogics/BookLogic.cs new file mode 100644 index 0000000..b1d41f7 --- /dev/null +++ b/Library/LibraryBusinessLogic/BusinessLogics/BookLogic.cs @@ -0,0 +1,60 @@ +using LibraryContracts.BusinessLogicsContracts; +using LibraryContracts.StorageContracts; +using LibraryContracts.BindingModels; +using LibraryContracts.ViewModels; + +namespace LibraryBusinessLogic.BusinessLogics +{ + public class BookLogic : IBookLogic + { + private readonly IBookStorage _bookStorage; + public BookLogic(IBookStorage bookStorage) + { + _bookStorage = bookStorage; + } + + public List Read(BookBindingModel model) + { + if (model == null) + { + return _bookStorage.GetFullList(); + } + if (model.Id.HasValue) + { + return new List { _bookStorage.GetElement(model) }; + } + return _bookStorage.GetFilteredList(model); + } + + public void CreateOrUpdate(BookBindingModel model) + { + var element = _bookStorage.GetElement( + new BookBindingModel + { + Title = model.Title + }); + if (element != null && element.Id != model.Id) + { + throw new Exception("Книга с таким названием уже существует"); + } + if (model.Id.HasValue) + { + _bookStorage.Update(model); + } + else + { + _bookStorage.Insert(model); + } + } + + public void Delete(BookBindingModel model) + { + var element = _bookStorage.GetElement(new BookBindingModel { Id = model.Id }); + if (element == null) + { + throw new Exception("Книга не найдена"); + } + _bookStorage.Delete(model); + } + } +} diff --git a/Library/LibraryBusinessLogic/BusinessLogics/GenreLogic.cs b/Library/LibraryBusinessLogic/BusinessLogics/GenreLogic.cs new file mode 100644 index 0000000..e9b4432 --- /dev/null +++ b/Library/LibraryBusinessLogic/BusinessLogics/GenreLogic.cs @@ -0,0 +1,61 @@ +using LibraryContracts.BindingModels; +using LibraryContracts.BusinessLogicsContracts; +using LibraryContracts.StorageContracts; +using LibraryContracts.ViewModels; + +namespace LibraryBusinessLogic.BusinessLogics +{ + public class GenreLogic : IGenreLogic + { + private readonly IGenreStorage _genreStorage; + + public GenreLogic(IGenreStorage genreStorage) + { + _genreStorage = genreStorage; + } + + public List Read(GenreBindingModel model) + { + if (model == null) + { + return _genreStorage.GetFullList(); + } + if (model.Id.HasValue) + { + return new List { _genreStorage.GetElement(model) }; + } + return _genreStorage.GetFilteredList(model); + } + + public void CreateOrUpdate(GenreBindingModel model) + { + var element = _genreStorage.GetElement( + new GenreBindingModel + { + Name = model.Name + }); + if (element != null && element.Id != model.Id) + { + throw new Exception("Такой жанр уже существует"); + } + if (model.Id.HasValue) + { + _genreStorage.Update(model); + } + else + { + _genreStorage.Insert(model); + } + } + + public void Delete(GenreBindingModel model) + { + var element = _genreStorage.GetElement(new GenreBindingModel { Id = model.Id }); + if (element == null) + { + throw new Exception("Жанр не найден"); + } + _genreStorage.Delete(model); + } + } +} diff --git a/Library/LibraryBusinessLogic/LibraryBusinessLogic.csproj b/Library/LibraryBusinessLogic/LibraryBusinessLogic.csproj new file mode 100644 index 0000000..d6914e9 --- /dev/null +++ b/Library/LibraryBusinessLogic/LibraryBusinessLogic.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/Library/LibraryContracts/BindingModels/BookBindingModel.cs b/Library/LibraryContracts/BindingModels/BookBindingModel.cs new file mode 100644 index 0000000..f91c49f --- /dev/null +++ b/Library/LibraryContracts/BindingModels/BookBindingModel.cs @@ -0,0 +1,15 @@ +namespace LibraryContracts.BindingModels +{ + public class BookBindingModel + { + public int? Id { get; set; } + + public string Title { get; set; } + + public string Description { get; set; } + + public string Genre { get; set; } + + public int? Cost { get; set; } + } +} diff --git a/Library/LibraryContracts/BindingModels/GenreBindingModel.cs b/Library/LibraryContracts/BindingModels/GenreBindingModel.cs new file mode 100644 index 0000000..08a33ee --- /dev/null +++ b/Library/LibraryContracts/BindingModels/GenreBindingModel.cs @@ -0,0 +1,8 @@ +namespace LibraryContracts.BindingModels +{ + public class GenreBindingModel + { + public int? Id { get; set; } + public string Name { get; set; } + } +} diff --git a/Library/LibraryContracts/BusinessLogicsContracts/IBookLogic.cs b/Library/LibraryContracts/BusinessLogicsContracts/IBookLogic.cs new file mode 100644 index 0000000..c1e7dc3 --- /dev/null +++ b/Library/LibraryContracts/BusinessLogicsContracts/IBookLogic.cs @@ -0,0 +1,12 @@ +using LibraryContracts.BindingModels; +using LibraryContracts.ViewModels; + +namespace LibraryContracts.BusinessLogicsContracts +{ + public interface IBookLogic + { + List Read(BookBindingModel model); + void CreateOrUpdate(BookBindingModel model); + void Delete(BookBindingModel model); + } +} diff --git a/Library/LibraryContracts/BusinessLogicsContracts/IGenreLogic.cs b/Library/LibraryContracts/BusinessLogicsContracts/IGenreLogic.cs new file mode 100644 index 0000000..b2d9d43 --- /dev/null +++ b/Library/LibraryContracts/BusinessLogicsContracts/IGenreLogic.cs @@ -0,0 +1,12 @@ +using LibraryContracts.BindingModels; +using LibraryContracts.ViewModels; + +namespace LibraryContracts.BusinessLogicsContracts +{ + public interface IGenreLogic + { + List Read(GenreBindingModel model); + void CreateOrUpdate(GenreBindingModel model); + void Delete(GenreBindingModel model); + } +} diff --git a/Library/LibraryContracts/LibraryContracts.csproj b/Library/LibraryContracts/LibraryContracts.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/Library/LibraryContracts/LibraryContracts.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/Library/LibraryContracts/StorageContracts/IBookStorage.cs b/Library/LibraryContracts/StorageContracts/IBookStorage.cs new file mode 100644 index 0000000..d530edf --- /dev/null +++ b/Library/LibraryContracts/StorageContracts/IBookStorage.cs @@ -0,0 +1,16 @@ +using LibraryContracts.BindingModels; +using LibraryContracts.ViewModels; + +namespace LibraryContracts.StorageContracts +{ + public interface IBookStorage + { + List GetFullList(); + List GetFilteredList(BookBindingModel model); + BookViewModel GetElement(BookBindingModel model); + + void Insert(BookBindingModel model); + void Update(BookBindingModel model); + void Delete(BookBindingModel model); + } +} diff --git a/Library/LibraryContracts/StorageContracts/IGenreStorage.cs b/Library/LibraryContracts/StorageContracts/IGenreStorage.cs new file mode 100644 index 0000000..c65ecba --- /dev/null +++ b/Library/LibraryContracts/StorageContracts/IGenreStorage.cs @@ -0,0 +1,16 @@ +using LibraryContracts.BindingModels; +using LibraryContracts.ViewModels; + +namespace LibraryContracts.StorageContracts +{ + public interface IGenreStorage + { + List GetFullList(); + List GetFilteredList(GenreBindingModel model); + GenreViewModel GetElement(GenreBindingModel model); + + void Insert(GenreBindingModel model); + void Update(GenreBindingModel model); + void Delete(GenreBindingModel model); + } +} diff --git a/Library/LibraryContracts/ViewModels/BookViewModel.cs b/Library/LibraryContracts/ViewModels/BookViewModel.cs new file mode 100644 index 0000000..940e7db --- /dev/null +++ b/Library/LibraryContracts/ViewModels/BookViewModel.cs @@ -0,0 +1,37 @@ +using System.ComponentModel; + +namespace LibraryContracts.ViewModels +{ + public class BookViewModel + { + public int? Id { get; set; } + + [DisplayName("Название")] + public string Title { get; set; } + + [DisplayName("Описание")] + public string Description { get; set; } + + [DisplayName("Жанр")] + public string Genre { get; set; } + + [DisplayName("Стоимость")] + public int? Cost { get; set; } + + public string CostStr + { + set + { + if (Cost == 0) CostStr = "Бесплатная"; + else if (Cost == null) CostStr = "Не указано"; + else CostStr = value; + } + get + { + if (Cost == 0) return "Бесплатная"; + else if (Cost == null) return "Не указано"; + else return Cost.ToString(); + } + } + } +} diff --git a/Library/LibraryContracts/ViewModels/GenreViewModel.cs b/Library/LibraryContracts/ViewModels/GenreViewModel.cs new file mode 100644 index 0000000..d44eb61 --- /dev/null +++ b/Library/LibraryContracts/ViewModels/GenreViewModel.cs @@ -0,0 +1,9 @@ +namespace LibraryContracts.ViewModels +{ + public class GenreViewModel + { + public int? Id { get; set; } + + public string Name { get; set; } + } +} diff --git a/Library/LibraryDatabaseImplement/Implements/BookStorage.cs b/Library/LibraryDatabaseImplement/Implements/BookStorage.cs new file mode 100644 index 0000000..d78600a --- /dev/null +++ b/Library/LibraryDatabaseImplement/Implements/BookStorage.cs @@ -0,0 +1,120 @@ +using LibraryContracts.BindingModels; +using LibraryContracts.StorageContracts; +using LibraryContracts.ViewModels; +using LibraryDatabaseImplement.Models; + +namespace LibraryDatabaseImplement.Implements +{ + public class BookStorage : IBookStorage + { + public List GetFullList() + { + using (var context = new LibraryDatabase()) + { + return context.Books + .ToList() + .Select(CreateModel) + .ToList(); + } + } + + public List GetFilteredList(BookBindingModel model) + { + var context = new LibraryDatabase(); + return context.Books + .Where(book => book.Title.Contains(model.Title) && book.Genre.Contains(model.Genre)) + .ToList() + .Select(CreateModel) + .ToList(); + } + + public BookViewModel GetElement(BookBindingModel model) + { + if (model == null) + { + return null; + } + using var context = new LibraryDatabase(); + var book = context.Books + .ToList() + .FirstOrDefault(rec => rec.Title == model.Title || rec.Id == model.Id); + return book != null ? CreateModel(book) : null; + } + + public void Insert(BookBindingModel model) + { + var context = new LibraryDatabase(); + var transaction = context.Database.BeginTransaction(); + try + { + context.Books.Add(CreateModel(model, new Book())); + context.SaveChanges(); + transaction.Commit(); + } + catch + { + transaction.Rollback(); + throw; + } + } + + public void Update(BookBindingModel model) + { + var context = new LibraryDatabase(); + var transaction = context.Database.BeginTransaction(); + try + { + var book = context.Books.FirstOrDefault(rec => rec.Id == model.Id); + if (book == null) + { + throw new Exception("Книга не найдена"); + } + CreateModel(model, book); + context.SaveChanges(); + transaction.Commit(); + } + catch + { + transaction.Rollback(); + throw; + } + } + + + public void Delete(BookBindingModel model) + { + var context = new LibraryDatabase(); + var book = context.Books.FirstOrDefault(rec => rec.Id == model.Id); + if (book != null) + { + context.Books.Remove(book); + context.SaveChanges(); + } + else + { + throw new Exception("Книга не найдена"); + } + } + + private static Book CreateModel(BookBindingModel model, Book book) + { + book.Title = model.Title; + book.Description = model.Description; + book.Genre = model.Genre; + book.Cost = model.Cost; + return book; + } + + private BookViewModel CreateModel(Book book) + { + return new BookViewModel + { + Id = book.Id, + Title = book.Title, + Description = book.Description, + Genre = book.Genre, + Cost = book.Cost + }; + } + } +} diff --git a/Library/LibraryDatabaseImplement/Implements/GenreStorage.cs b/Library/LibraryDatabaseImplement/Implements/GenreStorage.cs new file mode 100644 index 0000000..5cc8f54 --- /dev/null +++ b/Library/LibraryDatabaseImplement/Implements/GenreStorage.cs @@ -0,0 +1,121 @@ +using LibraryContracts.BindingModels; +using LibraryContracts.StorageContracts; +using LibraryContracts.ViewModels; +using LibraryDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LibraryDatabaseImplement.Implements +{ + public class GenreStorage : IGenreStorage + { + public List GetFullList() + { + using var context = new LibraryDatabase(); + return context.Genres + .Select(CreateModel) + .ToList(); + } + + public List GetFilteredList(GenreBindingModel model) + { + if (model == null) + { + return null; + } + using var context = new LibraryDatabase(); + return context.Genres + .Where(rec => rec.Name.Contains(model.Name)) + .Select(CreateModel) + .ToList(); + } + + public GenreViewModel GetElement(GenreBindingModel model) + { + if (model == null) + { + return null; + } + using var context = new LibraryDatabase(); + + var genre = context.Genres + .ToList() + .FirstOrDefault(rec => rec.Id == model.Id || rec.Name == model.Name); + return genre != null ? CreateModel(genre) : null; + + } + + public void Insert(GenreBindingModel model) + { + var context = new LibraryDatabase(); + var transaction = context.Database.BeginTransaction(); + try + { + context.Genres.Add(CreateModel(model, new Genre())); + context.SaveChanges(); + transaction.Commit(); + } + catch + { + transaction.Rollback(); + throw; + } + } + + public void Update(GenreBindingModel model) + { + var context = new LibraryDatabase(); + var transaction = context.Database.BeginTransaction(); + try + { + var genre = context.Genres.FirstOrDefault(rec => rec.Id == model.Id); + if (genre == null) + { + throw new Exception("Жанр не найден"); + } + CreateModel(model, genre); + context.SaveChanges(); + transaction.Commit(); + } + catch + { + transaction.Rollback(); + throw; + } + } + + + public void Delete(GenreBindingModel model) + { + var context = new LibraryDatabase(); + var shape = context.Genres.FirstOrDefault(rec => rec.Id == model.Id); + if (shape != null) + { + context.Genres.Remove(shape); + context.SaveChanges(); + } + else + { + throw new Exception("Жанр не найден"); + } + } + + private static Genre CreateModel(GenreBindingModel model, Genre genre) + { + genre.Name = model.Name; + return genre; + } + + private static GenreViewModel CreateModel(Genre genre) + { + return new GenreViewModel + { + Id = genre.Id, + Name = genre.Name + }; + } + } +} diff --git a/Library/LibraryDatabaseImplement/LibraryDatabase.cs b/Library/LibraryDatabaseImplement/LibraryDatabase.cs new file mode 100644 index 0000000..4412327 --- /dev/null +++ b/Library/LibraryDatabaseImplement/LibraryDatabase.cs @@ -0,0 +1,27 @@ +using LibraryDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; + +namespace LibraryDatabaseImplement +{ + public class LibraryDatabase : DbContext + { + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + if (optionsBuilder.IsConfigured == false) + { + optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=LibraryDatabase;Integrated Security=True;MultipleActiveResultSets=True; TrustServerCertificate=True"); + } + base.OnConfiguring(optionsBuilder); + } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity().Property(m => m.Cost).IsRequired(false); + base.OnModelCreating(modelBuilder); + } + + public virtual DbSet Books { set; get; } + + public virtual DbSet Genres { set; get; } + } +} diff --git a/Library/LibraryDatabaseImplement/LibraryDatabaseImplement.csproj b/Library/LibraryDatabaseImplement/LibraryDatabaseImplement.csproj new file mode 100644 index 0000000..d9c8514 --- /dev/null +++ b/Library/LibraryDatabaseImplement/LibraryDatabaseImplement.csproj @@ -0,0 +1,23 @@ + + + + net6.0 + enable + enable + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + diff --git a/Library/LibraryDatabaseImplement/Migrations/20231116200005_InitialCreate.Designer.cs b/Library/LibraryDatabaseImplement/Migrations/20231116200005_InitialCreate.Designer.cs new file mode 100644 index 0000000..0f7816f --- /dev/null +++ b/Library/LibraryDatabaseImplement/Migrations/20231116200005_InitialCreate.Designer.cs @@ -0,0 +1,79 @@ +// +using System; +using LibraryDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace LibraryDatabaseImplement.Migrations +{ + [DbContext(typeof(LibraryDatabase))] + [Migration("20231116200005_InitialCreate")] + partial class InitialCreate + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("LibraryDatabaseImplement.Models.Book", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Cost") + .HasColumnType("int"); + + b.Property("CostStr") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Genre") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Title") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Books"); + }); + + modelBuilder.Entity("LibraryDatabaseImplement.Models.Genre", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Genres"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Library/LibraryDatabaseImplement/Migrations/20231116200005_InitialCreate.cs b/Library/LibraryDatabaseImplement/Migrations/20231116200005_InitialCreate.cs new file mode 100644 index 0000000..772cba9 --- /dev/null +++ b/Library/LibraryDatabaseImplement/Migrations/20231116200005_InitialCreate.cs @@ -0,0 +1,54 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace LibraryDatabaseImplement.Migrations +{ + /// + public partial class InitialCreate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Books", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Title = table.Column(type: "nvarchar(max)", nullable: false), + Description = table.Column(type: "nvarchar(max)", nullable: false), + Genre = table.Column(type: "nvarchar(max)", nullable: false), + Cost = table.Column(type: "int", nullable: true), + CostStr = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Books", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Genres", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Genres", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Books"); + + migrationBuilder.DropTable( + name: "Genres"); + } + } +} diff --git a/Library/LibraryDatabaseImplement/Migrations/LibraryDatabaseModelSnapshot.cs b/Library/LibraryDatabaseImplement/Migrations/LibraryDatabaseModelSnapshot.cs new file mode 100644 index 0000000..80770df --- /dev/null +++ b/Library/LibraryDatabaseImplement/Migrations/LibraryDatabaseModelSnapshot.cs @@ -0,0 +1,76 @@ +// +using System; +using LibraryDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace LibraryDatabaseImplement.Migrations +{ + [DbContext(typeof(LibraryDatabase))] + partial class LibraryDatabaseModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("LibraryDatabaseImplement.Models.Book", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Cost") + .HasColumnType("int"); + + b.Property("CostStr") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Genre") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Title") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Books"); + }); + + modelBuilder.Entity("LibraryDatabaseImplement.Models.Genre", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Genres"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Library/LibraryDatabaseImplement/Models/Book.cs b/Library/LibraryDatabaseImplement/Models/Book.cs new file mode 100644 index 0000000..ce018fa --- /dev/null +++ b/Library/LibraryDatabaseImplement/Models/Book.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LibraryDatabaseImplement.Models +{ + public class Book + { + public int Id { get; set; } + + [Required] + public string Title { get; set; } + + [Required] + public string Description { get; set; } + + [Required] + public string Genre { get; set; } + + [Required] + public int? Cost { get; set; } + + public string CostStr + { + set { } + get + { + if (Cost == 0) return "Бесплатная"; + else if (Cost == null) return "Не указано"; + else return Cost.ToString(); + } + } + } +} diff --git a/Library/LibraryDatabaseImplement/Models/Genre.cs b/Library/LibraryDatabaseImplement/Models/Genre.cs new file mode 100644 index 0000000..cc08068 --- /dev/null +++ b/Library/LibraryDatabaseImplement/Models/Genre.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LibraryDatabaseImplement.Models +{ + public class Genre + { + public int Id { get; set; } + + [Required] + public string Name { get; set; } + } +} diff --git a/Library/LibraryView/FormBook.Designer.cs b/Library/LibraryView/FormBook.Designer.cs new file mode 100644 index 0000000..8c576c7 --- /dev/null +++ b/Library/LibraryView/FormBook.Designer.cs @@ -0,0 +1,167 @@ +namespace LibraryView +{ + partial class FormBook + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.romanovaComboBoxGenre = new ComponentsLibrary.MyVisualComponents.RomanovaComboBox(); + this.textBoxTitle = new System.Windows.Forms.TextBox(); + this.label2 = new System.Windows.Forms.Label(); + this.textBoxDescription = new System.Windows.Forms.TextBox(); + this.label3 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.textBoxCost = new ComponentsLibrary.IstyukovVisualComponents.TextBoxModified(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonClose = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(22, 21); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(121, 20); + this.label1.TabIndex = 0; + this.label1.Text = "Название книги"; + // + // romanovaComboBoxGenre + // + this.romanovaComboBoxGenre.Location = new System.Drawing.Point(-3, 240); + this.romanovaComboBoxGenre.Name = "romanovaComboBoxGenre"; + this.romanovaComboBoxGenre.SelectElement = ""; + this.romanovaComboBoxGenre.Size = new System.Drawing.Size(259, 116); + this.romanovaComboBoxGenre.TabIndex = 1; + // + // textBoxTitle + // + this.textBoxTitle.Location = new System.Drawing.Point(22, 44); + this.textBoxTitle.Name = "textBoxTitle"; + this.textBoxTitle.Size = new System.Drawing.Size(196, 27); + this.textBoxTitle.TabIndex = 2; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.BackColor = System.Drawing.SystemColors.Control; + this.label2.Location = new System.Drawing.Point(20, 91); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(123, 20); + this.label2.TabIndex = 3; + this.label2.Text = "Описание книги"; + // + // textBoxDescription + // + this.textBoxDescription.Location = new System.Drawing.Point(22, 114); + this.textBoxDescription.Multiline = true; + this.textBoxDescription.Name = "textBoxDescription"; + this.textBoxDescription.Size = new System.Drawing.Size(290, 110); + this.textBoxDescription.TabIndex = 4; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(22, 240); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(48, 20); + this.label3.TabIndex = 5; + this.label3.Text = "Жанр"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(22, 310); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(83, 20); + this.label4.TabIndex = 6; + this.label4.Text = "Стоимость"; + // + // textBoxCost + // + this.textBoxCost.Location = new System.Drawing.Point(20, 333); + this.textBoxCost.Margin = new System.Windows.Forms.Padding(2, 3, 2, 3); + this.textBoxCost.Name = "textBoxCost"; + this.textBoxCost.Size = new System.Drawing.Size(168, 84); + this.textBoxCost.TabIndex = 7; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(49, 435); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(94, 29); + this.buttonSave.TabIndex = 8; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // buttonClose + // + this.buttonClose.Location = new System.Drawing.Point(162, 435); + this.buttonClose.Name = "buttonClose"; + this.buttonClose.Size = new System.Drawing.Size(94, 29); + this.buttonClose.TabIndex = 9; + this.buttonClose.Text = "Отменить"; + this.buttonClose.UseVisualStyleBackColor = true; + this.buttonClose.Click += new System.EventHandler(this.buttonClose_Click); + // + // FormBook + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(342, 477); + this.Controls.Add(this.buttonClose); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxCost); + this.Controls.Add(this.label4); + this.Controls.Add(this.label3); + this.Controls.Add(this.textBoxDescription); + this.Controls.Add(this.label2); + this.Controls.Add(this.textBoxTitle); + this.Controls.Add(this.romanovaComboBoxGenre); + this.Controls.Add(this.label1); + this.Name = "FormBook"; + this.Text = "Книги"; + this.Load += new System.EventHandler(this.FormBook_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label label1; + private CustomComponents.DropDownList MeComboBoxGenre; + private TextBox textBoxTitle; + private Label label2; + private TextBox textBoxDescription; + private Label label3; + private Label label4; + private CustomComponents. + private Button buttonSave; + private Button buttonClose; + } +} \ No newline at end of file diff --git a/Library/LibraryView/FormBook.cs b/Library/LibraryView/FormBook.cs new file mode 100644 index 0000000..6aad1cc --- /dev/null +++ b/Library/LibraryView/FormBook.cs @@ -0,0 +1,128 @@ +using LibraryContracts.BindingModels; +using LibraryContracts.BusinessLogicsContracts; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace LibraryView +{ + public partial class FormBook : Form + { + private readonly IBookLogic _bookLogic; + private readonly IGenreLogic _genreLogic; + public int Id { set { id = value; } } + private int? id; + public FormBook(IBookLogic bookLogic, IGenreLogic genreLogic) + { + _bookLogic = bookLogic; + _genreLogic = genreLogic; + InitializeComponent(); + LoadGenries(); + } + + private void LoadGenries() + { + var genries = _genreLogic.Read(null); + foreach (var genre in genries) + { + romanovaComboBoxGenre.FillList(genre.Name); + } + } + + private void FormBook_Load(object sender, EventArgs e) + { + if (id.HasValue) + { + try + { + var view = _bookLogic.Read(new BookBindingModel { Id = id })?[0]; + if (view != null) + { + if (view.CostStr == "Не указано") + { + textBoxTitle.Text = view.Title; + textBoxDescription.Text = view.Description; + romanovaComboBoxGenre.SelectElement = view.Genre; + textBoxCost.Value = null; + } + else + { + textBoxTitle.Text = view.Title; + textBoxDescription.Text = view.Description; + romanovaComboBoxGenre.SelectElement = view.Genre; + textBoxCost.Value = view.Cost; + } + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxTitle.Text)) + { + MessageBox.Show("Заполните название книга", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (string.IsNullOrEmpty(textBoxDescription.Text)) + { + MessageBox.Show("Заполните описание книги", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (string.IsNullOrEmpty(romanovaComboBoxGenre.SelectElement.ToString())) + { + MessageBox.Show("Выберите жанр книги", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + int? cost = null; + if (textBoxCost.Value != null) + { + try + { + cost = Convert.ToInt32(textBoxCost.Value); + } + catch + { + MessageBox.Show("Стоимость должна быть целым числом", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + try + { + _bookLogic.CreateOrUpdate(new BookBindingModel + { + Id = id, + Title = textBoxTitle.Text, + Description = textBoxDescription.Text, + Genre = romanovaComboBoxGenre.SelectElement.ToString(), + Cost = cost + }); + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonClose_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/Library/LibraryView/FormBook.resx b/Library/LibraryView/FormBook.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Library/LibraryView/FormBook.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Library/LibraryView/FormMain.Designer.cs b/Library/LibraryView/FormMain.Designer.cs new file mode 100644 index 0000000..0300c41 --- /dev/null +++ b/Library/LibraryView/FormMain.Designer.cs @@ -0,0 +1,95 @@ +namespace LibraryView +{ + partial class FormMain + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.menuStrip = new System.Windows.Forms.MenuStrip(); + this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.sevaTreeView = new ComponentsLibrary.BasharinVisualComponents.SevaTreeView(); + this.romanovaExcelDocument = new ComponentsLibrary.MyNotVisualComponents.RomanovaExcelDocument(this.components); + this.diagramTopdf1 = new ComponentsLibrary.BasharinNotVisualComponents.DiagramToPDF(this.components); + this.componentDocumentWithTableMultiHeaderWord = new ComponentsLibraryNet60.DocumentWithTable.ComponentDocumentWithTableMultiHeaderWord(this.components); + this.menuStrip.SuspendLayout(); + this.SuspendLayout(); + // + // menuStrip + // + this.menuStrip.ImageScalingSize = new System.Drawing.Size(20, 20); + this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.справочникиToolStripMenuItem}); + this.menuStrip.Location = new System.Drawing.Point(0, 0); + this.menuStrip.Name = "menuStrip"; + this.menuStrip.Size = new System.Drawing.Size(694, 28); + this.menuStrip.TabIndex = 0; + this.menuStrip.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(117, 24); + this.справочникиToolStripMenuItem.Text = "Справочники"; + // + // sevaTreeView + // + this.sevaTreeView.Dock = System.Windows.Forms.DockStyle.Fill; + this.sevaTreeView.Location = new System.Drawing.Point(0, 28); + this.sevaTreeView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.sevaTreeView.Name = "sevaTreeView"; + this.sevaTreeView.SelectedNodeIndex = 0; + this.sevaTreeView.Size = new System.Drawing.Size(694, 354); + this.sevaTreeView.TabIndex = 1; + this.sevaTreeView.Load += new System.EventHandler(this.treeViewControl_Load); + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(694, 382); + this.Controls.Add(this.sevaTreeView); + this.Controls.Add(this.menuStrip); + this.MainMenuStrip = this.menuStrip; + this.Name = "FormMain"; + this.Text = "Главная форма"; + this.menuStrip.ResumeLayout(false); + this.menuStrip.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private MenuStrip menuStrip; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ComponentsLibrary.BasharinVisualComponents.SevaTreeView sevaTreeView; + private ComponentsLibrary.MyNotVisualComponents.RomanovaExcelDocument romanovaExcelDocument; + private ComponentsLibrary.BasharinNotVisualComponents.DiagramToPDF diagramTopdf1; + private ComponentsLibraryNet60.DocumentWithTable.ComponentDocumentWithTableMultiHeaderWord componentDocumentWithTableMultiHeaderWord; + } +} \ No newline at end of file diff --git a/Library/LibraryView/FormMain.cs b/Library/LibraryView/FormMain.cs new file mode 100644 index 0000000..794800d --- /dev/null +++ b/Library/LibraryView/FormMain.cs @@ -0,0 +1,307 @@ +using ComponentsLibrary.IstyukovNotVisualComponents; +using ComponentsLibrary.MyUnvisualComponents; +using ComponentsLibrary.MyUnvisualComponents.HelperModels; +using ComponentsLibraryNet60.DocumentWithTable; +using ComponentsLibraryNet60.Models; +using LibraryContracts.BindingModels; +using LibraryContracts.BusinessLogicsContracts; +using LibraryDatabaseImplement.Models; +using Microsoft.Office.Interop.Excel; +using System; +using System.Collections.Generic; +using System.Windows.Forms; +using Unity; + +namespace LibraryView +{ + public partial class FormMain : Form + { + private ContextMenuStrip contextMenu = new ContextMenuStrip(); + private readonly IBookLogic _bookLogic; + private readonly IGenreLogic _genreLogic; + public FormMain(IBookLogic bookLogic, IGenreLogic genreLogic) + { + + InitializeComponent(); + + _bookLogic = bookLogic; + _genreLogic = genreLogic; + + List hierarhy = new List(); + hierarhy.Add("Genre"); + hierarhy.Add("CostStr"); + hierarhy.Add("Id"); + hierarhy.Add("Title"); + + sevaTreeView.SetHierarhy(hierarhy); + + // создаем элементы меню + ToolStripMenuItem addMenuGenre = new ToolStripMenuItem("Справочник"); + ToolStripMenuItem addMenuItem = new ToolStripMenuItem("Добавить книгу"); + ToolStripMenuItem updateMenuItem = new ToolStripMenuItem("Изменить книгу"); + ToolStripMenuItem deleteMenuItem = new ToolStripMenuItem("Удалить книгу"); + ToolStripMenuItem simpleDocMenuItem = new ToolStripMenuItem("Простой документ"); + ToolStripMenuItem tableMenuItem = new ToolStripMenuItem("Таблица"); + ToolStripMenuItem diagramMenuItem = new ToolStripMenuItem("Диаграмма"); + + // добавляем элементы в меню + contextMenu.Items.AddRange(new[] { addMenuGenre, addMenuItem, updateMenuItem, deleteMenuItem, simpleDocMenuItem, tableMenuItem, diagramMenuItem }); + + // ассоциируем контекстное меню с узлом дерева + sevaTreeView.ContextMenuStrip = contextMenu; + + // устанавливаем обработчики событий для меню + addMenuGenre.Click += addGenreItem_Click; + addMenuItem.Click += addMenuItem_Click; + updateMenuItem.Click += updateMenuItem_Click; + deleteMenuItem.Click += deleteMenuItem_Click; + simpleDocMenuItem.Click += simpleDocMenuItem_Click; + tableMenuItem.Click += tableMenuItem_Click; + diagramMenuItem.Click += diagramDocMenuItem_Click; + } + + private void treeViewControl_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + sevaTreeView.Clear(); + var books = _bookLogic.Read(null); + if (books != null) + { + foreach (var book in books) + { + if (book != null) + { + sevaTreeView.Add(book); + } + } + } + } + + void addMenuItem_Click(object sender, EventArgs e) + { + var form = Program.Container.Resolve(); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + + void addGenreItem_Click(object sender, EventArgs e) + { + var form = Program.Container.Resolve(); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + + private void updateMenuItem_Click(object sender, EventArgs e) + { + var form = Program.Container.Resolve(); + form.Id = Convert.ToInt32(sevaTreeView.GetSelectedValue().Id); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + + private void deleteMenuItem_Click(object sender, EventArgs e) + { + if (MessageBox.Show("Удалить запись", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(sevaTreeView.GetSelectedValue().Id); + try + { + _bookLogic.Delete(new BookBindingModel { Id = id }); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + + private void simpleDocMenuItem_Click(object sender, EventArgs e) + { + CreateExcelSimpleDoc(); + } + + private void tableMenuItem_Click(object sender, EventArgs e) + { + CreateWordTable(); + } + + private void diagramDocMenuItem_Click(object sender, EventArgs e) + { + CreatePdfDiagram(); + } + + protected override bool ProcessCmdKey(ref Message msg, Keys keyData) + { + if (keyData == (Keys.Control | Keys.A)) + { + addMenuItem_Click(null, null); + return true; + } + + if (keyData == (Keys.Control | Keys.U)) + { + updateMenuItem_Click(null, null); + return true; + } + + if (keyData == (Keys.Control | Keys.D)) + { + deleteMenuItem_Click(null, null); + return true; + } + + if (keyData == (Keys.Control | Keys.S)) + { + CreateExcelSimpleDoc(); + return true; + } + + if (keyData == (Keys.Control | Keys.T)) + { + CreateWordTable(); + return true; + } + + if (keyData == (Keys.Control | Keys.C)) + { + CreatePdfDiagram(); + return true; + } + + if (keyData == (Keys.Control | Keys.G)) + { + addGenreItem_Click(null, null); + return true; + } + + return base.ProcessCmdKey(ref msg, keyData); + } + + private void CreateExcelSimpleDoc() + { + string dataSet = ""; + var products = _bookLogic.Read(null); + if (products != null) + { + foreach (var product in products) + { + if (product.Cost == 0) + { + dataSet += product.Title + " " + product.Description + ";"; + } + } + + string[] data = dataSet.Split(';'); + var sfd = new SaveFileDialog(); + sfd.FileName = "D:\\Study\\3 course\\KOP\\file\\simpleDocProducts.xls"; + sfd.Filter = "Excel files (*.xlsx)|*.xlsx"; + if (sfd.ShowDialog() == DialogResult.OK) + { + if (data != null) + { + romanovaExcelDocument.CreateExcel(sfd.FileName, "Книги", data); + MessageBox.Show("Файл был создан успешно", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Файл не был создан", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void CreatePdfDiagram() + { + Dictionary data = new Dictionary(); + var books = _bookLogic.Read(null); + var genries = _genreLogic.Read(null); + if (books != null && genries != null) + { + foreach (var genre in genries) + { + int count = 0; + foreach (var book in books) + { + if (book.Cost == 0 && book.Genre.Equals(genre.Name)) + { + count++; + } + } + data.Add(genre.Name, count); + } + var sfd = new SaveFileDialog(); + sfd.FileName = "DiagramBook.pdf"; + sfd.Filter = "Pdf files (*.pdf)|*.pdf"; + if (sfd.ShowDialog() == DialogResult.OK) + { + diagramTopdf1.CreateDocument(sfd.FileName, "Бесплатные книги", + "Сколько бесплатных книг какого жанра", ComponentsLibrary.BasharinNotVisualComponents.Area.TOP, data); + MessageBox.Show("Файл был создан успешно", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + } + + private void CreateWordTable() + { + var sfd = new SaveFileDialog(); + sfd.FileName = "WordBooks.docx"; + sfd.Filter = "Word files (*.docx)|*.docx"; + var booksDB = _bookLogic.Read(null); + List books = new List(); + foreach (var book in booksDB) + { + Book prod = new Book + { + Id = (int)book.Id, + Title = book.Title, + Description = book.Description, + Genre = book.Genre, + Cost = book.Cost + }; + books.Add(prod); + } + if (sfd.ShowDialog() == DialogResult.OK) + { + componentDocumentWithTableMultiHeaderWord.CreateDoc(new ComponentDocumentWithTableHeaderDataConfig + { + FilePath = sfd.FileName, + Header = "Информация по всем книгам", + ColumnsRowsWidth = new List<(int, int)> { (5, 5), (10, 5), (10, 0), (5, 0), (7, 0) }, + Headers = new List<(int ColumnIndex, int RowIndex, string Header, string PropertyName)> + { + (0, 0, "Id", "Id"), + (1, 0, "Название", "Title"), + (2, 0, "Описание", "Description"), + (3, 0, "Категория", "Genre"), + (4, 0, "Стоимость книг", "CostStr") + }, + Data = books + }); + MessageBox.Show("Файл был создан успешно", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + + public List getColumnsWidth(int count, int width) + { + List list = new List(); + + for (int i = 0; i < count; i++) + { + list.Add(width); + } + return list; + } + } +} + diff --git a/Library/LibraryView/FormMain.resx b/Library/LibraryView/FormMain.resx new file mode 100644 index 0000000..c4eca3a --- /dev/null +++ b/Library/LibraryView/FormMain.resx @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + 144, 17 + + + 370, 17 + + + 527, 17 + + \ No newline at end of file diff --git a/Library/LibraryView/FormManual.Designer.cs b/Library/LibraryView/FormManual.Designer.cs new file mode 100644 index 0000000..b4658f2 --- /dev/null +++ b/Library/LibraryView/FormManual.Designer.cs @@ -0,0 +1,85 @@ +namespace LibraryView +{ + partial class FormManual + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.Id = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.NameGenre = new System.Windows.Forms.DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.Id, + this.NameGenre}); + this.dataGridView.Location = new System.Drawing.Point(1, 1); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(485, 330); + this.dataGridView.TabIndex = 0; + // + // Id + // + this.Id.HeaderText = "Id"; + this.Id.MinimumWidth = 6; + this.Id.Name = "Id"; + this.Id.Visible = false; + this.Id.Width = 125; + // + // NameGenre + // + this.NameGenre.HeaderText = "Жанр"; + this.NameGenre.MinimumWidth = 6; + this.NameGenre.Name = "NameGenre"; + this.NameGenre.Width = 200; + // + // FormManual + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(485, 343); + this.Controls.Add(this.dataGridView); + this.Name = "FormManual"; + this.Text = "Справочник жанров"; + this.Load += new System.EventHandler(this.FormManual_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private DataGridViewTextBoxColumn Id; + private DataGridViewTextBoxColumn NameGenre; + } +} \ No newline at end of file diff --git a/Library/LibraryView/FormManual.cs b/Library/LibraryView/FormManual.cs new file mode 100644 index 0000000..fb800b5 --- /dev/null +++ b/Library/LibraryView/FormManual.cs @@ -0,0 +1,113 @@ +using LibraryContracts.BindingModels; +using LibraryContracts.BusinessLogicsContracts; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace LibraryView +{ + public partial class FormManual : Form + { + private readonly IGenreLogic _genreLogic; + public FormManual(IGenreLogic genreLogic) + { + _genreLogic = genreLogic; + InitializeComponent(); + } + + private void FormManual_Load(object sender, EventArgs e) + { + LoadData(); + dataGridView.CellEndEdit += CellEndEdit; + } + + private void LoadData() + { + var genries = _genreLogic.Read(null); + if (genries != null) + { + dataGridView.Rows.Clear(); + foreach (var genre in genries) + { + dataGridView.Rows.Add(genre.Id, genre.Name); + } + } + } + + private void CellEndEdit(object sender, EventArgs e) + { + if (dataGridView.CurrentCell.Value != null) + { + if (dataGridView.CurrentRow.Cells[0].Value == null) + { + _genreLogic.CreateOrUpdate(new GenreBindingModel + { + Name = dataGridView.CurrentCell.Value.ToString() + }); + } + else + { + _genreLogic.CreateOrUpdate(new GenreBindingModel + { + Id = (int)dataGridView.CurrentRow.Cells[0].Value, + Name = dataGridView.CurrentCell.Value.ToString() + }); + } + } + } + + protected override bool ProcessCmdKey(ref Message msg, Keys keyData) + { + DataGridViewRow row = new DataGridViewRow(); + if (keyData == (Keys.Insert)) + { + DataGridViewCell cell = dataGridView.Rows[dataGridView.NewRowIndex].Cells[1]; + dataGridView.CurrentCell = cell; + dataGridView.BeginEdit(true); + return true; + } + + if (keyData == (Keys.Enter)) + { + dataGridView.EndEdit(); + LoadData(); + } + + if (keyData == (Keys.Delete)) + { + if (MessageBox.Show("Удалить запись", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int? id = null; + try + { + id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + } + catch + { + MessageBox.Show("Чтобы удалить запись, нажмите на пустую ячейку слева от удаляемой записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + if (id != null) + { + try + { + _genreLogic.Delete(new GenreBindingModel { Id = id }); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + LoadData(); + } + return true; + } + return base.ProcessCmdKey(ref msg, keyData); + } + } +} diff --git a/Library/LibraryView/FormManual.resx b/Library/LibraryView/FormManual.resx new file mode 100644 index 0000000..a2146e0 --- /dev/null +++ b/Library/LibraryView/FormManual.resx @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + \ No newline at end of file diff --git a/Library/LibraryView/FormSecond.Designer.cs b/Library/LibraryView/FormSecond.Designer.cs index 4b636c0..34966a5 100644 --- a/Library/LibraryView/FormSecond.Designer.cs +++ b/Library/LibraryView/FormSecond.Designer.cs @@ -33,6 +33,9 @@ buttonCreateExDoc = new Button(); buttonCreateTable = new Button(); buttonCreateDiagram = new Button(); + pdfImages1 = new ViewComponents.NotVisualComponents.PdfImages(components); + pdfTable1 = new ViewComponents.NotVisualComponents.PdfTable(components); + pieChartpdf1 = new ViewComponents.NotVisualComponents.PieChartPDF(components); SuspendLayout(); // // buttonCreateExDoc @@ -85,5 +88,8 @@ private Button buttonCreateExDoc; private Button buttonCreateTable; private Button buttonCreateDiagram; + private ViewComponents.NotVisualComponents.PdfImages pdfImages1; + private ViewComponents.NotVisualComponents.PdfTable pdfTable1; + private ViewComponents.NotVisualComponents.PieChartPDF pieChartpdf1; } } \ No newline at end of file diff --git a/Library/LibraryView/FormSecond.cs b/Library/LibraryView/FormSecond.cs index e42f6ea..b6e83b3 100644 --- a/Library/LibraryView/FormSecond.cs +++ b/Library/LibraryView/FormSecond.cs @@ -1,4 +1,5 @@ using CustomComponents; +using CustomComponents.MyNonVisualComponents; using Microsoft.VisualBasic; namespace LibraryView @@ -15,7 +16,7 @@ namespace LibraryView string[] text = { "Некий текст 1", "Ещё один некий текст", "Текст" }; BigTextComponent bigText = new BigTextComponent(); - + bigText.CreateExcel("D:\\Papka\\КОП\\ExcelDoc.xls", "Документ", text); } diff --git a/Library/LibraryView/FormSecond.resx b/Library/LibraryView/FormSecond.resx index 8e89b0f..9c24520 100644 --- a/Library/LibraryView/FormSecond.resx +++ b/Library/LibraryView/FormSecond.resx @@ -60,4 +60,13 @@ 17, 17 + + 209, 17 + + + 342, 17 + + + 463, 17 + \ No newline at end of file diff --git a/Library/LibraryView/LibraryView.csproj b/Library/LibraryView/LibraryView.csproj index 6136776..43410ec 100644 --- a/Library/LibraryView/LibraryView.csproj +++ b/Library/LibraryView/LibraryView.csproj @@ -10,10 +10,17 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + \ No newline at end of file