готовая лаба 3

This commit is contained in:
Полина Чубыкина 2024-10-29 11:23:52 +04:00
parent 32e651c219
commit c5a31a3ca4
8 changed files with 66 additions and 122 deletions

View File

@ -6,6 +6,7 @@
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>$(VersionPrefix)1.0.3</Version>
</PropertyGroup>
<ItemGroup>

View File

@ -25,7 +25,10 @@ namespace ChubykinaComponents.Components
}
set
{
if (value != null && checkedListBox.Items.Contains(value)) checkedListBox.SelectedItem = value;
if (value != null && checkedListBox.Items.Contains(value)) {
checkedListBox.SelectedItem = value;
checkedListBox.SetItemChecked(checkedListBox.SelectedIndex, true);
}
}
}

View File

@ -17,6 +17,7 @@ namespace ChubykinaComponents.Components
{
InitializeComponent();
}
private List<(string, bool)> hierarchy = new List<(string, bool)>();
public int SelectedNodeIndex
@ -27,8 +28,10 @@ namespace ChubykinaComponents.Components
}
set
{
if (treeView.SelectedNode == null) treeView.SelectedNode = value >= 0 && value < treeView.Nodes.Count ? treeView.Nodes[value] : treeView.SelectedNode;
else treeView.SelectedNode = value >= 0 && value < treeView.SelectedNode.Nodes.Count ? treeView.SelectedNode.Nodes[value] : treeView.SelectedNode;
if (treeView.SelectedNode == null)
treeView.SelectedNode = value >= 0 && value < treeView.Nodes.Count ? treeView.Nodes[value] : treeView.SelectedNode;
else
treeView.SelectedNode = value >= 0 && value < treeView.SelectedNode.Nodes.Count ? treeView.SelectedNode.Nodes[value] : treeView.SelectedNode;
}
}
@ -37,15 +40,15 @@ namespace ChubykinaComponents.Components
if (treeView.SelectedNode == null || treeView.SelectedNode.Nodes.Count > 0) return default(T);
TreeNode? node = treeView.SelectedNode;
var type = typeof(T);
var fields = type.GetFields();
var properties = type.GetProperties();
var item = Activator.CreateInstance(type);
while (node != null)
{
var field = fields.FirstOrDefault(x => x.Name == node.Name);
if (field != null)
var property = properties.FirstOrDefault(x => x.Name == node.Name);
if (property != null)
{
field.SetValue(item, node.Text);
property.SetValue(item, Convert.ChangeType(node.Text, property.PropertyType));
}
node = node.Parent;
}
@ -61,23 +64,23 @@ namespace ChubykinaComponents.Components
public void addItems<T>(List<T> items)
{
var type = typeof(T);
var fields = type.GetFields();
var properties = type.GetProperties();
foreach (T item in items)
{
TreeNodeCollection nodes = treeView.Nodes;
for (int i = 0; i < hierarchy.Count; i++)
{
var field = fields.FirstOrDefault(x => x.Name.Equals(hierarchy[i].Item1));
if (field is not null)
var property = properties.FirstOrDefault(x => x.Name.Equals(hierarchy[i].Item1));
if (property is not null)
{
var node = nodes.Find(field.Name, false).FirstOrDefault(x => x.Text == field.GetValue(item).ToString());
var node = nodes.Find(property.Name, false).FirstOrDefault(x => x.Text == property.GetValue(item).ToString());
if (node is not null && !hierarchy[i].Item2)
{
nodes = node.Nodes;
}
else
{
TreeNode newNode = nodes.Add(field.Name, field.GetValue(item).ToString());
TreeNode newNode = nodes.Add(property.Name, property.GetValue(item).ToString());
nodes = newNode.Nodes;
}
}

View File

@ -30,10 +30,8 @@
{
this.label1 = new System.Windows.Forms.Label();
this.textBoxFio = new System.Windows.Forms.TextBox();
this.textBoxPassword = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.mailControl = new BulatovaComponents.MailControl();
this.mailControl = new BulatovaComponents.Components.MailControl();
this.userCheckedListBox = new ChubykinaComponents.Components.UserCheckedListBox();
this.label4 = new System.Windows.Forms.Label();
this.buttonSave = new System.Windows.Forms.Button();
@ -46,43 +44,25 @@
//
this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 9);
this.label1.Location = new System.Drawing.Point(12, 20);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(52, 20);
this.label1.Size = new System.Drawing.Size(42, 20);
this.label1.TabIndex = 0;
this.label1.Text = "ФИО";
//
// textBoxFio
//
this.textBoxFio.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
this.textBoxFio.Location = new System.Drawing.Point(12, 32);
this.textBoxFio.Location = new System.Drawing.Point(12, 43);
this.textBoxFio.Name = "textBoxFio";
this.textBoxFio.Size = new System.Drawing.Size(389, 27);
this.textBoxFio.TabIndex = 1;
//
// textBoxPassword
//
this.textBoxPassword.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
this.textBoxPassword.Location = new System.Drawing.Point(12, 86);
this.textBoxPassword.Name = "textBoxPassword";
this.textBoxPassword.Size = new System.Drawing.Size(389, 27);
this.textBoxPassword.TabIndex = 3;
//
// label2
//
this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(12, 63);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(62, 20);
this.label2.TabIndex = 2;
this.label2.Text = "Пароль";
//
// label3
//
this.label3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(12, 116);
this.label3.Location = new System.Drawing.Point(12, 90);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(51, 20);
this.label3.TabIndex = 4;
@ -92,7 +72,7 @@
//
this.mailControl.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
this.mailControl.Email = null;
this.mailControl.Location = new System.Drawing.Point(12, 139);
this.mailControl.Location = new System.Drawing.Point(12, 113);
this.mailControl.Name = "mailControl";
this.mailControl.Size = new System.Drawing.Size(389, 42);
this.mailControl.TabIndex = 5;
@ -101,8 +81,8 @@
// userCheckedListBox
//
this.userCheckedListBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
this.userCheckedListBox.Location = new System.Drawing.Point(12, 207);
this.userCheckedListBox.Name = "UserCheckedListBox";
this.userCheckedListBox.Location = new System.Drawing.Point(12, 181);
this.userCheckedListBox.Name = "userCheckedListBox";
this.userCheckedListBox.selectedItem = null;
this.userCheckedListBox.Size = new System.Drawing.Size(389, 130);
this.userCheckedListBox.TabIndex = 6;
@ -111,15 +91,15 @@
//
this.label4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(12, 184);
this.label4.Location = new System.Drawing.Point(12, 158);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(78, 20);
this.label4.Size = new System.Drawing.Size(82, 20);
this.label4.TabIndex = 7;
this.label4.Text = "Интересы";
this.label4.Text = "Категории";
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(12, 420);
this.buttonSave.Location = new System.Drawing.Point(12, 350);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(94, 29);
this.buttonSave.TabIndex = 8;
@ -129,7 +109,7 @@
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(307, 420);
this.buttonCancel.Location = new System.Drawing.Point(307, 350);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(94, 29);
this.buttonCancel.TabIndex = 9;
@ -143,7 +123,7 @@
//
// buttonAvatar
//
this.buttonAvatar.Location = new System.Drawing.Point(12, 343);
this.buttonAvatar.Location = new System.Drawing.Point(12, 304);
this.buttonAvatar.Name = "buttonAvatar";
this.buttonAvatar.Size = new System.Drawing.Size(389, 29);
this.buttonAvatar.TabIndex = 10;
@ -155,7 +135,7 @@
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(413, 461);
this.ClientSize = new System.Drawing.Size(413, 392);
this.Controls.Add(this.buttonAvatar);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonSave);
@ -163,8 +143,6 @@
this.Controls.Add(this.userCheckedListBox);
this.Controls.Add(this.mailControl);
this.Controls.Add(this.label3);
this.Controls.Add(this.textBoxPassword);
this.Controls.Add(this.label2);
this.Controls.Add(this.textBoxFio);
this.Controls.Add(this.label1);
this.Name = "FormClient";
@ -179,10 +157,8 @@
private Label label1;
private TextBox textBoxFio;
private TextBox textBoxPassword;
private Label label2;
private Label label3;
private BulatovaComponents.MailControl mailControl;
private BulatovaComponents.Components.MailControl mailControl;
private ChubykinaComponents.Components.UserCheckedListBox userCheckedListBox;
private Label label4;
private Button buttonSave;

View File

@ -1,64 +1,4 @@
<?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.
-->
<root>
<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">
@ -117,4 +57,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -41,7 +41,7 @@
this.категорииToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.controlDataTable = new ControlsLibraryNet60.Data.ControlDataTableTable();
this.excelImagesComponent = new ChubykinaComponents.LogicalComponents.ExcelImagesComponent(this.components);
this.wordTableComponentClient = new BulatovaComponents.LogicalComponents.WordTableComponent(this.components);
this.wordTableComponentClient = new BulatovaComponents.NonVisualComponents.WordTableComponent(this.components);
this.componentDocumentWithChartBarPdf = new ComponentsLibraryNet60.DocumentWithChart.ComponentDocumentWithChartBarPdf(this.components);
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
@ -131,7 +131,7 @@
//
this.категорииToolStripMenuItem.Name = атегорииToolStripMenuItem";
this.категорииToolStripMenuItem.Size = new System.Drawing.Size(92, 24);
this.категорииToolStripMenuItem.Text = "Интересы";
this.категорииToolStripMenuItem.Text = "Категории";
this.категорииToolStripMenuItem.Click += new System.EventHandler(this.категорииToolStripMenuItem_Click);
//
// controlDataTable
@ -175,7 +175,7 @@
private ToolStripMenuItem категорииToolStripMenuItem;
private ControlsLibraryNet60.Data.ControlDataTableTable controlDataTable;
private ChubykinaComponents.LogicalComponents.ExcelImagesComponent excelImagesComponent;
private BulatovaComponents.LogicalComponents.WordTableComponent wordTableComponentClient;
private BulatovaComponents.NonVisualComponents.WordTableComponent wordTableComponentClient;
private ComponentsLibraryNet60.DocumentWithChart.ComponentDocumentWithChartBarPdf componentDocumentWithChartBarPdf;
}
}

