diff --git a/NevaevaLibrary/AccountContracts/ViewModels/AccountViewModel.cs b/NevaevaLibrary/AccountContracts/ViewModels/AccountViewModel.cs index 34f4905..63957b2 100644 --- a/NevaevaLibrary/AccountContracts/ViewModels/AccountViewModel.cs +++ b/NevaevaLibrary/AccountContracts/ViewModels/AccountViewModel.cs @@ -10,15 +10,17 @@ namespace AccountContracts.ViewModels { public class AccountViewModel : IAccountModel { - public int Id { get; set; } + public int Id { get; set; } = 0; [DisplayName("Логин")] public string Login { get; set; } = string.Empty; [DisplayName("Рейтинг")] - public float? Rating { get; set; } + public float? Rating { get; set; } = null; [DisplayName("Предупреждения")] public string? Warnings { get; set; } = string.Empty; - public int RoleId { get; set; } + public int RoleId { get; set; } = 0; [DisplayName("Роль")] - public string RoleName { get; set; } + public string RoleName { get; set; } = string.Empty; + public float ViewRating { get; set; } = 0; + public string DocRating { get; set; } = string.Empty; } } diff --git a/NevaevaLibrary/AccountsView/AccountsView.csproj b/NevaevaLibrary/AccountsView/AccountsView.csproj index 994ec10..e96fc91 100644 --- a/NevaevaLibrary/AccountsView/AccountsView.csproj +++ b/NevaevaLibrary/AccountsView/AccountsView.csproj @@ -9,13 +9,14 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/NevaevaLibrary/AccountsView/FormMain.Designer.cs b/NevaevaLibrary/AccountsView/FormMain.Designer.cs index 1a7c97a..72d9090 100644 --- a/NevaevaLibrary/AccountsView/FormMain.Designer.cs +++ b/NevaevaLibrary/AccountsView/FormMain.Designer.cs @@ -28,14 +28,21 @@ /// private void InitializeComponent() { + this.components = new System.ComponentModel.Container(); this.menuStrip1 = new System.Windows.Forms.MenuStrip(); this.аккаунтыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.создатьToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.редактироватьToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.удалитьToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.отчётыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.документToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.документСТаблицейToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.документСДиаграммойToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.ролиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.abazovTreeView = new AbazovViewComponents.Components.AbazovTreeView(); + this.wordLongTextComponent = new NevaevaLibrary.LogicalComponents.WordLongTextComponent(this.components); + this.excelDiagramComponent = new AbazovViewComponents.LogicalComponents.ExcelDiagramComponent(this.components); + this.componentDocumentWithTableMultiHeaderPdf = new ComponentsLibraryNet60.DocumentWithTable.ComponentDocumentWithTableMultiHeaderPdf(this.components); this.menuStrip1.SuspendLayout(); this.SuspendLayout(); // @@ -76,6 +83,7 @@ this.редактироватьToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.U))); this.редактироватьToolStripMenuItem.Size = new System.Drawing.Size(246, 26); this.редактироватьToolStripMenuItem.Text = "Редактировать"; + this.редактироватьToolStripMenuItem.Click += new System.EventHandler(this.редактироватьToolStripMenuItem_Click); // // удалитьToolStripMenuItem // @@ -83,13 +91,42 @@ this.удалитьToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.D))); this.удалитьToolStripMenuItem.Size = new System.Drawing.Size(246, 26); this.удалитьToolStripMenuItem.Text = "Удалить"; + this.удалитьToolStripMenuItem.Click += new System.EventHandler(this.удалитьToolStripMenuItem_Click); // // отчётыToolStripMenuItem // + this.отчётыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.документToolStripMenuItem, + this.документСТаблицейToolStripMenuItem, + this.документСДиаграммойToolStripMenuItem}); this.отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem"; this.отчётыToolStripMenuItem.Size = new System.Drawing.Size(73, 24); this.отчётыToolStripMenuItem.Text = "Отчёты"; // + // документToolStripMenuItem + // + this.документToolStripMenuItem.Name = "документToolStripMenuItem"; + this.документToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.S))); + this.документToolStripMenuItem.Size = new System.Drawing.Size(313, 26); + this.документToolStripMenuItem.Text = "Документ"; + this.документToolStripMenuItem.Click += new System.EventHandler(this.документToolStripMenuItem_Click); + // + // документСТаблицейToolStripMenuItem + // + this.документСТаблицейToolStripMenuItem.Name = "документСТаблицейToolStripMenuItem"; + this.документСТаблицейToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.T))); + this.документСТаблицейToolStripMenuItem.Size = new System.Drawing.Size(313, 26); + this.документСТаблицейToolStripMenuItem.Text = "Документ с таблицей"; + this.документСТаблицейToolStripMenuItem.Click += new System.EventHandler(this.документСТаблицейToolStripMenuItem_Click); + // + // документСДиаграммойToolStripMenuItem + // + this.документСДиаграммойToolStripMenuItem.Name = "документСДиаграммойToolStripMenuItem"; + this.документСДиаграммойToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.C))); + this.документСДиаграммойToolStripMenuItem.Size = new System.Drawing.Size(313, 26); + this.документСДиаграммойToolStripMenuItem.Text = "Документ с диаграммой"; + this.документСДиаграммойToolStripMenuItem.Click += new System.EventHandler(this.документСДиаграммойToolStripMenuItem_Click); + // // ролиToolStripMenuItem // this.ролиToolStripMenuItem.Name = "ролиToolStripMenuItem"; @@ -134,5 +171,11 @@ private ToolStripMenuItem создатьToolStripMenuItem; private ToolStripMenuItem редактироватьToolStripMenuItem; private ToolStripMenuItem удалитьToolStripMenuItem; + private ToolStripMenuItem документToolStripMenuItem; + private ToolStripMenuItem документСТаблицейToolStripMenuItem; + private ToolStripMenuItem документСДиаграммойToolStripMenuItem; + private NevaevaLibrary.LogicalComponents.WordLongTextComponent wordLongTextComponent; + private AbazovViewComponents.LogicalComponents.ExcelDiagramComponent excelDiagramComponent; + private ComponentsLibraryNet60.DocumentWithTable.ComponentDocumentWithTableMultiHeaderPdf componentDocumentWithTableMultiHeaderPdf; } } \ No newline at end of file diff --git a/NevaevaLibrary/AccountsView/FormMain.cs b/NevaevaLibrary/AccountsView/FormMain.cs index f365ee8..17782ca 100644 --- a/NevaevaLibrary/AccountsView/FormMain.cs +++ b/NevaevaLibrary/AccountsView/FormMain.cs @@ -1,5 +1,11 @@ -using AccountContracts.BusinessLogicsContracts; +using AbazovViewComponents.LogicalComponents; +using AccountContracts.BindingModels; +using AccountContracts.BusinessLogicsContracts; +using AccountContracts.ViewModels; +using AccountDatabaseImplement.Models; +using ComponentsLibraryNet60.Models; using ControlsLibraryNet60.Core; +using NevaevaLibrary.LogicalComponents; using System; using System.Collections.Generic; using System.ComponentModel; @@ -20,7 +26,7 @@ namespace AccountsView { InitializeComponent(); _logic = logic; - abazovTreeView.setHierarchy(new List<(string, bool)> { ("RoleName", false), ("Rating", false), ("Id", true), ("Login", true) }); + abazovTreeView.setHierarchy(new List<(string, bool)> { ("RoleName", false), ("ViewRating", false), ("Id", true), ("Login", true) }); } private void ролиToolStripMenuItem_Click(object sender, EventArgs e) @@ -47,7 +53,11 @@ namespace AccountsView { if (!account.Rating.HasValue) { - account.Rating = 0; + account.ViewRating = 0; + } + else + { + account.ViewRating = account.Rating.Value; } } abazovTreeView.addItems(accounts); @@ -65,5 +75,121 @@ namespace AccountsView } } } + + private void редактироватьToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormAccount)); + if (service is FormAccount form) + { + var selected = abazovTreeView.getSelecetedNodeValue(); + 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(); + 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 paragraphs = new List(); + 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 paragraphs = new List(); + 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 paragraphs = new List(); + 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 config = new ComponentsLibraryNet60.Models.ComponentDocumentWithTableHeaderDataConfig + { + 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("Документ создан"); + } } } diff --git a/NevaevaLibrary/AccountsView/FormMain.resx b/NevaevaLibrary/AccountsView/FormMain.resx index 938108a..52ddc4f 100644 --- a/NevaevaLibrary/AccountsView/FormMain.resx +++ b/NevaevaLibrary/AccountsView/FormMain.resx @@ -60,4 +60,13 @@ 17, 17 + + 152, 17 + + + 383, 17 + + + 609, 17 + \ No newline at end of file