147 lines
5.6 KiB
C#
147 lines
5.6 KiB
C#
using AbazovViewComponents.LogicalComponents;
|
||
using AccountsContracts.BindingModels;
|
||
using AccountsContracts.BusinessLogicContracts;
|
||
using AccountsContracts.ViewModels;
|
||
using ComponentsLibraryNet60.Models;
|
||
using ControlsLibraryNet60.Core;
|
||
using ControlsLibraryNet60.Models;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using System.Data;
|
||
using System.Drawing;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using System.Windows.Forms;
|
||
|
||
namespace AccountsApp
|
||
{
|
||
public partial class FormMain : Form
|
||
{
|
||
private IAccountLogic _logic;
|
||
|
||
public FormMain(IAccountLogic logic)
|
||
{
|
||
InitializeComponent();
|
||
_logic = logic;
|
||
controlDataTable.LoadColumns(new List<DataTableColumnConfig> {
|
||
new DataTableColumnConfig { ColumnHeader = "", PropertyName = "Id", Visible = false, Width = 10},
|
||
new DataTableColumnConfig { ColumnHeader = "Логин", PropertyName = "Login", Visible = true, Width = 200},
|
||
new DataTableColumnConfig { ColumnHeader = "Выбранный интерес", PropertyName = "InterestName", Visible = true, Width = 200},
|
||
new DataTableColumnConfig { ColumnHeader = "Email", PropertyName = "Email", Visible = true, Width = 200},
|
||
});
|
||
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
||
}
|
||
|
||
private void создатьToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
var service = Program.ServiceProvider?.GetService(typeof(FormAccount));
|
||
if (service is FormAccount form)
|
||
{
|
||
if (form.ShowDialog() == DialogResult.OK)
|
||
{
|
||
LoadData();
|
||
}
|
||
}
|
||
}
|
||
|
||
private void интересыToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
var service = Program.ServiceProvider?.GetService(typeof(FormInterests));
|
||
if (service is FormInterests form)
|
||
{
|
||
form.ShowDialog();
|
||
}
|
||
}
|
||
|
||
private void FormMain_Load(object sender, EventArgs e)
|
||
{
|
||
LoadData();
|
||
}
|
||
|
||
private void LoadData()
|
||
{
|
||
controlDataTable.Clear();
|
||
var accounts = _logic.ReadList(null);
|
||
if (accounts != null)
|
||
{
|
||
controlDataTable.AddTable(accounts);
|
||
}
|
||
}
|
||
|
||
private void редактироватьToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
var service = Program.ServiceProvider?.GetService(typeof(FormAccount));
|
||
if (service is FormAccount form)
|
||
{
|
||
form.Id = controlDataTable.GetSelectedObject<AccountViewModel>().Id;
|
||
if (form.ShowDialog() == DialogResult.OK)
|
||
{
|
||
LoadData();
|
||
}
|
||
}
|
||
}
|
||
|
||
private void удалитьToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
if (MessageBox.Show("Удалить запись?", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
|
||
{
|
||
if (_logic.Delete(new AccountBindingModel { Id = controlDataTable.GetSelectedObject<AccountViewModel>().Id }))
|
||
{
|
||
LoadData();
|
||
}
|
||
}
|
||
}
|
||
|
||
private void документToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
List<string> avatars = new List<string>();
|
||
foreach (var account in _logic.ReadList(null))
|
||
{
|
||
avatars.Add(account.Avatar);
|
||
}
|
||
string path = AppDomain.CurrentDomain.BaseDirectory + "Аватары.xlsx";
|
||
if (excelImagesComponent.createWithImages(new ExcelImageInfo(path, "Аватары", avatars.ToArray()))) MessageBox.Show("Документ создан");
|
||
}
|
||
|
||
private void документСДиаграммойToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
string path = AppDomain.CurrentDomain.BaseDirectory + "Интересы.pdf";
|
||
Dictionary<string, List<(int, double)>> data = new Dictionary<string, List<(int, double)>>();
|
||
|
||
data = _logic
|
||
.ReadList(null)
|
||
.GroupBy(x => x.InterestName)
|
||
.ToDictionary(x => x.Key, x => new List<(int, double)> { (0, x.Count())});
|
||
|
||
componentDocumentWithChartBarPdf.CreateDoc(new ComponentDocumentWithChartConfig
|
||
{
|
||
Header = "Интересы",
|
||
FilePath = path,
|
||
ChartTitle = "Интересы",
|
||
LegendLocation = ComponentsLibraryNet60.Models.Location.Bottom,
|
||
Data = data,
|
||
});
|
||
|
||
MessageBox.Show("Успех");
|
||
}
|
||
|
||
private void документСТаблицейToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
string path = AppDomain.CurrentDomain.BaseDirectory + "Аккаунты.docx";
|
||
List<(int, int)> merges = new List<(int, int)> { (1, 2) };
|
||
List<int> widths = new List<int> { 100, 100, 100, 100 };
|
||
List<(string, string)> headers = new List<(string, string)> {
|
||
("Id", "Идентификатор"),
|
||
("", "Личные данные"),
|
||
("Login", "Логин"),
|
||
("Email", "Эл. почта"),
|
||
("InterestName", "Выбранный интерес")
|
||
};
|
||
|
||
wordTableComponentAccount.createWithTable(path, "Список аккаунтов", merges, widths, headers, _logic.ReadList(null));
|
||
}
|
||
}
|
||
}
|