add some logic

This commit is contained in:
MaxKarme 2023-04-11 21:52:06 +04:00
parent abc25205ce
commit dbeb844986
10 changed files with 64 additions and 9 deletions

View File

@ -42,6 +42,7 @@
this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.button6 = new System.Windows.Forms.Button();
this.buttonSell = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
@ -174,11 +175,23 @@
this.button6.UseVisualStyleBackColor = true;
this.button6.Click += new System.EventHandler(this.ButtonRestore_Click);
//
// buttonSell
//
this.buttonSell.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonSell.Location = new System.Drawing.Point(987, 328);
this.buttonSell.Name = "buttonSell";
this.buttonSell.Size = new System.Drawing.Size(209, 29);
this.buttonSell.TabIndex = 13;
this.buttonSell.Text = "Продать";
this.buttonSell.UseVisualStyleBackColor = true;
this.buttonSell.Click += new System.EventHandler(this.ButtonSell_Click);
//
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1233, 439);
this.Controls.Add(this.buttonSell);
this.Controls.Add(this.button6);
this.Controls.Add(this.menuStrip1);
this.Controls.Add(this.button3);
@ -214,5 +227,6 @@
private ToolStripMenuItem изделияToolStripMenuItem;
private ToolStripMenuItem магазиныToolStripMenuItem;
private Button button6;
private Button buttonSell;
}
}

View File

@ -159,6 +159,11 @@ namespace Pizzeria
LoadData();
}
private void ButtonSell_Click(object sender, EventArgs e)
{
LoadData();
}
private void ButtonRestore_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShopPizza));

View File

@ -41,6 +41,8 @@
this.labelShop = new System.Windows.Forms.Label();
this.buttonSave = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.textBoxCapacity = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
@ -103,7 +105,7 @@
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowHeadersWidth = 62;
this.dataGridView.RowTemplate.Height = 25;
this.dataGridView.Size = new System.Drawing.Size(664, 296);
this.dataGridView.Size = new System.Drawing.Size(870, 296);
this.dataGridView.TabIndex = 21;
//
// ColumnID
@ -147,7 +149,7 @@
// buttonSave
//
this.buttonSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonSave.Location = new System.Drawing.Point(415, 383);
this.buttonSave.Location = new System.Drawing.Point(621, 383);
this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(137, 30);
@ -159,7 +161,7 @@
// buttonCancel
//
this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonCancel.Location = new System.Drawing.Point(558, 383);
this.buttonCancel.Location = new System.Drawing.Point(764, 383);
this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(118, 30);
@ -168,11 +170,30 @@
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// textBoxCapacity
//
this.textBoxCapacity.Location = new System.Drawing.Point(696, 36);
this.textBoxCapacity.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.textBoxCapacity.Name = "textBoxCapacity";
this.textBoxCapacity.Size = new System.Drawing.Size(186, 27);
this.textBoxCapacity.TabIndex = 29;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(696, 12);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(100, 20);
this.label1.TabIndex = 30;
this.label1.Text = "Вместимость";
//
// FormShop
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(704, 426);
this.ClientSize = new System.Drawing.Size(910, 426);
this.Controls.Add(this.label1);
this.Controls.Add(this.textBoxCapacity);
this.Controls.Add(this.buttonSave);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.dateTimePicker);
@ -206,5 +227,7 @@
private Label labelShop;
private Button buttonSave;
private Button buttonCancel;
private TextBox textBoxCapacity;
private Label label1;
}
}

View File

@ -90,6 +90,7 @@ namespace Pizzeria
Id = _id ?? 0,
ShopName = textBoxName.Text,
Addres = textBoxAddres.Text,
Capacity = Convert.ToInt32(textBoxCapacity.Text),
OpenTime = dateTimePicker.Value.Date,
ShopPizzas = _shopPizzas
};

View File

