Лабораторная работа №1

This commit is contained in:
Егор Васин 2024-12-14 16:11:17 +03:00
parent 0c9c6f8496
commit e422a50929
27 changed files with 225 additions and 203 deletions

View File

@ -6,12 +6,15 @@ public class Client
public string Name { get; private set; } = string.Empty; public string Name { get; private set; } = string.Empty;
public static Client CreateEntity(int id, string name) public string LegalForm { get; private set; } = string.Empty;
public static Client CreateEntity(int id, string name, string legalForm)
{ {
return new Client return new Client
{ {
Id = id, Id = id,
Name = name ?? string.Empty Name = name ?? string.Empty,
LegalForm = legalForm ?? string.Empty
}; };
} }
} }

View File

@ -12,16 +12,16 @@ public class Contract
public int Amount { get; private set; } public int Amount { get; private set; }
public DateTime Deadline { get; private set; } public DateTime StartDate { get; private set; }
public Status Status { get; private set; } public DateTime Deadline { get; private set; }
public ContractType ContractType { get; private set; } public ContractType ContractType { get; private set; }
public IEnumerable<Service> Services { get; private set; } = []; public IEnumerable<ServiceContract> ServiceContracts { get; private set; } = [];
public static Contract CreateEntity(int id, int clientId, int contractorId, int amount, public static Contract CreateEntity(int id, int clientId, int contractorId, int amount,
DateTime deadline, Status status, ContractType contractType, IEnumerable<Service> services) DateTime deadline, ContractType contractType, IEnumerable<ServiceContract> serviceContracts)
{ {
return new Contract return new Contract
{ {
@ -29,10 +29,10 @@ public class Contract
ClientId = clientId, ClientId = clientId,
ContractorId = contractorId, ContractorId = contractorId,
Amount = amount, Amount = amount,
StartDate = DateTime.Now,
Deadline = deadline, Deadline = deadline,
Status = status,
ContractType = contractType, ContractType = contractType,
Services = services ServiceContracts = serviceContracts
}; };
} }
} }

View File

@ -6,12 +6,15 @@ public class Contractor
public string Name { get; private set; } = string.Empty; public string Name { get; private set; } = string.Empty;
public static Contractor CreateEntity(int id, string name) public string Surname { get; private set; } = string.Empty;
public static Contractor CreateEntity(int id, string name, string surname)
{ {
return new Contractor return new Contractor
{ {
Id = id, Id = id,
Name = name ?? string.Empty Name = name ?? string.Empty,
Surname = surname ?? string.Empty
}; };
} }
} }

View File

@ -0,0 +1,12 @@
namespace ISEbd_22_Vasin_E.D._It_Company.Entities.Enums;
public enum VacationType
{
None = 0,
Paid = 1,
NonPaid = 2,
Maternity = 3
}

View File

@ -1,4 +1,4 @@
namespace OISEbd_22_Vasin_E.D._It_CompanyTP.Entities; namespace ISEbd_22_Vasin_E.D._It_Company.Entities;
public class ServiceContract public class ServiceContract
{ {
@ -6,15 +6,12 @@ public class ServiceContract
public int ServiceId { get; private set; } public int ServiceId { get; private set; }
public int ContractId { get; private set; } public static ServiceContract CreateElement(int id, int serviceId)
public static ServiceContract CreateElement(int id, int serviceId, int contractId)
{ {
return new ServiceContract return new ServiceContract
{ {
Id = id, Id = id,
ServiceId = serviceId, ServiceId = serviceId
ContractId = contractId
}; };
} }
} }

View File

@ -1,4 +1,6 @@
namespace ISEbd_22_Vasin_E.D._It_Company.Entities; using ISEbd_22_Vasin_E.D._It_Company.Entities.Enums;
namespace ISEbd_22_Vasin_E.D._It_Company.Entities;
public class Vacation public class Vacation
{ {
@ -8,13 +10,16 @@ public class Vacation
public DateTime EndDate { get; private set; } public DateTime EndDate { get; private set; }
public static Vacation CreateEntity(int id, DateTime startDate, DateTime endDate) public VacationType VacationType { get; private set; }
public static Vacation CreateEntity(int id, DateTime startDate, DateTime endDate, VacationType vacationType)
{ {
return new Vacation return new Vacation
{ {
Id = id, Id = id,
StartDate = startDate, StartDate = startDate,
EndDate = endDate EndDate = endDate,
VacationType = vacationType
}; };
} }
} }

View File

