Исправлял формы, а то не работало :(

This commit is contained in:
Кашин Максим 2023-04-09 19:30:00 +04:00
parent d8c56a9723
commit 85cf33de52
3 changed files with 49 additions and 44 deletions

View File

@ -31,49 +31,45 @@
this.ReinforcedLabel = new System.Windows.Forms.Label(); this.ReinforcedLabel = new System.Windows.Forms.Label();
this.QuantityLabel = new System.Windows.Forms.Label(); this.QuantityLabel = new System.Windows.Forms.Label();
this.ReindorcedСomboBox = new System.Windows.Forms.ComboBox(); this.ReindorcedСomboBox = new System.Windows.Forms.ComboBox();
this.QuantityTextBox = new System.Windows.Forms.TextBox();
this.SaveButton = new System.Windows.Forms.Button(); this.SaveButton = new System.Windows.Forms.Button();
this.ButtonCancel = new System.Windows.Forms.Button(); this.ButtonCancel = new System.Windows.Forms.Button();
this.numericUpDownCount = new System.Windows.Forms.NumericUpDown();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
// ReinforcedLabel // ReinforcedLabel
// //
this.ReinforcedLabel.AutoSize = true; this.ReinforcedLabel.AutoSize = true;
this.ReinforcedLabel.Location = new System.Drawing.Point(12, 18); this.ReinforcedLabel.Location = new System.Drawing.Point(14, 24);
this.ReinforcedLabel.Name = "ReinforcedLabel"; this.ReinforcedLabel.Name = "ReinforcedLabel";
this.ReinforcedLabel.Size = new System.Drawing.Size(56, 15); this.ReinforcedLabel.Size = new System.Drawing.Size(71, 20);
this.ReinforcedLabel.TabIndex = 0; this.ReinforcedLabel.TabIndex = 0;
this.ReinforcedLabel.Text = "Изделие:"; this.ReinforcedLabel.Text = "Изделие:";
// //
// QuantityLabel // QuantityLabel
// //
this.QuantityLabel.AutoSize = true; this.QuantityLabel.AutoSize = true;
this.QuantityLabel.Location = new System.Drawing.Point(12, 51); this.QuantityLabel.Location = new System.Drawing.Point(14, 68);
this.QuantityLabel.Name = "QuantityLabel"; this.QuantityLabel.Name = "QuantityLabel";
this.QuantityLabel.Size = new System.Drawing.Size(75, 15); this.QuantityLabel.Size = new System.Drawing.Size(93, 20);
this.QuantityLabel.TabIndex = 1; this.QuantityLabel.TabIndex = 1;
this.QuantityLabel.Text = "Количество:"; this.QuantityLabel.Text = "Количество:";
// //
// ReindorcedСomboBox // ReindorcedСomboBox
// //
this.ReindorcedСomboBox.FormattingEnabled = true; this.ReindorcedСomboBox.FormattingEnabled = true;
this.ReindorcedСomboBox.Location = new System.Drawing.Point(88, 15); this.ReindorcedСomboBox.Location = new System.Drawing.Point(101, 20);
this.ReindorcedСomboBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.ReindorcedСomboBox.Name = "ReindorcedСomboBox"; this.ReindorcedСomboBox.Name = "ReindorcedСomboBox";
this.ReindorcedСomboBox.Size = new System.Drawing.Size(184, 23); this.ReindorcedСomboBox.Size = new System.Drawing.Size(210, 28);
this.ReindorcedСomboBox.TabIndex = 2; this.ReindorcedСomboBox.TabIndex = 2;
// //
// QuantityTextBox
//
this.QuantityTextBox.Location = new System.Drawing.Point(88, 48);
this.QuantityTextBox.Name = "QuantityTextBox";
this.QuantityTextBox.Size = new System.Drawing.Size(184, 23);
this.QuantityTextBox.TabIndex = 3;
//
// SaveButton // SaveButton
// //
this.SaveButton.Location = new System.Drawing.Point(72, 100); this.SaveButton.Location = new System.Drawing.Point(82, 133);
this.SaveButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.SaveButton.Name = "SaveButton"; this.SaveButton.Name = "SaveButton";
this.SaveButton.Size = new System.Drawing.Size(97, 29); this.SaveButton.Size = new System.Drawing.Size(111, 39);
this.SaveButton.TabIndex = 4; this.SaveButton.TabIndex = 4;
this.SaveButton.Text = "Сохранить"; this.SaveButton.Text = "Сохранить";
this.SaveButton.UseVisualStyleBackColor = true; this.SaveButton.UseVisualStyleBackColor = true;
@ -81,27 +77,37 @@
// //
// ButtonCancel // ButtonCancel
// //
this.ButtonCancel.Location = new System.Drawing.Point(175, 100); this.ButtonCancel.Location = new System.Drawing.Point(200, 133);
this.ButtonCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.ButtonCancel.Name = "ButtonCancel"; this.ButtonCancel.Name = "ButtonCancel";
this.ButtonCancel.Size = new System.Drawing.Size(97, 29); this.ButtonCancel.Size = new System.Drawing.Size(111, 39);
this.ButtonCancel.TabIndex = 5; this.ButtonCancel.TabIndex = 5;
this.ButtonCancel.Text = "Отмена"; this.ButtonCancel.Text = "Отмена";
this.ButtonCancel.UseVisualStyleBackColor = true; this.ButtonCancel.UseVisualStyleBackColor = true;
this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
// //
// numericUpDownCount
//
this.numericUpDownCount.Location = new System.Drawing.Point(113, 68);
this.numericUpDownCount.Name = "numericUpDownCount";
this.numericUpDownCount.Size = new System.Drawing.Size(198, 27);
this.numericUpDownCount.TabIndex = 7;
//
// FormSellReinforced // FormSellReinforced
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 141); this.ClientSize = new System.Drawing.Size(325, 188);
this.Controls.Add(this.numericUpDownCount);
this.Controls.Add(this.ButtonCancel); this.Controls.Add(this.ButtonCancel);
this.Controls.Add(this.SaveButton); this.Controls.Add(this.SaveButton);
this.Controls.Add(this.QuantityTextBox);
this.Controls.Add(this.ReindorcedСomboBox); this.Controls.Add(this.ReindorcedСomboBox);
this.Controls.Add(this.QuantityLabel); this.Controls.Add(this.QuantityLabel);
this.Controls.Add(this.ReinforcedLabel); this.Controls.Add(this.ReinforcedLabel);
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.Name = "FormSellReinforced"; this.Name = "FormSellReinforced";
this.Text = "Продать Изделие"; this.Text = "Продать Изделие";
((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout(); this.PerformLayout();
@ -112,8 +118,8 @@
private Label ReinforcedLabel; private Label ReinforcedLabel;
private Label QuantityLabel; private Label QuantityLabel;
private ComboBox ReindorcedСomboBox; private ComboBox ReindorcedСomboBox;
private TextBox QuantityTextBox;
private Button SaveButton; private Button SaveButton;
private Button ButtonCancel; private Button ButtonCancel;
private NumericUpDown numericUpDownCount;
} }
} }

