154 lines
4.8 KiB
C#
154 lines
4.8 KiB
C#
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)
|
|
{
|
|
|
|
}
|
|
}
|
|
} |