216 lines
8.2 KiB
C#
216 lines
8.2 KiB
C#
|
using ComponentsLibraryNet60.Models;
|
|||
|
using ControlsLibraryNet60.Models;
|
|||
|
using PortalAccountsContracts.BindingModels;
|
|||
|
using PortalAccountsContracts.BusinessLogicsContracts;
|
|||
|
using PortalAccountsContracts.ViewModels;
|
|||
|
using RodionovLibrary.NonVisualComponents.HelperModels;
|
|||
|
|
|||
|
namespace PortalAccountsView
|
|||
|
{
|
|||
|
public partial class FormMain : Form
|
|||
|
{
|
|||
|
private readonly IAccountLogic _logic;
|
|||
|
|
|||
|
public FormMain(IAccountLogic logic)
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
|
|||
|
_logic = logic;
|
|||
|
|
|||
|
var nodeNames = new Queue<string>();
|
|||
|
nodeNames.Enqueue("RoleName");
|
|||
|
nodeNames.Enqueue("OutputRating");
|
|||
|
nodeNames.Enqueue("Id");
|
|||
|
nodeNames.Enqueue("Login");
|
|||
|
controlDataTreeTable.LoadConfig(new DataTreeNodeConfig { NodeNames = nodeNames });
|
|||
|
}
|
|||
|
|
|||
|
private void <EFBFBD><EFBFBD><EFBFBD><EFBFBD>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()
|
|||
|
{
|
|||
|
controlDataTreeTable.Clear();
|
|||
|
var accounts = _logic.ReadList(null);
|
|||
|
if (accounts != null)
|
|||
|
{
|
|||
|
foreach (var account in accounts)
|
|||
|
{
|
|||
|
account.OutputRating = account.Rating?.ToString() ?? "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
|||
|
}
|
|||
|
controlDataTreeTable.AddTable(accounts);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>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 <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ToolStripMenuItem_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
var service = Program.ServiceProvider?.GetService(typeof(FormAccount));
|
|||
|
if (service is FormAccount form)
|
|||
|
{
|
|||
|
var selected = controlDataTreeTable.GetSelectedObject<AccountViewModel>();
|
|||
|
if (selected == null)
|
|||
|
return;
|
|||
|
form.Id = selected.Id;
|
|||
|
if (form.ShowDialog() == DialogResult.OK)
|
|||
|
{
|
|||
|
LoadData();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ToolStripMenuItem_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
var selected = controlDataTreeTable.GetSelectedObject<AccountViewModel>();
|
|||
|
if (selected == null)
|
|||
|
return;
|
|||
|
if (MessageBox.Show("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>?", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
|
|||
|
{
|
|||
|
if (_logic.Delete(new AccountBindingModel { Id = selected.Id }))
|
|||
|
{
|
|||
|
LoadData();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ToolStripMenuItem_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
using var dialog = new SaveFileDialog
|
|||
|
{
|
|||
|
Filter = "docx|*.docx"
|
|||
|
};
|
|||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var accounts = _logic.ReadList(null) ?? throw new Exception("<22><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|||
|
List<string> paragraphs = new();
|
|||
|
foreach (var account in accounts)
|
|||
|
{
|
|||
|
if (account.Rating == null)
|
|||
|
{
|
|||
|
paragraphs.Add($"{account.Login}: {(string.IsNullOrWhiteSpace(account.Warnings) ? "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" : account.Warnings)}");
|
|||
|
}
|
|||
|
}
|
|||
|
wordLongTextComponent.CreateWordText(new WordLongTextInfo()
|
|||
|
{
|
|||
|
FileName = dialog.FileName,
|
|||
|
Title = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
|
|||
|
Paragraphs = paragraphs.ToArray()
|
|||
|
});
|
|||
|
MessageBox.Show("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!");
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
MessageBox.Show("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: " + ex.Message, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ToolStripMenuItem_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
using var dialog = new SaveFileDialog
|
|||
|
{
|
|||
|
Filter = "Excel Files|*.xlsx"
|
|||
|
};
|
|||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var accounts = _logic.ReadList(null) ?? throw new Exception("<22><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|||
|
var roleMapping = new List<string>();
|
|||
|
var data = new Dictionary<string, List<(int Date, double Value)>>
|
|||
|
{
|
|||
|
{
|
|||
|
"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
|
|||
|
accounts
|
|||
|
.Where(x => x.Rating != null)
|
|||
|
.GroupBy(x => x.RoleName)
|
|||
|
.Select((group, index) =>
|
|||
|
{
|
|||
|
roleMapping.Add($"{group.Key} - {index + 1}");
|
|||
|
|
|||
|
return (Date: index + 1, Value: (double)group.Count());
|
|||
|
})
|
|||
|
.ToList()
|
|||
|
}
|
|||
|
};
|
|||
|
componentDocumentWithChartPieExcel.CreateDoc(new ComponentDocumentWithChartConfig
|
|||
|
{
|
|||
|
FilePath = dialog.FileName,
|
|||
|
Header = $"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD> ({string.Join(", ", roleMapping)})",
|
|||
|
ChartTitle = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
|
|||
|
LegendLocation = ComponentsLibraryNet60.Models.Location.Bottom,
|
|||
|
Data = data
|
|||
|
});
|
|||
|
MessageBox.Show("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!");
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
MessageBox.Show("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: " + ex.Message, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ToolStripMenuItem_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
using var dialog = new SaveFileDialog
|
|||
|
{
|
|||
|
Filter = "PDF Files|*.pdf"
|
|||
|
};
|
|||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var accounts = _logic.ReadList(null) ?? throw new Exception("<22><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|||
|
foreach (var account in accounts)
|
|||
|
{
|
|||
|
account.OutputRating = account.Rating?.ToString() ?? "<22><><EFBFBD>";
|
|||
|
}
|
|||
|
componentDocumentWithTableMultiHeaderPdf.CreateDoc(new ComponentDocumentWithTableHeaderDataConfig<AccountViewModel>
|
|||
|
{
|
|||
|
FilePath = dialog.FileName,
|
|||
|
Header = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
|
|||
|
ColumnsRowsWidth = new List<(int, int)> { (10, 10), (10, 10), (10, 10), (10, 10)}, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
Headers = new List<(int ColumnIndex, int RowIndex, string Header, string PropertyName)>
|
|||
|
{
|
|||
|
(0, 0, "Id", "Id"),
|
|||
|
(1, 0, "<22><><EFBFBD><EFBFBD><EFBFBD>", "Login"),
|
|||
|
(2, 0, "<22><><EFBFBD><EFBFBD>", "RoleName"),
|
|||
|
(3, 0, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "OutputRating")
|
|||
|
},
|
|||
|
Data = accounts
|
|||
|
});
|
|||
|
MessageBox.Show("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!");
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
MessageBox.Show("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: " + ex.Message, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|