From c98c740959db87f44c80b3ee573ce1cde5028ac1 Mon Sep 17 00:00:00 2001 From: frog24 Date: Tue, 12 Nov 2024 17:41:57 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BE=D1=81=D1=82=D0=B0=D0=BB=D0=B8=D1=81?= =?UTF-8?q?=D1=8C=20=D1=85=D0=BE=D1=82=D0=BA=D0=B5=D0=B8=20=D0=B8=20=D0=BE?= =?UTF-8?q?=D1=82=D1=87=D0=B5=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CustomComboBox/BusinessLogic/WorkerLogic.cs | 2 +- CustomComboBox/TestApp/FormMain.Designer.cs | 18 +- CustomComboBox/TestApp/FormMain.cs | 54 +++++- CustomComboBox/TestApp/FormWorker.Designer.cs | 174 ++++++++++++++++++ CustomComboBox/TestApp/FormWorker.cs | 146 +++++++++++++++ CustomComboBox/TestApp/FormWorker.resx | 120 ++++++++++++ CustomComboBox/TestApp/Program.cs | 1 + CustomComboBox/TestApp/Transmit.cs | 22 +++ 8 files changed, 533 insertions(+), 4 deletions(-) create mode 100644 CustomComboBox/TestApp/FormWorker.Designer.cs create mode 100644 CustomComboBox/TestApp/FormWorker.cs create mode 100644 CustomComboBox/TestApp/FormWorker.resx create mode 100644 CustomComboBox/TestApp/Transmit.cs diff --git a/CustomComboBox/BusinessLogic/WorkerLogic.cs b/CustomComboBox/BusinessLogic/WorkerLogic.cs index 782663a..72b12ab 100644 --- a/CustomComboBox/BusinessLogic/WorkerLogic.cs +++ b/CustomComboBox/BusinessLogic/WorkerLogic.cs @@ -63,7 +63,7 @@ namespace BusinessLogic } public bool Delete(WorkerBindingModel model) { - CheckModel(model); + CheckModel(model, false); if (_workerStorage.Delete(model) == null) { return false; diff --git a/CustomComboBox/TestApp/FormMain.Designer.cs b/CustomComboBox/TestApp/FormMain.Designer.cs index 2170db3..c47289f 100644 --- a/CustomComboBox/TestApp/FormMain.Designer.cs +++ b/CustomComboBox/TestApp/FormMain.Designer.cs @@ -37,6 +37,7 @@ pdfToolStripMenuItem = new ToolStripMenuItem(); excelToolStripMenuItem = new ToolStripMenuItem(); wordToolStripMenuItem = new ToolStripMenuItem(); + customTreeView = new BelianinComponents.CustomTreeView(); menuStrip1.SuspendLayout(); SuspendLayout(); // @@ -46,7 +47,7 @@ menuStrip1.Items.AddRange(new ToolStripItem[] { menuToolStripMenuItem }); menuStrip1.Location = new Point(0, 0); menuStrip1.Name = "menuStrip1"; - menuStrip1.Size = new Size(800, 28); + menuStrip1.Size = new Size(550, 28); menuStrip1.TabIndex = 1; menuStrip1.Text = "menuStrip1"; // @@ -69,18 +70,21 @@ addWorkerToolStripMenuItem.Name = "addWorkerToolStripMenuItem"; addWorkerToolStripMenuItem.Size = new Size(224, 26); addWorkerToolStripMenuItem.Text = "add worker"; + addWorkerToolStripMenuItem.Click += addWorkerToolStripMenuItem_Click; // // editWorkerToolStripMenuItem // editWorkerToolStripMenuItem.Name = "editWorkerToolStripMenuItem"; editWorkerToolStripMenuItem.Size = new Size(224, 26); editWorkerToolStripMenuItem.Text = "edit worker"; + editWorkerToolStripMenuItem.Click += editWorkerToolStripMenuItem_Click; // // deleteWorkerToolStripMenuItem // deleteWorkerToolStripMenuItem.Name = "deleteWorkerToolStripMenuItem"; deleteWorkerToolStripMenuItem.Size = new Size(224, 26); deleteWorkerToolStripMenuItem.Text = "delete worker"; + deleteWorkerToolStripMenuItem.Click += deleteWorkerToolStripMenuItem_Click; // // pdfToolStripMenuItem // @@ -100,11 +104,20 @@ wordToolStripMenuItem.Size = new Size(224, 26); 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 // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 450); + ClientSize = new Size(550, 312); + Controls.Add(customTreeView); Controls.Add(menuStrip1); MainMenuStrip = menuStrip1; Name = "FormMain"; @@ -125,5 +138,6 @@ private ToolStripMenuItem pdfToolStripMenuItem; private ToolStripMenuItem excelToolStripMenuItem; private ToolStripMenuItem wordToolStripMenuItem; + private BelianinComponents.CustomTreeView customTreeView; } } \ No newline at end of file diff --git a/CustomComboBox/TestApp/FormMain.cs b/CustomComboBox/TestApp/FormMain.cs index 502a2b6..35c80f6 100644 --- a/CustomComboBox/TestApp/FormMain.cs +++ b/CustomComboBox/TestApp/FormMain.cs @@ -1,4 +1,6 @@ using Contracts.BusinessLogicContracts; +using Contracts.BindingModels; +using Contracts.ViewModels; using System; using System.Collections.Generic; using System.ComponentModel; @@ -20,7 +22,20 @@ namespace TestApp InitializeComponent(); _workerLogic = workerLogic; _jobTypeLogic = jobTypeLogic; - + LoadData(); + } + private void LoadData() + { + var list = _workerLogic.ReadList(null); + if (list != null) + { + customTreeView.Clear(); + customTreeView.hierarchy = new List { "JobType", "DateAdvance", "Id", "Name" }; + foreach (var item in list) + { + customTreeView.AddNode(item, "Name"); + } + } } private void jobTypesToolStripMenuItem_Click(object sender, EventArgs e) @@ -31,5 +46,42 @@ namespace TestApp 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(); + + 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(); + if (confirmResult == DialogResult.Yes) + { + _workerLogic.Delete(new WorkerBindingModel + { + Id = Convert.ToInt32(item.Id) + }); + LoadData(); + } + } } } diff --git a/CustomComboBox/TestApp/FormWorker.Designer.cs b/CustomComboBox/TestApp/FormWorker.Designer.cs new file mode 100644 index 0000000..0dbd02e --- /dev/null +++ b/CustomComboBox/TestApp/FormWorker.Designer.cs @@ -0,0 +1,174 @@ +namespace TestApp +{ + partial class FormWorker + { + /// + /// 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() + { + 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; + } +} \ No newline at end of file diff --git a/CustomComboBox/TestApp/FormWorker.cs b/CustomComboBox/TestApp/FormWorker.cs new file mode 100644 index 0000000..77e1f1f --- /dev/null +++ b/CustomComboBox/TestApp/FormWorker.cs @@ -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(); + } + } +} diff --git a/CustomComboBox/TestApp/FormWorker.resx b/CustomComboBox/TestApp/FormWorker.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/CustomComboBox/TestApp/FormWorker.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/CustomComboBox/TestApp/Program.cs b/CustomComboBox/TestApp/Program.cs index 390168f..5831017 100644 --- a/CustomComboBox/TestApp/Program.cs +++ b/CustomComboBox/TestApp/Program.cs @@ -30,6 +30,7 @@ namespace TestApp services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/CustomComboBox/TestApp/Transmit.cs b/CustomComboBox/TestApp/Transmit.cs new file mode 100644 index 0000000..22c6110 --- /dev/null +++ b/CustomComboBox/TestApp/Transmit.cs @@ -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; + } +}