остались хоткеи и отчеты

This commit is contained in:
frog24 2024-11-12 17:41:57 +04:00
parent 6f971d1327
commit c98c740959
8 changed files with 533 additions and 4 deletions

View File

@ -63,7 +63,7 @@ namespace BusinessLogic
} }
public bool Delete(WorkerBindingModel model) public bool Delete(WorkerBindingModel model)
{ {
CheckModel(model); CheckModel(model, false);
if (_workerStorage.Delete(model) == null) if (_workerStorage.Delete(model) == null)
{ {
return false; return false;

View File

@ -37,6 +37,7 @@
pdfToolStripMenuItem = new ToolStripMenuItem(); pdfToolStripMenuItem = new ToolStripMenuItem();
excelToolStripMenuItem = new ToolStripMenuItem(); excelToolStripMenuItem = new ToolStripMenuItem();
wordToolStripMenuItem = new ToolStripMenuItem(); wordToolStripMenuItem = new ToolStripMenuItem();
customTreeView = new BelianinComponents.CustomTreeView();
menuStrip1.SuspendLayout(); menuStrip1.SuspendLayout();
SuspendLayout(); SuspendLayout();
// //
@ -46,7 +47,7 @@
menuStrip1.Items.AddRange(new ToolStripItem[] { menuToolStripMenuItem }); menuStrip1.Items.AddRange(new ToolStripItem[] { menuToolStripMenuItem });
menuStrip1.Location = new Point(0, 0); menuStrip1.Location = new Point(0, 0);
menuStrip1.Name = "menuStrip1"; menuStrip1.Name = "menuStrip1";
menuStrip1.Size = new Size(800, 28); menuStrip1.Size = new Size(550, 28);
menuStrip1.TabIndex = 1; menuStrip1.TabIndex = 1;
menuStrip1.Text = "menuStrip1"; menuStrip1.Text = "menuStrip1";
// //
@ -69,18 +70,21 @@
addWorkerToolStripMenuItem.Name = "addWorkerToolStripMenuItem"; addWorkerToolStripMenuItem.Name = "addWorkerToolStripMenuItem";
addWorkerToolStripMenuItem.Size = new Size(224, 26); addWorkerToolStripMenuItem.Size = new Size(224, 26);
addWorkerToolStripMenuItem.Text = "add worker"; addWorkerToolStripMenuItem.Text = "add worker";
addWorkerToolStripMenuItem.Click += addWorkerToolStripMenuItem_Click;
// //
// editWorkerToolStripMenuItem // editWorkerToolStripMenuItem
// //
editWorkerToolStripMenuItem.Name = "editWorkerToolStripMenuItem"; editWorkerToolStripMenuItem.Name = "editWorkerToolStripMenuItem";
editWorkerToolStripMenuItem.Size = new Size(224, 26); editWorkerToolStripMenuItem.Size = new Size(224, 26);
editWorkerToolStripMenuItem.Text = "edit worker"; editWorkerToolStripMenuItem.Text = "edit worker";
editWorkerToolStripMenuItem.Click += editWorkerToolStripMenuItem_Click;
// //
// deleteWorkerToolStripMenuItem // deleteWorkerToolStripMenuItem
// //
deleteWorkerToolStripMenuItem.Name = "deleteWorkerToolStripMenuItem"; deleteWorkerToolStripMenuItem.Name = "deleteWorkerToolStripMenuItem";
deleteWorkerToolStripMenuItem.Size = new Size(224, 26); deleteWorkerToolStripMenuItem.Size = new Size(224, 26);
deleteWorkerToolStripMenuItem.Text = "delete worker"; deleteWorkerToolStripMenuItem.Text = "delete worker";
deleteWorkerToolStripMenuItem.Click += deleteWorkerToolStripMenuItem_Click;
// //
// pdfToolStripMenuItem // pdfToolStripMenuItem
// //
@ -100,11 +104,20 @@
wordToolStripMenuItem.Size = new Size(224, 26); wordToolStripMenuItem.Size = new Size(224, 26);
wordToolStripMenuItem.Text = "word"; wordToolStripMenuItem.Text = "word";
// //
// customTreeView
//
customTreeView.hierarchy = null;
customTreeView.Location = new Point(12, 31);
customTreeView.Name = "customTreeView";
customTreeView.Size = new Size(529, 271);
customTreeView.TabIndex = 2;
//
// FormMain // FormMain
// //
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450); ClientSize = new Size(550, 312);
Controls.Add(customTreeView);
Controls.Add(menuStrip1); Controls.Add(menuStrip1);
MainMenuStrip = menuStrip1; MainMenuStrip = menuStrip1;
Name = "FormMain"; Name = "FormMain";
@ -125,5 +138,6 @@
private ToolStripMenuItem pdfToolStripMenuItem; private ToolStripMenuItem pdfToolStripMenuItem;
private ToolStripMenuItem excelToolStripMenuItem; private ToolStripMenuItem excelToolStripMenuItem;
private ToolStripMenuItem wordToolStripMenuItem; private ToolStripMenuItem wordToolStripMenuItem;
private BelianinComponents.CustomTreeView customTreeView;
} }
} }

