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

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.QuantityLabel = new System.Windows.Forms.Label();
this.ReindorcedСomboBox = new System.Windows.Forms.ComboBox();
this.QuantityTextBox = new System.Windows.Forms.TextBox();
this.SaveButton = 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();
//
// ReinforcedLabel
//
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.Size = new System.Drawing.Size(56, 15);
this.ReinforcedLabel.Size = new System.Drawing.Size(71, 20);
this.ReinforcedLabel.TabIndex = 0;
this.ReinforcedLabel.Text = "Изделие:";
//
// QuantityLabel
//
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.Size = new System.Drawing.Size(75, 15);
this.QuantityLabel.Size = new System.Drawing.Size(93, 20);
this.QuantityLabel.TabIndex = 1;
this.QuantityLabel.Text = "Количество:";
//
// ReindorcedСomboBox
//
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.Size = new System.Drawing.Size(184, 23);
this.ReindorcedСomboBox.Size = new System.Drawing.Size(210, 28);
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
//
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.Size = new System.Drawing.Size(97, 29);
this.SaveButton.Size = new System.Drawing.Size(111, 39);
this.SaveButton.TabIndex = 4;
this.SaveButton.Text = "Сохранить";
this.SaveButton.UseVisualStyleBackColor = true;
@ -81,27 +77,37 @@
//
// 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.Size = new System.Drawing.Size(97, 29);
this.ButtonCancel.Size = new System.Drawing.Size(111, 39);
this.ButtonCancel.TabIndex = 5;
this.ButtonCancel.Text = "Отмена";
this.ButtonCancel.UseVisualStyleBackColor = true;
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
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
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.SaveButton);
this.Controls.Add(this.QuantityTextBox);
this.Controls.Add(this.ReindorcedСomboBox);
this.Controls.Add(this.QuantityLabel);
this.Controls.Add(this.ReinforcedLabel);
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.Name = "FormSellReinforced";
this.Text = "Продать Изделие";
((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
@ -112,8 +118,8 @@
private Label ReinforcedLabel;
private Label QuantityLabel;
private ComboBox ReindorcedСomboBox;
private TextBox QuantityTextBox;
private Button SaveButton;
private Button ButtonCancel;
private NumericUpDown numericUpDownCount;
}
}

View File

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

View File

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