Исправления
This commit is contained in:
parent
48a5b72bbb
commit
785d086b3f
@ -52,7 +52,8 @@ namespace ConfectioneryListImplement
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
Address = Address,
|
||||
Pastries = Pastries
|
||||
Pastries = Pastries,
|
||||
DateOpening = DateOpening,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
1
Confectionery/FormShop.Designer.cs
generated
1
Confectionery/FormShop.Designer.cs
generated
@ -163,6 +163,7 @@
|
||||
this.Controls.Add(this.label1);
|
||||
this.Name = "FormShop";
|
||||
this.Text = "Просмотр изделий магазина";
|
||||
this.Load += new System.EventHandler(this.FormShop_Load);
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
@ -23,34 +23,21 @@ namespace ConfectioneryView
|
||||
private readonly List<ShopViewModel>? _listShops;
|
||||
private readonly IShopLogic _logic;
|
||||
private readonly ILogger _logger;
|
||||
private IShopModel? _currentShopModel;
|
||||
|
||||
public int Id
|
||||
{
|
||||
get
|
||||
{
|
||||
return Convert.ToInt32(comboBoxShop.SelectedValue);
|
||||
}
|
||||
set
|
||||
{
|
||||
comboBoxShop.SelectedValue = value;
|
||||
}
|
||||
}
|
||||
public IShopModel? ShopModel
|
||||
{
|
||||
get => _currentShopModel;
|
||||
get; set;
|
||||
}
|
||||
|
||||
private IShopModel? GetShop()
|
||||
{
|
||||
var list = _logic.ReadList(null);
|
||||
if (list == null)
|
||||
if (_listShops == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
foreach (var elem in list)
|
||||
foreach (var elem in _listShops)
|
||||
{
|
||||
if (elem.Id == this.Id)
|
||||
if (elem.Id == Id)
|
||||
{
|
||||
return elem;
|
||||
}
|
||||
@ -77,22 +64,18 @@ namespace ConfectioneryView
|
||||
{
|
||||
try
|
||||
{
|
||||
var currentShop = _logic.ReadElement(new() { Id = this.Id});
|
||||
if (currentShop != null)
|
||||
var model = GetShop();
|
||||
if (model != null)
|
||||
{
|
||||
var vmodel = GetShop();
|
||||
if (vmodel != null)
|
||||
{
|
||||
comboBoxShop.Text = vmodel.Name;
|
||||
textBoxAddress.Text = vmodel.Address;
|
||||
textBoxDateOpening.Text = Convert.ToString(vmodel.DateOpening);
|
||||
}
|
||||
comboBoxShop.Text = model.Name;
|
||||
textBoxAddress.Text = model.Address;
|
||||
textBoxDateOpening.Text = Convert.ToString(model.DateOpening);
|
||||
|
||||
dataGridView.Rows.Clear();
|
||||
foreach (var el in currentShop.Pastries.Values)
|
||||
foreach (var el in model.Pastries.Values)
|
||||
{
|
||||
dataGridView.Rows.Add(new object[]{el.Item1.PastryName, el.Item1.Price, el.Item2 });
|
||||
}
|
||||
|
||||
}
|
||||
_logger.LogInformation("Загрузка магазинов");
|
||||
}
|
||||
@ -126,13 +109,6 @@ namespace ConfectioneryView
|
||||
_logger.LogInformation("Сохранение изделия");
|
||||
try
|
||||
{
|
||||
var vmodel = GetShop();
|
||||
if (vmodel != null)
|
||||
{
|
||||
_currentShopModel = vmodel;
|
||||
return;
|
||||
}
|
||||
// Создаем новый магазин если не нашли такого
|
||||
DateTime.TryParse(textBoxDateOpening.Text, out var dateTime);
|
||||
ShopBindingModel model = new()
|
||||
{
|
||||
@ -140,8 +116,18 @@ namespace ConfectioneryView
|
||||
Address = textBoxAddress.Text,
|
||||
DateOpening = dateTime
|
||||
};
|
||||
var operationResult = _logic.Create(model);
|
||||
_currentShopModel = model;
|
||||
var vmodel = GetShop();
|
||||
bool operationResult = false;
|
||||
|
||||
if (vmodel != null)
|
||||
{
|
||||
model.Id = vmodel.Id;
|
||||
operationResult = _logic.Update(model);
|
||||
}
|
||||
else
|
||||
{
|
||||
operationResult = _logic.Create(model);
|
||||
}
|
||||
if (!operationResult)
|
||||
{
|
||||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||
@ -163,5 +149,10 @@ namespace ConfectioneryView
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
|
||||
private void FormShop_Load(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,9 @@ namespace ConfectioneryView
|
||||
if (list != null)
|
||||
{
|
||||
dataGridView.DataSource = list;
|
||||
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
dataGridView.Columns["Pastries"].Visible = false;
|
||||
dataGridView.Columns["Name"].AutoSizeMode =
|
||||
DataGridViewAutoSizeColumnMode.Fill;
|
||||
}
|
||||
@ -57,26 +59,14 @@ namespace ConfectioneryView
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormShop));
|
||||
if (service is FormShop form)
|
||||
{
|
||||
var id = form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
var model = form.ShopModel;
|
||||
if (model != null)
|
||||
{
|
||||
_logic.Update(new()
|
||||
{
|
||||
Id = id,
|
||||
Address = model.Address,
|
||||
Name = model.Name,
|
||||
DateOpening= model.DateOpening,
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private void ButtonDel_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
|
Loading…
Reference in New Issue
Block a user