diff --git a/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/ReportLogic.cs b/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/ReportLogic.cs index 7f3f226..2412ee0 100644 --- a/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/ReportLogic.cs @@ -1,6 +1,10 @@ -using ComputerShopContracts.BindingModels; +using ComputerShopBusinessLogic.OfficePackage; +using ComputerShopBusinessLogic.OfficePackage.HelperModels; +using ComputerShopContracts.BindingModels; using ComputerShopContracts.BusinessLogicContracts; +using ComputerShopContracts.StorageContracts; using ComputerShopContracts.ViewModels; +using ComputerShopContracts.SearchModels; using System; using System.Collections.Generic; using System.Linq; @@ -9,37 +13,83 @@ using System.Threading.Tasks; namespace ComputerShopBusinessLogic.BusinessLogics { - //public class ReportLogic : IReportLogic - //{ - // private readonly IBlankStorage _blankStorage; - // private readonly IDocumentStorage _documentStorage; - // private readonly IOrderStorage _orderStorage; - // private readonly AbstractSaveToExcel _saveToExcel; - // private readonly AbstractSaveToWord _saveToWord; - // private readonly AbstractSaveToPdf _saveToPdf; - // public List GetPurchaseReceiving() - // { - // throw new NotImplementedException(); - // } + public class ReportLogic : IReportLogic + { + private readonly IComponentStorage _componentStorage; + private readonly ISupplyStorage _supplyStorage; + private readonly IAssemblyStorage _assemblyStorage; + private readonly IEquipmentReceivingStorage _receivingStorage; + private readonly AbstractSaveToExcel _saveToExcel; + private readonly AbstractSaveToWord _saveToWord; + private readonly AbstractSaveToPdf _saveToPdf; - // public List GetPurchaseSupply() - // { - // throw new NotImplementedException(); - // } + public ReportLogic(IComponentStorage componentStorage, IAssemblyStorage assemblyStorage, IEquipmentReceivingStorage receivingStorage, ISupplyStorage supplyStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) + { + _componentStorage = componentStorage; + _assemblyStorage = assemblyStorage; + _receivingStorage = receivingStorage; + _supplyStorage = supplyStorage; + _saveToExcel = saveToExcel; + _saveToWord = saveToWord; + _saveToPdf = saveToPdf; + } - // public void SaveOrdersToPdfFile(ReportBindingModel model) - // { - // throw new NotImplementedException(); - // } + public List GetComponentReceivings(List ids) + { + var result = new List(); - // public void SavePackagesToWordFile(ReportBindingModel model) - // { - // throw new NotImplementedException(); - // } + List components = new List(); + foreach (int id in ids) + { + var component = _componentStorage.GetElement(new ComponentSearchModel() + { + Id = id, + }); + if (component != null) components.Add(component); + } + - // public void SaveProductComponentToExcelFile(ReportBindingModel model) - // { - // throw new NotImplementedException(); - // } - //} + return result; + } + + public void SaveReceivingComponentsToWordFile(ReportBindingModel model) + { + //_saveToWord.CreateDoc(new WordInfoProvider + //{ + // FileName = model.FileName, + // Title = "Список получений по компонентам", + // ComponentReceivings = GetComponentReceivings(model.Ids) + //}); + } + + public void SaveReceivingComponentsToXmlFile(ReportBindingModel mode) + { + + } + + public List GetPurchaseReceiving() + { + throw new NotImplementedException(); + } + + public List GetPurchaseSupply() + { + throw new NotImplementedException(); + } + + public void SaveOrdersToPdfFile(ReportBindingModel model) + { + throw new NotImplementedException(); + } + + public void SavePackagesToWordFile(ReportBindingModel model) + { + throw new NotImplementedException(); + } + + public void SaveProductComponentToExcelFile(ReportBindingModel model) + { + throw new NotImplementedException(); + } + } } diff --git a/ComputerShopProvider/ComputerShopBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/ComputerShopProvider/ComputerShopBusinessLogic/OfficePackage/AbstractSaveToWord.cs index 8cacbaa..2e8f9ec 100644 --- a/ComputerShopProvider/ComputerShopBusinessLogic/OfficePackage/AbstractSaveToWord.cs +++ b/ComputerShopProvider/ComputerShopBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -1,4 +1,6 @@ -using System; +using ComputerShopBusinessLogic.OfficePackage.HelperEnums; +using ComputerShopBusinessLogic.OfficePackage.HelperModels; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -8,5 +10,53 @@ namespace ComputerShopBusinessLogic.OfficePackage { public class AbstractSaveToWord { + public void CreateDoc(WordInfoProvider info) + { + //CreateWord(info); + + //CreateParagraph(new WordParagraph + //{ + // Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24", }) }, + // TextProperties = new WordTextProperties + // { + // Size = "24", + // JustificationType = WordJustificationType.Center + // } + //}); + + //foreach (var mc in info.MemberConferences) + //{ + // CreateParagraph(new WordParagraph + // { + // Texts = new List<(string, WordTextProperties)> + // { (mc.MemberFIO, new WordTextProperties { Size = "20", Bold=true})}, + // TextProperties = new WordTextProperties + // { + // Size = "24", + // JustificationType = WordJustificationType.Both + // } + // }); + + // foreach (var conference in mc.Conferences) + // { + // CreateParagraph(new WordParagraph + // { + // Texts = new List<(string, WordTextProperties)> + // { (conference.Item1 + " - ", new WordTextProperties { Size = "16", Bold=false}), + // (conference.Item2.ToShortDateString(), new WordTextProperties { Size = "16", Bold=false})}, + // TextProperties = new WordTextProperties + // { + // Size = "24", + // JustificationType = WordJustificationType.Both + // } + // }); + // } + //} + //SaveWord(info); + } + + //protected abstract void CreateWord(WordInfoOrganiser info); + //protected abstract void CreateParagraph(WordParagraph paragraph); + //protected abstract void SaveWord(WordInfoOrganiser info); } } diff --git a/ComputerShopProvider/ComputerShopBusinessLogic/OfficePackage/HelperModels/WordInfoProvider.cs b/ComputerShopProvider/ComputerShopBusinessLogic/OfficePackage/HelperModels/WordInfoProvider.cs new file mode 100644 index 0000000..fb69f23 --- /dev/null +++ b/ComputerShopProvider/ComputerShopBusinessLogic/OfficePackage/HelperModels/WordInfoProvider.cs @@ -0,0 +1,16 @@ +using ComputerShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputerShopBusinessLogic.OfficePackage.HelperModels +{ + public class WordInfoProvider + { + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + public Dictionary> ComponentReceivings { get; set; } = new(); + } +} diff --git a/ComputerShopProvider/ComputerShopClientApp/Controllers/HomeController.cs b/ComputerShopProvider/ComputerShopClientApp/Controllers/HomeController.cs index 4c57e82..54549cf 100644 --- a/ComputerShopProvider/ComputerShopClientApp/Controllers/HomeController.cs +++ b/ComputerShopProvider/ComputerShopClientApp/Controllers/HomeController.cs @@ -43,6 +43,24 @@ namespace ComputerShopClientApp.Controllers return View(APIClient.GetRequest>($"api/Assembly/getassemblylist?clientId={APIClient.Client.Id}")); } + public IActionResult Report() + { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + return View(); + } + + public IActionResult ReportDocXml() + { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest>($"api/Component/getcomponentlist?clientId={APIClient.Client.Id}")); + } + [HttpGet] public IActionResult Privacy() { @@ -84,6 +102,51 @@ namespace ComputerShopClientApp.Controllers return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); } + [HttpPost] + public void ListMemberConferenceToFile(int[] Ids, string type) + { + if (APIClient.Client == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + + if (Ids.Length <= 0) + { + throw new Exception("Количество должно быть больше 0"); + } + + if (string.IsNullOrEmpty(type)) + { + throw new Exception("Неверный тип отчета"); + } + + List res = new List(); + + foreach (var item in Ids) + { + res.Add(item); + } + + if (type == "docx") + { + APIClient.PostRequest("api/report/createdocreport", new ReportBindingModel + { + Ids = res, + FileName = "F:\\ReportsCourseWork\\wordfile.docx" + }); + Response.Redirect("GetWordFile"); + } + else + { + APIClient.PostRequest("api/report/createxmlreport", new ReportBindingModel + { + Ids = res, + FileName = "F:\\ReportsCourseWork\\excelfile.xlsx" + }); + Response.Redirect("GetExcelFile"); + } + } + [HttpGet] public IActionResult Enter() { diff --git a/ComputerShopProvider/ComputerShopClientApp/Views/Home/Report.cshtml b/ComputerShopProvider/ComputerShopClientApp/Views/Home/Report.cshtml new file mode 100644 index 0000000..b745b1a --- /dev/null +++ b/ComputerShopProvider/ComputerShopClientApp/Views/Home/Report.cshtml @@ -0,0 +1,17 @@ + + +
+

Отчёты

+
+ + + \ No newline at end of file diff --git a/ComputerShopProvider/ComputerShopClientApp/Views/Home/ReportDocXml.cshtml b/ComputerShopProvider/ComputerShopClientApp/Views/Home/ReportDocXml.cshtml new file mode 100644 index 0000000..93ca93a --- /dev/null +++ b/ComputerShopProvider/ComputerShopClientApp/Views/Home/ReportDocXml.cshtml @@ -0,0 +1,89 @@ +@using ComputerShopContracts.ViewModels + +@model List + +@{ + ViewData["Title"] = "ReportDocXml"; +} + +
+

+ Создание отчета по компонентам +

+
+ +
+
+
+ +
+ + +
+
+ + +
+
+
+
+
+ + + + + + + + + + + + + + + @foreach (var item in Model) + { + + + + + + } + +
+ + + Название компонента + + Цена +
+ + + @Html.DisplayFor(modelItem => item.ComponentName) + + @Html.DisplayFor(modelItem => item.Cost) +
+
+
+
+
+
+
+
+
+
diff --git a/ComputerShopProvider/ComputerShopClientApp/Views/Shared/_Layout.cshtml b/ComputerShopProvider/ComputerShopClientApp/Views/Shared/_Layout.cshtml index cb605b6..64036d0 100644 --- a/ComputerShopProvider/ComputerShopClientApp/Views/Shared/_Layout.cshtml +++ b/ComputerShopProvider/ComputerShopClientApp/Views/Shared/_Layout.cshtml @@ -6,8 +6,15 @@ @ViewData["Title"] - ComputerShopClientApp - + + + +
@@ -20,7 +27,7 @@ diff --git a/ComputerShopProvider/ComputerShopContracts/BindingModels/ReportBindingModel.cs b/ComputerShopProvider/ComputerShopContracts/BindingModels/ReportBindingModel.cs index 6980d4f..2c94a6c 100644 --- a/ComputerShopProvider/ComputerShopContracts/BindingModels/ReportBindingModel.cs +++ b/ComputerShopProvider/ComputerShopContracts/BindingModels/ReportBindingModel.cs @@ -9,6 +9,7 @@ namespace ComputerShopContracts.BindingModels public class ReportBindingModel { public string FileName { get; set; } = string.Empty; + public List? Ids { get; set; } public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } } diff --git a/ComputerShopProvider/ComputerShopContracts/BusinessLogicContracts/IReportLogic.cs b/ComputerShopProvider/ComputerShopContracts/BusinessLogicContracts/IReportLogic.cs index a427a10..f664635 100644 --- a/ComputerShopProvider/ComputerShopContracts/BusinessLogicContracts/IReportLogic.cs +++ b/ComputerShopProvider/ComputerShopContracts/BusinessLogicContracts/IReportLogic.cs @@ -20,5 +20,7 @@ namespace ComputerShopContracts.BusinessLogicContracts void SaveProductComponentToExcelFile(ReportBindingModel model); /// Сохранение заказов в файл-Pdf void SaveOrdersToPdfFile(ReportBindingModel model); + void SaveReceivingComponentsToWordFile(ReportBindingModel model); + void SaveReceivingComponentsToXmlFile(ReportBindingModel model); } } diff --git a/ComputerShopProvider/ComputerShopContracts/ViewModels/ReportComponentReceivingViewModel.cs b/ComputerShopProvider/ComputerShopContracts/ViewModels/ReportComponentReceivingViewModel.cs new file mode 100644 index 0000000..38c52b5 --- /dev/null +++ b/ComputerShopProvider/ComputerShopContracts/ViewModels/ReportComponentReceivingViewModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputerShopContracts.ViewModels +{ + public class ReportComponentReceivingViewModel + { + public string ComponentName { get; set; } = string.Empty; + public List Receivings { get; set; } = new(); + } +} diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/20230518181418_supplymig.Designer.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/20230518181418_supplymig.Designer.cs new file mode 100644 index 0000000..6d124ea --- /dev/null +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/20230518181418_supplymig.Designer.cs @@ -0,0 +1,530 @@ +// +using System; +using ComputerShopDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ComputerShopDatabaseImplement.Migrations +{ + [DbContext(typeof(ComputerShopDatabase))] + [Migration("20230518181418_supplymig")] + partial class supplymig + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Assembly", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AssemblyName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.ToTable("Assemblies"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.AssemblyComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AssemblyId") + .HasColumnType("int"); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("AssemblyId"); + + b.HasIndex("ComponentId"); + + b.ToTable("AssemblyComponents"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.AssemblyOrder", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AssemblyId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("OrderId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("AssemblyId"); + + b.HasIndex("OrderId"); + + b.ToTable("AssemblyOrders"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.ComponentSupply", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("SupplyId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("SupplyId"); + + b.ToTable("ComponentSupplies"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.EquipmentReceiving", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("Status") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.ToTable("EquipmentReceivings"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Purchase", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("ComponentId"); + + b.ToTable("Purchases"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Supply", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("OrderId") + .HasColumnType("int"); + + b.Property("ReceivingId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("ReceivingId"); + + b.ToTable("Supplies"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.SupplyOrder", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("OrderId") + .HasColumnType("int"); + + b.Property("SupplyId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("OrderId"); + + b.HasIndex("SupplyId"); + + b.ToTable("SupplyOrders"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Assembly", b => + { + b.HasOne("ComputerShopDatabaseImplement.Models.Client", "Client") + .WithMany("Assemblies") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.AssemblyComponent", b => + { + b.HasOne("ComputerShopDatabaseImplement.Models.Assembly", "Assembly") + .WithMany("Components") + .HasForeignKey("AssemblyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputerShopDatabaseImplement.Models.Component", "Component") + .WithMany("AssemblyComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Assembly"); + + b.Navigation("Component"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.AssemblyOrder", b => + { + b.HasOne("ComputerShopDatabaseImplement.Models.Assembly", "Assembly") + .WithMany("Orders") + .HasForeignKey("AssemblyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputerShopDatabaseImplement.Models.Order", "Order") + .WithMany("Assemblies") + .HasForeignKey("OrderId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Assembly"); + + b.Navigation("Order"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Component", b => + { + b.HasOne("ComputerShopDatabaseImplement.Models.Client", null) + .WithMany("Components") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.ComponentSupply", b => + { + b.HasOne("ComputerShopDatabaseImplement.Models.Component", "Component") + .WithMany("Supplies") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputerShopDatabaseImplement.Models.Supply", "Supply") + .WithMany("ComponentSupplies") + .HasForeignKey("SupplyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Supply"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.EquipmentReceiving", b => + { + b.HasOne("ComputerShopDatabaseImplement.Models.Client", null) + .WithMany("EquipmentReceivings") + .HasForeignKey("ClientId"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Order", b => + { + b.HasOne("ComputerShopDatabaseImplement.Models.Client", null) + .WithMany("Orders") + .HasForeignKey("ClientId"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Purchase", b => + { + b.HasOne("ComputerShopDatabaseImplement.Models.Client", "Client") + .WithMany("Purchases") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputerShopDatabaseImplement.Models.Component", "Component") + .WithMany("Purchases") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("Component"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Supply", b => + { + b.HasOne("ComputerShopDatabaseImplement.Models.Client", null) + .WithMany("Supplies") + .HasForeignKey("ClientId"); + + b.HasOne("ComputerShopDatabaseImplement.Models.EquipmentReceiving", null) + .WithMany("Supplies") + .HasForeignKey("ReceivingId"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.SupplyOrder", b => + { + b.HasOne("ComputerShopDatabaseImplement.Models.Order", "Order") + .WithMany("SupplyOrders") + .HasForeignKey("OrderId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputerShopDatabaseImplement.Models.Supply", "Supply") + .WithMany("Orders") + .HasForeignKey("SupplyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Order"); + + b.Navigation("Supply"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Assembly", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Client", b => + { + b.Navigation("Assemblies"); + + b.Navigation("Components"); + + b.Navigation("EquipmentReceivings"); + + b.Navigation("Orders"); + + b.Navigation("Purchases"); + + b.Navigation("Supplies"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Component", b => + { + b.Navigation("AssemblyComponents"); + + b.Navigation("Purchases"); + + b.Navigation("Supplies"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.EquipmentReceiving", b => + { + b.Navigation("Supplies"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Order", b => + { + b.Navigation("Assemblies"); + + b.Navigation("SupplyOrders"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Supply", b => + { + b.Navigation("ComponentSupplies"); + + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/20230518181418_supplymig.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/20230518181418_supplymig.cs new file mode 100644 index 0000000..596c814 --- /dev/null +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/20230518181418_supplymig.cs @@ -0,0 +1,95 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ComputerShopDatabaseImplement.Migrations +{ + /// + public partial class supplymig : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_EquipmentReceivings_Supplies_SupplyId", + table: "EquipmentReceivings"); + + migrationBuilder.DropIndex( + name: "IX_EquipmentReceivings_SupplyId", + table: "EquipmentReceivings"); + + migrationBuilder.DropColumn( + name: "SupplyId", + table: "EquipmentReceivings"); + + migrationBuilder.AlterColumn( + name: "ReceivingId", + table: "Supplies", + type: "int", + nullable: true, + oldClrType: typeof(int), + oldType: "int"); + + migrationBuilder.CreateIndex( + name: "IX_Supplies_ReceivingId", + table: "Supplies", + column: "ReceivingId"); + + migrationBuilder.AddForeignKey( + name: "FK_Supplies_EquipmentReceivings_ReceivingId", + table: "Supplies", + column: "ReceivingId", + principalTable: "EquipmentReceivings", + principalColumn: "Id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + + migrationBuilder.DropForeignKey( + name: "FK_Supplies_EquipmentReceivings_ReceivingId", + table: "Supplies"); + + migrationBuilder.DropIndex( + name: "IX_Supplies_ReceivingId", + table: "Supplies"); + + migrationBuilder.AlterColumn( + name: "ReceivingId", + table: "Supplies", + type: "int", + nullable: false, + defaultValue: 0, + oldClrType: typeof(int), + oldType: "int", + oldNullable: true); + + migrationBuilder.AddColumn( + name: "SupplyId", + table: "EquipmentReceivings", + type: "int", + nullable: true); + + migrationBuilder.AlterColumn( + name: "ClientId", + table: "Assemblies", + type: "int", + nullable: true, + oldClrType: typeof(int), + oldType: "int"); + + migrationBuilder.CreateIndex( + name: "IX_EquipmentReceivings_SupplyId", + table: "EquipmentReceivings", + column: "SupplyId"); + + migrationBuilder.AddForeignKey( + name: "FK_EquipmentReceivings_Supplies_SupplyId", + table: "EquipmentReceivings", + column: "SupplyId", + principalTable: "Supplies", + principalColumn: "Id"); + } + } +} diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/ComputerShopDatabaseModelSnapshot.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/ComputerShopDatabaseModelSnapshot.cs index ede7dbf..b85e8f6 100644 --- a/ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/ComputerShopDatabaseModelSnapshot.cs +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/ComputerShopDatabaseModelSnapshot.cs @@ -34,7 +34,7 @@ namespace ComputerShopDatabaseImplement.Migrations .IsRequired() .HasColumnType("nvarchar(max)"); - b.Property("ClientId") + b.Property("ClientId") .HasColumnType("int"); b.Property("Price") @@ -192,15 +192,10 @@ namespace ComputerShopDatabaseImplement.Migrations b.Property("Status") .HasColumnType("int"); - b.Property("SupplyId") - .HasColumnType("int"); - b.HasKey("Id"); b.HasIndex("ClientId"); - b.HasIndex("SupplyId"); - b.ToTable("EquipmentReceivings"); }); @@ -296,7 +291,7 @@ namespace ComputerShopDatabaseImplement.Migrations b.Property("OrderId") .HasColumnType("int"); - b.Property("ReceivingId") + b.Property("ReceivingId") .HasColumnType("int"); b.Property("Status") @@ -306,6 +301,8 @@ namespace ComputerShopDatabaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ReceivingId"); + b.ToTable("Supplies"); }); @@ -337,9 +334,13 @@ namespace ComputerShopDatabaseImplement.Migrations modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Assembly", b => { - b.HasOne("ComputerShopDatabaseImplement.Models.Client", null) + b.HasOne("ComputerShopDatabaseImplement.Models.Client", "Client") .WithMany("Assemblies") - .HasForeignKey("ClientId"); + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); }); modelBuilder.Entity("ComputerShopDatabaseImplement.Models.AssemblyComponent", b => @@ -398,7 +399,7 @@ namespace ComputerShopDatabaseImplement.Migrations .IsRequired(); b.HasOne("ComputerShopDatabaseImplement.Models.Supply", "Supply") - .WithMany("Supplies") + .WithMany("ComponentSupplies") .HasForeignKey("SupplyId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -413,10 +414,6 @@ namespace ComputerShopDatabaseImplement.Migrations b.HasOne("ComputerShopDatabaseImplement.Models.Client", null) .WithMany("EquipmentReceivings") .HasForeignKey("ClientId"); - - b.HasOne("ComputerShopDatabaseImplement.Models.Supply", null) - .WithMany("Receivings") - .HasForeignKey("SupplyId"); }); modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Order", b => @@ -450,6 +447,10 @@ namespace ComputerShopDatabaseImplement.Migrations b.HasOne("ComputerShopDatabaseImplement.Models.Client", null) .WithMany("Supplies") .HasForeignKey("ClientId"); + + b.HasOne("ComputerShopDatabaseImplement.Models.EquipmentReceiving", null) + .WithMany("Supplies") + .HasForeignKey("ReceivingId"); }); modelBuilder.Entity("ComputerShopDatabaseImplement.Models.SupplyOrder", b => @@ -502,6 +503,11 @@ namespace ComputerShopDatabaseImplement.Migrations b.Navigation("Supplies"); }); + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.EquipmentReceiving", b => + { + b.Navigation("Supplies"); + }); + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Order", b => { b.Navigation("Assemblies"); @@ -511,11 +517,9 @@ namespace ComputerShopDatabaseImplement.Migrations modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Supply", b => { + b.Navigation("ComponentSupplies"); + b.Navigation("Orders"); - - b.Navigation("Receivings"); - - b.Navigation("Supplies"); }); #pragma warning restore 612, 618 } diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/Models/EquipmentReceiving.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/Models/EquipmentReceiving.cs index ed62267..37213b5 100644 --- a/ComputerShopProvider/ComputerShopDatabaseImplement/Models/EquipmentReceiving.cs +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/Models/EquipmentReceiving.cs @@ -5,6 +5,7 @@ using ComputerShopDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -19,6 +20,9 @@ namespace ComputerShopDatabaseImplement.Models public int Id { get; set; } public EquipmentReceivingStatus Status { get; private set; } = EquipmentReceivingStatus.Неизвестен; + [ForeignKey("ReceivingId")] + public List Supplies { get; set; } = new(); + public static EquipmentReceiving? Create(EquipmentReceivingBindingModel? model) { if (model == null) diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Supply.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Supply.cs index 298295d..b7fefd1 100644 --- a/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Supply.cs +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Supply.cs @@ -25,7 +25,6 @@ namespace ComputerShopDatabaseImplement.Models public int OrderId { get; set; } - public int ReceivingId { get; set; } private Dictionary? _supplyOrders = null; [NotMapped] @@ -45,9 +44,7 @@ namespace ComputerShopDatabaseImplement.Models [ForeignKey("SupplyId")] public virtual List Orders { get; set; } = new(); [ForeignKey("SupplyId")] - public virtual List Receivings { get; set; } = new(); - [ForeignKey("SupplyId")] - public virtual List Supplies { get; set; } = new(); + public virtual List ComponentSupplies { get; set; } = new(); public static Supply Create(ComputerShopDatabase context, SupplyBindingModel model) { diff --git a/ComputerShopProvider/ComputerShopRestApi/Controllers/ClientController.cs b/ComputerShopProvider/ComputerShopRestApi/Controllers/ClientController.cs index b522fea..487a9d4 100644 --- a/ComputerShopProvider/ComputerShopRestApi/Controllers/ClientController.cs +++ b/ComputerShopProvider/ComputerShopRestApi/Controllers/ClientController.cs @@ -11,8 +11,7 @@ public class ClientController : Controller { private readonly ILogger _logger; private readonly IClientLogic _logic; - public ClientController(IClientLogic logic, ILogger - logger) + public ClientController(IClientLogic logic, ILogger logger) { _logger = logger; _logic = logic; diff --git a/ComputerShopProvider/ComputerShopRestApi/Controllers/ReportController.cs b/ComputerShopProvider/ComputerShopRestApi/Controllers/ReportController.cs new file mode 100644 index 0000000..51859f2 --- /dev/null +++ b/ComputerShopProvider/ComputerShopRestApi/Controllers/ReportController.cs @@ -0,0 +1,46 @@ +using ComputerShopContracts.BindingModels; +using ComputerShopContracts.SearchModels; +using ComputerShopContracts.ViewModels; +using ComputerShopBusinessLogic.BusinessLogics; +using Microsoft.AspNetCore.Mvc; +using ComputerShopContracts.BusinessLogicContracts; + +[Route("api/[controller]/[action]")] +[ApiController] +public class ReportController : Controller +{ + private readonly ILogger _logger; + private readonly IReportLogic _reportLogic; + public ReportController(ILogger logger, IReportLogic reportLogic) + { + _logger = logger; + _reportLogic = reportLogic; + } + + [HttpPost] + public void CreateDocReport(ReportBindingModel model) + { + try + { + _reportLogic.SaveReceivingComponentsToWordFile(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания отчета"); + throw; + } + } + [HttpPost] + public void CreateXmlReport(ReportBindingModel model) + { + try + { + _reportLogic.SaveReceivingComponentsToXmlFile(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания отчета"); + throw; + } + } +} \ No newline at end of file