This commit is contained in:
mar-va 2024-12-17 22:50:36 +04:00
parent ff4579d373
commit 3d7f0ac061
11 changed files with 82 additions and 31 deletions

View File

@ -80,6 +80,6 @@ namespace ProjectItCompany.Forms
private void ButtonCancel_Click(object sender, EventArgs e) => Close(); private void ButtonCancel_Click(object sender, EventArgs e) => Close();
private Executor CreateExecutor(int id) => Executor.CreateEntity(id, textBoxFullName.Text, dateTimePickerDateOfBirth.Value, numericUpDownHourlyRate.Value, Entities.Enums.JobTitles.Analyst); private Executor CreateExecutor(int id) => Executor.CreateEntity(id, textBoxFullName.Text, dateTimePickerDateOfBirth.Value, numericUpDownHourlyRate.Value, (JobTitles)comboBoxJobTitle.SelectedItem!);
} }
} }

View File

@ -49,10 +49,14 @@ namespace ProjectItCompany.Forms
} }
} }
} }
public FormProject(IProjectRepository projectRepository) public FormProject(IProjectRepository projectRepository, ICustomerRepository customerRepository)
{ {
InitializeComponent(); InitializeComponent();
_projectRepository = projectRepository ?? throw new ArgumentNullException(nameof(projectRepository)); _projectRepository = projectRepository ?? throw new ArgumentNullException(nameof(projectRepository));
comboBoxCustomer.DataSource = customerRepository.ReadCustomers();
comboBoxCustomer.DisplayMember = "NameCustomer";
comboBoxCustomer.ValueMember = "Id";
} }
private void ButtonSave_Click(object sender, EventArgs e) private void ButtonSave_Click(object sender, EventArgs e)

View File

@ -81,9 +81,12 @@
// numericUpDownYear // numericUpDownYear
// //
numericUpDownYear.Location = new Point(130, 32); numericUpDownYear.Location = new Point(130, 32);
numericUpDownYear.Maximum = new decimal(new int[] { 2200, 0, 0, 0 });
numericUpDownYear.Minimum = new decimal(new int[] { 1950, 0, 0, 0 });
numericUpDownYear.Name = "numericUpDownYear"; numericUpDownYear.Name = "numericUpDownYear";
numericUpDownYear.Size = new Size(120, 23); numericUpDownYear.Size = new Size(120, 23);
numericUpDownYear.TabIndex = 5; numericUpDownYear.TabIndex = 5;
numericUpDownYear.Value = new decimal(new int[] { 1950, 0, 0, 0 });
// //
// numericUpDownNumberOfHours // numericUpDownNumberOfHours
// //
@ -145,7 +148,7 @@
Controls.Add(labelMonth); Controls.Add(labelMonth);
Name = "FormWage"; Name = "FormWage";
StartPosition = FormStartPosition.CenterParent; StartPosition = FormStartPosition.CenterParent;
Text = "FormWage"; Text = "Зарплата";
((System.ComponentModel.ISupportInitialize)numericUpDownYear).EndInit(); ((System.ComponentModel.ISupportInitialize)numericUpDownYear).EndInit();
((System.ComponentModel.ISupportInitialize)numericUpDownNumberOfHours).EndInit(); ((System.ComponentModel.ISupportInitialize)numericUpDownNumberOfHours).EndInit();
ResumeLayout(false); ResumeLayout(false);

View File

@ -11,14 +11,14 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Dapper" Version="2.1.35" /> <PackageReference Include="Dapper" Version="2.1.35" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0" /> <PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" /> <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" /> <PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="5.0.8" />
<PackageReference Include="Npgsql" Version="9.0.2" /> <PackageReference Include="Npgsql" Version="6.0.0" />
<PackageReference Include="Serilog" Version="4.2.0" /> <PackageReference Include="Serilog" Version="4.2.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="9.0.0" /> <PackageReference Include="Serilog.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="9.0.0" /> <PackageReference Include="Serilog.Settings.Configuration" Version="7.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" /> <PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageReference Include="Unity" Version="5.11.10" /> <PackageReference Include="Unity" Version="5.11.10" />
<PackageReference Include="Unity.Microsoft.Logging" Version="5.11.1" /> <PackageReference Include="Unity.Microsoft.Logging" Version="5.11.1" />

View File

@ -7,5 +7,5 @@ using System.Threading.Tasks;
namespace ProjectItCompany.Repositories.Implementations; namespace ProjectItCompany.Repositories.Implementations;
public class ConnectionString : IConnectionString public class ConnectionString : IConnectionString
{ {
string IConnectionString.ConnectionString => "Server=localhost, 5432;Database=itcompanyotp;Uid=postgres;Pwd=postgres;"; string IConnectionString.ConnectionString => "Server=localhost, 5432; Database=itcompanyotp;Uid=postgres;Pwd=marva;";
} }

View File