@ -32,6 +32,8 @@
textBoxName = new TextBox(); textBoxName = new TextBox();
buttonCancel = new Button(); buttonCancel = new Button();
buttonSave = new Button(); buttonSave = new Button();
textBoxLegalForm = new TextBox();
labelLegalForm = new Label();
SuspendLayout(); SuspendLayout();
// //
// labelName // labelName
@ -45,14 +47,14 @@
// //
// textBoxName // textBoxName
// //
textBoxName.Location = new Point(51, 12); textBoxName.Location = new Point(103, 12);
textBoxName.Name = "textBoxName"; textBoxName.Name = "textBoxName";
textBoxName.Size = new Size(217, 23); textBoxName.Size = new Size(187, 23);
textBoxName.TabIndex = 1; textBoxName.TabIndex = 1;
// //
// buttonCancel // buttonCancel
// //
buttonCancel.Location = new Point(151, 41); buttonCancel.Location = new Point(173, 77);
buttonCancel.Name = "buttonCancel"; buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(117, 23); buttonCancel.Size = new Size(117, 23);
buttonCancel.TabIndex = 10; buttonCancel.TabIndex = 10;
@ -62,7 +64,7 @@
// //
// buttonSave // buttonSave
// //
buttonSave.Location = new Point(11, 41); buttonSave.Location = new Point(12, 77);
buttonSave.Name = "buttonSave"; buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(117, 23); buttonSave.Size = new Size(117, 23);
buttonSave.TabIndex = 9; buttonSave.TabIndex = 9;
@ -70,11 +72,29 @@
buttonSave.UseVisualStyleBackColor = true; buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += ButtonSave_Click; buttonSave.Click += ButtonSave_Click;
// //
// textBoxLegalForm
//
textBoxLegalForm.Location = new Point(103, 48);
textBoxLegalForm.Name = "textBoxLegalForm";
textBoxLegalForm.Size = new Size(187, 23);
textBoxLegalForm.TabIndex = 14;
//
// labelLegalForm
//
labelLegalForm.AutoSize = true;
labelLegalForm.Location = new Point(11, 41);
labelLegalForm.Name = "labelLegalForm";
labelLegalForm.Size = new Size(86, 30);
labelLegalForm.TabIndex = 13;
labelLegalForm.Text = "Юридическая \r\nформа:";
//
// FormClient // FormClient
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(283, 75); ClientSize = new Size(300, 113);
Controls.Add(textBoxLegalForm);
Controls.Add(labelLegalForm);
Controls.Add(buttonCancel); Controls.Add(buttonCancel);
Controls.Add(buttonSave); Controls.Add(buttonSave);
Controls.Add(textBoxName); Controls.Add(textBoxName);
@ -92,5 +112,7 @@
private TextBox textBoxName; private TextBox textBoxName;
private Button buttonCancel; private Button buttonCancel;
private Button buttonSave; private Button buttonSave;
private TextBox textBoxLegalForm;
private Label labelLegalForm;
} }
} }

View File

