вроде полный фикс

This commit is contained in:
MorozovDanil 2024-12-15 16:20:27 +04:00
parent a8a2fd350e
commit 8a60aa872a
7 changed files with 132 additions and 84 deletions

View File

@ -32,7 +32,7 @@
ButtonCancel = new Button();
label1 = new Label();
label2 = new Label();
dateTimePicker1 = new DateTimePicker();
dateTimePickerOrderDate = new DateTimePicker();
dateTimeCompletion = new DateTimePicker();
dateTimeIssue = new DateTimePicker();
label3 = new Label();
@ -40,12 +40,12 @@
numericUpDownFullPrice = new NumericUpDown();
label5 = new Label();
comboBoxMaster = new ComboBox();
groupBox1 = new GroupBox();
groupBoxDetail = new GroupBox();
dataGridView = new DataGridView();
Detail = new DataGridViewComboBoxColumn();
DetailCount = new DataGridViewTextBoxColumn();
((System.ComponentModel.ISupportInitialize)numericUpDownFullPrice).BeginInit();
groupBox1.SuspendLayout();
groupBoxDetail.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
@ -89,13 +89,13 @@
label2.TabIndex = 3;
label2.Text = "Дата начала работы:";
//
// dateTimePicker1
// dateTimePickerOrderDate
//
dateTimePicker1.Enabled = false;
dateTimePicker1.Location = new Point(190, 12);
dateTimePicker1.Name = "dateTimePicker1";
dateTimePicker1.Size = new Size(188, 25);
dateTimePicker1.TabIndex = 4;
dateTimePickerOrderDate.Enabled = false;
dateTimePickerOrderDate.Location = new Point(190, 12);
dateTimePickerOrderDate.Name = "dateTimePickerOrderDate";
dateTimePickerOrderDate.Size = new Size(188, 25);
dateTimePickerOrderDate.TabIndex = 4;
//
// dateTimeCompletion
//
@ -156,28 +156,31 @@
comboBoxMaster.Size = new Size(182, 25);
comboBoxMaster.TabIndex = 11;
//
// groupBox1
// groupBoxDetail
//
groupBox1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
groupBox1.Controls.Add(dataGridView);
groupBox1.Location = new Point(30, 234);
groupBox1.Name = "groupBox1";
groupBox1.Size = new Size(401, 224);
groupBox1.TabIndex = 12;
groupBox1.TabStop = false;
groupBox1.Text = "groupBox1";
groupBoxDetail.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
groupBoxDetail.Controls.Add(dataGridView);
groupBoxDetail.Location = new Point(30, 234);
groupBoxDetail.Name = "groupBoxDetail";
groupBoxDetail.RightToLeft = RightToLeft.No;
groupBoxDetail.Size = new Size(401, 224);
groupBoxDetail.TabIndex = 12;
groupBoxDetail.TabStop = false;
groupBoxDetail.Text = "Детали";
//
// dataGridView
//
dataGridView.AllowUserToDeleteRows = false;
dataGridView.AllowUserToResizeColumns = false;
dataGridView.AllowUserToResizeRows = false;
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Columns.AddRange(new DataGridViewColumn[] { Detail, DetailCount });
dataGridView.Location = new Point(3, 21);
dataGridView.MultiSelect = false;
dataGridView.Name = "dataGridView";
dataGridView.RowHeadersVisible = false;
dataGridView.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;
dataGridView.Size = new Size(395, 200);
dataGridView.TabIndex = 0;
//
@ -196,7 +199,7 @@
AutoScaleDimensions = new SizeF(7F, 17F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(461, 532);
Controls.Add(groupBox1);
Controls.Add(groupBoxDetail);
Controls.Add(comboBoxMaster);
Controls.Add(label5);
Controls.Add(numericUpDownFullPrice);
@ -204,7 +207,7 @@
Controls.Add(label3);
Controls.Add(dateTimeIssue);
Controls.Add(dateTimeCompletion);
Controls.Add(dateTimePicker1);
Controls.Add(dateTimePickerOrderDate);
Controls.Add(label2);
Controls.Add(label1);
Controls.Add(ButtonCancel);
@ -213,7 +216,7 @@
StartPosition = FormStartPosition.CenterParent;
Text = "Заказ";
((System.ComponentModel.ISupportInitialize)numericUpDownFullPrice).EndInit();
groupBox1.ResumeLayout(false);
groupBoxDetail.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
PerformLayout();
@ -225,7 +228,7 @@
private Button ButtonCancel;
private Label label1;
private Label label2;
private DateTimePicker dateTimePicker1;
private DateTimePicker dateTimePickerOrderDate;
private DateTimePicker dateTimeCompletion;
private DateTimePicker dateTimeIssue;
private Label label3;
@ -233,7 +236,7 @@
private NumericUpDown numericUpDownFullPrice;
private Label label5;
private ComboBox comboBoxMaster;
private GroupBox groupBox1;
private GroupBox groupBoxDetail;
private DataGridView dataGridView;
private DataGridViewComboBoxColumn Detail;
private DataGridViewTextBoxColumn DetailCount;

View File

@ -12,15 +12,48 @@ namespace ProjectRepairCompany.Forms
public partial class FormOrder : Form
{
private readonly IOrderRepository _orderRepository;
private readonly IDetailRepository _detailRepository;
private int? _orderId;
public int Id
{
set
{
try
{
var order = _orderRepository.ReadOrderById(value);
if (order == null)
{
throw new InvalidOperationException(nameof(order));
}
comboBoxMaster.SelectedValue = order.MasterId;
numericUpDownFullPrice.Value = (decimal)order.FullPrice;
dateTimeCompletion.Value = order.DateCompletion;
dateTimeIssue.Value = order.DateIssue;
foreach (var detail in order.OrderDetails)
{
dataGridView.Rows.Add(detail.DetailId, detail.DetailCount);
}
_orderId = value;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
}
public FormOrder(IOrderRepository orderRepository, IMasterRepository masterRepository, IDetailRepository detailRepository)
{
InitializeComponent();
_orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository));
comboBoxMaster.DataSource = masterRepository.ReadMasters();
comboBoxMaster.DisplayMember = "Name";
comboBoxMaster.DisplayMember = "MasterName";
comboBoxMaster.ValueMember = "Id";
Detail.DataSource = detailRepository.ReadDetails();
@ -37,29 +70,16 @@ namespace ProjectRepairCompany.Forms
throw new Exception("Имеются незаполненные поля.");
}
var order = Order.CreateOperation(
id: 0,
fullPrice: (int)numericUpDownFullPrice.Value,
masterId: (int)comboBoxMaster.SelectedValue!,
dateCompletion: dateTimeCompletion.Value,
dateIssue: dateTimeIssue.Value);
foreach (DataGridViewRow row in dataGridView.Rows)
var order = CreateOrder();
if (_orderId.HasValue)
{
if (row.Cells["Detail"].Value == null || row.Cells["DetailCount"].Value == null)
{
continue;
}
int detailId = (int)row.Cells["Detail"].Value;
int detailCount = int.Parse(row.Cells["DetailCount"].Value.ToString() ?? "0");
var detailPrice = (int)_detailRepository.ReadDetailById(detailId).PriceDetail;
order.AddOrderDetail(detailId, detailPrice, detailCount);
_orderRepository.UpdateOrder(order);
}
_orderRepository.CreateOrder(order);
else
{
_orderRepository.CreateOrder(order);
}
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
@ -69,5 +89,36 @@ namespace ProjectRepairCompany.Forms
}
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
private List<OrderDetail> CreateListOrderDetailsFromDataGrid()
{
var list = new List<OrderDetail>();
foreach (DataGridViewRow row in dataGridView.Rows)
{
if (row.Cells["Detail"].Value == null ||
row.Cells["DetailCount"].Value == null)
{
continue;
}
list.Add(OrderDetail.CreateOperation(0,
Convert.ToInt32(row.Cells["Detail"].Value),
Convert.ToInt32(row.Cells["DetailCount"].Value)));
}
return list;
}
private Order CreateOrder()
{
var orderDetails = CreateListOrderDetailsFromDataGrid();
return Order.CreateOperation(
_orderId ?? 0,
Convert.ToInt32(numericUpDownFullPrice.Value),
(int)comboBoxMaster.SelectedValue,
dateTimeCompletion.Value,
dateTimeIssue.Value,
orderDetails
);
}
}
}

