3 компонент готов, остался 2
This commit is contained in:
parent
708c818336
commit
bb355ba8d4
18
COP/VisualCompLib/Components/SupportClasses/DataLineChart.cs
Normal file
18
COP/VisualCompLib/Components/SupportClasses/DataLineChart.cs
Normal file
@ -0,0 +1,18 @@
|
||||
namespace VisualCompLib.Components.SupportClasses
|
||||
{
|
||||
public class DataLineChart
|
||||
{
|
||||
public string NameSeries { get; set; } = string.Empty;
|
||||
|
||||
public string[] NameData { get; set; }
|
||||
|
||||
public double[] Data { get; set; }
|
||||
|
||||
public DataLineChart(string nameSeries, string[] nameData, double[] data)
|
||||
{
|
||||
NameSeries = nameSeries;
|
||||
NameData = nameData;
|
||||
Data = data;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
using VisualCompLib.Components.SupportClasses.Enums;
|
||||
|
||||
namespace VisualCompLib.Components.SupportClasses
|
||||
{
|
||||
public class SimpleLineChart
|
||||
{
|
||||
public string FilePath = string.Empty;
|
||||
|
||||
public string FileHeader = string.Empty;
|
||||
|
||||
public string LineChartName = string.Empty;
|
||||
|
||||
public EnumAreaLegend AreaLegend;
|
||||
|
||||
public List<DataLineChart> DataList = new();
|
||||
|
||||
public SimpleLineChart(string filePath, string fileHeader, string lineChartName, EnumAreaLegend areaLegend, List<DataLineChart> dataList)
|
||||
{
|
||||
FilePath = filePath;
|
||||
FileHeader = fileHeader;
|
||||
LineChartName = lineChartName;
|
||||
AreaLegend = areaLegend;
|
||||
DataList = dataList;
|
||||
}
|
||||
}
|
||||
}
|
36
COP/VisualCompLib/Components/WordLineChart.Designer.cs
generated
Normal file
36
COP/VisualCompLib/Components/WordLineChart.Designer.cs
generated
Normal file
@ -0,0 +1,36 @@
|
||||
namespace VisualCompLib.Components
|
||||
{
|
||||
partial class WordLineChart
|
||||
{
|
||||
/// <summary>
|
||||
/// Обязательная переменная конструктора.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Освободить все используемые ресурсы.
|
||||
/// </summary>
|
||||
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Код, автоматически созданный конструктором компонентов
|
||||
|
||||
/// <summary>
|
||||
/// Требуемый метод для поддержки конструктора — не изменяйте
|
||||
/// содержимое этого метода с помощью редактора кода.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
components = new System.ComponentModel.Container();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
84
COP/VisualCompLib/Components/WordLineChart.cs
Normal file
84
COP/VisualCompLib/Components/WordLineChart.cs
Normal file
@ -0,0 +1,84 @@
|
||||
using Aspose.Words;
|
||||
using Aspose.Words.Drawing;
|
||||
using Aspose.Words.Drawing.Charts;
|
||||
using System.ComponentModel;
|
||||
using VisualCompLib.Components.SupportClasses;
|
||||
|
||||
namespace VisualCompLib.Components
|
||||
{
|
||||
public partial class WordLineChart : Component
|
||||
{
|
||||
public WordLineChart()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public WordLineChart(IContainer container)
|
||||
{
|
||||
container.Add(this);
|
||||
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void AddLineChart(SimpleLineChart simpleLineChart)
|
||||
{
|
||||
if (!CheckData(simpleLineChart.DataList))
|
||||
{
|
||||
throw new Exception("Не данные заполнены");
|
||||
}
|
||||
Document doc = new Document();
|
||||
DocumentBuilder builder = new DocumentBuilder(doc);
|
||||
|
||||
Aspose.Words.Font font = builder.Font;
|
||||
font.Size = 24;
|
||||
font.Bold = true;
|
||||
font.Color = Color.Black;
|
||||
font.Name = "Times New Roman";
|
||||
|
||||
ParagraphFormat paragraphFormat = builder.ParagraphFormat;
|
||||
paragraphFormat.FirstLineIndent = 8;
|
||||
paragraphFormat.SpaceAfter = 24;
|
||||
paragraphFormat.Alignment = ParagraphAlignment.Center;
|
||||
paragraphFormat.KeepTogether = true;
|
||||
|
||||
builder.Writeln(simpleLineChart.FileHeader);
|
||||
|
||||
Shape shape = builder.InsertChart(ChartType.Line, 500, 270);
|
||||
|
||||
Chart chart = shape.Chart;
|
||||
|
||||
chart.Title.Text = simpleLineChart.LineChartName;
|
||||
|
||||
ChartSeriesCollection seriesColl = chart.Series;
|
||||
|
||||
Console.WriteLine(seriesColl.Count);
|
||||
|
||||
seriesColl.Clear();
|
||||
|
||||
foreach (var data in simpleLineChart.DataList)
|
||||
{
|
||||
seriesColl.Add(data.NameSeries, data.NameData, data.Data );
|
||||
}
|
||||
|
||||
ChartLegend legend = chart.Legend;
|
||||
|
||||
legend.Position = (LegendPosition)simpleLineChart.AreaLegend;
|
||||
|
||||
legend.Overlay = true;
|
||||
|
||||
doc.Save(simpleLineChart.FilePath);
|
||||
}
|
||||
static bool CheckData(List<DataLineChart> data)
|
||||
{
|
||||
foreach (var _data in data)
|
||||
{
|
||||
if (string.IsNullOrEmpty(_data.NameSeries) || string.IsNullOrEmpty(_data.NameData.ToString()) || string.IsNullOrEmpty(_data.Data.ToString()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
31
COP/WinForms/FormWord.Designer.cs
generated
31
COP/WinForms/FormWord.Designer.cs
generated
@ -32,7 +32,11 @@
|
||||
wordText = new VisualCompLib.Components.WordText(components);
|
||||
groupBox1 = new GroupBox();
|
||||
button1 = new Button();
|
||||
wordLineChart = new VisualCompLib.Components.WordLineChart(components);
|
||||
groupBox3 = new GroupBox();
|
||||
button3 = new Button();
|
||||
groupBox1.SuspendLayout();
|
||||
groupBox3.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// groupBox1
|
||||
@ -55,15 +59,37 @@
|
||||
button1.UseVisualStyleBackColor = true;
|
||||
button1.Click += button1_Click;
|
||||
//
|
||||
// groupBox3
|
||||
//
|
||||
groupBox3.Controls.Add(button3);
|
||||
groupBox3.Location = new Point(158, 12);
|
||||
groupBox3.Name = "groupBox3";
|
||||
groupBox3.Size = new Size(120, 80);
|
||||
groupBox3.TabIndex = 1;
|
||||
groupBox3.TabStop = false;
|
||||
groupBox3.Text = "Линейная диаграмма";
|
||||
//
|
||||
// button3
|
||||
//
|
||||
button3.Location = new Point(6, 45);
|
||||
button3.Name = "button3";
|
||||
button3.Size = new Size(94, 29);
|
||||
button3.TabIndex = 0;
|
||||
button3.Text = "Создать";
|
||||
button3.UseVisualStyleBackColor = true;
|
||||
button3.Click += button3_Click;
|
||||
//
|
||||
// FormWord
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
ClientSize = new Size(320, 165);
|
||||
Controls.Add(groupBox3);
|
||||
Controls.Add(groupBox1);
|
||||
Name = "FormWord";
|
||||
Text = "Невизуальные компоненты";
|
||||
groupBox1.ResumeLayout(false);
|
||||
groupBox3.ResumeLayout(false);
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
@ -72,5 +98,8 @@
|
||||
private VisualCompLib.Components.WordText wordText;
|
||||
private GroupBox groupBox1;
|
||||
private Button button1;
|
||||
private VisualCompLib.Components.WordLineChart wordLineChart;
|
||||
private GroupBox groupBox3;
|
||||
private Button button3;
|
||||
}
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
using VisualCompLib.Components.SupportClasses;
|
||||
using System.Diagnostics.Metrics;
|
||||
using VisualCompLib.Components.SupportClasses;
|
||||
using VisualCompLib.Components.SupportClasses.Enums;
|
||||
|
||||
namespace WinForms
|
||||
{
|
||||
@ -32,5 +34,36 @@ namespace WinForms
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void button3_Click(object sender, EventArgs e)
|
||||
{
|
||||
//фильтрация файлов для диалогового окна
|
||||
using var dialog = new SaveFileDialog
|
||||
{
|
||||
Filter = "docx|*.docx"
|
||||
};
|
||||
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
string[] month = { "Январь", "Февраль", "Март" };
|
||||
double[] profit1 = { 300, 440, 270 };
|
||||
double[] profit2 = { 500, 620, 310 };
|
||||
double[] profit3 = { 420, 189, 430 };
|
||||
SimpleLineChart lineChart = new(dialog.FileName, "Третье задание", "График прибыли", EnumAreaLegend.Right, new List<DataLineChart> {
|
||||
new DataLineChart("Компания 1", month, profit1), new DataLineChart("Компания 2", month, profit2), new DataLineChart("Компания 3", month, profit3),
|
||||
});
|
||||
|
||||
wordLineChart.AddLineChart(lineChart);
|
||||
|
||||
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -120,4 +120,7 @@
|
||||
<metadata name="wordText.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="wordLineChart.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>134, 17</value>
|
||||
</metadata>
|
||||
</root>
|
@ -8,6 +8,10 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Aspose.Words" Version="23.10.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\VisualCompLib\VisualCompLib.csproj" />
|
||||
</ItemGroup>
|
||||
|
Loading…
Reference in New Issue
Block a user