последние доработки
This commit is contained in:
parent
ae95a6a1bc
commit
ada6f48ad7
@ -29,12 +29,12 @@ namespace SnackBarView
|
|||||||
_logger.LogInformation("Loading snack for order");
|
_logger.LogInformation("Loading snack for order");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var iceCreamList = _logicIC.ReadList(null);
|
var snackList = _logicIC.ReadList(null);
|
||||||
if (iceCreamList != null)
|
if (snackList != null)
|
||||||
{
|
{
|
||||||
comboBoxSnack.DisplayMember = "SnackName";
|
comboBoxSnack.DisplayMember = "SnackName";
|
||||||
comboBoxSnack.ValueMember = "Id";
|
comboBoxSnack.ValueMember = "Id";
|
||||||
comboBoxSnack.DataSource = iceCreamList;
|
comboBoxSnack.DataSource = snackList;
|
||||||
comboBoxSnack.SelectedItem = null;
|
comboBoxSnack.SelectedItem = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ namespace SnackBarView
|
|||||||
|
|
||||||
private int? _id;
|
private int? _id;
|
||||||
|
|
||||||
private Dictionary<int, (IComponentModel, int)> _iceCreamComponents;
|
private Dictionary<int, (IComponentModel, int)> _snackComponents;
|
||||||
|
|
||||||
public int Id { set { _id = value; } }
|
public int Id { set { _id = value; } }
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ namespace SnackBarView
|
|||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_logic = logic;
|
_logic = logic;
|
||||||
_iceCreamComponents = new Dictionary<int, (IComponentModel, int)>();
|
_snackComponents = new Dictionary<int, (IComponentModel, int)>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FormSnack_Load(object sender, EventArgs e)
|
private void FormSnack_Load(object sender, EventArgs e)
|
||||||
@ -49,7 +49,7 @@ namespace SnackBarView
|
|||||||
{
|
{
|
||||||
textBoxName.Text = view.SnackName;
|
textBoxName.Text = view.SnackName;
|
||||||
textBoxPrice.Text = view.Price.ToString();
|
textBoxPrice.Text = view.Price.ToString();
|
||||||
_iceCreamComponents = view.SnackComponents ?? new Dictionary<int, (IComponentModel, int)>();
|
_snackComponents = view.SnackComponents ?? new Dictionary<int, (IComponentModel, int)>();
|
||||||
LoadData();
|
LoadData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -66,12 +66,12 @@ namespace SnackBarView
|
|||||||
_logger.LogInformation("Snack components loading");
|
_logger.LogInformation("Snack components loading");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (_iceCreamComponents != null)
|
if (_snackComponents != null)
|
||||||
{
|
{
|
||||||
dataGridView.Rows.Clear();
|
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();
|
textBoxPrice.Text = CalcPrice().ToString();
|
||||||
}
|
}
|
||||||
@ -95,13 +95,13 @@ namespace SnackBarView
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_logger.LogInformation("Adding new component: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count);
|
_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
|
else
|
||||||
{
|
{
|
||||||
_iceCreamComponents.Add(form.Id, (form.ComponentModel, form.Count));
|
_snackComponents.Add(form.Id, (form.ComponentModel, form.Count));
|
||||||
}
|
}
|
||||||
LoadData();
|
LoadData();
|
||||||
}
|
}
|
||||||
@ -117,7 +117,7 @@ namespace SnackBarView
|
|||||||
{
|
{
|
||||||
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 = _iceCreamComponents[id].Item2;
|
form.Count = _snackComponents[id].Item2;
|
||||||
if (form.ShowDialog() == DialogResult.OK)
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
if (form.ComponentModel == null)
|
if (form.ComponentModel == null)
|
||||||
@ -125,7 +125,7 @@ namespace SnackBarView
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_logger.LogInformation("Component editing: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count);
|
_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();
|
LoadData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -142,7 +142,7 @@ namespace SnackBarView
|
|||||||
{
|
{
|
||||||
_logger.LogInformation("Deletion of component: {ComponentName} - {Count}", dataGridView.SelectedRows[0].Cells[1].Value,
|
_logger.LogInformation("Deletion of component: {ComponentName} - {Count}", dataGridView.SelectedRows[0].Cells[1].Value,
|
||||||
dataGridView.SelectedRows[0].Cells[2].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)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -170,7 +170,7 @@ namespace SnackBarView
|
|||||||
MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (_iceCreamComponents == null || _iceCreamComponents.Count == 0)
|
if (_snackComponents == null || _snackComponents.Count == 0)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
return;
|
return;
|
||||||
@ -183,7 +183,7 @@ namespace SnackBarView
|
|||||||
Id = _id ?? 0,
|
Id = _id ?? 0,
|
||||||
SnackName = textBoxName.Text,
|
SnackName = textBoxName.Text,
|
||||||
Price = Convert.ToDouble(textBoxPrice.Text),
|
Price = Convert.ToDouble(textBoxPrice.Text),
|
||||||
SnackComponents = _iceCreamComponents
|
SnackComponents = _snackComponents
|
||||||
};
|
};
|
||||||
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
|
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
|
||||||
if (!operationResult)
|
if (!operationResult)
|
||||||
@ -210,7 +210,7 @@ namespace SnackBarView
|
|||||||
private double CalcPrice()
|
private double CalcPrice()
|
||||||
{
|
{
|
||||||
double price = 0;
|
double price = 0;
|
||||||
foreach (var elem in _iceCreamComponents)
|
foreach (var elem in _snackComponents)
|
||||||
{
|
{
|
||||||
price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2);
|
price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user