View File

@ -1,4 +1,5 @@
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using PrecastConcretePlantBusinessLogic.BusinessLogic;
using PrecastConcretePlantContracts.BusinessLogicsContracts; using PrecastConcretePlantContracts.BusinessLogicsContracts;
using PrecastConcretePlantContracts.SearchModels; using PrecastConcretePlantContracts.SearchModels;
@ -47,40 +48,42 @@ namespace PrecastConcretePlantView
private void SaveButton_Click(object sender, EventArgs e) private void SaveButton_Click(object sender, EventArgs e)
{ {
if (string.IsNullOrEmpty(QuantityTextBox.Text))
{
MessageBox.Show("Укажите количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (ReindorcedСomboBox.SelectedValue == null) if (ReindorcedСomboBox.SelectedValue == null)
{ {
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
} }
if (string.IsNullOrEmpty(numericUpDownCount.Text))
_logger.LogInformation("Product sale."); {
MessageBox.Show("Заполните количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Продажа изделий");
try try
{ {
var operationResult = _logicShop.SellReinforced(_logicReinforced.ReadElement(new ReinforcedSearchModel() var reinforced = _logicReinforced.ReadElement(new()
{ {
Id = Convert.ToInt32(ReindorcedСomboBox.SelectedValue) Id = (int)ReindorcedСomboBox.SelectedValue
})!, Convert.ToInt32(QuantityTextBox.Text)); });
if (reinforced == null)
{
throw new Exception("Изделие не найдено. Дополнительная информация в логах.");
}
var operationResult = _logicShop.SellReinforced(
reinforced: reinforced,
quantity: (int)numericUpDownCount.Value
);
if (!operationResult) if (!operationResult)
{ {
throw new Exception("Ошибка при продаже изделия. Дополнительная информация в логах."); throw new Exception("Ошибка при продаже изделий. Дополнительная информация в логах.");
} }
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK; DialogResult = DialogResult.OK;
Close(); Close();
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Product sale error."); _logger.LogError(ex, "Ошибка сохранения поездки");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
} }

View File

@ -108,7 +108,7 @@ namespace PrecastConcretePlantDatabaseImplement.Implements
return null; return null;
} }
public bool SellReinforcedies(IReinforcedModel model, int count) public bool SellReinforced(IReinforcedModel model, int count)
{ {
using var context = new PrecastConcretePlantDataBase(); using var context = new PrecastConcretePlantDataBase();
using var transaction = context.Database.BeginTransaction(); using var transaction = context.Database.BeginTransaction();
@ -152,9 +152,5 @@ namespace PrecastConcretePlantDatabaseImplement.Implements
} }
} }
public bool SellReinforced(IReinforcedModel model, int quantity)
{
throw new NotImplementedException();
}
} }
} }