From a204cc5e69a23cdf64343a3fca87d6d68f8fe2a8 Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Mon, 26 Feb 2024 00:26:47 +0400 Subject: [PATCH] =?UTF-8?q?=D0=92=D1=81=D0=B5=20=D1=80=D0=B5=D0=B0=D0=BB?= =?UTF-8?q?=D0=B8=D0=B7=D0=BE=D0=B2=D0=B0=D0=BD=D0=BE,=20=D0=BD=D0=BE=20?= =?UTF-8?q?=D0=B5=D1=81=D1=82=D1=8C=20=D0=B1=D0=B0=D0=B3:=20=D0=BD=D0=B5?= =?UTF-8?q?=20=D1=81=D0=BE=D1=85=D1=80=D0=B0=D0=BD=D1=8F=D1=8E=D1=82=D1=81?= =?UTF-8?q?=D1=8F=20=D0=B8=D0=B7=D0=B4=D0=B5=D0=BB=D0=B8=D1=8F=20=D0=B8=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BC=D0=BF=D0=BE=D0=BD=D0=B5=D0=BD=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormComponents.Designer.cs | 18 ++- .../SecuritySystemView/FormMain.Designer.cs | 28 ++-- .../FormSecures.Designer.cs | 120 ++++++++++++++++++ .../SecuritySystemView/FormSecures.cs | 97 ++++++++++++++ .../SecuritySystemView/FormSecures.resx | 120 ++++++++++++++++++ SecuritySystem/SecuritySystemView/Program.cs | 2 +- 6 files changed, 364 insertions(+), 21 deletions(-) create mode 100644 SecuritySystem/SecuritySystemView/FormSecures.Designer.cs create mode 100644 SecuritySystem/SecuritySystemView/FormSecures.cs create mode 100644 SecuritySystem/SecuritySystemView/FormSecures.resx diff --git a/SecuritySystem/SecuritySystemView/FormComponents.Designer.cs b/SecuritySystem/SecuritySystemView/FormComponents.Designer.cs index be34d06..bab7e50 100644 --- a/SecuritySystem/SecuritySystemView/FormComponents.Designer.cs +++ b/SecuritySystem/SecuritySystemView/FormComponents.Designer.cs @@ -38,8 +38,8 @@ // // dataGridViewComponents // + dataGridViewComponents.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; dataGridViewComponents.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridViewComponents.Dock = DockStyle.Left; dataGridViewComponents.Location = new Point(0, 0); dataGridViewComponents.MultiSelect = false; dataGridViewComponents.Name = "dataGridViewComponents"; @@ -48,12 +48,13 @@ dataGridViewComponents.RowHeadersWidth = 51; dataGridViewComponents.RowTemplate.Height = 29; dataGridViewComponents.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridViewComponents.Size = new Size(539, 450); + dataGridViewComponents.Size = new Size(637, 450); dataGridViewComponents.TabIndex = 0; // // buttonAddComponent // - buttonAddComponent.Location = new Point(562, 23); + buttonAddComponent.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonAddComponent.Location = new Point(660, 23); buttonAddComponent.Name = "buttonAddComponent"; buttonAddComponent.Size = new Size(94, 29); buttonAddComponent.TabIndex = 1; @@ -63,7 +64,8 @@ // // buttonEditComponent // - buttonEditComponent.Location = new Point(562, 75); + buttonEditComponent.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonEditComponent.Location = new Point(660, 75); buttonEditComponent.Name = "buttonEditComponent"; buttonEditComponent.Size = new Size(94, 29); buttonEditComponent.TabIndex = 2; @@ -73,7 +75,8 @@ // // buttonDeleteComponent // - buttonDeleteComponent.Location = new Point(562, 125); + buttonDeleteComponent.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonDeleteComponent.Location = new Point(660, 125); buttonDeleteComponent.Name = "buttonDeleteComponent"; buttonDeleteComponent.Size = new Size(94, 29); buttonDeleteComponent.TabIndex = 3; @@ -83,7 +86,8 @@ // // buttonRefreshComponents // - buttonRefreshComponents.Location = new Point(562, 173); + buttonRefreshComponents.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonRefreshComponents.Location = new Point(660, 173); buttonRefreshComponents.Name = "buttonRefreshComponents"; buttonRefreshComponents.Size = new Size(94, 29); buttonRefreshComponents.TabIndex = 4; @@ -95,7 +99,7 @@ // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(684, 450); + ClientSize = new Size(775, 450); Controls.Add(buttonRefreshComponents); Controls.Add(buttonDeleteComponent); Controls.Add(buttonEditComponent); diff --git a/SecuritySystem/SecuritySystemView/FormMain.Designer.cs b/SecuritySystem/SecuritySystemView/FormMain.Designer.cs index a899111..9d83640 100644 --- a/SecuritySystem/SecuritySystemView/FormMain.Designer.cs +++ b/SecuritySystem/SecuritySystemView/FormMain.Designer.cs @@ -30,8 +30,8 @@ { menuStrip = new MenuStrip(); справочникиToolStripMenuItem = new ToolStripMenuItem(); - компонентыToolStripMenuItem = new ToolStripMenuItem(); - изделияToolStripMenuItem = new ToolStripMenuItem(); + ComponentsToolStripMenuItem = new ToolStripMenuItem(); + SecuresToolStripMenuItem = new ToolStripMenuItem(); dataGridView = new DataGridView(); buttonCreateOrder = new Button(); buttonTakeOrderInWork = new Button(); @@ -54,22 +54,24 @@ // // справочникиToolStripMenuItem // - справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделияToolStripMenuItem }); + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ComponentsToolStripMenuItem, SecuresToolStripMenuItem }); справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; справочникиToolStripMenuItem.Size = new Size(117, 24); справочникиToolStripMenuItem.Text = "Справочники"; // - // компонентыToolStripMenuItem + // ComponentsToolStripMenuItem // - компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - компонентыToolStripMenuItem.Size = new Size(182, 26); - компонентыToolStripMenuItem.Text = "Компоненты"; + ComponentsToolStripMenuItem.Name = "ComponentsToolStripMenuItem"; + ComponentsToolStripMenuItem.Size = new Size(224, 26); + ComponentsToolStripMenuItem.Text = "Компоненты"; + ComponentsToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click; // - // изделияToolStripMenuItem + // SecuresToolStripMenuItem // - изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; - изделияToolStripMenuItem.Size = new Size(182, 26); - изделияToolStripMenuItem.Text = "Изделия"; + SecuresToolStripMenuItem.Name = "SecuresToolStripMenuItem"; + SecuresToolStripMenuItem.Size = new Size(224, 26); + SecuresToolStripMenuItem.Text = "Изделия"; + SecuresToolStripMenuItem.Click += SecuresToolStripMenuItem_Click; // // dataGridView // @@ -163,8 +165,8 @@ private MenuStrip menuStrip; private ToolStripMenuItem справочникиToolStripMenuItem; - private ToolStripMenuItem компонентыToolStripMenuItem; - private ToolStripMenuItem изделияToolStripMenuItem; + private ToolStripMenuItem ComponentsToolStripMenuItem; + private ToolStripMenuItem SecuresToolStripMenuItem; private DataGridView dataGridView; private Button buttonCreateOrder; private Button buttonTakeOrderInWork; diff --git a/SecuritySystem/SecuritySystemView/FormSecures.Designer.cs b/SecuritySystem/SecuritySystemView/FormSecures.Designer.cs new file mode 100644 index 0000000..5aee437 --- /dev/null +++ b/SecuritySystem/SecuritySystemView/FormSecures.Designer.cs @@ -0,0 +1,120 @@ +namespace SecuritySystemView +{ + partial class FormSecures + { + /// + /// 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() + { + dataGridView = new DataGridView(); + buttonRefresh = new Button(); + buttonDelete = new Button(); + buttonEdit = new Button(); + buttonAdd = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(3, 3); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(705, 296); + dataGridView.TabIndex = 0; + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonRefresh.Location = new Point(739, 162); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(94, 29); + buttonRefresh.TabIndex = 8; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRefreshSecures_Click; + // + // buttonDelete + // + buttonDelete.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonDelete.Location = new Point(739, 114); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(94, 29); + buttonDelete.TabIndex = 7; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += ButtonDeleteSecure_Click; + // + // buttonEdit + // + buttonEdit.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonEdit.Location = new Point(739, 64); + buttonEdit.Name = "buttonEdit"; + buttonEdit.Size = new Size(94, 29); + buttonEdit.TabIndex = 6; + buttonEdit.Text = "Изменить"; + buttonEdit.UseVisualStyleBackColor = true; + buttonEdit.Click += ButtonEditSecure_Click; + // + // buttonAdd + // + buttonAdd.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonAdd.Location = new Point(739, 12); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(94, 29); + buttonAdd.TabIndex = 5; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAddSecure_Click; + // + // FormSecures + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(853, 311); + Controls.Add(buttonRefresh); + Controls.Add(buttonDelete); + Controls.Add(buttonEdit); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormSecures"; + Text = "Иделия"; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonRefresh; + private Button buttonDelete; + private Button buttonEdit; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/FormSecures.cs b/SecuritySystem/SecuritySystemView/FormSecures.cs new file mode 100644 index 0000000..23313f4 --- /dev/null +++ b/SecuritySystem/SecuritySystemView/FormSecures.cs @@ -0,0 +1,97 @@ +using Microsoft.Extensions.Logging; +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.BusinessLogicsContracts; + +namespace SecuritySystemView +{ + public partial class FormSecures : Form + { + private readonly ILogger _logger; + private readonly ISecureLogic _logic; + public FormSecures(ILogger logger, ISecureLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormSecures_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["SecureName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка изделий"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделий"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void ButtonAddSecure_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSecure)); + if (service is FormSecure form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ButtonEditSecure_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSecure)); + if (service is FormSecure form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void ButtonDeleteSecure_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление изделия"); + try + { + if (!_logic.Delete(new SecureBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления изделия"); + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void ButtonRefreshSecures_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/SecuritySystem/SecuritySystemView/FormSecures.resx b/SecuritySystem/SecuritySystemView/FormSecures.resx new file mode 100644 index 0000000..a395bff --- /dev/null +++ b/SecuritySystem/SecuritySystemView/FormSecures.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/SecuritySystem/SecuritySystemView/Program.cs b/SecuritySystem/SecuritySystemView/Program.cs index 9621dd6..e5fad2f 100644 --- a/SecuritySystem/SecuritySystemView/Program.cs +++ b/SecuritySystem/SecuritySystemView/Program.cs @@ -45,7 +45,7 @@ namespace SecuritySystemView services.AddTransient(); services.AddTransient(); services.AddTransient(); - //services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file