Много много

This commit is contained in:
Pipiaka 2024-12-19 20:47:31 +04:00
parent df2cdb9c0e
commit 22f6e25d90
20 changed files with 183 additions and 52 deletions

View File

@ -1,12 +1,16 @@
 
using System.ComponentModel;
namespace Accounting_Time_It_Company.Entities; namespace Accounting_Time_It_Company.Entities;
public class Client public class Client
{ {
public int Id { get; private set; } public int Id { get; private set; }
[DisplayName("Имя")]
public string NameClient { get; private set; } = string.Empty; public string NameClient { get; private set; } = string.Empty;
[DisplayName("Телефон")]
public string Phone { get; private set; } = string.Empty; public string Phone { get; private set; } = string.Empty;
public static Client CreateEntity(int id, string nameClaent, string phone) public static Client CreateEntity(int id, string nameClaent, string phone)

View File

@ -1,16 +1,34 @@
 
using System.ComponentModel;
namespace Accounting_Time_It_Company.Entities; namespace Accounting_Time_It_Company.Entities;
public class Employee public class Employee
{ {
public int Id { get; private set; } public int Id { get; private set; }
[Browsable(false)]
public int PostId { get; private set; } public int PostId { get; private set; }
[Browsable(false)]
public string PostName { get; private set; } = string.Empty;
[Browsable(false)]
public string PostLevel { get; private set; } = string.Empty;
[Browsable(false)]
public string PostWage { get; private set; } = string.Empty;
[DisplayName("Должность")]
public string FullPost => $"{PostName}<{PostLevel}>-{PostWage}";
[DisplayName("Имя")]
public string Name { get; private set; } = string.Empty; public string Name { get; private set; } = string.Empty;
[DisplayName("Телефон")]
public string Phone { get; private set; } = string.Empty; public string Phone { get; private set; } = string.Empty;
[DisplayName("Надбавка(%)")]
public float Allowance { get; private set; } public float Allowance { get; private set; }
public static Employee CreateEntity(int id, int postId, string name, string phone, float allowance) public static Employee CreateEntity(int id, int postId, string name, string phone, float allowance)

View File

@ -1,4 +1,5 @@
using Accounting_Time_It_Company.Entities.Enums; using Accounting_Time_It_Company.Entities.Enums;
using System.ComponentModel;
namespace Accounting_Time_It_Company.Entities; namespace Accounting_Time_It_Company.Entities;
@ -6,10 +7,15 @@ public class Post
{ {
public int Id { get; private set; } public int Id { get; private set; }
[DisplayName("Должность")]
public TypePost NamePost { get; private set; } public TypePost NamePost { get; private set; }
[DisplayName("Уровень")]
public string LevelPost { get; private set; } = string.Empty; public string LevelPost { get; private set; } = string.Empty;
public string FullName => $"{NamePost}<{LevelPost}>-{Wage}";
[DisplayName("Зарплата")]
public int Wage { get; private set; } public int Wage { get; private set; }
public static Post CreateEntity(int id, TypePost namePost, string levelPost, int wage) public static Post CreateEntity(int id, TypePost namePost, string levelPost, int wage)

View File

@ -1,4 +1,5 @@
using Accounting_Time_It_Company.Entities.Enums; using Accounting_Time_It_Company.Entities.Enums;
using System.ComponentModel;
namespace Accounting_Time_It_Company.Entities; namespace Accounting_Time_It_Company.Entities;
@ -6,10 +7,16 @@ public class Product
{ {
public int Id { get; private set; } public int Id { get; private set; }
[Browsable(false)]
public int ClientId { get; private set; } public int ClientId { get; private set; }
[DisplayName("Клиент")]
public string ClientName { get; private set; } = string.Empty;
[DisplayName("Имя проекта")]
public string Name { get; private set; } = string.Empty; public string Name { get; private set; } = string.Empty;
[DisplayName("Тип проекта")]
public TypeProduct Type { get; private set; } public TypeProduct Type { get; private set; }
public static Product CreateEntity(int id, int clientId, string name, TypeProduct type) public static Product CreateEntity(int id, int clientId, string name, TypeProduct type)

View File

@ -1,17 +0,0 @@

using Accounting_Time_It_Company.Entities.Enums;
namespace Accounting_Time_It_Company.Entities;
public class TempWorkTime
{
public int Id { get; private set; }
public int ProductId { get; private set; }
public int DirectorId { get; private set; }
public string Description { get; private set; } = string.Empty;
public int AllowanceForJob { get; private set; }
public DateTime Date { get; private set; }
public int EmployeeId { get; private set; }
public int Hours { get; private set; }
public TypePost NamePost { get; private set; }
}

View File

@ -1,22 +1,47 @@
 
using System.ComponentModel;
namespace Accounting_Time_It_Company.Entities; namespace Accounting_Time_It_Company.Entities;
public class TypeJob public class TypeJob
{ {
public int Id { get; private set; } public int Id { get; private set; }
[Browsable(false)]
public int ProductId { get; private set; } public int ProductId { get; private set; }
[Browsable(false)]
public int DirectorId { get; private set; } public int DirectorId { get; private set; }
[DisplayName("Проект")]
public string ProductName { get; private set; } = string.Empty;
[DisplayName("Директор")]
public string DirectorName { get; private set; } = string.Empty;
[DisplayName("Описание")]
public string Description { get; private set; } = string.Empty; public string Description { get; private set; } = string.Empty;
[DisplayName("Надбавка")]
public int AllowanceForJob { get; private set; } public int AllowanceForJob { get; private set; }
[DisplayName("Дата")]
public DateTime Date { get; private set; } public DateTime Date { get; private set; }
[DisplayName("Разработчики")]
public string Developes => WorkTimesDevelop != null ?
string.Join(", ", WorkTimesDevelop.Select(x => $"{x.EmployeeName} {x.Hours}")) :
string.Empty;
[DisplayName("Менеджеры")]
public string Managers => WorkTimesManager != null ?
string.Join(", ", WorkTimesManager.Select(x => $"{x.EmployeeName} {x.Hours}")) :
string.Empty;
[Browsable(false)]
public IEnumerable<WorkTime> WorkTimesDevelop { get; private set; } = []; public IEnumerable<WorkTime> WorkTimesDevelop { get; private set; } = [];
[Browsable(false)]
public IEnumerable<WorkTime> WorkTimesManager { get; private set; } = []; public IEnumerable<WorkTime> WorkTimesManager { get; private set; } = [];
public static TypeJob CreateOperation(int id, int productId, int directorId, string discription, int allowanceForJob, public static TypeJob CreateOperation(int id, int productId, int directorId, string discription, int allowanceForJob,
@ -35,19 +60,15 @@ public class TypeJob
}; };
} }
public static TypeJob CreateOperation(TempWorkTime tempWorkTime, public void SetWorkTime(IEnumerable<WorkTime> dev, IEnumerable<WorkTime> man)
IEnumerable<WorkTime> workTimesDevelop, IEnumerable<WorkTime> workTimesManager)
{ {
return new TypeJob if (dev.Any() && WorkTimesDevelop != null)
{ {
Id = tempWorkTime.Id, WorkTimesDevelop = dev;
ProductId = tempWorkTime.ProductId, }
DirectorId = tempWorkTime.DirectorId, if (man.Any() && WorkTimesManager != null)
Description = tempWorkTime.Description, {
AllowanceForJob = tempWorkTime.AllowanceForJob, WorkTimesManager = man;
Date = tempWorkTime.Date, }
WorkTimesDevelop = workTimesDevelop,
WorkTimesManager = workTimesManager
};
} }
} }

View File

@ -1,16 +1,28 @@
 
using System.ComponentModel;
namespace Accounting_Time_It_Company.Entities; namespace Accounting_Time_It_Company.Entities;
public class Vacation public class Vacation
{ {
public int Id { get; private set; } public int Id { get; private set; }
[Browsable(false)]
public int DirectorId { get; private set; } public int DirectorId { get; private set; }
[Browsable(false)]
public int EmployeeId { get; private set; } public int EmployeeId { get; private set; }
[DisplayName("Ответственный директор")]
public string DirectorName { get; private set; } = string.Empty;
[DisplayName("Сотрудник")]
public string EmployeeName { get; private set; } = string.Empty;
[DisplayName("Дата начала")]
public DateTime StartDate { get; private set; } public DateTime StartDate { get; private set; }
[DisplayName("Дата конца")]
public DateTime EndDate { get; private set; } public DateTime EndDate { get; private set; }
public static Vacation CreateOpeartion(int id, int directorId, int EmployeeId, DateTime startDate, DateTime endDate) public static Vacation CreateOpeartion(int id, int directorId, int EmployeeId, DateTime startDate, DateTime endDate)

View File

@ -7,6 +7,8 @@ public class WorkTime
public int EmployeeId { get; private set; } public int EmployeeId { get; private set; }
public string EmployeeName { get; private set; } = string.Empty;
public int Hours { get; private set; } public int Hours { get; private set; }
public static WorkTime CreateElement(int id, int employeeId, int hours) public static WorkTime CreateElement(int id, int employeeId, int hours)

View File

@ -81,7 +81,11 @@ namespace Accounting_Time_It_Company.Forms
} }
} }
private void LoadList() => dataGridViewData.DataSource = _clientRepositories.ReadClients(); private void LoadList()
{
dataGridViewData.DataSource = _clientRepositories.ReadClients();
dataGridViewData.Columns["Id"].Visible = false;
}
private bool TryGetIdentifierFromSelectedRow(out int id) private bool TryGetIdentifierFromSelectedRow(out int id)
{ {

View File

@ -40,7 +40,7 @@ namespace Accounting_Time_It_Company.Forms
_employeeRepositories = employeeRepositories ?? throw new ArgumentNullException(nameof(employeeRepositories)); _employeeRepositories = employeeRepositories ?? throw new ArgumentNullException(nameof(employeeRepositories));
comboBoxPost.DataSource = postRepositories.ReadPosts(); comboBoxPost.DataSource = postRepositories.ReadPosts();
comboBoxPost.DisplayMember = "NamePost"; comboBoxPost.DisplayMember = "FullName";
comboBoxPost.ValueMember = "Id"; comboBoxPost.ValueMember = "Id";
} }

View File

@ -81,7 +81,11 @@ namespace Accounting_Time_It_Company.Forms
} }
} }
private void LoadList() => dataGridViewData.DataSource = _employeeRepositories.ReadEmployees(); private void LoadList()
{
dataGridViewData.DataSource = _employeeRepositories.ReadEmployees();
dataGridViewData.Columns["Id"].Visible = false;
}
private bool TryGetIdentifierFromSelectedRow(out int id) private bool TryGetIdentifierFromSelectedRow(out int id)
{ {

View File

@ -81,7 +81,12 @@ namespace Accounting_Time_It_Company.Forms
} }
} }
private void LoadList() => dataGridViewData.DataSource = _postRepositories.ReadPosts(); private void LoadList()
{
dataGridViewData.DataSource = _postRepositories.ReadPosts();
dataGridViewData.Columns["Id"].Visible = false;
dataGridViewData.Columns["FullName"].Visible = false;
}
private bool TryGetIdentifierFromSelectedRow(out int id) private bool TryGetIdentifierFromSelectedRow(out int id)
{ {

View File

@ -81,7 +81,11 @@ namespace Accounting_Time_It_Company.Forms
} }
} }
private void LoadList() => dataGridViewData.DataSource = _productRepositories.ReadProducts(); private void LoadList()
{
dataGridViewData.DataSource = _productRepositories.ReadProducts();
dataGridViewData.Columns["Id"].Visible = false;
}
private bool TryGetIdentifierFromSelectedRow(out int id) private bool TryGetIdentifierFromSelectedRow(out int id)
{ {

View File

@ -41,7 +41,7 @@
panel1.Controls.Add(buttonDelete); panel1.Controls.Add(buttonDelete);
panel1.Controls.Add(buttonAdd); panel1.Controls.Add(buttonAdd);
panel1.Dock = DockStyle.Right; panel1.Dock = DockStyle.Right;
panel1.Location = new Point(686, 0); panel1.Location = new Point(978, 0);
panel1.Name = "panel1"; panel1.Name = "panel1";
panel1.Size = new Size(114, 450); panel1.Size = new Size(114, 450);
panel1.TabIndex = 6; panel1.TabIndex = 6;
@ -84,14 +84,14 @@
dataGridViewData.RowHeadersVisible = false; dataGridViewData.RowHeadersVisible = false;
dataGridViewData.RowHeadersWidth = 51; dataGridViewData.RowHeadersWidth = 51;
dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridViewData.Size = new Size(800, 450); dataGridViewData.Size = new Size(1092, 450);
dataGridViewData.TabIndex = 7; dataGridViewData.TabIndex = 7;
// //
// FormTypeJobs // FormTypeJobs
// //
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450); ClientSize = new Size(1092, 450);
Controls.Add(panel1); Controls.Add(panel1);
Controls.Add(dataGridViewData); Controls.Add(dataGridViewData);
Name = "FormTypeJobs"; Name = "FormTypeJobs";

View File

@ -62,7 +62,12 @@ namespace Accounting_Time_It_Company.Forms
} }
} }
private void LoadList() => dataGridViewData.DataSource = _typeJobRepositories.ReadTypeJobs(); private void LoadList()
{
dataGridViewData.DataSource = _typeJobRepositories.ReadTypeJobs();
dataGridViewData.Columns["Id"].Visible = false;
dataGridViewData.Columns["Date"].DefaultCellStyle.Format = "MMMM yy";
}
private bool TryGetIdentifierFromSelectedRow(out int id) private bool TryGetIdentifierFromSelectedRow(out int id)
{ {

View File

@ -41,6 +41,12 @@ namespace Accounting_Time_It_Company.Forms
} }
} }
private void LoadList() => dataGridViewData.DataSource = _vacationRepositories.ReadVacations(); private void LoadList()
{
dataGridViewData.DataSource = _vacationRepositories.ReadVacations();
dataGridViewData.Columns["Id"].Visible = false;
dataGridViewData.Columns["StartDate"].DefaultCellStyle.Format = "dd.MM.yy";
dataGridViewData.Columns["EndDate"].DefaultCellStyle.Format = "dd.MM.yy";
}
} }
} }

