когда же это закончится
This commit is contained in:
parent
3de3f75776
commit
abe9f95aae
@ -44,6 +44,7 @@ namespace DatabaseImplement.Models
|
|||||||
{
|
{
|
||||||
Id = model.Id,
|
Id = model.Id,
|
||||||
Name = model.Name,
|
Name = model.Name,
|
||||||
|
Deals = model.Deals,
|
||||||
Products = model.AvailibleProducts.Select(x => new
|
Products = model.AvailibleProducts.Select(x => new
|
||||||
SupplierProduct
|
SupplierProduct
|
||||||
{
|
{
|
||||||
@ -55,10 +56,12 @@ namespace DatabaseImplement.Models
|
|||||||
public void Update(Database context, SupplierBindingModel model)
|
public void Update(Database context, SupplierBindingModel model)
|
||||||
{
|
{
|
||||||
Name = model.Name;
|
Name = model.Name;
|
||||||
|
|
||||||
|
Debug.WriteLine(model.AvailibleProducts.Keys);
|
||||||
Products = model.AvailibleProducts.Select(x => new
|
Products = model.AvailibleProducts.Select(x => new
|
||||||
SupplierProduct
|
SupplierProduct
|
||||||
{
|
{
|
||||||
Product = context.Products.First(y => y.Id == x.Key),
|
Product = context.Products.First(y => y.Id == x.Value.Item1.Id),
|
||||||
Count = x.Value.Item2
|
Count = x.Value.Item2
|
||||||
}).ToList();
|
}).ToList();
|
||||||
}
|
}
|
||||||
@ -78,28 +81,55 @@ namespace DatabaseImplement.Models
|
|||||||
}
|
}
|
||||||
public void UpdateProducts(Database context, SupplierBindingModel model)
|
public void UpdateProducts(Database context, SupplierBindingModel model)
|
||||||
{
|
{
|
||||||
var supplierProducts = context.SupplierProducts.Where(rec =>
|
var supplierProducts = context.SupplierProducts.Where(rec => rec.SupplierId == model.Id).ToList();
|
||||||
rec.Id == model.Id).ToList();
|
if (supplierProducts != null && supplierProducts.Count > model.AvailibleProducts.Count)
|
||||||
|
{
|
||||||
|
var newList = new List<SupplierProduct>();
|
||||||
|
var trueCount = model.AvailibleProducts.Count;
|
||||||
|
for (int i = 0; i < trueCount; i++)
|
||||||
|
{
|
||||||
|
newList.Add(supplierProducts[i]);
|
||||||
|
}
|
||||||
|
supplierProducts = newList;
|
||||||
|
}
|
||||||
if (supplierProducts != null && supplierProducts.Count > 0)
|
if (supplierProducts != null && supplierProducts.Count > 0)
|
||||||
{ // удалили те, которых нет в модели
|
{ // удалили те, которых нет в модели
|
||||||
context.SupplierProducts.RemoveRange(supplierProducts.Where(rec
|
foreach (var item in supplierProducts)
|
||||||
=> !model.AvailibleProducts.ContainsKey(rec.ProductId)));
|
{
|
||||||
|
bool flag = false;
|
||||||
|
foreach(var product in model.AvailibleProducts)
|
||||||
|
{
|
||||||
|
if (product.Value.Item1.Id == item.ProductId)
|
||||||
|
{
|
||||||
|
flag = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!flag)
|
||||||
|
{
|
||||||
|
context.SupplierProducts.Remove(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
// обновили количество у существующих записей
|
//обновили количество у существующих записей, затем удалили
|
||||||
foreach (var updateProduct in supplierProducts)
|
foreach (var updateProduct in supplierProducts)
|
||||||
{
|
{
|
||||||
updateProduct.Count = model.AvailibleProducts[updateProduct.ProductId].Item2;
|
try
|
||||||
model.AvailibleProducts.Remove(updateProduct.ProductId);
|
{
|
||||||
|
updateProduct.Count = model.AvailibleProducts[updateProduct.Id].Item2;
|
||||||
|
model.AvailibleProducts.Remove(updateProduct.Id);
|
||||||
|
}
|
||||||
|
catch (Exception ex) { }
|
||||||
}
|
}
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
}
|
}
|
||||||
var supplier = context.Suppliers.First(x => x.Id == Id);
|
var supplier = context.Suppliers.First(x => x.Id == Id);
|
||||||
|
// тут всё дюпается, тут должны добавляться те которые остались в модели
|
||||||
foreach (var pc in model.AvailibleProducts)
|
foreach (var pc in model.AvailibleProducts)
|
||||||
{
|
{
|
||||||
context.SupplierProducts.Add(new SupplierProduct
|
context.SupplierProducts.Add(new SupplierProduct
|
||||||
{
|
{
|
||||||
Supplier = supplier,
|
Supplier = supplier,
|
||||||
Product = context.Products.First(x => x.Id == pc.Key),
|
Product = context.Products.First(x => x.Id == pc.Value.Item1.Id),
|
||||||
Count = pc.Value.Item2
|
Count = pc.Value.Item2
|
||||||
});
|
});
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
|
76
WinFormsApp/FormSuppliers.Designer.cs
generated
76
WinFormsApp/FormSuppliers.Designer.cs
generated
@ -29,7 +29,11 @@
|
|||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
groupBoxCreateSupplier = new GroupBox();
|
groupBoxCreateSupplier = new GroupBox();
|
||||||
|
label4 = new Label();
|
||||||
|
label3 = new Label();
|
||||||
|
numericUpDownDeals = new NumericUpDown();
|
||||||
groupBoxSupplierProducts = new GroupBox();
|
groupBoxSupplierProducts = new GroupBox();
|
||||||
|
buttonRefresh = new Button();
|
||||||
label2 = new Label();
|
label2 = new Label();
|
||||||
buttonCancel = new Button();
|
buttonCancel = new Button();
|
||||||
label1 = new Label();
|
label1 = new Label();
|
||||||
@ -46,16 +50,13 @@
|
|||||||
buttonUpdateSupplier = new Button();
|
buttonUpdateSupplier = new Button();
|
||||||
buttonCreateSupplier = new Button();
|
buttonCreateSupplier = new Button();
|
||||||
dataGridView = new DataGridView();
|
dataGridView = new DataGridView();
|
||||||
numericUpDownDeals = new NumericUpDown();
|
|
||||||
label3 = new Label();
|
|
||||||
label4 = new Label();
|
|
||||||
groupBoxCreateSupplier.SuspendLayout();
|
groupBoxCreateSupplier.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericUpDownDeals).BeginInit();
|
||||||
groupBoxSupplierProducts.SuspendLayout();
|
groupBoxSupplierProducts.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)numericUpDownCount).BeginInit();
|
((System.ComponentModel.ISupportInitialize)numericUpDownCount).BeginInit();
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridViewProducts).BeginInit();
|
((System.ComponentModel.ISupportInitialize)dataGridViewProducts).BeginInit();
|
||||||
groupBoxControls.SuspendLayout();
|
groupBoxControls.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||||
((System.ComponentModel.ISupportInitialize)numericUpDownDeals).BeginInit();
|
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// groupBoxCreateSupplier
|
// groupBoxCreateSupplier
|
||||||
@ -74,8 +75,35 @@
|
|||||||
groupBoxCreateSupplier.TabStop = false;
|
groupBoxCreateSupplier.TabStop = false;
|
||||||
groupBoxCreateSupplier.Text = "Создание/изменение поставщика";
|
groupBoxCreateSupplier.Text = "Создание/изменение поставщика";
|
||||||
//
|
//
|
||||||
|
// label4
|
||||||
|
//
|
||||||
|
label4.AutoSize = true;
|
||||||
|
label4.Location = new Point(17, 93);
|
||||||
|
label4.Name = "label4";
|
||||||
|
label4.Size = new Size(87, 15);
|
||||||
|
label4.TabIndex = 15;
|
||||||
|
label4.Text = "Кол-во сделок";
|
||||||
|
//
|
||||||
|
// label3
|
||||||
|
//
|
||||||
|
label3.AutoSize = true;
|
||||||
|
label3.Location = new Point(6, 54);
|
||||||
|
label3.Name = "label3";
|
||||||
|
label3.Size = new Size(101, 15);
|
||||||
|
label3.TabIndex = 14;
|
||||||
|
label3.Text = "Имя поставщика";
|
||||||
|
//
|
||||||
|
// numericUpDownDeals
|
||||||
|
//
|
||||||
|
numericUpDownDeals.Location = new Point(110, 91);
|
||||||
|
numericUpDownDeals.Maximum = new decimal(new int[] { 100000, 0, 0, 0 });
|
||||||
|
numericUpDownDeals.Name = "numericUpDownDeals";
|
||||||
|
numericUpDownDeals.Size = new Size(245, 23);
|
||||||
|
numericUpDownDeals.TabIndex = 14;
|
||||||
|
//
|
||||||
// groupBoxSupplierProducts
|
// groupBoxSupplierProducts
|
||||||
//
|
//
|
||||||
|
groupBoxSupplierProducts.Controls.Add(buttonRefresh);
|
||||||
groupBoxSupplierProducts.Controls.Add(label2);
|
groupBoxSupplierProducts.Controls.Add(label2);
|
||||||
groupBoxSupplierProducts.Controls.Add(buttonCancel);
|
groupBoxSupplierProducts.Controls.Add(buttonCancel);
|
||||||
groupBoxSupplierProducts.Controls.Add(label1);
|
groupBoxSupplierProducts.Controls.Add(label1);
|
||||||
@ -91,6 +119,16 @@
|
|||||||
groupBoxSupplierProducts.TabStop = false;
|
groupBoxSupplierProducts.TabStop = false;
|
||||||
groupBoxSupplierProducts.Text = "Доступные товары поставщика";
|
groupBoxSupplierProducts.Text = "Доступные товары поставщика";
|
||||||
//
|
//
|
||||||
|
// buttonRefresh
|
||||||
|
//
|
||||||
|
buttonRefresh.Location = new Point(58, 307);
|
||||||
|
buttonRefresh.Name = "buttonRefresh";
|
||||||
|
buttonRefresh.Size = new Size(81, 23);
|
||||||
|
buttonRefresh.TabIndex = 14;
|
||||||
|
buttonRefresh.Text = "Обновить";
|
||||||
|
buttonRefresh.UseVisualStyleBackColor = true;
|
||||||
|
buttonRefresh.Click += buttonRefresh_Click;
|
||||||
|
//
|
||||||
// label2
|
// label2
|
||||||
//
|
//
|
||||||
label2.AutoSize = true;
|
label2.AutoSize = true;
|
||||||
@ -108,6 +146,7 @@
|
|||||||
buttonCancel.TabIndex = 5;
|
buttonCancel.TabIndex = 5;
|
||||||
buttonCancel.Text = "Отмена";
|
buttonCancel.Text = "Отмена";
|
||||||
buttonCancel.UseVisualStyleBackColor = true;
|
buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
buttonCancel.Click += buttonCancel_Click;
|
||||||
//
|
//
|
||||||
// label1
|
// label1
|
||||||
//
|
//
|
||||||
@ -237,32 +276,6 @@
|
|||||||
dataGridView.Size = new Size(392, 637);
|
dataGridView.Size = new Size(392, 637);
|
||||||
dataGridView.TabIndex = 4;
|
dataGridView.TabIndex = 4;
|
||||||
//
|
//
|
||||||
// numericUpDownDeals
|
|
||||||
//
|
|
||||||
numericUpDownDeals.Location = new Point(110, 91);
|
|
||||||
numericUpDownDeals.Maximum = new decimal(new int[] { 100000, 0, 0, 0 });
|
|
||||||
numericUpDownDeals.Name = "numericUpDownDeals";
|
|
||||||
numericUpDownDeals.Size = new Size(245, 23);
|
|
||||||
numericUpDownDeals.TabIndex = 14;
|
|
||||||
//
|
|
||||||
// label3
|
|
||||||
//
|
|
||||||
label3.AutoSize = true;
|
|
||||||
label3.Location = new Point(6, 54);
|
|
||||||
label3.Name = "label3";
|
|
||||||
label3.Size = new Size(101, 15);
|
|
||||||
label3.TabIndex = 14;
|
|
||||||
label3.Text = "Имя поставщика";
|
|
||||||
//
|
|
||||||
// label4
|
|
||||||
//
|
|
||||||
label4.AutoSize = true;
|
|
||||||
label4.Location = new Point(17, 93);
|
|
||||||
label4.Name = "label4";
|
|
||||||
label4.Size = new Size(87, 15);
|
|
||||||
label4.TabIndex = 15;
|
|
||||||
label4.Text = "Кол-во сделок";
|
|
||||||
//
|
|
||||||
// FormSuppliers
|
// FormSuppliers
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
@ -276,13 +289,13 @@
|
|||||||
Load += FormSuppliers_Load;
|
Load += FormSuppliers_Load;
|
||||||
groupBoxCreateSupplier.ResumeLayout(false);
|
groupBoxCreateSupplier.ResumeLayout(false);
|
||||||
groupBoxCreateSupplier.PerformLayout();
|
groupBoxCreateSupplier.PerformLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericUpDownDeals).EndInit();
|
||||||
groupBoxSupplierProducts.ResumeLayout(false);
|
groupBoxSupplierProducts.ResumeLayout(false);
|
||||||
groupBoxSupplierProducts.PerformLayout();
|
groupBoxSupplierProducts.PerformLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)numericUpDownCount).EndInit();
|
((System.ComponentModel.ISupportInitialize)numericUpDownCount).EndInit();
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridViewProducts).EndInit();
|
((System.ComponentModel.ISupportInitialize)dataGridViewProducts).EndInit();
|
||||||
groupBoxControls.ResumeLayout(false);
|
groupBoxControls.ResumeLayout(false);
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||||
((System.ComponentModel.ISupportInitialize)numericUpDownDeals).EndInit();
|
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -309,5 +322,6 @@
|
|||||||
private Label label4;
|
private Label label4;
|
||||||
private Label label3;
|
private Label label3;
|
||||||
private NumericUpDown numericUpDownDeals;
|
private NumericUpDown numericUpDownDeals;
|
||||||
|
private Button buttonRefresh;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -54,16 +54,6 @@ namespace WinFormsApp
|
|||||||
|
|
||||||
private void LoadSupplierData()
|
private void LoadSupplierData()
|
||||||
{
|
{
|
||||||
if (_id.HasValue)
|
|
||||||
{
|
|
||||||
var view = _supplierLogic.ReadElement(new SupplierSearchModel
|
|
||||||
{
|
|
||||||
Id = _id.Value
|
|
||||||
});
|
|
||||||
_supplierProducts = view.AvailibleProducts;
|
|
||||||
textBoxName.Text = view.Name;
|
|
||||||
numericUpDownDeals.Value = view.Deals;
|
|
||||||
}
|
|
||||||
dataGridViewProducts.Rows.Clear();
|
dataGridViewProducts.Rows.Clear();
|
||||||
foreach (var pc in _supplierProducts)
|
foreach (var pc in _supplierProducts)
|
||||||
{
|
{
|
||||||
@ -110,6 +100,9 @@ namespace WinFormsApp
|
|||||||
{
|
{
|
||||||
Id = _id.Value
|
Id = _id.Value
|
||||||
});
|
});
|
||||||
|
_supplierProducts = view.AvailibleProducts;
|
||||||
|
textBoxName.Text = view.Name;
|
||||||
|
numericUpDownDeals.Value = view.Deals;
|
||||||
LoadSupplierData();
|
LoadSupplierData();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,7 +212,7 @@ namespace WinFormsApp
|
|||||||
};
|
};
|
||||||
|
|
||||||
var operationResult = _id.HasValue ? _supplierLogic.Update(model) : _supplierLogic.Create(model);
|
var operationResult = _id.HasValue ? _supplierLogic.Update(model) : _supplierLogic.Create(model);
|
||||||
|
|
||||||
if (!operationResult)
|
if (!operationResult)
|
||||||
{
|
{
|
||||||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||||
@ -235,17 +228,22 @@ namespace WinFormsApp
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
LoadData();
|
LoadData();
|
||||||
_id = null;
|
_id = null;
|
||||||
_supplierProducts.Clear();
|
_supplierProducts = new Dictionary<Guid, (IProduct, int)>;
|
||||||
textBoxName.Text = string.Empty;
|
textBoxName.Text = string.Empty;
|
||||||
numericUpDownDeals.Value = 0;
|
numericUpDownDeals.Value = 0;
|
||||||
groupBoxControls.Enabled = true;
|
//groupBoxControls.Enabled = true;
|
||||||
groupBoxControls.Show();
|
groupBoxControls.Show();
|
||||||
groupBoxCreateSupplier.Enabled = false;
|
//groupBoxCreateSupplier.Enabled = false;
|
||||||
groupBoxCreateSupplier.Hide();
|
groupBoxCreateSupplier.Hide();
|
||||||
textBoxName.Text = string.Empty;
|
textBoxName.Text = string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void buttonRefresh_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadSupplierData();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user