PIbd-33_Abazov_A.A._KOP_29/AbazovApp/AccountsApp/FormMain.cs

131 lines
4.8 KiB
C#
Raw Normal View History

2023-11-30 00:23:56 +04:00
using AbazovViewComponents.LogicalComponents;
using AccountsContracts.BindingModels;
2023-11-29 23:40:28 +04:00
using AccountsContracts.BusinessLogicContracts;
using AccountsContracts.ViewModels;
2023-11-30 00:51:17 +04:00
using ComponentsLibraryNet60.Models;
2023-11-29 23:40:28 +04:00
using ControlsLibraryNet60.Core;
using ControlsLibraryNet60.Models;
using System;
2023-11-16 20:39:00 +04:00
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
{
2023-11-29 23:40:28 +04:00
private IAccountLogic _logic;
public FormMain(IAccountLogic logic)
2023-11-16 20:39:00 +04:00
{
InitializeComponent();
2023-11-29 23:40:28 +04:00
_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},
});
2023-11-30 00:51:17 +04:00
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
2023-11-16 20:39:00 +04:00
}
2023-11-16 23:49:40 +04:00
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)
{
2023-11-29 23:40:28 +04:00
LoadData();
2023-11-16 23:49:40 +04:00
}
}
}
private void интересыToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormInterests));
if (service is FormInterests form)
{
form.ShowDialog();
}
}
2023-11-29 23:40:28 +04:00
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();
}
}
}
2023-11-30 00:23:56 +04:00
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("Документ создан");
}
2023-11-30 00:51:17 +04:00
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("Успех");
}
2023-11-16 20:39:00 +04:00
}
}