View File

@ -113,7 +113,12 @@ public class EmployeeRepositories : IEmployeeRepositories
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
connection.Open(); connection.Open();
var querySelect = "SELECT * FROM Employee"; var querySelect = @"SELECT e.*,
p.NamePost AS PostName,
p.LevelPost AS PostLevel,
p.Wage AS PostWage
FROM Employee e
LEFT JOIN Post p ON p.id = e.postid";
var employees = connection.Query<Employee>(querySelect); var employees = connection.Query<Employee>(querySelect);
_logger.LogDebug("Полученные объекты: {json}", _logger.LogDebug("Полученные объекты: {json}",
JsonConvert.SerializeObject(employees)); JsonConvert.SerializeObject(employees));

View File

@ -112,7 +112,10 @@ public class ProductRepositories : IProductRepositories
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
connection.Open(); connection.Open();
var querySelect = "SELECT * FROM Product"; var querySelect = @"SELECT p.*,
c.NameClient AS ClientName
FROM Product p
LEFT JOIN Client c ON c.id = p.clientid";
var products = connection.Query<Product>(querySelect); var products = connection.Query<Product>(querySelect);
_logger.LogDebug("Полученные объекты: {json}", _logger.LogDebug("Полученные объекты: {json}",
JsonConvert.SerializeObject(products)); JsonConvert.SerializeObject(products));