@ -22,6 +22,7 @@ namespace ISEbd_22_Vasin_E.D._It_Company.Forms
} }
textBoxName.Text = client.Name; textBoxName.Text = client.Name;
textBoxLegalForm.Text = client.LegalForm;
_clientId = value; _clientId = value;
} }
catch (Exception ex) catch (Exception ex)
@ -42,7 +43,8 @@ namespace ISEbd_22_Vasin_E.D._It_Company.Forms
{ {
try try
{ {
if (string.IsNullOrEmpty(textBoxName.Text)) if (string.IsNullOrEmpty(textBoxName.Text) ||
string.IsNullOrEmpty(textBoxLegalForm.Text))
{ {
throw new Exception("Имеются незаполненные поля"); throw new Exception("Имеются незаполненные поля");
} }
@ -50,12 +52,12 @@ namespace ISEbd_22_Vasin_E.D._It_Company.Forms
if (_clientId.HasValue) if (_clientId.HasValue)
{ {
_clientRepository.UpdateClient(Client.CreateEntity(_clientId.Value, _clientRepository.UpdateClient(Client.CreateEntity(_clientId.Value,
textBoxName.Text)); textBoxName.Text, textBoxLegalForm.Text));
} }
else else
{ {
_clientRepository.CreateClient(Client.CreateEntity(0, _clientRepository.CreateClient(Client.CreateEntity(0,
textBoxName.Text)); textBoxName.Text, textBoxLegalForm.Text));
} }
Close(); Close();

View File

@ -36,15 +36,13 @@
comboBoxContractor = new ComboBox(); comboBoxContractor = new ComboBox();
labelDeadline = new Label(); labelDeadline = new Label();
dateTimePickerDeadline = new DateTimePicker(); dateTimePickerDeadline = new DateTimePicker();
labelStatus = new Label();
comboBoxStatus = new ComboBox();
checkedListBoxContractType = new CheckedListBox(); checkedListBoxContractType = new CheckedListBox();
labelContractType = new Label(); labelContractType = new Label();
groupBoxServices = new GroupBox(); groupBoxServices = new GroupBox();
dataGridViewServices = new DataGridView(); dataGridViewServices = new DataGridView();
ColumnServiceName = new DataGridViewComboBoxColumn();
buttonCancel = new Button(); buttonCancel = new Button();
buttonSave = new Button(); buttonSave = new Button();
ColumnServiceName = new DataGridViewComboBoxColumn();
((System.ComponentModel.ISupportInitialize)numericUpDownAmount).BeginInit(); ((System.ComponentModel.ISupportInitialize)numericUpDownAmount).BeginInit();
groupBoxServices.SuspendLayout(); groupBoxServices.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridViewServices).BeginInit(); ((System.ComponentModel.ISupportInitialize)dataGridViewServices).BeginInit();
@ -70,7 +68,9 @@
// //
// numericUpDownAmount // numericUpDownAmount
// //
numericUpDownAmount.Increment = new decimal(new int[] { 10000, 0, 0, 0 });
numericUpDownAmount.Location = new Point(117, 70); numericUpDownAmount.Location = new Point(117, 70);
numericUpDownAmount.Maximum = new decimal(new int[] { 1000000000, 0, 0, 0 });
numericUpDownAmount.Name = "numericUpDownAmount"; numericUpDownAmount.Name = "numericUpDownAmount";
numericUpDownAmount.Size = new Size(199, 23); numericUpDownAmount.Size = new Size(199, 23);
numericUpDownAmount.TabIndex = 2; numericUpDownAmount.TabIndex = 2;
@ -116,27 +116,10 @@
dateTimePickerDeadline.Size = new Size(200, 23); dateTimePickerDeadline.Size = new Size(200, 23);
dateTimePickerDeadline.TabIndex = 7; dateTimePickerDeadline.TabIndex = 7;
// //
// labelStatus
//
labelStatus.AutoSize = true;
labelStatus.Location = new Point(12, 131);
labelStatus.Name = "labelStatus";
labelStatus.Size = new Size(46, 15);
labelStatus.TabIndex = 8;
labelStatus.Text = "Статус:";
//
// comboBoxStatus
//
comboBoxStatus.FormattingEnabled = true;
comboBoxStatus.Location = new Point(117, 128);
comboBoxStatus.Name = "comboBoxStatus";
comboBoxStatus.Size = new Size(200, 23);
comboBoxStatus.TabIndex = 9;
//
// checkedListBoxContractType // checkedListBoxContractType
// //
checkedListBoxContractType.FormattingEnabled = true; checkedListBoxContractType.FormattingEnabled = true;
checkedListBoxContractType.Location = new Point(117, 157); checkedListBoxContractType.Location = new Point(117, 128);
checkedListBoxContractType.Name = "checkedListBoxContractType"; checkedListBoxContractType.Name = "checkedListBoxContractType";
checkedListBoxContractType.Size = new Size(199, 58); checkedListBoxContractType.Size = new Size(199, 58);
checkedListBoxContractType.TabIndex = 10; checkedListBoxContractType.TabIndex = 10;
@ -144,7 +127,7 @@
// labelContractType // labelContractType
// //
labelContractType.AutoSize = true; labelContractType.AutoSize = true;
labelContractType.Location = new Point(12, 166); labelContractType.Location = new Point(12, 137);
labelContractType.Name = "labelContractType"; labelContractType.Name = "labelContractType";
labelContractType.Size = new Size(89, 15); labelContractType.Size = new Size(89, 15);
labelContractType.TabIndex = 11; labelContractType.TabIndex = 11;
@ -153,7 +136,7 @@
// groupBoxServices // groupBoxServices
// //
groupBoxServices.Controls.Add(dataGridViewServices); groupBoxServices.Controls.Add(dataGridViewServices);
groupBoxServices.Location = new Point(12, 221); groupBoxServices.Location = new Point(12, 192);
groupBoxServices.Name = "groupBoxServices"; groupBoxServices.Name = "groupBoxServices";
groupBoxServices.Size = new Size(305, 246); groupBoxServices.Size = new Size(305, 246);
groupBoxServices.TabIndex = 12; groupBoxServices.TabIndex = 12;
@ -174,9 +157,17 @@
dataGridViewServices.Size = new Size(299, 224); dataGridViewServices.Size = new Size(299, 224);
dataGridViewServices.TabIndex = 0; dataGridViewServices.TabIndex = 0;
// //
// ColumnServiceName
//
ColumnServiceName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
ColumnServiceName.HeaderText = "Название услуги";
ColumnServiceName.Name = "ColumnServiceName";
ColumnServiceName.Resizable = DataGridViewTriState.True;
ColumnServiceName.SortMode = DataGridViewColumnSortMode.Automatic;
//
// buttonCancel // buttonCancel
// //
buttonCancel.Location = new Point(200, 470); buttonCancel.Location = new Point(200, 441);
buttonCancel.Name = "buttonCancel"; buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(117, 23); buttonCancel.Size = new Size(117, 23);
buttonCancel.TabIndex = 14; buttonCancel.TabIndex = 14;
@ -186,7 +177,7 @@
// //
// buttonSave // buttonSave
// //
buttonSave.Location = new Point(12, 470); buttonSave.Location = new Point(12, 441);
buttonSave.Name = "buttonSave"; buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(117, 23); buttonSave.Size = new Size(117, 23);
buttonSave.TabIndex = 13; buttonSave.TabIndex = 13;
@ -194,26 +185,16 @@
buttonSave.UseVisualStyleBackColor = true; buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += ButtonSave_Click; buttonSave.Click += ButtonSave_Click;
// //
// ColumnServiceName
//
ColumnServiceName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
ColumnServiceName.HeaderText = "Название услуги";
ColumnServiceName.Name = "ColumnServiceName";
ColumnServiceName.Resizable = DataGridViewTriState.True;
ColumnServiceName.SortMode = DataGridViewColumnSortMode.Automatic;
//
// FormContract // FormContract
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(332, 504); ClientSize = new Size(332, 474);
Controls.Add(buttonCancel); Controls.Add(buttonCancel);
Controls.Add(buttonSave); Controls.Add(buttonSave);
Controls.Add(groupBoxServices); Controls.Add(groupBoxServices);
Controls.Add(labelContractType); Controls.Add(labelContractType);
Controls.Add(checkedListBoxContractType); Controls.Add(checkedListBoxContractType);
Controls.Add(comboBoxStatus);
Controls.Add(labelStatus);
Controls.Add(dateTimePickerDeadline); Controls.Add(dateTimePickerDeadline);
Controls.Add(labelDeadline); Controls.Add(labelDeadline);
Controls.Add(comboBoxContractor); Controls.Add(comboBoxContractor);
@ -242,8 +223,6 @@
private ComboBox comboBoxContractor; private ComboBox comboBoxContractor;
private Label labelDeadline; private Label labelDeadline;
private DateTimePicker dateTimePickerDeadline; private DateTimePicker dateTimePickerDeadline;
private Label labelStatus;
private ComboBox comboBoxStatus;
private CheckedListBox checkedListBoxContractType; private CheckedListBox checkedListBoxContractType;
private Label labelContractType; private Label labelContractType;
private GroupBox groupBoxServices; private GroupBox groupBoxServices;

View File

@ -8,40 +8,6 @@ namespace ISEbd_22_Vasin_E.D._It_Company.Forms
{ {
private readonly IContractRepository _contractRepository; private readonly IContractRepository _contractRepository;
private int? _contractId;
public int Id
{
set
{
try
{
var contract = _contractRepository.ReadContractById(value);
if (contract == null)
{
throw new InvalidDataException(nameof(contract));
}
comboBoxClient.SelectedItem = contract.ClientId;
comboBoxContractor.SelectedItem = contract.ContractorId;
numericUpDownAmount.Value = contract.Amount;
dateTimePickerDeadline.Value = contract.Deadline;
comboBoxStatus.SelectedItem = contract.Status;
checkedListBoxContractType.Items.Clear();
foreach (ContractType type in Enum.GetValues(typeof(ContractType)))
{
checkedListBoxContractType.Items.Add(type, contract.ContractType.HasFlag(type));
}
_contractId = value;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
}
public FormContract(IContractRepository contractRepository, IClientRepository clientRepository, public FormContract(IContractRepository contractRepository, IClientRepository clientRepository,
IContractorRepository contractorRepository, IServiceRepository serviceRepository) IContractorRepository contractorRepository, IServiceRepository serviceRepository)
{ {
@ -64,8 +30,6 @@ namespace ISEbd_22_Vasin_E.D._It_Company.Forms
{ {
checkedListBoxContractType.Items.Add(elem); checkedListBoxContractType.Items.Add(elem);
} }
comboBoxStatus.DataSource = Enum.GetValues(typeof(Status));
} }
private void ButtonSave_Click(object sender, EventArgs e) private void ButtonSave_Click(object sender, EventArgs e)
@ -75,19 +39,13 @@ namespace ISEbd_22_Vasin_E.D._It_Company.Forms
if (checkedListBoxContractType.CheckedItems.Count == 0 || if (checkedListBoxContractType.CheckedItems.Count == 0 ||
comboBoxContractor.SelectedIndex < 0 || comboBoxContractor.SelectedIndex < 0 ||
comboBoxClient.SelectedIndex < 0 || comboBoxClient.SelectedIndex < 0 ||
comboBoxStatus.SelectedIndex < 0) dataGridViewServices.Rows.Count == 1)
{ {
throw new Exception("Имеются незаполненные поля"); throw new Exception("Имеются незаполненные поля");
} }
if (_contractId.HasValue) _contractRepository.CreateContract(CreateContract(0));
{
_contractRepository.UpdateContract(CreateContract(_contractId.Value));
}
else
{
_contractRepository.CreateContract(CreateContract(0));
}
Close(); Close();
} }
catch (Exception ex) catch (Exception ex)
@ -108,20 +66,20 @@ namespace ISEbd_22_Vasin_E.D._It_Company.Forms
return Contract.CreateEntity(id, (int)comboBoxClient.SelectedValue!, return Contract.CreateEntity(id, (int)comboBoxClient.SelectedValue!,
(int)comboBoxContractor.SelectedValue!, Convert.ToInt32(numericUpDownAmount.Value), (int)comboBoxContractor.SelectedValue!, Convert.ToInt32(numericUpDownAmount.Value),
dateTimePickerDeadline.Value, (Status)comboBoxStatus.SelectedItem!, contractType, dateTimePickerDeadline.Value, contractType,
CreateListServicesFromDataGrid()); CreateListServiceContractsFromDataGrid());
} }
private List<Service> CreateListServicesFromDataGrid() private List<ServiceContract> CreateListServiceContractsFromDataGrid()
{ {
var list = new List<Service>(); var list = new List<ServiceContract>();
foreach (DataGridViewRow row in dataGridViewServices.Rows) foreach (DataGridViewRow row in dataGridViewServices.Rows)
if (row.Cells["ColumnServiceName"].Value != null && if (row.Cells["ColumnServiceName"].Value != null)
row.Cells["ColumnServiceDescription"].Value != null)
{ {
list.Add(Service.CreateEntity(0, Convert.ToString(row.Cells["ColumnServiceName"].Value)!)); list.Add(ServiceContract.CreateElement(0, Convert.ToInt32(row.Cells["ColumnServiceName"].Value)));
} }
return list; return list;
} }
} }

View File

@ -32,11 +32,13 @@
buttonSave = new Button(); buttonSave = new Button();
textBoxName = new TextBox(); textBoxName = new TextBox();
labelName = new Label(); labelName = new Label();
textBoxSurname = new TextBox();
labelSurname = new Label();
SuspendLayout(); SuspendLayout();
// //
// buttonCancel // buttonCancel
// //
buttonCancel.Location = new Point(150, 41); buttonCancel.Location = new Point(150, 70);
buttonCancel.Name = "buttonCancel"; buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(117, 23); buttonCancel.Size = new Size(117, 23);
buttonCancel.TabIndex = 14; buttonCancel.TabIndex = 14;
@ -46,7 +48,7 @@
// //
// buttonSave // buttonSave
// //
buttonSave.Location = new Point(10, 41); buttonSave.Location = new Point(10, 70);
buttonSave.Name = "buttonSave"; buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(117, 23); buttonSave.Size = new Size(117, 23);
buttonSave.TabIndex = 13; buttonSave.TabIndex = 13;
@ -56,9 +58,9 @@
// //
// textBoxName // textBoxName
// //
textBoxName.Location = new Point(50, 12); textBoxName.Location = new Point(77, 12);
textBoxName.Name = "textBoxName"; textBoxName.Name = "textBoxName";
textBoxName.Size = new Size(217, 23); textBoxName.Size = new Size(190, 23);
textBoxName.TabIndex = 12; textBoxName.TabIndex = 12;
// //
// labelName // labelName
@ -70,11 +72,29 @@
labelName.TabIndex = 11; labelName.TabIndex = 11;
labelName.Text = "Имя:"; labelName.Text = "Имя:";
// //
// textBoxSurname
//
textBoxSurname.Location = new Point(77, 41);
textBoxSurname.Name = "textBoxSurname";
textBoxSurname.Size = new Size(190, 23);
textBoxSurname.TabIndex = 16;
//
// labelSurname
//
labelSurname.AutoSize = true;
labelSurname.Location = new Point(10, 44);
labelSurname.Name = "labelSurname";
labelSurname.Size = new Size(61, 15);
labelSurname.TabIndex = 15;
labelSurname.Text = "Фамилия:";
//
// FormContractor // FormContractor
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(286, 79); ClientSize = new Size(281, 104);
Controls.Add(textBoxSurname);
Controls.Add(labelSurname);
Controls.Add(buttonCancel); Controls.Add(buttonCancel);
Controls.Add(buttonSave); Controls.Add(buttonSave);
Controls.Add(textBoxName); Controls.Add(textBoxName);
@ -92,5 +112,7 @@
private Button buttonSave; private Button buttonSave;
private TextBox textBoxName; private TextBox textBoxName;
private Label labelName; private Label labelName;
private TextBox textBoxSurname;
private Label labelSurname;
} }
} }

