Сданный вариант

This commit is contained in:
Егор Пыжов 2024-11-27 12:17:51 +04:00
parent 24a71032da
commit 3d777101ad
23 changed files with 393 additions and 209 deletions

View File

@ -8,7 +8,7 @@ public class Appointment
public DateTime StartDate { get; private set; } public DateTime StartDate { get; private set; }
public DateTime? EndDate { get; private set; } public DateTime? EndDate { get; private set; }
public static Appointment CreateOperation(int id, int orderId, int employeeId, DateTime appointmentStartDate, DateTime appointmentEndDate) public static Appointment CreateOperation(int id, int orderId, int employeeId, DateTime appointmentStartDate, DateTime? appointmentEndDate)
{ {
return new Appointment return new Appointment
{ {

View File

@ -4,8 +4,8 @@ public class Order
{ {
public int Id { get; private set; } public int Id { get; private set; }
public int CompanyId { get; private set; } public int CompanyId { get; private set; }
public DateTime OrderDate { get; private set; } public DateTime Date { get; private set; }
public decimal OrderPrice { get; private set; } public decimal Price { get; private set; }
public IEnumerable<OrderService> OrderService { get; private set; } = []; public IEnumerable<OrderService> OrderService { get; private set; } = [];
@ -15,8 +15,8 @@ public class Order
{ {
Id = id, Id = id,
CompanyId = companyId, CompanyId = companyId,
OrderDate = DateTime.Now, Date = DateTime.Now,
OrderPrice = orderPrice, Price = orderPrice,
OrderService = orderService OrderService = orderService
}; };
} }

View File

@ -8,12 +8,11 @@ public class OrderService
public int Quantity { get; private set; } public int Quantity { get; private set; }
public DateTime ExecutionDate { get; private set; } public DateTime ExecutionDate { get; private set; }
public static OrderService CreateOperation(int id, int orderId, int serviceId, int serviceQuantity, DateTime executionDate) public static OrderService CreateOperation(int id, int serviceId, int serviceQuantity, DateTime executionDate)
{ {
return new OrderService return new OrderService
{ {
Id = id, Id = id,
OrderId = orderId,
ServiceId = serviceId, ServiceId = serviceId,
Quantity = serviceQuantity, Quantity = serviceQuantity,
ExecutionDate = executionDate ExecutionDate = executionDate

View File

@ -43,18 +43,18 @@
// label1 // label1
// //
label1.AutoSize = true; label1.AutoSize = true;
label1.Location = new Point(46, 46); label1.Location = new Point(53, 61);
label1.Name = "label1"; label1.Name = "label1";
label1.Size = new Size(40, 15); label1.Size = new Size(50, 20);
label1.TabIndex = 0; label1.TabIndex = 0;
label1.Text = "Заказ:"; label1.Text = "Заказ:";
// //
// label2 // label2
// //
label2.AutoSize = true; label2.AutoSize = true;
label2.Location = new Point(46, 141); label2.Location = new Point(53, 188);
label2.Name = "label2"; label2.Name = "label2";
label2.Size = new Size(69, 15); label2.Size = new Size(85, 20);
label2.TabIndex = 1; label2.TabIndex = 1;
label2.Text = "Сотрудник:"; label2.Text = "Сотрудник:";
// //
@ -62,51 +62,55 @@
// //
comboBoxEmployee.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxEmployee.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxEmployee.FormattingEnabled = true; comboBoxEmployee.FormattingEnabled = true;
comboBoxEmployee.Location = new Point(214, 138); comboBoxEmployee.Location = new Point(262, 184);
comboBoxEmployee.Margin = new Padding(3, 4, 3, 4);
comboBoxEmployee.Name = "comboBoxEmployee"; comboBoxEmployee.Name = "comboBoxEmployee";
comboBoxEmployee.Size = new Size(207, 23); comboBoxEmployee.Size = new Size(236, 28);
comboBoxEmployee.TabIndex = 2; comboBoxEmployee.TabIndex = 2;
// //
// comboBoxOrder // comboBoxOrder
// //
comboBoxOrder.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxOrder.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxOrder.FormattingEnabled = true; comboBoxOrder.FormattingEnabled = true;
comboBoxOrder.Location = new Point(214, 46); comboBoxOrder.Location = new Point(262, 61);
comboBoxOrder.Margin = new Padding(3, 4, 3, 4);
comboBoxOrder.Name = "comboBoxOrder"; comboBoxOrder.Name = "comboBoxOrder";
comboBoxOrder.Size = new Size(207, 23); comboBoxOrder.Size = new Size(236, 28);
comboBoxOrder.TabIndex = 3; comboBoxOrder.TabIndex = 3;
// //
// dateTimePickerStart // dateTimePickerStart
// //
dateTimePickerStart.ImeMode = ImeMode.Disable; dateTimePickerStart.ImeMode = ImeMode.Disable;
dateTimePickerStart.Location = new Point(214, 228); dateTimePickerStart.Location = new Point(262, 304);
dateTimePickerStart.Margin = new Padding(3, 4, 3, 4);
dateTimePickerStart.Name = "dateTimePickerStart"; dateTimePickerStart.Name = "dateTimePickerStart";
dateTimePickerStart.Size = new Size(207, 23); dateTimePickerStart.Size = new Size(236, 27);
dateTimePickerStart.TabIndex = 4; dateTimePickerStart.TabIndex = 4;
// //
// label3 // label3
// //
label3.AutoSize = true; label3.AutoSize = true;
label3.Location = new Point(46, 234); label3.Location = new Point(53, 312);
label3.Name = "label3"; label3.Name = "label3";
label3.Size = new Size(149, 15); label3.Size = new Size(193, 20);
label3.TabIndex = 5; label3.TabIndex = 5;
label3.Text = "Дата назначения на заказ:"; label3.Text = "Дата назначения на заказ:";
// //
// label4 // label4
// //
label4.AutoSize = true; label4.AutoSize = true;
label4.Location = new Point(46, 328); label4.Location = new Point(53, 437);
label4.Name = "label4"; label4.Name = "label4";
label4.Size = new Size(95, 15); label4.Size = new Size(121, 20);
label4.TabIndex = 6; label4.TabIndex = 6;
label4.Text = "Дата окончания"; label4.Text = "Дата окончания";
// //
// buttonCancel // buttonCancel
// //
buttonCancel.Location = new Point(285, 442); buttonCancel.Location = new Point(326, 589);
buttonCancel.Margin = new Padding(3, 4, 3, 4);
buttonCancel.Name = "buttonCancel"; buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(112, 28); buttonCancel.Size = new Size(128, 37);
buttonCancel.TabIndex = 9; buttonCancel.TabIndex = 9;
buttonCancel.Text = "Отмена"; buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true; buttonCancel.UseVisualStyleBackColor = true;
@ -114,9 +118,10 @@
// //
// buttonAdd // buttonAdd
// //
buttonAdd.Location = new Point(59, 442); buttonAdd.Location = new Point(67, 589);
buttonAdd.Margin = new Padding(3, 4, 3, 4);
buttonAdd.Name = "buttonAdd"; buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(112, 28); buttonAdd.Size = new Size(128, 37);
buttonAdd.TabIndex = 8; buttonAdd.TabIndex = 8;
buttonAdd.Text = "Добавить"; buttonAdd.Text = "Добавить";
buttonAdd.UseVisualStyleBackColor = true; buttonAdd.UseVisualStyleBackColor = true;
@ -124,17 +129,20 @@
// //
// dateTimePickerEnd // dateTimePickerEnd
// //
dateTimePickerEnd.CustomFormat = "В процессе";
dateTimePickerEnd.Format = DateTimePickerFormat.Custom;
dateTimePickerEnd.ImeMode = ImeMode.Disable; dateTimePickerEnd.ImeMode = ImeMode.Disable;
dateTimePickerEnd.Location = new Point(214, 328); dateTimePickerEnd.Location = new Point(262, 437);
dateTimePickerEnd.Margin = new Padding(3, 4, 3, 4);
dateTimePickerEnd.Name = "dateTimePickerEnd"; dateTimePickerEnd.Name = "dateTimePickerEnd";
dateTimePickerEnd.Size = new Size(207, 23); dateTimePickerEnd.Size = new Size(236, 27);
dateTimePickerEnd.TabIndex = 10; dateTimePickerEnd.TabIndex = 10;
// //
// FormAppointment // FormAppointment
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(476, 505); ClientSize = new Size(544, 673);
Controls.Add(dateTimePickerEnd); Controls.Add(dateTimePickerEnd);
Controls.Add(buttonCancel); Controls.Add(buttonCancel);
Controls.Add(buttonAdd); Controls.Add(buttonAdd);
@ -145,6 +153,7 @@
Controls.Add(comboBoxEmployee); Controls.Add(comboBoxEmployee);
Controls.Add(label2); Controls.Add(label2);
Controls.Add(label1); Controls.Add(label1);
Margin = new Padding(3, 4, 3, 4);
Name = "FormAppointment"; Name = "FormAppointment";
Text = "Назначение"; Text = "Назначение";
ResumeLayout(false); ResumeLayout(false);

View File

@ -1,15 +1,5 @@
using ITServiceManager.Entities; using ITServiceManager.Entities;
using ITServiceManager.Repositories; using ITServiceManager.Repositories;
using ITServiceManager.Repositories.Implementations;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ITServiceManager.Forms namespace ITServiceManager.Forms
{ {
@ -30,8 +20,8 @@ namespace ITServiceManager.Forms
throw new throw new
InvalidDataException(nameof(appointment)); InvalidDataException(nameof(appointment));
} }
comboBoxEmployee.SelectedIndex = appointment.EmployeeId; comboBoxEmployee.SelectedItem = appointment.EmployeeId;
comboBoxOrder.SelectedIndex = appointment.OrderId; comboBoxOrder.SelectedItem = appointment.OrderId;
_appointmentId = value; _appointmentId = value;
} }
catch (Exception ex) catch (Exception ex)
@ -54,15 +44,30 @@ namespace ITServiceManager.Forms
comboBoxEmployee.DataSource = employeeRepository.ReadEmployees(); comboBoxEmployee.DataSource = employeeRepository.ReadEmployees();
comboBoxEmployee.DisplayMember = "Name"; comboBoxEmployee.DisplayMember = "Name";
comboBoxEmployee.ValueMember = "Id"; comboBoxEmployee.ValueMember = "Id";
dateTimePickerEnd.Format = DateTimePickerFormat.Custom;
dateTimePickerEnd.CustomFormat = "В процессе";
dateTimePickerEnd.ValueChanged += DateTimePickerEnd_ValueChanged;
}
private void DateTimePickerEnd_ValueChanged(object sender, EventArgs e)
{
if (dateTimePickerEnd.CustomFormat == "В процессе")
{
dateTimePickerEnd.CustomFormat = "dd.MM.yyyy HH:mm";
}
} }
private void ButtonAdd_Click(object sender, EventArgs e) private void ButtonAdd_Click(object sender, EventArgs e)
{ {
try try
{ {
if (comboBoxEmployee.SelectedIndex < 0 || comboBoxOrder.SelectedIndex < 0 || dateTimePickerStart.CustomFormat != " ") if (comboBoxEmployee.SelectedIndex < 0 || comboBoxOrder.SelectedIndex < 0)
{ {
throw new Exception("Имеются незаполненные поля"); throw new Exception("Имеются незаполненные поля");
} }
if (_appointmentId.HasValue) if (_appointmentId.HasValue)
{ {
_appointmentRepository.UpdateAppointment(CreateAppointment(_appointmentId.Value)); _appointmentRepository.UpdateAppointment(CreateAppointment(_appointmentId.Value));
@ -80,7 +85,12 @@ namespace ITServiceManager.Forms
} }
} }
private void ButtonCancel_Click(object sender, EventArgs e) => Close(); private void ButtonCancel_Click(object sender, EventArgs e) => Close();
private Appointment CreateAppointment(int id) => Appointment.CreateOperation(id, comboBoxOrder.SelectedIndex, comboBoxEmployee.SelectedIndex, Convert.ToDateTime(dateTimePickerStart) , private Appointment CreateAppointment(int id)
Convert.ToDateTime(dateTimePickerEnd)); {
DateTime? endDate = dateTimePickerEnd.CustomFormat == "В процессе" ? (DateTime?)null : dateTimePickerEnd.Value;
return Appointment.CreateOperation(id, (int)comboBoxOrder.SelectedValue!, (int)comboBoxEmployee.SelectedValue!, Convert.ToDateTime(dateTimePickerStart.Value),
endDate);
}
} }
} }

View File

@ -30,6 +30,7 @@
{ {
dataGridView = new DataGridView(); dataGridView = new DataGridView();
panel = new Panel(); panel = new Panel();
buttonRemove = new Button();
buttonUpdate = new Button(); buttonUpdate = new Button();
buttonAdd = new Button(); buttonAdd = new Button();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
@ -42,9 +43,11 @@
dataGridView.AllowUserToDeleteRows = false; dataGridView.AllowUserToDeleteRows = false;
dataGridView.AllowUserToResizeColumns = false; dataGridView.AllowUserToResizeColumns = false;
dataGridView.AllowUserToResizeRows = false; dataGridView.AllowUserToResizeRows = false;
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Dock = DockStyle.Fill; dataGridView.Dock = DockStyle.Fill;
dataGridView.Location = new Point(0, 0); dataGridView.Location = new Point(0, 0);
dataGridView.Margin = new Padding(3, 4, 3, 4);
dataGridView.MultiSelect = false; dataGridView.MultiSelect = false;
dataGridView.Name = "dataGridView"; dataGridView.Name = "dataGridView";
dataGridView.ReadOnly = true; dataGridView.ReadOnly = true;
@ -52,26 +55,41 @@
dataGridView.RowHeadersWidth = 51; dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 25; dataGridView.RowTemplate.Height = 25;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.Size = new Size(652, 450); dataGridView.Size = new Size(745, 600);
dataGridView.TabIndex = 2; dataGridView.TabIndex = 2;
// //
// panel // panel
// //
panel.Controls.Add(buttonRemove);
panel.Controls.Add(buttonUpdate); panel.Controls.Add(buttonUpdate);
panel.Controls.Add(buttonAdd); panel.Controls.Add(buttonAdd);
panel.Dock = DockStyle.Right; panel.Dock = DockStyle.Right;
panel.Location = new Point(652, 0); panel.Location = new Point(745, 0);
panel.Margin = new Padding(3, 4, 3, 4);
panel.Name = "panel"; panel.Name = "panel";
panel.Size = new Size(148, 450); panel.Size = new Size(169, 600);
panel.TabIndex = 3; panel.TabIndex = 3;
// //
// buttonRemove
//
buttonRemove.BackgroundImage = Properties.Resources.minus;
buttonRemove.BackgroundImageLayout = ImageLayout.Stretch;
buttonRemove.Location = new Point(45, 200);
buttonRemove.Margin = new Padding(3, 4, 3, 4);
buttonRemove.Name = "buttonRemove";
buttonRemove.Size = new Size(86, 101);
buttonRemove.TabIndex = 3;
buttonRemove.UseVisualStyleBackColor = true;
buttonRemove.Click += buttonRemove_Click;
//
// buttonUpdate // buttonUpdate
// //
buttonUpdate.BackgroundImage = Properties.Resources.edit; buttonUpdate.BackgroundImage = Properties.Resources.edit;
buttonUpdate.BackgroundImageLayout = ImageLayout.Stretch; buttonUpdate.BackgroundImageLayout = ImageLayout.Stretch;
buttonUpdate.Location = new Point(33, 269); buttonUpdate.Location = new Point(38, 359);
buttonUpdate.Margin = new Padding(3, 4, 3, 4);
buttonUpdate.Name = "buttonUpdate"; buttonUpdate.Name = "buttonUpdate";
buttonUpdate.Size = new Size(81, 80); buttonUpdate.Size = new Size(93, 107);
buttonUpdate.TabIndex = 2; buttonUpdate.TabIndex = 2;
buttonUpdate.UseVisualStyleBackColor = true; buttonUpdate.UseVisualStyleBackColor = true;
buttonUpdate.Click += ButtonUpd_Click; buttonUpdate.Click += ButtonUpd_Click;
@ -80,20 +98,22 @@
// //
buttonAdd.BackgroundImage = Properties.Resources.plus; buttonAdd.BackgroundImage = Properties.Resources.plus;
buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
buttonAdd.Location = new Point(33, 43); buttonAdd.Location = new Point(38, 57);
buttonAdd.Margin = new Padding(3, 4, 3, 4);
buttonAdd.Name = "buttonAdd"; buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(81, 71); buttonAdd.Size = new Size(93, 95);
buttonAdd.TabIndex = 0; buttonAdd.TabIndex = 0;
buttonAdd.UseVisualStyleBackColor = true; buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += ButtonAdd_Click; buttonAdd.Click += ButtonAdd_Click;
// //
// FormAppointments // FormAppointments
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450); ClientSize = new Size(914, 600);
Controls.Add(dataGridView); Controls.Add(dataGridView);
Controls.Add(panel); Controls.Add(panel);
Margin = new Padding(3, 4, 3, 4);
Name = "FormAppointments"; Name = "FormAppointments";
Text = "Назначения"; Text = "Назначения";
Load += FormAppointments_Load; Load += FormAppointments_Load;
@ -108,5 +128,6 @@
private Panel panel; private Panel panel;
private Button buttonUpdate; private Button buttonUpdate;
private Button buttonAdd; private Button buttonAdd;
private Button buttonRemove;
} }
} }