View File

@ -4,6 +4,9 @@ using Dapper;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Newtonsoft.Json; using Newtonsoft.Json;
using Npgsql; using Npgsql;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace Accounting_Time_It_Company.Repositories.Implementations; namespace Accounting_Time_It_Company.Repositories.Implementations;
@ -93,17 +96,51 @@ public class TypeJobRepositories : ITypeJobRepositories
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
connection.Open(); connection.Open();
var querySelect = @"SELECT tj.*, wt.EmployeeId, wt.Hours, p.namepost var querySelect = @"SELECT
tj.*,
pr.Name AS ProductName,
ed.Name AS DirectorName,
wt.EmployeeID,
wt.Hours,
e.Name AS EmployeeName,
e.Name,
e.PostId
FROM TypeJob tj FROM TypeJob tj
INNER JOIN WorkTime wt ON wt.typejobid = tj.id LEFT JOIN Product pr ON pr.id = tj.productid
INNER JOIN Employee e ON e.id = wt.employeeid LEFT JOIN Employee ed ON ed.id = tj.directorid
INNER JOIN Post p ON p.id = e.PostId;"; LEFT JOIN WorkTime wt ON wt.typejobid = tj.id
var typeJobs = connection.Query<TempWorkTime>(querySelect); LEFT JOIN Employee e ON e.id = wt.employeeid";
var jobDictDev = new Dictionary<int, List<WorkTime>>();
var jobDictMan = new Dictionary<int, List<WorkTime>>();
var typeJobs = connection.Query<TypeJob, WorkTime, Employee, TypeJob>(querySelect,
(tj, wt, e) =>
{
if (!jobDictDev.TryGetValue(tj.Id, out var tjwtd))
{
tjwtd = [];
jobDictDev.Add(tj.Id, tjwtd);
}
if (!jobDictMan.TryGetValue(tj.Id, out var tjwtm))
{
tjwtm = [];
jobDictMan.Add(tj.Id, tjwtm);
}
if (e.PostId == (int)TypePost.Developer) tjwtd.Add(wt);
if (e.PostId == (int)TypePost.Manager) tjwtm.Add(wt);
return tj;
}, splitOn: "employeeid, name");
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(typeJobs)); _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(typeJobs));
return typeJobs.GroupBy(x => x.Id, y => y,
(key, value) => TypeJob.CreateOperation(value.First(), return typeJobs.GroupBy(x => x.Id).Select(x => x.First()).Select(x =>
value.Where(z => z.NamePost == TypePost.Developer).Select(h => WorkTime.CreateElement(0, h.EmployeeId, h.Hours)).ToList(), {
value.Where(z => z.NamePost == TypePost.Manager).Select(h => WorkTime.CreateElement(0, h.EmployeeId, h.Hours)).ToList())).ToList(); var dev = jobDictDev.Where(y => y.Key == x.Id).Select(y => y.Value).SelectMany(a => a).ToList();
var man = jobDictMan.Where(y => y.Key == x.Id).Select(y => y.Value).SelectMany(a => a).ToList();
x.SetWorkTime(dev, man);
return x;
}).ToArray();
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -48,7 +48,12 @@ public class VacationRepositories : IVacationRepositories
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
connection.Open(); connection.Open();
var querySelect = "SELECT * FROM Vacation"; var querySelect = @"SELECT v.*,
ed.Name AS DirectorName,
ee.Name AS EmployeeName
FROM Vacation v
LEFT JOIN Employee ed ON ed.id = v.directorid
LEFT JOIN Employee ee ON ee.id = v.employeeid";
var vacations = connection.Query<Vacation>(querySelect); var vacations = connection.Query<Vacation>(querySelect);
_logger.LogDebug("Полученные объекты: {json}", _logger.LogDebug("Полученные объекты: {json}",
JsonConvert.SerializeObject(vacations)); JsonConvert.SerializeObject(vacations));