diff --git a/ITServiceManager/ITServiceManager/Entities/Appointment.cs b/ITServiceManager/ITServiceManager/Entities/Appointment.cs index 281c7e0..af30c6e 100644 --- a/ITServiceManager/ITServiceManager/Entities/Appointment.cs +++ b/ITServiceManager/ITServiceManager/Entities/Appointment.cs @@ -8,7 +8,7 @@ public class Appointment public DateTime StartDate { 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 { diff --git a/ITServiceManager/ITServiceManager/Entities/Order.cs b/ITServiceManager/ITServiceManager/Entities/Order.cs index 44ea53a..978bccc 100644 --- a/ITServiceManager/ITServiceManager/Entities/Order.cs +++ b/ITServiceManager/ITServiceManager/Entities/Order.cs @@ -4,8 +4,8 @@ public class Order { public int Id { get; private set; } public int CompanyId { get; private set; } - public DateTime OrderDate { get; private set; } - public decimal OrderPrice { get; private set; } + public DateTime Date { get; private set; } + public decimal Price { get; private set; } public IEnumerable OrderService { get; private set; } = []; @@ -15,8 +15,8 @@ public class Order { Id = id, CompanyId = companyId, - OrderDate = DateTime.Now, - OrderPrice = orderPrice, + Date = DateTime.Now, + Price = orderPrice, OrderService = orderService }; } diff --git a/ITServiceManager/ITServiceManager/Entities/OrderService.cs b/ITServiceManager/ITServiceManager/Entities/OrderService.cs index 68457f1..e6434d5 100644 --- a/ITServiceManager/ITServiceManager/Entities/OrderService.cs +++ b/ITServiceManager/ITServiceManager/Entities/OrderService.cs @@ -8,12 +8,11 @@ public class OrderService public int Quantity { 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 { Id = id, - OrderId = orderId, ServiceId = serviceId, Quantity = serviceQuantity, ExecutionDate = executionDate diff --git a/ITServiceManager/ITServiceManager/Forms/FormAppointment.Designer.cs b/ITServiceManager/ITServiceManager/Forms/FormAppointment.Designer.cs index b76d94c..5f2fcf9 100644 --- a/ITServiceManager/ITServiceManager/Forms/FormAppointment.Designer.cs +++ b/ITServiceManager/ITServiceManager/Forms/FormAppointment.Designer.cs @@ -43,18 +43,18 @@ // label1 // label1.AutoSize = true; - label1.Location = new Point(46, 46); + label1.Location = new Point(53, 61); label1.Name = "label1"; - label1.Size = new Size(40, 15); + label1.Size = new Size(50, 20); label1.TabIndex = 0; label1.Text = "Заказ:"; // // label2 // label2.AutoSize = true; - label2.Location = new Point(46, 141); + label2.Location = new Point(53, 188); label2.Name = "label2"; - label2.Size = new Size(69, 15); + label2.Size = new Size(85, 20); label2.TabIndex = 1; label2.Text = "Сотрудник:"; // @@ -62,51 +62,55 @@ // comboBoxEmployee.DropDownStyle = ComboBoxStyle.DropDownList; 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.Size = new Size(207, 23); + comboBoxEmployee.Size = new Size(236, 28); comboBoxEmployee.TabIndex = 2; // // comboBoxOrder // comboBoxOrder.DropDownStyle = ComboBoxStyle.DropDownList; 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.Size = new Size(207, 23); + comboBoxOrder.Size = new Size(236, 28); comboBoxOrder.TabIndex = 3; // // dateTimePickerStart // 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.Size = new Size(207, 23); + dateTimePickerStart.Size = new Size(236, 27); dateTimePickerStart.TabIndex = 4; // // label3 // label3.AutoSize = true; - label3.Location = new Point(46, 234); + label3.Location = new Point(53, 312); label3.Name = "label3"; - label3.Size = new Size(149, 15); + label3.Size = new Size(193, 20); label3.TabIndex = 5; label3.Text = "Дата назначения на заказ:"; // // label4 // label4.AutoSize = true; - label4.Location = new Point(46, 328); + label4.Location = new Point(53, 437); label4.Name = "label4"; - label4.Size = new Size(95, 15); + label4.Size = new Size(121, 20); label4.TabIndex = 6; label4.Text = "Дата окончания"; // // 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.Size = new Size(112, 28); + buttonCancel.Size = new Size(128, 37); buttonCancel.TabIndex = 9; buttonCancel.Text = "Отмена"; buttonCancel.UseVisualStyleBackColor = true; @@ -114,9 +118,10 @@ // // 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.Size = new Size(112, 28); + buttonAdd.Size = new Size(128, 37); buttonAdd.TabIndex = 8; buttonAdd.Text = "Добавить"; buttonAdd.UseVisualStyleBackColor = true; @@ -124,17 +129,20 @@ // // dateTimePickerEnd // + dateTimePickerEnd.CustomFormat = "В процессе"; + dateTimePickerEnd.Format = DateTimePickerFormat.Custom; 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.Size = new Size(207, 23); + dateTimePickerEnd.Size = new Size(236, 27); dateTimePickerEnd.TabIndex = 10; // // FormAppointment // - AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(476, 505); + ClientSize = new Size(544, 673); Controls.Add(dateTimePickerEnd); Controls.Add(buttonCancel); Controls.Add(buttonAdd); @@ -145,6 +153,7 @@ Controls.Add(comboBoxEmployee); Controls.Add(label2); Controls.Add(label1); + Margin = new Padding(3, 4, 3, 4); Name = "FormAppointment"; Text = "Назначение"; ResumeLayout(false); diff --git a/ITServiceManager/ITServiceManager/Forms/FormAppointment.cs b/ITServiceManager/ITServiceManager/Forms/FormAppointment.cs index 879aa55..66f1548 100644 --- a/ITServiceManager/ITServiceManager/Forms/FormAppointment.cs +++ b/ITServiceManager/ITServiceManager/Forms/FormAppointment.cs @@ -1,15 +1,5 @@ using ITServiceManager.Entities; 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 { @@ -30,8 +20,8 @@ namespace ITServiceManager.Forms throw new InvalidDataException(nameof(appointment)); } - comboBoxEmployee.SelectedIndex = appointment.EmployeeId; - comboBoxOrder.SelectedIndex = appointment.OrderId; + comboBoxEmployee.SelectedItem = appointment.EmployeeId; + comboBoxOrder.SelectedItem = appointment.OrderId; _appointmentId = value; } catch (Exception ex) @@ -54,15 +44,30 @@ namespace ITServiceManager.Forms comboBoxEmployee.DataSource = employeeRepository.ReadEmployees(); comboBoxEmployee.DisplayMember = "Name"; 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) { try { - if (comboBoxEmployee.SelectedIndex < 0 || comboBoxOrder.SelectedIndex < 0 || dateTimePickerStart.CustomFormat != " ") + if (comboBoxEmployee.SelectedIndex < 0 || comboBoxOrder.SelectedIndex < 0) { throw new Exception("Имеются незаполненные поля"); } + if (_appointmentId.HasValue) { _appointmentRepository.UpdateAppointment(CreateAppointment(_appointmentId.Value)); @@ -80,7 +85,12 @@ namespace ITServiceManager.Forms } } private void ButtonCancel_Click(object sender, EventArgs e) => Close(); - private Appointment CreateAppointment(int id) => Appointment.CreateOperation(id, comboBoxOrder.SelectedIndex, comboBoxEmployee.SelectedIndex, Convert.ToDateTime(dateTimePickerStart) , - Convert.ToDateTime(dateTimePickerEnd)); + private Appointment CreateAppointment(int id) + { + DateTime? endDate = dateTimePickerEnd.CustomFormat == "В процессе" ? (DateTime?)null : dateTimePickerEnd.Value; + + return Appointment.CreateOperation(id, (int)comboBoxOrder.SelectedValue!, (int)comboBoxEmployee.SelectedValue!, Convert.ToDateTime(dateTimePickerStart.Value), + endDate); + } } } diff --git a/ITServiceManager/ITServiceManager/Forms/FormAppointments.Designer.cs b/ITServiceManager/ITServiceManager/Forms/FormAppointments.Designer.cs index 1bf330d..328ff6a 100644 --- a/ITServiceManager/ITServiceManager/Forms/FormAppointments.Designer.cs +++ b/ITServiceManager/ITServiceManager/Forms/FormAppointments.Designer.cs @@ -30,6 +30,7 @@ { dataGridView = new DataGridView(); panel = new Panel(); + buttonRemove = new Button(); buttonUpdate = new Button(); buttonAdd = new Button(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); @@ -42,9 +43,11 @@ dataGridView.AllowUserToDeleteRows = false; dataGridView.AllowUserToResizeColumns = false; dataGridView.AllowUserToResizeRows = false; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.Dock = DockStyle.Fill; dataGridView.Location = new Point(0, 0); + dataGridView.Margin = new Padding(3, 4, 3, 4); dataGridView.MultiSelect = false; dataGridView.Name = "dataGridView"; dataGridView.ReadOnly = true; @@ -52,26 +55,41 @@ dataGridView.RowHeadersWidth = 51; dataGridView.RowTemplate.Height = 25; dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridView.Size = new Size(652, 450); + dataGridView.Size = new Size(745, 600); dataGridView.TabIndex = 2; // // panel // + panel.Controls.Add(buttonRemove); panel.Controls.Add(buttonUpdate); panel.Controls.Add(buttonAdd); 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.Size = new Size(148, 450); + panel.Size = new Size(169, 600); 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.BackgroundImage = Properties.Resources.edit; 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.Size = new Size(81, 80); + buttonUpdate.Size = new Size(93, 107); buttonUpdate.TabIndex = 2; buttonUpdate.UseVisualStyleBackColor = true; buttonUpdate.Click += ButtonUpd_Click; @@ -80,20 +98,22 @@ // buttonAdd.BackgroundImage = Properties.Resources.plus; 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.Size = new Size(81, 71); + buttonAdd.Size = new Size(93, 95); buttonAdd.TabIndex = 0; buttonAdd.UseVisualStyleBackColor = true; buttonAdd.Click += ButtonAdd_Click; // // FormAppointments // - AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 450); + ClientSize = new Size(914, 600); Controls.Add(dataGridView); Controls.Add(panel); + Margin = new Padding(3, 4, 3, 4); Name = "FormAppointments"; Text = "Назначения"; Load += FormAppointments_Load; @@ -108,5 +128,6 @@ private Panel panel; private Button buttonUpdate; private Button buttonAdd; + private Button buttonRemove; } } \ No newline at end of file diff --git a/ITServiceManager/ITServiceManager/Forms/FormAppointments.cs b/ITServiceManager/ITServiceManager/Forms/FormAppointments.cs index 974dfc7..c0ea03f 100644 --- a/ITServiceManager/ITServiceManager/Forms/FormAppointments.cs +++ b/ITServiceManager/ITServiceManager/Forms/FormAppointments.cs @@ -1,4 +1,5 @@ using ITServiceManager.Repositories; +using ITServiceManager.Repositories.Implementations; using System; using System.Collections.Generic; using System.ComponentModel; @@ -76,6 +77,27 @@ namespace ITServiceManager.Forms id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); 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); + } + } } } diff --git a/ITServiceManager/ITServiceManager/Forms/FormCompanies.Designer.cs b/ITServiceManager/ITServiceManager/Forms/FormCompanies.Designer.cs index 81866a4..9c13f9f 100644 --- a/ITServiceManager/ITServiceManager/Forms/FormCompanies.Designer.cs +++ b/ITServiceManager/ITServiceManager/Forms/FormCompanies.Designer.cs @@ -91,6 +91,7 @@ dataGridView.AllowUserToDeleteRows = false; dataGridView.AllowUserToResizeColumns = false; dataGridView.AllowUserToResizeRows = false; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.Dock = DockStyle.Fill; dataGridView.Location = new Point(0, 0); diff --git a/ITServiceManager/ITServiceManager/Forms/FormCompany.Designer.cs b/ITServiceManager/ITServiceManager/Forms/FormCompany.Designer.cs index 746c07f..2e245ed 100644 --- a/ITServiceManager/ITServiceManager/Forms/FormCompany.Designer.cs +++ b/ITServiceManager/ITServiceManager/Forms/FormCompany.Designer.cs @@ -51,7 +51,6 @@ textBoxName.Name = "textBoxName"; textBoxName.Size = new Size(200, 23); textBoxName.TabIndex = 1; - textBoxName.TextChanged += textBoxName_TextChanged; // // buttonAdd // diff --git a/ITServiceManager/ITServiceManager/Forms/FormCompany.cs b/ITServiceManager/ITServiceManager/Forms/FormCompany.cs index a75fc60..be360bc 100644 --- a/ITServiceManager/ITServiceManager/Forms/FormCompany.cs +++ b/ITServiceManager/ITServiceManager/Forms/FormCompany.cs @@ -1,79 +1,63 @@ using ITServiceManager.Entities; 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 +public partial class FormCompany : Form { - public partial class FormCompany : Form + private readonly ICompanyRepository _companyRepository; + private int? _companyId; + public int Id { - private readonly ICompanyRepository _companyRepository; - private int? _companyId; - public int Id - { - set - { - try - { - var company = _companyRepository.ReadCompanyById(value); - if (company == null) - { - throw new InvalidDataException(nameof(company)); - } - textBoxName.Text = company.Name; - textBoxAddress.Text = company.Address; - _companyId = value; - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - } - public FormCompany(ICompanyRepository companyRepository) - { - InitializeComponent(); - _companyRepository = companyRepository ?? throw new ArgumentNullException(nameof(companyRepository)); - } - - private void ButtonAdd_Click(object sender, EventArgs e) + set { try { - if (string.IsNullOrWhiteSpace(textBoxName.Text) || string.IsNullOrWhiteSpace(textBoxAddress.Text)) + var company = _companyRepository.ReadCompanyById(value); + if (company == null) { - throw new Exception("Имеются незаполненные поля"); + throw new InvalidDataException(nameof(company)); } - if (_companyId.HasValue) - { - _companyRepository.UpdateCompany(CreateCompany(_companyId.Value)); - } - else - { - _companyRepository.CreateCompany(CreateCompany(0)); - } - Close(); + textBoxName.Text = company.Name; + textBoxAddress.Text = company.Address; + _companyId = value; } catch (Exception ex) { - MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; } } - private void ButtonCancel_Click(object sender, EventArgs e) => Close(); - private Company CreateCompany(int id) => Company.CreateEntity(id, textBoxName.Text, textBoxAddress.Text); + } + public FormCompany(ICompanyRepository companyRepository) + { + InitializeComponent(); + _companyRepository = companyRepository ?? throw new ArgumentNullException(nameof(companyRepository)); + } - private void textBoxName_TextChanged(object sender, EventArgs e) + private void ButtonAdd_Click(object sender, EventArgs e) + { + try { - + if (string.IsNullOrWhiteSpace(textBoxName.Text) || string.IsNullOrWhiteSpace(textBoxAddress.Text)) + { + throw new Exception("Имеются незаполненные поля"); + } + if (_companyId.HasValue) + { + _companyRepository.UpdateCompany(CreateCompany(_companyId.Value)); + } + else + { + _companyRepository.CreateCompany(CreateCompany(0)); + } + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); } } + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + private Company CreateCompany(int id) => Company.CreateEntity(id, textBoxName.Text, textBoxAddress.Text); + } diff --git a/ITServiceManager/ITServiceManager/Forms/FormEmployees.Designer.cs b/ITServiceManager/ITServiceManager/Forms/FormEmployees.Designer.cs index 9dc53e0..3bc21bb 100644 --- a/ITServiceManager/ITServiceManager/Forms/FormEmployees.Designer.cs +++ b/ITServiceManager/ITServiceManager/Forms/FormEmployees.Designer.cs @@ -43,18 +43,20 @@ panel.Controls.Add(buttonRemove); panel.Controls.Add(buttonAdd); 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.Size = new Size(148, 450); + panel.Size = new Size(169, 600); panel.TabIndex = 2; // // buttonUpdate // buttonUpdate.BackgroundImage = Properties.Resources.edit; 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.Size = new Size(78, 80); + buttonUpdate.Size = new Size(89, 107); buttonUpdate.TabIndex = 2; buttonUpdate.UseVisualStyleBackColor = true; buttonUpdate.Click += ButtonUpd_Click; @@ -63,9 +65,10 @@ // buttonRemove.BackgroundImage = Properties.Resources.minus; 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.Size = new Size(75, 76); + buttonRemove.Size = new Size(86, 101); buttonRemove.TabIndex = 1; buttonRemove.UseVisualStyleBackColor = true; buttonRemove.Click += ButtonDel_Click; @@ -74,9 +77,10 @@ // buttonAdd.BackgroundImage = Properties.Resources.plus; 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.Size = new Size(81, 71); + buttonAdd.Size = new Size(93, 95); buttonAdd.TabIndex = 0; buttonAdd.UseVisualStyleBackColor = true; buttonAdd.Click += ButtonAdd_Click; @@ -87,9 +91,11 @@ dataGridView.AllowUserToDeleteRows = false; dataGridView.AllowUserToResizeColumns = false; dataGridView.AllowUserToResizeRows = false; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.Dock = DockStyle.Fill; dataGridView.Location = new Point(0, 0); + dataGridView.Margin = new Padding(3, 4, 3, 4); dataGridView.MultiSelect = false; dataGridView.Name = "dataGridView"; dataGridView.ReadOnly = true; @@ -97,17 +103,16 @@ dataGridView.RowHeadersWidth = 51; dataGridView.RowTemplate.Height = 25; dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridView.Size = new Size(652, 450); + dataGridView.Size = new Size(745, 600); dataGridView.TabIndex = 3; // // FormEmployees // - AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 450); + ClientSize = new Size(914, 600); Controls.Add(dataGridView); Controls.Add(panel); - Margin = new Padding(3, 2, 3, 2); Name = "FormEmployees"; StartPosition = FormStartPosition.CenterScreen; Text = "Сотрудники"; diff --git a/ITServiceManager/ITServiceManager/Forms/FormOrder.Designer.cs b/ITServiceManager/ITServiceManager/Forms/FormOrder.Designer.cs index e756c3a..5ae7bb1 100644 --- a/ITServiceManager/ITServiceManager/Forms/FormOrder.Designer.cs +++ b/ITServiceManager/ITServiceManager/Forms/FormOrder.Designer.cs @@ -122,7 +122,7 @@ // label2 // label2.AutoSize = true; - label2.Location = new Point(59, 164); + label2.Location = new Point(59, 200); label2.Name = "label2"; label2.Size = new Size(125, 20); label2.TabIndex = 12; @@ -131,7 +131,8 @@ // numericUpDownPrice // 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.Maximum = new decimal(new int[] { 1000000, 0, 0, 0 }); numericUpDownPrice.Name = "numericUpDownPrice"; diff --git a/ITServiceManager/ITServiceManager/Forms/FormOrder.cs b/ITServiceManager/ITServiceManager/Forms/FormOrder.cs index 38880ae..0a39fa6 100644 --- a/ITServiceManager/ITServiceManager/Forms/FormOrder.cs +++ b/ITServiceManager/ITServiceManager/Forms/FormOrder.cs @@ -1,64 +1,53 @@ using ITServiceManager.Entities; using ITServiceManager.Repositories; -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; -using System.Windows.Forms.VisualStyles; +namespace ITServiceManager.Forms; -namespace ITServiceManager.Forms +public partial class FormOrder : Form { - public partial class FormOrder : Form + private readonly IOrderRepository _orderRepository; + public FormOrder(IOrderRepository orderRepository, IServiceRepository serviceRepository, ICompanyRepository companyRepository) { - private readonly IOrderRepository _orderRepository; - public FormOrder(IOrderRepository orderRepository, IServiceRepository serviceRepository, ICompanyRepository companyRepository) - { - InitializeComponent(); - _orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository)); + InitializeComponent(); + _orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository)); - comboBoxCompany.DataSource = companyRepository.ReadCompanies(); - comboBoxCompany.DisplayMember = "Name"; - comboBoxCompany.ValueMember = "Id"; + comboBoxCompany.DataSource = companyRepository.ReadCompanies(); + comboBoxCompany.DisplayMember = "Name"; + comboBoxCompany.ValueMember = "Id"; - ColumnService.DataSource = serviceRepository.ReadServices(); - ColumnService.DisplayMember = "ServiceType"; - ColumnService.ValueMember = "Id"; - } - private void ButtonAdd_Click(object sender, EventArgs e) + ColumnService.DataSource = serviceRepository.ReadServices(); + ColumnService.DisplayMember = "ServiceType"; + ColumnService.ValueMember = "Id"; + + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + if (dataGridView.RowCount < 1 || comboBoxCompany.SelectedIndex < 0 || numericUpDownPrice.Value <= 0) { - if (dataGridView.RowCount < 1 || comboBoxCompany.SelectedIndex < 0 || numericUpDownPrice.Value <= 0) - { - throw new Exception("Имеются незаполненны поля"); - } - try - { - _orderRepository.CreateOrder(Order.CreateOperation(0, comboBoxCompany.SelectedIndex, numericUpDownPrice.Value, CreateListServiceFromDataGrid())); - Close(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); - } + throw new Exception("Имеются незаполненны поля"); } - private void ButtonCancel_Click(object sender, EventArgs e) => Close(); - private List CreateListServiceFromDataGrid() + try { - var list = new List(); - foreach (DataGridViewRow row in dataGridView.Rows) - { - if (row.Cells["ColumService"].Value == null || row.Cells["ColumQuantity"].Value == null || row.Cells["ColumnExecutionDate"].Value == null) - { - 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))); - } - return list; + _orderRepository.CreateOrder(Order.CreateOperation(0, (int)comboBoxCompany.SelectedValue!, numericUpDownPrice.Value, CreateListServiceFromDataGrid())); + Close(); } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + private List CreateListServiceFromDataGrid() + { + var list = new List(); + foreach (DataGridViewRow row in dataGridView.Rows) + { + if (row.Cells["ColumnService"].Value == null || row.Cells["ColumnQuantity"].Value == null || row.Cells["ColumnExecutionDate"].Value == null) + { + continue; + } + 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; } } diff --git a/ITServiceManager/ITServiceManager/Forms/FormOrders.Designer.cs b/ITServiceManager/ITServiceManager/Forms/FormOrders.Designer.cs index 4638caa..c53b690 100644 --- a/ITServiceManager/ITServiceManager/Forms/FormOrders.Designer.cs +++ b/ITServiceManager/ITServiceManager/Forms/FormOrders.Designer.cs @@ -41,18 +41,20 @@ panel.Controls.Add(buttonRemove); panel.Controls.Add(buttonAdd); 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.Size = new Size(148, 450); + panel.Size = new Size(169, 600); panel.TabIndex = 4; // // buttonRemove // buttonRemove.BackgroundImage = Properties.Resources.minus; 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.Size = new Size(75, 76); + buttonRemove.Size = new Size(86, 101); buttonRemove.TabIndex = 1; buttonRemove.UseVisualStyleBackColor = true; buttonRemove.Click += ButtonRemove_Click; @@ -61,9 +63,10 @@ // buttonAdd.BackgroundImage = Properties.Resources.plus; 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.Size = new Size(81, 71); + buttonAdd.Size = new Size(93, 95); buttonAdd.TabIndex = 0; buttonAdd.UseVisualStyleBackColor = true; buttonAdd.Click += ButtonAdd_Click; @@ -74,9 +77,11 @@ dataGridView.AllowUserToDeleteRows = false; dataGridView.AllowUserToResizeColumns = false; dataGridView.AllowUserToResizeRows = false; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.Dock = DockStyle.Fill; dataGridView.Location = new Point(0, 0); + dataGridView.Margin = new Padding(3, 4, 3, 4); dataGridView.MultiSelect = false; dataGridView.Name = "dataGridView"; dataGridView.ReadOnly = true; @@ -84,16 +89,17 @@ dataGridView.RowHeadersWidth = 51; dataGridView.RowTemplate.Height = 25; dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridView.Size = new Size(652, 450); + dataGridView.Size = new Size(745, 600); dataGridView.TabIndex = 5; // // FormOrders // - AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 450); + ClientSize = new Size(914, 600); Controls.Add(dataGridView); Controls.Add(panel); + Margin = new Padding(3, 4, 3, 4); Name = "FormOrders"; StartPosition = FormStartPosition.CenterScreen; Text = "Заказы"; diff --git a/ITServiceManager/ITServiceManager/Forms/FormServices.Designer.cs b/ITServiceManager/ITServiceManager/Forms/FormServices.Designer.cs index 6e4c2db..2074e47 100644 --- a/ITServiceManager/ITServiceManager/Forms/FormServices.Designer.cs +++ b/ITServiceManager/ITServiceManager/Forms/FormServices.Designer.cs @@ -91,6 +91,7 @@ dataGridView.AllowUserToDeleteRows = false; dataGridView.AllowUserToResizeColumns = false; dataGridView.AllowUserToResizeRows = false; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.Dock = DockStyle.Fill; dataGridView.Location = new Point(0, 0); diff --git a/ITServiceManager/ITServiceManager/ITServiceManager.csproj b/ITServiceManager/ITServiceManager/ITServiceManager.csproj index 6470a09..a64093b 100644 --- a/ITServiceManager/ITServiceManager/ITServiceManager.csproj +++ b/ITServiceManager/ITServiceManager/ITServiceManager.csproj @@ -11,9 +11,9 @@ - - - + + + diff --git a/ITServiceManager/ITServiceManager/Repositories/IAppointmentRepository.cs b/ITServiceManager/ITServiceManager/Repositories/IAppointmentRepository.cs index 71d2109..04feabc 100644 --- a/ITServiceManager/ITServiceManager/Repositories/IAppointmentRepository.cs +++ b/ITServiceManager/ITServiceManager/Repositories/IAppointmentRepository.cs @@ -8,4 +8,6 @@ public interface IAppointmentRepository Appointment ReadAppointmentById(int id); void CreateAppointment(Appointment appointment); void UpdateAppointment(Appointment appointment); + void DeleteAppointment(int id); + } diff --git a/ITServiceManager/ITServiceManager/Repositories/IOrderRepository.cs b/ITServiceManager/ITServiceManager/Repositories/IOrderRepository.cs index d4632c4..3f126af 100644 --- a/ITServiceManager/ITServiceManager/Repositories/IOrderRepository.cs +++ b/ITServiceManager/ITServiceManager/Repositories/IOrderRepository.cs @@ -5,7 +5,6 @@ namespace ITServiceManager.Repositories; public interface IOrderRepository { IEnumerable ReadOrders(DateTime? dateForm = null, DateTime? dateTo = null, int? orderId = null, int? companyId = null); - Order ReadOrderById(int orderId); void CreateOrder(Order order); void DeleteOrder(int id); } diff --git a/ITServiceManager/ITServiceManager/Repositories/Implementations/AppointmentRepository.cs b/ITServiceManager/ITServiceManager/Repositories/Implementations/AppointmentRepository.cs index 8e895bc..7fefee4 100644 --- a/ITServiceManager/ITServiceManager/Repositories/Implementations/AppointmentRepository.cs +++ b/ITServiceManager/ITServiceManager/Repositories/Implementations/AppointmentRepository.cs @@ -22,9 +22,9 @@ public class AppointmentRepository : IAppointmentRepository { using var connection = new NpgsqlConnection(_connectionString.ConnectionString); var querySelect = @"SELECT * FROM Appointments"; - var order = connection.Query(querySelect); - _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(order)); - return order; + var appointment = connection.Query(querySelect); + _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(appointment)); + return appointment; } catch (Exception ex) { @@ -34,14 +34,84 @@ public class AppointmentRepository : IAppointmentRepository } 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(querySelect, new + { + id + }); + _logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(appointment)); + return appointment; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при поиске объекта"); + throw; + } } 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) { - + _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; + } } } diff --git a/ITServiceManager/ITServiceManager/Repositories/Implementations/CompanyRepository.cs b/ITServiceManager/ITServiceManager/Repositories/Implementations/CompanyRepository.cs index a5f9f12..dbcb973 100644 --- a/ITServiceManager/ITServiceManager/Repositories/Implementations/CompanyRepository.cs +++ b/ITServiceManager/ITServiceManager/Repositories/Implementations/CompanyRepository.cs @@ -85,7 +85,7 @@ public class CompanyRepository : ICompanyRepository UPDATE Companies SET Name=@Name, - Address=@Address, + Address=@Address WHERE Id=@Id"; connection.Execute(queryUpdate, company); } diff --git a/ITServiceManager/ITServiceManager/Repositories/Implementations/ConnectionString.cs b/ITServiceManager/ITServiceManager/Repositories/Implementations/ConnectionString.cs index b4140ca..15ab2b2 100644 --- a/ITServiceManager/ITServiceManager/Repositories/Implementations/ConnectionString.cs +++ b/ITServiceManager/ITServiceManager/Repositories/Implementations/ConnectionString.cs @@ -2,5 +2,5 @@ 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;"; } diff --git a/ITServiceManager/ITServiceManager/Repositories/Implementations/OrderRepository.cs b/ITServiceManager/ITServiceManager/Repositories/Implementations/OrderRepository.cs index 66dd2f7..b43f17d 100644 --- a/ITServiceManager/ITServiceManager/Repositories/Implementations/OrderRepository.cs +++ b/ITServiceManager/ITServiceManager/Repositories/Implementations/OrderRepository.cs @@ -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; public class OrderRepository : IOrderRepository { + private readonly IConnectionString _connectionString; + private readonly ILogger _logger; + + public OrderRepository(IConnectionString connectionString, ILogger logger) + { + _connectionString = connectionString; + _logger = logger; + } public IEnumerable ReadOrders(DateTime? dateForm = null, DateTime? dateTo = null, int? orderId = null, int? companyId = null) { - return []; - } - public Order ReadOrderById(int orderId) - { - return null; + _logger.LogInformation("Получение всех объектов"); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = @"SELECT * FROM Orders"; + var order = connection.Query(querySelect); + _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(order)); + return order; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при чтении объектов"); + throw; + } } 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(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) { - + _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; + } } } diff --git a/ITServiceManager/ITServiceManager/Repositories/Implementations/ServiceRepository.cs b/ITServiceManager/ITServiceManager/Repositories/Implementations/ServiceRepository.cs index af28da3..e29eebe 100644 --- a/ITServiceManager/ITServiceManager/Repositories/Implementations/ServiceRepository.cs +++ b/ITServiceManager/ITServiceManager/Repositories/Implementations/ServiceRepository.cs @@ -64,8 +64,8 @@ public class ServiceRepository : IServiceRepository { using var connection = new NpgsqlConnection(_connectionString.ConnectionString); var queryInsert = @" - INSERT INTO Services (Name, ServiceType, Description) - VALUES (@Name, @ServiceType, @Description)"; + INSERT INTO Services (ServiceType, Description) + VALUES (@ServiceType, @Description)"; connection.Execute(queryInsert, service); } catch (Exception ex) @@ -85,7 +85,7 @@ public class ServiceRepository : IServiceRepository UPDATE Services SET ServiceType=@ServiceType, - Description=@Description, + Description=@Description WHERE Id=@Id"; connection.Execute(queryUpdate, service); }