View File

@ -1,4 +1,5 @@
using ITServiceManager.Repositories; using ITServiceManager.Repositories;
using ITServiceManager.Repositories.Implementations;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
@ -76,6 +77,27 @@ namespace ITServiceManager.Forms
id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
return true; return true;
} }
private void buttonRemove_Click(object sender, EventArgs e)
{
if (!TryGetIdentifierFromSelectedRow(out var findId))
{
return;
}
if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes)
{
return;
}
try
{
_appointmentRepository.DeleteAppointment(findId);
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
} }
} }

View File

@ -91,6 +91,7 @@
dataGridView.AllowUserToDeleteRows = false; dataGridView.AllowUserToDeleteRows = false;
dataGridView.AllowUserToResizeColumns = false; dataGridView.AllowUserToResizeColumns = false;
dataGridView.AllowUserToResizeRows = false; dataGridView.AllowUserToResizeRows = false;
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Dock = DockStyle.Fill; dataGridView.Dock = DockStyle.Fill;
dataGridView.Location = new Point(0, 0); dataGridView.Location = new Point(0, 0);

View File

@ -51,7 +51,6 @@
textBoxName.Name = "textBoxName"; textBoxName.Name = "textBoxName";
textBoxName.Size = new Size(200, 23); textBoxName.Size = new Size(200, 23);
textBoxName.TabIndex = 1; textBoxName.TabIndex = 1;
textBoxName.TextChanged += textBoxName_TextChanged;
// //
// buttonAdd // buttonAdd
// //