View File

@ -19,6 +19,7 @@ namespace ISEbd_22_Vasin_E.D._It_Company.Forms
if (contractor == null) throw new InvalidDataException(nameof(contractor)); if (contractor == null) throw new InvalidDataException(nameof(contractor));
textBoxName.Text = contractor.Name; textBoxName.Text = contractor.Name;
textBoxSurname.Text = contractor.Surname;
_contractorId = value; _contractorId = value;
} }
catch (Exception ex) catch (Exception ex)
@ -39,18 +40,21 @@ namespace ISEbd_22_Vasin_E.D._It_Company.Forms
{ {
try try
{ {
if (string.IsNullOrEmpty(textBoxName.Text)) if (string.IsNullOrEmpty(textBoxName.Text) ||
string.IsNullOrEmpty(textBoxSurname.Text))
{ {
throw new Exception("Имеются незаполненные поля"); throw new Exception("Имеются незаполненные поля");
} }
if (_contractorId.HasValue) if (_contractorId.HasValue)
{ {
_contractorRepository.UpdateContractor(Contractor.CreateEntity(_contractorId.Value, textBoxName.Text)); _contractorRepository.UpdateContractor(Contractor.CreateEntity(_contractorId.Value,
textBoxName.Text, textBoxSurname.Text));
} }
else else
{ {
_contractorRepository.CreateContractor(Contractor.CreateEntity(0, textBoxName.Text)); _contractorRepository.CreateContractor(Contractor.CreateEntity(0,
textBoxName.Text, textBoxSurname.Text));
} }
Close(); Close();

View File

@ -31,6 +31,7 @@
dataGridViewData = new DataGridView(); dataGridViewData = new DataGridView();
panel = new Panel(); panel = new Panel();
buttonAdd = new Button(); buttonAdd = new Button();
buttonDel = new Button();
((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit(); ((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit();
panel.SuspendLayout(); panel.SuspendLayout();
SuspendLayout(); SuspendLayout();
@ -55,6 +56,7 @@
// //
// panel // panel
// //
panel.Controls.Add(buttonDel);
panel.Controls.Add(buttonAdd); panel.Controls.Add(buttonAdd);
panel.Dock = DockStyle.Right; panel.Dock = DockStyle.Right;
panel.Location = new Point(861, 0); panel.Location = new Point(861, 0);
@ -73,6 +75,17 @@
buttonAdd.UseVisualStyleBackColor = true; buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += ButtonAdd_Click; buttonAdd.Click += ButtonAdd_Click;
// //
// buttonDel
//
buttonDel.BackgroundImage = Properties.Resources.icon_remove;
buttonDel.BackgroundImageLayout = ImageLayout.Stretch;
buttonDel.Location = new Point(16, 108);
buttonDel.Name = "buttonDel";
buttonDel.Size = new Size(90, 90);
buttonDel.TabIndex = 3;
buttonDel.UseVisualStyleBackColor = true;
buttonDel.Click += ButtonDel_Click;
//
// FormContractorVacations // FormContractorVacations
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
@ -94,5 +107,6 @@
private DataGridView dataGridViewData; private DataGridView dataGridViewData;
private Panel panel; private Panel panel;
private Button buttonAdd; private Button buttonAdd;
private Button buttonDel;
} }
} }

View File

@ -13,7 +13,7 @@ namespace ISEbd_22_Vasin_E.D._It_Company.Forms
{ {
InitializeComponent(); InitializeComponent();
_container = container ?? throw new ArgumentException(nameof(container)); _container = container ?? throw new ArgumentException(nameof(container));
_contractorVacationRepository = contractorVacationRepository ?? _contractorVacationRepository = contractorVacationRepository ??
throw new ArgumentException(nameof(contractorVacationRepository)); throw new ArgumentException(nameof(contractorVacationRepository));
} }
@ -42,6 +42,25 @@ namespace ISEbd_22_Vasin_E.D._It_Company.Forms
} }
} }
private void ButtonDel_Click(object sender, EventArgs e)
{
if (!TryGetIdentifierFromSelectedRow(out var findId))
return;
if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes)
return;
try
{
_contractorVacationRepository.DeleteContractorVacation(findId);
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void LoadList() => dataGridViewData.DataSource = _contractorVacationRepository.ReadContractorVacations(); private void LoadList() => dataGridViewData.DataSource = _contractorVacationRepository.ReadContractorVacations();
private bool TryGetIdentifierFromSelectedRow(out int id) private bool TryGetIdentifierFromSelectedRow(out int id)

View File

@ -30,7 +30,6 @@
{ {
dataGridViewData = new DataGridView(); dataGridViewData = new DataGridView();
panel = new Panel(); panel = new Panel();
buttonUpd = new Button();
buttonAdd = new Button(); buttonAdd = new Button();
((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit(); ((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit();
panel.SuspendLayout(); panel.SuspendLayout();
@ -56,7 +55,6 @@
// //
// panel // panel
// //
panel.Controls.Add(buttonUpd);
panel.Controls.Add(buttonAdd); panel.Controls.Add(buttonAdd);
panel.Dock = DockStyle.Right; panel.Dock = DockStyle.Right;
panel.Location = new Point(861, 0); panel.Location = new Point(861, 0);
@ -64,17 +62,6 @@
panel.Size = new Size(123, 461); panel.Size = new Size(123, 461);
panel.TabIndex = 6; panel.TabIndex = 6;
// //
// buttonUpd
//
buttonUpd.BackgroundImage = Properties.Resources.icon_edit;
buttonUpd.BackgroundImageLayout = ImageLayout.Stretch;
buttonUpd.Location = new Point(16, 108);
buttonUpd.Name = "buttonUpd";
buttonUpd.Size = new Size(90, 90);
buttonUpd.TabIndex = 1;
buttonUpd.UseVisualStyleBackColor = true;
buttonUpd.Click += ButtonUpd_Click;
//
// buttonAdd // buttonAdd
// //
buttonAdd.BackgroundImage = Properties.Resources.icon_add; buttonAdd.BackgroundImage = Properties.Resources.icon_add;
@ -106,7 +93,6 @@
private DataGridView dataGridViewData; private DataGridView dataGridViewData;
private Panel panel; private Panel panel;
private Button buttonUpd;
private Button buttonAdd; private Button buttonAdd;
} }
} }

View File

@ -41,37 +41,6 @@ namespace ISEbd_22_Vasin_E.D._It_Company.Forms
} }
} }
private void ButtonUpd_Click(object sender, EventArgs e)
{
if (!TryGetIdentifierFromSelectedRow(out var findId))
return;
try
{
var form = _container.Resolve<FormContract>();
form.Id = findId;
form.ShowDialog();
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void LoadList() => dataGridViewData.DataSource = _contractRepository.ReadContracts(); private void LoadList() => dataGridViewData.DataSource = _contractRepository.ReadContracts();
private bool TryGetIdentifierFromSelectedRow(out int id)
{
id = 0;
if (dataGridViewData.SelectedRows.Count < 1)
{
MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
id = Convert.ToInt32(dataGridViewData.SelectedRows[0].Cells["Id"].Value);
return true;
}
} }
} }

