feat(lab-3): do lab-3
This commit is contained in:
parent
d99c4b78a0
commit
c5b14425b0
@ -1,31 +0,0 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
|
||||||
# Visual Studio Version 17
|
|
||||||
VisualStudioVersion = 17.9.34723.18
|
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComponentLibrary1", "ComponentLibrary1\ComponentLibrary1.csproj", "{9AA4EAF0-DA17-4872-A45B-25DC4A7C82CD}"
|
|
||||||
EndProject
|
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestApp1", "TestApp1\TestApp1.csproj", "{E318008C-A386-40D8-B623-47E6C2C14FD0}"
|
|
||||||
EndProject
|
|
||||||
Global
|
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
|
||||||
Debug|Any CPU = Debug|Any CPU
|
|
||||||
Release|Any CPU = Release|Any CPU
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
|
||||||
{9AA4EAF0-DA17-4872-A45B-25DC4A7C82CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{9AA4EAF0-DA17-4872-A45B-25DC4A7C82CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{9AA4EAF0-DA17-4872-A45B-25DC4A7C82CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{9AA4EAF0-DA17-4872-A45B-25DC4A7C82CD}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{E318008C-A386-40D8-B623-47E6C2C14FD0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{E318008C-A386-40D8-B623-47E6C2C14FD0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{E318008C-A386-40D8-B623-47E6C2C14FD0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{E318008C-A386-40D8-B623-47E6C2C14FD0}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
|
||||||
HideSolutionNode = FALSE
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
|
||||||
SolutionGuid = {27B1B7B6-7B2C-49EA-B19C-2C947CD4CF24}
|
|
||||||
EndGlobalSection
|
|
||||||
EndGlobal
|
|
@ -1,15 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>net6.0-windows</TargetFramework>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
<UseWindowsForms>true</UseWindowsForms>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
56
ComponentLibrary1/check_list/CheckList.Designer.cs
generated
56
ComponentLibrary1/check_list/CheckList.Designer.cs
generated
@ -1,56 +0,0 @@
|
|||||||
namespace ComponentLibrary1
|
|
||||||
{
|
|
||||||
partial class CheckList
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Обязательная переменная конструктора.
|
|
||||||
/// </summary>
|
|
||||||
private System.ComponentModel.IContainer components = null;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Освободить все используемые ресурсы.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
|
|
||||||
protected override void Dispose(bool disposing)
|
|
||||||
{
|
|
||||||
if (disposing && (components != null))
|
|
||||||
{
|
|
||||||
components.Dispose();
|
|
||||||
}
|
|
||||||
base.Dispose(disposing);
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Код, автоматически созданный конструктором компонентов
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Требуемый метод для поддержки конструктора — не изменяйте
|
|
||||||
/// содержимое этого метода с помощью редактора кода.
|
|
||||||
/// </summary>
|
|
||||||
private void InitializeComponent()
|
|
||||||
{
|
|
||||||
checkedListBox = new CheckedListBox();
|
|
||||||
SuspendLayout();
|
|
||||||
//
|
|
||||||
// checkedListBox
|
|
||||||
//
|
|
||||||
checkedListBox.Dock = DockStyle.Fill;
|
|
||||||
checkedListBox.FormattingEnabled = true;
|
|
||||||
checkedListBox.Location = new Point(0, 0);
|
|
||||||
checkedListBox.Name = "checkedListBox";
|
|
||||||
checkedListBox.Size = new Size(209, 172);
|
|
||||||
checkedListBox.TabIndex = 0;
|
|
||||||
checkedListBox.SelectedIndexChanged += checkedListBox_SelectedIndexChanged;
|
|
||||||
//
|
|
||||||
// CheckList
|
|
||||||
//
|
|
||||||
Controls.Add(checkedListBox);
|
|
||||||
Name = "CheckList";
|
|
||||||
Size = new Size(209, 172);
|
|
||||||
ResumeLayout(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
private CheckedListBox checkedListBox;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,63 +0,0 @@
|
|||||||
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 ComponentLibrary1
|
|
||||||
{
|
|
||||||
public partial class CheckList : UserControl
|
|
||||||
{
|
|
||||||
|
|
||||||
private event EventHandler? _сhangeEvent;
|
|
||||||
|
|
||||||
public event EventHandler ChangeEvent
|
|
||||||
{
|
|
||||||
add
|
|
||||||
{
|
|
||||||
_сhangeEvent += value;
|
|
||||||
}
|
|
||||||
remove
|
|
||||||
{
|
|
||||||
_сhangeEvent -= value;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
public string SelectedItem
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return checkedListBox.SelectedItem?.ToString() ?? string.Empty;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
checkedListBox.SelectedIndex = checkedListBox.Items.IndexOf(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public CheckList()
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Input(string input)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(input))
|
|
||||||
throw new ArgumentNullException("input");
|
|
||||||
checkedListBox.Items.Add(input);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Clear()
|
|
||||||
{
|
|
||||||
checkedListBox.Items.Clear();
|
|
||||||
}
|
|
||||||
private void checkedListBox_SelectedIndexChanged(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
_сhangeEvent?.Invoke(this, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,58 +0,0 @@
|
|||||||
namespace ComponentLibrary1
|
|
||||||
{
|
|
||||||
partial class LimitedText
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Обязательная переменная конструктора.
|
|
||||||
/// </summary>
|
|
||||||
private System.ComponentModel.IContainer components = null;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Освободить все используемые ресурсы.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
|
|
||||||
protected override void Dispose(bool disposing)
|
|
||||||
{
|
|
||||||
if (disposing && (components != null))
|
|
||||||
{
|
|
||||||
components.Dispose();
|
|
||||||
}
|
|
||||||
base.Dispose(disposing);
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Код, автоматически созданный конструктором компонентов
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Требуемый метод для поддержки конструктора — не изменяйте
|
|
||||||
/// содержимое этого метода с помощью редактора кода.
|
|
||||||
/// </summary>
|
|
||||||
private void InitializeComponent()
|
|
||||||
{
|
|
||||||
textBox = new TextBox();
|
|
||||||
SuspendLayout();
|
|
||||||
//
|
|
||||||
// textBox
|
|
||||||
//
|
|
||||||
textBox.Dock = DockStyle.Fill;
|
|
||||||
textBox.Location = new Point(0, 0);
|
|
||||||
textBox.Name = "textBox";
|
|
||||||
textBox.Size = new Size(150, 23);
|
|
||||||
textBox.TabIndex = 0;
|
|
||||||
textBox.TextChanged += textBox_TextChanged;
|
|
||||||
//
|
|
||||||
// LimitedText
|
|
||||||
//
|
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
|
||||||
Controls.Add(textBox);
|
|
||||||
Name = "LimitedText";
|
|
||||||
Size = new Size(150, 24);
|
|
||||||
ResumeLayout(false);
|
|
||||||
PerformLayout();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
private TextBox textBox;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,107 +0,0 @@
|
|||||||
using ComponentLibrary1.limited_text;
|
|
||||||
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 ComponentLibrary1
|
|
||||||
{
|
|
||||||
public partial class LimitedText : UserControl
|
|
||||||
{
|
|
||||||
private event EventHandler? _changeEvent;
|
|
||||||
public event EventHandler ChangeEvent
|
|
||||||
{
|
|
||||||
add
|
|
||||||
{
|
|
||||||
_changeEvent += value;
|
|
||||||
}
|
|
||||||
remove
|
|
||||||
{
|
|
||||||
_changeEvent -= value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private int? _min = null;
|
|
||||||
public int? Min
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return _min;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (value < 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (Max != null && value > Max)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_min = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private int? _max = null;
|
|
||||||
public int? Max
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return _max;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (value < 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (Max != null && value < Min)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_max = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public string TextField
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (Min == null || Max == null)
|
|
||||||
{
|
|
||||||
throw new RangeUndefinedException();
|
|
||||||
}
|
|
||||||
if (textBox.Text.Length < Min || textBox.Text.Length > Max)
|
|
||||||
{
|
|
||||||
throw new OutOfRangeException((int)Min, (int)Max);
|
|
||||||
}
|
|
||||||
return textBox.Text;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (Min == null || Max == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (value.Length >= Min && value.Length <= Max)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public LimitedText()
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void textBox_TextChanged(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
_changeEvent?.Invoke(this, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Runtime.Serialization;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ComponentLibrary1.limited_text
|
|
||||||
{
|
|
||||||
[Serializable]
|
|
||||||
internal class OutOfRangeException : ApplicationException
|
|
||||||
{
|
|
||||||
public OutOfRangeException(int min, int max) : base($"Введенное значение не входит в диапазон от {min} до {max}") { }
|
|
||||||
public OutOfRangeException() : base() { }
|
|
||||||
public OutOfRangeException(string message) : base(message) { }
|
|
||||||
public OutOfRangeException(string message, Exception exception) : base(message, exception) { }
|
|
||||||
protected OutOfRangeException(SerializationInfo info, StreamingContext context) : base(info, context) { }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Runtime.Serialization;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ComponentLibrary1.limited_text
|
|
||||||
{
|
|
||||||
[Serializable]
|
|
||||||
internal class RangeUndefinedException : ApplicationException
|
|
||||||
{
|
|
||||||
public RangeUndefinedException() : base("Диапазон не определен") { }
|
|
||||||
public RangeUndefinedException(string message) : base(message) { }
|
|
||||||
public RangeUndefinedException(string message, Exception exception) : base(message, exception) { }
|
|
||||||
protected RangeUndefinedException(SerializationInfo info, StreamingContext context) : base(info, context) { }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ComponentLibrary1.office_package.HelperEnums
|
|
||||||
{
|
|
||||||
public enum PdfParagraphAlignmentType
|
|
||||||
{
|
|
||||||
Center,
|
|
||||||
Left,
|
|
||||||
Right
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ComponentLibrary1.office_package.HelperModels
|
|
||||||
{
|
|
||||||
public interface IPdfInfo
|
|
||||||
{
|
|
||||||
public string FileName { get; }
|
|
||||||
public string Title { get; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
using ComponentLibrary1.office_package.HelperEnums;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ComponentLibrary1.office_package.HelperModels
|
|
||||||
{
|
|
||||||
public interface IPdfPieChartParameters
|
|
||||||
{
|
|
||||||
public string ChartTitle { get; }
|
|
||||||
public PdfDiagramLegendLocation LegendLocation { get; }
|
|
||||||
public PdfDiagramSeries Series { get; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
using ComponentLibrary1.office_package.HelperEnums;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ComponentLibrary1.office_package.HelperModels
|
|
||||||
{
|
|
||||||
public interface ITableTextParameters
|
|
||||||
{
|
|
||||||
public string Style { get; }
|
|
||||||
public PdfParagraphAlignmentType ParagraphAlignment { get; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
using ComponentLibrary1.office_package.HelperEnums;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ComponentLibrary1.office_package.HelperModels
|
|
||||||
{
|
|
||||||
public class PdfCellParameters : ITableTextParameters
|
|
||||||
{
|
|
||||||
public string Text { get; set; } = string.Empty;
|
|
||||||
public string Style { get; set; } = string.Empty;
|
|
||||||
public PdfParagraphAlignmentType ParagraphAlignment { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
using ComponentLibrary1.office_package.HelperEnums;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ComponentLibrary1.office_package.HelperModels
|
|
||||||
{
|
|
||||||
public class PdfCellsMergeParameters
|
|
||||||
{
|
|
||||||
public int RowIndex = 0;
|
|
||||||
public int ColumnIndex = 0;
|
|
||||||
public PdfCellsMergeDirections Direction;
|
|
||||||
public int CellNumber = 1;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
using ComponentLibrary1.office_package.HelperEnums;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ComponentLibrary1.office_package.HelperModels
|
|
||||||
{
|
|
||||||
public class PdfColumnParameters : ITableTextParameters
|
|
||||||
{
|
|
||||||
public List<string> Texts { get; set; } = new();
|
|
||||||
public string Style { get; set; } = string.Empty;
|
|
||||||
public int ColumnIndex = 0;
|
|
||||||
public PdfParagraphAlignmentType ParagraphAlignment { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ComponentLibrary1.office_package.HelperModels
|
|
||||||
{
|
|
||||||
public class PdfDiagramSeries
|
|
||||||
{
|
|
||||||
public string SeriesName { get; set; } = string.Empty;
|
|
||||||
public Dictionary<string, double> Data = new();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
using ComponentLibrary1.office_package.HelperEnums;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ComponentLibrary1.office_package.HelperModels
|
|
||||||
{
|
|
||||||
public class PdfParagraph
|
|
||||||
{
|
|
||||||
public string Text { get; set; } = string.Empty;
|
|
||||||
public string Style { get; set; } = string.Empty;
|
|
||||||
public PdfParagraphAlignmentType ParagraphAlignment { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
using ComponentLibrary1.office_package.HelperEnums;
|
|
||||||
using ComponentLibrary1.office_package.HelperModels;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ComponentLibrary1.office_package.HelperModels
|
|
||||||
{
|
|
||||||
public class PdfRowParameters : ITableTextParameters
|
|
||||||
{
|
|
||||||
public List<string> Texts { get; set; } = new();
|
|
||||||
public string Style { get; set; } = string.Empty;
|
|
||||||
public PdfParagraphAlignmentType ParagraphAlignment { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,66 +0,0 @@
|
|||||||
using ComponentLibrary1.office_package.HelperEnums;
|
|
||||||
using ComponentLibrary1.office_package.HelperModels;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ComponentLibrary1.office_package
|
|
||||||
{
|
|
||||||
public interface ISaveToPdf
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Создание doc-файла
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="info"></param>
|
|
||||||
void CreatePdf(IPdfInfo info);
|
|
||||||
/// <summary>
|
|
||||||
/// Создание параграфа с текстом
|
|
||||||
/// </summary>
|
|
||||||
void CreateParagraph(PdfParagraph paragraph);
|
|
||||||
/// <summary>
|
|
||||||
/// Создание изображения в pdf файле
|
|
||||||
/// </summary>
|
|
||||||
void CreateImage(byte[] image);
|
|
||||||
/// <summary>
|
|
||||||
/// Создание таблицы
|
|
||||||
/// определенной ширины
|
|
||||||
/// </summary>
|
|
||||||
void CreateTable();
|
|
||||||
/// <summary>
|
|
||||||
/// Создание таблицы с заданным количеством столбцов
|
|
||||||
/// определенной ширины
|
|
||||||
/// </summary>
|
|
||||||
void CreateTableWithColumns(List<string> columns);
|
|
||||||
/// <summary>
|
|
||||||
/// Создание таблицы с заданным количеством столбцов
|
|
||||||
/// </summary>
|
|
||||||
void CreateTableWithColumns(int columnNumber);
|
|
||||||
/// <summary>
|
|
||||||
/// Создание и заполнение строки
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="rowParameters"></param>
|
|
||||||
void CreateRow(PdfRowParameters rowParameters);
|
|
||||||
/// <summary>
|
|
||||||
/// Создание и заполнение столбца
|
|
||||||
/// </summary>
|
|
||||||
void InsertTextIntoColumn(PdfColumnParameters columnParameters);
|
|
||||||
/// <summary>
|
|
||||||
/// Создание и заполнение ячейки
|
|
||||||
/// </summary>
|
|
||||||
void InsertTextIntoCell(int rowIndex, int columnIndex, PdfCellParameters cellParameters);
|
|
||||||
/// <summary>
|
|
||||||
/// Создание и заполнение ячейки
|
|
||||||
/// </summary>
|
|
||||||
void MergeCells(PdfCellsMergeParameters parameters);
|
|
||||||
/// <summary>
|
|
||||||
/// Создание и заполнение круговой диаграммы
|
|
||||||
/// </summary>
|
|
||||||
void CreatePieChart(IPdfPieChartParameters parameters);
|
|
||||||
/// <summary>
|
|
||||||
/// Сохранение файла
|
|
||||||
/// </summary>
|
|
||||||
void SavePdf(IPdfInfo info);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,273 +0,0 @@
|
|||||||
using ComponentLibrary1.office_package.HelperEnums;
|
|
||||||
using ComponentLibrary1.office_package.HelperModels;
|
|
||||||
using MigraDoc.DocumentObjectModel;
|
|
||||||
using MigraDoc.Rendering;
|
|
||||||
using MigraDoc.DocumentObjectModel.Tables;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Security.Cryptography;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Data.Common;
|
|
||||||
using MigraDoc.DocumentObjectModel.Shapes;
|
|
||||||
using MigraDoc.DocumentObjectModel.Shapes.Charts;
|
|
||||||
|
|
||||||
namespace ComponentLibrary1.office_package.Implements
|
|
||||||
{
|
|
||||||
public class SaveToPdf : ISaveToPdf
|
|
||||||
{
|
|
||||||
private Document? _document;
|
|
||||||
private Section? _section;
|
|
||||||
private Table? _table;
|
|
||||||
|
|
||||||
#region константы
|
|
||||||
private readonly Unit BORDER_WIDTH = 0.5;
|
|
||||||
private readonly Unit COLUMN_WIDTH = Unit.FromCentimeter(3.5);
|
|
||||||
private readonly Unit IMAGE_WIDTH = Unit.FromCentimeter(15);
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region работа с файлом
|
|
||||||
public void CreatePdf(IPdfInfo info)
|
|
||||||
{
|
|
||||||
_document = new Document();
|
|
||||||
DefineStyles(_document);
|
|
||||||
_section = _document.AddSection();
|
|
||||||
}
|
|
||||||
public void SavePdf(IPdfInfo info)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(info.FileName))
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException("Имя файла не задано");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_document == null || _section == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException("Документ не сформирован, сохранять нечего");
|
|
||||||
}
|
|
||||||
var renderer = new PdfDocumentRenderer(true)
|
|
||||||
{
|
|
||||||
Document = _document
|
|
||||||
};
|
|
||||||
renderer.RenderDocument();
|
|
||||||
renderer.PdfDocument.Save(info.FileName);
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region работа с текстом
|
|
||||||
private static ParagraphAlignment GetParagraphAlignment(
|
|
||||||
PdfParagraphAlignmentType type)
|
|
||||||
{
|
|
||||||
return type switch
|
|
||||||
{
|
|
||||||
PdfParagraphAlignmentType.Center => ParagraphAlignment.Center,
|
|
||||||
PdfParagraphAlignmentType.Left => ParagraphAlignment.Left,
|
|
||||||
PdfParagraphAlignmentType.Right => ParagraphAlignment.Right,
|
|
||||||
_ => ParagraphAlignment.Justify,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void DefineStyles(Document document)
|
|
||||||
{
|
|
||||||
var style = document.Styles["Normal"];
|
|
||||||
style.Font.Name = "Times New Roman";
|
|
||||||
style.Font.Size = 14;
|
|
||||||
style = document.Styles.AddStyle("NormalTitle", "Normal");
|
|
||||||
style.Font.Bold = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void CreateParagraph(PdfParagraph pdfParagraph)
|
|
||||||
{
|
|
||||||
if (_document == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (_section == null)
|
|
||||||
{
|
|
||||||
_section = _document.AddSection();
|
|
||||||
}
|
|
||||||
var paragraph = _section.AddParagraph(pdfParagraph.Text);
|
|
||||||
paragraph.Format.SpaceAfter = "1cm";
|
|
||||||
paragraph.Format.Alignment = GetParagraphAlignment(pdfParagraph.ParagraphAlignment);
|
|
||||||
paragraph.Style = pdfParagraph.Style;
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region работа с изображениями
|
|
||||||
public void CreateImage(byte[] image)
|
|
||||||
{
|
|
||||||
if (image == null || image.Length == 0)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException("Картинка не загружена");
|
|
||||||
}
|
|
||||||
if (_document == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (_section == null)
|
|
||||||
{
|
|
||||||
_section = _document.AddSection();
|
|
||||||
}
|
|
||||||
var imageFileName = Path.GetTempFileName();
|
|
||||||
File.WriteAllBytes(imageFileName, image);
|
|
||||||
var img = _section.AddImage(imageFileName);
|
|
||||||
img.Width = IMAGE_WIDTH;
|
|
||||||
img.LockAspectRatio = true;
|
|
||||||
_section.AddParagraph();
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region работа с таблицами
|
|
||||||
public void CreateTable()
|
|
||||||
{
|
|
||||||
if (_document == null || _section == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_table = _section.AddTable();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void CreateTableWithColumns(List<string> columns)
|
|
||||||
{
|
|
||||||
if (_document == null || _section == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_table = _section.AddTable();
|
|
||||||
foreach (var elem in columns)
|
|
||||||
{
|
|
||||||
_table.AddColumn(elem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void CreateTableWithColumns(int columnNumber)
|
|
||||||
{
|
|
||||||
if (_document == null || _section == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_table = _section.AddTable();
|
|
||||||
for (int i = 0; i < columnNumber; i++)
|
|
||||||
{
|
|
||||||
_table.AddColumn(COLUMN_WIDTH);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void CreateRow(PdfRowParameters rowParameters)
|
|
||||||
{
|
|
||||||
if (_table == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var row = _table.AddRow();
|
|
||||||
for (int i = 0; i < rowParameters.Texts.Count; ++i)
|
|
||||||
{
|
|
||||||
if (!string.IsNullOrWhiteSpace(rowParameters.Texts[i]))
|
|
||||||
InsertTextIntoCell(row.Index, i, rowParameters, rowParameters.Texts[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void InsertTextIntoColumn(PdfColumnParameters columnParameters)
|
|
||||||
{
|
|
||||||
if (_table == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (int i = 0; i < columnParameters.Texts.Count; ++i)
|
|
||||||
{
|
|
||||||
if (!string.IsNullOrWhiteSpace(columnParameters.Texts[i]))
|
|
||||||
InsertTextIntoCell(i, columnParameters.ColumnIndex, columnParameters, columnParameters.Texts[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void InsertTextIntoCell(int rowIndex, int columnIndex, PdfCellParameters cellParameters)
|
|
||||||
{
|
|
||||||
InsertTextIntoCell(rowIndex, columnIndex, cellParameters, cellParameters.Text);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void InsertTextIntoCell(int rowIndex, int columnIndex, ITableTextParameters parameters, string text)
|
|
||||||
{
|
|
||||||
if (_table == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Cell cell = _table.Rows[rowIndex].Cells[columnIndex];
|
|
||||||
cell.AddParagraph(text);
|
|
||||||
if (!string.IsNullOrEmpty(parameters.Style))
|
|
||||||
{
|
|
||||||
cell.Style = parameters.Style;
|
|
||||||
}
|
|
||||||
cell.Borders.Left.Width = BORDER_WIDTH;
|
|
||||||
cell.Borders.Right.Width = BORDER_WIDTH;
|
|
||||||
cell.Borders.Top.Width = BORDER_WIDTH;
|
|
||||||
cell.Borders.Bottom.Width = BORDER_WIDTH;
|
|
||||||
cell.Format.Alignment = GetParagraphAlignment(
|
|
||||||
parameters.ParagraphAlignment);
|
|
||||||
cell.VerticalAlignment = VerticalAlignment.Center;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void MergeCells(PdfCellsMergeParameters parameters)
|
|
||||||
{
|
|
||||||
if (_table == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Cell cell = _table.Rows[parameters.RowIndex].Cells[parameters.ColumnIndex];
|
|
||||||
switch (parameters.Direction)
|
|
||||||
{
|
|
||||||
case PdfCellsMergeDirections.Down:
|
|
||||||
cell.MergeDown = parameters.CellNumber;
|
|
||||||
break;
|
|
||||||
case PdfCellsMergeDirections.Right:
|
|
||||||
cell.MergeRight = parameters.CellNumber;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region работа с диаграммами
|
|
||||||
public void CreatePieChart(IPdfPieChartParameters parameters)
|
|
||||||
{
|
|
||||||
if (_document == null || _section == null)
|
|
||||||
throw new ArgumentNullException(nameof(_document), "Document is not created.");
|
|
||||||
Chart chart = new Chart(ChartType.Pie2D);
|
|
||||||
Series series = chart.SeriesCollection.AddSeries();
|
|
||||||
series.Name = parameters.Series.SeriesName;
|
|
||||||
series.Add(parameters.Series.Data.Select(x => x.Value).ToArray());
|
|
||||||
chart.XValues.AddXSeries().Add(parameters.Series.Data.Select(x => x.Key).ToArray());
|
|
||||||
ConfigChart(parameters, chart);
|
|
||||||
_section.Add(chart);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ConfigChart(IPdfPieChartParameters parameters, Chart chart)
|
|
||||||
{
|
|
||||||
chart.DataLabel.Type = DataLabelType.Percent;
|
|
||||||
chart.DataLabel.Position = DataLabelPosition.OutsideEnd;
|
|
||||||
chart.Width = Unit.FromCentimeter(16.0);
|
|
||||||
chart.Height = Unit.FromCentimeter(12.0);
|
|
||||||
chart.TopArea.AddParagraph(parameters.ChartTitle);
|
|
||||||
chart.XAxis.MajorTickMark = (TickMarkType)2;
|
|
||||||
chart.YAxis.MajorTickMark = (TickMarkType)2;
|
|
||||||
chart.YAxis.HasMajorGridlines = true;
|
|
||||||
chart.PlotArea.LineFormat.Width = new Unit(1);
|
|
||||||
chart.PlotArea.LineFormat.Visible = true;
|
|
||||||
switch (parameters.LegendLocation)
|
|
||||||
{
|
|
||||||
case PdfDiagramLegendLocation.Left:
|
|
||||||
chart.LeftArea.AddLegend();
|
|
||||||
break;
|
|
||||||
case PdfDiagramLegendLocation.Right:
|
|
||||||
chart.RightArea.AddLegend();
|
|
||||||
break;
|
|
||||||
case PdfDiagramLegendLocation.Top:
|
|
||||||
chart.TopArea.AddLegend();
|
|
||||||
break;
|
|
||||||
case PdfDiagramLegendLocation.Bottom:
|
|
||||||
chart.BottomArea.AddLegend();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
36
ComponentLibrary1/pdf_diagram/PdfDiagram.Designer.cs
generated
36
ComponentLibrary1/pdf_diagram/PdfDiagram.Designer.cs
generated
@ -1,36 +0,0 @@
|
|||||||
namespace ComponentLibrary1.pdf_diagram
|
|
||||||
{
|
|
||||||
partial class PdfDiagram
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Обязательная переменная конструктора.
|
|
||||||
/// </summary>
|
|
||||||
private System.ComponentModel.IContainer components = null;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Освободить все используемые ресурсы.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
|
|
||||||
protected override void Dispose(bool disposing)
|
|
||||||
{
|
|
||||||
if (disposing && (components != null))
|
|
||||||
{
|
|
||||||
components.Dispose();
|
|
||||||
}
|
|
||||||
base.Dispose(disposing);
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Код, автоматически созданный конструктором компонентов
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Требуемый метод для поддержки конструктора — не изменяйте
|
|
||||||
/// содержимое этого метода с помощью редактора кода.
|
|
||||||
/// </summary>
|
|
||||||
private void InitializeComponent()
|
|
||||||
{
|
|
||||||
components = new System.ComponentModel.Container();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,45 +0,0 @@
|
|||||||
using ComponentLibrary1.office_package;
|
|
||||||
using ComponentLibrary1.office_package.HelperEnums;
|
|
||||||
using ComponentLibrary1.office_package.HelperModels;
|
|
||||||
using ComponentLibrary1.office_package.Implements;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ComponentLibrary1.pdf_diagram
|
|
||||||
{
|
|
||||||
public partial class PdfDiagram : Component
|
|
||||||
{
|
|
||||||
ISaveToPdf SaveToPdf = new SaveToPdf();
|
|
||||||
|
|
||||||
public PdfDiagram()
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
}
|
|
||||||
|
|
||||||
public PdfDiagram(IContainer container)
|
|
||||||
{
|
|
||||||
container.Add(this);
|
|
||||||
|
|
||||||
InitializeComponent();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void CreateDiagram(PdfDiagramInfo info)
|
|
||||||
{
|
|
||||||
info.CheckFields();
|
|
||||||
SaveToPdf.CreatePdf(info);
|
|
||||||
SaveToPdf.CreateParagraph(new PdfParagraph
|
|
||||||
{
|
|
||||||
Text = info.Title,
|
|
||||||
Style = "NormalTitle",
|
|
||||||
ParagraphAlignment = PdfParagraphAlignmentType.Center
|
|
||||||
});
|
|
||||||
SaveToPdf.CreatePieChart(info);
|
|
||||||
SaveToPdf.SavePdf(info);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
using ComponentLibrary1.office_package.HelperEnums;
|
|
||||||
using ComponentLibrary1.office_package.HelperModels;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ComponentLibrary1.pdf_diagram
|
|
||||||
{
|
|
||||||
public class PdfDiagramInfo : IPdfInfo, IPdfPieChartParameters
|
|
||||||
{
|
|
||||||
public string FileName { get; set; } = string.Empty;
|
|
||||||
public string Title { get; set; } = string.Empty;
|
|
||||||
public string ChartTitle { get; set; } = string.Empty;
|
|
||||||
public PdfDiagramLegendLocation LegendLocation { get; set; } = PdfDiagramLegendLocation.Right;
|
|
||||||
public PdfDiagramSeries Series { get; set; } = new();
|
|
||||||
|
|
||||||
public void CheckFields()
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(FileName))
|
|
||||||
throw new ArgumentNullException(nameof(FileName), "File path and name cannot be null or empty.");
|
|
||||||
if (string.IsNullOrEmpty(Title))
|
|
||||||
throw new ArgumentNullException(nameof(Title), "Title cannot be null or empty.");
|
|
||||||
if (Series == null)
|
|
||||||
throw new ArgumentNullException(nameof(Series), "Series cannot be null or empty.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
36
ComponentLibrary1/pdf_image/PdfImage.Designer.cs
generated
36
ComponentLibrary1/pdf_image/PdfImage.Designer.cs
generated
@ -1,36 +0,0 @@
|
|||||||
namespace ComponentLibrary1.pdf_image
|
|
||||||
{
|
|
||||||
partial class PdfImage
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Обязательная переменная конструктора.
|
|
||||||
/// </summary>
|
|
||||||
private System.ComponentModel.IContainer components = null;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Освободить все используемые ресурсы.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
|
|
||||||
protected override void Dispose(bool disposing)
|
|
||||||
{
|
|
||||||
if (disposing && (components != null))
|
|
||||||
{
|
|
||||||
components.Dispose();
|
|
||||||
}
|
|
||||||
base.Dispose(disposing);
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Код, автоматически созданный конструктором компонентов
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Требуемый метод для поддержки конструктора — не изменяйте
|
|
||||||
/// содержимое этого метода с помощью редактора кода.
|
|
||||||
/// </summary>
|
|
||||||
private void InitializeComponent()
|
|
||||||
{
|
|
||||||
components = new System.ComponentModel.Container();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,47 +0,0 @@
|
|||||||
using ComponentLibrary1.office_package;
|
|
||||||
using ComponentLibrary1.office_package.HelperEnums;
|
|
||||||
using ComponentLibrary1.office_package.HelperModels;
|
|
||||||
using ComponentLibrary1.office_package.Implements;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ComponentLibrary1.pdf_image
|
|
||||||
{
|
|
||||||
public partial class PdfImage : Component
|
|
||||||
{
|
|
||||||
ISaveToPdf SaveToPdf = new SaveToPdf();
|
|
||||||
|
|
||||||
public PdfImage()
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
}
|
|
||||||
|
|
||||||
public PdfImage(IContainer container)
|
|
||||||
{
|
|
||||||
container.Add(this);
|
|
||||||
InitializeComponent();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void CreatePdf(PdfImageInfo info)
|
|
||||||
{
|
|
||||||
info.CheckFields();
|
|
||||||
SaveToPdf.CreatePdf(info);
|
|
||||||
SaveToPdf.CreateParagraph(new PdfParagraph
|
|
||||||
{
|
|
||||||
Text = info.Title,
|
|
||||||
Style = "NormalTitle",
|
|
||||||
ParagraphAlignment = PdfParagraphAlignmentType.Center
|
|
||||||
});
|
|
||||||
foreach (var image in info.Images)
|
|
||||||
{
|
|
||||||
SaveToPdf.CreateImage(image);
|
|
||||||
}
|
|
||||||
SaveToPdf.SavePdf(info);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,24 +0,0 @@
|
|||||||
using ComponentLibrary1.office_package.HelperModels;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ComponentLibrary1.pdf_image
|
|
||||||
{
|
|
||||||
public class PdfImageInfo : IPdfInfo
|
|
||||||
{
|
|
||||||
public string FileName { get; set; } = string.Empty;
|
|
||||||
public string Title { get; set; } = string.Empty;
|
|
||||||
public List<byte[]> Images { get; set; } = new List<byte[]>();
|
|
||||||
|
|
||||||
public void CheckFields()
|
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(FileName) || string.IsNullOrWhiteSpace(Title) || Images == null || Images.Count == 0)
|
|
||||||
{
|
|
||||||
throw new ArgumentException("Все поля должны быть заполнены.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
36
ComponentLibrary1/pdf_table/PdfTable.Designer.cs
generated
36
ComponentLibrary1/pdf_table/PdfTable.Designer.cs
generated
@ -1,36 +0,0 @@
|
|||||||
namespace ComponentLibrary1.pdf_table
|
|
||||||
{
|
|
||||||
partial class PdfTable
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Обязательная переменная конструктора.
|
|
||||||
/// </summary>
|
|
||||||
private System.ComponentModel.IContainer components = null;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Освободить все используемые ресурсы.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
|
|
||||||
protected override void Dispose(bool disposing)
|
|
||||||
{
|
|
||||||
if (disposing && (components != null))
|
|
||||||
{
|
|
||||||
components.Dispose();
|
|
||||||
}
|
|
||||||
base.Dispose(disposing);
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Код, автоматически созданный конструктором компонентов
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Требуемый метод для поддержки конструктора — не изменяйте
|
|
||||||
/// содержимое этого метода с помощью редактора кода.
|
|
||||||
/// </summary>
|
|
||||||
private void InitializeComponent()
|
|
||||||
{
|
|
||||||
components = new System.ComponentModel.Container();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,152 +0,0 @@
|
|||||||
using ComponentLibrary1.office_package;
|
|
||||||
using ComponentLibrary1.office_package.HelperEnums;
|
|
||||||
using ComponentLibrary1.office_package.HelperModels;
|
|
||||||
using ComponentLibrary1.office_package.Implements;
|
|
||||||
using MigraDoc.DocumentObjectModel;
|
|
||||||
using MigraDoc.Rendering;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ComponentLibrary1.pdf_table
|
|
||||||
{
|
|
||||||
public partial class PdfTable : Component
|
|
||||||
{
|
|
||||||
ISaveToPdf SaveToPdf = new SaveToPdf();
|
|
||||||
|
|
||||||
public PdfTable()
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
}
|
|
||||||
|
|
||||||
public PdfTable(IContainer container)
|
|
||||||
{
|
|
||||||
container.Add(this);
|
|
||||||
|
|
||||||
InitializeComponent();
|
|
||||||
}
|
|
||||||
public void CreatePdf<T>(PdfTableInfo<T> info)
|
|
||||||
{
|
|
||||||
info.CheckFields();
|
|
||||||
SaveToPdf.CreatePdf(info);
|
|
||||||
SaveToPdf.CreateParagraph(new PdfParagraph
|
|
||||||
{
|
|
||||||
Text = info.Title,
|
|
||||||
Style = "NormalTitle",
|
|
||||||
ParagraphAlignment = PdfParagraphAlignmentType.Center
|
|
||||||
});
|
|
||||||
SaveToPdf.CreateTableWithColumns(info.Data.Count + 2);
|
|
||||||
SaveToPdf.CreateRow(new PdfRowParameters());
|
|
||||||
int rowIndex = 0;
|
|
||||||
int columnIndex = 0;
|
|
||||||
List<string> properties = new List<string>();
|
|
||||||
string? header;
|
|
||||||
foreach (var node in info.Headers)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(node.Text))
|
|
||||||
{
|
|
||||||
throw new Exception("Cannot read header");
|
|
||||||
}
|
|
||||||
SaveToPdf.CreateRow(new PdfRowParameters());
|
|
||||||
SaveToPdf.InsertTextIntoCell(
|
|
||||||
rowIndex,
|
|
||||||
columnIndex,
|
|
||||||
new PdfCellParameters
|
|
||||||
{
|
|
||||||
Text = node.Text,
|
|
||||||
Style = "NormalTitle",
|
|
||||||
ParagraphAlignment = PdfParagraphAlignmentType.Center
|
|
||||||
});
|
|
||||||
if (node.Nodes.Count == 0)
|
|
||||||
{
|
|
||||||
SaveToPdf.MergeCells(new PdfCellsMergeParameters
|
|
||||||
{
|
|
||||||
RowIndex = rowIndex,
|
|
||||||
ColumnIndex = columnIndex,
|
|
||||||
Direction = PdfCellsMergeDirections.Right
|
|
||||||
});
|
|
||||||
header = node.Tag as string;
|
|
||||||
if (header == null)
|
|
||||||
{
|
|
||||||
throw new Exception("Cannot read property name");
|
|
||||||
}
|
|
||||||
properties.Add(header);
|
|
||||||
rowIndex++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int mergeRowIndex = rowIndex;
|
|
||||||
int mergeColumnIndex = columnIndex;
|
|
||||||
foreach (TreeNode child in node.Nodes)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(child.Text))
|
|
||||||
{
|
|
||||||
throw new Exception("Cannot read header");
|
|
||||||
}
|
|
||||||
SaveToPdf.CreateRow(new PdfRowParameters());
|
|
||||||
SaveToPdf.InsertTextIntoCell(
|
|
||||||
rowIndex,
|
|
||||||
columnIndex + 1,
|
|
||||||
new PdfCellParameters
|
|
||||||
{
|
|
||||||
Text = child.Text,
|
|
||||||
Style = "NormalTitle",
|
|
||||||
ParagraphAlignment = PdfParagraphAlignmentType.Left
|
|
||||||
});
|
|
||||||
header = child.Tag as string;
|
|
||||||
if (header == null)
|
|
||||||
{
|
|
||||||
throw new Exception("Cannot read property name");
|
|
||||||
}
|
|
||||||
properties.Add(header);
|
|
||||||
rowIndex++;
|
|
||||||
}
|
|
||||||
SaveToPdf.MergeCells(new PdfCellsMergeParameters
|
|
||||||
{
|
|
||||||
RowIndex = mergeRowIndex,
|
|
||||||
ColumnIndex = mergeColumnIndex,
|
|
||||||
Direction = PdfCellsMergeDirections.Down,
|
|
||||||
CellNumber = node.Nodes.Count - 1
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
columnIndex = 2;
|
|
||||||
foreach (var obj in info.Data)
|
|
||||||
{
|
|
||||||
if (obj == null)
|
|
||||||
{
|
|
||||||
throw new Exception("Table Data element cannot be null");
|
|
||||||
}
|
|
||||||
List<string> cells = new List<string>();
|
|
||||||
for (int i = 0; i < properties.Count; i++)
|
|
||||||
{
|
|
||||||
string propertyName = properties[i];
|
|
||||||
var property = obj.GetType().GetProperty(propertyName);
|
|
||||||
if (property is null)
|
|
||||||
{
|
|
||||||
throw new ArgumentException($"Failed to find property {propertyName} in provided objects class");
|
|
||||||
}
|
|
||||||
var value = property.GetValue(obj)?.ToString();
|
|
||||||
if (value == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentException($"Failed to find property {propertyName} in provided objects class");
|
|
||||||
}
|
|
||||||
cells.Add(value);
|
|
||||||
}
|
|
||||||
SaveToPdf.InsertTextIntoColumn(new PdfColumnParameters
|
|
||||||
{
|
|
||||||
Texts = cells,
|
|
||||||
ColumnIndex = columnIndex,
|
|
||||||
Style = "Normal",
|
|
||||||
ParagraphAlignment= PdfParagraphAlignmentType.Left
|
|
||||||
});
|
|
||||||
columnIndex++;
|
|
||||||
}
|
|
||||||
SaveToPdf.SavePdf(info);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
using ComponentLibrary1.office_package.HelperModels;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ComponentLibrary1.pdf_table
|
|
||||||
{
|
|
||||||
public class PdfTableInfo<T> : IPdfInfo
|
|
||||||
{
|
|
||||||
public string FileName { get; set; } = string.Empty;
|
|
||||||
public string Title { get; set; } = string.Empty;
|
|
||||||
public List<TreeNode> Headers { get; set; } = new();
|
|
||||||
public List<T> Data { get; set; } = new();
|
|
||||||
|
|
||||||
public void CheckFields()
|
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(FileName))
|
|
||||||
throw new ArgumentException("Имя файла не может быть пустым.", nameof(FileName));
|
|
||||||
if (string.IsNullOrWhiteSpace(Title))
|
|
||||||
throw new ArgumentException("Название документа не может быть пустым.", nameof(Title));
|
|
||||||
if (Headers == null || Headers.Count == 0)
|
|
||||||
throw new ArgumentException("Заголовки для шапки не могут быть пустыми.", nameof(Headers));
|
|
||||||
if (Data == null || Data.Count == 0)
|
|
||||||
throw new ArgumentException("Данные для таблицы не могут быть пустыми.", nameof(Data));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
55
ComponentLibrary1/tree_list/TreeList.Designer.cs
generated
55
ComponentLibrary1/tree_list/TreeList.Designer.cs
generated
@ -1,55 +0,0 @@
|
|||||||
namespace ComponentLibrary1.tree_list
|
|
||||||
{
|
|
||||||
partial class TreeList
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Обязательная переменная конструктора.
|
|
||||||
/// </summary>
|
|
||||||
private System.ComponentModel.IContainer components = null;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Освободить все используемые ресурсы.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
|
|
||||||
protected override void Dispose(bool disposing)
|
|
||||||
{
|
|
||||||
if (disposing && (components != null))
|
|
||||||
{
|
|
||||||
components.Dispose();
|
|
||||||
}
|
|
||||||
base.Dispose(disposing);
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Код, автоматически созданный конструктором компонентов
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Требуемый метод для поддержки конструктора — не изменяйте
|
|
||||||
/// содержимое этого метода с помощью редактора кода.
|
|
||||||
/// </summary>
|
|
||||||
private void InitializeComponent()
|
|
||||||
{
|
|
||||||
treeView = new TreeView();
|
|
||||||
SuspendLayout();
|
|
||||||
//
|
|
||||||
// treeView
|
|
||||||
//
|
|
||||||
treeView.Dock = DockStyle.Fill;
|
|
||||||
treeView.Location = new Point(0, 0);
|
|
||||||
treeView.Name = "treeView";
|
|
||||||
treeView.Size = new Size(150, 150);
|
|
||||||
treeView.TabIndex = 0;
|
|
||||||
//
|
|
||||||
// TreeList
|
|
||||||
//
|
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
|
||||||
Controls.Add(treeView);
|
|
||||||
Name = "TreeList";
|
|
||||||
ResumeLayout(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
private TreeView treeView;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,106 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections;
|
|
||||||
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 System.Xml.Linq;
|
|
||||||
|
|
||||||
namespace ComponentLibrary1.tree_list
|
|
||||||
{
|
|
||||||
public partial class TreeList : UserControl
|
|
||||||
{
|
|
||||||
private List<string> CategoriesNames = new List<string>();
|
|
||||||
|
|
||||||
public TreeList()
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetCategories (List<string> categories)
|
|
||||||
{
|
|
||||||
CategoriesNames = categories;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AddTreeListObject<T>(T treeListObject) where T : class, new()
|
|
||||||
{
|
|
||||||
if (CategoriesNames == null || CategoriesNames.Count == 0)
|
|
||||||
{
|
|
||||||
throw new Exception("CategoriesNames is null or empty");
|
|
||||||
}
|
|
||||||
if (treeListObject == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentException("treeObject is null");
|
|
||||||
}
|
|
||||||
Queue<string> values = new Queue<string>();
|
|
||||||
Type type = treeListObject.GetType();
|
|
||||||
foreach (string categoryName in CategoriesNames)
|
|
||||||
{
|
|
||||||
string? value = type.GetProperty(categoryName)?.GetValue(treeListObject) as string;
|
|
||||||
if (string.IsNullOrEmpty(value))
|
|
||||||
{
|
|
||||||
throw new ArgumentException($"{type.Name}.{categoryName} is not found or is not a not empty string");
|
|
||||||
}
|
|
||||||
values.Enqueue(value);
|
|
||||||
}
|
|
||||||
TreeNodeCollection nodeCollection = treeView.Nodes;
|
|
||||||
string hierarchyElement = values.Dequeue();
|
|
||||||
while (values.Count > 0)
|
|
||||||
{
|
|
||||||
bool branchIsFind = false;
|
|
||||||
foreach (TreeNode node in nodeCollection)
|
|
||||||
{
|
|
||||||
if (node.Text == hierarchyElement)
|
|
||||||
{
|
|
||||||
branchIsFind = true;
|
|
||||||
nodeCollection = node.Nodes;
|
|
||||||
hierarchyElement = values.Dequeue();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (branchIsFind)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
TreeNode newBranch = nodeCollection.Add(hierarchyElement);
|
|
||||||
nodeCollection = newBranch.Nodes;
|
|
||||||
hierarchyElement = values.Dequeue();
|
|
||||||
}
|
|
||||||
TreeNode newLeaf = nodeCollection.Add(hierarchyElement);
|
|
||||||
for(TreeNode node = newLeaf; node != null; node = node.Parent)
|
|
||||||
{
|
|
||||||
node.Expand();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public T? GetSelectedObject<T>() where T : class, new()
|
|
||||||
{
|
|
||||||
if(treeView.SelectedNode == null)
|
|
||||||
{
|
|
||||||
throw new Exception("There are no selected nodes");
|
|
||||||
}
|
|
||||||
T result = new T();
|
|
||||||
Type type = typeof(T);
|
|
||||||
int i;
|
|
||||||
TreeNode treeNode = treeView.SelectedNode;
|
|
||||||
for (i = CategoriesNames.Count - 1; i >= 0 && treeNode != null; i--, treeNode = treeNode.Parent)
|
|
||||||
{
|
|
||||||
type.GetProperty(CategoriesNames[i])?.SetValue(result, treeNode.Text);
|
|
||||||
}
|
|
||||||
if(treeNode != null || i >= 0)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Clear()
|
|
||||||
{
|
|
||||||
treeView.Nodes.Clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,120 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<root>
|
|
||||||
<!--
|
|
||||||
Microsoft ResX Schema
|
|
||||||
|
|
||||||
Version 2.0
|
|
||||||
|
|
||||||
The primary goals of this format is to allow a simple XML format
|
|
||||||
that is mostly human readable. The generation and parsing of the
|
|
||||||
various data types are done through the TypeConverter classes
|
|
||||||
associated with the data types.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
... ado.net/XML headers & schema ...
|
|
||||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
|
||||||
<resheader name="version">2.0</resheader>
|
|
||||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
|
||||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
|
||||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
|
||||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
|
||||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
|
||||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
|
||||||
</data>
|
|
||||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
|
||||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
|
||||||
<comment>This is a comment</comment>
|
|
||||||
</data>
|
|
||||||
|
|
||||||
There are any number of "resheader" rows that contain simple
|
|
||||||
name/value pairs.
|
|
||||||
|
|
||||||
Each data row contains a name, and value. The row also contains a
|
|
||||||
type or mimetype. Type corresponds to a .NET class that support
|
|
||||||
text/value conversion through the TypeConverter architecture.
|
|
||||||
Classes that don't support this are serialized and stored with the
|
|
||||||
mimetype set.
|
|
||||||
|
|
||||||
The mimetype is used for serialized objects, and tells the
|
|
||||||
ResXResourceReader how to depersist the object. This is currently not
|
|
||||||
extensible. For a given mimetype the value must be set accordingly:
|
|
||||||
|
|
||||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
|
||||||
that the ResXResourceWriter will generate, however the reader can
|
|
||||||
read any of the formats listed below.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.binary.base64
|
|
||||||
value : The object must be serialized with
|
|
||||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.soap.base64
|
|
||||||
value : The object must be serialized with
|
|
||||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
|
||||||
value : The object must be serialized into a byte array
|
|
||||||
: using a System.ComponentModel.TypeConverter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
-->
|
|
||||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
|
||||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
|
||||||
<xsd:element name="root" msdata:IsDataSet="true">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:choice maxOccurs="unbounded">
|
|
||||||
<xsd:element name="metadata">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:sequence>
|
|
||||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
|
||||||
</xsd:sequence>
|
|
||||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
|
||||||
<xsd:attribute name="type" type="xsd:string" />
|
|
||||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
|
||||||
<xsd:attribute ref="xml:space" />
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
<xsd:element name="assembly">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:attribute name="alias" type="xsd:string" />
|
|
||||||
<xsd:attribute name="name" type="xsd:string" />
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
<xsd:element name="data">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:sequence>
|
|
||||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
|
||||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
|
||||||
</xsd:sequence>
|
|
||||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
|
||||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
|
||||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
|
||||||
<xsd:attribute ref="xml:space" />
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
<xsd:element name="resheader">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:sequence>
|
|
||||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
|
||||||
</xsd:sequence>
|
|
||||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
</xsd:choice>
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
</xsd:schema>
|
|
||||||
<resheader name="resmimetype">
|
|
||||||
<value>text/microsoft-resx</value>
|
|
||||||
</resheader>
|
|
||||||
<resheader name="version">
|
|
||||||
<value>2.0</value>
|
|
||||||
</resheader>
|
|
||||||
<resheader name="reader">
|
|
||||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
|
||||||
</resheader>
|
|
||||||
<resheader name="writer">
|
|
||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
|
||||||
</resheader>
|
|
||||||
</root>
|
|
13
LibraryContracts/LibraryContracts.csproj
Normal file
13
LibraryContracts/LibraryContracts.csproj
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\LibraryDataModels\LibraryDataModels.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
19
LibraryContracts/StorageContracts/IAuthorStorage.cs
Normal file
19
LibraryContracts/StorageContracts/IAuthorStorage.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using LibraryDataModels.Dtos;
|
||||||
|
using LibraryDataModels.Views;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LibraryContracts.StorageContracts
|
||||||
|
{
|
||||||
|
public interface IAuthorStorage
|
||||||
|
{
|
||||||
|
List<AuthorView> GetFullList();
|
||||||
|
AuthorView? GetElement(AuthorDto model);
|
||||||
|
AuthorView? Insert(AuthorDto model);
|
||||||
|
AuthorView? Update(AuthorDto model);
|
||||||
|
AuthorView? Delete(AuthorDto model);
|
||||||
|
}
|
||||||
|
}
|
19
LibraryContracts/StorageContracts/IBookStorage.cs
Normal file
19
LibraryContracts/StorageContracts/IBookStorage.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using LibraryDataModels.Dtos;
|
||||||
|
using LibraryDataModels.Views;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LibraryContracts.StorageContracts
|
||||||
|
{
|
||||||
|
public interface IBookStorage
|
||||||
|
{
|
||||||
|
List<BookView> GetFullList();
|
||||||
|
BookView? GetElement(BookDto model);
|
||||||
|
BookView? Insert(BookDto model);
|
||||||
|
BookView? Update(BookDto model);
|
||||||
|
BookView? Delete(BookDto model);
|
||||||
|
}
|
||||||
|
}
|
@ -4,11 +4,10 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace ComponentLibrary1.office_package.HelperEnums
|
namespace LibraryDataModels.AbstractModels
|
||||||
{
|
{
|
||||||
public enum PdfCellsMergeDirections
|
public interface IAuthor : IId
|
||||||
{
|
{
|
||||||
Down,
|
string Name { get; }
|
||||||
Right
|
|
||||||
}
|
}
|
||||||
}
|
}
|
16
LibraryDataModels/AbstractModels/IBook.cs
Normal file
16
LibraryDataModels/AbstractModels/IBook.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LibraryDataModels.AbstractModels
|
||||||
|
{
|
||||||
|
public interface IBook : IId
|
||||||
|
{
|
||||||
|
string Name { get; }
|
||||||
|
string BookCover { get; }
|
||||||
|
string Author { get; }
|
||||||
|
string ReleaseDate { get; }
|
||||||
|
}
|
||||||
|
}
|
@ -4,13 +4,10 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace ComponentLibrary1.office_package.HelperEnums
|
namespace LibraryDataModels.AbstractModels
|
||||||
{
|
{
|
||||||
public enum PdfDiagramLegendLocation
|
public interface IId
|
||||||
{
|
{
|
||||||
Left,
|
int Id { get; }
|
||||||
Right,
|
|
||||||
Top,
|
|
||||||
Bottom,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
21
LibraryDataModels/Dtos/AuthorDto.cs
Normal file
21
LibraryDataModels/Dtos/AuthorDto.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
using LibraryDataModels.AbstractModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LibraryDataModels.Dtos
|
||||||
|
{
|
||||||
|
public class AuthorDto : IAuthor
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Name { get; set; } = string.Empty;
|
||||||
|
public AuthorDto() {}
|
||||||
|
public AuthorDto(IAuthor author)
|
||||||
|
{
|
||||||
|
Id = author.Id;
|
||||||
|
Name = author.Name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
27
LibraryDataModels/Dtos/BookDto.cs
Normal file
27
LibraryDataModels/Dtos/BookDto.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
using LibraryDataModels.AbstractModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LibraryDataModels.Dtos
|
||||||
|
{
|
||||||
|
public class BookDto : IBook
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Name { get; set; } = string.Empty;
|
||||||
|
public string BookCover { get; set; } = string.Empty;
|
||||||
|
public string Author { get; set; } = string.Empty;
|
||||||
|
public string ReleaseDate { get; set; } = string.Empty;
|
||||||
|
public BookDto() {}
|
||||||
|
public BookDto(IBook book)
|
||||||
|
{
|
||||||
|
Id = book.Id;
|
||||||
|
Name = book.Name;
|
||||||
|
BookCover = book.BookCover;
|
||||||
|
Author = book.Author;
|
||||||
|
ReleaseDate = book.ReleaseDate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
9
LibraryDataModels/LibraryDataModels.csproj
Normal file
9
LibraryDataModels/LibraryDataModels.csproj
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
24
LibraryDataModels/Views/AuthorView.cs
Normal file
24
LibraryDataModels/Views/AuthorView.cs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
using LibraryDataModels.AbstractModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LibraryDataModels.Views
|
||||||
|
{
|
||||||
|
public class AuthorView : IAuthor
|
||||||
|
{
|
||||||
|
public int Id { get; set; } = -1;
|
||||||
|
|
||||||
|
[DisplayName("ФИО автора")]
|
||||||
|
public string Name { get; set; } = string.Empty;
|
||||||
|
public AuthorView() {}
|
||||||
|
public AuthorView(IAuthor author)
|
||||||
|
{
|
||||||
|
Id = author.Id;
|
||||||
|
Name = author.Name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
34
LibraryDataModels/Views/BookView.cs
Normal file
34
LibraryDataModels/Views/BookView.cs
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
using LibraryDataModels.AbstractModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LibraryDataModels.Views
|
||||||
|
{
|
||||||
|
public class BookView : IBook
|
||||||
|
{
|
||||||
|
public int Id { get; set; } = -1;
|
||||||
|
|
||||||
|
[DisplayName("Название")]
|
||||||
|
public string Name { get; set; } = string.Empty;
|
||||||
|
public string BookCover { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[DisplayName("ФИО автора")]
|
||||||
|
public string Author { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[DisplayName("Дата издания")]
|
||||||
|
public string ReleaseDate { get; set; } = string.Empty;
|
||||||
|
public BookView() {}
|
||||||
|
public BookView(IBook book)
|
||||||
|
{
|
||||||
|
Id = book.Id;
|
||||||
|
Name = book.Name;
|
||||||
|
BookCover = book.BookCover;
|
||||||
|
Author = book.Author;
|
||||||
|
ReleaseDate = book.ReleaseDate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
23
LibraryDatabase/LibraryDatabase.csproj
Normal file
23
LibraryDatabase/LibraryDatabase.csproj
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.16" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.16" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.16">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\LibraryContracts\LibraryContracts.csproj" />
|
||||||
|
<ProjectReference Include="..\LibraryDataModels\LibraryDataModels.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
24
LibraryDatabase/LibraryDatabaseContext.cs
Normal file
24
LibraryDatabase/LibraryDatabaseContext.cs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using LibraryDatabase.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace LibraryDatabase
|
||||||
|
{
|
||||||
|
internal class LibraryDatabaseContext : DbContext
|
||||||
|
{
|
||||||
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
|
{
|
||||||
|
if (optionsBuilder.IsConfigured == false)
|
||||||
|
{
|
||||||
|
optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=LibratyDataBase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||||
|
}
|
||||||
|
base.OnConfiguring(optionsBuilder);
|
||||||
|
}
|
||||||
|
public virtual DbSet<Book> Books { set; get; }
|
||||||
|
public virtual DbSet<Author> Authors { set; get; }
|
||||||
|
}
|
||||||
|
}
|
82
LibraryDatabase/Migrations/20241010133359_InitialCreate.Designer.cs
generated
Normal file
82
LibraryDatabase/Migrations/20241010133359_InitialCreate.Designer.cs
generated
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using LibraryDatabase;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace LibraryDatabase.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(LibraryDatabaseContext))]
|
||||||
|
[Migration("20241010133359_InitialCreate")]
|
||||||
|
partial class InitialCreate
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "7.0.16")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||||
|
|
||||||
|
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("LibraryDatabase.Models.Author", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int")
|
||||||
|
.HasColumnName("author_id");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)")
|
||||||
|
.HasColumnName("author_name");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("authors");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LibraryDatabase.Models.Book", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int")
|
||||||
|
.HasColumnName("book_id");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Author")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)")
|
||||||
|
.HasColumnName("book_author_name");
|
||||||
|
|
||||||
|
b.Property<string>("BookCover")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)")
|
||||||
|
.HasColumnName("book_cover");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)")
|
||||||
|
.HasColumnName("book_name");
|
||||||
|
|
||||||
|
b.Property<string>("ReleaseDate")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)")
|
||||||
|
.HasColumnName("book_release_date");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("books");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
53
LibraryDatabase/Migrations/20241010133359_InitialCreate.cs
Normal file
53
LibraryDatabase/Migrations/20241010133359_InitialCreate.cs
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace LibraryDatabase.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class InitialCreate : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "authors",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
author_id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
author_name = table.Column<string>(type: "nvarchar(max)", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_authors", x => x.author_id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "books",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
book_id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
book_name = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||||
|
book_cover = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||||
|
book_author_name = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||||
|
book_release_date = table.Column<string>(type: "nvarchar(max)", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_books", x => x.book_id);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "authors");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "books");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,79 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using LibraryDatabase;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace LibraryDatabase.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(LibraryDatabaseContext))]
|
||||||
|
partial class LibraryDatabaseContextModelSnapshot : ModelSnapshot
|
||||||
|
{
|
||||||
|
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "7.0.16")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||||
|
|
||||||
|
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("LibraryDatabase.Models.Author", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int")
|
||||||
|
.HasColumnName("author_id");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)")
|
||||||
|
.HasColumnName("author_name");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("authors");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LibraryDatabase.Models.Book", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int")
|
||||||
|
.HasColumnName("book_id");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Author")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)")
|
||||||
|
.HasColumnName("book_author_name");
|
||||||
|
|
||||||
|
b.Property<string>("BookCover")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)")
|
||||||
|
.HasColumnName("book_cover");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)")
|
||||||
|
.HasColumnName("book_name");
|
||||||
|
|
||||||
|
b.Property<string>("ReleaseDate")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)")
|
||||||
|
.HasColumnName("book_release_date");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("books");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
41
LibraryDatabase/Models/Author.cs
Normal file
41
LibraryDatabase/Models/Author.cs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
using LibraryDataModels.AbstractModels;
|
||||||
|
using LibraryDataModels.Views;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LibraryDatabase.Models
|
||||||
|
{
|
||||||
|
[Table("authors")]
|
||||||
|
public class Author : IAuthor
|
||||||
|
{
|
||||||
|
[Column("author_id")]
|
||||||
|
public int Id { get; private set; }
|
||||||
|
[Required]
|
||||||
|
[Column("author_name")]
|
||||||
|
public string Name { get; private set; } = string.Empty;
|
||||||
|
public Author() {}
|
||||||
|
public Author(IAuthor author)
|
||||||
|
{
|
||||||
|
Id = author.Id;
|
||||||
|
Name = author.Name;
|
||||||
|
}
|
||||||
|
public static Author Create(IAuthor author)
|
||||||
|
{
|
||||||
|
if (author == null)
|
||||||
|
throw new ArgumentNullException("Cannot create author because model is null");
|
||||||
|
return new Author(author);
|
||||||
|
}
|
||||||
|
public void Update(IAuthor author)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(author?.Name))
|
||||||
|
throw new ArgumentNullException("Cannot update author because model is null");
|
||||||
|
Name = author.Name;
|
||||||
|
}
|
||||||
|
public AuthorView GetView => new AuthorView(this);
|
||||||
|
}
|
||||||
|
}
|
61
LibraryDatabase/Models/Book.cs
Normal file
61
LibraryDatabase/Models/Book.cs
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
using LibraryDataModels.AbstractModels;
|
||||||
|
using LibraryDataModels.Views;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LibraryDatabase.Models
|
||||||
|
{
|
||||||
|
[Table("books")]
|
||||||
|
public class Book : IBook
|
||||||
|
{
|
||||||
|
[Column("book_id")]
|
||||||
|
public int Id { get; private set; }
|
||||||
|
[Required]
|
||||||
|
[Column("book_name")]
|
||||||
|
public string Name { get; private set; } = string.Empty;
|
||||||
|
[Required]
|
||||||
|
[Column("book_cover")]
|
||||||
|
public string BookCover { get; private set; } = string.Empty;
|
||||||
|
[Required]
|
||||||
|
[Column("book_author_name")]
|
||||||
|
public string Author { get; private set; } = string.Empty;
|
||||||
|
[Required]
|
||||||
|
[Column("book_release_date")]
|
||||||
|
public string ReleaseDate { get; private set; } = string.Empty;
|
||||||
|
public Book() {}
|
||||||
|
public Book(IBook book)
|
||||||
|
{
|
||||||
|
Id = book.Id;
|
||||||
|
Name = book.Name;
|
||||||
|
BookCover = book.BookCover;
|
||||||
|
Author = book.Author;
|
||||||
|
ReleaseDate = book.ReleaseDate;
|
||||||
|
}
|
||||||
|
public static Book Create(IBook book)
|
||||||
|
{
|
||||||
|
if (book == null)
|
||||||
|
throw new ArgumentNullException("Cannot create book because model is null");
|
||||||
|
return new Book(book);
|
||||||
|
}
|
||||||
|
public void Update(IBook book)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(book?.Name) ||
|
||||||
|
string.IsNullOrWhiteSpace(book?.BookCover) ||
|
||||||
|
string.IsNullOrWhiteSpace(book?.Author) ||
|
||||||
|
string.IsNullOrWhiteSpace(book?.ReleaseDate))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Cannot update book because model is null");
|
||||||
|
}
|
||||||
|
Name = book.Name;
|
||||||
|
BookCover = book.BookCover;
|
||||||
|
Author = book.Author;
|
||||||
|
ReleaseDate = book.ReleaseDate;
|
||||||
|
}
|
||||||
|
public BookView GetView => new BookView(this);
|
||||||
|
}
|
||||||
|
}
|
72
LibraryDatabase/Storages/AuthorStorage.cs
Normal file
72
LibraryDatabase/Storages/AuthorStorage.cs
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
using LibraryContracts.StorageContracts;
|
||||||
|
using LibraryDatabase;
|
||||||
|
using LibraryDatabase.Models;
|
||||||
|
using LibraryDataModels.Dtos;
|
||||||
|
using LibraryDataModels.Views;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.ConstrainedExecution;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LibraryDatabase.Storages
|
||||||
|
{
|
||||||
|
public class AuthorStorage : IAuthorStorage
|
||||||
|
{
|
||||||
|
public List<AuthorView> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new LibraryDatabaseContext();
|
||||||
|
return context.Authors
|
||||||
|
.Select(x => x.GetView)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public AuthorView? GetElement(AuthorDto model)
|
||||||
|
{
|
||||||
|
using var context = new LibraryDatabaseContext();
|
||||||
|
return context.Authors
|
||||||
|
.FirstOrDefault(x => x.Id == model.Id)
|
||||||
|
?.GetView;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AuthorView? Insert(AuthorDto model)
|
||||||
|
{
|
||||||
|
var newAuthor = Author.Create(model);
|
||||||
|
if (newAuthor == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new LibraryDatabaseContext();
|
||||||
|
context.Authors.Add(newAuthor);
|
||||||
|
context.SaveChanges();
|
||||||
|
return newAuthor.GetView;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AuthorView? Update(AuthorDto model)
|
||||||
|
{
|
||||||
|
using var context = new LibraryDatabaseContext();
|
||||||
|
var author = context.Authors.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (author == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
author.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
return author.GetView;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AuthorView? Delete(AuthorDto model)
|
||||||
|
{
|
||||||
|
using var context = new LibraryDatabaseContext();
|
||||||
|
var element = context.Authors.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
context.Authors.Remove(element);
|
||||||
|
context.SaveChanges();
|
||||||
|
return element.GetView;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
70
LibraryDatabase/Storages/BookStorage.cs
Normal file
70
LibraryDatabase/Storages/BookStorage.cs
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
using LibraryContracts.StorageContracts;
|
||||||
|
using LibraryDatabase.Models;
|
||||||
|
using LibraryDataModels.Dtos;
|
||||||
|
using LibraryDataModels.Views;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LibraryDatabase.Storages
|
||||||
|
{
|
||||||
|
public class BookStorage : IBookStorage
|
||||||
|
{
|
||||||
|
public List<BookView> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new LibraryDatabaseContext();
|
||||||
|
return context.Books
|
||||||
|
.Select(x => x.GetView)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public BookView? GetElement(BookDto model)
|
||||||
|
{
|
||||||
|
using var context = new LibraryDatabaseContext();
|
||||||
|
return context.Books
|
||||||
|
.FirstOrDefault(x => x.Id == model.Id)
|
||||||
|
?.GetView;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BookView? Insert(BookDto model)
|
||||||
|
{
|
||||||
|
var newBook = Book.Create(model);
|
||||||
|
if (newBook == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new LibraryDatabaseContext();
|
||||||
|
context.Books.Add(newBook);
|
||||||
|
context.SaveChanges();
|
||||||
|
return newBook.GetView;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BookView? Update(BookDto model)
|
||||||
|
{
|
||||||
|
using var context = new LibraryDatabaseContext();
|
||||||
|
var Book = context.Books.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (Book == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Book.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
return Book.GetView;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BookView? Delete(BookDto model)
|
||||||
|
{
|
||||||
|
using var context = new LibraryDatabaseContext();
|
||||||
|
var element = context.Books.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
context.Books.Remove(element);
|
||||||
|
context.SaveChanges();
|
||||||
|
return element.GetView;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
43
LibraryWinFormsApp.sln
Normal file
43
LibraryWinFormsApp.sln
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.9.34723.18
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibraryWinFormsApp", "LibraryWinFormsApp\LibraryWinFormsApp.csproj", "{E8BD6D99-6C63-42E4-8BBC-6FF8419C7C9E}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibraryContracts", "LibraryContracts\LibraryContracts.csproj", "{70D8ED64-2FC3-40DB-8C27-324439B590AA}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibraryDataModels", "LibraryDataModels\LibraryDataModels.csproj", "{37477D2C-F5EB-418D-A9FA-135A71B430E1}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibraryDatabase", "LibraryDatabase\LibraryDatabase.csproj", "{4F0EC406-67F6-49C1-97C8-F553455780FB}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{E8BD6D99-6C63-42E4-8BBC-6FF8419C7C9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{E8BD6D99-6C63-42E4-8BBC-6FF8419C7C9E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{E8BD6D99-6C63-42E4-8BBC-6FF8419C7C9E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{E8BD6D99-6C63-42E4-8BBC-6FF8419C7C9E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{70D8ED64-2FC3-40DB-8C27-324439B590AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{70D8ED64-2FC3-40DB-8C27-324439B590AA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{70D8ED64-2FC3-40DB-8C27-324439B590AA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{70D8ED64-2FC3-40DB-8C27-324439B590AA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{37477D2C-F5EB-418D-A9FA-135A71B430E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{37477D2C-F5EB-418D-A9FA-135A71B430E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{37477D2C-F5EB-418D-A9FA-135A71B430E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{37477D2C-F5EB-418D-A9FA-135A71B430E1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{4F0EC406-67F6-49C1-97C8-F553455780FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{4F0EC406-67F6-49C1-97C8-F553455780FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{4F0EC406-67F6-49C1-97C8-F553455780FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{4F0EC406-67F6-49C1-97C8-F553455780FB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {1F08A961-9933-4260-9243-C5138D4A82EA}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
15
LibraryWinFormsApp/DocType.cs
Normal file
15
LibraryWinFormsApp/DocType.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LibraryWinFormsApp
|
||||||
|
{
|
||||||
|
public enum DocType
|
||||||
|
{
|
||||||
|
Excel,
|
||||||
|
Word,
|
||||||
|
Pdf
|
||||||
|
}
|
||||||
|
}
|
66
LibraryWinFormsApp/FormAuthors.Designer.cs
generated
Normal file
66
LibraryWinFormsApp/FormAuthors.Designer.cs
generated
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
namespace LibraryWinFormsApp
|
||||||
|
{
|
||||||
|
partial class FormAuthors
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
authorsTable = new DataGridView();
|
||||||
|
((System.ComponentModel.ISupportInitialize)authorsTable).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// authorsTable
|
||||||
|
//
|
||||||
|
authorsTable.AllowUserToAddRows = false;
|
||||||
|
authorsTable.AllowUserToDeleteRows = false;
|
||||||
|
authorsTable.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
authorsTable.Dock = DockStyle.Fill;
|
||||||
|
authorsTable.Location = new Point(0, 0);
|
||||||
|
authorsTable.Name = "authorsTable";
|
||||||
|
authorsTable.RowTemplate.Height = 25;
|
||||||
|
authorsTable.Size = new Size(800, 450);
|
||||||
|
authorsTable.TabIndex = 0;
|
||||||
|
authorsTable.CellEndEdit += authorsTable_CellEndEdit;
|
||||||
|
authorsTable.KeyDown += authorsTable_KeyDown;
|
||||||
|
//
|
||||||
|
// FormAuthors
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(800, 450);
|
||||||
|
Controls.Add(authorsTable);
|
||||||
|
Name = "FormAuthors";
|
||||||
|
Text = "Авторы";
|
||||||
|
Load += FormAuthors_Load;
|
||||||
|
((System.ComponentModel.ISupportInitialize)authorsTable).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private DataGridView authorsTable;
|
||||||
|
}
|
||||||
|
}
|
113
LibraryWinFormsApp/FormAuthors.cs
Normal file
113
LibraryWinFormsApp/FormAuthors.cs
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
using LibraryContracts.StorageContracts;
|
||||||
|
using LibraryDataModels.Dtos;
|
||||||
|
using LibraryDataModels.Views;
|
||||||
|
using Microsoft.IdentityModel.Tokens;
|
||||||
|
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 LibraryWinFormsApp
|
||||||
|
{
|
||||||
|
public partial class FormAuthors : Form
|
||||||
|
{
|
||||||
|
private IAuthorStorage _authorStorage;
|
||||||
|
private List<AuthorView> _authors;
|
||||||
|
public FormAuthors(IAuthorStorage authorStorage)
|
||||||
|
{
|
||||||
|
_authorStorage = authorStorage;
|
||||||
|
_authors = new List<AuthorView>();
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FormAuthors_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadData()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_authors = _authorStorage.GetFullList();
|
||||||
|
if (_authors != null)
|
||||||
|
{
|
||||||
|
authorsTable.DataSource = _authors;
|
||||||
|
authorsTable.Columns[0].Visible = false;
|
||||||
|
authorsTable.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void authorsTable_CellEndEdit(object sender, DataGridViewCellEventArgs e)
|
||||||
|
{
|
||||||
|
var cellValue = (string)authorsTable.CurrentRow.Cells[1].EditedFormattedValue;
|
||||||
|
if (!string.IsNullOrEmpty(cellValue))
|
||||||
|
{
|
||||||
|
var keyValue = Convert.ToInt32(authorsTable.CurrentRow.Cells[0].Value);
|
||||||
|
if (keyValue != -1)
|
||||||
|
{
|
||||||
|
_authorStorage.Update(new AuthorDto()
|
||||||
|
{
|
||||||
|
Id = keyValue,
|
||||||
|
Name = cellValue,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_authorStorage.Insert(new AuthorDto()
|
||||||
|
{
|
||||||
|
Name = cellValue,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Введена пустая строка", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void authorsTable_KeyDown(object sender, KeyEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.KeyData == Keys.Insert)
|
||||||
|
{
|
||||||
|
if (authorsTable.Rows.Count == 0)
|
||||||
|
{
|
||||||
|
_authors.Add(new AuthorView());
|
||||||
|
authorsTable.DataSource = new BindingList<AuthorView>(_authors);
|
||||||
|
authorsTable.CurrentCell = authorsTable.Rows[0].Cells[1];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (authorsTable.Rows[authorsTable.Rows.Count - 1].Cells[1].Value != null)
|
||||||
|
{
|
||||||
|
_authors.Add(new AuthorView());
|
||||||
|
authorsTable.DataSource = new BindingList<AuthorView>(_authors);
|
||||||
|
authorsTable.CurrentCell = authorsTable.Rows[authorsTable.Rows.Count - 1].Cells[1];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (e.KeyData == Keys.Delete)
|
||||||
|
{
|
||||||
|
if (MessageBox.Show("Удалить выбранный элемент?", "Удаление",
|
||||||
|
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
|
{
|
||||||
|
_authorStorage.Delete(new AuthorDto()
|
||||||
|
{
|
||||||
|
Id = Convert.ToInt32(authorsTable.CurrentRow.Cells[0].Value),
|
||||||
|
});
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
180
LibraryWinFormsApp/FormBook.Designer.cs
generated
Normal file
180
LibraryWinFormsApp/FormBook.Designer.cs
generated
Normal file
@ -0,0 +1,180 @@
|
|||||||
|
namespace LibraryWinFormsApp
|
||||||
|
{
|
||||||
|
partial class FormBook
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
releaseDateField = new Library_var_4_lab_1.DateInputBox();
|
||||||
|
nameField = new TextBox();
|
||||||
|
coverLabel = new Label();
|
||||||
|
nameLabel = new Label();
|
||||||
|
releaseDateLabel = new Label();
|
||||||
|
authorLabel = new Label();
|
||||||
|
authorField = new YunusovComponentsLibrary.SelectedComponent();
|
||||||
|
saveButton = new Button();
|
||||||
|
pictureBox = new PictureBox();
|
||||||
|
changeCoverButton = new Button();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// releaseDateField
|
||||||
|
//
|
||||||
|
releaseDateField.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
|
releaseDateField.Location = new Point(8, 67);
|
||||||
|
releaseDateField.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
releaseDateField.Name = "releaseDateField";
|
||||||
|
releaseDateField.Size = new Size(215, 61);
|
||||||
|
releaseDateField.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// nameField
|
||||||
|
//
|
||||||
|
nameField.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
|
nameField.Location = new Point(8, 24);
|
||||||
|
nameField.Name = "nameField";
|
||||||
|
nameField.Size = new Size(215, 23);
|
||||||
|
nameField.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// coverLabel
|
||||||
|
//
|
||||||
|
coverLabel.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
coverLabel.AutoSize = true;
|
||||||
|
coverLabel.Location = new Point(229, 4);
|
||||||
|
coverLabel.Name = "coverLabel";
|
||||||
|
coverLabel.Size = new Size(58, 15);
|
||||||
|
coverLabel.TabIndex = 3;
|
||||||
|
coverLabel.Text = "Обложка";
|
||||||
|
//
|
||||||
|
// nameLabel
|
||||||
|
//
|
||||||
|
nameLabel.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
|
nameLabel.AutoSize = true;
|
||||||
|
nameLabel.Location = new Point(8, 4);
|
||||||
|
nameLabel.Name = "nameLabel";
|
||||||
|
nameLabel.Size = new Size(59, 15);
|
||||||
|
nameLabel.TabIndex = 4;
|
||||||
|
nameLabel.Text = "Название";
|
||||||
|
//
|
||||||
|
// releaseDateLabel
|
||||||
|
//
|
||||||
|
releaseDateLabel.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
|
releaseDateLabel.AutoSize = true;
|
||||||
|
releaseDateLabel.Location = new Point(8, 50);
|
||||||
|
releaseDateLabel.Name = "releaseDateLabel";
|
||||||
|
releaseDateLabel.Size = new Size(79, 15);
|
||||||
|
releaseDateLabel.TabIndex = 5;
|
||||||
|
releaseDateLabel.Text = "Дата издания";
|
||||||
|
//
|
||||||
|
// authorLabel
|
||||||
|
//
|
||||||
|
authorLabel.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
|
authorLabel.AutoSize = true;
|
||||||
|
authorLabel.Location = new Point(8, 97);
|
||||||
|
authorLabel.Name = "authorLabel";
|
||||||
|
authorLabel.Size = new Size(40, 15);
|
||||||
|
authorLabel.TabIndex = 6;
|
||||||
|
authorLabel.Text = "Автор";
|
||||||
|
//
|
||||||
|
// authorField
|
||||||
|
//
|
||||||
|
authorField.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
|
authorField.Location = new Point(8, 114);
|
||||||
|
authorField.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
authorField.Name = "authorField";
|
||||||
|
authorField.SelectedItem = "";
|
||||||
|
authorField.Size = new Size(215, 208);
|
||||||
|
authorField.TabIndex = 7;
|
||||||
|
//
|
||||||
|
// saveButton
|
||||||
|
//
|
||||||
|
saveButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
|
saveButton.Location = new Point(8, 330);
|
||||||
|
saveButton.Name = "saveButton";
|
||||||
|
saveButton.Size = new Size(215, 30);
|
||||||
|
saveButton.TabIndex = 8;
|
||||||
|
saveButton.Text = "Сохранить";
|
||||||
|
saveButton.UseVisualStyleBackColor = true;
|
||||||
|
saveButton.Click += saveButton_Click;
|
||||||
|
//
|
||||||
|
// pictureBox
|
||||||
|
//
|
||||||
|
pictureBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
pictureBox.Location = new Point(229, 24);
|
||||||
|
pictureBox.Name = "pictureBox";
|
||||||
|
pictureBox.Size = new Size(400, 276);
|
||||||
|
pictureBox.SizeMode = PictureBoxSizeMode.Zoom;
|
||||||
|
pictureBox.TabIndex = 9;
|
||||||
|
pictureBox.TabStop = false;
|
||||||
|
//
|
||||||
|
// changeCoverButton
|
||||||
|
//
|
||||||
|
changeCoverButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
changeCoverButton.Location = new Point(229, 330);
|
||||||
|
changeCoverButton.Name = "changeCoverButton";
|
||||||
|
changeCoverButton.Size = new Size(402, 30);
|
||||||
|
changeCoverButton.TabIndex = 10;
|
||||||
|
changeCoverButton.Text = "Изменить обложку";
|
||||||
|
changeCoverButton.UseVisualStyleBackColor = true;
|
||||||
|
changeCoverButton.Click += changeCoverButton_Click;
|
||||||
|
//
|
||||||
|
// FormBook
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(639, 364);
|
||||||
|
Controls.Add(changeCoverButton);
|
||||||
|
Controls.Add(pictureBox);
|
||||||
|
Controls.Add(saveButton);
|
||||||
|
Controls.Add(authorField);
|
||||||
|
Controls.Add(authorLabel);
|
||||||
|
Controls.Add(releaseDateLabel);
|
||||||
|
Controls.Add(nameLabel);
|
||||||
|
Controls.Add(coverLabel);
|
||||||
|
Controls.Add(nameField);
|
||||||
|
Controls.Add(releaseDateField);
|
||||||
|
Name = "FormBook";
|
||||||
|
Text = "Kнигa";
|
||||||
|
FormClosing += FormBook_FormClosing;
|
||||||
|
Load += FormBook_Load;
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Library_var_4_lab_1.DateInputBox releaseDateField;
|
||||||
|
private TextBox nameField;
|
||||||
|
private Label coverLabel;
|
||||||
|
private Label nameLabel;
|
||||||
|
private Label releaseDateLabel;
|
||||||
|
private Label authorLabel;
|
||||||
|
private YunusovComponentsLibrary.SelectedComponent authorField;
|
||||||
|
private Button saveButton;
|
||||||
|
private PictureBox pictureBox;
|
||||||
|
private Button changeCoverButton;
|
||||||
|
}
|
||||||
|
}
|
177
LibraryWinFormsApp/FormBook.cs
Normal file
177
LibraryWinFormsApp/FormBook.cs
Normal file
@ -0,0 +1,177 @@
|
|||||||
|
using DocumentFormat.OpenXml.Office2010.Excel;
|
||||||
|
using Library_var_4_lab_1;
|
||||||
|
using LibraryContracts.StorageContracts;
|
||||||
|
using LibraryDatabase.Models;
|
||||||
|
using LibraryDatabase.Storages;
|
||||||
|
using LibraryDataModels.Dtos;
|
||||||
|
using LibraryDataModels.Views;
|
||||||
|
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.Controls.Primitives;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace LibraryWinFormsApp
|
||||||
|
{
|
||||||
|
public partial class FormBook : Form
|
||||||
|
{
|
||||||
|
public int _id { get; set; } = -1;
|
||||||
|
private string _cover { get; set; } = string.Empty;
|
||||||
|
private BookView? _book = null;
|
||||||
|
private IBookStorage _bookStorage;
|
||||||
|
private IAuthorStorage _authorStorage;
|
||||||
|
private ImageConverter _imageConverter = new ImageConverter();
|
||||||
|
public FormBook(IBookStorage bookStorage, IAuthorStorage authorStorage)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_bookStorage = bookStorage;
|
||||||
|
_authorStorage = authorStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FormBook_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadData()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
releaseDateField.Template = @"^([1-9]|[12][0-9]|3[01]) (января|февраля|марта|апреля|мая|июня|июля|августа|сентября|октября|ноября|декабря) [0-9]{4}$";
|
||||||
|
var authors = _authorStorage.GetFullList();
|
||||||
|
if (authors != null)
|
||||||
|
{
|
||||||
|
foreach (var author in authors)
|
||||||
|
{
|
||||||
|
authorField.Input(author.Name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (_id != -1)
|
||||||
|
{
|
||||||
|
_book = _bookStorage.GetElement(new BookDto()
|
||||||
|
{
|
||||||
|
Id = _id,
|
||||||
|
});
|
||||||
|
if (_book != null)
|
||||||
|
{
|
||||||
|
_cover = _book.BookCover;
|
||||||
|
nameField.Text = _book.Name;
|
||||||
|
releaseDateField.Date = _book.ReleaseDate;
|
||||||
|
authorField.SelectedItem = _book.Author;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
pictureBox.Image = _imageConverter.StringToImage(_cover);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FormBook_FormClosing(object sender, FormClosingEventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
bool Changed = false;
|
||||||
|
if (_book == null)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(_cover))
|
||||||
|
Changed = true;
|
||||||
|
if (!string.IsNullOrEmpty(nameField.Text))
|
||||||
|
Changed = true;
|
||||||
|
if (!string.IsNullOrEmpty(releaseDateField.Text))
|
||||||
|
Changed = true;
|
||||||
|
if (!string.IsNullOrEmpty(authorField.Text))
|
||||||
|
Changed = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (_cover != _book.BookCover)
|
||||||
|
Changed = true;
|
||||||
|
if (nameField.Text != _book.Name)
|
||||||
|
Changed = true;
|
||||||
|
if (releaseDateField.Date != _book.ReleaseDate)
|
||||||
|
Changed = true;
|
||||||
|
if (authorField.SelectedItem != _book.Author)
|
||||||
|
Changed = true;
|
||||||
|
}
|
||||||
|
if (Changed)
|
||||||
|
{
|
||||||
|
DialogResult dialogResult = MessageBox.Show("Изменения не были сохранены. Всё равно выйти?", "Внимание!", MessageBoxButtons.YesNo);
|
||||||
|
if (dialogResult == DialogResult.No)
|
||||||
|
{
|
||||||
|
e.Cancel = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(_cover))
|
||||||
|
{
|
||||||
|
throw new Exception("Выберите обложку");
|
||||||
|
}
|
||||||
|
var book = new BookDto()
|
||||||
|
{
|
||||||
|
Name = nameField.Text,
|
||||||
|
BookCover = _cover,
|
||||||
|
Author = authorField.SelectedItem,
|
||||||
|
ReleaseDate = releaseDateField.Date,
|
||||||
|
};
|
||||||
|
if (_id != -1)
|
||||||
|
{
|
||||||
|
book.Id = _id;
|
||||||
|
_book = _bookStorage.Update(book);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_book = _bookStorage.Insert(book);
|
||||||
|
}
|
||||||
|
_id = _book?.Id ?? -1;
|
||||||
|
_cover = _book?.BookCover ?? string.Empty;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void changeCoverButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
var dialog = new OpenFileDialog();
|
||||||
|
|
||||||
|
dialog.Title = "Выберите изображение";
|
||||||
|
dialog.Filter = "Изображения|*.jpg;*.jpeg;*.png;*.bmp";
|
||||||
|
|
||||||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
var image_new = new Bitmap(dialog.FileName);
|
||||||
|
pictureBox.Image = image_new;
|
||||||
|
_cover = _imageConverter.ImageToString(image_new);
|
||||||
|
}
|
||||||
|
|
||||||
|
dialog.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
145
LibraryWinFormsApp/FormBooks.Designer.cs
generated
Normal file
145
LibraryWinFormsApp/FormBooks.Designer.cs
generated
Normal file
@ -0,0 +1,145 @@
|
|||||||
|
namespace LibraryWinFormsApp
|
||||||
|
{
|
||||||
|
partial class FormBooks
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
components = new System.ComponentModel.Container();
|
||||||
|
bookTable = new YunusovComponentsLibrary.ListOutputComponent();
|
||||||
|
bookTableContextMenuStrip = new ContextMenuStrip(components);
|
||||||
|
changeAuthorsToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
createBookToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
updateBookToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
deleteBookToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
createPdfToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
createExcellToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
createWordToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
pdfImage = new ComponentLibrary1.pdf_image.PdfImage(components);
|
||||||
|
configurableTable = new Library_var_4_lab_1.ConfigurableTable(components);
|
||||||
|
wordDiagram = new YunusovComponentsLibrary.WordDiagram(components);
|
||||||
|
bookTableContextMenuStrip.SuspendLayout();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// bookTable
|
||||||
|
//
|
||||||
|
bookTable.AutoSize = true;
|
||||||
|
bookTable.ContextMenuStrip = bookTableContextMenuStrip;
|
||||||
|
bookTable.Dock = DockStyle.Fill;
|
||||||
|
bookTable.Location = new Point(0, 0);
|
||||||
|
bookTable.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
bookTable.Name = "bookTable";
|
||||||
|
bookTable.SelectedRow = -1;
|
||||||
|
bookTable.Size = new Size(827, 493);
|
||||||
|
bookTable.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// bookTableContextMenuStrip
|
||||||
|
//
|
||||||
|
bookTableContextMenuStrip.Items.AddRange(new ToolStripItem[] { changeAuthorsToolStripMenuItem, createBookToolStripMenuItem, updateBookToolStripMenuItem, deleteBookToolStripMenuItem, createPdfToolStripMenuItem, createExcellToolStripMenuItem, createWordToolStripMenuItem });
|
||||||
|
bookTableContextMenuStrip.Name = "bookTableContextMenuStrip";
|
||||||
|
bookTableContextMenuStrip.Size = new Size(202, 158);
|
||||||
|
//
|
||||||
|
// changeAuthorsToolStripMenuItem
|
||||||
|
//
|
||||||
|
changeAuthorsToolStripMenuItem.Name = "changeAuthorsToolStripMenuItem";
|
||||||
|
changeAuthorsToolStripMenuItem.Size = new Size(201, 22);
|
||||||
|
changeAuthorsToolStripMenuItem.Text = "Редактировать авторов";
|
||||||
|
changeAuthorsToolStripMenuItem.Click += changeAuthorsToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// createBookToolStripMenuItem
|
||||||
|
//
|
||||||
|
createBookToolStripMenuItem.Name = "createBookToolStripMenuItem";
|
||||||
|
createBookToolStripMenuItem.Size = new Size(201, 22);
|
||||||
|
createBookToolStripMenuItem.Text = "Добавить книгу";
|
||||||
|
createBookToolStripMenuItem.Click += createBookToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// updateBookToolStripMenuItem
|
||||||
|
//
|
||||||
|
updateBookToolStripMenuItem.Name = "updateBookToolStripMenuItem";
|
||||||
|
updateBookToolStripMenuItem.Size = new Size(201, 22);
|
||||||
|
updateBookToolStripMenuItem.Text = "Редактировать книгу";
|
||||||
|
updateBookToolStripMenuItem.Click += updateBookToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// deleteBookToolStripMenuItem
|
||||||
|
//
|
||||||
|
deleteBookToolStripMenuItem.Name = "deleteBookToolStripMenuItem";
|
||||||
|
deleteBookToolStripMenuItem.Size = new Size(201, 22);
|
||||||
|
deleteBookToolStripMenuItem.Text = "Удалить книгу";
|
||||||
|
deleteBookToolStripMenuItem.Click += deleteBookToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// createPdfToolStripMenuItem
|
||||||
|
//
|
||||||
|
createPdfToolStripMenuItem.Name = "createPdfToolStripMenuItem";
|
||||||
|
createPdfToolStripMenuItem.Size = new Size(201, 22);
|
||||||
|
createPdfToolStripMenuItem.Text = "Создать pdf";
|
||||||
|
createPdfToolStripMenuItem.Click += createPdfToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// createExcellToolStripMenuItem
|
||||||
|
//
|
||||||
|
createExcellToolStripMenuItem.Name = "createExcellToolStripMenuItem";
|
||||||
|
createExcellToolStripMenuItem.Size = new Size(201, 22);
|
||||||
|
createExcellToolStripMenuItem.Text = "Создать excell";
|
||||||
|
createExcellToolStripMenuItem.Click += createExcellToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// createWordToolStripMenuItem
|
||||||
|
//
|
||||||
|
createWordToolStripMenuItem.Name = "createWordToolStripMenuItem";
|
||||||
|
createWordToolStripMenuItem.Size = new Size(201, 22);
|
||||||
|
createWordToolStripMenuItem.Text = "Создать word";
|
||||||
|
createWordToolStripMenuItem.Click += createWordToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// FormBooks
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(827, 493);
|
||||||
|
Controls.Add(bookTable);
|
||||||
|
KeyPreview = true;
|
||||||
|
Name = "FormBooks";
|
||||||
|
Text = "Книги";
|
||||||
|
Load += FormBooks_Load;
|
||||||
|
KeyDown += booksTable_KeyDown;
|
||||||
|
bookTableContextMenuStrip.ResumeLayout(false);
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private YunusovComponentsLibrary.ListOutputComponent bookTable;
|
||||||
|
private ContextMenuStrip bookTableContextMenuStrip;
|
||||||
|
private ToolStripMenuItem changeAuthorsToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem createBookToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem updateBookToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem deleteBookToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem createPdfToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem createExcellToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem createWordToolStripMenuItem;
|
||||||
|
private ComponentLibrary1.pdf_image.PdfImage pdfImage;
|
||||||
|
private Library_var_4_lab_1.ConfigurableTable configurableTable;
|
||||||
|
private YunusovComponentsLibrary.WordDiagram wordDiagram;
|
||||||
|
}
|
||||||
|
}
|
357
LibraryWinFormsApp/FormBooks.cs
Normal file
357
LibraryWinFormsApp/FormBooks.cs
Normal file
@ -0,0 +1,357 @@
|
|||||||
|
using ComponentLibrary1.pdf_image;
|
||||||
|
using LibraryContracts.StorageContracts;
|
||||||
|
using LibraryDataModels.Dtos;
|
||||||
|
using LibraryDataModels.Views;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using YunusovComponentsLibrary;
|
||||||
|
using YunusovComponentsLibrary.OfficePackage.HelperModels;
|
||||||
|
|
||||||
|
namespace LibraryWinFormsApp
|
||||||
|
{
|
||||||
|
public partial class FormBooks : Form
|
||||||
|
{
|
||||||
|
private IBookStorage _bookStorage;
|
||||||
|
private IAuthorStorage _authorStorage;
|
||||||
|
private List<BookView> _books = new List<BookView>();
|
||||||
|
private ImageConverter _converter = new ImageConverter();
|
||||||
|
public FormBooks(IBookStorage bookStorage, IAuthorStorage authorStorage)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_bookStorage = bookStorage;
|
||||||
|
_authorStorage = authorStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
#region event-handler-methods
|
||||||
|
private void FormBooks_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void changeAuthorsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormAuthors));
|
||||||
|
if (service is FormAuthors form)
|
||||||
|
{
|
||||||
|
form.ShowDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createBookToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
CreateBook();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateBookToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
UpdateBook();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deleteBookToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
DeleteBook();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createPdfToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
CreatePdf();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createExcellToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
CreateExcell();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createWordToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
CreateWord();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void booksTable_KeyDown(object sender, KeyEventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!e.Control) { return; }
|
||||||
|
switch (e.KeyCode)
|
||||||
|
{
|
||||||
|
case Keys.A:
|
||||||
|
CreateBook();
|
||||||
|
break;
|
||||||
|
case Keys.U:
|
||||||
|
UpdateBook();
|
||||||
|
break;
|
||||||
|
case Keys.D:
|
||||||
|
DeleteBook();
|
||||||
|
break;
|
||||||
|
case Keys.S:
|
||||||
|
CreatePdf();
|
||||||
|
break;
|
||||||
|
case Keys.T:
|
||||||
|
CreateExcell();
|
||||||
|
break;
|
||||||
|
case Keys.C:
|
||||||
|
CreateWord();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private void LoadData()
|
||||||
|
{
|
||||||
|
_books = _bookStorage.GetFullList();
|
||||||
|
List<ColumnInfo> parameters = new List<ColumnInfo>()
|
||||||
|
{
|
||||||
|
new ColumnInfo("", 0, false, "Id"),
|
||||||
|
new ColumnInfo("Íàçâàíèå", 258, true, "Name"),
|
||||||
|
new ColumnInfo("", 0, false, "BookCover"),
|
||||||
|
new ColumnInfo("ÔÈÎ àâòîðà", 258, true, "Author"),
|
||||||
|
new ColumnInfo("Äàòà èçäàíèÿ", 258, true, "ReleaseDate"),
|
||||||
|
};
|
||||||
|
bookTable.ConfigColumn(parameters);
|
||||||
|
if (_books == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
foreach (var book in _books)
|
||||||
|
{
|
||||||
|
bookTable.AddItem(book);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CreateBook()
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormBook));
|
||||||
|
if (service is FormBook form)
|
||||||
|
{
|
||||||
|
form.ShowDialog();
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateBook()
|
||||||
|
{
|
||||||
|
int selectedRow = bookTable.SelectedRow;
|
||||||
|
if (selectedRow == -1)
|
||||||
|
{
|
||||||
|
throw new Exception("Âûáåðèòå êíèãó äëÿ ðåäàêòèðîâàíèÿ äàííûõ");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int id = Convert.ToInt32(bookTable.Rows[selectedRow].Cells[0].Value);
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormBook));
|
||||||
|
if (service is FormBook form)
|
||||||
|
{
|
||||||
|
form._id = id;
|
||||||
|
form.ShowDialog();
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DeleteBook()
|
||||||
|
{
|
||||||
|
int selectedRow = bookTable.SelectedRow;
|
||||||
|
if (selectedRow == -1)
|
||||||
|
{
|
||||||
|
throw new Exception("Âûáåðèòå êíèãó äëÿ óäàëåíèÿ");
|
||||||
|
}
|
||||||
|
if (MessageBox.Show("Óäàëèòü çàïèñü?", "Âîïðîñ", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
|
{
|
||||||
|
int id = Convert.ToInt32(bookTable.Rows[selectedRow].Cells[0].Value);
|
||||||
|
_bookStorage.Delete(new BookDto()
|
||||||
|
{
|
||||||
|
Id = id
|
||||||
|
});
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetFileExtension(DocType type)
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case DocType.Excel:
|
||||||
|
return ".xlsx";
|
||||||
|
case DocType.Word:
|
||||||
|
return ".docx";
|
||||||
|
case DocType.Pdf:
|
||||||
|
return ".pdf";
|
||||||
|
default:
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetFileFullName(DocType type)
|
||||||
|
{
|
||||||
|
string extension = GetFileExtension(type);
|
||||||
|
if (string.IsNullOrEmpty(extension))
|
||||||
|
{
|
||||||
|
throw new Exception("Invalid file extension");
|
||||||
|
}
|
||||||
|
using SaveFileDialog fileDialog = new SaveFileDialog
|
||||||
|
{
|
||||||
|
Filter = $"Ôàéëû|*{extension}"
|
||||||
|
};
|
||||||
|
if (fileDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
return fileDialog.FileName;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CreatePdf()
|
||||||
|
{
|
||||||
|
string fileName = GetFileFullName(DocType.Pdf);
|
||||||
|
if (string.IsNullOrWhiteSpace(fileName))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_books = _bookStorage.GetFullList();
|
||||||
|
List<byte[]> selectedImages = new List<byte[]>();
|
||||||
|
foreach (var book in _books)
|
||||||
|
{
|
||||||
|
selectedImages.Add(_converter.StringToByteArray(book.BookCover));
|
||||||
|
}
|
||||||
|
var info = new PdfImageInfo
|
||||||
|
{
|
||||||
|
FileName = fileName,
|
||||||
|
Title = "Îáëîæêè",
|
||||||
|
Images = selectedImages,
|
||||||
|
};
|
||||||
|
pdfImage.CreatePdf(info);
|
||||||
|
MessageBox.Show("PDF óñïåøíî ñîçäàí!", "Óñïåõ", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CreateExcell()
|
||||||
|
{
|
||||||
|
string fileName = GetFileFullName(DocType.Excel);
|
||||||
|
if (string.IsNullOrWhiteSpace(fileName))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<TreeNode> headers = new List<TreeNode>
|
||||||
|
{
|
||||||
|
new TreeNode
|
||||||
|
{
|
||||||
|
Text = "Èäåíòèôèêàòîð",
|
||||||
|
Tag = "Id",
|
||||||
|
Name = "40",
|
||||||
|
},
|
||||||
|
new TreeNode("Êíèãà", new TreeNode[]
|
||||||
|
{
|
||||||
|
new TreeNode
|
||||||
|
{
|
||||||
|
Text = "Íàçâàíèå",
|
||||||
|
Tag = "Name",
|
||||||
|
Name = "40",
|
||||||
|
},
|
||||||
|
new TreeNode
|
||||||
|
{
|
||||||
|
Text = "Àâòîð",
|
||||||
|
Tag = "Author",
|
||||||
|
Name = "40",
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new TreeNode
|
||||||
|
{
|
||||||
|
Text = "Äàòà",
|
||||||
|
Tag = "ReleaseDate",
|
||||||
|
Name = "40",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
_books = _bookStorage.GetFullList();
|
||||||
|
configurableTable.CreateTable(
|
||||||
|
fileName,
|
||||||
|
"Êíèãè",
|
||||||
|
headers,
|
||||||
|
_books);
|
||||||
|
MessageBox.Show("Excell óñïåøíî ñîçäàí!", "Óñïåõ", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CreateWord()
|
||||||
|
{
|
||||||
|
string fileName = GetFileFullName(DocType.Word);
|
||||||
|
if (string.IsNullOrWhiteSpace(fileName))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_books = _bookStorage.GetFullList();
|
||||||
|
var authors = _authorStorage.GetFullList();
|
||||||
|
WordDiagramSeries series = new WordDiagramSeries();
|
||||||
|
series.SeriesName = "Àâòîðû";
|
||||||
|
foreach (var author in authors)
|
||||||
|
{
|
||||||
|
double sum = 0.0;
|
||||||
|
foreach (var book in _books)
|
||||||
|
{
|
||||||
|
if (string.Equals(book.Author, author.Name))
|
||||||
|
{
|
||||||
|
sum++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
series.Data.Add(author.Name, sum);
|
||||||
|
}
|
||||||
|
wordDiagram.CreateDiagram(new WordDiagramInfo()
|
||||||
|
{
|
||||||
|
FileName = fileName,
|
||||||
|
Title = "Àâòîðû",
|
||||||
|
ChartTitle = "Àâòîðû",
|
||||||
|
Series = series,
|
||||||
|
});
|
||||||
|
MessageBox.Show("Word óñïåøíî ñîçäàí!", "Óñïåõ", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -117,13 +117,16 @@
|
|||||||
<resheader name="writer">
|
<resheader name="writer">
|
||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
</resheader>
|
</resheader>
|
||||||
<metadata name="pdfImage.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
<metadata name="bookTableContextMenuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
<value>17, 17</value>
|
<value>17, 17</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
<metadata name="pdfTable.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
<metadata name="pdfImage.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
<value>122, 17</value>
|
<value>222, 17</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
<metadata name="pdfDiagram.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
<metadata name="configurableTable.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
<value>221, 17</value>
|
<value>327, 17</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="wordDiagram.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>475, 17</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
</root>
|
</root>
|
33
LibraryWinFormsApp/ImageConverter.cs
Normal file
33
LibraryWinFormsApp/ImageConverter.cs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LibraryWinFormsApp
|
||||||
|
{
|
||||||
|
internal class ImageConverter
|
||||||
|
{
|
||||||
|
public Image StringToImage(string bytes)
|
||||||
|
{
|
||||||
|
byte[] arrayimg = Convert.FromBase64String(bytes);
|
||||||
|
Image imageStr = Image.FromStream(new MemoryStream(arrayimg));
|
||||||
|
return imageStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string ImageToString(Image image)
|
||||||
|
{
|
||||||
|
using (var ms = new MemoryStream())
|
||||||
|
{
|
||||||
|
image.Save(ms, image.RawFormat);
|
||||||
|
byte[] imageBytes = ms.ToArray();
|
||||||
|
string base64String = Convert.ToBase64String(imageBytes);
|
||||||
|
return base64String;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public byte[] StringToByteArray(string bytes)
|
||||||
|
{
|
||||||
|
return Convert.FromBase64String(bytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
22
LibraryWinFormsApp/LibraryWinFormsApp.csproj
Normal file
22
LibraryWinFormsApp/LibraryWinFormsApp.csproj
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>WinExe</OutputType>
|
||||||
|
<TargetFramework>net6.0-windows</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="ComponentLibrary1" Version="1.0.0" />
|
||||||
|
<PackageReference Include="Library_var_4_lab_1" Version="1.0.1" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
||||||
|
<PackageReference Include="YunusovComponentsLibrary" Version="1.0.1" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\LibraryDatabase\LibraryDatabase.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
36
LibraryWinFormsApp/Program.cs
Normal file
36
LibraryWinFormsApp/Program.cs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
using System;
|
||||||
|
using LibraryContracts.StorageContracts;
|
||||||
|
using LibraryDatabase.Storages;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
|
namespace LibraryWinFormsApp
|
||||||
|
{
|
||||||
|
internal static class Program
|
||||||
|
{
|
||||||
|
private static ServiceProvider? _serviceProvider;
|
||||||
|
public static ServiceProvider? ServiceProvider => _serviceProvider;
|
||||||
|
/// <summary>
|
||||||
|
/// The main entry point for the application.
|
||||||
|
/// </summary>
|
||||||
|
[STAThread]
|
||||||
|
static void Main()
|
||||||
|
{
|
||||||
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
|
// see https://aka.ms/applicationconfiguration.
|
||||||
|
ApplicationConfiguration.Initialize();
|
||||||
|
var services = new ServiceCollection();
|
||||||
|
ConfigureServices(services);
|
||||||
|
_serviceProvider = services.BuildServiceProvider();
|
||||||
|
Application.Run(_serviceProvider.GetRequiredService<FormBooks>());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ConfigureServices(ServiceCollection services)
|
||||||
|
{
|
||||||
|
services.AddTransient<IAuthorStorage, AuthorStorage>();
|
||||||
|
services.AddTransient<IBookStorage, BookStorage>();
|
||||||
|
services.AddTransient<FormBooks>();
|
||||||
|
services.AddTransient<FormBook>();
|
||||||
|
services.AddTransient<FormAuthors>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,28 +0,0 @@
|
|||||||
using ComponentLibrary1.tree_list;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace TestApp1
|
|
||||||
{
|
|
||||||
internal class Employee
|
|
||||||
{
|
|
||||||
public string Department { get; set; }
|
|
||||||
public string JobTitle { get; set; }
|
|
||||||
public string FullName { get; set; }
|
|
||||||
public Employee()
|
|
||||||
{
|
|
||||||
Department = string.Empty;
|
|
||||||
JobTitle = string.Empty;
|
|
||||||
FullName = string.Empty;
|
|
||||||
}
|
|
||||||
public Employee(string department, string jobTitle, string fullName)
|
|
||||||
{
|
|
||||||
Department = department;
|
|
||||||
JobTitle = jobTitle;
|
|
||||||
FullName = fullName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
490
TestApp1/Form1.Designer.cs
generated
490
TestApp1/Form1.Designer.cs
generated
@ -1,490 +0,0 @@
|
|||||||
namespace TestApp1
|
|
||||||
{
|
|
||||||
partial class Form1
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Required designer variable.
|
|
||||||
/// </summary>
|
|
||||||
private System.ComponentModel.IContainer components = null;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Clean up any resources being used.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
|
||||||
protected override void Dispose(bool disposing)
|
|
||||||
{
|
|
||||||
if (disposing && (components != null))
|
|
||||||
{
|
|
||||||
components.Dispose();
|
|
||||||
}
|
|
||||||
base.Dispose(disposing);
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Windows Form Designer generated code
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Required method for Designer support - do not modify
|
|
||||||
/// the contents of this method with the code editor.
|
|
||||||
/// </summary>
|
|
||||||
private void InitializeComponent()
|
|
||||||
{
|
|
||||||
components = new System.ComponentModel.Container();
|
|
||||||
input = new Button();
|
|
||||||
clear = new Button();
|
|
||||||
textBox1 = new TextBox();
|
|
||||||
set = new Button();
|
|
||||||
get = new Button();
|
|
||||||
checkList = new ComponentLibrary1.CheckList();
|
|
||||||
changeBox = new CheckBox();
|
|
||||||
groupBox1 = new GroupBox();
|
|
||||||
groupBox2 = new GroupBox();
|
|
||||||
numericMax = new NumericUpDown();
|
|
||||||
numericMin = new NumericUpDown();
|
|
||||||
inputMax = new Button();
|
|
||||||
inputMin = new Button();
|
|
||||||
limitedText = new ComponentLibrary1.LimitedText();
|
|
||||||
write = new Button();
|
|
||||||
read = new Button();
|
|
||||||
textBox2 = new TextBox();
|
|
||||||
changeBox2 = new CheckBox();
|
|
||||||
groupBox3 = new GroupBox();
|
|
||||||
textBoxOutput = new TextBox();
|
|
||||||
treeList = new ComponentLibrary1.tree_list.TreeList();
|
|
||||||
textBoxDepartment = new TextBox();
|
|
||||||
textBoxJobTitle = new TextBox();
|
|
||||||
add = new Button();
|
|
||||||
clearTreeList = new Button();
|
|
||||||
textBoxFullName = new TextBox();
|
|
||||||
getObject = new Button();
|
|
||||||
groupBox4 = new GroupBox();
|
|
||||||
listBoxImages = new ListBox();
|
|
||||||
chooseImage = new Button();
|
|
||||||
createPdfImages = new Button();
|
|
||||||
pdfImage = new ComponentLibrary1.pdf_image.PdfImage(components);
|
|
||||||
groupBox5 = new GroupBox();
|
|
||||||
createTable = new Button();
|
|
||||||
pdfTable = new ComponentLibrary1.pdf_table.PdfTable(components);
|
|
||||||
pdfDiagram = new ComponentLibrary1.pdf_diagram.PdfDiagram(components);
|
|
||||||
groupBox6 = new GroupBox();
|
|
||||||
createDiagram = new Button();
|
|
||||||
groupBox1.SuspendLayout();
|
|
||||||
groupBox2.SuspendLayout();
|
|
||||||
((System.ComponentModel.ISupportInitialize)numericMax).BeginInit();
|
|
||||||
((System.ComponentModel.ISupportInitialize)numericMin).BeginInit();
|
|
||||||
groupBox3.SuspendLayout();
|
|
||||||
groupBox4.SuspendLayout();
|
|
||||||
groupBox5.SuspendLayout();
|
|
||||||
groupBox6.SuspendLayout();
|
|
||||||
SuspendLayout();
|
|
||||||
//
|
|
||||||
// input
|
|
||||||
//
|
|
||||||
input.Location = new Point(6, 269);
|
|
||||||
input.Name = "input";
|
|
||||||
input.Size = new Size(70, 26);
|
|
||||||
input.TabIndex = 0;
|
|
||||||
input.Text = "input";
|
|
||||||
input.UseVisualStyleBackColor = true;
|
|
||||||
input.Click += input_Click;
|
|
||||||
//
|
|
||||||
// clear
|
|
||||||
//
|
|
||||||
clear.Location = new Point(82, 269);
|
|
||||||
clear.Name = "clear";
|
|
||||||
clear.Size = new Size(70, 26);
|
|
||||||
clear.TabIndex = 1;
|
|
||||||
clear.Text = "clear";
|
|
||||||
clear.UseVisualStyleBackColor = true;
|
|
||||||
clear.Click += clear_Click;
|
|
||||||
//
|
|
||||||
// textBox1
|
|
||||||
//
|
|
||||||
textBox1.Location = new Point(6, 240);
|
|
||||||
textBox1.Name = "textBox1";
|
|
||||||
textBox1.Size = new Size(146, 23);
|
|
||||||
textBox1.TabIndex = 2;
|
|
||||||
//
|
|
||||||
// set
|
|
||||||
//
|
|
||||||
set.Location = new Point(6, 301);
|
|
||||||
set.Name = "set";
|
|
||||||
set.Size = new Size(70, 26);
|
|
||||||
set.TabIndex = 3;
|
|
||||||
set.Text = "set";
|
|
||||||
set.UseVisualStyleBackColor = true;
|
|
||||||
set.Click += set_Click;
|
|
||||||
//
|
|
||||||
// get
|
|
||||||
//
|
|
||||||
get.Location = new Point(82, 301);
|
|
||||||
get.Name = "get";
|
|
||||||
get.Size = new Size(70, 26);
|
|
||||||
get.TabIndex = 4;
|
|
||||||
get.Text = "get";
|
|
||||||
get.UseVisualStyleBackColor = true;
|
|
||||||
get.Click += get_Click;
|
|
||||||
//
|
|
||||||
// checkList
|
|
||||||
//
|
|
||||||
checkList.Location = new Point(6, 22);
|
|
||||||
checkList.Name = "checkList";
|
|
||||||
checkList.SelectedItem = "";
|
|
||||||
checkList.Size = new Size(146, 172);
|
|
||||||
checkList.TabIndex = 5;
|
|
||||||
//
|
|
||||||
// changeBox
|
|
||||||
//
|
|
||||||
changeBox.AutoSize = true;
|
|
||||||
changeBox.Location = new Point(6, 200);
|
|
||||||
changeBox.Name = "changeBox";
|
|
||||||
changeBox.Size = new Size(72, 19);
|
|
||||||
changeBox.TabIndex = 6;
|
|
||||||
changeBox.Text = "changed";
|
|
||||||
changeBox.UseVisualStyleBackColor = true;
|
|
||||||
//
|
|
||||||
// groupBox1
|
|
||||||
//
|
|
||||||
groupBox1.Controls.Add(checkList);
|
|
||||||
groupBox1.Controls.Add(input);
|
|
||||||
groupBox1.Controls.Add(clear);
|
|
||||||
groupBox1.Controls.Add(textBox1);
|
|
||||||
groupBox1.Controls.Add(changeBox);
|
|
||||||
groupBox1.Controls.Add(set);
|
|
||||||
groupBox1.Controls.Add(get);
|
|
||||||
groupBox1.Location = new Point(16, 12);
|
|
||||||
groupBox1.Name = "groupBox1";
|
|
||||||
groupBox1.Size = new Size(157, 332);
|
|
||||||
groupBox1.TabIndex = 10;
|
|
||||||
groupBox1.TabStop = false;
|
|
||||||
groupBox1.Text = "Test1";
|
|
||||||
//
|
|
||||||
// groupBox2
|
|
||||||
//
|
|
||||||
groupBox2.Controls.Add(numericMax);
|
|
||||||
groupBox2.Controls.Add(numericMin);
|
|
||||||
groupBox2.Controls.Add(inputMax);
|
|
||||||
groupBox2.Controls.Add(inputMin);
|
|
||||||
groupBox2.Controls.Add(limitedText);
|
|
||||||
groupBox2.Controls.Add(write);
|
|
||||||
groupBox2.Controls.Add(read);
|
|
||||||
groupBox2.Controls.Add(textBox2);
|
|
||||||
groupBox2.Controls.Add(changeBox2);
|
|
||||||
groupBox2.Location = new Point(179, 12);
|
|
||||||
groupBox2.Name = "groupBox2";
|
|
||||||
groupBox2.Size = new Size(157, 332);
|
|
||||||
groupBox2.TabIndex = 11;
|
|
||||||
groupBox2.TabStop = false;
|
|
||||||
groupBox2.Text = "Test2";
|
|
||||||
//
|
|
||||||
// numericMax
|
|
||||||
//
|
|
||||||
numericMax.Location = new Point(7, 160);
|
|
||||||
numericMax.Name = "numericMax";
|
|
||||||
numericMax.Size = new Size(145, 23);
|
|
||||||
numericMax.TabIndex = 11;
|
|
||||||
//
|
|
||||||
// numericMin
|
|
||||||
//
|
|
||||||
numericMin.Location = new Point(7, 131);
|
|
||||||
numericMin.Name = "numericMin";
|
|
||||||
numericMin.Size = new Size(145, 23);
|
|
||||||
numericMin.TabIndex = 10;
|
|
||||||
//
|
|
||||||
// inputMax
|
|
||||||
//
|
|
||||||
inputMax.Location = new Point(82, 301);
|
|
||||||
inputMax.Name = "inputMax";
|
|
||||||
inputMax.Size = new Size(70, 26);
|
|
||||||
inputMax.TabIndex = 9;
|
|
||||||
inputMax.Text = "inputMax";
|
|
||||||
inputMax.UseVisualStyleBackColor = true;
|
|
||||||
inputMax.Click += inputMax_Click;
|
|
||||||
//
|
|
||||||
// inputMin
|
|
||||||
//
|
|
||||||
inputMin.Location = new Point(6, 301);
|
|
||||||
inputMin.Name = "inputMin";
|
|
||||||
inputMin.Size = new Size(70, 26);
|
|
||||||
inputMin.TabIndex = 8;
|
|
||||||
inputMin.Text = "inputMin";
|
|
||||||
inputMin.UseVisualStyleBackColor = true;
|
|
||||||
inputMin.Click += inputMin_Click;
|
|
||||||
//
|
|
||||||
// limitedText
|
|
||||||
//
|
|
||||||
limitedText.Location = new Point(7, 74);
|
|
||||||
limitedText.Max = null;
|
|
||||||
limitedText.Min = null;
|
|
||||||
limitedText.Name = "limitedText";
|
|
||||||
limitedText.Size = new Size(145, 26);
|
|
||||||
limitedText.TabIndex = 7;
|
|
||||||
//
|
|
||||||
// write
|
|
||||||
//
|
|
||||||
write.Location = new Point(6, 269);
|
|
||||||
write.Name = "write";
|
|
||||||
write.Size = new Size(70, 26);
|
|
||||||
write.TabIndex = 0;
|
|
||||||
write.Text = "write";
|
|
||||||
write.UseVisualStyleBackColor = true;
|
|
||||||
write.Click += write_Click;
|
|
||||||
//
|
|
||||||
// read
|
|
||||||
//
|
|
||||||
read.Location = new Point(82, 269);
|
|
||||||
read.Name = "read";
|
|
||||||
read.Size = new Size(70, 26);
|
|
||||||
read.TabIndex = 1;
|
|
||||||
read.Text = "read";
|
|
||||||
read.UseVisualStyleBackColor = true;
|
|
||||||
read.Click += read_Click;
|
|
||||||
//
|
|
||||||
// textBox2
|
|
||||||
//
|
|
||||||
textBox2.Location = new Point(6, 240);
|
|
||||||
textBox2.Name = "textBox2";
|
|
||||||
textBox2.Size = new Size(146, 23);
|
|
||||||
textBox2.TabIndex = 2;
|
|
||||||
//
|
|
||||||
// changeBox2
|
|
||||||
//
|
|
||||||
changeBox2.AutoSize = true;
|
|
||||||
changeBox2.Location = new Point(6, 200);
|
|
||||||
changeBox2.Name = "changeBox2";
|
|
||||||
changeBox2.Size = new Size(72, 19);
|
|
||||||
changeBox2.TabIndex = 6;
|
|
||||||
changeBox2.Text = "changed";
|
|
||||||
changeBox2.UseVisualStyleBackColor = true;
|
|
||||||
//
|
|
||||||
// groupBox3
|
|
||||||
//
|
|
||||||
groupBox3.Controls.Add(textBoxOutput);
|
|
||||||
groupBox3.Controls.Add(treeList);
|
|
||||||
groupBox3.Controls.Add(textBoxDepartment);
|
|
||||||
groupBox3.Controls.Add(textBoxJobTitle);
|
|
||||||
groupBox3.Controls.Add(add);
|
|
||||||
groupBox3.Controls.Add(clearTreeList);
|
|
||||||
groupBox3.Controls.Add(textBoxFullName);
|
|
||||||
groupBox3.Controls.Add(getObject);
|
|
||||||
groupBox3.Location = new Point(342, 12);
|
|
||||||
groupBox3.Name = "groupBox3";
|
|
||||||
groupBox3.Size = new Size(157, 332);
|
|
||||||
groupBox3.TabIndex = 11;
|
|
||||||
groupBox3.TabStop = false;
|
|
||||||
groupBox3.Text = "Test3";
|
|
||||||
//
|
|
||||||
// textBoxOutput
|
|
||||||
//
|
|
||||||
textBoxOutput.Location = new Point(6, 240);
|
|
||||||
textBoxOutput.Name = "textBoxOutput";
|
|
||||||
textBoxOutput.Size = new Size(145, 23);
|
|
||||||
textBoxOutput.TabIndex = 15;
|
|
||||||
//
|
|
||||||
// treeList
|
|
||||||
//
|
|
||||||
treeList.Location = new Point(6, 22);
|
|
||||||
treeList.Name = "treeList";
|
|
||||||
treeList.Size = new Size(145, 125);
|
|
||||||
treeList.TabIndex = 14;
|
|
||||||
//
|
|
||||||
// textBoxDepartment
|
|
||||||
//
|
|
||||||
textBoxDepartment.Location = new Point(6, 153);
|
|
||||||
textBoxDepartment.Name = "textBoxDepartment";
|
|
||||||
textBoxDepartment.Size = new Size(145, 23);
|
|
||||||
textBoxDepartment.TabIndex = 13;
|
|
||||||
//
|
|
||||||
// textBoxJobTitle
|
|
||||||
//
|
|
||||||
textBoxJobTitle.Location = new Point(6, 182);
|
|
||||||
textBoxJobTitle.Name = "textBoxJobTitle";
|
|
||||||
textBoxJobTitle.Size = new Size(145, 23);
|
|
||||||
textBoxJobTitle.TabIndex = 12;
|
|
||||||
//
|
|
||||||
// add
|
|
||||||
//
|
|
||||||
add.Location = new Point(6, 269);
|
|
||||||
add.Name = "add";
|
|
||||||
add.Size = new Size(70, 26);
|
|
||||||
add.TabIndex = 0;
|
|
||||||
add.Text = "add";
|
|
||||||
add.UseVisualStyleBackColor = true;
|
|
||||||
add.Click += add_Click;
|
|
||||||
//
|
|
||||||
// clearTreeList
|
|
||||||
//
|
|
||||||
clearTreeList.Location = new Point(6, 300);
|
|
||||||
clearTreeList.Name = "clearTreeList";
|
|
||||||
clearTreeList.Size = new Size(145, 26);
|
|
||||||
clearTreeList.TabIndex = 1;
|
|
||||||
clearTreeList.Text = "clear";
|
|
||||||
clearTreeList.UseVisualStyleBackColor = true;
|
|
||||||
clearTreeList.Click += clearTreeList_Click;
|
|
||||||
//
|
|
||||||
// textBoxFullName
|
|
||||||
//
|
|
||||||
textBoxFullName.Location = new Point(6, 211);
|
|
||||||
textBoxFullName.Name = "textBoxFullName";
|
|
||||||
textBoxFullName.Size = new Size(145, 23);
|
|
||||||
textBoxFullName.TabIndex = 2;
|
|
||||||
//
|
|
||||||
// getObject
|
|
||||||
//
|
|
||||||
getObject.Location = new Point(81, 269);
|
|
||||||
getObject.Name = "getObject";
|
|
||||||
getObject.Size = new Size(70, 26);
|
|
||||||
getObject.TabIndex = 3;
|
|
||||||
getObject.Text = "get object";
|
|
||||||
getObject.UseVisualStyleBackColor = true;
|
|
||||||
getObject.Click += getObject_Click;
|
|
||||||
//
|
|
||||||
// groupBox4
|
|
||||||
//
|
|
||||||
groupBox4.Controls.Add(listBoxImages);
|
|
||||||
groupBox4.Controls.Add(chooseImage);
|
|
||||||
groupBox4.Controls.Add(createPdfImages);
|
|
||||||
groupBox4.Location = new Point(505, 12);
|
|
||||||
groupBox4.Name = "groupBox4";
|
|
||||||
groupBox4.Size = new Size(157, 205);
|
|
||||||
groupBox4.TabIndex = 11;
|
|
||||||
groupBox4.TabStop = false;
|
|
||||||
groupBox4.Text = "Test4";
|
|
||||||
//
|
|
||||||
// listBoxImages
|
|
||||||
//
|
|
||||||
listBoxImages.FormattingEnabled = true;
|
|
||||||
listBoxImages.ItemHeight = 15;
|
|
||||||
listBoxImages.Location = new Point(6, 23);
|
|
||||||
listBoxImages.Name = "listBoxImages";
|
|
||||||
listBoxImages.Size = new Size(146, 109);
|
|
||||||
listBoxImages.TabIndex = 3;
|
|
||||||
//
|
|
||||||
// chooseImage
|
|
||||||
//
|
|
||||||
chooseImage.Location = new Point(6, 141);
|
|
||||||
chooseImage.Name = "chooseImage";
|
|
||||||
chooseImage.Size = new Size(146, 26);
|
|
||||||
chooseImage.TabIndex = 0;
|
|
||||||
chooseImage.Text = "Выбрать изображения";
|
|
||||||
chooseImage.UseVisualStyleBackColor = true;
|
|
||||||
chooseImage.Click += chooseImage_Click;
|
|
||||||
//
|
|
||||||
// createPdfImages
|
|
||||||
//
|
|
||||||
createPdfImages.Location = new Point(6, 173);
|
|
||||||
createPdfImages.Name = "createPdfImages";
|
|
||||||
createPdfImages.Size = new Size(146, 26);
|
|
||||||
createPdfImages.TabIndex = 1;
|
|
||||||
createPdfImages.Text = "Cоздать pdf с фотками";
|
|
||||||
createPdfImages.UseVisualStyleBackColor = true;
|
|
||||||
createPdfImages.Click += createPdfImages_Click;
|
|
||||||
//
|
|
||||||
// groupBox5
|
|
||||||
//
|
|
||||||
groupBox5.Controls.Add(createTable);
|
|
||||||
groupBox5.Location = new Point(505, 223);
|
|
||||||
groupBox5.Name = "groupBox5";
|
|
||||||
groupBox5.Size = new Size(157, 59);
|
|
||||||
groupBox5.TabIndex = 12;
|
|
||||||
groupBox5.TabStop = false;
|
|
||||||
groupBox5.Text = "Test5";
|
|
||||||
//
|
|
||||||
// createTable
|
|
||||||
//
|
|
||||||
createTable.Location = new Point(6, 23);
|
|
||||||
createTable.Name = "createTable";
|
|
||||||
createTable.Size = new Size(146, 26);
|
|
||||||
createTable.TabIndex = 0;
|
|
||||||
createTable.Text = "Создать pdf таблицу";
|
|
||||||
createTable.UseVisualStyleBackColor = true;
|
|
||||||
createTable.Click += createTable_Click;
|
|
||||||
//
|
|
||||||
// groupBox6
|
|
||||||
//
|
|
||||||
groupBox6.Controls.Add(createDiagram);
|
|
||||||
groupBox6.Location = new Point(505, 285);
|
|
||||||
groupBox6.Name = "groupBox6";
|
|
||||||
groupBox6.Size = new Size(157, 59);
|
|
||||||
groupBox6.TabIndex = 13;
|
|
||||||
groupBox6.TabStop = false;
|
|
||||||
groupBox6.Text = "Test6";
|
|
||||||
//
|
|
||||||
// createDiagram
|
|
||||||
//
|
|
||||||
createDiagram.Location = new Point(6, 23);
|
|
||||||
createDiagram.Name = "createDiagram";
|
|
||||||
createDiagram.Size = new Size(146, 26);
|
|
||||||
createDiagram.TabIndex = 0;
|
|
||||||
createDiagram.Text = "Создать pdf диаграмму";
|
|
||||||
createDiagram.UseVisualStyleBackColor = true;
|
|
||||||
createDiagram.Click += createDiagram_Click;
|
|
||||||
//
|
|
||||||
// Form1
|
|
||||||
//
|
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
|
||||||
ClientSize = new Size(676, 360);
|
|
||||||
Controls.Add(groupBox6);
|
|
||||||
Controls.Add(groupBox5);
|
|
||||||
Controls.Add(groupBox4);
|
|
||||||
Controls.Add(groupBox3);
|
|
||||||
Controls.Add(groupBox2);
|
|
||||||
Controls.Add(groupBox1);
|
|
||||||
Name = "Form1";
|
|
||||||
Text = "Form1";
|
|
||||||
groupBox1.ResumeLayout(false);
|
|
||||||
groupBox1.PerformLayout();
|
|
||||||
groupBox2.ResumeLayout(false);
|
|
||||||
groupBox2.PerformLayout();
|
|
||||||
((System.ComponentModel.ISupportInitialize)numericMax).EndInit();
|
|
||||||
((System.ComponentModel.ISupportInitialize)numericMin).EndInit();
|
|
||||||
groupBox3.ResumeLayout(false);
|
|
||||||
groupBox3.PerformLayout();
|
|
||||||
groupBox4.ResumeLayout(false);
|
|
||||||
groupBox5.ResumeLayout(false);
|
|
||||||
groupBox6.ResumeLayout(false);
|
|
||||||
ResumeLayout(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
private Button input;
|
|
||||||
private Button clear;
|
|
||||||
private TextBox textBox1;
|
|
||||||
private Button set;
|
|
||||||
private Button get;
|
|
||||||
private ComponentLibrary1.CheckList checkList;
|
|
||||||
private CheckBox changeBox;
|
|
||||||
private GroupBox groupBox1;
|
|
||||||
private GroupBox groupBox2;
|
|
||||||
private Button write;
|
|
||||||
private Button read;
|
|
||||||
private TextBox textBox2;
|
|
||||||
private CheckBox changeBox2;
|
|
||||||
private ComponentLibrary1.LimitedText limitedText;
|
|
||||||
private Button inputMax;
|
|
||||||
private Button inputMin;
|
|
||||||
private NumericUpDown numericMin;
|
|
||||||
private NumericUpDown numericMax;
|
|
||||||
private GroupBox groupBox3;
|
|
||||||
private Button add;
|
|
||||||
private Button clearTreeList;
|
|
||||||
private TextBox textBoxFullName;
|
|
||||||
private Button getObject;
|
|
||||||
private TextBox textBoxDepartment;
|
|
||||||
private TextBox textBoxJobTitle;
|
|
||||||
private ComponentLibrary1.tree_list.TreeList treeList;
|
|
||||||
private TextBox textBoxOutput;
|
|
||||||
private GroupBox groupBox4;
|
|
||||||
private Button chooseImage;
|
|
||||||
private Button createPdfImages;
|
|
||||||
private ListBox listBoxImages;
|
|
||||||
private ComponentLibrary1.pdf_image.PdfImage pdfImage;
|
|
||||||
private GroupBox groupBox5;
|
|
||||||
private Button createTable;
|
|
||||||
private ComponentLibrary1.pdf_table.PdfTable pdfTable;
|
|
||||||
private ComponentLibrary1.pdf_diagram.PdfDiagram pdfDiagram;
|
|
||||||
private GroupBox groupBox6;
|
|
||||||
private Button createDiagram;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,278 +0,0 @@
|
|||||||
using ComponentLibrary1.pdf_diagram;
|
|
||||||
using ComponentLibrary1.pdf_image;
|
|
||||||
using ComponentLibrary1.pdf_table;
|
|
||||||
|
|
||||||
namespace TestApp1
|
|
||||||
{
|
|
||||||
public partial class Form1 : Form
|
|
||||||
{
|
|
||||||
private List<byte[]> selectedImages = new List<byte[]>();
|
|
||||||
public Form1()
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
|
||||||
checkList.ChangeEvent += DoChange;
|
|
||||||
limitedText.ChangeEvent += DoChange2;
|
|
||||||
List<string> categories = new List<string>
|
|
||||||
{
|
|
||||||
"Department",
|
|
||||||
"JobTitle",
|
|
||||||
"FullName"
|
|
||||||
};
|
|
||||||
treeList.SetCategories(categories);
|
|
||||||
}
|
|
||||||
|
|
||||||
#region test1
|
|
||||||
private void input_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
checkList.Input(textBox1.Text);
|
|
||||||
textBox1.Text = string.Empty;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show(ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void clear_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
checkList.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void set_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
checkList.SelectedItem = textBox1.Text;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void get_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
textBox1.Text = checkList.SelectedItem;
|
|
||||||
}
|
|
||||||
private void DoChange(object? sender, EventArgs e)
|
|
||||||
{
|
|
||||||
changeBox.Checked = true;
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region test2
|
|
||||||
private void write_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
limitedText.TextField = textBox2.Text;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show(ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void read_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
textBox2.Text = limitedText.TextField;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show(ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void inputMin_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
limitedText.Min = (int)numericMin.Value;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void inputMax_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
limitedText.Max = (int)numericMax.Value;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void DoChange2(object? sender, EventArgs e)
|
|
||||||
{
|
|
||||||
changeBox2.Checked = true;
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region test3
|
|
||||||
private void add_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(textBoxDepartment.Text) ||
|
|
||||||
string.IsNullOrEmpty(textBoxJobTitle.Text) ||
|
|
||||||
string.IsNullOrEmpty(textBoxFullName.Text))
|
|
||||||
{
|
|
||||||
throw new Exception("Çàïîëíèòå äàííûå ñîòðóäíèêà");
|
|
||||||
}
|
|
||||||
treeList.AddTreeListObject(new Employee(textBoxDepartment.Text, textBoxJobTitle.Text, textBoxFullName.Text));
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show(ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void clearTreeList_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
treeList.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void getObject_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Employee? employee = treeList.GetSelectedObject<Employee>();
|
|
||||||
if (employee == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
textBoxDepartment.Text = employee.Department;
|
|
||||||
textBoxJobTitle.Text = employee.JobTitle;
|
|
||||||
textBoxFullName.Text = employee.FullName;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show(ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region test4
|
|
||||||
private void chooseImage_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using OpenFileDialog openFileDialog = new OpenFileDialog
|
|
||||||
{
|
|
||||||
Multiselect = true,
|
|
||||||
Filter = "Èçîáðàæåíèÿ|*.jpg;*.jpeg;*.png;*.bmp"
|
|
||||||
};
|
|
||||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
|
||||||
{
|
|
||||||
selectedImages.Clear();
|
|
||||||
listBoxImages.Items.Clear();
|
|
||||||
foreach (string filePath in openFileDialog.FileNames)
|
|
||||||
{
|
|
||||||
selectedImages.Add(File.ReadAllBytes(filePath));
|
|
||||||
listBoxImages.Items.Add(Path.GetFileName(filePath));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show(ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createPdfImages_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (selectedImages.Count == 0)
|
|
||||||
{
|
|
||||||
MessageBox.Show("Âûáåðèòå õîòÿ áû îäíî èçîáðàæåíèå!", "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var info = new PdfImageInfo
|
|
||||||
{
|
|
||||||
FileName = "C://Users//user//PdfWithImage.pdf",
|
|
||||||
Title = "Óëüÿíîâñê",
|
|
||||||
Images = selectedImages
|
|
||||||
};
|
|
||||||
pdfImage.CreatePdf(info);
|
|
||||||
MessageBox.Show("PDF óñïåøíî ñîçäàí!", "Óñïåõ", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show(ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region test5
|
|
||||||
private void createTable_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
List<TreeNode> headers = new List<TreeNode>
|
|
||||||
{
|
|
||||||
new TreeNode
|
|
||||||
{
|
|
||||||
Text = "ÔÈÎ",
|
|
||||||
Tag = "FullName",
|
|
||||||
},
|
|
||||||
new TreeNode("Êîðïîðàòèâíûå äàííûå", new TreeNode[]
|
|
||||||
{
|
|
||||||
new TreeNode
|
|
||||||
{
|
|
||||||
Text = "Îòäåë",
|
|
||||||
Tag = "Department"
|
|
||||||
},
|
|
||||||
new TreeNode
|
|
||||||
{
|
|
||||||
Text = "Äîëæíîñòü",
|
|
||||||
Tag = "JobTitle"
|
|
||||||
}
|
|
||||||
})
|
|
||||||
};
|
|
||||||
List<Employee> data = new List<Employee>
|
|
||||||
{
|
|
||||||
new Employee("Îòäåë ïî æèâîòíûì", "Ãëàâà îòäåëà", "Àðò¸ì"),
|
|
||||||
new Employee("Îòäåë ïî æèâîòíûì", "Çàì", "Ðîñòèñëàâ"),
|
|
||||||
new Employee("Îòäåë ïî àâòîõëàìó", "Çàì", "Íèÿç")
|
|
||||||
};
|
|
||||||
var info = new PdfTableInfo<Employee>
|
|
||||||
{
|
|
||||||
FileName = "C://Users//user//PdfWithTable.pdf",
|
|
||||||
Title = "Ñîòðóäíèêè",
|
|
||||||
Headers = headers,
|
|
||||||
Data = data
|
|
||||||
};
|
|
||||||
pdfTable.CreatePdf(info);
|
|
||||||
MessageBox.Show("PDF óñïåøíî ñîçäàí!", "Óñïåõ", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show(ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region test6
|
|
||||||
private void createDiagram_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
pdfDiagram.CreateDiagram(new PdfDiagramInfo
|
|
||||||
{
|
|
||||||
FileName = "C://Users//user//PdfWithPieDiagram.pdf",
|
|
||||||
Title = "Äîêóìåíò ñ äèàãðàììîé",
|
|
||||||
ChartTitle = "Ðàñïðåäåëåíèå äîëåé ðûíêà íàñòîëüíûõ îïåðàöèííûõ ñèñòåì, àâãóñò 2024",
|
|
||||||
LegendLocation = ComponentLibrary1.office_package.HelperEnums.PdfDiagramLegendLocation.Bottom,
|
|
||||||
Series = new ComponentLibrary1.office_package.HelperModels.PdfDiagramSeries
|
|
||||||
{
|
|
||||||
SeriesName = "DesctopOperatingSystemAugust2024",
|
|
||||||
Data = new Dictionary<string, double>
|
|
||||||
{
|
|
||||||
{ "Windows", 71.5 },
|
|
||||||
{ "OS X", 15.5 },
|
|
||||||
{ "Linux", 4.5 },
|
|
||||||
{ "Others", 8.5 },
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
MessageBox.Show("PDF äîêóìåíò ñ äèàãðàììîé ñîçäàí!", "Óñïåõ");
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show($"Îøèáêà: {ex.Message}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
namespace TestApp1
|
|
||||||
{
|
|
||||||
internal static class Program
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// The main entry point for the application.
|
|
||||||
/// </summary>
|
|
||||||
[STAThread]
|
|
||||||
static void Main()
|
|
||||||
{
|
|
||||||
// To customize application configuration such as set high DPI settings or default font,
|
|
||||||
// see https://aka.ms/applicationconfiguration.
|
|
||||||
ApplicationConfiguration.Initialize();
|
|
||||||
Application.Run(new Form1());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<OutputType>WinExe</OutputType>
|
|
||||||
<TargetFramework>net6.0-windows</TargetFramework>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
<UseWindowsForms>true</UseWindowsForms>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\ComponentLibrary1\ComponentLibrary1.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
Loading…
Reference in New Issue
Block a user