View File

@ -1,18 +1,7 @@
using ITServiceManager.Entities; using ITServiceManager.Entities;
using ITServiceManager.Repositories; using ITServiceManager.Repositories;
using ITServiceManager.Repositories.Implementations; namespace ITServiceManager.Forms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ITServiceManager.Forms
{
public partial class FormCompany : Form public partial class FormCompany : Form
{ {
private readonly ICompanyRepository _companyRepository; private readonly ICompanyRepository _companyRepository;
@ -71,9 +60,4 @@ namespace ITServiceManager.Forms
private void ButtonCancel_Click(object sender, EventArgs e) => Close(); private void ButtonCancel_Click(object sender, EventArgs e) => Close();
private Company CreateCompany(int id) => Company.CreateEntity(id, textBoxName.Text, textBoxAddress.Text); private Company CreateCompany(int id) => Company.CreateEntity(id, textBoxName.Text, textBoxAddress.Text);
private void textBoxName_TextChanged(object sender, EventArgs e)
{
}
}
} }

View File

@ -43,18 +43,20 @@
panel.Controls.Add(buttonRemove); panel.Controls.Add(buttonRemove);
panel.Controls.Add(buttonAdd); panel.Controls.Add(buttonAdd);
panel.Dock = DockStyle.Right; panel.Dock = DockStyle.Right;
panel.Location = new Point(652, 0); panel.Location = new Point(745, 0);
panel.Margin = new Padding(3, 4, 3, 4);
panel.Name = "panel"; panel.Name = "panel";
panel.Size = new Size(148, 450); panel.Size = new Size(169, 600);
panel.TabIndex = 2; panel.TabIndex = 2;
// //
// buttonUpdate // buttonUpdate
// //
buttonUpdate.BackgroundImage = Properties.Resources.edit; buttonUpdate.BackgroundImage = Properties.Resources.edit;
buttonUpdate.BackgroundImageLayout = ImageLayout.Stretch; buttonUpdate.BackgroundImageLayout = ImageLayout.Stretch;
buttonUpdate.Location = new Point(36, 249); buttonUpdate.Location = new Point(41, 332);
buttonUpdate.Margin = new Padding(3, 4, 3, 4);
buttonUpdate.Name = "buttonUpdate"; buttonUpdate.Name = "buttonUpdate";
buttonUpdate.Size = new Size(78, 80); buttonUpdate.Size = new Size(89, 107);
buttonUpdate.TabIndex = 2; buttonUpdate.TabIndex = 2;
buttonUpdate.UseVisualStyleBackColor = true; buttonUpdate.UseVisualStyleBackColor = true;
buttonUpdate.Click += ButtonUpd_Click; buttonUpdate.Click += ButtonUpd_Click;
@ -63,9 +65,10 @@
// //
buttonRemove.BackgroundImage = Properties.Resources.minus; buttonRemove.BackgroundImage = Properties.Resources.minus;
buttonRemove.BackgroundImageLayout = ImageLayout.Stretch; buttonRemove.BackgroundImageLayout = ImageLayout.Stretch;
buttonRemove.Location = new Point(36, 141); buttonRemove.Location = new Point(41, 188);
buttonRemove.Margin = new Padding(3, 4, 3, 4);
buttonRemove.Name = "buttonRemove"; buttonRemove.Name = "buttonRemove";
buttonRemove.Size = new Size(75, 76); buttonRemove.Size = new Size(86, 101);
buttonRemove.TabIndex = 1; buttonRemove.TabIndex = 1;
buttonRemove.UseVisualStyleBackColor = true; buttonRemove.UseVisualStyleBackColor = true;
buttonRemove.Click += ButtonDel_Click; buttonRemove.Click += ButtonDel_Click;
@ -74,9 +77,10 @@
// //
buttonAdd.BackgroundImage = Properties.Resources.plus; buttonAdd.BackgroundImage = Properties.Resources.plus;
buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
buttonAdd.Location = new Point(33, 43); buttonAdd.Location = new Point(38, 57);
buttonAdd.Margin = new Padding(3, 4, 3, 4);
buttonAdd.Name = "buttonAdd"; buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(81, 71); buttonAdd.Size = new Size(93, 95);
buttonAdd.TabIndex = 0; buttonAdd.TabIndex = 0;
buttonAdd.UseVisualStyleBackColor = true; buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += ButtonAdd_Click; buttonAdd.Click += ButtonAdd_Click;
@ -87,9 +91,11 @@
dataGridView.AllowUserToDeleteRows = false; dataGridView.AllowUserToDeleteRows = false;
dataGridView.AllowUserToResizeColumns = false; dataGridView.AllowUserToResizeColumns = false;
dataGridView.AllowUserToResizeRows = false; dataGridView.AllowUserToResizeRows = false;
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Dock = DockStyle.Fill; dataGridView.Dock = DockStyle.Fill;
dataGridView.Location = new Point(0, 0); dataGridView.Location = new Point(0, 0);
dataGridView.Margin = new Padding(3, 4, 3, 4);
dataGridView.MultiSelect = false; dataGridView.MultiSelect = false;
dataGridView.Name = "dataGridView"; dataGridView.Name = "dataGridView";
dataGridView.ReadOnly = true; dataGridView.ReadOnly = true;
@ -97,17 +103,16 @@
dataGridView.RowHeadersWidth = 51; dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 25; dataGridView.RowTemplate.Height = 25;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.Size = new Size(652, 450); dataGridView.Size = new Size(745, 600);
dataGridView.TabIndex = 3; dataGridView.TabIndex = 3;
// //
// FormEmployees // FormEmployees
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450); ClientSize = new Size(914, 600);
Controls.Add(dataGridView); Controls.Add(dataGridView);
Controls.Add(panel); Controls.Add(panel);
Margin = new Padding(3, 2, 3, 2);
Name = "FormEmployees"; Name = "FormEmployees";
StartPosition = FormStartPosition.CenterScreen; StartPosition = FormStartPosition.CenterScreen;
Text = "Сотрудники"; Text = "Сотрудники";