View File

@ -1,4 +1,6 @@
using Contracts.BusinessLogicContracts; using Contracts.BusinessLogicContracts;
using Contracts.BindingModels;
using Contracts.ViewModels;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
@ -20,7 +22,20 @@ namespace TestApp
InitializeComponent(); InitializeComponent();
_workerLogic = workerLogic; _workerLogic = workerLogic;
_jobTypeLogic = jobTypeLogic; _jobTypeLogic = jobTypeLogic;
LoadData();
}
private void LoadData()
{
var list = _workerLogic.ReadList(null);
if (list != null)
{
customTreeView.Clear();
customTreeView.hierarchy = new List<string> { "JobType", "DateAdvance", "Id", "Name" };
foreach (var item in list)
{
customTreeView.AddNode(item, "Name");
}
}
} }
private void jobTypesToolStripMenuItem_Click(object sender, EventArgs e) private void jobTypesToolStripMenuItem_Click(object sender, EventArgs e)
@ -31,5 +46,42 @@ namespace TestApp
form.ShowDialog(); form.ShowDialog();
} }
} }
private void addWorkerToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormWorker));
if (service is FormWorker form)
{
form.ShowDialog();
}
LoadData();
}
private void editWorkerToolStripMenuItem_Click(object sender, EventArgs e)
{
Transmit item = customTreeView.GetSelectedNode<Transmit>();
int id = Convert.ToInt32(item.Id);
FormWorker form = new FormWorker(_jobTypeLogic, _workerLogic, id);
form.ShowDialog();
LoadData();
}
private void deleteWorkerToolStripMenuItem_Click(object sender, EventArgs e)
{
var confirmResult = MessageBox.Show("Вы действительно хотите удалить запись?", "Подтвердите действие",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question
);
Transmit item = customTreeView.GetSelectedNode<Transmit>();
if (confirmResult == DialogResult.Yes)
{
_workerLogic.Delete(new WorkerBindingModel
{
Id = Convert.ToInt32(item.Id)
});
LoadData();
}
}
} }
} }

View File

