report word
This commit is contained in:
parent
a50fc5be80
commit
052c917bcc
@ -83,6 +83,7 @@ namespace ComputerShopBusinessLogic.BusinessLogics
|
||||
|
||||
public void SaveReceivingComponentsToWordFile(ReportBindingModel model)
|
||||
{
|
||||
if (model.Ids != null)
|
||||
_saveToWord.CreateDoc(new WordInfoProvider
|
||||
{
|
||||
FileName = model.FileName,
|
||||
|
@ -7,6 +7,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DocumentFormat.OpenXml" Version="2.20.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.4">
|
||||
|
@ -8,13 +8,13 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerShopBusinessLogic.OfficePackage
|
||||
{
|
||||
public class AbstractSaveToWord
|
||||
public abstract class AbstractSaveToWord
|
||||
{
|
||||
|
||||
public void CreateDoc(WordInfoProvider info)
|
||||
{
|
||||
/*
|
||||
|
||||
|
||||
|
||||
CreateWord(info);
|
||||
|
||||
CreateParagraph(new WordParagraph
|
||||
@ -27,12 +27,12 @@ namespace ComputerShopBusinessLogic.OfficePackage
|
||||
}
|
||||
});
|
||||
|
||||
foreach (var mc in info.MemberConferences)
|
||||
foreach (var cr in info.ComponentReceivings)
|
||||
{
|
||||
CreateParagraph(new WordParagraph
|
||||
{
|
||||
Texts = new List<(string, WordTextProperties)>
|
||||
{ (mc.MemberFIO, new WordTextProperties { Size = "20", Bold=true})},
|
||||
{ (cr.ComponentName, new WordTextProperties { Size = "20", Bold=true})},
|
||||
TextProperties = new WordTextProperties
|
||||
{
|
||||
Size = "24",
|
||||
@ -40,13 +40,11 @@ namespace ComputerShopBusinessLogic.OfficePackage
|
||||
}
|
||||
});
|
||||
|
||||
foreach (var conference in mc.Conferences)
|
||||
foreach (var receiving in cr.Receivings)
|
||||
{
|
||||
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})},
|
||||
Texts = new List<(string, WordTextProperties)> { (receiving, new WordTextProperties { Size = "16", Bold = false }) },
|
||||
TextProperties = new WordTextProperties
|
||||
{
|
||||
Size = "24",
|
||||
@ -55,17 +53,13 @@ namespace ComputerShopBusinessLogic.OfficePackage
|
||||
});
|
||||
}
|
||||
}
|
||||
SaveWord(info);
|
||||
SaveWord(info);
|
||||
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
protected abstract void CreateWord(WordInfoOrganiser info);
|
||||
protected abstract void CreateWord(WordInfoProvider info);
|
||||
protected abstract void CreateParagraph(WordParagraph paragraph);
|
||||
protected abstract void SaveWord(WordInfoOrganiser info);
|
||||
|
||||
*/
|
||||
protected abstract void SaveWord(WordInfoProvider info);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerShopBusinessLogic.OfficePackage.HelperEnums
|
||||
{
|
||||
public class WordTextProperties
|
||||
{
|
||||
public string Size { get; set; } = string.Empty;
|
||||
public bool Bold { get; set; }
|
||||
public WordJustificationType JustificationType { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using ComputerShopBusinessLogic.OfficePackage.HelperEnums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerShopBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class WordParagraph
|
||||
{
|
||||
public List<(string, WordTextProperties)> Texts { get; set; } = new();
|
||||
public WordTextProperties? TextProperties { get; set; }
|
||||
}
|
||||
}
|
@ -1,4 +1,9 @@
|
||||
using System;
|
||||
using ComputerShopBusinessLogic.OfficePackage.HelperEnums;
|
||||
using ComputerShopBusinessLogic.OfficePackage.HelperModels;
|
||||
using DocumentFormat.OpenXml;
|
||||
using DocumentFormat.OpenXml.Packaging;
|
||||
using DocumentFormat.OpenXml.Wordprocessing;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@ -8,6 +13,116 @@ namespace ComputerShopBusinessLogic.OfficePackage.Implements
|
||||
{
|
||||
public class SaveToWord : AbstractSaveToWord
|
||||
{
|
||||
private WordprocessingDocument? _wordDocument;
|
||||
private Body? _docBody;
|
||||
private static JustificationValues GetJustificationValues(WordJustificationType type)
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
WordJustificationType.Both => JustificationValues.Both,
|
||||
WordJustificationType.Center => JustificationValues.Center,
|
||||
_ => JustificationValues.Left,
|
||||
};
|
||||
}
|
||||
|
||||
private static SectionProperties CreateSectionProperties()
|
||||
{
|
||||
var properties = new SectionProperties();
|
||||
var pageSize = new PageSize
|
||||
{
|
||||
Orient = PageOrientationValues.Portrait
|
||||
};
|
||||
properties.AppendChild(pageSize);
|
||||
return properties;
|
||||
}
|
||||
|
||||
private static ParagraphProperties? CreateParagraphProperties(WordTextProperties? paragraphProperties)
|
||||
{
|
||||
if (paragraphProperties == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var properties = new ParagraphProperties();
|
||||
|
||||
properties.AppendChild(new Justification()
|
||||
{
|
||||
Val = GetJustificationValues(paragraphProperties.JustificationType)
|
||||
});
|
||||
|
||||
properties.AppendChild(new SpacingBetweenLines
|
||||
{
|
||||
LineRule = LineSpacingRuleValues.Auto
|
||||
});
|
||||
|
||||
properties.AppendChild(new Indentation());
|
||||
var paragraphMarkRunProperties = new ParagraphMarkRunProperties();
|
||||
|
||||
if (!string.IsNullOrEmpty(paragraphProperties.Size))
|
||||
{
|
||||
paragraphMarkRunProperties.AppendChild(new FontSize
|
||||
{
|
||||
Val = paragraphProperties.Size
|
||||
});
|
||||
}
|
||||
|
||||
properties.AppendChild(paragraphMarkRunProperties);
|
||||
|
||||
return properties;
|
||||
}
|
||||
protected override void CreateParagraph(WordParagraph paragraph)
|
||||
{
|
||||
if (_docBody == null || paragraph == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var docParagraph = new Paragraph();
|
||||
|
||||
docParagraph.AppendChild(CreateParagraphProperties(paragraph.TextProperties));
|
||||
|
||||
foreach (var run in paragraph.Texts)
|
||||
{
|
||||
var docRun = new Run();
|
||||
var properties = new RunProperties();
|
||||
properties.AppendChild(new FontSize { Val = run.Item2.Size });
|
||||
|
||||
if (run.Item2.Bold)
|
||||
{
|
||||
properties.AppendChild(new Bold());
|
||||
}
|
||||
|
||||
docRun.AppendChild(properties);
|
||||
|
||||
docRun.AppendChild(new Text
|
||||
{
|
||||
Text = run.Item1,
|
||||
Space = SpaceProcessingModeValues.Preserve
|
||||
});
|
||||
|
||||
docParagraph.AppendChild(docRun);
|
||||
}
|
||||
_docBody.AppendChild(docParagraph);
|
||||
}
|
||||
|
||||
protected override void CreateWord(WordInfoProvider info)
|
||||
{
|
||||
_wordDocument = WordprocessingDocument.Create(info.FileName, WordprocessingDocumentType.Document);
|
||||
MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart();
|
||||
mainPart.Document = new Document();
|
||||
_docBody = mainPart.Document.AppendChild(new Body());
|
||||
}
|
||||
|
||||
protected override void SaveWord(WordInfoProvider info)
|
||||
{
|
||||
if (_docBody == null || _wordDocument == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_docBody.AppendChild(CreateSectionProperties());
|
||||
_wordDocument.MainDocumentPart!.Document.Save();
|
||||
_wordDocument.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ namespace ComputerShopDatabaseImplement
|
||||
{
|
||||
if (optionsBuilder.IsConfigured == false)
|
||||
{
|
||||
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-QA8P9OJ;Initial Catalog=ComputerShopDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-IRUVF5S\SQLEXPRESS;Initial Catalog=ComputerShopDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||
}
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user