View File

@ -122,7 +122,7 @@
// label2 // label2
// //
label2.AutoSize = true; label2.AutoSize = true;
label2.Location = new Point(59, 164); label2.Location = new Point(59, 200);
label2.Name = "label2"; label2.Name = "label2";
label2.Size = new Size(125, 20); label2.Size = new Size(125, 20);
label2.TabIndex = 12; label2.TabIndex = 12;
@ -131,7 +131,8 @@
// numericUpDownPrice // numericUpDownPrice
// //
numericUpDownPrice.DecimalPlaces = 2; numericUpDownPrice.DecimalPlaces = 2;
numericUpDownPrice.Location = new Point(207, 161); numericUpDownPrice.Increment = new decimal(new int[] { 100, 0, 0, 0 });
numericUpDownPrice.Location = new Point(207, 197);
numericUpDownPrice.Margin = new Padding(3, 4, 3, 4); numericUpDownPrice.Margin = new Padding(3, 4, 3, 4);
numericUpDownPrice.Maximum = new decimal(new int[] { 1000000, 0, 0, 0 }); numericUpDownPrice.Maximum = new decimal(new int[] { 1000000, 0, 0, 0 });
numericUpDownPrice.Name = "numericUpDownPrice"; numericUpDownPrice.Name = "numericUpDownPrice";

