Lab2
This commit is contained in:
parent
ff4579d373
commit
3d7f0ac061
@ -80,6 +80,6 @@ namespace ProjectItCompany.Forms
|
||||
|
||||
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!);
|
||||
}
|
||||
}
|
||||
|
@ -49,10 +49,14 @@ namespace ProjectItCompany.Forms
|
||||
}
|
||||
}
|
||||
}
|
||||
public FormProject(IProjectRepository projectRepository)
|
||||
public FormProject(IProjectRepository projectRepository, ICustomerRepository customerRepository)
|
||||
{
|
||||
InitializeComponent();
|
||||
_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)
|
||||
|
@ -81,9 +81,12 @@
|
||||
// numericUpDownYear
|
||||
//
|
||||
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.Size = new Size(120, 23);
|
||||
numericUpDownYear.TabIndex = 5;
|
||||
numericUpDownYear.Value = new decimal(new int[] { 1950, 0, 0, 0 });
|
||||
//
|
||||
// numericUpDownNumberOfHours
|
||||
//
|
||||
@ -145,7 +148,7 @@
|
||||
Controls.Add(labelMonth);
|
||||
Name = "FormWage";
|
||||
StartPosition = FormStartPosition.CenterParent;
|
||||
Text = "FormWage";
|
||||
Text = "Зарплата";
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownYear).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownNumberOfHours).EndInit();
|
||||
ResumeLayout(false);
|
||||
|
@ -11,14 +11,14 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Dapper" Version="2.1.35" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="Npgsql" Version="9.0.2" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="5.0.8" />
|
||||
<PackageReference Include="Npgsql" Version="6.0.0" />
|
||||
<PackageReference Include="Serilog" Version="4.2.0" />
|
||||
<PackageReference Include="Serilog.Extensions.Logging" Version="9.0.0" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="9.0.0" />
|
||||
<PackageReference Include="Serilog.Extensions.Logging" Version="7.0.0" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
|
||||
<PackageReference Include="Unity" Version="5.11.10" />
|
||||
<PackageReference Include="Unity.Microsoft.Logging" Version="5.11.1" />
|
||||
|
@ -7,5 +7,5 @@ using System.Threading.Tasks;
|
||||
namespace ProjectItCompany.Repositories.Implementations;
|
||||
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;";
|
||||
}
|
||||
|
@ -33,11 +33,11 @@ public class ContractRepository : IContractRepository
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
using var transaction = connection.BeginTransaction();
|
||||
var queryInsert = @"INSERT INTO Contracts (Date, ProjectId)
|
||||
var queryInsert = @"INSERT INTO contract (Date, ProjectId)
|
||||
VALUES (@Date, @ProjectId);
|
||||
SELECT MAX(Id) FROM Contracts";
|
||||
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)";
|
||||
foreach (var elem in contract.CustomerId)
|
||||
{
|
||||
@ -64,7 +64,7 @@ public class ContractRepository : IContractRepository
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryDelete = @"DELETE FROM Contracts
|
||||
var queryDelete = @"DELETE FROM contract
|
||||
WHERE ID=@id";
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
@ -81,7 +81,7 @@ public class ContractRepository : IContractRepository
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"SELECT * FROM Contracts";
|
||||
var querySelect = @"SELECT * FROM contract";
|
||||
var contracts = connection.Query<Entities.Contract>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(contracts));
|
||||
return contracts;
|
||||
|
@ -28,7 +28,7 @@ public class CustomerRepository : ICustomerRepository
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"INSERT INTO Customers (NameCustomer, Description)
|
||||
var queryInsert = @"INSERT INTO customer (NameCustomer, Description)
|
||||
VALUES (@NameCustomer, @Description)";
|
||||
connection.Execute(queryInsert, customer);
|
||||
}
|
||||
@ -47,7 +47,7 @@ public class CustomerRepository : ICustomerRepository
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryUpdate = @"UPDATE Customers SET
|
||||
var queryUpdate = @"UPDATE customer SET
|
||||
NameCustomer=@NameCustomer,
|
||||
Description=@Description
|
||||
WHERE ID=@id";
|
||||
@ -67,7 +67,7 @@ public class CustomerRepository : ICustomerRepository
|
||||
try
|
||||
{
|
||||
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 });
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -84,7 +84,7 @@ public class CustomerRepository : ICustomerRepository
|
||||
try
|
||||
{
|
||||
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
|
||||
{
|
||||
id
|
||||
@ -106,7 +106,7 @@ public class CustomerRepository : ICustomerRepository
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM Customers";
|
||||
var querySelect = "SELECT * FROM customer";
|
||||
var customers = connection.Query<Customer>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}",
|
||||
JsonConvert.SerializeObject(customers));
|
||||
|
@ -28,7 +28,7 @@ public class ExecutorRepository : IExecutorRepository
|
||||
try
|
||||
{
|
||||
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)";
|
||||
connection.Execute(queryInsert, executor);
|
||||
}
|
||||
@ -47,7 +47,7 @@ public class ExecutorRepository : IExecutorRepository
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryUpdate = @"UPDATE Executors SET
|
||||
var queryUpdate = @"UPDATE executor SET
|
||||
FullName=@FullName,
|
||||
DateOfBirth=@DateOfBirth,
|
||||
HourlyRate=@HourlyRate,
|
||||
@ -69,7 +69,7 @@ public class ExecutorRepository : IExecutorRepository
|
||||
try
|
||||
{
|
||||
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 });
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -86,7 +86,7 @@ public class ExecutorRepository : IExecutorRepository
|
||||
try
|
||||
{
|
||||
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
|
||||
{
|
||||
id
|
||||
@ -108,7 +108,7 @@ public class ExecutorRepository : IExecutorRepository
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM Executors";
|
||||
var querySelect = "SELECT * FROM executor";
|
||||
var executors = connection.Query<Executor>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}",
|
||||
JsonConvert.SerializeObject(executors));
|
||||
|
@ -28,7 +28,7 @@ public class ProjectRepository : IProjectRepository
|
||||
try
|
||||
{
|
||||
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)";
|
||||
connection.Execute(queryInsert, project);
|
||||
}
|
||||
@ -47,7 +47,7 @@ public class ProjectRepository : IProjectRepository
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryUpdate = @"UPDATE Projects SET
|
||||
var queryUpdate = @"UPDATE project SET
|
||||
NameProject=@NameProject,
|
||||
CustomerId=@CustomerId,
|
||||
CompletedStages=@CompletedStages
|
||||
@ -68,7 +68,7 @@ public class ProjectRepository : IProjectRepository
|
||||
try
|
||||
{
|
||||
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 });
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -85,7 +85,7 @@ public class ProjectRepository : IProjectRepository
|
||||
try
|
||||
{
|
||||
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
|
||||
{
|
||||
id
|
||||
@ -107,7 +107,7 @@ public class ProjectRepository : IProjectRepository
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM Projects";
|
||||
var querySelect = "SELECT * FROM project";
|
||||
var projects = connection.Query<Project>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}",
|
||||
JsonConvert.SerializeObject(projects));
|
||||
|
@ -29,7 +29,7 @@ public class WageRepository : IWageRepository
|
||||
try
|
||||
{
|
||||
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)";
|
||||
connection.Execute(queryInsert, wage);
|
||||
}
|
||||
@ -47,7 +47,7 @@ public class WageRepository : IWageRepository
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM Wages";
|
||||
var querySelect = "SELECT * FROM wage";
|
||||
var wages = connection.Query<Wage>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}",
|
||||
JsonConvert.SerializeObject(wages));
|
||||
|
44
SQL.pgsql
Normal file
44
SQL.pgsql
Normal 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;
|
Loading…
x
Reference in New Issue
Block a user