готова к сдаче

This commit is contained in:
MorozovDanil 2024-12-02 15:20:07 +04:00
parent 194d4f03e4
commit e841730166
3 changed files with 41 additions and 76 deletions

View File

@ -35,7 +35,9 @@
label3 = new Label(); label3 = new Label();
numericUpDown1 = new NumericUpDown(); numericUpDown1 = new NumericUpDown();
dateTimePicker1 = new DateTimePicker(); dateTimePicker1 = new DateTimePicker();
textBox1 = new TextBox(); comboBoxAddress = new ComboBox();
label4 = new Label();
comboBoxDetail = new ComboBox();
((System.ComponentModel.ISupportInitialize)numericUpDown1).BeginInit(); ((System.ComponentModel.ISupportInitialize)numericUpDown1).BeginInit();
SuspendLayout(); SuspendLayout();
// //
@ -100,19 +102,41 @@
dateTimePicker1.Size = new Size(187, 25); dateTimePicker1.Size = new Size(187, 25);
dateTimePicker1.TabIndex = 6; dateTimePicker1.TabIndex = 6;
// //
// textBox1 // comboBoxAddress
// //
textBox1.Location = new Point(127, 15); comboBoxAddress.DropDownStyle = ComboBoxStyle.DropDownList;
textBox1.Name = "textBox1"; comboBoxAddress.FormattingEnabled = true;
textBox1.Size = new Size(175, 25); comboBoxAddress.Location = new Point(119, 148);
textBox1.TabIndex = 7; comboBoxAddress.Name = "comboBoxAddress";
comboBoxAddress.Size = new Size(183, 25);
comboBoxAddress.TabIndex = 8;
//
// label4
//
label4.AutoSize = true;
label4.Location = new Point(15, 151);
label4.Name = "label4";
label4.Size = new Size(91, 17);
label4.TabIndex = 9;
label4.Text = "Адрес склада:";
//
// comboBoxDetail
//
comboBoxDetail.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxDetail.FormattingEnabled = true;
comboBoxDetail.Location = new Point(119, 23);
comboBoxDetail.Name = "comboBoxDetail";
comboBoxDetail.Size = new Size(183, 25);
comboBoxDetail.TabIndex = 10;
// //
// FormStorageDetail // FormStorageDetail
// //
AutoScaleDimensions = new SizeF(7F, 17F); AutoScaleDimensions = new SizeF(7F, 17F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(393, 435); ClientSize = new Size(393, 283);
Controls.Add(textBox1); Controls.Add(comboBoxDetail);
Controls.Add(label4);
Controls.Add(comboBoxAddress);
Controls.Add(dateTimePicker1); Controls.Add(dateTimePicker1);
Controls.Add(numericUpDown1); Controls.Add(numericUpDown1);
Controls.Add(label3); Controls.Add(label3);
@ -136,6 +160,8 @@
private Label label3; private Label label3;
private NumericUpDown numericUpDown1; private NumericUpDown numericUpDown1;
private DateTimePicker dateTimePicker1; private DateTimePicker dateTimePicker1;
private TextBox textBox1; private ComboBox comboBoxAddress;
private Label label4;
private ComboBox comboBoxDetail;
} }
} }

View File

@ -16,16 +16,6 @@ namespace ProjectRepairCompany.Forms
{ {
private readonly IStorageDetailRepository _storageDetailRepository; private readonly IStorageDetailRepository _storageDetailRepository;
private readonly IDetailRepository _detailRepository; private readonly IDetailRepository _detailRepository;
private int? _storageId; // ID записи для редактирования
public int Id
{
set
{
_storageId = value;
LoadData();
}
}
public FormStorageDetail(IStorageDetailRepository storageDetailRepository, IDetailRepository detailRepository) public FormStorageDetail(IStorageDetailRepository storageDetailRepository, IDetailRepository detailRepository)
{ {
@ -34,67 +24,15 @@ namespace ProjectRepairCompany.Forms
_detailRepository = detailRepository ?? throw new ArgumentNullException(nameof(detailRepository)); _detailRepository = detailRepository ?? throw new ArgumentNullException(nameof(detailRepository));
} }
private void FormStorageDetailAdd_Load(object sender, EventArgs e)
{
if (_storageId.HasValue)
{
LoadData();
}
}
private void LoadData()
{
try
{
if (!_storageId.HasValue)
{
return;
}
var storageDetail = _storageDetailRepository.ReadStorageDetails()
.FirstOrDefault(x => x.StorageId == _storageId.Value);
if (storageDetail == null)
{
throw new Exception("Запись не найдена.");
}
textBox1.Text = _detailRepository.ReadDetailById(storageDetail.DetailId)?.NameDetail;
numericUpDown1.Value = storageDetail.DetailCount;
dateTimePicker1.Value = storageDetail.SupplyDate;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка загрузки данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonSave_Click(object sender, EventArgs e) private void ButtonSave_Click(object sender, EventArgs e)
{ {
try try
{ {
// Проверка на заполненность данных if (comboBoxDetail.SelectedIndex < 0 || comboBoxAddress.SelectedIndex < 0 || Convert.ToInt32(numericUpDown1.Value) == 0)
if (string.IsNullOrWhiteSpace(textBox1.Text) || numericUpDown1.Value <= 0)
{ {
throw new Exception("Необходимо заполнить все поля."); throw new Exception("Заполни все поля");
} }
_storageDetailRepository.CreateStorageDetail(StorageDetail.CreateOperation((int)comboBoxAddress.SelectedValue!, (int)comboBoxDetail.SelectedValue!, Convert.ToInt32(numericUpDown1.Value), dateTimePicker1.Value));
// Получение данных из формы
var detail = _detailRepository.ReadDetails()
.FirstOrDefault(d => d.NameDetail == textBox1.Text);
if (detail == null)
{
throw new Exception("Деталь с указанным названием не найдена.");
}
var storageDetail = StorageDetail.CreateOperation(
storageId: _storageId ?? 0,
detailId: detail.Id,
detailCount: (int)numericUpDown1.Value,
supplyDate: dateTimePicker1.Value
);
_storageDetailRepository.CreateStorageDetail(storageDetail);
Close(); Close();
} }
catch (Exception ex) catch (Exception ex)

View File

@ -73,15 +73,16 @@
dataGridView.Size = new Size(607, 450); dataGridView.Size = new Size(607, 450);
dataGridView.TabIndex = 4; dataGridView.TabIndex = 4;
// //
// FormStorageDetail // FormStorageDetails
// //
AutoScaleDimensions = new SizeF(7F, 17F); AutoScaleDimensions = new SizeF(7F, 17F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450); ClientSize = new Size(800, 450);
Controls.Add(dataGridView); Controls.Add(dataGridView);
Controls.Add(panel1); Controls.Add(panel1);
Name = "FormStorageDetail"; Name = "FormStorageDetails";
Text = "Пополнение деталей"; Text = "Пополнение деталей";
Load += FormStorageDetail_Load;
panel1.ResumeLayout(false); panel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false); ResumeLayout(false);