View File

@ -1,18 +1,7 @@
using ITServiceManager.Entities; using ITServiceManager.Entities;
using ITServiceManager.Repositories; using ITServiceManager.Repositories;
using System; namespace ITServiceManager.Forms;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
namespace ITServiceManager.Forms
{
public partial class FormOrder : Form public partial class FormOrder : Form
{ {
private readonly IOrderRepository _orderRepository; private readonly IOrderRepository _orderRepository;
@ -28,6 +17,7 @@ namespace ITServiceManager.Forms
ColumnService.DataSource = serviceRepository.ReadServices(); ColumnService.DataSource = serviceRepository.ReadServices();
ColumnService.DisplayMember = "ServiceType"; ColumnService.DisplayMember = "ServiceType";
ColumnService.ValueMember = "Id"; ColumnService.ValueMember = "Id";
} }
private void ButtonAdd_Click(object sender, EventArgs e) private void ButtonAdd_Click(object sender, EventArgs e)
{ {
@ -37,7 +27,7 @@ namespace ITServiceManager.Forms
} }
try try
{ {
_orderRepository.CreateOrder(Order.CreateOperation(0, comboBoxCompany.SelectedIndex, numericUpDownPrice.Value, CreateListServiceFromDataGrid())); _orderRepository.CreateOrder(Order.CreateOperation(0, (int)comboBoxCompany.SelectedValue!, numericUpDownPrice.Value, CreateListServiceFromDataGrid()));
Close(); Close();
} }
catch (Exception ex) catch (Exception ex)
@ -51,14 +41,13 @@ namespace ITServiceManager.Forms
var list = new List<OrderService>(); var list = new List<OrderService>();
foreach (DataGridViewRow row in dataGridView.Rows) foreach (DataGridViewRow row in dataGridView.Rows)
{ {
if (row.Cells["ColumService"].Value == null || row.Cells["ColumQuantity"].Value == null || row.Cells["ColumnExecutionDate"].Value == null) if (row.Cells["ColumnService"].Value == null || row.Cells["ColumnQuantity"].Value == null || row.Cells["ColumnExecutionDate"].Value == null)
{ {
continue; continue;
} }
list.Add(OrderService.CreateOperation(0, 0, Convert.ToInt32(row.Cells["ColumnServices"].Value), Convert.ToInt32(row.Cells["ColumnQuantity"].Value), Convert.ToDateTime(row.Cells["ColumnExecutionDate"].Value))); list.Add(OrderService.CreateOperation(0, Convert.ToInt32(row.Cells["ColumnService"].Value), Convert.ToInt32(row.Cells["ColumnQuantity"].Value), Convert.ToDateTime(row.Cells["ColumnExecutionDate"].Value)));
} }
return list; return list;
} }
} }
}

