commit 13d3b1c1b290012a97347efbd895517029f4eee9 Author: Oleg Shabunov Date: Tue Sep 10 21:45:18 2024 +0400 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e7f2ee3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,400 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ +[Bb]inaries/ +[Ii]ntermediate/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.tlog +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio 6 auto-generated project file (contains which files were open etc.) +*.vbp + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files +*.ncb +*.aps + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# Visual Studio History (VSHistory) files +.vshistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp + +# JetBrains Rider +*.sln.iml diff --git a/FormsTesting/Form1.Designer.cs b/FormsTesting/Form1.Designer.cs new file mode 100644 index 0000000..e541983 --- /dev/null +++ b/FormsTesting/Form1.Designer.cs @@ -0,0 +1,163 @@ +namespace FormsTesting +{ + partial class Form1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + SelectComponent = new ShabComponentsLibrary.ShabSelectComponent(); + InputComponent = new ShabComponentsLibrary.ShabInputComponent(); + GridComponent = new ShabComponentsLibrary.ShabListOutputComponent(); + groupBox1 = new GroupBox(); + ClearListButton = new Button(); + groupBox2 = new GroupBox(); + ShowIntButton = new Button(); + groupBox3 = new GroupBox(); + PrintObjectButton = new Button(); + groupBox1.SuspendLayout(); + groupBox2.SuspendLayout(); + groupBox3.SuspendLayout(); + SuspendLayout(); + // + // SelectComponent + // + SelectComponent.Location = new Point(6, 22); + SelectComponent.Margin = new Padding(0); + SelectComponent.Name = "SelectComponent"; + SelectComponent.SelectedItem = ""; + SelectComponent.Size = new Size(200, 86); + SelectComponent.TabIndex = 0; + SelectComponent.ItemSelected += SelectComponent_ItemSelected; + // + // InputComponent + // + InputComponent.Location = new Point(6, 22); + InputComponent.Margin = new Padding(0); + InputComponent.Name = "InputComponent"; + InputComponent.Size = new Size(182, 30); + InputComponent.TabIndex = 1; + InputComponent.ValueChanged += InputComponent_ValueChanged; + // + // GridComponent + // + GridComponent.Location = new Point(6, 22); + GridComponent.Name = "GridComponent"; + GridComponent.SelectedRow = -1; + GridComponent.Size = new Size(505, 213); + GridComponent.TabIndex = 2; + // + // groupBox1 + // + groupBox1.Controls.Add(ClearListButton); + groupBox1.Controls.Add(SelectComponent); + groupBox1.Location = new Point(12, 12); + groupBox1.Name = "groupBox1"; + groupBox1.Size = new Size(407, 113); + groupBox1.TabIndex = 3; + groupBox1.TabStop = false; + groupBox1.Text = "Компонент выбора"; + // + // ClearListButton + // + ClearListButton.Location = new Point(215, 38); + ClearListButton.Name = "ClearListButton"; + ClearListButton.Size = new Size(107, 48); + ClearListButton.TabIndex = 1; + ClearListButton.Text = "Очистить"; + ClearListButton.UseVisualStyleBackColor = true; + ClearListButton.Click += ClearListButton_Click; + // + // groupBox2 + // + groupBox2.Controls.Add(ShowIntButton); + groupBox2.Controls.Add(InputComponent); + groupBox2.Location = new Point(12, 143); + groupBox2.Name = "groupBox2"; + groupBox2.Size = new Size(293, 100); + groupBox2.TabIndex = 4; + groupBox2.TabStop = false; + groupBox2.Text = "Компонент ввода"; + // + // ShowIntButton + // + ShowIntButton.Location = new Point(6, 58); + ShowIntButton.Name = "ShowIntButton"; + ShowIntButton.Size = new Size(172, 36); + ShowIntButton.TabIndex = 2; + ShowIntButton.Text = "Вывести на экран"; + ShowIntButton.UseVisualStyleBackColor = true; + ShowIntButton.Click += ShowIntButton_Click; + // + // groupBox3 + // + groupBox3.Controls.Add(PrintObjectButton); + groupBox3.Controls.Add(GridComponent); + groupBox3.Location = new Point(12, 260); + groupBox3.Name = "groupBox3"; + groupBox3.Size = new Size(517, 280); + groupBox3.TabIndex = 5; + groupBox3.TabStop = false; + groupBox3.Text = "Компонент вывода списков"; + // + // PrintObjectButton + // + PrintObjectButton.Location = new Point(6, 241); + PrintObjectButton.Name = "PrintObjectButton"; + PrintObjectButton.Size = new Size(182, 33); + PrintObjectButton.TabIndex = 3; + PrintObjectButton.Text = "Вывести выбранный объект"; + PrintObjectButton.UseVisualStyleBackColor = true; + PrintObjectButton.Click += PrintObjectButton_Click; + // + // Form1 + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(637, 581); + Controls.Add(groupBox3); + Controls.Add(groupBox2); + Controls.Add(groupBox1); + Name = "Form1"; + Text = "Тест компонентов"; + groupBox1.ResumeLayout(false); + groupBox2.ResumeLayout(false); + groupBox3.ResumeLayout(false); + ResumeLayout(false); + } + + #endregion + + private ShabComponentsLibrary.ShabSelectComponent SelectComponent; + private ShabComponentsLibrary.ShabInputComponent InputComponent; + private ShabComponentsLibrary.ShabListOutputComponent GridComponent; + private GroupBox groupBox1; + private Button ClearListButton; + private GroupBox groupBox2; + private Button ShowIntButton; + private GroupBox groupBox3; + private Button PrintObjectButton; + } +} diff --git a/FormsTesting/Form1.cs b/FormsTesting/Form1.cs new file mode 100644 index 0000000..0b0ee53 --- /dev/null +++ b/FormsTesting/Form1.cs @@ -0,0 +1,101 @@ +using ShabComponentsLibrary; +using ShabComponentsLibrary.Exceptions; + +namespace FormsTesting +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + + InitializeSelectComponent(); + InitializeInputComponent(); + InitializeGridComponent(); + } + + private void InitializeSelectComponent() + { + SelectComponent.SetItems(new List + { + " 1", + " 2", + " 3", + " 4", + " 5", + }); + } + + private void InitializeInputComponent() + { + InputComponent.IntValue = 1848; + } + + private void InitializeGridComponent() + { + GridComponent.ConfigureColumns(new List + { + new ColumnInfo("", 0, false, "Id"), + new ColumnInfo("", 150, true, "LastName"), + new ColumnInfo("", 150, true, "FirstName"), + new ColumnInfo("", 100, true, "Age"), + }); + + List Persons = new List + { + new TestPerson(1, "", "", 34), + new TestPerson(2, "", "", 44), + new TestPerson(3, "", "", 55), + new TestPerson(4, "", "", 34), + new TestPerson(5, "", "", 44), + }; + + GridComponent.InsertValues(Persons); + } + + private void SelectComponent_ItemSelected(object sender, EventArgs e) + { + MessageBox.Show(SelectComponent.SelectedItem); + } + + private void InputComponent_ValueChanged(object sender, EventArgs e) + { + + } + + private void ClearListButton_Click(object sender, EventArgs e) + { + SelectComponent.ClearList(); + } + + private void ShowIntButton_Click(object sender, EventArgs e) + { + try + { + int? Value = InputComponent.IntValue; + if (Value != null) + { + MessageBox.Show($" : {Value}"); + } + else + { + MessageBox.Show(" - null"); + } + } + catch (MalformedIntegralException ex) + { + MessageBox.Show(ex.Message); + } + catch (EmptyValueException ex) + { + MessageBox.Show(ex.Message); + } + } + + private void PrintObjectButton_Click(object sender, EventArgs e) + { + var Test = GridComponent.GetSelectedObject(); + MessageBox.Show(Test.ToString()); + } + } +} diff --git a/FormsTesting/Form1.resx b/FormsTesting/Form1.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/FormsTesting/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/FormsTesting/FormsTesting.csproj b/FormsTesting/FormsTesting.csproj new file mode 100644 index 0000000..3e75b31 --- /dev/null +++ b/FormsTesting/FormsTesting.csproj @@ -0,0 +1,15 @@ + + + + WinExe + net8.0-windows + enable + true + enable + + + + + + + \ No newline at end of file diff --git a/FormsTesting/Program.cs b/FormsTesting/Program.cs new file mode 100644 index 0000000..58eaf88 --- /dev/null +++ b/FormsTesting/Program.cs @@ -0,0 +1,17 @@ +namespace FormsTesting +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [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()); + } + } +} \ No newline at end of file diff --git a/FormsTesting/TestPerson.cs b/FormsTesting/TestPerson.cs new file mode 100644 index 0000000..0c224c2 --- /dev/null +++ b/FormsTesting/TestPerson.cs @@ -0,0 +1,29 @@ +namespace ShabComponentsLibrary +{ + public class TestPerson + { + public int Id { get; set; } + + public string FirstName { get; set; } = string.Empty; + + public string LastName { get; set; } = string.Empty; + + public int Age { get; set; } + + public TestPerson() + { } + + public TestPerson(int Id, string FirstName, string LastName, int Age) + { + this.Id = Id; + this.FirstName = FirstName; + this.LastName = LastName; + this.Age = Age; + } + + public override string ToString() + { + return $"[{Id}] {FirstName} {LastName}. Возраст: {Age}"; + } + } +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..7ea856c --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +# Компонентно-ориентированное программирование +Библиотека компонентов. +Вариант 21. + +*Автор: Шабунов Олег, ПИбд-32* + diff --git a/ShabComponentsLibrary.sln b/ShabComponentsLibrary.sln new file mode 100644 index 0000000..be8a916 --- /dev/null +++ b/ShabComponentsLibrary.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.8.34511.84 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShabComponentsLibrary", "ShabComponentsLibrary\ShabComponentsLibrary.csproj", "{DB0A9BE4-E285-413E-88B0-7D70261702D6}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FormsTesting", "FormsTesting\FormsTesting.csproj", "{6AE149F2-88C0-42BE-A198-2B59A4280B2D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {DB0A9BE4-E285-413E-88B0-7D70261702D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DB0A9BE4-E285-413E-88B0-7D70261702D6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DB0A9BE4-E285-413E-88B0-7D70261702D6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DB0A9BE4-E285-413E-88B0-7D70261702D6}.Release|Any CPU.Build.0 = Release|Any CPU + {6AE149F2-88C0-42BE-A198-2B59A4280B2D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6AE149F2-88C0-42BE-A198-2B59A4280B2D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6AE149F2-88C0-42BE-A198-2B59A4280B2D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6AE149F2-88C0-42BE-A198-2B59A4280B2D}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {01C6DE7D-113E-47E6-8C9E-E570FE377AD4} + EndGlobalSection +EndGlobal diff --git a/ShabComponentsLibrary/ColumnInfo.cs b/ShabComponentsLibrary/ColumnInfo.cs new file mode 100644 index 0000000..bb4c23c --- /dev/null +++ b/ShabComponentsLibrary/ColumnInfo.cs @@ -0,0 +1,21 @@ +namespace ShabComponentsLibrary +{ + public class ColumnInfo + { + public string Header = string.Empty; + + public int Width; + + public bool IsVisible; + + public string Name = string.Empty; + + public ColumnInfo(string Header, int Width, bool IsVisible, string Name) + { + this.Header = Header; + this.Width = Width; + this.IsVisible = IsVisible; + this.Name = Name; + } + } +} diff --git a/ShabComponentsLibrary/Exceptions/EmptyValueException.cs b/ShabComponentsLibrary/Exceptions/EmptyValueException.cs new file mode 100644 index 0000000..9431d15 --- /dev/null +++ b/ShabComponentsLibrary/Exceptions/EmptyValueException.cs @@ -0,0 +1,9 @@ +namespace ShabComponentsLibrary.Exceptions +{ + public class EmptyValueException : ApplicationException + { + public EmptyValueException() + : base("Значение не введено") + { } + } +} diff --git a/ShabComponentsLibrary/Exceptions/MalformedIntegralException.cs b/ShabComponentsLibrary/Exceptions/MalformedIntegralException.cs new file mode 100644 index 0000000..cf2e0ca --- /dev/null +++ b/ShabComponentsLibrary/Exceptions/MalformedIntegralException.cs @@ -0,0 +1,9 @@ +namespace ShabComponentsLibrary.Exceptions +{ + public class MalformedIntegralException : ApplicationException + { + public MalformedIntegralException() + : base("Введенное значение не является целочисленным") + { } + } +} diff --git a/ShabComponentsLibrary/ShabComponentsLibrary.csproj b/ShabComponentsLibrary/ShabComponentsLibrary.csproj new file mode 100644 index 0000000..3e210aa --- /dev/null +++ b/ShabComponentsLibrary/ShabComponentsLibrary.csproj @@ -0,0 +1,10 @@ + + + + net8.0-windows + enable + true + enable + + + diff --git a/ShabComponentsLibrary/ShabInputComponent.Designer.cs b/ShabComponentsLibrary/ShabInputComponent.Designer.cs new file mode 100644 index 0000000..64a86b3 --- /dev/null +++ b/ShabComponentsLibrary/ShabInputComponent.Designer.cs @@ -0,0 +1,74 @@ +namespace ShabComponentsLibrary +{ + partial class ShabInputComponent + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + IsNullCheckBox = new CheckBox(); + MainTextBox = new TextBox(); + SuspendLayout(); + // + // IsNullCheckBox + // + IsNullCheckBox.AutoSize = true; + IsNullCheckBox.Location = new Point(3, 7); + IsNullCheckBox.Name = "IsNullCheckBox"; + IsNullCheckBox.Size = new Size(15, 14); + IsNullCheckBox.TabIndex = 0; + IsNullCheckBox.UseVisualStyleBackColor = true; + IsNullCheckBox.CheckedChanged += IsNullCheckBox_CheckedChanged; + // + // MainTextBox + // + MainTextBox.Location = new Point(20, 3); + MainTextBox.Margin = new Padding(0); + MainTextBox.MaxLength = 10; + MainTextBox.Name = "MainTextBox"; + MainTextBox.PlaceholderText = "0"; + MainTextBox.Size = new Size(153, 23); + MainTextBox.TabIndex = 1; + MainTextBox.TextChanged += MainTextBox_TextChanged; + // + // ShabInputComponent + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(MainTextBox); + Controls.Add(IsNullCheckBox); + Margin = new Padding(0); + Name = "ShabInputComponent"; + Size = new Size(175, 29); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private CheckBox IsNullCheckBox; + private TextBox MainTextBox; + } +} diff --git a/ShabComponentsLibrary/ShabInputComponent.cs b/ShabComponentsLibrary/ShabInputComponent.cs new file mode 100644 index 0000000..9eb97ba --- /dev/null +++ b/ShabComponentsLibrary/ShabInputComponent.cs @@ -0,0 +1,97 @@ +using ShabComponentsLibrary.Exceptions; + +namespace ShabComponentsLibrary +{ + /// + /// Текстовый визуальный компонент для ввода значения определенного типа + /// + public partial class ShabInputComponent : UserControl + { + private event EventHandler? _valueChanged; + + public ShabInputComponent() + { + InitializeComponent(); + } + + /// + /// Установка и получение введенного значения + /// + public int? IntValue + { + get + { + if (IsNullCheckBox.Checked) + { + return null; + } + + if (string.IsNullOrEmpty(MainTextBox.Text)) + { + throw new EmptyValueException(); + } + + int ParsedInt; + if (Int32.TryParse(MainTextBox.Text, out ParsedInt)) + { + return ParsedInt; + } + else + { + throw new MalformedIntegralException(); + } + } + set + { + if (value is null) + { + SetNullState(true); + } + else + { + SetNullState(false); + MainTextBox.Text = value.ToString(); + } + } + } + + /// + /// Событие, вызываемое при смене значения (либо при смене CheckBox) + /// + public event EventHandler? ValueChanged + { + add { _valueChanged += value; } + remove { _valueChanged -= value; } + } + + private void SetNullState(bool IsNull, bool ClearText = false) + { + if (IsNull) + { + IsNullCheckBox.Checked = true; + MainTextBox.Enabled = false; + } + else + { + IsNullCheckBox.Checked = false; + MainTextBox.Enabled = true; + } + + if (ClearText) + { + MainTextBox.Text = string.Empty; + } + } + + private void IsNullCheckBox_CheckedChanged(object sender, EventArgs e) + { + SetNullState(IsNullCheckBox.Checked); + _valueChanged?.Invoke(this, e); + } + + private void MainTextBox_TextChanged(object sender, EventArgs e) + { + _valueChanged?.Invoke(this, e); + } + } +} diff --git a/ShabComponentsLibrary/ShabInputComponent.resx b/ShabComponentsLibrary/ShabInputComponent.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ShabComponentsLibrary/ShabInputComponent.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ShabComponentsLibrary/ShabListOutputComponent.Designer.cs b/ShabComponentsLibrary/ShabListOutputComponent.Designer.cs new file mode 100644 index 0000000..a3d04c3 --- /dev/null +++ b/ShabComponentsLibrary/ShabListOutputComponent.Designer.cs @@ -0,0 +1,63 @@ +namespace ShabComponentsLibrary +{ + partial class ShabListOutputComponent + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + Grid = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)Grid).BeginInit(); + SuspendLayout(); + // + // Grid + // + Grid.AllowUserToAddRows = false; + Grid.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + Grid.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + Grid.Location = new Point(3, 3); + Grid.MultiSelect = false; + Grid.Name = "Grid"; + Grid.RowHeadersVisible = false; + Grid.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + Grid.Size = new Size(380, 243); + Grid.TabIndex = 0; + // + // ShabListOutputComponent + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(Grid); + Name = "ShabListOutputComponent"; + Size = new Size(386, 249); + ((System.ComponentModel.ISupportInitialize)Grid).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView Grid; + } +} diff --git a/ShabComponentsLibrary/ShabListOutputComponent.cs b/ShabComponentsLibrary/ShabListOutputComponent.cs new file mode 100644 index 0000000..e2adef4 --- /dev/null +++ b/ShabComponentsLibrary/ShabListOutputComponent.cs @@ -0,0 +1,107 @@ +namespace ShabComponentsLibrary +{ + public partial class ShabListOutputComponent : UserControl + { + /// + /// Установка и получение индекса выбранной строки + /// + public int SelectedRow + { + get => Grid.SelectedRows.Count == 1 ? Grid.SelectedRows[0].Index : -1; + set + { + if (value >= 0) + { + Grid.Rows[value].Selected = true; + } + } + } + + public ShabListOutputComponent() + { + InitializeComponent(); + } + + /// + /// Конфигурация столбцов. + /// Для каждого столбца указываются заголовок, ширина, видимость и имя свойства/поля объекта + /// + /// Информация о столбцах + public void ConfigureColumns(List Columns) + { + Grid.ColumnCount = Columns.Count; + + for (int Index = 0; Index < Columns.Count; ++Index) + { + Grid.Columns[Index].HeaderText = Columns[Index].Header; + Grid.Columns[Index].Width = Columns[Index].Width; + Grid.Columns[Index].Visible = Columns[Index].IsVisible; + Grid.Columns[Index].Name = Columns[Index].Name; + } + } + + /// + /// Очистка строк + /// + public void ClearGrid() + { + Grid.Rows.Clear(); + } + + /// + /// Получение объекта из выбранной строки + /// + /// Тип получаемого объекта + /// + public T GetSelectedObject() where T : new() + { + T RetVal = new T(); + var Properties = typeof(T).GetProperties(); + + var Cells = Grid.SelectedRows[0].Cells; + for (int Index = 0; Index < Grid.ColumnCount; ++Index) + { + DataGridViewColumn Column = Grid.Columns[Index]; + var Cell = Cells[Index]; + + var Property = Properties.FirstOrDefault(x => x.Name == Column.Name); + Property?.SetValue(RetVal, Cell.Value); + } + + return RetVal; + } + + /// + /// Заполнение таблицы через передаваемый список объектов класса T + /// + public void InsertValues(List Objects) + { + ClearGrid(); + + var Type = typeof(T); + var Properties = Type.GetProperties(); + + foreach (var Object in Objects) + { + int NewRowIndex = Grid.Rows.Add(); + + foreach (DataGridViewColumn Column in Grid.Columns) + { + var Property = Properties.FirstOrDefault(x => x.Name == Column.Name); + if (Property == null) + throw new InvalidOperationException($"В типе {Type.Name} не найдено свойство с именем {Column.Name}"); + + var Value = Property.GetValue(Object); + Grid.Rows[NewRowIndex].Cells[Column.Index].Value = Value; + } + } + + foreach (DataGridViewColumn Column in Grid.Columns) + { + var Property = Properties.FirstOrDefault(x => x.Name == Column.Name); + if (Property == null) + throw new InvalidOperationException($"В типе {Type.Name} не найдено свойство с именем {Column.Name}"); + } + } + } +} diff --git a/ShabComponentsLibrary/ShabListOutputComponent.resx b/ShabComponentsLibrary/ShabListOutputComponent.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ShabComponentsLibrary/ShabListOutputComponent.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ShabComponentsLibrary/ShabSelectComponent.Designer.cs b/ShabComponentsLibrary/ShabSelectComponent.Designer.cs new file mode 100644 index 0000000..5067097 --- /dev/null +++ b/ShabComponentsLibrary/ShabSelectComponent.Designer.cs @@ -0,0 +1,61 @@ +namespace ShabComponentsLibrary +{ + partial class ShabSelectComponent + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + MainListBox = new ListBox(); + SuspendLayout(); + // + // MainListBox + // + MainListBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + MainListBox.FormattingEnabled = true; + MainListBox.ItemHeight = 15; + MainListBox.Location = new Point(0, 0); + MainListBox.Margin = new Padding(0); + MainListBox.Name = "MainListBox"; + MainListBox.Size = new Size(200, 94); + MainListBox.TabIndex = 0; + MainListBox.SelectedIndexChanged += MainListBox_SelectedIndexChanged; + // + // ShabSelectComponent + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(MainListBox); + Margin = new Padding(0); + Name = "ShabSelectComponent"; + Size = new Size(200, 94); + ResumeLayout(false); + } + + #endregion + + private ListBox MainListBox; + } +} diff --git a/ShabComponentsLibrary/ShabSelectComponent.cs b/ShabComponentsLibrary/ShabSelectComponent.cs new file mode 100644 index 0000000..f26701f --- /dev/null +++ b/ShabComponentsLibrary/ShabSelectComponent.cs @@ -0,0 +1,58 @@ +namespace ShabComponentsLibrary +{ + /// + /// Визуальный компонент для выбора из обычного списка + /// + public partial class ShabSelectComponent : UserControl + { + private event EventHandler? _itemSelected; + + public ShabSelectComponent() + { + InitializeComponent(); + } + + /// + /// Метод, у которого в передаваемых параметрах идет список строк + /// + /// Список строк + public void SetItems(List Items) + { + foreach (var Item in Items) + { + MainListBox.Items.Add(Item); + } + } + + /// + /// Очистка списка + /// + public void ClearList() + { + MainListBox.Items.Clear(); + } + + /// + /// Установка и получение выбранного значения + /// + public string SelectedItem + { + get { return (string?)MainListBox.SelectedItem ?? string.Empty; } + set { MainListBox.SelectedItem = value; } + } + + /// + /// Событие, вызываемое при смене значения в ListBox + /// + public event EventHandler? ItemSelected + { + add { _itemSelected += value; } + remove { _itemSelected -= value; } + } + + private void MainListBox_SelectedIndexChanged(object sender, EventArgs e) + { + _itemSelected?.Invoke(this, e); + } + } +} diff --git a/ShabComponentsLibrary/ShabSelectComponent.resx b/ShabComponentsLibrary/ShabSelectComponent.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ShabComponentsLibrary/ShabSelectComponent.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file