View File

@ -97,18 +97,29 @@ namespace WinFormsTest
private void документToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog = new()
{
Filter = "Excel Files|*.xlsx"
};
if (saveFileDialog.ShowDialog() != DialogResult.OK) return;
string path = saveFileDialog.FileName;
List<string> photos = new List<string>();
foreach (var client in _logic.ReadList(null))
{
photos.Add(client.Photo);
}
string path = AppDomain.CurrentDomain.BaseDirectory + "Фото.xlsx";
if (excelImagesComponent.createWithImages(new ExcelImageInfo(path, "Фото", photos.ToArray()))) MessageBox.Show("Документ создан");
}
private void документСДиаграммойToolStripMenuItem_Click(object sender, EventArgs e)
{
string path = AppDomain.CurrentDomain.BaseDirectory + "Интересы.pdf";
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
SaveFileDialog saveFileDialog = new()
{
Filter = "PDF Files|*.pdf"
};
if (saveFileDialog.ShowDialog() != DialogResult.OK) return;
string path = saveFileDialog.FileName;
Dictionary<string, List<(int, double)>> data = new Dictionary<string, List<(int, double)>>();
data = _logic
@ -118,9 +129,9 @@ namespace WinFormsTest
componentDocumentWithChartBarPdf.CreateDoc(new ComponentDocumentWithChartConfig
{
Header = "Интересы",
Header = "Категории",
FilePath = path,
ChartTitle = "Интересы",
ChartTitle = "Категории",
LegendLocation = ComponentsLibraryNet60.Models.Location.Bottom,
Data = data,
});
@ -130,7 +141,12 @@ namespace WinFormsTest
private void документСТаблицейToolStripMenuItem_Click(object sender, EventArgs e)
{
string path = AppDomain.CurrentDomain.BaseDirectory + "Клиенты.docx";
SaveFileDialog saveFileDialog = new()
{
Filter = "Word Files|*.docx"
};
if (saveFileDialog.ShowDialog() != DialogResult.OK) return;
string path = saveFileDialog.FileName;
List<(int, int)> merges = new List<(int, int)> { (1, 2) };
List<int> widths = new List<int> { 100, 100, 100, 100 };
List<(string, string)> headers = new List<(string, string)> {
@ -142,7 +158,9 @@ namespace WinFormsTest
};
wordTableComponentClient.createWithTable(path, "Список клиентов", merges, widths, headers, _logic.ReadList(null));
MessageBox.Show("Документ создан");
}
}
}

View File

@ -9,7 +9,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BulatovaComponents" Version="1.0.0" />
<PackageReference Include="BulatovaComponents" Version="1.0.1" />
<PackageReference Include="ComponentsLibraryNet60" Version="1.0.0" />
<PackageReference Include="ControlsLibraryNet60" Version="1.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.20">