231 lines
8.3 KiB
C#
231 lines
8.3 KiB
C#
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.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 = "Íàçâàíèå",
|
|
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<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 óäàëèòüToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
if (dataTable.GetSelectedObject<ProviderViewModel>() == null) return;
|
|
if (MessageBox.Show(
|
|
"Âû õîòèòå óäàëèòü âûáðàííûå ýëåìåíòû?",
|
|
"Âîïðîñ",
|
|
MessageBoxButtons.YesNo,
|
|
MessageBoxIcon.Question) == DialogResult.Yes)
|
|
{
|
|
_providerStorage.Delete(new(dataTable.GetSelectedObject<ProviderViewModel>()));
|
|
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<ColumnDefinition> columnDefinitionsUp = new List<ColumnDefinition> {
|
|
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<ColumnDefinition> columnDefinitionsDown = new List<ColumnDefinition> {
|
|
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<int[]> mergedColums = new() { new int[] { 1, 2 } };
|
|
|
|
BigTable<ProviderViewModel> 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();
|
|
|
|
Dictionary<string, List<(int Date, double Value)>> data = new Dictionary<string, List<(int Date, double Value)>>();
|
|
|
|
foreach (var uniqueType in uniqueTypes)
|
|
{
|
|
var typeProviders = providers.Where(p => p.Type == uniqueType).ToList();
|
|
|
|
var dataList = new List<(int Date, double Value)>();
|
|
|
|
for (int i = 0; i < typeProviders.Count; i++)
|
|
{
|
|
dataList.Add((i + 1, i + 1)); // Ïðîñòî ïðèìåð äàííûõ (Date, Value), âû ìîæåòå èñïîëüçîâàòü ñâîè äàííûå
|
|
}
|
|
|
|
data.Add(uniqueType, dataList);
|
|
}
|
|
|
|
componentDocumentWithChartBarExcel1.CreateDoc(new ComponentDocumentWithChartConfig()
|
|
{
|
|
FilePath = fileName,
|
|
Header = "Ñâîäêà ïî òèïàì èçäåëèÿ.",
|
|
ChartTitle = "Êîëè÷åñòâî ïîñòàâùèêîâ äëÿ òîâàðîâ êàæäîãî òèïà",
|
|
LegendLocation = ComponentsLibraryNet60.Models.Location.Bottom,
|
|
Data = data
|
|
});
|
|
}
|
|
}
|
|
} |