@ -33,11 +33,11 @@ public class ContractRepository : IContractRepository
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
connection.Open(); connection.Open();
using var transaction = connection.BeginTransaction(); using var transaction = connection.BeginTransaction();
var queryInsert = @"INSERT INTO Contracts (Date, ProjectId) var queryInsert = @"INSERT INTO contract (Date, ProjectId)
VALUES (@Date, @ProjectId); VALUES (@Date, @ProjectId);
SELECT MAX(Id) FROM Contracts"; SELECT MAX(Id) FROM Contracts";
var feedReplenishmentId = connection.QueryFirst<int>(queryInsert, contract, transaction); var feedReplenishmentId = connection.QueryFirst<int>(queryInsert, contract, transaction);
var querySubInsert = @"INSERT INTO CustomerOnProject (ContractId, CostomerId, Description) var querySubInsert = @"INSERT INTO customerOnProject (ContractId, CostomerId, Description)
VALUES (@ContractId,@CostomerId, @Description)"; VALUES (@ContractId,@CostomerId, @Description)";
foreach (var elem in contract.CustomerId) foreach (var elem in contract.CustomerId)
{ {
@ -64,7 +64,7 @@ public class ContractRepository : IContractRepository
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryDelete = @"DELETE FROM Contracts var queryDelete = @"DELETE FROM contract
WHERE ID=@id"; WHERE ID=@id";
connection.Execute(queryDelete, new { id }); connection.Execute(queryDelete, new { id });
} }
@ -81,7 +81,7 @@ public class ContractRepository : IContractRepository
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"SELECT * FROM Contracts"; var querySelect = @"SELECT * FROM contract";
var contracts = connection.Query<Entities.Contract>(querySelect); var contracts = connection.Query<Entities.Contract>(querySelect);
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(contracts)); _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(contracts));
return contracts; return contracts;

View File

