using ComponentsLibraryNet60.Models; using Contracts.StorageContracts; using Contracts.ViewModels; using ControlsLibraryNet60.Data; using ControlsLibraryNet60.Models; using DocumentFormat.OpenXml.Drawing.Charts; using System.ComponentModel; using WinFormsLibrary; using WinFormsLibrary.not_visual; 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 columns = new List() { new DataTableColumnConfig { ColumnHeader = "Id", PropertyName = "Id", Visible = false }, new DataTableColumnConfig { ColumnHeader = "Название", PropertyName = "Name", Visible = true }, new DataTableColumnConfig { ColumnHeader = "Тип изделий", PropertyName = "Type", Visible = true }, new DataTableColumnConfig { ColumnHeader = "Телефон", 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 создать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 изменитьToolStripMenuItem_Click(object sender, EventArgs e) { if (dataTable.GetSelectedObject() == null) { return; } else { var service = Program.ServiceProvider?.GetService(typeof(FormProvider)); if (service is FormProvider form) { form.Id = Convert.ToInt32(dataTable.GetSelectedObject()?.Id); if (form.ShowDialog() == DialogResult.OK) { LoadData(); } } } } private void удалитьToolStripMenuItem_Click(object sender, EventArgs e) { if (dataTable.GetSelectedObject() == null) return; if (MessageBox.Show( "Вы хотите удалить выбранные элементы?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { _providerStorage.Delete(new(dataTable.GetSelectedObject())); LoadData(); } } private void справочник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 сформирировать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("Выполнено", "Успех", 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 сформироватьPdfToolStripMenuItem_Click(object sender, EventArgs e) { 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("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); } } List columnDefinitionsUp = new List { new ColumnDefinition{Header = "#", PropertyName = "Id", Weight = 30}, new ColumnDefinition{Header = "Информация", PropertyName = "NumberType", Weight = 30}, new ColumnDefinition{Header = "", PropertyName = "NumberType", Weight = 30}, new ColumnDefinition{Header = "Номер телефона", PropertyName = "Number", Weight = 30}, }; List columnDefinitionsDown = new List { new ColumnDefinition{Header = "#", PropertyName = "Id", Weight = 30}, new ColumnDefinition{Header = "Название", PropertyName = "Name", Weight = 30}, new ColumnDefinition{Header = "Тип изделия", PropertyName = "Type", Weight = 30}, new ColumnDefinition{Header = "-", PropertyName = "Number", Weight = 30}, }; var providers = _providerStorage.GetFullList(); List mergedColums = new() { new int[] { 1, 2 } }; BigTable info = new(fileName, "Table", columnDefinitionsUp, columnDefinitionsDown, providers, mergedColums); table2column1.CreateTable(info); MessageBox.Show("Готово"); } private void сформировать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("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); } } var providers = _providerStorage.GetFullList(); var uniqueTypes = providers.Select(p => p.Type).Distinct(); List data = new List(); foreach (var uniqueType in uniqueTypes) { var typeProviders = providers.Where(p => p.Type == uniqueType).ToList(); var dataList = new List(); // Используем Count() для подсчета общего количества поставщиков каждого типа int totalCount = typeProviders.Count(); ChartData chData = new ChartData(); chData.SeriesName = uniqueType; chData.Data = new double[] { totalCount }; data.Add(chData); } gistograma1.GenerateExcelChartDocument(fileName, "Сводка по типам изделия.", "Количество поставщиков для товаров каждого типа", WinFormsLibrary.not_visual.LegendPosition.Bottom, data); } } }