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