View File

@ -1,4 +1,5 @@
using ProjectRepairCompany.Repositories;
using ProjectRepairCompany.Entities;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@ -53,16 +54,19 @@ namespace ProjectRepairCompany.Forms
private void ButtonUp_Click(object sender, EventArgs e)
{
if (!TryGetIdentifierFromSelectRow(out int findId))
if (!TryGetIdentifierFromSelectRow(out var findId))
{
return;
}
try
{
var form = _container.Resolve<FormMaster>();
var form = _container.Resolve<FormOrder>();
form.Id = findId;
form.ShowDialog();
LoadList();
if (form.ShowDialog() == DialogResult.OK)
{
LoadList();
dataGridView.Refresh();
}
}
catch (Exception ex)
{
@ -72,7 +76,7 @@ namespace ProjectRepairCompany.Forms
private void ButtonDel_Click(object sender, EventArgs e)
{
if (!TryGetIdentifierFromSelectRow(out int findId))
if (!TryGetIdentifierFromSelectRow(out var findId))
{
return;
}
@ -91,17 +95,7 @@ namespace ProjectRepairCompany.Forms
}
}
private void LoadList()
{
try
{
dataGridView.DataSource = _orderRepository.ReadOrders();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка загрузки данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void LoadList() => dataGridView.DataSource = _orderRepository.ReadOrders();
private bool TryGetIdentifierFromSelectRow(out int id)
{

View File

@ -33,12 +33,12 @@
label1 = new Label();
label2 = new Label();
label3 = new Label();
numericUpDown1 = new NumericUpDown();
dateTimePicker1 = new DateTimePicker();
numericUpDownCount = new NumericUpDown();
dateTimePickerDate = new DateTimePicker();
comboBoxAddress = new ComboBox();
label4 = new Label();
comboBoxDetail = new ComboBox();
((System.ComponentModel.ISupportInitialize)numericUpDown1).BeginInit();
((System.ComponentModel.ISupportInitialize)numericUpDownCount).BeginInit();
SuspendLayout();
//
// ButtonSave
@ -88,19 +88,19 @@
label3.TabIndex = 4;
label3.Text = "Дата";
//
// numericUpDown1
// numericUpDownCount
//
numericUpDown1.Location = new Point(128, 62);
numericUpDown1.Name = "numericUpDown1";
numericUpDown1.Size = new Size(154, 25);
numericUpDown1.TabIndex = 5;
numericUpDownCount.Location = new Point(128, 62);
numericUpDownCount.Name = "numericUpDownCount";
numericUpDownCount.Size = new Size(154, 25);
numericUpDownCount.TabIndex = 5;
//
// dateTimePicker1
// dateTimePickerDate
//
dateTimePicker1.Location = new Point(119, 104);
dateTimePicker1.Name = "dateTimePicker1";
dateTimePicker1.Size = new Size(187, 25);
dateTimePicker1.TabIndex = 6;
dateTimePickerDate.Location = new Point(119, 104);
dateTimePickerDate.Name = "dateTimePickerDate";
dateTimePickerDate.Size = new Size(187, 25);
dateTimePickerDate.TabIndex = 6;
//
// comboBoxAddress
//
@ -137,8 +137,8 @@
Controls.Add(comboBoxDetail);
Controls.Add(label4);
Controls.Add(comboBoxAddress);
Controls.Add(dateTimePicker1);
Controls.Add(numericUpDown1);
Controls.Add(dateTimePickerDate);
Controls.Add(numericUpDownCount);
Controls.Add(label3);
Controls.Add(label2);
Controls.Add(label1);
@ -146,7 +146,7 @@
Controls.Add(ButtonSave);
Name = "FormStorageDetail";
Text = "FormStorageDetail";
((System.ComponentModel.ISupportInitialize)numericUpDown1).EndInit();
((System.ComponentModel.ISupportInitialize)numericUpDownCount).EndInit();
ResumeLayout(false);
PerformLayout();
}
@ -158,8 +158,8 @@
private Label label1;
private Label label2;
private Label label3;
private NumericUpDown numericUpDown1;
private DateTimePicker dateTimePicker1;
private NumericUpDown numericUpDownCount;
private DateTimePicker dateTimePickerDate;
private ComboBox comboBoxAddress;
private Label label4;
private ComboBox comboBoxDetail;

View File

@ -28,11 +28,11 @@ namespace ProjectRepairCompany.Forms
{
try
{
if (comboBoxDetail.SelectedIndex < 0 || comboBoxAddress.SelectedIndex < 0 || Convert.ToInt32(numericUpDown1.Value) == 0)
if (comboBoxDetail.SelectedIndex < 0 || comboBoxAddress.SelectedIndex < 0 || Convert.ToInt32(numericUpDownCount.Value) == 0)
{
throw new Exception("Заполни все поля");
}
_storageDetailRepository.CreateStorageDetail(StorageDetail.CreateOperation((int)comboBoxAddress.SelectedValue!, (int)comboBoxDetail.SelectedValue!, Convert.ToInt32(numericUpDown1.Value), dateTimePicker1.Value));
_storageDetailRepository.CreateStorageDetail(StorageDetail.CreateOperation((int)comboBoxAddress.SelectedValue!, (int)comboBoxDetail.SelectedValue!, Convert.ToInt32(numericUpDownCount.Value), dateTimePickerDate.Value));
Close();
}
catch (Exception ex)

View File

@ -81,7 +81,7 @@
Controls.Add(dataGridView);
Controls.Add(panel1);
Name = "FormStorageDetails";
Text = "Пополнение деталей";
Text = "Пополнение складов";
Load += FormStorageDetail_Load;
panel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();

View File

@ -34,7 +34,7 @@ namespace ProjectRepairCompany.Forms
{
try
{
_container.Resolve<FormStorageDetail>().ShowDialog(); // Форма добавления StorageDetail
_container.Resolve<FormStorageDetail>().ShowDialog();
LoadList();
}
catch (Exception ex)