View File

@ -34,6 +34,8 @@
labelEndDate = new Label(); labelEndDate = new Label();
buttonCancel = new Button(); buttonCancel = new Button();
buttonSave = new Button(); buttonSave = new Button();
comboBoxVacationType = new ComboBox();
labelVacationType = new Label();
SuspendLayout(); SuspendLayout();
// //
// labelStartDate // labelStartDate
@ -70,7 +72,7 @@
// //
// buttonCancel // buttonCancel
// //
buttonCancel.Location = new Point(178, 70); buttonCancel.Location = new Point(178, 99);
buttonCancel.Name = "buttonCancel"; buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(117, 23); buttonCancel.Size = new Size(117, 23);
buttonCancel.TabIndex = 12; buttonCancel.TabIndex = 12;
@ -80,7 +82,7 @@
// //
// buttonSave // buttonSave
// //
buttonSave.Location = new Point(12, 70); buttonSave.Location = new Point(15, 99);
buttonSave.Name = "buttonSave"; buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(117, 23); buttonSave.Size = new Size(117, 23);
buttonSave.TabIndex = 11; buttonSave.TabIndex = 11;
@ -88,11 +90,30 @@
buttonSave.UseVisualStyleBackColor = true; buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += ButtonSave_Click; buttonSave.Click += ButtonSave_Click;
// //
// comboBoxVacationType
//
comboBoxVacationType.FormattingEnabled = true;
comboBoxVacationType.Location = new Point(95, 70);
comboBoxVacationType.Name = "comboBoxVacationType";
comboBoxVacationType.Size = new Size(200, 23);
comboBoxVacationType.TabIndex = 13;
//
// labelVacationType
//
labelVacationType.AutoSize = true;
labelVacationType.Location = new Point(12, 73);
labelVacationType.Name = "labelVacationType";
labelVacationType.Size = new Size(77, 15);
labelVacationType.TabIndex = 14;
labelVacationType.Text = "Тип отпуска:";
//
// FormVacation // FormVacation
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(310, 102); ClientSize = new Size(310, 136);
Controls.Add(labelVacationType);
Controls.Add(comboBoxVacationType);
Controls.Add(buttonCancel); Controls.Add(buttonCancel);
Controls.Add(buttonSave); Controls.Add(buttonSave);
Controls.Add(dateTimePickerEndDate); Controls.Add(dateTimePickerEndDate);
@ -114,5 +135,7 @@
private Label labelEndDate; private Label labelEndDate;
private Button buttonCancel; private Button buttonCancel;
private Button buttonSave; private Button buttonSave;
private ComboBox comboBoxVacationType;
private Label labelVacationType;
} }
} }