View File

@ -41,18 +41,20 @@
panel.Controls.Add(buttonRemove); panel.Controls.Add(buttonRemove);
panel.Controls.Add(buttonAdd); panel.Controls.Add(buttonAdd);
panel.Dock = DockStyle.Right; panel.Dock = DockStyle.Right;
panel.Location = new Point(652, 0); panel.Location = new Point(745, 0);
panel.Margin = new Padding(3, 4, 3, 4);
panel.Name = "panel"; panel.Name = "panel";
panel.Size = new Size(148, 450); panel.Size = new Size(169, 600);
panel.TabIndex = 4; panel.TabIndex = 4;
// //
// buttonRemove // buttonRemove
// //
buttonRemove.BackgroundImage = Properties.Resources.minus; buttonRemove.BackgroundImage = Properties.Resources.minus;
buttonRemove.BackgroundImageLayout = ImageLayout.Stretch; buttonRemove.BackgroundImageLayout = ImageLayout.Stretch;
buttonRemove.Location = new Point(39, 265); buttonRemove.Location = new Point(45, 353);
buttonRemove.Margin = new Padding(3, 4, 3, 4);
buttonRemove.Name = "buttonRemove"; buttonRemove.Name = "buttonRemove";
buttonRemove.Size = new Size(75, 76); buttonRemove.Size = new Size(86, 101);
buttonRemove.TabIndex = 1; buttonRemove.TabIndex = 1;
buttonRemove.UseVisualStyleBackColor = true; buttonRemove.UseVisualStyleBackColor = true;
buttonRemove.Click += ButtonRemove_Click; buttonRemove.Click += ButtonRemove_Click;
@ -61,9 +63,10 @@
// //
buttonAdd.BackgroundImage = Properties.Resources.plus; buttonAdd.BackgroundImage = Properties.Resources.plus;
buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
buttonAdd.Location = new Point(33, 92); buttonAdd.Location = new Point(38, 123);
buttonAdd.Margin = new Padding(3, 4, 3, 4);
buttonAdd.Name = "buttonAdd"; buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(81, 71); buttonAdd.Size = new Size(93, 95);
buttonAdd.TabIndex = 0; buttonAdd.TabIndex = 0;
buttonAdd.UseVisualStyleBackColor = true; buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += ButtonAdd_Click; buttonAdd.Click += ButtonAdd_Click;
@ -74,9 +77,11 @@
dataGridView.AllowUserToDeleteRows = false; dataGridView.AllowUserToDeleteRows = false;
dataGridView.AllowUserToResizeColumns = false; dataGridView.AllowUserToResizeColumns = false;
dataGridView.AllowUserToResizeRows = false; dataGridView.AllowUserToResizeRows = false;
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Dock = DockStyle.Fill; dataGridView.Dock = DockStyle.Fill;
dataGridView.Location = new Point(0, 0); dataGridView.Location = new Point(0, 0);
dataGridView.Margin = new Padding(3, 4, 3, 4);
dataGridView.MultiSelect = false; dataGridView.MultiSelect = false;
dataGridView.Name = "dataGridView"; dataGridView.Name = "dataGridView";
dataGridView.ReadOnly = true; dataGridView.ReadOnly = true;
@ -84,16 +89,17 @@
dataGridView.RowHeadersWidth = 51; dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 25; dataGridView.RowTemplate.Height = 25;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.Size = new Size(652, 450); dataGridView.Size = new Size(745, 600);
dataGridView.TabIndex = 5; dataGridView.TabIndex = 5;
// //
// FormOrders // FormOrders
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450); ClientSize = new Size(914, 600);
Controls.Add(dataGridView); Controls.Add(dataGridView);
Controls.Add(panel); Controls.Add(panel);
Margin = new Padding(3, 4, 3, 4);
Name = "FormOrders"; Name = "FormOrders";
StartPosition = FormStartPosition.CenterScreen; StartPosition = FormStartPosition.CenterScreen;
Text = "Заказы"; Text = "Заказы";

