Шаг 6. Исправление неправильного оформления

This commit is contained in:
Кашин Максим 2023-01-30 23:32:09 +04:00
parent c3b6653f5c
commit 1b1b8ee7bf
4 changed files with 71 additions and 71 deletions

View File

@ -28,24 +28,24 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.PackageNameLabel = new System.Windows.Forms.Label(); this.ReinforcedNameLabel = new System.Windows.Forms.Label();
this.CountLabel = new System.Windows.Forms.Label(); this.CountLabel = new System.Windows.Forms.Label();
this.SumLabel = new System.Windows.Forms.Label(); this.SumLabel = new System.Windows.Forms.Label();
this.PackageComboBox = new System.Windows.Forms.ComboBox(); this.ReinforcedComboBox = new System.Windows.Forms.ComboBox();
this.CountTextBox = new System.Windows.Forms.TextBox(); this.CountTextBox = new System.Windows.Forms.TextBox();
this.SumTextBox = new System.Windows.Forms.TextBox(); this.SumTextBox = new System.Windows.Forms.TextBox();
this.ButtonCancel = new System.Windows.Forms.Button(); this.ButtonCancel = new System.Windows.Forms.Button();
this.SaveButton = new System.Windows.Forms.Button(); this.SaveButton = new System.Windows.Forms.Button();
this.SuspendLayout(); this.SuspendLayout();
// //
// PackageNameLabel // ReinforcedNameLabel
// //
this.PackageNameLabel.AutoSize = true; this.ReinforcedNameLabel.AutoSize = true;
this.PackageNameLabel.Location = new System.Drawing.Point(12, 9); this.ReinforcedNameLabel.Location = new System.Drawing.Point(12, 9);
this.PackageNameLabel.Name = "PackageNameLabel"; this.ReinforcedNameLabel.Name = "ReinforcedNameLabel";
this.PackageNameLabel.Size = new System.Drawing.Size(59, 15); this.ReinforcedNameLabel.Size = new System.Drawing.Size(59, 15);
this.PackageNameLabel.TabIndex = 0; this.ReinforcedNameLabel.TabIndex = 0;
this.PackageNameLabel.Text = "Изделие: "; this.ReinforcedNameLabel.Text = "Изделие: ";
// //
// CountLabel // CountLabel
// //
@ -65,14 +65,14 @@
this.SumLabel.TabIndex = 2; this.SumLabel.TabIndex = 2;
this.SumLabel.Text = "Сумма: "; this.SumLabel.Text = "Сумма: ";
// //
// PackageComboBox // ReinforcedComboBox
// //
this.PackageComboBox.FormattingEnabled = true; this.ReinforcedComboBox.FormattingEnabled = true;
this.PackageComboBox.Location = new System.Drawing.Point(93, 6); this.ReinforcedComboBox.Location = new System.Drawing.Point(93, 6);
this.PackageComboBox.Name = "PackageComboBox"; this.ReinforcedComboBox.Name = "ReinforcedComboBox";
this.PackageComboBox.Size = new System.Drawing.Size(201, 23); this.ReinforcedComboBox.Size = new System.Drawing.Size(201, 23);
this.PackageComboBox.TabIndex = 3; this.ReinforcedComboBox.TabIndex = 3;
this.PackageComboBox.SelectedIndexChanged += new System.EventHandler(this.PackageComboBox_SelectedIndexChanged); this.ReinforcedComboBox.SelectedIndexChanged += new System.EventHandler(this.ReinforcedComboBox_SelectedIndexChanged);
// //
// CountTextBox // CountTextBox
// //
@ -118,10 +118,10 @@
this.Controls.Add(this.ButtonCancel); this.Controls.Add(this.ButtonCancel);
this.Controls.Add(this.SumTextBox); this.Controls.Add(this.SumTextBox);
this.Controls.Add(this.CountTextBox); this.Controls.Add(this.CountTextBox);
this.Controls.Add(this.PackageComboBox); this.Controls.Add(this.ReinforcedComboBox);
this.Controls.Add(this.SumLabel); this.Controls.Add(this.SumLabel);
this.Controls.Add(this.CountLabel); this.Controls.Add(this.CountLabel);
this.Controls.Add(this.PackageNameLabel); this.Controls.Add(this.ReinforcedNameLabel);
this.Name = "FormCreateOrder"; this.Name = "FormCreateOrder";
this.Text = "Заказ"; this.Text = "Заказ";
this.ResumeLayout(false); this.ResumeLayout(false);
@ -131,10 +131,10 @@
#endregion #endregion
private Label PackageNameLabel; private Label ReinforcedNameLabel;
private Label CountLabel; private Label CountLabel;
private Label SumLabel; private Label SumLabel;
private ComboBox PackageComboBox; private ComboBox ReinforcedComboBox;
private TextBox CountTextBox; private TextBox CountTextBox;
private TextBox SumTextBox; private TextBox SumTextBox;
private Button ButtonCancel; private Button ButtonCancel;

