2024-10-07 14:27:01 +04:00
|
|
|
|
using Components;
|
|
|
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
|
|
|
|
using LegendPosition = Components.ComponentExcelWithPieDiagram.LegendPosition;
|
|
|
|
|
|
|
|
|
|
namespace WinFormsApp
|
2024-10-07 00:07:33 +04:00
|
|
|
|
{
|
|
|
|
|
public partial class FormNoVisual : Form
|
|
|
|
|
{
|
2024-10-07 14:27:01 +04:00
|
|
|
|
private List<ComponentExcelWithPieDiagram.ChartData> _chartData;
|
|
|
|
|
private double _chartDataValuesSum
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _chartData.Sum(x => x.SeriesValue);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-07 00:07:33 +04:00
|
|
|
|
public FormNoVisual()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2024-10-07 14:27:01 +04:00
|
|
|
|
_chartData = new List<ComponentExcelWithPieDiagram.ChartData>();
|
|
|
|
|
comboBoxLegendPosition.DataSource = Enum.GetValues(typeof(LegendPosition));
|
|
|
|
|
UpdateNumericUpDownSeriesValueMaximumValue();
|
2024-10-07 00:07:33 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonCreateExcelFile_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
string[] list = new string[listBoxImages.Items.Count];
|
|
|
|
|
for (int i = 0; i < listBoxImages.Items.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
list[i] = listBoxImages.Items[i].ToString();
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
componentExcelWithImage.CreateExcelWithImages(textBoxFilePath.Text, textBoxTitle.Text, list);
|
2024-10-07 12:52:54 +04:00
|
|
|
|
MessageBox.Show("Файл успешно создан", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
2024-10-07 00:07:33 +04:00
|
|
|
|
}
|
2024-10-07 12:52:54 +04:00
|
|
|
|
catch (Exception ex)
|
2024-10-07 00:07:33 +04:00
|
|
|
|
{
|
2024-10-07 12:52:54 +04:00
|
|
|
|
MessageBox.Show($"Ошибка при создании файла:\n{ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
2024-10-07 00:07:33 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonSetFilePath_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var filePath = string.Empty;
|
|
|
|
|
|
2024-10-07 14:42:26 +04:00
|
|
|
|
using (SaveFileDialog saveFileDialog = new SaveFileDialog())
|
2024-10-07 00:07:33 +04:00
|
|
|
|
{
|
2024-10-07 14:42:26 +04:00
|
|
|
|
saveFileDialog.InitialDirectory = "d:\\tmp";
|
|
|
|
|
saveFileDialog.Filter = "Excel files (*.xlsx)|*.xlsx|All files (*.*)|*.*";
|
|
|
|
|
saveFileDialog.FilterIndex = 1;
|
|
|
|
|
saveFileDialog.RestoreDirectory = true;
|
2024-10-07 00:07:33 +04:00
|
|
|
|
|
2024-10-07 14:42:26 +04:00
|
|
|
|
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
2024-10-07 00:07:33 +04:00
|
|
|
|
{
|
2024-10-07 14:42:26 +04:00
|
|
|
|
filePath = saveFileDialog.FileName;
|
2024-10-07 00:07:33 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(filePath))
|
|
|
|
|
{
|
|
|
|
|
textBoxFilePath.Text = filePath;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
textBoxFilePath.Text = string.Empty;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonAddImage_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var filePath = string.Empty;
|
|
|
|
|
|
|
|
|
|
using (OpenFileDialog openFileDialog = new OpenFileDialog())
|
|
|
|
|
{
|
|
|
|
|
openFileDialog.InitialDirectory = "d:\\tmp";
|
2024-10-07 12:52:54 +04:00
|
|
|
|
openFileDialog.Filter = "Image files (*.jpeg;*.jpg;*.png)|*.jpeg;*.jpg;*.png|All files (*.*)|*.*";
|
2024-10-07 00:07:33 +04:00
|
|
|
|
openFileDialog.FilterIndex = 1;
|
|
|
|
|
openFileDialog.RestoreDirectory = true;
|
|
|
|
|
|
|
|
|
|
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
filePath = openFileDialog.FileName;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(filePath))
|
|
|
|
|
{
|
|
|
|
|
listBoxImages.Items.Add(filePath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonClearImages_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
listBoxImages.Items.Clear();
|
|
|
|
|
}
|
2024-10-07 14:27:01 +04:00
|
|
|
|
|
|
|
|
|
private void buttonAddSeries_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(textBoxSeriesName.Text) || numericUpDownSeriesValue.Value == 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ComponentExcelWithPieDiagram.ChartData chartData = new();
|
|
|
|
|
chartData.SeriesName = textBoxSeriesName.Text;
|
|
|
|
|
chartData.SeriesValue = (double)numericUpDownSeriesValue.Value;
|
|
|
|
|
_chartData.Add(chartData);
|
|
|
|
|
textBoxSeriesName.Text = string.Empty;
|
|
|
|
|
UpdateDataGridViewChartData();
|
|
|
|
|
UpdateNumericUpDownSeriesValueMaximumValue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonClearSeries_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
_chartData.Clear();
|
|
|
|
|
dataGridViewSeries.DataSource = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonCreateExcelWithPieDiagram_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
LegendPosition legendPosition;
|
|
|
|
|
Enum.TryParse<LegendPosition>(comboBoxLegendPosition.SelectedValue.ToString(), out legendPosition);
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
componentExcelWithPieDiagram.CreateExcelWithPieChart(textBoxFilePath.Text, textBoxTitle.Text, textBoxDiagramTitle.Text, legendPosition, _chartData);
|
|
|
|
|
MessageBox.Show("Файл успешно создан", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show($"Ошибка при создании файла:\n{ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateDataGridViewChartData()
|
|
|
|
|
{
|
|
|
|
|
dataGridViewSeries.DataSource = null;
|
|
|
|
|
dataGridViewSeries.DataSource = _chartData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateNumericUpDownSeriesValueMaximumValue()
|
|
|
|
|
{
|
|
|
|
|
numericUpDownSeriesValue.Maximum = (decimal)(100 - _chartDataValuesSum);
|
|
|
|
|
numericUpDownSeriesValue.Value = numericUpDownSeriesValue.Maximum;
|
|
|
|
|
}
|
2024-10-07 00:07:33 +04:00
|
|
|
|
}
|
|
|
|
|
}
|