View File

@ -1,4 +1,5 @@
using ISEbd_22_Vasin_E.D._It_Company.Entities; using ISEbd_22_Vasin_E.D._It_Company.Entities;
using ISEbd_22_Vasin_E.D._It_Company.Entities.Enums;
using ISEbd_22_Vasin_E.D._It_Company.Repositories; using ISEbd_22_Vasin_E.D._It_Company.Repositories;
namespace ISEbd_22_Vasin_E.D._It_Company.Forms namespace ISEbd_22_Vasin_E.D._It_Company.Forms
@ -23,6 +24,7 @@ namespace ISEbd_22_Vasin_E.D._It_Company.Forms
dateTimePickerStartDate.Value = vacation.StartDate; dateTimePickerStartDate.Value = vacation.StartDate;
dateTimePickerEndDate.Value = vacation.EndDate; dateTimePickerEndDate.Value = vacation.EndDate;
comboBoxVacationType.SelectedItem = vacation.VacationType;
_vacationId = value; _vacationId = value;
} }
catch (Exception ex) catch (Exception ex)
@ -37,21 +39,28 @@ namespace ISEbd_22_Vasin_E.D._It_Company.Forms
{ {
InitializeComponent(); InitializeComponent();
_vacationRepository = vacationRepository ?? throw new ArgumentNullException(nameof(vacationRepository)); _vacationRepository = vacationRepository ?? throw new ArgumentNullException(nameof(vacationRepository));
comboBoxVacationType.DataSource = Enum.GetValues(typeof(VacationType));
} }
private void ButtonSave_Click(object sender, EventArgs e) private void ButtonSave_Click(object sender, EventArgs e)
{ {
try try
{ {
if (comboBoxVacationType.SelectedIndex < 1)
{
throw new Exception("Имеются незаполненные поля");
}
if (_vacationId.HasValue) if (_vacationId.HasValue)
{ {
_vacationRepository.UpdateVacation(Vacation.CreateEntity(_vacationId.Value, _vacationRepository.UpdateVacation(Vacation.CreateEntity(_vacationId.Value,
dateTimePickerStartDate.Value, dateTimePickerEndDate.Value)); dateTimePickerStartDate.Value, dateTimePickerEndDate.Value, (VacationType)comboBoxVacationType.SelectedValue!));
} }
else else
{ {
_vacationRepository.CreateVacation(Vacation.CreateEntity(0, dateTimePickerStartDate.Value, _vacationRepository.CreateVacation(Vacation.CreateEntity(0, dateTimePickerStartDate.Value,
dateTimePickerEndDate.Value)); dateTimePickerEndDate.Value, (VacationType)comboBoxVacationType.SelectedValue!));
} }
Close(); Close();

View File

@ -1,5 +1,6 @@
using ISEbd_22_Vasin_E.D._It_Company; using ISEbd_22_Vasin_E.D._It_Company;
using ISEbd_22_Vasin_E.D._It_Company.Repositories; using ISEbd_22_Vasin_E.D._It_Company.Repositories;
using ISEbd_22_Vasin_E.D._It_Company.Repositories.Implementations;
using Unity; using Unity;
namespace ISEbd_22_Vasin_E.D._It_Company namespace ISEbd_22_Vasin_E.D._It_Company

View File

@ -6,12 +6,8 @@ namespace ISEbd_22_Vasin_E.D._It_Company.Repositories;
public interface IContractRepository public interface IContractRepository
{ {
IEnumerable<Contract> ReadContracts(int? clientId = null, int? contractorId = null, int? amountFrom = null, IEnumerable<Contract> ReadContracts(int? clientId = null, int? contractorId = null, int? amountFrom = null,
int? amountTo = null, DateTime? deadlineFrom = null, DateTime? deadlineTo = null, int? amountTo = null, DateTime? startDateFrom = null, DateTime? startDateTo = null,
Status? status = null, ContractType? contractType = null); DateTime? deadlineFrom = null, DateTime? deadlineTo = null, ContractType? contractType = null);
Contract ReadContractById(int id);
void CreateContract(Contract contract); void CreateContract(Contract contract);
void UpdateContract(Contract contract);
} }

View File

@ -8,4 +8,6 @@ public interface IContractorVacationRepository
int? vacationId = null); int? vacationId = null);
void CreateContractorVacation(ContractorVacation contractorVacation); void CreateContractorVacation(ContractorVacation contractorVacation);
void DeleteContractorVacation(int id);
} }