View File

@ -39,10 +39,10 @@ namespace PrecastConcretePlantView
var list = _logicP.ReadList(null); var list = _logicP.ReadList(null);
if (list != null) if (list != null)
{ {
PackageComboBox.DisplayMember = "ReinforcedName"; ReinforcedComboBox.DisplayMember = "ReinforcedName";
PackageComboBox.ValueMember = "Id"; ReinforcedComboBox.ValueMember = "Id";
PackageComboBox.DataSource = list; ReinforcedComboBox.DataSource = list;
PackageComboBox.SelectedItem = null; ReinforcedComboBox.SelectedItem = null;
} }
} }
@ -60,11 +60,11 @@ namespace PrecastConcretePlantView
private void CalcSum() private void CalcSum()
{ {
if (PackageComboBox.SelectedValue != null && !string.IsNullOrEmpty(CountTextBox.Text)) if (ReinforcedComboBox.SelectedValue != null && !string.IsNullOrEmpty(CountTextBox.Text))
{ {
try try
{ {
int id = Convert.ToInt32(PackageComboBox.SelectedValue); int id = Convert.ToInt32(ReinforcedComboBox.SelectedValue);
var reinforced = _logicP.ReadElement(new ReinforcedSearchModel var reinforced = _logicP.ReadElement(new ReinforcedSearchModel
{ {
@ -88,11 +88,6 @@ namespace PrecastConcretePlantView
CalcSum(); CalcSum();
} }
private void PackageComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
CalcSum();
}
private void SaveButton_Click(object sender, EventArgs e) private void SaveButton_Click(object sender, EventArgs e)
{ {
if (string.IsNullOrEmpty(CountTextBox.Text)) if (string.IsNullOrEmpty(CountTextBox.Text))
@ -101,7 +96,7 @@ namespace PrecastConcretePlantView
return; return;
} }
if (PackageComboBox.SelectedValue == null) if (ReinforcedComboBox.SelectedValue == null)
{ {
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
@ -113,7 +108,7 @@ namespace PrecastConcretePlantView
{ {
var operationResult = _logicO.CreateOrder(new OrderBindingModel var operationResult = _logicO.CreateOrder(new OrderBindingModel
{ {
ReinforcedId = Convert.ToInt32(PackageComboBox.SelectedValue), ReinforcedId = Convert.ToInt32(ReinforcedComboBox.SelectedValue),
Count = Convert.ToInt32(CountTextBox.Text), Count = Convert.ToInt32(CountTextBox.Text),
Sum = Convert.ToDouble(SumTextBox.Text) Sum = Convert.ToDouble(SumTextBox.Text)
}); });
@ -139,5 +134,10 @@ namespace PrecastConcretePlantView
DialogResult = DialogResult.Cancel; DialogResult = DialogResult.Cancel;
Close(); Close();
} }
private void ReinforcedComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
CalcSum();
}
} }
} }

View File

@ -31,9 +31,9 @@
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle5 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle5 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle6 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle6 = new System.Windows.Forms.DataGridViewCellStyle();
this.PackageNameLabel = new System.Windows.Forms.Label(); this.ReinforcedNameLabel = new System.Windows.Forms.Label();
this.PriceLabel = new System.Windows.Forms.Label(); this.PriceLabel = new System.Windows.Forms.Label();
this.PackageNameTextBox = new System.Windows.Forms.TextBox(); this.ReinforcedNameTextBox = new System.Windows.Forms.TextBox();
this.PriceTextBox = new System.Windows.Forms.TextBox(); this.PriceTextBox = new System.Windows.Forms.TextBox();
this.ComponentsGroupBox = new System.Windows.Forms.GroupBox(); this.ComponentsGroupBox = new System.Windows.Forms.GroupBox();
this.UpdateButton = new System.Windows.Forms.Button(); this.UpdateButton = new System.Windows.Forms.Button();
@ -50,14 +50,14 @@
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
// PackageNameLabel // ReinforcedNameLabel
// //
this.PackageNameLabel.AutoSize = true; this.ReinforcedNameLabel.AutoSize = true;
this.PackageNameLabel.Location = new System.Drawing.Point(12, 9); this.ReinforcedNameLabel.Location = new System.Drawing.Point(12, 9);
this.PackageNameLabel.Name = "PackageNameLabel"; this.ReinforcedNameLabel.Name = "ReinforcedNameLabel";
this.PackageNameLabel.Size = new System.Drawing.Size(65, 15); this.ReinforcedNameLabel.Size = new System.Drawing.Size(65, 15);
this.PackageNameLabel.TabIndex = 0; this.ReinforcedNameLabel.TabIndex = 0;
this.PackageNameLabel.Text = "Название: "; this.ReinforcedNameLabel.Text = "Название: ";
// //
// PriceLabel // PriceLabel
// //
@ -68,12 +68,12 @@
this.PriceLabel.TabIndex = 1; this.PriceLabel.TabIndex = 1;
this.PriceLabel.Text = "Стоимость: "; this.PriceLabel.Text = "Стоимость: ";
// //
// PackageNameTextBox // ReinforcedNameTextBox
// //
this.PackageNameTextBox.Location = new System.Drawing.Point(83, 6); this.ReinforcedNameTextBox.Location = new System.Drawing.Point(83, 6);
this.PackageNameTextBox.Name = "PackageNameTextBox"; this.ReinforcedNameTextBox.Name = "ReinforcedNameTextBox";
this.PackageNameTextBox.Size = new System.Drawing.Size(283, 23); this.ReinforcedNameTextBox.Size = new System.Drawing.Size(283, 23);
this.PackageNameTextBox.TabIndex = 2; this.ReinforcedNameTextBox.TabIndex = 2;
// //
// PriceTextBox // PriceTextBox
// //
@ -210,7 +210,7 @@
this.SaveButton.UseVisualStyleBackColor = true; this.SaveButton.UseVisualStyleBackColor = true;
this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click); this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click);
// //
// FormPackage // FormReinforced
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
@ -219,10 +219,10 @@
this.Controls.Add(this.ButtonCancel); this.Controls.Add(this.ButtonCancel);
this.Controls.Add(this.ComponentsGroupBox); this.Controls.Add(this.ComponentsGroupBox);
this.Controls.Add(this.PriceTextBox); this.Controls.Add(this.PriceTextBox);
this.Controls.Add(this.PackageNameTextBox); this.Controls.Add(this.ReinforcedNameTextBox);
this.Controls.Add(this.PriceLabel); this.Controls.Add(this.PriceLabel);
this.Controls.Add(this.PackageNameLabel); this.Controls.Add(this.ReinforcedNameLabel);
this.Name = "FormPackage"; this.Name = "FormReinforced";
this.Text = "Изделие"; this.Text = "Изделие";
this.ComponentsGroupBox.ResumeLayout(false); this.ComponentsGroupBox.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit();
@ -233,9 +233,9 @@
#endregion #endregion
private Label PackageNameLabel; private Label ReinforcedNameLabel;
private Label PriceLabel; private Label PriceLabel;
private TextBox PackageNameTextBox; private TextBox ReinforcedNameTextBox;
private TextBox PriceTextBox; private TextBox PriceTextBox;
private GroupBox ComponentsGroupBox; private GroupBox ComponentsGroupBox;
private Button UpdateButton; private Button UpdateButton;

View File

@ -24,7 +24,7 @@ namespace PrecastConcretePlantView
private int? _id; private int? _id;
private Dictionary<int, (IComponentModel, int)> _packageComponents; private Dictionary<int, (IComponentModel, int)> _reinforcedComponents;
public int Id { set { _id = value; } } public int Id { set { _id = value; } }
public FormReinforced(ILogger<FormReinforced> logger, IReinforcedLogic logic) public FormReinforced(ILogger<FormReinforced> logger, IReinforcedLogic logic)
@ -32,9 +32,9 @@ namespace PrecastConcretePlantView
InitializeComponent(); InitializeComponent();
_logger = logger; _logger = logger;
_logic = logic; _logic = logic;
_packageComponents = new Dictionary<int, (IComponentModel, int)>(); _reinforcedComponents = new Dictionary<int, (IComponentModel, int)>();
} }
private void FormPackage_Load(object sender, EventArgs e) private void FormReinforced_Load(object sender, EventArgs e)
{ {
if (_id.HasValue) if (_id.HasValue)
{ {
@ -49,9 +49,9 @@ namespace PrecastConcretePlantView
if (view != null) if (view != null)
{ {
PackageNameTextBox.Text = view.ReinforcedName; ReinforcedNameTextBox.Text = view.ReinforcedName;
PriceTextBox.Text = view.Price.ToString(); PriceTextBox.Text = view.Price.ToString();
_packageComponents = view.ReinforcedComponents ?? new Dictionary<int, (IComponentModel, int)>(); _reinforcedComponents = view.ReinforcedComponents ?? new Dictionary<int, (IComponentModel, int)>();
LoadData(); LoadData();
} }
} }
@ -68,10 +68,10 @@ namespace PrecastConcretePlantView
try try
{ {
if (_packageComponents != null) if (_reinforcedComponents != null)
{ {
DataGridView.Rows.Clear(); DataGridView.Rows.Clear();
foreach (var pc in _packageComponents) foreach (var pc in _reinforcedComponents)
{ {
DataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 }); DataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 });
} }
@ -99,14 +99,14 @@ namespace PrecastConcretePlantView
_logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); _logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count);
if (_packageComponents.ContainsKey(form.Id)) if (_reinforcedComponents.ContainsKey(form.Id))
{ {
_packageComponents[form.Id] = (form.ComponentModel, form.Count); _reinforcedComponents[form.Id] = (form.ComponentModel, form.Count);
} }
else else
{ {
_packageComponents.Add(form.Id, (form.ComponentModel, form.Count)); _reinforcedComponents.Add(form.Id, (form.ComponentModel, form.Count));
} }
LoadData(); LoadData();
@ -124,7 +124,7 @@ namespace PrecastConcretePlantView
{ {
int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells[0].Value); int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells[0].Value);
form.Id = id; form.Id = id;
form.Count = _packageComponents[id].Item2; form.Count = _reinforcedComponents[id].Item2;
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
@ -134,7 +134,7 @@ namespace PrecastConcretePlantView
} }
_logger.LogInformation("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); _logger.LogInformation("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count);
_packageComponents[form.Id] = (form.ComponentModel, form.Count); _reinforcedComponents[form.Id] = (form.ComponentModel, form.Count);
LoadData(); LoadData();
} }
} }
@ -150,7 +150,7 @@ namespace PrecastConcretePlantView
try try
{ {
_logger.LogInformation("Удаление компонента: { ComponentName} - { Count}", DataGridView.SelectedRows[0].Cells[1].Value); _logger.LogInformation("Удаление компонента: { ComponentName} - { Count}", DataGridView.SelectedRows[0].Cells[1].Value);
_packageComponents?.Remove(Convert.ToInt32(DataGridView.SelectedRows[0].Cells[0].Value)); _reinforcedComponents?.Remove(Convert.ToInt32(DataGridView.SelectedRows[0].Cells[0].Value));
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -169,7 +169,7 @@ namespace PrecastConcretePlantView
private void SaveButton_Click(object sender, EventArgs e) private void SaveButton_Click(object sender, EventArgs e)
{ {
if (string.IsNullOrEmpty(PackageNameTextBox.Text)) if (string.IsNullOrEmpty(ReinforcedNameTextBox.Text))
{ {
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
@ -181,7 +181,7 @@ namespace PrecastConcretePlantView
return; return;
} }
if (_packageComponents == null || _packageComponents.Count == 0) if (_reinforcedComponents == null || _reinforcedComponents.Count == 0)
{ {
MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
@ -194,9 +194,9 @@ namespace PrecastConcretePlantView
var model = new ReinforcedBindingModel var model = new ReinforcedBindingModel
{ {
Id = _id ?? 0, Id = _id ?? 0,
ReinforcedName = PackageNameTextBox.Text, ReinforcedName = ReinforcedNameTextBox.Text,
Price = Convert.ToDouble(PriceTextBox.Text), Price = Convert.ToDouble(PriceTextBox.Text),
ReinforcedComponents = _packageComponents ReinforcedComponents = _reinforcedComponents
}; };
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
@ -227,7 +227,7 @@ namespace PrecastConcretePlantView
{ {
double price = 0; double price = 0;
foreach (var elem in _packageComponents) foreach (var elem in _reinforcedComponents)
{ {
price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2);
} }