View File

@ -91,6 +91,7 @@
dataGridView.AllowUserToDeleteRows = false; dataGridView.AllowUserToDeleteRows = false;
dataGridView.AllowUserToResizeColumns = false; dataGridView.AllowUserToResizeColumns = false;
dataGridView.AllowUserToResizeRows = false; dataGridView.AllowUserToResizeRows = false;
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Dock = DockStyle.Fill; dataGridView.Dock = DockStyle.Fill;
dataGridView.Location = new Point(0, 0); dataGridView.Location = new Point(0, 0);

View File

@ -11,9 +11,9 @@
<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="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" /> <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" /> <PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Npgsql" Version="8.0.5" /> <PackageReference Include="Npgsql" Version="8.0.5" />
<PackageReference Include="Serilog" Version="4.1.0" /> <PackageReference Include="Serilog" Version="4.1.0" />

View File

@ -8,4 +8,6 @@ public interface IAppointmentRepository
Appointment ReadAppointmentById(int id); Appointment ReadAppointmentById(int id);
void CreateAppointment(Appointment appointment); void CreateAppointment(Appointment appointment);
void UpdateAppointment(Appointment appointment); void UpdateAppointment(Appointment appointment);
void DeleteAppointment(int id);
} }

View File

@ -5,7 +5,6 @@ namespace ITServiceManager.Repositories;
public interface IOrderRepository public interface IOrderRepository
{ {
IEnumerable<Order> ReadOrders(DateTime? dateForm = null, DateTime? dateTo = null, int? orderId = null, int? companyId = null); IEnumerable<Order> ReadOrders(DateTime? dateForm = null, DateTime? dateTo = null, int? orderId = null, int? companyId = null);
Order ReadOrderById(int orderId);
void CreateOrder(Order order); void CreateOrder(Order order);
void DeleteOrder(int id); void DeleteOrder(int id);
} }

View File

