From 8b6c4644c19320ed5914178523a4a7753e2dd9ce Mon Sep 17 00:00:00 2001 From: vasmaae Date: Mon, 25 Nov 2024 01:34:17 -0800 Subject: [PATCH] add REAL many-to-many relationship (come back) --- .../Entities/Service.cs | 7 +- .../Entities/ServiceContract.cs | 20 +++ .../FormItCompany.Designer.cs | 11 +- .../FormItCompany.cs | 12 ++ .../Forms/FormContract.Designer.cs | 5 +- .../Forms/FormContract.cs | 27 ++-- .../Forms/FormService.Designer.cs | 96 +++++++++++++ .../Forms/FormService.cs | 58 ++++++++ .../Forms/FormService.resx | 120 ++++++++++++++++ .../Forms/FormServices.Designer.cs | 130 ++++++++++++++++++ .../Forms/FormServices.cs | 96 +++++++++++++ .../Forms/FormServices.resx | 120 ++++++++++++++++ PIbd-23_Gutorov_I.A._IT-Company/Program.cs | 1 + .../Repositories/IServiceRepository.cs | 16 +++ .../Implementations/ServiceRepository.cs | 28 ++++ 15 files changed, 727 insertions(+), 20 deletions(-) create mode 100644 PIbd-23_Gutorov_I.A._IT-Company/Entities/ServiceContract.cs create mode 100644 PIbd-23_Gutorov_I.A._IT-Company/Forms/FormService.Designer.cs create mode 100644 PIbd-23_Gutorov_I.A._IT-Company/Forms/FormService.cs create mode 100644 PIbd-23_Gutorov_I.A._IT-Company/Forms/FormService.resx create mode 100644 PIbd-23_Gutorov_I.A._IT-Company/Forms/FormServices.Designer.cs create mode 100644 PIbd-23_Gutorov_I.A._IT-Company/Forms/FormServices.cs create mode 100644 PIbd-23_Gutorov_I.A._IT-Company/Forms/FormServices.resx create mode 100644 PIbd-23_Gutorov_I.A._IT-Company/Repositories/IServiceRepository.cs create mode 100644 PIbd-23_Gutorov_I.A._IT-Company/Repositories/Implementations/ServiceRepository.cs diff --git a/PIbd-23_Gutorov_I.A._IT-Company/Entities/Service.cs b/PIbd-23_Gutorov_I.A._IT-Company/Entities/Service.cs index 3b670c6..76ee123 100644 --- a/PIbd-23_Gutorov_I.A._IT-Company/Entities/Service.cs +++ b/PIbd-23_Gutorov_I.A._IT-Company/Entities/Service.cs @@ -6,15 +6,12 @@ public class Service public string Description { get; private set; } = string.Empty; - public int ContractId { get; private set; } - - public static Service CreateEntity(int id, string description, int contractId) + public static Service CreateEntity(int id, string description) { return new Service { Id = id, - Description = description, - ContractId = contractId + Description = description }; } } diff --git a/PIbd-23_Gutorov_I.A._IT-Company/Entities/ServiceContract.cs b/PIbd-23_Gutorov_I.A._IT-Company/Entities/ServiceContract.cs new file mode 100644 index 0000000..7edd1bd --- /dev/null +++ b/PIbd-23_Gutorov_I.A._IT-Company/Entities/ServiceContract.cs @@ -0,0 +1,20 @@ +namespace PIbd_23_Gutorov_I.A._IT_Company.Entities; + +public class ServiceContract +{ + public int Id { get; private set; } + + public int ServiceId { get; private set; } + + public int ContractId { get; private set; } + + public static ServiceContract CreateElement(int id, int serviceId, int contractId) + { + return new ServiceContract + { + Id = id, + ContractId = contractId, + ServiceId = serviceId + }; + } +} diff --git a/PIbd-23_Gutorov_I.A._IT-Company/FormItCompany.Designer.cs b/PIbd-23_Gutorov_I.A._IT-Company/FormItCompany.Designer.cs index 4aec222..ada79b9 100644 --- a/PIbd-23_Gutorov_I.A._IT-Company/FormItCompany.Designer.cs +++ b/PIbd-23_Gutorov_I.A._IT-Company/FormItCompany.Designer.cs @@ -32,6 +32,7 @@ справочникиToolStripMenuItem = new ToolStripMenuItem(); CustomersToolStripMenuItem = new ToolStripMenuItem(); ExecutorsToolStripMenuItem = new ToolStripMenuItem(); + ServicesToolStripMenuItem = new ToolStripMenuItem(); операцииToolStripMenuItem = new ToolStripMenuItem(); CustomerContractReviewsToolStripMenuItem = new ToolStripMenuItem(); контрактыToolStripMenuItem = new ToolStripMenuItem(); @@ -50,7 +51,7 @@ // // справочникиToolStripMenuItem // - справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { CustomersToolStripMenuItem, ExecutorsToolStripMenuItem }); + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { CustomersToolStripMenuItem, ExecutorsToolStripMenuItem, ServicesToolStripMenuItem }); справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; справочникиToolStripMenuItem.Size = new Size(94, 20); справочникиToolStripMenuItem.Text = "Справочники"; @@ -69,6 +70,13 @@ ExecutorsToolStripMenuItem.Text = "Исполнители"; ExecutorsToolStripMenuItem.Click += ExecutorsToolStripMenuItem_Click; // + // ServicesToolStripMenuItem + // + ServicesToolStripMenuItem.Name = "ServicesToolStripMenuItem"; + ServicesToolStripMenuItem.Size = new Size(180, 22); + ServicesToolStripMenuItem.Text = "Услуги"; + ServicesToolStripMenuItem.Click += ServicesToolStripMenuItem_Click; + // // операцииToolStripMenuItem // операцииToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { CustomerContractReviewsToolStripMenuItem, контрактыToolStripMenuItem }); @@ -124,5 +132,6 @@ private ToolStripMenuItem отчетыToolStripMenuItem; private ToolStripMenuItem CustomerContractReviewsToolStripMenuItem; private ToolStripMenuItem контрактыToolStripMenuItem; + private ToolStripMenuItem ServicesToolStripMenuItem; } } diff --git a/PIbd-23_Gutorov_I.A._IT-Company/FormItCompany.cs b/PIbd-23_Gutorov_I.A._IT-Company/FormItCompany.cs index 3035efc..795a495 100644 --- a/PIbd-23_Gutorov_I.A._IT-Company/FormItCompany.cs +++ b/PIbd-23_Gutorov_I.A._IT-Company/FormItCompany.cs @@ -60,5 +60,17 @@ namespace PIbd_23_Gutorov_I.A._IT_Company MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); } } + + private void ServicesToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } } } diff --git a/PIbd-23_Gutorov_I.A._IT-Company/Forms/FormContract.Designer.cs b/PIbd-23_Gutorov_I.A._IT-Company/Forms/FormContract.Designer.cs index 165e71c..d0fa481 100644 --- a/PIbd-23_Gutorov_I.A._IT-Company/Forms/FormContract.Designer.cs +++ b/PIbd-23_Gutorov_I.A._IT-Company/Forms/FormContract.Designer.cs @@ -42,7 +42,7 @@ labelContractPaymentAmount = new Label(); dataGridViewServices = new DataGridView(); groupBox = new GroupBox(); - ColumnServiceDescription = new DataGridViewTextBoxColumn(); + ColumnServiceDescription = new DataGridViewComboBoxColumn(); ((System.ComponentModel.ISupportInitialize)numericUpDownContractPaymentAmount).BeginInit(); ((System.ComponentModel.ISupportInitialize)dataGridViewServices).BeginInit(); groupBox.SuspendLayout(); @@ -189,6 +189,7 @@ ColumnServiceDescription.HeaderText = "Услуга"; ColumnServiceDescription.Name = "ColumnServiceDescription"; ColumnServiceDescription.Resizable = DataGridViewTriState.True; + ColumnServiceDescription.SortMode = DataGridViewColumnSortMode.Automatic; // // FormContract // @@ -234,6 +235,6 @@ private Label labelContractPaymentAmount; private DataGridView dataGridViewServices; private GroupBox groupBox; - private DataGridViewTextBoxColumn ColumnServiceDescription; + private DataGridViewComboBoxColumn ColumnServiceDescription; } } \ No newline at end of file diff --git a/PIbd-23_Gutorov_I.A._IT-Company/Forms/FormContract.cs b/PIbd-23_Gutorov_I.A._IT-Company/Forms/FormContract.cs index b2ceea6..6271a08 100644 --- a/PIbd-23_Gutorov_I.A._IT-Company/Forms/FormContract.cs +++ b/PIbd-23_Gutorov_I.A._IT-Company/Forms/FormContract.cs @@ -9,18 +9,22 @@ namespace PIbd_23_Gutorov_I.A._IT_Company.Forms private readonly IContractRepository _contractRepository; public FormContract(IContractRepository contractRepository, ICustomerRepository customerRepository, - IExecutorRepository executorRepository) + IExecutorRepository executorRepository, IServiceRepository serviceRepository) { InitializeComponent(); _contractRepository = contractRepository ?? throw new ArgumentNullException(nameof(contractRepository)); comboBoxContractCustomerId.DataSource = customerRepository.ReadCustomers(); comboBoxContractCustomerId.DisplayMember = "Name"; - comboBoxContractCustomerId.DisplayMember = "Id"; + comboBoxContractCustomerId.ValueMember = "Id"; comboBoxContractExecutorId.DataSource = executorRepository.ReadExecutors(); comboBoxContractExecutorId.DisplayMember = "Name"; - comboBoxContractExecutorId.DisplayMember = "Id"; + comboBoxContractExecutorId.ValueMember= "Id"; + + ColumnServiceDescription.DataSource = serviceRepository.ReadServices(); + ColumnServiceDescription.DisplayMember = "Description"; + ColumnServiceDescription.ValueMember = "Id"; foreach (var elem in Enum.GetValues(typeof(ContractCategory))) { @@ -59,22 +63,21 @@ namespace PIbd_23_Gutorov_I.A._IT_Company.Forms contractCategory |= (ContractCategory)elem; } - return Contract.CreateEntity(id, (int)comboBoxContractCustomerId.SelectedValue!, - (int)comboBoxContractExecutorId.SelectedValue!, contractCategory, - dateTimePickerContractDeadline.Value, Convert.ToInt32(numericUpDownContractPaymentAmount.Value), - CreateServicesFromDataGrid()); + return Contract.CreateEntity(id, (int)comboBoxContractCustomerId.SelectedValue!, + (int)comboBoxContractExecutorId.SelectedValue!, contractCategory, + dateTimePickerContractDeadline.Value, Convert.ToInt32(numericUpDownContractPaymentAmount.Value), + CreateListServicesFromDataGrid()); } - private List CreateServicesFromDataGrid() + private List CreateListServicesFromDataGrid() { var list = new List(); - + foreach (DataGridViewRow row in dataGridViewServices.Rows) - if (!row.IsNewRow) - list.Add(Service.CreateEntity(0, Convert.ToString(row.Cells["Description"].Value)!, 0)); + if (row.Cells["ColumnServiceDescription"].Value != null) + list.Add(Service.CreateEntity(0, Convert.ToString(row.Cells["ColumnServiceDescription"].Value)!)); return list; } - } } diff --git a/PIbd-23_Gutorov_I.A._IT-Company/Forms/FormService.Designer.cs b/PIbd-23_Gutorov_I.A._IT-Company/Forms/FormService.Designer.cs new file mode 100644 index 0000000..4112755 --- /dev/null +++ b/PIbd-23_Gutorov_I.A._IT-Company/Forms/FormService.Designer.cs @@ -0,0 +1,96 @@ +namespace PIbd_23_Gutorov_I.A._IT_Company.Forms +{ + partial class FormService + { + /// + /// 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() + { + labelServiceDescription = new Label(); + richTextBoxServiceDescription = new RichTextBox(); + buttonCancel = new Button(); + buttonSave = new Button(); + SuspendLayout(); + // + // labelServiceDescription + // + labelServiceDescription.AutoSize = true; + labelServiceDescription.Location = new Point(16, 15); + labelServiceDescription.Name = "labelServiceDescription"; + labelServiceDescription.Size = new Size(65, 15); + labelServiceDescription.TabIndex = 30; + labelServiceDescription.Text = "Описание:"; + // + // richTextBoxServiceDescription + // + richTextBoxServiceDescription.Location = new Point(173, 12); + richTextBoxServiceDescription.Name = "richTextBoxServiceDescription"; + richTextBoxServiceDescription.Size = new Size(202, 96); + richTextBoxServiceDescription.TabIndex = 29; + richTextBoxServiceDescription.Text = ""; + // + // buttonCancel + // + buttonCancel.Location = new Point(16, 143); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(359, 23); + buttonCancel.TabIndex = 32; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(16, 114); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(359, 23); + buttonSave.TabIndex = 31; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // FormService + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(387, 181); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(labelServiceDescription); + Controls.Add(richTextBoxServiceDescription); + Name = "FormService"; + StartPosition = FormStartPosition.CenterParent; + Text = "Услуга"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + private Label labelServiceDescription; + private RichTextBox richTextBoxServiceDescription; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/PIbd-23_Gutorov_I.A._IT-Company/Forms/FormService.cs b/PIbd-23_Gutorov_I.A._IT-Company/Forms/FormService.cs new file mode 100644 index 0000000..6831fd9 --- /dev/null +++ b/PIbd-23_Gutorov_I.A._IT-Company/Forms/FormService.cs @@ -0,0 +1,58 @@ +using PIbd_23_Gutorov_I.A._IT_Company.Entities; +using PIbd_23_Gutorov_I.A._IT_Company.Repositories; + +namespace PIbd_23_Gutorov_I.A._IT_Company.Forms +{ + public partial class FormService : Form + { + private readonly IServiceRepository _serviceRepository; + + private int? _serviceId; + + public int Id + { + set + { + try + { + var service = _serviceRepository.ReadServiceById(value); + if (service == null) throw new InvalidDataException(nameof(service)); + + richTextBoxServiceDescription.Text = service.Description; + _serviceId = value; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + } + + public FormService(IServiceRepository serviceRepository) + { + InitializeComponent(); + _serviceRepository = serviceRepository ?? throw new ArgumentNullException(nameof(serviceRepository)); + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrEmpty(richTextBoxServiceDescription.Text)) + throw new Exception("Имеются незаполненные поля"); + + _serviceRepository.CreateService(Service.CreateEntity(0, + richTextBoxServiceDescription.Text)); + + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + } +} \ No newline at end of file diff --git a/PIbd-23_Gutorov_I.A._IT-Company/Forms/FormService.resx b/PIbd-23_Gutorov_I.A._IT-Company/Forms/FormService.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/PIbd-23_Gutorov_I.A._IT-Company/Forms/FormService.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/PIbd-23_Gutorov_I.A._IT-Company/Forms/FormServices.Designer.cs b/PIbd-23_Gutorov_I.A._IT-Company/Forms/FormServices.Designer.cs new file mode 100644 index 0000000..1666c9a --- /dev/null +++ b/PIbd-23_Gutorov_I.A._IT-Company/Forms/FormServices.Designer.cs @@ -0,0 +1,130 @@ +using static System.Net.Mime.MediaTypeNames; +using System.Windows.Forms; +using System.Xml.Linq; + +namespace PIbd_23_Gutorov_I.A._IT_Company.Forms +{ + partial class FormServices + { + /// + /// 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() + { + dataGridViewData = new DataGridView(); + panel = new Panel(); + buttonDel = new Button(); + buttonUpd = new Button(); + buttonAdd = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit(); + panel.SuspendLayout(); + SuspendLayout(); + // + // dataGridViewData + // + dataGridViewData.AllowUserToAddRows = false; + dataGridViewData.AllowUserToDeleteRows = false; + dataGridViewData.AllowUserToResizeColumns = false; + dataGridViewData.AllowUserToResizeRows = false; + dataGridViewData.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewData.Dock = DockStyle.Fill; + dataGridViewData.Location = new Point(0, 0); + dataGridViewData.MultiSelect = false; + dataGridViewData.Name = "dataGridViewData"; + dataGridViewData.ReadOnly = true; + dataGridViewData.RowHeadersVisible = false; + dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewData.Size = new Size(677, 450); + dataGridViewData.TabIndex = 5; + // + // panel + // + panel.Controls.Add(buttonDel); + panel.Controls.Add(buttonUpd); + panel.Controls.Add(buttonAdd); + panel.Dock = DockStyle.Right; + panel.Location = new Point(677, 0); + panel.Name = "panel"; + panel.Size = new Size(123, 450); + panel.TabIndex = 4; + // + // buttonDel + // + buttonDel.BackgroundImage = Properties.Resources.icon_remove_button; + buttonDel.BackgroundImageLayout = ImageLayout.Stretch; + buttonDel.Location = new Point(16, 204); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(90, 90); + buttonDel.TabIndex = 2; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonUpd + // + buttonUpd.BackgroundImage = Properties.Resources.icon_edit_button; + buttonUpd.BackgroundImageLayout = ImageLayout.Stretch; + buttonUpd.Location = new Point(16, 108); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(90, 90); + buttonUpd.TabIndex = 1; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.icon_add_button; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(16, 12); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(90, 90); + buttonAdd.TabIndex = 0; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // FormServices + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridViewData); + Controls.Add(panel); + Name = "FormServices"; + StartPosition = FormStartPosition.CenterParent; + Text = "Услуги"; + Load += FormServices_Load; + ((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit(); + panel.ResumeLayout(false); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridViewData; + private Panel panel; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/PIbd-23_Gutorov_I.A._IT-Company/Forms/FormServices.cs b/PIbd-23_Gutorov_I.A._IT-Company/Forms/FormServices.cs new file mode 100644 index 0000000..60f8f62 --- /dev/null +++ b/PIbd-23_Gutorov_I.A._IT-Company/Forms/FormServices.cs @@ -0,0 +1,96 @@ +using PIbd_23_Gutorov_I.A._IT_Company.Repositories; +using Unity; + +namespace PIbd_23_Gutorov_I.A._IT_Company.Forms +{ + public partial class FormServices : Form + { + private readonly IUnityContainer _container; + + private readonly IServiceRepository _serviceRepository; + + public FormServices(IUnityContainer container, IServiceRepository serviceRepository) + { + InitializeComponent(); + _container = container ?? throw new ArgumentException(nameof(container)); + _serviceRepository = serviceRepository ?? throw new ArgumentException(nameof(serviceRepository)); + } + + private void FormServices_Load(object sender, EventArgs e) + { + try + { + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + return; + + try + { + var form = _container.Resolve(); + form.Id = findId; + form.ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + return; + + if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) + return; + + try + { + _serviceRepository.DeleteService(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadList() => dataGridViewData.DataSource = _serviceRepository.ReadServices(); + + private bool TryGetIdentifierFromSelectedRow(out int id) + { + id = 0; + if (dataGridViewData.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + + id = Convert.ToInt32(dataGridViewData.SelectedRows[0].Cells["Id"].Value); + return true; + } + } +} \ No newline at end of file diff --git a/PIbd-23_Gutorov_I.A._IT-Company/Forms/FormServices.resx b/PIbd-23_Gutorov_I.A._IT-Company/Forms/FormServices.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/PIbd-23_Gutorov_I.A._IT-Company/Forms/FormServices.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/PIbd-23_Gutorov_I.A._IT-Company/Program.cs b/PIbd-23_Gutorov_I.A._IT-Company/Program.cs index 7874b0a..3c5e10d 100644 --- a/PIbd-23_Gutorov_I.A._IT-Company/Program.cs +++ b/PIbd-23_Gutorov_I.A._IT-Company/Program.cs @@ -26,6 +26,7 @@ namespace PIbd_23_Gutorov_I.A._IT_Company container.RegisterType(); container.RegisterType(); container.RegisterType(); + container.RegisterType(); return container; } diff --git a/PIbd-23_Gutorov_I.A._IT-Company/Repositories/IServiceRepository.cs b/PIbd-23_Gutorov_I.A._IT-Company/Repositories/IServiceRepository.cs new file mode 100644 index 0000000..aa261c0 --- /dev/null +++ b/PIbd-23_Gutorov_I.A._IT-Company/Repositories/IServiceRepository.cs @@ -0,0 +1,16 @@ +using PIbd_23_Gutorov_I.A._IT_Company.Entities; + +namespace PIbd_23_Gutorov_I.A._IT_Company.Repositories; + +public interface IServiceRepository +{ + IEnumerable ReadServices(); + + Service ReadServiceById(int id); + + void CreateService(Service Service); + + void UpdateService(Service Service); + + void DeleteService(int id); +} \ No newline at end of file diff --git a/PIbd-23_Gutorov_I.A._IT-Company/Repositories/Implementations/ServiceRepository.cs b/PIbd-23_Gutorov_I.A._IT-Company/Repositories/Implementations/ServiceRepository.cs new file mode 100644 index 0000000..922a9fc --- /dev/null +++ b/PIbd-23_Gutorov_I.A._IT-Company/Repositories/Implementations/ServiceRepository.cs @@ -0,0 +1,28 @@ +using PIbd_23_Gutorov_I.A._IT_Company.Entities; + +namespace PIbd_23_Gutorov_I.A._IT_Company.Repositories.Implementations; + +internal class ServiceRepository : IServiceRepository +{ + public void CreateService(Service Service) + { + } + + public void DeleteService(int id) + { + } + + public Service ReadServiceById(int id) + { + return Service.CreateEntity(0, string.Empty); + } + + public IEnumerable ReadServices() + { + return []; + } + + public void UpdateService(Service Service) + { + } +} \ No newline at end of file