@ -28,7 +28,7 @@ public class CustomerRepository : ICustomerRepository
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryInsert = @"INSERT INTO Customers (NameCustomer, Description) var queryInsert = @"INSERT INTO customer (NameCustomer, Description)
VALUES (@NameCustomer, @Description)"; VALUES (@NameCustomer, @Description)";
connection.Execute(queryInsert, customer); connection.Execute(queryInsert, customer);
} }
@ -47,7 +47,7 @@ public class CustomerRepository : ICustomerRepository
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryUpdate = @"UPDATE Customers SET var queryUpdate = @"UPDATE customer SET
NameCustomer=@NameCustomer, NameCustomer=@NameCustomer,
Description=@Description Description=@Description
WHERE ID=@id"; WHERE ID=@id";
@ -67,7 +67,7 @@ public class CustomerRepository : ICustomerRepository
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryDelete = @"DELETE FROM Customers WHERE ID=@id"; var queryDelete = @"DELETE FROM customer WHERE ID=@id";
connection.Execute(queryDelete, new { id }); connection.Execute(queryDelete, new { id });
} }
catch (Exception ex) catch (Exception ex)
@ -84,7 +84,7 @@ public class CustomerRepository : ICustomerRepository
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"SELECT * FROM Customers WHERE ID=@id"; var querySelect = @"SELECT * FROM customer WHERE ID=@id";
var customer = connection.QueryFirst<Customer>(querySelect, new var customer = connection.QueryFirst<Customer>(querySelect, new
{ {
id id
@ -106,7 +106,7 @@ public class CustomerRepository : ICustomerRepository
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = "SELECT * FROM Customers"; var querySelect = "SELECT * FROM customer";
var customers = connection.Query<Customer>(querySelect); var customers = connection.Query<Customer>(querySelect);
_logger.LogDebug("Полученные объекты: {json}", _logger.LogDebug("Полученные объекты: {json}",
JsonConvert.SerializeObject(customers)); JsonConvert.SerializeObject(customers));

View File

@ -28,7 +28,7 @@ public class ExecutorRepository : IExecutorRepository
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryInsert = @"INSERT INTO Executors (FullName, DateOfBirth, HourlyRate, JobTitles) var queryInsert = @"INSERT INTO executor (FullName, DateOfBirth, HourlyRate, JobTitles)
VALUES (@FullName, @DateOfBirth, @HourlyRate, @JobTitles)"; VALUES (@FullName, @DateOfBirth, @HourlyRate, @JobTitles)";
connection.Execute(queryInsert, executor); connection.Execute(queryInsert, executor);
} }
@ -47,7 +47,7 @@ public class ExecutorRepository : IExecutorRepository
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryUpdate = @"UPDATE Executors SET var queryUpdate = @"UPDATE executor SET
FullName=@FullName, FullName=@FullName,
DateOfBirth=@DateOfBirth, DateOfBirth=@DateOfBirth,
HourlyRate=@HourlyRate, HourlyRate=@HourlyRate,
@ -69,7 +69,7 @@ public class ExecutorRepository : IExecutorRepository
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryDelete = @"DELETE FROM Executors WHERE ID=@id"; var queryDelete = @"DELETE FROM executor WHERE ID=@id";
connection.Execute(queryDelete, new { id }); connection.Execute(queryDelete, new { id });
} }
catch (Exception ex) catch (Exception ex)
@ -86,7 +86,7 @@ public class ExecutorRepository : IExecutorRepository
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"SELECT * FROM Executors WHERE ID=@id"; var querySelect = @"SELECT * FROM executor WHERE ID=@id";
var executor = connection.QueryFirst<Executor>(querySelect, new var executor = connection.QueryFirst<Executor>(querySelect, new
{ {
id id
@ -108,7 +108,7 @@ public class ExecutorRepository : IExecutorRepository
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = "SELECT * FROM Executors"; var querySelect = "SELECT * FROM executor";
var executors = connection.Query<Executor>(querySelect); var executors = connection.Query<Executor>(querySelect);
_logger.LogDebug("Полученные объекты: {json}", _logger.LogDebug("Полученные объекты: {json}",
JsonConvert.SerializeObject(executors)); JsonConvert.SerializeObject(executors));

View File

@ -28,7 +28,7 @@ public class ProjectRepository : IProjectRepository
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryInsert = @"INSERT INTO Projects (NameProject, CustomerId, CompletedStages) var queryInsert = @"INSERT INTO project (NameProject, CustomerId, CompletedStages)
VALUES (@NameProject, @CustomerId, @CompletedStages)"; VALUES (@NameProject, @CustomerId, @CompletedStages)";
connection.Execute(queryInsert, project); connection.Execute(queryInsert, project);
} }
@ -47,7 +47,7 @@ public class ProjectRepository : IProjectRepository
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryUpdate = @"UPDATE Projects SET var queryUpdate = @"UPDATE project SET
NameProject=@NameProject, NameProject=@NameProject,
CustomerId=@CustomerId, CustomerId=@CustomerId,
CompletedStages=@CompletedStages CompletedStages=@CompletedStages
@ -68,7 +68,7 @@ public class ProjectRepository : IProjectRepository
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryDelete = @"DELETE FROM Projects WHERE ID=@id"; var queryDelete = @"DELETE FROM project WHERE ID=@id";
connection.Execute(queryDelete, new { id }); connection.Execute(queryDelete, new { id });
} }
catch (Exception ex) catch (Exception ex)
@ -85,7 +85,7 @@ public class ProjectRepository : IProjectRepository
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"SELECT * FROM Projects WHERE ID=@id"; var querySelect = @"SELECT * FROM project WHERE ID=@id";
var project = connection.QueryFirst<Project>(querySelect, new var project = connection.QueryFirst<Project>(querySelect, new
{ {
id id
@ -107,7 +107,7 @@ public class ProjectRepository : IProjectRepository
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = "SELECT * FROM Projects"; var querySelect = "SELECT * FROM project";
var projects = connection.Query<Project>(querySelect); var projects = connection.Query<Project>(querySelect);
_logger.LogDebug("Полученные объекты: {json}", _logger.LogDebug("Полученные объекты: {json}",
JsonConvert.SerializeObject(projects)); JsonConvert.SerializeObject(projects));

View File

@ -29,7 +29,7 @@ public class WageRepository : IWageRepository
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryInsert = @"INSERT INTO Wages (Month, Year, NumberOfHours, ExecutorID) var queryInsert = @"INSERT INTO wage (Month, Year, NumberOfHours, ExecutorID)
VALUES (@Month, @Year, @NumberOfHours, @ExecutorID)"; VALUES (@Month, @Year, @NumberOfHours, @ExecutorID)";
connection.Execute(queryInsert, wage); connection.Execute(queryInsert, wage);
} }
@ -47,7 +47,7 @@ public class WageRepository : IWageRepository
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = "SELECT * FROM Wages"; var querySelect = "SELECT * FROM wage";
var wages = connection.Query<Wage>(querySelect); var wages = connection.Query<Wage>(querySelect);
_logger.LogDebug("Полученные объекты: {json}", _logger.LogDebug("Полученные объекты: {json}",
JsonConvert.SerializeObject(wages)); JsonConvert.SerializeObject(wages));

44
SQL.pgsql Normal file
View File

@ -0,0 +1,44 @@
CREATE TABLE contract (
ID SERIAL PRIMARY KEY,
Date timestamp NOT NULL,
ProjectId INT REFERENCES project(ID),
CustomerId INT REFERENCES customer(ID)
);
CREATE TABLE customer (
ID SERIAL PRIMARY KEY,
NameCustomer VARCHAR(30) NOT NULL,
Description VARCHAR NOT NULL
);
CREATE TABLE customeronproject (
ID SERIAL PRIMARY KEY,
Descriptio VARCHAR NOT NULL,
ContractId INT REFERENCES contract(ID),
CustomerId INT REFERENCES customer(ID)
);
CREATE TABLE executor (
ID SERIAL PRIMARY KEY,
FullName VARCHAR NOT NULL,
DateOfBirth timestamp NOT NULL,
HourlyRate DECIMAL NOT NULL,
JobTitles INT NOT NULL
);
CREATE TABLE project (
ID SERIAL PRIMARY KEY,
NameProject VARCHAR NOT NULL,
CustomerId INT REFERENCES customer(ID),
CompletedStages INT NOT NULL
);
CREATE TABLE wage (
ID SERIAL PRIMARY KEY,
Month INT NOT NULL,
Year INT NOT NULL,
NumberOfHours INT,
ExecutorId INT REFERENCES executor(ID)
);
SELECT * FROM wage;