From 20a6b8ebcf4c9a3729f1ca16e1956cbf9e3f4367 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D0=B8=D0=BB=20=D0=9F=D1=83=D1=82?= =?UTF-8?q?=D0=B8=D0=BD=D1=86=D0=B5=D0=B2?= Date: Thu, 9 May 2024 12:24:52 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B2=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=87=D0=B0=D1=8F=20=D1=81=D1=83=D1=89=D0=BD=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Booking/Booking.sln | 37 ++++ .../BookingAbstractions.csproj | 9 + .../BookingAbstractions/Models/Publisher.cs | 13 ++ .../WorkAbstractions/IPublisherWork.cs | 17 ++ .../BookingPostgresImplementation.csproj | 17 ++ .../SqlConnection.cs | 12 ++ .../WorkImplementation/PublisherWork.cs | 80 ++++++++ Booking/BookingView/BookingView.csproj | 20 ++ Booking/BookingView/FormMain.Designer.cs | 99 +++++++++ Booking/BookingView/FormMain.cs | 22 ++ Booking/BookingView/FormMain.resx | 123 ++++++++++++ Booking/BookingView/FormPublisher.Designer.cs | 188 ++++++++++++++++++ Booking/BookingView/FormPublisher.cs | 114 +++++++++++ Booking/BookingView/FormPublisher.resx | 120 +++++++++++ Booking/BookingView/Program.cs | 32 +++ 15 files changed, 903 insertions(+) create mode 100644 Booking/Booking.sln create mode 100644 Booking/BookingAbstractions/BookingAbstractions.csproj create mode 100644 Booking/BookingAbstractions/Models/Publisher.cs create mode 100644 Booking/BookingAbstractions/WorkAbstractions/IPublisherWork.cs create mode 100644 Booking/BookingPostgresImplementation/BookingPostgresImplementation.csproj create mode 100644 Booking/BookingPostgresImplementation/SqlConnection.cs create mode 100644 Booking/BookingPostgresImplementation/WorkImplementation/PublisherWork.cs create mode 100644 Booking/BookingView/BookingView.csproj create mode 100644 Booking/BookingView/FormMain.Designer.cs create mode 100644 Booking/BookingView/FormMain.cs create mode 100644 Booking/BookingView/FormMain.resx create mode 100644 Booking/BookingView/FormPublisher.Designer.cs create mode 100644 Booking/BookingView/FormPublisher.cs create mode 100644 Booking/BookingView/FormPublisher.resx create mode 100644 Booking/BookingView/Program.cs diff --git a/Booking/Booking.sln b/Booking/Booking.sln new file mode 100644 index 0000000..ed4b1af --- /dev/null +++ b/Booking/Booking.sln @@ -0,0 +1,37 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34723.18 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BookingView", "BookingView\BookingView.csproj", "{6C4EAA44-E940-49A1-B8C7-EEE58666AA8A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BookingPostgresImplementation", "BookingPostgresImplementation\BookingPostgresImplementation.csproj", "{DD5E0B00-3CF3-45AB-93AC-69CD58CB2412}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BookingAbstractions", "BookingAbstractions\BookingAbstractions.csproj", "{289F8880-A75B-48B3-AB32-4B69A3EC357F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6C4EAA44-E940-49A1-B8C7-EEE58666AA8A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6C4EAA44-E940-49A1-B8C7-EEE58666AA8A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6C4EAA44-E940-49A1-B8C7-EEE58666AA8A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6C4EAA44-E940-49A1-B8C7-EEE58666AA8A}.Release|Any CPU.Build.0 = Release|Any CPU + {DD5E0B00-3CF3-45AB-93AC-69CD58CB2412}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DD5E0B00-3CF3-45AB-93AC-69CD58CB2412}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DD5E0B00-3CF3-45AB-93AC-69CD58CB2412}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DD5E0B00-3CF3-45AB-93AC-69CD58CB2412}.Release|Any CPU.Build.0 = Release|Any CPU + {289F8880-A75B-48B3-AB32-4B69A3EC357F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {289F8880-A75B-48B3-AB32-4B69A3EC357F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {289F8880-A75B-48B3-AB32-4B69A3EC357F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {289F8880-A75B-48B3-AB32-4B69A3EC357F}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {D558A4A7-0F2D-439F-97B4-44C7AAF40540} + EndGlobalSection +EndGlobal diff --git a/Booking/BookingAbstractions/BookingAbstractions.csproj b/Booking/BookingAbstractions/BookingAbstractions.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/Booking/BookingAbstractions/BookingAbstractions.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/Booking/BookingAbstractions/Models/Publisher.cs b/Booking/BookingAbstractions/Models/Publisher.cs new file mode 100644 index 0000000..06afa19 --- /dev/null +++ b/Booking/BookingAbstractions/Models/Publisher.cs @@ -0,0 +1,13 @@ +namespace BookingAbstractions.Models +{ + public class Publisher + { + public int Id { get; set; } + + public string Name { get; set; } = string.Empty; + + public string Address { get; set; } = string.Empty; + + public string PhoneNumber { get; set; } = string.Empty; + } +} diff --git a/Booking/BookingAbstractions/WorkAbstractions/IPublisherWork.cs b/Booking/BookingAbstractions/WorkAbstractions/IPublisherWork.cs new file mode 100644 index 0000000..94d976d --- /dev/null +++ b/Booking/BookingAbstractions/WorkAbstractions/IPublisherWork.cs @@ -0,0 +1,17 @@ +using BookingAbstractions.Models; + +namespace BookingAbstractions.WorkAbstractions +{ + public interface IPublisherWork + { + List GetAll(); + + Publisher? Get(int id); + + Publisher? Create(Publisher publisher); + + Publisher? Update(Publisher publisher); + + Publisher? Delete(int id); + } +} diff --git a/Booking/BookingPostgresImplementation/BookingPostgresImplementation.csproj b/Booking/BookingPostgresImplementation/BookingPostgresImplementation.csproj new file mode 100644 index 0000000..6394d55 --- /dev/null +++ b/Booking/BookingPostgresImplementation/BookingPostgresImplementation.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/Booking/BookingPostgresImplementation/SqlConnection.cs b/Booking/BookingPostgresImplementation/SqlConnection.cs new file mode 100644 index 0000000..096231f --- /dev/null +++ b/Booking/BookingPostgresImplementation/SqlConnection.cs @@ -0,0 +1,12 @@ +using Npgsql; + +namespace BookingPostgresImplementation +{ + public class SqlConnection + { + public static NpgsqlConnection GetConnection() + { + return new NpgsqlConnection("Host=localhost;Port=6456;Username=postgres;Database=SUBD;Password=dan"); + } + } +} diff --git a/Booking/BookingPostgresImplementation/WorkImplementation/PublisherWork.cs b/Booking/BookingPostgresImplementation/WorkImplementation/PublisherWork.cs new file mode 100644 index 0000000..dc2975d --- /dev/null +++ b/Booking/BookingPostgresImplementation/WorkImplementation/PublisherWork.cs @@ -0,0 +1,80 @@ +using BookingAbstractions.Models; +using BookingAbstractions.WorkAbstractions; +using Npgsql; + +namespace BookingPostgresImplementation.WorkImplementation +{ + public class PublisherWork : IPublisherWork + { + public List GetAll() + { + var publishers = new List(); + using var con = SqlConnection.GetConnection(); + con.Open(); + using var cmd = new NpgsqlCommand("SELECT * FROM publisher order by id", con); + using var reader = cmd.ExecuteReader(); + while (reader.Read()) + { + publishers.Add(new Publisher + { + Id = reader.GetInt32(0), + Name = reader.GetString(1), + Address = reader.GetString(2), + PhoneNumber = reader.GetString(3), + }); + } + return publishers; + } + + public Publisher? Get(int id) + { + using var con = SqlConnection.GetConnection(); + con.Open(); + using var cmd = new NpgsqlCommand($"SELECT * FROM publisher WHERE id = {id}", con); + using var reader = cmd.ExecuteReader(); + if (reader.Read()) + { + return new Publisher + { + Id = reader.GetInt32(0), + Name = reader.GetString(1), + Address = reader.GetString(2), + PhoneNumber = reader.GetString(3), + }; + } + return null; + } + + public Publisher? Create(Publisher publisher) + { + using var con = SqlConnection.GetConnection(); + con.Open(); + using var cmd = new NpgsqlCommand("INSERT INTO publisher (name, adress, phonenumber) VALUES (@Name, @Address, @PhoneNumber)", con); + cmd.Parameters.AddWithValue("@Name", publisher.Name); + cmd.Parameters.AddWithValue("@Address", publisher.Address); + cmd.Parameters.AddWithValue("@PhoneNumber", publisher.PhoneNumber); + cmd.ExecuteNonQuery(); + return publisher; + } + + public Publisher? Update(Publisher publisher) + { + using var con = SqlConnection.GetConnection(); + con.Open(); + using var cmd = new NpgsqlCommand($"UPDATE publisher SET name = {publisher.Name}, adress = {publisher.Address}, phonenumber = {publisher.PhoneNumber} WHERE id = {publisher.Id}", con); + cmd.ExecuteNonQuery(); + var element = Get(publisher.Id); + return element; + } + + public Publisher? Delete(int id) + { + var element = Get(id); + using var con = SqlConnection.GetConnection(); + con.Open(); + using var cmd = new NpgsqlCommand($"DELETE FROM publisher WHERE id = {id}", con); + cmd.ExecuteNonQuery(); + return element; + } + } +} diff --git a/Booking/BookingView/BookingView.csproj b/Booking/BookingView/BookingView.csproj new file mode 100644 index 0000000..635b4e7 --- /dev/null +++ b/Booking/BookingView/BookingView.csproj @@ -0,0 +1,20 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + + + + + + + + \ No newline at end of file diff --git a/Booking/BookingView/FormMain.Designer.cs b/Booking/BookingView/FormMain.Designer.cs new file mode 100644 index 0000000..93144e7 --- /dev/null +++ b/Booking/BookingView/FormMain.Designer.cs @@ -0,0 +1,99 @@ +namespace BookingView +{ + partial class FormMain + { + /// + /// 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() + { + menuStrip1 = new MenuStrip(); + справочникиToolStripMenuItem = new ToolStripMenuItem(); + замерВремениToolStripMenuItem = new ToolStripMenuItem(); + labelTest = new Label(); + издателиToolStripMenuItem = new ToolStripMenuItem(); + menuStrip1.SuspendLayout(); + SuspendLayout(); + // + // menuStrip1 + // + menuStrip1.ImageScalingSize = new Size(20, 20); + menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, замерВремениToolStripMenuItem }); + menuStrip1.Location = new Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Padding = new Padding(7, 3, 0, 3); + menuStrip1.Size = new Size(633, 30); + menuStrip1.TabIndex = 0; + menuStrip1.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { издателиToolStripMenuItem }); + справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + справочникиToolStripMenuItem.Size = new Size(117, 24); + справочникиToolStripMenuItem.Text = "Справочники"; + // + // labelTest + // + labelTest.BorderStyle = BorderStyle.FixedSingle; + labelTest.Location = new Point(178, 109); + labelTest.Name = "labelTest"; + labelTest.Size = new Size(285, 133); + labelTest.TabIndex = 3; + labelTest.TextAlign = ContentAlignment.MiddleCenter; + // + // издателиToolStripMenuItem + // + издателиToolStripMenuItem.Name = "издателиToolStripMenuItem"; + издателиToolStripMenuItem.Size = new Size(224, 26); + издателиToolStripMenuItem.Text = "Издатели"; + издателиToolStripMenuItem.Click += издателиToolStripMenuItem_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(633, 348); + Controls.Add(labelTest); + Controls.Add(menuStrip1); + MainMenuStrip = menuStrip1; + Margin = new Padding(3, 4, 3, 4); + Name = "FormMain"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Электронный дневник"; + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private MenuStrip menuStrip1; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem замерВремениToolStripMenuItem; + private Label labelTest; + private ToolStripMenuItem издателиToolStripMenuItem; + } +} \ No newline at end of file diff --git a/Booking/BookingView/FormMain.cs b/Booking/BookingView/FormMain.cs new file mode 100644 index 0000000..686341e --- /dev/null +++ b/Booking/BookingView/FormMain.cs @@ -0,0 +1,22 @@ +using BookingAbstractions.WorkAbstractions; + +namespace BookingView +{ + public partial class FormMain : Form + { + + public FormMain() + { + InitializeComponent(); + } + + private void издателиToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPublisher)); + if (service is FormPublisher form) + { + form.ShowDialog(); + } + } + } +} diff --git a/Booking/BookingView/FormMain.resx b/Booking/BookingView/FormMain.resx new file mode 100644 index 0000000..a0623c8 --- /dev/null +++ b/Booking/BookingView/FormMain.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 17, 17 + + \ No newline at end of file diff --git a/Booking/BookingView/FormPublisher.Designer.cs b/Booking/BookingView/FormPublisher.Designer.cs new file mode 100644 index 0000000..9f6c024 --- /dev/null +++ b/Booking/BookingView/FormPublisher.Designer.cs @@ -0,0 +1,188 @@ +namespace BookingView +{ + partial class FormPublisher + { + /// + /// 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() + { + buttonDelete = new Button(); + buttonUpdate = new Button(); + buttonCreate = new Button(); + dataGridView = new DataGridView(); + textBoxPublisherName = new TextBox(); + label1 = new Label(); + textBoxPublisherNumber = new TextBox(); + label2 = new Label(); + textBoxPublisherAddress = new TextBox(); + label3 = new Label(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // buttonDelete + // + buttonDelete.Location = new Point(730, 547); + buttonDelete.Margin = new Padding(3, 4, 3, 4); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(146, 40); + buttonDelete.TabIndex = 28; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += ButtonDelete_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(730, 481); + buttonUpdate.Margin = new Padding(3, 4, 3, 4); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(146, 40); + buttonUpdate.TabIndex = 27; + buttonUpdate.Text = "Изменить"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += ButtonUpdate_Click; + // + // buttonCreate + // + buttonCreate.Location = new Point(730, 416); + buttonCreate.Margin = new Padding(3, 4, 3, 4); + buttonCreate.Name = "buttonCreate"; + buttonCreate.Size = new Size(146, 40); + buttonCreate.TabIndex = 26; + buttonCreate.Text = "Добавить"; + buttonCreate.UseVisualStyleBackColor = true; + buttonCreate.Click += ButtonCreate_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.BackgroundColor = SystemColors.Window; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(15, 19); + dataGridView.Margin = new Padding(3, 4, 3, 4); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 25; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(477, 568); + dataGridView.TabIndex = 15; + dataGridView.CellClick += DataGridView_CellClick; + // + // textBoxPublisherName + // + textBoxPublisherName.Location = new Point(670, 29); + textBoxPublisherName.Margin = new Padding(3, 4, 3, 4); + textBoxPublisherName.Name = "textBoxPublisherName"; + textBoxPublisherName.Size = new Size(206, 27); + textBoxPublisherName.TabIndex = 38; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(552, 32); + label1.Name = "label1"; + label1.Size = new Size(80, 20); + label1.TabIndex = 37; + label1.Text = "Название:"; + // + // textBoxPublisherNumber + // + textBoxPublisherNumber.Location = new Point(670, 130); + textBoxPublisherNumber.Margin = new Padding(3, 4, 3, 4); + textBoxPublisherNumber.Name = "textBoxPublisherNumber"; + textBoxPublisherNumber.Size = new Size(206, 27); + textBoxPublisherNumber.TabIndex = 40; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(552, 133); + label2.Name = "label2"; + label2.Size = new Size(60, 20); + label2.TabIndex = 39; + label2.Text = "Номер:"; + // + // textBoxPublisherAddress + // + textBoxPublisherAddress.Location = new Point(670, 78); + textBoxPublisherAddress.Margin = new Padding(3, 4, 3, 4); + textBoxPublisherAddress.Name = "textBoxPublisherAddress"; + textBoxPublisherAddress.Size = new Size(206, 27); + textBoxPublisherAddress.TabIndex = 42; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(552, 81); + label3.Name = "label3"; + label3.Size = new Size(61, 20); + label3.TabIndex = 41; + label3.Text = "Адресс:"; + // + // FormPublisher + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(914, 600); + Controls.Add(textBoxPublisherAddress); + Controls.Add(label3); + Controls.Add(textBoxPublisherNumber); + Controls.Add(label2); + Controls.Add(textBoxPublisherName); + Controls.Add(label1); + Controls.Add(buttonDelete); + Controls.Add(buttonUpdate); + Controls.Add(buttonCreate); + Controls.Add(dataGridView); + Margin = new Padding(3, 4, 3, 4); + Name = "FormPublisher"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Издатели"; + Load += FormPublisher_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button buttonDelete; + private Button buttonUpdate; + private Button buttonCreate; + private ComboBox comboBoxBodyType; + private TextBox textBoxSeats; + private TextBox textBoxYear; + private TextBox textBoxModel; + private Label label5; + private DataGridView dataGridView; + private TextBox textBoxPublisherName; + private Label label1; + private TextBox textBoxPublisherNumber; + private Label label2; + private TextBox textBoxPublisherAddress; + private Label label3; + } +} \ No newline at end of file diff --git a/Booking/BookingView/FormPublisher.cs b/Booking/BookingView/FormPublisher.cs new file mode 100644 index 0000000..44b6450 --- /dev/null +++ b/Booking/BookingView/FormPublisher.cs @@ -0,0 +1,114 @@ +using BookingAbstractions.Models; +using BookingAbstractions.WorkAbstractions; +using System.Windows.Forms; + +namespace BookingView +{ + public partial class FormPublisher : Form + { + private readonly IPublisherWork _logic; + + public FormPublisher(IPublisherWork logic) + { + InitializeComponent(); + _logic = logic; + } + + private void FormPublisher_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + var publishers = _logic.GetAll(); + + dataGridView.Rows.Clear(); + + if (dataGridView.ColumnCount == 0) + { + dataGridView.Columns.Add("Id", "ID"); + dataGridView.Columns.Add("Name", "Название"); + dataGridView.Columns.Add("Address", "Адрес"); + dataGridView.Columns.Add("PhoneNumber", "Номер"); + } + + dataGridView.Columns["Id"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Address"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["PhoneNumber"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + + foreach (var publisher in publishers) + { + dataGridView.Rows.Add(publisher.Id, publisher.Name, publisher.Address, publisher.PhoneNumber); + } + } + + private void ButtonCreate_Click(object sender, EventArgs e) + { + Publisher newPublisher = new() + { + Name = textBoxPublisherName.Text, + Address = textBoxPublisherAddress.Text, + PhoneNumber = textBoxPublisherNumber.Text, + }; + + _logic.Create(newPublisher); + + LoadData(); + } + + private void ButtonUpdate_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count > 0) + { + DataGridViewRow selectedRow = dataGridView.SelectedRows[0]; + int publisherd = Convert.ToInt32(selectedRow.Cells["Id"].Value); + + Publisher updatedPublisher = new() + { + Id = publisherd, + Name = textBoxPublisherName.Text, + Address = textBoxPublisherAddress.Text, + PhoneNumber = textBoxPublisherNumber.Text, + }; + + _logic.Update(updatedPublisher); + + LoadData(); + } + else + { + MessageBox.Show("Пожалуйста, выберите издательство, которое необходимо обновить"); + } + } + + private void ButtonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count > 0) + { + DataGridViewRow selectedRow = dataGridView.SelectedRows[0]; + int publisherId = Convert.ToInt32(selectedRow.Cells["Id"].Value); + + _logic.Delete(publisherId); + + LoadData(); + } + else + { + MessageBox.Show("Пожалуйста, выберите издательство, которое необходимо удалить"); + } + } + + private void DataGridView_CellClick(object sender, DataGridViewCellEventArgs e) + { + if (e.RowIndex >= 0) + { + DataGridViewRow row = dataGridView.Rows[e.RowIndex]; + textBoxPublisherName.Text = row.Cells["Name"].Value.ToString(); + textBoxPublisherAddress.Text = row.Cells["Address"].Value.ToString(); + textBoxPublisherNumber.Text = row.Cells["PhoneNumber"].Value.ToString(); + } + } + } +} diff --git a/Booking/BookingView/FormPublisher.resx b/Booking/BookingView/FormPublisher.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Booking/BookingView/FormPublisher.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/Booking/BookingView/Program.cs b/Booking/BookingView/Program.cs new file mode 100644 index 0000000..b0d1a01 --- /dev/null +++ b/Booking/BookingView/Program.cs @@ -0,0 +1,32 @@ +using BookingAbstractions.WorkAbstractions; +using BookingPostgresImplementation.WorkImplementation; +using Microsoft.Extensions.DependencyInjection; + +namespace BookingView +{ + internal static class Program + { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + var services = new ServiceCollection(); + ConfigureServices(services); + _serviceProvider = services.BuildServiceProvider(); + Application.Run(_serviceProvider.GetRequiredService()); + } + private static void ConfigureServices(ServiceCollection services) + { + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + } + } +} \ No newline at end of file