@ -22,9 +22,9 @@ public class AppointmentRepository : IAppointmentRepository
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"SELECT * FROM Appointments"; var querySelect = @"SELECT * FROM Appointments";
var order = connection.Query<Appointment>(querySelect); var appointment = connection.Query<Appointment>(querySelect);
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(order)); _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(appointment));
return order; return appointment;
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -34,14 +34,84 @@ public class AppointmentRepository : IAppointmentRepository
} }
public Appointment ReadAppointmentById(int id) public Appointment ReadAppointmentById(int id)
{ {
return null; _logger.LogInformation("Получение объекта по идентификатору");
_logger.LogDebug("Объект: {id}", id);
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"
SELECT * FROM Appointments
WHERE Id=@id";
var appointment = connection.QueryFirst<Appointment>(querySelect, new
{
id
});
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(appointment));
return appointment;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при поиске объекта");
throw;
}
} }
public void CreateAppointment(Appointment appointment) public void CreateAppointment(Appointment appointment)
{ {
_logger.LogInformation("Добавление объекта");
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(appointment));
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryInsert = @"
INSERT INTO Appointments (EmployeeId, OrderId, StartDate, EndDate)
VALUES (@EmployeeId, @OrderId, @StartDate, @EndDate)";
connection.Execute(queryInsert, appointment);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при добавлении объекта");
throw;
}
} }
public void UpdateAppointment(Appointment appointment) public void UpdateAppointment(Appointment appointment)
{ {
_logger.LogInformation("Редактирование объекта");
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(appointment));
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryUpdate = @"
UPDATE Appointments
SET
EmployeeId=@EmployeeId,
OrderId=@OrderId,
StartDate=@StartDate,
EndDate=@EndDate
WHERE Id=@Id";
connection.Execute(queryUpdate, appointment);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при редактировании объекта");
throw;
}
}
public void DeleteAppointment(int id)
{
_logger.LogInformation("Удаление объекта");
_logger.LogDebug("Объект: {id}", id);
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryDelete = @"
DELETE FROM Appointments
WHERE Id=@id";
connection.Execute(queryDelete, new { id });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при удалении объекта");
throw;
}
} }
} }

View File

@ -85,7 +85,7 @@ public class CompanyRepository : ICompanyRepository
UPDATE Companies UPDATE Companies
SET SET
Name=@Name, Name=@Name,
Address=@Address, Address=@Address
WHERE Id=@Id"; WHERE Id=@Id";
connection.Execute(queryUpdate, company); connection.Execute(queryUpdate, company);
} }

View File

@ -2,5 +2,5 @@
internal class ConnectionString : IConnectionString internal class ConnectionString : IConnectionString
{ {
string IConnectionString.ConnectionString => "Server=localhost;Port=5432;Database=itcompany;"; string IConnectionString.ConnectionString => "Server=localhost;Port=5432;Database=It-company;Username=postgres;Password=postgres;";
} }

View File

@ -1,23 +1,89 @@
using ITServiceManager.Entities; using Dapper;
using ITServiceManager.Entities;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Npgsql;
namespace ITServiceManager.Repositories.Implementations; namespace ITServiceManager.Repositories.Implementations;
public class OrderRepository : IOrderRepository public class OrderRepository : IOrderRepository
{ {
private readonly IConnectionString _connectionString;
private readonly ILogger<Order> _logger;
public OrderRepository(IConnectionString connectionString, ILogger<Order> logger)
{
_connectionString = connectionString;
_logger = logger;
}
public IEnumerable<Order> ReadOrders(DateTime? dateForm = null, DateTime? dateTo = null, int? orderId = null, int? companyId = null) public IEnumerable<Order> ReadOrders(DateTime? dateForm = null, DateTime? dateTo = null, int? orderId = null, int? companyId = null)
{ {
return []; _logger.LogInformation("Получение всех объектов");
} try
public Order ReadOrderById(int orderId)
{ {
return null; using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"SELECT * FROM Orders";
var order = connection.Query<Order>(querySelect);
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(order));
return order;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при чтении объектов");
throw;
}
} }
public void CreateOrder(Order order) public void CreateOrder(Order order)
{ {
_logger.LogInformation("Добавление объекта");
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(order));
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
connection.Open();
using var transaction = connection.BeginTransaction();
var queryInsert = @"
INSERT INTO Orders (CompanyId, Price)
VALUES (@CompanyId, @Price);
SELECT MAX(Id) FROM Orders";
var orderId = connection.QueryFirst<int>(queryInsert, order, transaction);
var querySubInsert = @"
INSERT INTO Order_Service (OrderId, ServiceId, Quantity, ExecutionDate)
VALUES (@OrderId, @ServiceId, @Quantity, @ExecutionDate)";
foreach (var elem in order.OrderService)
{
connection.Execute(querySubInsert, new
{
orderId,
elem.ServiceId,
elem.Quantity,
elem.ExecutionDate
}, transaction);
}
transaction.Commit();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при добавлении объекта");
throw;
}
} }
public void DeleteOrder(int id) public void DeleteOrder(int id)
{ {
_logger.LogInformation("Удаление объекта");
_logger.LogDebug("Объект: {id}", id);
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryDelete = @"
DELETE FROM Orders
WHERE Id=@id";
connection.Execute(queryDelete, new { id });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при удалении объекта");
throw;
}
} }
} }

View File

@ -64,8 +64,8 @@ public class ServiceRepository : IServiceRepository
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryInsert = @" var queryInsert = @"
INSERT INTO Services (Name, ServiceType, Description) INSERT INTO Services (ServiceType, Description)
VALUES (@Name, @ServiceType, @Description)"; VALUES (@ServiceType, @Description)";
connection.Execute(queryInsert, service); connection.Execute(queryInsert, service);
} }
catch (Exception ex) catch (Exception ex)
@ -85,7 +85,7 @@ public class ServiceRepository : IServiceRepository
UPDATE Services UPDATE Services
SET SET
ServiceType=@ServiceType, ServiceType=@ServiceType,
Description=@Description, Description=@Description
WHERE Id=@Id"; WHERE Id=@Id";
connection.Execute(queryUpdate, service); connection.Execute(queryUpdate, service);
} }