Готовая лабораторная 5 (усложненная)

This commit is contained in:
Даниил Путинцев 2024-06-17 02:33:27 +04:00
parent 33bb6ab207
commit 6708dbcc76
6 changed files with 155 additions and 1 deletions

View File

@ -15,7 +15,7 @@ optionsBuilder)
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseSqlServer(@"Data Source=.\SQLEXPRESS;Initial Catalog=FoodOrdersDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
optionsBuilder.UseSqlServer(@"Data Source=.\SQLEXPRESS;Initial Catalog=FoodOrdersDatabaseHard;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
}
base.OnConfiguring(optionsBuilder);
}
@ -23,6 +23,8 @@ optionsBuilder)
public virtual DbSet<Dish> Dishs { set; get; }
public virtual DbSet<DishComponent> DishComponents { set; get; }
public virtual DbSet<Order> Orders { set; get; }
public virtual DbSet<Shop> Shops { set; get; }
public virtual DbSet<ShopDish> ShopDishs { set; get; }
public virtual DbSet<Client> Clients { set; get; }
}
}

View File

@ -151,6 +151,59 @@ namespace FoodOrdersDatabaseImplement.Migrations
b.ToTable("Orders");
});
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Shop", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Address")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("DateOpening")
.HasColumnType("datetime2");
b.Property<int>("MaxCountDishs")
.HasColumnType("int");
b.Property<string>("ShopName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Shops");
});
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.ShopDish", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("DishId")
.HasColumnType("int");
b.Property<int>("ShopId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("DishId");
b.HasIndex("ShopId");
b.ToTable("ShopDishs");
});
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.DishComponent", b =>
{
b.HasOne("FoodOrdersDatabaseImplement.Models.Component", "Component")
@ -184,9 +237,28 @@ namespace FoodOrdersDatabaseImplement.Migrations
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Dish");
});
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.ShopDish", b =>
{
b.HasOne("FoodOrdersDatabaseImplement.Models.Dish", "Dish")
.WithMany("ShopDishs")
.HasForeignKey("DishId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FoodOrdersDatabaseImplement.Models.Shop", "Shop")
.WithMany("Dishs")
.HasForeignKey("ShopId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Client");
b.Navigation("Dish");
b.Navigation("Shop");
});
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Client", b =>
@ -204,6 +276,13 @@ namespace FoodOrdersDatabaseImplement.Migrations
b.Navigation("Components");
b.Navigation("Orders");
b.Navigation("ShopDishs");
});
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Shop", b =>
{
b.Navigation("Dishs");
});
#pragma warning restore 612, 618
}

View File

@ -14,6 +14,7 @@ namespace FoodOrdersFileImplement
private readonly string DishFileName = "Dish.xml";
private readonly string ClientFileName = "Client.xml";
private readonly string ShopFileName = "Shop.xml";
public List<Component> Components { get; private set; }
public List<Order> Orders { get; private set; }
@ -21,6 +22,8 @@ namespace FoodOrdersFileImplement
public List<Dish> Dishs { get; private set; }
public List<Client> Clients { get; private set; }
public List<Shop> Shops { get; private set; }
public static DataFileSingleton GetInstance()
{
if (instance == null)
@ -37,12 +40,15 @@ namespace FoodOrdersFileImplement
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement);
public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement);
private DataFileSingleton()
{
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
Dishs = LoadData(DishFileName, "Dish", x => Dish.Create(x)!)!;
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!;
Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!;
}
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)

View File

@ -10,6 +10,8 @@ namespace FoodOrdersListImplement
public List<Order> Orders { get; set; }
public List<Dish> Dishes { get; set; }
public List<Shop> Shops { get; set; }
public List<Dish> Dishs { get; set; }
public List<Client> Clients { get; private set; }
@ -17,6 +19,8 @@ namespace FoodOrdersListImplement
{
Components = new List<Component>();
Orders = new List<Order>();
Dishes = new List<Dish>();
Shops = new List<Shop>();
Dishs = new List<Dish>();
Clients = new List<Client>();
}

View File

@ -188,5 +188,60 @@ namespace FoodOrdersView
form.ShowDialog();
}
}
private void магазиныToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShops));
if (service is FormShops form)
{
form.ShowDialog();
}
}
private void пополнениеМагазинаToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormMakeShipment));
if (service is FormMakeShipment form)
{
form.ShowDialog();
}
}
private void продажаБлюдToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormDishSale));
if (service is FormDishSale form)
{
form.ShowDialog();
}
}
private void списокМагазиновToolStripMenuItem_Click(object sender, EventArgs e)
{
using var dialog = new SaveFileDialog { Filter = "docx|*.docx" };
if (dialog.ShowDialog() == DialogResult.OK)
{
_reportLogic.SaveShopsToWordFile(new ReportBindingModel { FileName = dialog.FileName });
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void загруженностьМагазиновToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormReportShopDishs));
if (service is FormReportShopDishs form)
{
form.ShowDialog();
}
}
private void заказыПоДатамToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormReportGroupedOrders));
if (service is FormReportGroupedOrders form)
{
form.ShowDialog();
}
}
}
}

View File

@ -40,12 +40,14 @@ namespace FoodOrdersView
services.AddTransient<IComponentStorage, ComponentStorage>();
services.AddTransient<IOrderStorage, OrderStorage>();
services.AddTransient<IDishStorage, DishStorage>();
services.AddTransient<IShopStorage, ShopStorage>();
services.AddTransient<IClientStorage, ClientStorage>();
services.AddTransient<IComponentLogic, ComponentLogic>();
services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<IDishLogic, DishLogic>();
services.AddTransient<IReportLogic, ReportLogic>();
services.AddTransient<IShopLogic, ShopLogic>();
services.AddTransient<IClientLogic, ClientLogic>();
services.AddTransient<AbstractSaveToWord, SaveToWord>();
@ -62,6 +64,12 @@ namespace FoodOrdersView
services.AddTransient<FormDishes>();
services.AddTransient<FormReportDishComponents>();
services.AddTransient<FormReportOrders>();
services.AddTransient<FormShop>();
services.AddTransient<FormShops>();
services.AddTransient<FormMakeShipment>();
services.AddTransient<FormDishSale>();
services.AddTransient<FormReportShopDishs>();
services.AddTransient<FormReportGroupedOrders>();
}
}
}