196 lines
7.2 KiB
C#
Raw Permalink Normal View History

2023-12-01 02:29:05 +04:00
using AbazovViewComponents.LogicalComponents;
using AccountContracts.BindingModels;
using AccountContracts.BusinessLogicsContracts;
using AccountContracts.ViewModels;
using AccountDatabaseImplement.Models;
using ComponentsLibraryNet60.Models;
2023-12-01 01:01:22 +04:00
using ControlsLibraryNet60.Core;
2023-12-01 02:29:05 +04:00
using NevaevaLibrary.LogicalComponents;
2023-12-01 01:01:22 +04:00
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 AccountsView
{
public partial class FormMain : Form
{
private IAccountLogic _logic;
public FormMain(IAccountLogic logic)
{
InitializeComponent();
_logic = logic;
2023-12-01 02:29:05 +04:00
abazovTreeView.setHierarchy(new List<(string, bool)> { ("RoleName", false), ("ViewRating", false), ("Id", true), ("Login", true) });
2023-12-01 01:01:22 +04:00
}
private void ролиToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormRoles));
if (service is FormRoles form)
{
form.ShowDialog();
}
}
private void FormMain_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
abazovTreeView.clear();
var accounts = _logic.ReadList(null);
if (accounts != null)
{
2023-12-01 01:17:26 +04:00
foreach (var account in accounts)
{
if (!account.Rating.HasValue)
{
2023-12-01 02:29:05 +04:00
account.ViewRating = 0;
}
else
{
account.ViewRating = account.Rating.Value;
2023-12-01 01:17:26 +04:00
}
}
2023-12-01 01:01:22 +04:00
abazovTreeView.addItems(accounts);
}
}
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();
}
}
}
2023-12-01 02:29:05 +04:00
private void редактироватьToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormAccount));
if (service is FormAccount form)
{
var selected = abazovTreeView.getSelecetedNodeValue<AccountViewModel>();
if (selected == null) return;
form.Id = selected.Id;
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void удалитьToolStripMenuItem_Click(object sender, EventArgs e)
{
var selected = abazovTreeView.getSelecetedNodeValue<AccountViewModel>();
if (selected == null) return;
if (MessageBox.Show("Удалить запись?", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
if (_logic.Delete(new AccountBindingModel { Id = selected.Id }))
{
LoadData();
}
}
}
private void документToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog = new()
{
Filter = "Word Files|*.docx"
};
if (saveFileDialog.ShowDialog() != DialogResult.OK) return;
List<string> paragraphs = new List<string>();
foreach (var account in _logic.ReadList(null))
{
if (account.Rating == null)
{
paragraphs.Add(account.Login + ": " + account.Warnings);
}
}
string path = saveFileDialog.FileName;
wordLongTextComponent.createWithLongText(new WordLongTextInfo(path, "Аккаунты без рейтинга", paragraphs.ToArray()));
MessageBox.Show("Документ создан");
}
private void документСДиаграммойToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog = new()
{
Filter = "Excel Files|*.xlsx"
};
if (saveFileDialog.ShowDialog() != DialogResult.OK) return;
List<string> paragraphs = new List<string>();
string path = saveFileDialog.FileName;
var data = _logic.ReadList(null).Where(x => x.Rating == null).GroupBy(x => x.RoleName).Select(x => new
{
RoleName = x.Key,
RoleCount = x.Count(),
}).ToList();
excelDiagramComponent.createWithDiagram(path, "Роли без рейтинга", "Роли без рейтинга", AbazovViewComponents.LogicalComponents.DiagramLegendEnum.BottomRight,
data, "RoleName", "RoleCount");
MessageBox.Show("Документ создан");
}
private void документСТаблицейToolStripMenuItem_Click(object sender, EventArgs e)
{
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
SaveFileDialog saveFileDialog = new()
{
Filter = "PDF Files|*.pdf"
};
if (saveFileDialog.ShowDialog() != DialogResult.OK) return;
List<string> paragraphs = new List<string>();
string path = saveFileDialog.FileName;
var accounts = _logic.ReadList(null);
foreach (var account in accounts)
{
if (!account.Rating.HasValue)
{
account.DocRating = "нет";
}
else
{
account.DocRating = account.Rating.Value.ToString();
}
}
ComponentDocumentWithTableHeaderDataConfig<AccountViewModel> config = new ComponentsLibraryNet60.Models.ComponentDocumentWithTableHeaderDataConfig<AccountViewModel>
{
Data = accounts,
UseUnion = false,
Header = "Аккаунты",
ColumnsRowsDataCount = (4, 1),
Headers = new List<(int ColumnIndex, int RowIndex, string Header, string PropertyName)>
{
(0, 0, "Id", "Id"),
(1, 0, "Логин", "Login"),
(2, 0, "Роль", "RoleName"),
(3, 0, "Рейтинг", "DocRating")
},
ColumnsRowsWidth = new List<(int Column, int Row)>
{
(10, 10),
(10, 10),
(10, 10),
(10, 10)
},
ColumnUnion = new List<(int StartIndex, int Count)>(),
FilePath = path
};
componentDocumentWithTableMultiHeaderPdf.CreateDoc(config);
MessageBox.Show("Документ создан");
}
2023-12-01 01:01:22 +04:00
}
}