COP-17/WinFormsProject/AppView/FormMain.cs

227 lines
8.1 KiB
C#
Raw Permalink Normal View History

using ComponentsLibraryNet60.Models;
2023-11-30 00:36:01 +04:00
using Contracts.StorageContracts;
using Contracts.ViewModels;
using ControlsLibraryNet60.Data;
using ControlsLibraryNet60.Models;
using DocumentFormat.OpenXml.Drawing.Charts;
using System.ComponentModel;
using WinFormsLibrary;
2023-11-30 11:20:36 +04:00
using WinFormsLibrary.not_visual;
2023-11-30 00:36:01 +04:00
using WinFormsLibrary.SupportClasses;
namespace AppView
{
public partial class FormMain : Form
{
private readonly IProviderStorage _providerStorage;
private readonly ITypeStorage _typeStorage;
public FormMain(IProviderStorage providerStorage, ITypeStorage typeStorage)
{
InitializeComponent();
_providerStorage = providerStorage;
_typeStorage = typeStorage;
ContextMenuStrip = contextMenuStrip1;
List<DataTableColumnConfig> columns = new List<DataTableColumnConfig>()
{
new DataTableColumnConfig
{
ColumnHeader = "Id",
PropertyName = "Id",
Visible = false
},
new DataTableColumnConfig
{
ColumnHeader = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
PropertyName = "Name",
Visible = true
},
new DataTableColumnConfig
{
ColumnHeader = "<22><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
PropertyName = "Type",
Visible = true
},
new DataTableColumnConfig
{
ColumnHeader = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
PropertyName = "Number",
Visible = true
}
};
dataTable.LoadColumns(columns);
}
private void LoadData()
{
var list = _providerStorage.GetFullList();
dataTable.Clear();
dataTable.AddTable(list);
}
private void FormMain_Load(object sender, EventArgs e)
{
LoadData();
}
private void <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormProvider));
if (!(service is FormProvider form)) return;
if (form.ShowDialog() == DialogResult.OK) LoadData();
}
private void <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (dataTable.GetSelectedObject<ProviderViewModel>() == null)
{
return;
}
else
{
var service = Program.ServiceProvider?.GetService(typeof(FormProvider));
if (service is FormProvider form)
{
form.Id = Convert.ToInt32(dataTable.GetSelectedObject<ProviderViewModel>()?.Id);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (dataTable.GetSelectedObject<ProviderViewModel>() == null) return;
if (MessageBox.Show(
"<22><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>?",
"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question) == DialogResult.Yes)
{
_providerStorage.Delete(new(dataTable.GetSelectedObject<ProviderViewModel>()));
LoadData();
}
}
private void <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormType));
if (service is FormType form)
{
form.ShowDialog();
LoadData();
}
}
private void toolStripButton1_Click(object sender, EventArgs e)
{
}
private void <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>WordToolStripMenuItem_Click(object sender, EventArgs e)
{
string fileName = "";
using (var dialog = new SaveFileDialog { Filter = "docx|*.docx" })
{
if (dialog.ShowDialog() == DialogResult.OK)
{
fileName = dialog.FileName.ToString();
MessageBox.Show("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
}
ImageClass info = new ImageClass();
var images = _providerStorage.GetFullList().Select(x => x.Logo).ToList();
info.Title = "Images";
info.Path = fileName;
info.Files = images;
documentWithImage1.CreateDocument(info);
}
private void <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>PdfToolStripMenuItem_Click(object sender, EventArgs e)
{
2023-11-30 00:50:03 +04:00
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
string fileName = "";
using (var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" })
{
if (dialog.ShowDialog() == DialogResult.OK)
{
fileName = dialog.FileName.ToString();
MessageBox.Show("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
}
List<ColumnDefinition> columnDefinitionsUp = new List<ColumnDefinition> {
new ColumnDefinition{Header = "#", PropertyName = "Id", Weight = 30},
new ColumnDefinition{Header = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", PropertyName = "NumberType", Weight = 30},
new ColumnDefinition{Header = "", PropertyName = "NumberType", Weight = 30},
new ColumnDefinition{Header = "<22><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", PropertyName = "Number", Weight = 30},
};
List<ColumnDefinition> columnDefinitionsDown = new List<ColumnDefinition> {
new ColumnDefinition{Header = "#", PropertyName = "Id", Weight = 30},
new ColumnDefinition{Header = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", PropertyName = "Name", Weight = 30},
new ColumnDefinition{Header = "<22><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", PropertyName = "Type", Weight = 30},
new ColumnDefinition{Header = "-", PropertyName = "Number", Weight = 30},
};
var providers = _providerStorage.GetFullList();
2023-11-30 00:50:03 +04:00
List<int[]> mergedColums = new() { new int[] { 1, 2 } };
BigTable<ProviderViewModel> info = new(fileName, "Table", columnDefinitionsUp, columnDefinitionsDown, providers, mergedColums);
2023-11-30 00:36:01 +04:00
2023-11-30 00:50:03 +04:00
table2column1.CreateTable(info);
MessageBox.Show("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
2023-11-30 00:36:01 +04:00
}
private void <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ExcelToolStripMenuItem_Click(object sender, EventArgs e)
{
string fileName = "";
using (var dialog = new SaveFileDialog { Filter = "xlsx|*.xlsx" })
{
if (dialog.ShowDialog() == DialogResult.OK)
{
fileName = dialog.FileName.ToString();
MessageBox.Show("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
}
var providers = _providerStorage.GetFullList();
var uniqueTypes = providers.Select(p => p.Type).Distinct();
2023-11-30 11:20:36 +04:00
List<ChartData> data = new List<ChartData>();
foreach (var uniqueType in uniqueTypes)
{
var typeProviders = providers.Where(p => p.Type == uniqueType).ToList();
2023-11-30 11:20:36 +04:00
var dataList = new List<double>();
2023-12-13 22:12:18 +04:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Count() <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
int totalCount = typeProviders.Count();
2023-11-30 11:20:36 +04:00
ChartData chData = new ChartData();
chData.SeriesName = uniqueType;
2023-12-13 22:12:18 +04:00
chData.Data = new double[] { totalCount };
2023-12-13 22:12:18 +04:00
data.Add(chData);
}
2023-11-30 11:20:36 +04:00
gistograma1.GenerateExcelChartDocument(fileName, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>", WinFormsLibrary.not_visual.LegendPosition.Bottom, data);
}
2023-11-30 00:36:01 +04:00
}
}