diff --git a/VolkovLabs/WinFormsLibraryVolkov/DataTreeNodeConfig.cs b/VolkovLabs/WinFormsLibraryVolkov/DataTreeNodeConfig.cs deleted file mode 100644 index adeb9d2..0000000 --- a/VolkovLabs/WinFormsLibraryVolkov/DataTreeNodeConfig.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace WinFormsLibraryVolkov -{ - public class DataTreeNodeConfig - { - public Queue NodeNames { get; set; } - } -} diff --git a/VolkovLabs/WinFormsLibraryVolkov/Exceptions/DateBoundsNotSetException.cs b/VolkovLabs/WinFormsLibraryVolkov/Exceptions/DateBoundsNotSetException.cs new file mode 100644 index 0000000..82fae6c --- /dev/null +++ b/VolkovLabs/WinFormsLibraryVolkov/Exceptions/DateBoundsNotSetException.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; + +namespace WinFormsLibraryVolkov.Exceptions +{ + [Serializable] + public class DateBoundsNotSetException: ApplicationException + { + public DateBoundsNotSetException() : base() { } + public DateBoundsNotSetException(string message) : base(message) { } + public DateBoundsNotSetException(string message, Exception exception) : base(message, exception){ } + protected DateBoundsNotSetException(SerializationInfo info, StreamingContext contex) : base(info, contex) { } + } +} diff --git a/VolkovLabs/WinFormsLibraryVolkov/Exceptions/DateOutOfBoundsException.cs b/VolkovLabs/WinFormsLibraryVolkov/Exceptions/DateOutOfBoundsException.cs new file mode 100644 index 0000000..cc04d0a --- /dev/null +++ b/VolkovLabs/WinFormsLibraryVolkov/Exceptions/DateOutOfBoundsException.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; + +namespace WinFormsLibraryVolkov.Exceptions +{ + public class DateOutOfBoundsException : ApplicationException + { + public DateOutOfBoundsException() : base() { } + public DateOutOfBoundsException(string message) : base(message) { } + public DateOutOfBoundsException(string message, Exception exception) : base(message, exception) { } + protected DateOutOfBoundsException(SerializationInfo info, StreamingContext contex) : base(info, contex) { } + } +} diff --git a/VolkovLabs/WinFormsLibraryVolkov/NonVisualComponents/DiagramLegendEnum.cs b/VolkovLabs/WinFormsLibraryVolkov/NonVisualComponents/DiagramLegendEnum.cs new file mode 100644 index 0000000..a68d6da --- /dev/null +++ b/VolkovLabs/WinFormsLibraryVolkov/NonVisualComponents/DiagramLegendEnum.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WinFormsLibraryVolkov.NonVisualComponents +{ + public enum DiagramLegendEnum + { + TopLeft = 0, + TopRight = 1, + BottomRight = 2, + BottomLeft = 3, + } +} diff --git a/VolkovLabs/WinFormsLibraryVolkov/NonVisualComponents/ExcelDiagramComponent.Designer.cs b/VolkovLabs/WinFormsLibraryVolkov/NonVisualComponents/ExcelDiagramComponent.Designer.cs new file mode 100644 index 0000000..80ffd78 --- /dev/null +++ b/VolkovLabs/WinFormsLibraryVolkov/NonVisualComponents/ExcelDiagramComponent.Designer.cs @@ -0,0 +1,36 @@ +namespace WinFormsLibraryVolkov.NonVisualComponents +{ + partial class ExcelDiagramComponent + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + } + + #endregion + } +} diff --git a/VolkovLabs/WinFormsLibraryVolkov/NonVisualComponents/ExcelDiagramComponent.cs b/VolkovLabs/WinFormsLibraryVolkov/NonVisualComponents/ExcelDiagramComponent.cs new file mode 100644 index 0000000..c81a4ce --- /dev/null +++ b/VolkovLabs/WinFormsLibraryVolkov/NonVisualComponents/ExcelDiagramComponent.cs @@ -0,0 +1,119 @@ +using Microsoft.Office.Interop.Excel; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace WinFormsLibraryVolkov.NonVisualComponents +{ + [ToolboxItem(true)] + public partial class ExcelDiagramComponent : Component + { + public ExcelDiagramComponent() + { + InitializeComponent(); + } + + public ExcelDiagramComponent(IContainer container) + { + container.Add(this); + + InitializeComponent(); + } + + public bool createWithDiagram(string path, string title, string diagramTitle, DiagramLegendEnum diagramLegendAnchor, List data, string seriesNameField, string valueField) + { + var excelApp = new Microsoft.Office.Interop.Excel.Application { SheetsInNewWorkbook = 1 }; + Workbook workbook = excelApp.Workbooks.Add(Type.Missing); + try + { + Worksheet worksheet = (Worksheet)workbook.Worksheets.get_Item(1); + + FieldInfo? seriesName = typeof(T).GetField(seriesNameField); + FieldInfo? value = typeof(T).GetField(valueField); + if (seriesName == null || value == null) throw new ArgumentException("Переданного поля не существует"); + int columnCount = 2; + foreach(var item in data) + { + var cell = worksheet.get_Range("A" + columnCount, "A" + columnCount); + cell.Font.Size = 14; + cell.Font.Name = "Times New Roman"; + cell.ColumnWidth = 8; + cell.RowHeight = 25; + cell.HorizontalAlignment = Constants.xlCenter; + cell.VerticalAlignment = Constants.xlCenter; + cell.Value2 = seriesName.GetValue(item); + + cell = worksheet.get_Range("B" + columnCount, "B" + columnCount); + cell.Font.Size = 14; + cell.Font.Name = "Times New Roman"; + cell.ColumnWidth = 8; + cell.RowHeight = 25; + cell.HorizontalAlignment = Constants.xlCenter; + cell.VerticalAlignment = Constants.xlCenter; + cell.Value2 = value.GetValue(item); + + columnCount++; + } + + //header + var excelcells = worksheet.get_Range("A1", "A1"); + excelcells.Font.Bold = true; + excelcells.Font.Size = 14; + excelcells.Font.Name = "Times New Roman"; + excelcells.ColumnWidth = 8; + excelcells.RowHeight = 25; + excelcells.HorizontalAlignment = Constants.xlCenter; + excelcells.VerticalAlignment = Constants.xlCenter; + excelcells.Value2 = title; + + var charts = worksheet.ChartObjects() as ChartObjects; + int chartWidth = 300; + int chartHeight = 300; + var chartObject = charts.Add(250, 10, chartWidth, chartHeight); + var chart = chartObject.Chart; + var range = worksheet.get_Range($"A2", $"B{columnCount - 1}"); + chart.SetSourceData(range); + chart.ChartType = XlChartType.xlPie; + switch (diagramLegendAnchor) + { + case DiagramLegendEnum.TopLeft: + chart.Legend.Top = 0; + chart.Legend.Left = 0; + break; + case DiagramLegendEnum.TopRight: + chart.Legend.Top = 0; + chart.Legend.Left = chartWidth - chart.Legend.Width; + break; + case DiagramLegendEnum.BottomLeft: + chart.Legend.Top = chartHeight - chart.Legend.Height; + chart.Legend.Left = 0; + break; + case DiagramLegendEnum.BottomRight: + chart.Legend.Top = chartHeight - chart.Legend.Height; + chart.Legend.Left = chartWidth - chart.Legend.Width; + break; + } + chart.ChartWizard(Source: range, Title: diagramTitle); + + object missing = System.Reflection.Missing.Value; + workbook.SaveAs(path, XlFileFormat.xlOpenXMLWorkbook, missing, missing, false, false, XlSaveAsAccessMode.xlNoChange, + XlSaveConflictResolution.xlUserResolution, true, missing, missing, missing); + workbook.Close(); + excelApp.Quit(); + + return true; + } + catch (Exception) + { + workbook.Close(); + excelApp.Quit(); + throw; + } + } + } +} diff --git a/VolkovLabs/WinFormsLibraryVolkov/NonVisualComponents/ExcelImageInfo.cs b/VolkovLabs/WinFormsLibraryVolkov/NonVisualComponents/ExcelImageInfo.cs new file mode 100644 index 0000000..2351878 --- /dev/null +++ b/VolkovLabs/WinFormsLibraryVolkov/NonVisualComponents/ExcelImageInfo.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WinFormsLibraryVolkov.NonVisualComponents +{ + public class ExcelImageInfo + { + public ExcelImageInfo(string path, string title, string[] imagePaths) + { + this.path = path; + this.title = title; + this.imagePaths = imagePaths; + } + + public string path; + public string title; + public string[] imagePaths; + } +} diff --git a/VolkovLabs/WinFormsLibraryVolkov/NonVisualComponents/ExcelImagesComponent.Designer.cs b/VolkovLabs/WinFormsLibraryVolkov/NonVisualComponents/ExcelImagesComponent.Designer.cs new file mode 100644 index 0000000..47133fa --- /dev/null +++ b/VolkovLabs/WinFormsLibraryVolkov/NonVisualComponents/ExcelImagesComponent.Designer.cs @@ -0,0 +1,36 @@ +namespace WinFormsLibraryVolkov.NonVisualComponents +{ + partial class ExcelImagesComponent + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + } + + #endregion + } +} diff --git a/VolkovLabs/WinFormsLibraryVolkov/NonVisualComponents/ExcelImagesComponent.cs b/VolkovLabs/WinFormsLibraryVolkov/NonVisualComponents/ExcelImagesComponent.cs new file mode 100644 index 0000000..d490b94 --- /dev/null +++ b/VolkovLabs/WinFormsLibraryVolkov/NonVisualComponents/ExcelImagesComponent.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Office.Interop.Excel; +using Microsoft.Office.Core; + +namespace WinFormsLibraryVolkov.NonVisualComponents +{ + public partial class ExcelImagesComponent : Component + { + public ExcelImagesComponent() + { + InitializeComponent(); + } + + public ExcelImagesComponent(IContainer container) + { + container.Add(this); + + InitializeComponent(); + } + + public bool createWithImages(ExcelImageInfo info) + { + var excelApp = new Microsoft.Office.Interop.Excel.Application { SheetsInNewWorkbook = 1 }; + Workbook workbook = excelApp.Workbooks.Add(Type.Missing); + try + { + //create + Worksheet worksheet = (Worksheet)workbook.Worksheets.get_Item(1); + + //header + var excelcells = worksheet.get_Range("A1", "D1"); + excelcells.Merge(Type.Missing); + excelcells.Font.Bold = true; + excelcells.Font.Size = 14; + excelcells.Font.Name = "Times New Roman"; + excelcells.ColumnWidth = 8; + excelcells.RowHeight = 25; + excelcells.HorizontalAlignment = Constants.xlCenter; + excelcells.VerticalAlignment = Constants.xlCenter; + excelcells.Value2 = info.title; + + int topOffset = 25; + foreach (string path in info.imagePaths) + { + Bitmap bm = new Bitmap(path); + worksheet.Shapes.AddPicture2(path, MsoTriState.msoFalse, MsoTriState.msoCTrue, 0, topOffset, bm.Width, bm.Height, MsoPictureCompress.msoPictureCompressFalse); + topOffset += bm.Height; + bm.Dispose(); + } + + //save + object missing = System.Reflection.Missing.Value; + workbook.SaveAs(info.path, XlFileFormat.xlOpenXMLWorkbook, missing, missing, false, false, XlSaveAsAccessMode.xlNoChange, + XlSaveConflictResolution.xlUserResolution, true, missing, missing, missing); + workbook.Close(); + excelApp.Quit(); + + return true; + } + catch (Exception) + { + workbook.Close(); + excelApp.Quit(); + return false; + } + } + } +} diff --git a/VolkovLabs/WinFormsLibraryVolkov/NonVisualComponents/ExcelTableComponent.Designer.cs b/VolkovLabs/WinFormsLibraryVolkov/NonVisualComponents/ExcelTableComponent.Designer.cs new file mode 100644 index 0000000..bc411ca --- /dev/null +++ b/VolkovLabs/WinFormsLibraryVolkov/NonVisualComponents/ExcelTableComponent.Designer.cs @@ -0,0 +1,36 @@ +namespace WinFormsLibraryVolkov.NonVisualComponents +{ + partial class ExcelTableComponent + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + } + + #endregion + } +} diff --git a/VolkovLabs/WinFormsLibraryVolkov/NonVisualComponents/ExcelTableComponent.cs b/VolkovLabs/WinFormsLibraryVolkov/NonVisualComponents/ExcelTableComponent.cs new file mode 100644 index 0000000..dccb84a --- /dev/null +++ b/VolkovLabs/WinFormsLibraryVolkov/NonVisualComponents/ExcelTableComponent.cs @@ -0,0 +1,193 @@ +using Microsoft.Office.Interop.Excel; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data.Common; +using System.Diagnostics; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace WinFormsLibraryVolkov.NonVisualComponents +{ + public partial class ExcelTableComponent : Component + { + public ExcelTableComponent() + { + InitializeComponent(); + } + + public ExcelTableComponent(IContainer container) + { + container.Add(this); + + InitializeComponent(); + } + + private string GetExcelColumnName(int columnNumber) + { + string columnName = ""; + + while (columnNumber > 0) + { + int modulo = (columnNumber - 1) % 26; + columnName = Convert.ToChar('A' + modulo) + columnName; + columnNumber = (columnNumber - modulo) / 26; + } + + return columnName; + } + + public bool createWithTable(string path, string title, List<(int, int)> merges, List heights, List<(string, string)> headers, List items) + { + if (merges.Count == 0 || heights.Count == 0 || headers.Count == 0 || items.Count == 0) throw new ArgumentException("Недостаточно данных"); + int[] cellsArray = new int[heights.Count]; + foreach (var merge in merges) + { + if (merge.Item1 >= merge.Item2) throw new ArgumentException("Неправильно заполнены объединения строк"); + for (int i = merge.Item1; i < merge.Item2; i++) + { + cellsArray[i]++; + } + } + foreach (int cell in cellsArray) + { + if (cell > 1) throw new ArgumentException("Объединения заходят друг на друга"); + } + + var excelApp = new Microsoft.Office.Interop.Excel.Application { SheetsInNewWorkbook = 1 }; + Workbook workbook = excelApp.Workbooks.Add(Type.Missing); + try + { + //create + Worksheet worksheet = (Worksheet)workbook.Worksheets.get_Item(1); + + //header + var excelcells = worksheet.get_Range("A1", "A1"); + excelcells.Font.Bold = true; + excelcells.Font.Size = 14; + excelcells.Font.Name = "Times New Roman"; + excelcells.ColumnWidth = 8; + excelcells.RowHeight = 25; + excelcells.HorizontalAlignment = Constants.xlCenter; + excelcells.VerticalAlignment = Constants.xlCenter; + excelcells.Value2 = title; + + //checks + List ranges = new List(); + foreach (var merge in merges) + { + ranges.Add(worksheet.get_Range("A" + (merge.Item1 + 2), "A" + (merge.Item2 + 2))); + } + + int rangeIndex = 0; + int headerIndex = 0; + List cellFields = new List(); + var type = typeof(T); + for (int i = 0; i < heights.Count; i++) + { + if (cellsArray[i] == 1) + { + //work with merge + if (!string.IsNullOrEmpty(headers[headerIndex].Item1)) throw new ArgumentException("Заголовки и объединения строк не совпадают"); + + var groupRange = ranges[rangeIndex]; + groupRange.Merge(Type.Missing); + groupRange.Font.Bold = true; + groupRange.Font.Size = 14; + groupRange.Font.Name = "Times New Roman"; + groupRange.ColumnWidth = 20; + groupRange.HorizontalAlignment = Constants.xlCenter; + groupRange.VerticalAlignment = Constants.xlCenter; + groupRange.Value2 = headers[headerIndex].Item2; + headerIndex++; + + //work with cells in merge + for (; i <= merges[rangeIndex].Item2; i++) + { + //work with cell + if (string.IsNullOrEmpty(headers[headerIndex].Item1)) throw new ArgumentException("Заголовки и объединения строк не совпадают"); + var field = type.GetField(headers[headerIndex].Item1); + if (field == null) throw new ArgumentException("В заголовках указано поле, которого нет в переданном классе"); + //format header + var range = worksheet.get_Range("B" + (i + 2), "B" + (i + 2)); + range.Font.Bold = true; + range.Font.Size = 14; + range.Font.Name = "Times New Roman"; + range.ColumnWidth = 20; + range.RowHeight = heights[i]; + range.HorizontalAlignment = Constants.xlCenter; + range.VerticalAlignment = Constants.xlCenter; + range.Value2 = headers[headerIndex].Item2; + + cellFields.Add(field); + headerIndex++; + } + i--; + rangeIndex++; + } + else + { + //work with cell + if (string.IsNullOrEmpty(headers[headerIndex].Item1)) throw new ArgumentException("Заголовки и объединения строк не совпадают"); + var field = type.GetField(headers[headerIndex].Item1); + if (field == null) throw new ArgumentException("В заголовках указано поле, которого нет в переданном классе"); + //format header + var range = worksheet.get_Range("A" + (i + 2), "B" + (i + 2)); + range.Merge(Type.Missing); + range.Font.Bold = true; + range.Font.Size = 14; + range.Font.Name = "Times New Roman"; + range.ColumnWidth = 40; + range.RowHeight = heights[i]; + range.HorizontalAlignment = Constants.xlCenter; + range.VerticalAlignment = Constants.xlCenter; + range.Value2 = headers[headerIndex].Item2; + + cellFields.Add(field); + headerIndex++; + } + } + + int columnNum = 3; + foreach (T item in items) + { + string column = GetExcelColumnName(columnNum); + int rowNum = 2; + foreach (var cellField in cellFields) + { + var range = worksheet.get_Range(column + rowNum, column + rowNum); + range.Font.Size = 14; + range.Font.Name = "Times New Roman"; + range.ColumnWidth = 20; + range.HorizontalAlignment = Constants.xlCenter; + range.VerticalAlignment = Constants.xlCenter; + range.Value2 = cellField.FieldType == typeof(bool) ? ((bool) cellField.GetValue(item) ? "Да" : "Нет") : cellField.GetValue(item); + + rowNum++; + } + columnNum++; + } + var borderRange = worksheet.get_Range("A2", GetExcelColumnName(columnNum-1) + (headerIndex - 1)); + borderRange.Borders.LineStyle = XlLineStyle.xlContinuous; + borderRange.Borders.Weight = 2d; + + //save + object missing = System.Reflection.Missing.Value; + workbook.SaveAs(path, XlFileFormat.xlOpenXMLWorkbook, missing, missing, false, false, XlSaveAsAccessMode.xlNoChange, + XlSaveConflictResolution.xlUserResolution, true, missing, missing, missing); + workbook.Close(); + excelApp.Quit(); + + return true; + } + catch (Exception ex) + { + workbook.Close(); + excelApp.Quit(); + throw; + } + } + } +} diff --git a/VolkovLabs/WinFormsLibraryVolkov/CustomInputRangeDate.Designer.cs b/VolkovLabs/WinFormsLibraryVolkov/VisualComponents/CustomInputRangeDate.Designer.cs similarity index 100% rename from VolkovLabs/WinFormsLibraryVolkov/CustomInputRangeDate.Designer.cs rename to VolkovLabs/WinFormsLibraryVolkov/VisualComponents/CustomInputRangeDate.Designer.cs diff --git a/VolkovLabs/WinFormsLibraryVolkov/CustomInputRangeDate.cs b/VolkovLabs/WinFormsLibraryVolkov/VisualComponents/CustomInputRangeDate.cs similarity index 100% rename from VolkovLabs/WinFormsLibraryVolkov/CustomInputRangeDate.cs rename to VolkovLabs/WinFormsLibraryVolkov/VisualComponents/CustomInputRangeDate.cs diff --git a/VolkovLabs/WinFormsLibraryVolkov/CustomInputRangeDate.resx b/VolkovLabs/WinFormsLibraryVolkov/VisualComponents/CustomInputRangeDate.resx similarity index 100% rename from VolkovLabs/WinFormsLibraryVolkov/CustomInputRangeDate.resx rename to VolkovLabs/WinFormsLibraryVolkov/VisualComponents/CustomInputRangeDate.resx diff --git a/VolkovLabs/WinFormsLibraryVolkov/CustomSelectedCheckedListBox.Designer.cs b/VolkovLabs/WinFormsLibraryVolkov/VisualComponents/CustomSelectedCheckedListBox.Designer.cs similarity index 100% rename from VolkovLabs/WinFormsLibraryVolkov/CustomSelectedCheckedListBox.Designer.cs rename to VolkovLabs/WinFormsLibraryVolkov/VisualComponents/CustomSelectedCheckedListBox.Designer.cs diff --git a/VolkovLabs/WinFormsLibraryVolkov/CustomSelectedCheckedListBox.cs b/VolkovLabs/WinFormsLibraryVolkov/VisualComponents/CustomSelectedCheckedListBox.cs similarity index 100% rename from VolkovLabs/WinFormsLibraryVolkov/CustomSelectedCheckedListBox.cs rename to VolkovLabs/WinFormsLibraryVolkov/VisualComponents/CustomSelectedCheckedListBox.cs diff --git a/VolkovLabs/WinFormsLibraryVolkov/CustomSelectedCheckedListBox.resx b/VolkovLabs/WinFormsLibraryVolkov/VisualComponents/CustomSelectedCheckedListBox.resx similarity index 100% rename from VolkovLabs/WinFormsLibraryVolkov/CustomSelectedCheckedListBox.resx rename to VolkovLabs/WinFormsLibraryVolkov/VisualComponents/CustomSelectedCheckedListBox.resx diff --git a/VolkovLabs/WinFormsLibraryVolkov/CustomTreeCell.Designer.cs b/VolkovLabs/WinFormsLibraryVolkov/VisualComponents/CustomTreeCell.Designer.cs similarity index 100% rename from VolkovLabs/WinFormsLibraryVolkov/CustomTreeCell.Designer.cs rename to VolkovLabs/WinFormsLibraryVolkov/VisualComponents/CustomTreeCell.Designer.cs diff --git a/VolkovLabs/WinFormsLibraryVolkov/CustomTreeCell.cs b/VolkovLabs/WinFormsLibraryVolkov/VisualComponents/CustomTreeCell.cs similarity index 94% rename from VolkovLabs/WinFormsLibraryVolkov/CustomTreeCell.cs rename to VolkovLabs/WinFormsLibraryVolkov/VisualComponents/CustomTreeCell.cs index 42a4695..13515a9 100644 --- a/VolkovLabs/WinFormsLibraryVolkov/CustomTreeCell.cs +++ b/VolkovLabs/WinFormsLibraryVolkov/VisualComponents/CustomTreeCell.cs @@ -8,6 +8,7 @@ using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using WinFormsLibraryVolkov.VisualComponents; namespace WinFormsLibraryVolkov { @@ -40,7 +41,7 @@ namespace WinFormsLibraryVolkov if (Levels == null) throw new ArgumentException("Levels равен null"); if (element == null) throw new ArgumentException("element равен null"); if (columnIndex < 0) throw new ArgumentException("индекс колонки < 0"); - if (columnIndex >= Levels.NodeNames.Count) throw new ArgumentException("Индекс колонки > чем общее кол-во"); + if (columnIndex > Levels.NodeNames.Count) throw new ArgumentException("Индекс колонки > чем общее кол-во"); TreeNodeCollection treeNodeCollection = treeView.Nodes; int num = 0; diff --git a/VolkovLabs/WinFormsLibraryVolkov/CustomTreeCell.resx b/VolkovLabs/WinFormsLibraryVolkov/VisualComponents/CustomTreeCell.resx similarity index 100% rename from VolkovLabs/WinFormsLibraryVolkov/CustomTreeCell.resx rename to VolkovLabs/WinFormsLibraryVolkov/VisualComponents/CustomTreeCell.resx diff --git a/VolkovLabs/WinFormsLibraryVolkov/WinFormsLibraryVolkov.csproj b/VolkovLabs/WinFormsLibraryVolkov/WinFormsLibraryVolkov.csproj index 060aa1c..4a91ed0 100644 --- a/VolkovLabs/WinFormsLibraryVolkov/WinFormsLibraryVolkov.csproj +++ b/VolkovLabs/WinFormsLibraryVolkov/WinFormsLibraryVolkov.csproj @@ -7,4 +7,25 @@ enable + + + tlbimp + 9 + 1 + 00020813-0000-0000-c000-000000000046 + 0 + false + true + + + tlbimp + 8 + 2 + 2df8d04c-5bfa-101b-bde5-00aa0044de52 + 0 + false + true + + + diff --git a/VolkovLabs/WinFormsTestApp/Department.cs b/VolkovLabs/WinFormsTestApp/Department.cs new file mode 100644 index 0000000..bc81937 --- /dev/null +++ b/VolkovLabs/WinFormsTestApp/Department.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WinFormsTestApp +{ + public class Department + { + public string name; + public int sells; + + public Department(string name, int sells) + { + this.name = name; + this.sells = sells; + } + } +} diff --git a/VolkovLabs/WinFormsTestApp/FormMain.Designer.cs b/VolkovLabs/WinFormsTestApp/FormMain.Designer.cs index 9b50949..ab993e5 100644 --- a/VolkovLabs/WinFormsTestApp/FormMain.Designer.cs +++ b/VolkovLabs/WinFormsTestApp/FormMain.Designer.cs @@ -30,18 +30,20 @@ namespace WinFormsTestApp /// private void InitializeComponent() { - customInputRangeDate = new WinFormsLibraryVolkov.CustomInputRangeDate(); + components = new System.ComponentModel.Container(); buttonCheck = new Button(); labelCheckValue = new Label(); groupBoxInput = new GroupBox(); + customInputRangeDate = new CustomInputRangeDate(); groupBoxSelected = new GroupBox(); + customSelectedCheckedListBox = new CustomSelectedCheckedListBox(); buttonGetSelected = new Button(); labelSelectedValue = new Label(); buttonClear = new Button(); buttonAdd = new Button(); textBoxAdd = new TextBox(); - customSelectedCheckedListBox = new WinFormsLibraryVolkov.CustomSelectedCheckedListBox(); groupBoxData = new GroupBox(); + customTreeCell = new CustomTreeCell(); labelTransportType = new Label(); labelModel = new Label(); labelRegNum = new Label(); @@ -50,29 +52,24 @@ namespace WinFormsTestApp comboBoxTransportType = new ComboBox(); textBoxModel = new TextBox(); textBoxRegNumber = new TextBox(); - customTreeCell = new WinFormsLibraryVolkov.CustomTreeCell(); tabControl = new TabControl(); Visual = new TabPage(); + NonVisual = new TabPage(); + buttonExcelDiagram = new Button(); + buttonExcelImages = new Button(); + buttonExcelTables = new Button(); + excelTableComponent = new WinFormsLibraryVolkov.NonVisualComponents.ExcelTableComponent(components); + excelImagesComponent = new WinFormsLibraryVolkov.NonVisualComponents.ExcelImagesComponent(components); + excelDiagramComponent = new WinFormsLibraryVolkov.NonVisualComponents.ExcelDiagramComponent(components); + openFileDialog = new OpenFileDialog(); groupBoxInput.SuspendLayout(); groupBoxSelected.SuspendLayout(); groupBoxData.SuspendLayout(); tabControl.SuspendLayout(); Visual.SuspendLayout(); + NonVisual.SuspendLayout(); SuspendLayout(); // - // customInputRangeDate - // - customInputRangeDate.AutoValidate = AutoValidate.Disable; - customInputRangeDate.CausesValidation = false; - customInputRangeDate.Date = new DateTime(2024, 9, 4, 18, 20, 42, 32); - customInputRangeDate.Location = new Point(15, 19); - customInputRangeDate.Margin = new Padding(3, 4, 3, 4); - customInputRangeDate.MaxDate = new DateTime(2024, 12, 31, 0, 0, 0, 0); - customInputRangeDate.MinDate = new DateTime(2004, 1, 11, 0, 0, 0, 0); - customInputRangeDate.Name = "customInputRangeDate"; - customInputRangeDate.Size = new Size(148, 30); - customInputRangeDate.TabIndex = 0; - // // buttonCheck // buttonCheck.Location = new Point(169, 22); @@ -94,9 +91,9 @@ namespace WinFormsTestApp // // groupBoxInput // - groupBoxInput.Controls.Add(customInputRangeDate); groupBoxInput.Controls.Add(labelCheckValue); groupBoxInput.Controls.Add(buttonCheck); + groupBoxInput.Controls.Add(customInputRangeDate); groupBoxInput.Location = new Point(6, 6); groupBoxInput.Name = "groupBoxInput"; groupBoxInput.Size = new Size(311, 190); @@ -104,14 +101,23 @@ namespace WinFormsTestApp groupBoxInput.TabStop = false; groupBoxInput.Text = "Input"; // + // customInputRangeDate + // + customInputRangeDate.Location = new Point(15, 22); + customInputRangeDate.MaxDate = new DateTime(0L); + customInputRangeDate.MinDate = new DateTime(0L); + customInputRangeDate.Name = "customInputRangeDate"; + customInputRangeDate.Size = new Size(148, 231); + customInputRangeDate.TabIndex = 3; + // // groupBoxSelected // + groupBoxSelected.Controls.Add(customSelectedCheckedListBox); groupBoxSelected.Controls.Add(buttonGetSelected); groupBoxSelected.Controls.Add(labelSelectedValue); groupBoxSelected.Controls.Add(buttonClear); groupBoxSelected.Controls.Add(buttonAdd); groupBoxSelected.Controls.Add(textBoxAdd); - groupBoxSelected.Controls.Add(customSelectedCheckedListBox); groupBoxSelected.Location = new Point(324, 6); groupBoxSelected.Name = "groupBoxSelected"; groupBoxSelected.Size = new Size(311, 190); @@ -119,6 +125,14 @@ namespace WinFormsTestApp groupBoxSelected.TabStop = false; groupBoxSelected.Text = "Selected"; // + // customSelectedCheckedListBox + // + customSelectedCheckedListBox.Location = new Point(6, 22); + customSelectedCheckedListBox.Name = "customSelectedCheckedListBox"; + customSelectedCheckedListBox.SelectedElement = ""; + customSelectedCheckedListBox.Size = new Size(150, 150); + customSelectedCheckedListBox.TabIndex = 15; + // // buttonGetSelected // buttonGetSelected.Location = new Point(174, 139); @@ -165,17 +179,9 @@ namespace WinFormsTestApp textBoxAdd.Size = new Size(140, 23); textBoxAdd.TabIndex = 11; // - // customSelectedCheckedListBox - // - customSelectedCheckedListBox.Location = new Point(6, 19); - customSelectedCheckedListBox.Margin = new Padding(3, 4, 3, 4); - customSelectedCheckedListBox.Name = "customSelectedCheckedListBox"; - customSelectedCheckedListBox.SelectedElement = ""; - customSelectedCheckedListBox.Size = new Size(150, 157); - customSelectedCheckedListBox.TabIndex = 0; - // // groupBoxData // + groupBoxData.Controls.Add(customTreeCell); groupBoxData.Controls.Add(labelTransportType); groupBoxData.Controls.Add(labelModel); groupBoxData.Controls.Add(labelRegNum); @@ -184,7 +190,6 @@ namespace WinFormsTestApp groupBoxData.Controls.Add(comboBoxTransportType); groupBoxData.Controls.Add(textBoxModel); groupBoxData.Controls.Add(textBoxRegNumber); - groupBoxData.Controls.Add(customTreeCell); groupBoxData.Location = new Point(6, 202); groupBoxData.Name = "groupBoxData"; groupBoxData.Size = new Size(629, 230); @@ -192,6 +197,13 @@ namespace WinFormsTestApp groupBoxData.TabStop = false; groupBoxData.Text = "Data"; // + // customTreeCell + // + customTreeCell.Location = new Point(0, 23); + customTreeCell.Name = "customTreeCell"; + customTreeCell.Size = new Size(413, 195); + customTreeCell.TabIndex = 9; + // // labelTransportType // labelTransportType.AutoSize = true; @@ -261,17 +273,10 @@ namespace WinFormsTestApp textBoxRegNumber.Size = new Size(188, 23); textBoxRegNumber.TabIndex = 1; // - // customTreeCell - // - customTreeCell.Location = new Point(15, 22); - customTreeCell.Margin = new Padding(3, 4, 3, 4); - customTreeCell.Name = "customTreeCell"; - customTreeCell.Size = new Size(398, 202); - customTreeCell.TabIndex = 0; - // // tabControl // tabControl.Controls.Add(Visual); + tabControl.Controls.Add(NonVisual); tabControl.Location = new Point(12, 12); tabControl.Name = "tabControl"; tabControl.SelectedIndex = 0; @@ -291,6 +296,52 @@ namespace WinFormsTestApp Visual.Text = "Visual"; Visual.UseVisualStyleBackColor = true; // + // NonVisual + // + NonVisual.Controls.Add(buttonExcelDiagram); + NonVisual.Controls.Add(buttonExcelImages); + NonVisual.Controls.Add(buttonExcelTables); + NonVisual.Location = new Point(4, 24); + NonVisual.Name = "NonVisual"; + NonVisual.Size = new Size(645, 438); + NonVisual.TabIndex = 1; + NonVisual.Text = "NonVisual"; + NonVisual.UseVisualStyleBackColor = true; + // + // buttonExcelDiagram + // + buttonExcelDiagram.Location = new Point(446, 126); + buttonExcelDiagram.Name = "buttonExcelDiagram"; + buttonExcelDiagram.Size = new Size(177, 148); + buttonExcelDiagram.TabIndex = 2; + buttonExcelDiagram.Text = "Excel (диаграмма)"; + buttonExcelDiagram.UseVisualStyleBackColor = true; + buttonExcelDiagram.Click += buttonExcelDiagram_Click; + // + // buttonExcelImages + // + buttonExcelImages.Location = new Point(38, 126); + buttonExcelImages.Name = "buttonExcelImages"; + buttonExcelImages.Size = new Size(177, 148); + buttonExcelImages.TabIndex = 1; + buttonExcelImages.Text = "Excel (картинки)"; + buttonExcelImages.UseVisualStyleBackColor = true; + buttonExcelImages.Click += buttonExcelImages_Click; + // + // buttonExcelTables + // + buttonExcelTables.Location = new Point(242, 126); + buttonExcelTables.Name = "buttonExcelTables"; + buttonExcelTables.Size = new Size(177, 148); + buttonExcelTables.TabIndex = 0; + buttonExcelTables.Text = "Excel (таблица)"; + buttonExcelTables.UseVisualStyleBackColor = true; + buttonExcelTables.Click += buttonExcelTables_Click; + // + // openFileDialog + // + openFileDialog.FileName = "openFileDialog1"; + // // FormMain // AutoScaleDimensions = new SizeF(7F, 15F); @@ -307,12 +358,12 @@ namespace WinFormsTestApp groupBoxData.PerformLayout(); tabControl.ResumeLayout(false); Visual.ResumeLayout(false); + NonVisual.ResumeLayout(false); ResumeLayout(false); } #endregion - private WinFormsLibraryVolkov.CustomInputRangeDate customInputRangeDate; private Button buttonCheck; private Label labelCheckValue; private GroupBox groupBoxInput; @@ -322,9 +373,7 @@ namespace WinFormsTestApp private Button buttonClear; private Button buttonAdd; private TextBox textBoxAdd; - private WinFormsLibraryVolkov.CustomSelectedCheckedListBox customSelectedCheckedListBox; private GroupBox groupBoxData; - private WinFormsLibraryVolkov.CustomTreeCell customTreeCell; private Button buttonGetFromTree; private Button buttonAddToTree; private ComboBox comboBoxTransportType; @@ -335,5 +384,16 @@ namespace WinFormsTestApp private Label labelRegNum; private TabControl tabControl; private TabPage Visual; + private TabPage NonVisual; + private Button buttonExcelDiagram; + private Button buttonExcelImages; + private Button buttonExcelTables; + private WinFormsLibraryVolkov.NonVisualComponents.ExcelTableComponent excelTableComponent; + private WinFormsLibraryVolkov.NonVisualComponents.ExcelImagesComponent excelImagesComponent; + private WinFormsLibraryVolkov.NonVisualComponents.ExcelDiagramComponent excelDiagramComponent; + private OpenFileDialog openFileDialog; + private CustomInputRangeDate customInputRangeDate; + private CustomSelectedCheckedListBox customSelectedCheckedListBox; + private CustomTreeCell customTreeCell; } } \ No newline at end of file diff --git a/VolkovLabs/WinFormsTestApp/FormMain.cs b/VolkovLabs/WinFormsTestApp/FormMain.cs index 556dcfd..dec13bf 100644 --- a/VolkovLabs/WinFormsTestApp/FormMain.cs +++ b/VolkovLabs/WinFormsTestApp/FormMain.cs @@ -1,13 +1,16 @@ -using WinFormsLibraryVolkov; -using System; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using WinFormsLibraryVolkov.VisualComponents; +using WinFormsLibraryVolkov.NonVisualComponents; +using WinFormsLibraryVolkov.Exceptions; namespace WinFormsTestApp { @@ -97,7 +100,7 @@ namespace WinFormsTestApp if (textBoxRegNumber.Text == null || textBoxModel.Text == null || comboBoxTransportType.SelectedItem == null) { return; - } + } customTreeCell.AddCell(2, new(textBoxRegNumber.Text, comboBoxTransportType.SelectedItem.ToString(), textBoxModel.Text)); customTreeCell.Update(); } @@ -114,5 +117,51 @@ namespace WinFormsTestApp comboBoxTransportType.SelectedItem = tp.TransportType; } + private void buttonExcelDiagram_Click(object sender, EventArgs e) + { + List departments = new List(); + + departments.Add(new Department("Dep 1", 330)); + departments.Add(new Department("Dep 2", 500)); + departments.Add(new Department("Dep 3", 170)); + string path = AppDomain.CurrentDomain.BaseDirectory + "DiagramTesting.xlsx"; + if (excelDiagramComponent.createWithDiagram(path, "DiagramTest", "Продажи", DiagramLegendEnum.TopRight, departments, "name", "sells")) MessageBox.Show("Успех"); + else MessageBox.Show("Fail :("); + } + + private void buttonExcelTables_Click(object sender, EventArgs e) + { + List workers = new List(); + + workers.Add(new OfficeWorker(1, "Иванов", "Иван", 20, "Отдел продаж", "Бухгалтер", 25, "+7(834)234-03-49")); + workers.Add(new OfficeWorker(1, "Петров", "Петр", 25, "Отдел продаж", "Менеджер", 20, "+7(834)123-03-49")); + workers.Add(new OfficeWorker(1, "Сидоров", "Сергей", 27, "Отдел кадров", "HR", 2, "+7(834)593-03-49", true)); + string path = AppDomain.CurrentDomain.BaseDirectory + "ExcelTableTesting.xlsx"; + List<(int, int)> merges = new List<(int, int)>(); + merges.Add((1, 3)); + merges.Add((4, 6)); + List heights = Enumerable.Repeat(20, 9).ToList(); + + List<(string, string)> headers = new List<(string, string)> { ("id", "id"), ("", "Личные данные"), + ("lastName", "Фамилия"), ("firstName", "Имя"), + ("age", "Возраст"), ("", "Работа"), + ("department", "Отдел"), ("position", "Должность"), + ("boxNumber", "Номер бокса"), ("phoneNumber", "Телефон"), + ("isInVacation", "В отпуске"), }; + + if (excelTableComponent.createWithTable(path, "ExcelTable", merges, heights, headers, workers)) MessageBox.Show("Успех"); + } + + private void buttonExcelImages_Click(object sender, EventArgs e) + { + var res = openFileDialog.ShowDialog(this); + if (res != DialogResult.OK) return; + var files = openFileDialog.FileNames; + openFileDialog.Dispose(); + List images = new List(); + string path = AppDomain.CurrentDomain.BaseDirectory + "ImageTesting.xlsx"; + if (excelImagesComponent.createWithImages(new ExcelImageInfo(path, "Header", files))) MessageBox.Show("Успех!"); + else MessageBox.Show("Ошибка, проверьте консоль"); + } } } diff --git a/VolkovLabs/WinFormsTestApp/FormMain.resx b/VolkovLabs/WinFormsTestApp/FormMain.resx index af32865..e510dba 100644 --- a/VolkovLabs/WinFormsTestApp/FormMain.resx +++ b/VolkovLabs/WinFormsTestApp/FormMain.resx @@ -117,4 +117,16 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + + + 195, 17 + + + 384, 17 + + + 574, 17 + \ No newline at end of file diff --git a/VolkovLabs/WinFormsTestApp/OfficeWorker.cs b/VolkovLabs/WinFormsTestApp/OfficeWorker.cs new file mode 100644 index 0000000..8645b8c --- /dev/null +++ b/VolkovLabs/WinFormsTestApp/OfficeWorker.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WinFormsTestApp +{ + public class OfficeWorker + { + public OfficeWorker(int id, string lastName, string firstName, int age, string department, string position, int boxNumber, string phoneNumber, bool isInVacation = false) + { + this.id = id; + this.lastName = lastName; + this.firstName = firstName; + this.age = age; + this.department = department; + this.position = position; + this.boxNumber = boxNumber; + this.phoneNumber = phoneNumber; + this.isInVacation = isInVacation; + } + + public int id; + public string lastName; + public string firstName; + public int age; + public string department; + public string position; + public int boxNumber; + public string phoneNumber; + public bool isInVacation; + } +}