@ -10,6 +10,7 @@ namespace PizzeriaContracts.BindingModels
public string Addres { get; set; } = String.Empty;
public DateTime OpenTime { get; set; }
public int Capacity { get; set; }
public Dictionary<int, (IPizzaModel, int)> ShopPizzas
{

View File

@ -13,7 +13,8 @@ namespace PizzeriaContracts.ViewModels
public string Addres { get; set; } = string.Empty;
[DisplayName("Дата открытия")]
public DateTime OpenTime { get; set; }
[DisplayName("Вместимость")]
public int Capacity { get; set; }
public Dictionary<int, (IPizzaModel, int)> ShopPizzas
{
get;

View File

@ -12,6 +12,7 @@ namespace PizzeriaDataModels
string Addres { get; }
DateTime OpenTime { get; }
int Capacity { get; }
Dictionary<int, (IPizzaModel, int)> ShopPizzas { get; }
}
}

View File

@ -24,6 +24,7 @@ namespace PizzeriaFileImplement
}
public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement);
public void SavePizzas() => SaveData(Pizzas, PizzaFileName, "Pizzas", x => x.GetXElement);
public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement);
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
private DataFileSingleton()
{

View File

@ -50,7 +50,7 @@ namespace PizzeriaFileImplement.Implements
return null;
}
source.Shops.Add(newShop);
source.SaveData();
source.SaveShops();
return newShop.GetViewModel;
}
public ShopViewModel? Update(ShopBindingModel model)
@ -61,7 +61,7 @@ namespace PizzeriaFileImplement.Implements
return null;
}
shop.Update(model);
source.SaveData();
source.SaveShops();
return shop.GetViewModel;
}
public ShopViewModel? Delete(ShopBindingModel model)
@ -70,7 +70,7 @@ namespace PizzeriaFileImplement.Implements
if (element != null)
{
source.Shops.Remove(element);
source.SaveData();
source.SaveShops();
return element.GetViewModel;
}
return null;

View File

@ -11,6 +11,7 @@ namespace PizzeriaFileImplement.models
public string ShopName { get; set; } = string.Empty;
public string Addres { get; set; } = string.Empty;
public DateTime OpenTime { get; set; }
public int Capacity { get; set; }
public Dictionary<int, int> Pizzas { get; private set; } = new();
private Dictionary<int, (IPizzaModel, int)>? _shopPizzas = null;
public Dictionary<int, (IPizzaModel, int)> ShopPizzas
@ -40,6 +41,7 @@ namespace PizzeriaFileImplement.models
ShopName = model.ShopName,
Addres = model.Addres,
OpenTime = model.OpenTime,
Capacity = model.Capacity,
Pizzas = model.ShopPizzas.ToDictionary(x => x.Key, x => x.Value.Item2)
};
}
@ -49,11 +51,14 @@ namespace PizzeriaFileImplement.models
{
return null;
}
return new Shop()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
ShopName = element.Element("ShopName")!.Value,
Addres = element.Element("Price")!.Value,
Addres = element.Element("Addres")!.Value,
OpenTime = DateTime.Parse(element.Element("OpenTime")!.Value),
Capacity = Convert.ToInt32(element.Element("Capacity")!.Value),
Pizzas = element.Element("ShopPizzas")!.Elements("ShopPizza")
.ToDictionary(
x => Convert.ToInt32(x.Element("Key")?.Value),
@ -78,12 +83,15 @@ namespace PizzeriaFileImplement.models
ShopName = ShopName,
Addres = Addres,
OpenTime = OpenTime,
Capacity = Capacity,
ShopPizzas = ShopPizzas
};
public XElement GetXElement => new("Shop",
new XAttribute("Id", Id),
new XElement("ShopName", ShopName),
new XElement("Addres", Addres),
new XElement("OpenTime", OpenTime),
new XElement("Capacity", Capacity),
new XElement("ShopPizzas", Pizzas.Select(x =>
new XElement("ShopPizza",
new XElement("Key", x.Key),