Создана первая рабочая сущность

This commit is contained in:
Даниил Путинцев 2024-05-09 12:24:52 +04:00
parent 9240309c4c
commit 20a6b8ebcf
15 changed files with 903 additions and 0 deletions

37
Booking/Booking.sln Normal file
View File

@ -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

View File

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@ -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;
}
}

View File

@ -0,0 +1,17 @@
using BookingAbstractions.Models;
namespace BookingAbstractions.WorkAbstractions
{
public interface IPublisherWork
{
List<Publisher> GetAll();
Publisher? Get(int id);
Publisher? Create(Publisher publisher);
Publisher? Update(Publisher publisher);
Publisher? Delete(int id);
}
}

View File

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Npgsql" Version="8.0.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BookingAbstractions\BookingAbstractions.csproj" />
</ItemGroup>
</Project>

View File

@ -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");
}
}
}

View File

@ -0,0 +1,80 @@
using BookingAbstractions.Models;
using BookingAbstractions.WorkAbstractions;
using Npgsql;
namespace BookingPostgresImplementation.WorkImplementation
{
public class PublisherWork : IPublisherWork
{
public List<Publisher> GetAll()
{
var publishers = new List<Publisher>();
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;
}
}
}

View File

@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BookingAbstractions\BookingAbstractions.csproj" />
<ProjectReference Include="..\BookingPostgresImplementation\BookingPostgresImplementation.csproj" />
</ItemGroup>
</Project>

99
Booking/BookingView/FormMain.Designer.cs generated Normal file
View File

@ -0,0 +1,99 @@
namespace BookingView
{
partial class FormMain
{
/// <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()
{
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;
}
}

View File

@ -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();
}
}
}
}

View File

@ -0,0 +1,123 @@
<?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>
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -0,0 +1,188 @@
namespace BookingView
{
partial class FormPublisher
{
/// <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()
{
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;
}
}

View File

@ -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();
}
}
}
}

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

@ -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;
/// <summary>
/// The main entry point for the application.
/// </summary>
[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<FormMain>());
}
private static void ConfigureServices(ServiceCollection services)
{
services.AddTransient<IPublisherWork, PublisherWork>();
services.AddTransient<FormMain>();
services.AddTransient<FormPublisher>();
}
}
}