последние доработки

This commit is contained in:
Алексей Крюков 2024-02-12 12:51:37 +04:00
parent ae95a6a1bc
commit ada6f48ad7
2 changed files with 18 additions and 18 deletions

View File

@ -29,12 +29,12 @@ namespace SnackBarView
_logger.LogInformation("Loading snack for order");
try
{
var iceCreamList = _logicIC.ReadList(null);
if (iceCreamList != null)
var snackList = _logicIC.ReadList(null);
if (snackList != null)
{
comboBoxSnack.DisplayMember = "SnackName";
comboBoxSnack.ValueMember = "Id";
comboBoxSnack.DataSource = iceCreamList;
comboBoxSnack.DataSource = snackList;
comboBoxSnack.SelectedItem = null;
}
}

View File

@ -25,7 +25,7 @@ namespace SnackBarView
private int? _id;
private Dictionary<int, (IComponentModel, int)> _iceCreamComponents;
private Dictionary<int, (IComponentModel, int)> _snackComponents;
public int Id { set { _id = value; } }
@ -34,7 +34,7 @@ namespace SnackBarView
InitializeComponent();
_logger = logger;
_logic = logic;
_iceCreamComponents = new Dictionary<int, (IComponentModel, int)>();
_snackComponents = new Dictionary<int, (IComponentModel, int)>();
}
private void FormSnack_Load(object sender, EventArgs e)
@ -49,7 +49,7 @@ namespace SnackBarView
{
textBoxName.Text = view.SnackName;
textBoxPrice.Text = view.Price.ToString();
_iceCreamComponents = view.SnackComponents ?? new Dictionary<int, (IComponentModel, int)>();
_snackComponents = view.SnackComponents ?? new Dictionary<int, (IComponentModel, int)>();
LoadData();
}
}
@ -66,12 +66,12 @@ namespace SnackBarView
_logger.LogInformation("Snack components loading");
try
{
if (_iceCreamComponents != null)
if (_snackComponents != null)
{
dataGridView.Rows.Clear();
foreach (var iceCreamC in _iceCreamComponents)
foreach (var snackC in _snackComponents)
{
dataGridView.Rows.Add(new object[] { iceCreamC.Key, iceCreamC.Value.Item1.ComponentName, iceCreamC.Value.Item2 });
dataGridView.Rows.Add(new object[] { snackC.Key, snackC.Value.Item1.ComponentName, snackC.Value.Item2 });
}
textBoxPrice.Text = CalcPrice().ToString();
}
@ -95,13 +95,13 @@ namespace SnackBarView
return;
}
_logger.LogInformation("Adding new component: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count);
if (_iceCreamComponents.ContainsKey(form.Id))
if (_snackComponents.ContainsKey(form.Id))
{
_iceCreamComponents[form.Id] = (form.ComponentModel, form.Count);
_snackComponents[form.Id] = (form.ComponentModel, form.Count);
}
else
{
_iceCreamComponents.Add(form.Id, (form.ComponentModel, form.Count));
_snackComponents.Add(form.Id, (form.ComponentModel, form.Count));
}
LoadData();
}
@ -117,7 +117,7 @@ namespace SnackBarView
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
form.Id = id;
form.Count = _iceCreamComponents[id].Item2;
form.Count = _snackComponents[id].Item2;
if (form.ShowDialog() == DialogResult.OK)
{
if (form.ComponentModel == null)
@ -125,7 +125,7 @@ namespace SnackBarView
return;
}
_logger.LogInformation("Component editing: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count);
_iceCreamComponents[form.Id] = (form.ComponentModel, form.Count);
_snackComponents[form.Id] = (form.ComponentModel, form.Count);
LoadData();
}
}
@ -142,7 +142,7 @@ namespace SnackBarView
{
_logger.LogInformation("Deletion of component: {ComponentName} - {Count}", dataGridView.SelectedRows[0].Cells[1].Value,
dataGridView.SelectedRows[0].Cells[2].Value);
_iceCreamComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value));
_snackComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value));
}
catch (Exception ex)
{
@ -170,7 +170,7 @@ namespace SnackBarView
MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (_iceCreamComponents == null || _iceCreamComponents.Count == 0)
if (_snackComponents == null || _snackComponents.Count == 0)
{
MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
@ -183,7 +183,7 @@ namespace SnackBarView
Id = _id ?? 0,
SnackName = textBoxName.Text,
Price = Convert.ToDouble(textBoxPrice.Text),
SnackComponents = _iceCreamComponents
SnackComponents = _snackComponents
};
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
if (!operationResult)
@ -210,7 +210,7 @@ namespace SnackBarView
private double CalcPrice()
{
double price = 0;
foreach (var elem in _iceCreamComponents)
foreach (var elem in _snackComponents)
{
price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2);
}