View File

@ -1,6 +1,6 @@
using ISEbd_22_Vasin_E.D._It_Company.Entities; using ISEbd_22_Vasin_E.D._It_Company.Entities;
namespace ISEbd_22_Vasin_E.D._It_Company.Repositories; namespace ISEbd_22_Vasin_E.D._It_Company.Repositories.Implementations;
public class ClientRepository : IClientRepository public class ClientRepository : IClientRepository
{ {
@ -14,7 +14,7 @@ public class ClientRepository : IClientRepository
public Client ReadClientById(int id) public Client ReadClientById(int id)
{ {
return Client.CreateEntity(0, string.Empty); return Client.CreateEntity(0, string.Empty, string.Empty);
} }
public IEnumerable<Client> ReadClients() public IEnumerable<Client> ReadClients()

View File

@ -1,7 +1,7 @@
using ISEbd_22_Vasin_E.D._It_Company.Entities; using ISEbd_22_Vasin_E.D._It_Company.Entities;
using ISEbd_22_Vasin_E.D._It_Company.Entities.Enums; using ISEbd_22_Vasin_E.D._It_Company.Entities.Enums;
namespace ISEbd_22_Vasin_E.D._It_Company.Repositories; namespace ISEbd_22_Vasin_E.D._It_Company.Repositories.Implementations;
public class ContractRepository : IContractRepository public class ContractRepository : IContractRepository
{ {
@ -9,19 +9,10 @@ public class ContractRepository : IContractRepository
{ {
} }
public Contract ReadContractById(int id)
{
return Contract.CreateEntity(0, 0, 0, 0, DateTime.Now, Entities.Enums.Status.None, Entities.Enums.ContractType.None, []);
}
public IEnumerable<Contract> ReadContracts(int? clientId = null, int? contractorId = null, int? amountFrom = null, public IEnumerable<Contract> ReadContracts(int? clientId = null, int? contractorId = null, int? amountFrom = null,
int? amountTo = null, DateTime? deadlineFrom = null, DateTime? deadlineTo = null, int? amountTo = null, DateTime? startDateFrom = null, DateTime? startDateTo = null,
Status? status = null, ContractType? contractType = null) DateTime? deadlineFrom = null, DateTime? deadlineTo = null, ContractType? contractType = null)
{ {
return []; return [];
} }
public void UpdateContract(Contract contract)
{
}
} }

View File

@ -1,6 +1,6 @@
using ISEbd_22_Vasin_E.D._It_Company.Entities; using ISEbd_22_Vasin_E.D._It_Company.Entities;
namespace ISEbd_22_Vasin_E.D._It_Company.Repositories; namespace ISEbd_22_Vasin_E.D._It_Company.Repositories.Implementations;
public class ContractorRepository : IContractorRepository public class ContractorRepository : IContractorRepository
{ {
@ -14,7 +14,7 @@ public class ContractorRepository : IContractorRepository
public Contractor ReadContractorById(int id) public Contractor ReadContractorById(int id)
{ {
return Contractor.CreateEntity(0, string.Empty); return Contractor.CreateEntity(0, string.Empty, string.Empty);
} }
public IEnumerable<Contractor> ReadContractors() public IEnumerable<Contractor> ReadContractors()

View File

@ -1,6 +1,6 @@
using ISEbd_22_Vasin_E.D._It_Company.Entities; using ISEbd_22_Vasin_E.D._It_Company.Entities;
namespace ISEbd_22_Vasin_E.D._It_Company.Repositories; namespace ISEbd_22_Vasin_E.D._It_Company.Repositories.Implementations;
public class ContractorVacationRepository : IContractorVacationRepository public class ContractorVacationRepository : IContractorVacationRepository
{ {
@ -13,4 +13,8 @@ public class ContractorVacationRepository : IContractorVacationRepository
{ {
return []; return [];
} }
public void DeleteContractorVacation(int id)
{
}
} }

View File

@ -1,6 +1,6 @@
using ISEbd_22_Vasin_E.D._It_Company.Entities; using ISEbd_22_Vasin_E.D._It_Company.Entities;
namespace ISEbd_22_Vasin_E.D._It_Company.Repositories; namespace ISEbd_22_Vasin_E.D._It_Company.Repositories.Implementations;
public class ServiceRepository : IServiceRepository public class ServiceRepository : IServiceRepository
{ {

View File

@ -1,6 +1,7 @@
using ISEbd_22_Vasin_E.D._It_Company.Entities; using ISEbd_22_Vasin_E.D._It_Company.Entities;
using ISEbd_22_Vasin_E.D._It_Company.Entities.Enums;
namespace ISEbd_22_Vasin_E.D._It_Company.Repositories; namespace ISEbd_22_Vasin_E.D._It_Company.Repositories.Implementations;
public class VacationRepository : IVacationRepository public class VacationRepository : IVacationRepository
{ {
@ -14,7 +15,7 @@ public class VacationRepository : IVacationRepository
public Vacation ReadVacationById(int id) public Vacation ReadVacationById(int id)
{ {
return Vacation.CreateEntity(0, DateTime.Now, DateTime.Now); return Vacation.CreateEntity(0, DateTime.Now, DateTime.Now, VacationType.None);
} }
public IEnumerable<Vacation> ReadVacations() public IEnumerable<Vacation> ReadVacations()