@ -0,0 +1,174 @@
namespace TestApp
{
partial class FormWorker
{
/// <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()
{
label1 = new Label();
label2 = new Label();
label3 = new Label();
label4 = new Label();
textBoxName = new TextBox();
textBoxAutobiography = new TextBox();
customComboBox = new BarsukovComponents.VisualComponents.CustomComboBox();
dateBoxWithNull = new KryukovLib.DateBoxWithNull();
buttonCancel = new Button();
buttonOK = new Button();
SuspendLayout();
//
// label1
//
label1.AutoSize = true;
label1.Font = new Font("Times New Roman", 12F);
label1.Location = new Point(101, 10);
label1.Name = "label1";
label1.Size = new Size(60, 22);
label1.TabIndex = 0;
label1.Text = "ФИО:";
//
// label2
//
label2.AutoSize = true;
label2.Font = new Font("Times New Roman", 12F);
label2.Location = new Point(12, 45);
label2.Name = "label2";
label2.Size = new Size(149, 22);
label2.TabIndex = 1;
label2.Text = "Автобиография:";
//
// label3
//
label3.AutoSize = true;
label3.Font = new Font("Times New Roman", 12F);
label3.Location = new Point(49, 80);
label3.Name = "label3";
label3.Size = new Size(112, 22);
label3.TabIndex = 2;
label3.Text = "Должность:";
//
// label4
//
label4.Font = new Font("Times New Roman", 12F);
label4.Location = new Point(3, 185);
label4.Name = "label4";
label4.Size = new Size(158, 54);
label4.TabIndex = 3;
label4.Text = "Дата повышения: квалификации";
//
// textBoxName
//
textBoxName.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
textBoxName.Location = new Point(167, 5);
textBoxName.Name = "textBoxName";
textBoxName.Size = new Size(250, 27);
textBoxName.TabIndex = 4;
textBoxName.TextChanged += OnInputChange;
//
// textBoxAutobiography
//
textBoxAutobiography.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
textBoxAutobiography.Location = new Point(167, 43);
textBoxAutobiography.Name = "textBoxAutobiography";
textBoxAutobiography.Size = new Size(250, 27);
textBoxAutobiography.TabIndex = 5;
textBoxAutobiography.TextChanged += OnInputChange;
//
// customComboBox
//
customComboBox.BorderStyle = BorderStyle.FixedSingle;
customComboBox.Location = new Point(167, 80);
customComboBox.Name = "customComboBox";
customComboBox.SelectedItem = "";
customComboBox.Size = new Size(250, 91);
customComboBox.TabIndex = 6;
customComboBox.Enter += OnInputChange;
//
// dateBoxWithNull
//
dateBoxWithNull.Location = new Point(167, 185);
dateBoxWithNull.Name = "dateBoxWithNull";
dateBoxWithNull.Size = new Size(278, 45);
dateBoxWithNull.TabIndex = 7;
//
// buttonCancel
//
buttonCancel.Font = new Font("Times New Roman", 12F, FontStyle.Regular, GraphicsUnit.Point, 204);
buttonCancel.Location = new Point(339, 249);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(94, 29);
buttonCancel.TabIndex = 8;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += buttonCancel_Click;
//
// buttonOK
//
buttonOK.Font = new Font("Times New Roman", 12F, FontStyle.Regular, GraphicsUnit.Point, 204);
buttonOK.Location = new Point(239, 249);
buttonOK.Name = "buttonOK";
buttonOK.Size = new Size(94, 29);
buttonOK.TabIndex = 9;
buttonOK.Text = "OK";
buttonOK.UseVisualStyleBackColor = true;
buttonOK.Click += buttonOK_Click;
//
// FormWorker
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(445, 290);
Controls.Add(buttonOK);
Controls.Add(buttonCancel);
Controls.Add(dateBoxWithNull);
Controls.Add(customComboBox);
Controls.Add(textBoxAutobiography);
Controls.Add(textBoxName);
Controls.Add(label4);
Controls.Add(label3);
Controls.Add(label2);
Controls.Add(label1);
Name = "FormWorker";
Text = "FormWorker";
FormClosing += FormWorker_FormClosing;
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label label1;
private Label label2;
private Label label3;
private Label label4;
private TextBox textBoxName;
private TextBox textBoxAutobiography;
private BarsukovComponents.VisualComponents.CustomComboBox customComboBox;
private KryukovLib.DateBoxWithNull dateBoxWithNull;
private Button buttonCancel;
private Button buttonOK;
}
}

View File

@ -0,0 +1,146 @@
using BusinessLogic;
using Contracts.BindingModels;
using Contracts.SearchModels;
using Contracts.BusinessLogicContracts;
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 TestApp
{
public partial class FormWorker : Form
{
private int? _id;
private IJobTypeLogic _jobTypeLogic;
private IWorkerLogic _workerLogic;
private bool _isEdited;
public FormWorker(IJobTypeLogic jobTypeLogic, IWorkerLogic workerLogic, int? id = null)
{
InitializeComponent();
_jobTypeLogic = jobTypeLogic;
_workerLogic = workerLogic;
_id = id;
LoadData();
}
private void LoadData()
{
var list = _jobTypeLogic.ReadList(null);
if (list != null)
{
foreach (var item in list)
{
customComboBox.ComboBoxItems.Add(item.Name);
}
}
if (_id.HasValue)
{
var item = _workerLogic.ReadElement(new WorkerSearchModel
{
Id = _id.Value,
});
textBoxName.Text = item.Name;
textBoxAutobiography.Text = item.Autobiography;
if (item.DateAdvance == "Повышения квалификации не было")
{
dateBoxWithNull.Value = null;
}
else
{
dateBoxWithNull.Value = DateTime.Parse(item.DateAdvance);
}
customComboBox.SelectedItem = item.JobType;
_isEdited = false;
}
}
private void OnInputChange(object sender, EventArgs e)
{
_isEdited = true;
}
private void buttonOK_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxName.Text))
{
MessageBox.Show("Заполните поле ФИО", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(textBoxAutobiography.Text))
{
MessageBox.Show("Заполните поле Автобиография", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(customComboBox.SelectedItem))
{
MessageBox.Show("Выберите должность", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
try
{
string? date = dateBoxWithNull.Value.ToString();
}
catch (Exception ex)
{
MessageBox.Show("Впишите дату в формате DD.MM.YYYY, либо поставте галочку (в случае, если повышения квалификации не было)", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_isEdited = false;
try
{
var model = new WorkerBindingModel
{
Id = _id ?? 0,
Name = textBoxName.Text,
Autobiography = textBoxAutobiography.Text,
JobType = customComboBox.SelectedItem,
DateAdvance = dateBoxWithNull.Value.ToString() == ""
? "Повышения квалификации не было"
: dateBoxWithNull.Value.ToString(),
};
bool result = _id.HasValue ? _workerLogic.Update(model) : _workerLogic.Create(model);
if (!result)
{
throw new Exception("Error while creating or updating worker");
}
MessageBox.Show("Сохранено", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void FormWorker_FormClosing(object sender, FormClosingEventArgs e)
{
if (!_isEdited)
{
return;
}
var confirmResult = MessageBox.Show(
"Вы не сохранили изменения.\nВы действительно хотите выйти?", "Подтвердите действие",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question
);
if (confirmResult == DialogResult.No)
{
e.Cancel = true;
}
}
private void buttonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

@ -0,0 +1,120 @@
<?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>

View File

@ -30,6 +30,7 @@ namespace TestApp
services.AddTransient<IWorkerStorage, WorkerStorage>(); services.AddTransient<IWorkerStorage, WorkerStorage>();
services.AddTransient<FormMain>(); services.AddTransient<FormMain>();
services.AddTransient<FormJobType>(); services.AddTransient<FormJobType>();
services.AddTransient<FormWorker>();
} }
} }
} }

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestApp
{
public class Transmit
{
public string Id { get; set; }
[DisplayName("ФИО")]
public string Name { get; set; } = string.Empty;
[DisplayName("Автобиография")]
public string Autobiography { get; set; } = string.Empty;
[DisplayName("Должность")]
public string JobType { get; set; } = string.Empty;
[DisplayName("Дата повышения квалификации")]
public string? DateAdvance { get; set; } = string.Empty;
}
}