From 098e5a1d3c2d518f0f17838f210a5dfc23c5e4af Mon Sep 17 00:00:00 2001 From: bekodeg Date: Fri, 25 Oct 2024 22:29:47 +0400 Subject: [PATCH 01/20] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=202?= =?UTF-8?q?=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=BE=D0=BD=D0=B5=D0=BD=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .editorconfig | 304 ++++++++++++++++++ .../CustomPdfTableWithGrouping.Designer.cs | 36 +++ .../Components/CustomPdfTableWithGrouping.cs | 73 +++++ .../Cop.Borovkov.Var3/Models/ColumnInfo.cs | 9 + .../Models/PdfTableWithGroupingInfo.cs | 33 ++ .../Cop.Borovkov.Var3/Models/RowInfo.cs | 19 ++ .../Models/TableModels/PdfTable.cs | 7 +- .../PIHelperSh.PdfCreater/PdfCreator.cs | 8 +- .../Forms/Form2.Designer.cs | 25 +- .../TestCustomComponents/Forms/Form2.cs | 77 ++++- .../TestCustomComponents/Forms/Form2.resx | 7 +- .../TestCustomComponents/Models/TestModel.cs | 2 + 12 files changed, 588 insertions(+), 12 deletions(-) create mode 100644 .editorconfig create mode 100644 Cop.Borovkov.Var3/Cop.Borovkov.Var3/Components/CustomPdfTableWithGrouping.Designer.cs create mode 100644 Cop.Borovkov.Var3/Cop.Borovkov.Var3/Components/CustomPdfTableWithGrouping.cs create mode 100644 Cop.Borovkov.Var3/Cop.Borovkov.Var3/Models/ColumnInfo.cs create mode 100644 Cop.Borovkov.Var3/Cop.Borovkov.Var3/Models/PdfTableWithGroupingInfo.cs create mode 100644 Cop.Borovkov.Var3/Cop.Borovkov.Var3/Models/RowInfo.cs diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..5140c11 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,304 @@ +# Удалите строку ниже, если вы хотите наследовать параметры .editorconfig из каталогов, расположенных выше в иерархии +root = true + +# Файлы C# +[*.cs] + +#### Основные параметры EditorConfig #### + +# Отступы и интервалы +indent_size = 4 +indent_style = space +tab_width = 4 + +# Предпочтения для новых строк +end_of_line = crlf +insert_final_newline = false + +#### Рекомендации по написанию кода .NET #### + +# Упорядочение Using +dotnet_separate_import_directive_groups = false +dotnet_sort_system_directives_first = false +file_header_template = unset + +# Предпочтения для this. и Me. +dotnet_style_qualification_for_event = false:suggestion +dotnet_style_qualification_for_field = false +dotnet_style_qualification_for_method = false:suggestion +dotnet_style_qualification_for_property = false:suggestion + +# Параметры использования ключевых слов языка и типов BCL +dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion +dotnet_style_predefined_type_for_member_access = true:suggestion + +# Предпочтения для скобок +dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:suggestion +dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:suggestion +dotnet_style_parentheses_in_other_operators = never_if_unnecessary:suggestion +dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:suggestion + +# Предпочтения модификатора +dotnet_style_require_accessibility_modifiers = for_non_interface_members + +# Выражения уровень предпочтения +dotnet_style_coalesce_expression = true +dotnet_style_collection_initializer = true:warning +dotnet_style_explicit_tuple_names = true:warning +dotnet_style_namespace_match_folder = true +dotnet_style_null_propagation = true +dotnet_style_object_initializer = true:warning +dotnet_style_operator_placement_when_wrapping = beginning_of_line +dotnet_style_prefer_auto_properties = true:warning +dotnet_style_prefer_collection_expression = when_types_loosely_match +dotnet_style_prefer_compound_assignment = true:warning +dotnet_style_prefer_conditional_expression_over_assignment = true:suggestion +dotnet_style_prefer_conditional_expression_over_return = true:suggestion +dotnet_style_prefer_foreach_explicit_cast_in_source = when_strongly_typed +dotnet_style_prefer_inferred_anonymous_type_member_names = true:warning +dotnet_style_prefer_inferred_tuple_names = true:warning +dotnet_style_prefer_is_null_check_over_reference_equality_method = true +dotnet_style_prefer_simplified_boolean_expressions = true:warning +dotnet_style_prefer_simplified_interpolation = true + +# Предпочтения для полей +dotnet_style_readonly_field = true + +# Настройки параметров +dotnet_code_quality_unused_parameters = all + +# Параметры подавления +dotnet_remove_unnecessary_suppression_exclusions = none + +# Предпочтения для новых строк +dotnet_style_allow_multiple_blank_lines_experimental = false:warning +dotnet_style_allow_statement_immediately_after_block_experimental = false:suggestion + +#### Рекомендации по написанию кода C# #### + +# Предпочтения var +csharp_style_var_elsewhere = false:suggestion +csharp_style_var_for_built_in_types = false:suggestion +csharp_style_var_when_type_is_apparent = true:suggestion + +# Члены, заданные выражениями +csharp_style_expression_bodied_accessors = true:warning +csharp_style_expression_bodied_constructors = false:suggestion +csharp_style_expression_bodied_indexers = true:warning +csharp_style_expression_bodied_lambdas = true:warning +csharp_style_expression_bodied_local_functions = false +csharp_style_expression_bodied_methods = true:suggestion +csharp_style_expression_bodied_operators = true:suggestion +csharp_style_expression_bodied_properties = true:warning + +# Настройки соответствия шаблонов +csharp_style_pattern_matching_over_as_with_null_check = true +csharp_style_pattern_matching_over_is_with_cast_check = true +csharp_style_prefer_extended_property_pattern = true +csharp_style_prefer_not_pattern = true +csharp_style_prefer_pattern_matching = true:suggestion +csharp_style_prefer_switch_expression = true:warning + +# Настройки проверки на null +csharp_style_conditional_delegate_call = true + +# Предпочтения модификатора +csharp_prefer_static_local_function = true +csharp_preferred_modifier_order = public,private,protected,internal,file,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,required,volatile,async +csharp_style_prefer_readonly_struct = true +csharp_style_prefer_readonly_struct_member = true + +# Предпочтения для блоков кода +csharp_prefer_braces = true:suggestion +csharp_prefer_simple_using_statement = true +csharp_style_namespace_declarations = block_scoped:warning +csharp_style_prefer_method_group_conversion = true:warning +csharp_style_prefer_primary_constructors = true +csharp_style_prefer_top_level_statements = true:warning + +# Выражения уровень предпочтения +csharp_prefer_simple_default_expression = true:warning +csharp_style_deconstructed_variable_declaration = true +csharp_style_implicit_object_creation_when_type_is_apparent = true:warning +csharp_style_inlined_variable_declaration = true +csharp_style_prefer_index_operator = true:warning +csharp_style_prefer_local_over_anonymous_function = true +csharp_style_prefer_null_check_over_type_check = true +csharp_style_prefer_range_operator = true:warning +csharp_style_prefer_tuple_swap = true:warning +csharp_style_prefer_utf8_string_literals = true +csharp_style_throw_expression = true +csharp_style_unused_value_assignment_preference = discard_variable:warning +csharp_style_unused_value_expression_statement_preference = discard_variable:suggestion + +# предпочтения для директивы using +csharp_using_directive_placement = outside_namespace:warning + +# Предпочтения для новых строк +csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = false:warning +csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = false:warning +csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = false:warning +csharp_style_allow_blank_lines_between_consecutive_braces_experimental = false:warning +csharp_style_allow_embedded_statements_on_same_line_experimental = true:warning + +#### Правила форматирования C# #### + +# Предпочтения для новых строк +csharp_new_line_before_catch = true +csharp_new_line_before_else = true +csharp_new_line_before_finally = true +csharp_new_line_before_members_in_anonymous_types = true +csharp_new_line_before_members_in_object_initializers = true +csharp_new_line_before_open_brace = all +csharp_new_line_between_query_expression_clauses = true + +# Предпочтения для отступов +csharp_indent_block_contents = true +csharp_indent_braces = false +csharp_indent_case_contents = true +csharp_indent_case_contents_when_block = true +csharp_indent_labels = one_less_than_current +csharp_indent_switch_labels = true + +# Предпочтения для интервалов +csharp_space_after_cast = false +csharp_space_after_colon_in_inheritance_clause = true +csharp_space_after_comma = true +csharp_space_after_dot = false +csharp_space_after_keywords_in_control_flow_statements = true +csharp_space_after_semicolon_in_for_statement = true +csharp_space_around_binary_operators = before_and_after +csharp_space_around_declaration_statements = false +csharp_space_before_colon_in_inheritance_clause = true +csharp_space_before_comma = false +csharp_space_before_dot = false +csharp_space_before_open_square_brackets = false +csharp_space_before_semicolon_in_for_statement = false +csharp_space_between_empty_square_brackets = false +csharp_space_between_method_call_empty_parameter_list_parentheses = false +csharp_space_between_method_call_name_and_opening_parenthesis = false +csharp_space_between_method_call_parameter_list_parentheses = false +csharp_space_between_method_declaration_empty_parameter_list_parentheses = false +csharp_space_between_method_declaration_name_and_open_parenthesis = false +csharp_space_between_method_declaration_parameter_list_parentheses = false +csharp_space_between_parentheses = false +csharp_space_between_square_brackets = false + +# Предпочтения переноса +csharp_preserve_single_line_blocks = true +csharp_preserve_single_line_statements = true + +#### Стили именования #### + +# Правила именования + +dotnet_naming_rule.asyncmethods_should_be_pascalcaseasync.severity = warning +dotnet_naming_rule.asyncmethods_should_be_pascalcaseasync.symbols = asyncmethods +dotnet_naming_rule.asyncmethods_should_be_pascalcaseasync.style = pascalcaseasync + +dotnet_naming_rule.staticasyncmethods_should_be_pascalcaseasync.severity = warning +dotnet_naming_rule.staticasyncmethods_should_be_pascalcaseasync.symbols = staticasyncmethods +dotnet_naming_rule.staticasyncmethods_should_be_pascalcaseasync.style = pascalcaseasync + +dotnet_naming_rule.constmember_should_be_constant_case.severity = warning +dotnet_naming_rule.constmember_should_be_constant_case.symbols = constmember +dotnet_naming_rule.constmember_should_be_constant_case.style = constant_case + +dotnet_naming_rule.genericparametrs_should_be_typepascalcase.severity = warning +dotnet_naming_rule.genericparametrs_should_be_typepascalcase.symbols = genericparametrs +dotnet_naming_rule.genericparametrs_should_be_typepascalcase.style = typepascalcase + +dotnet_naming_rule.localmembers_should_be_camelcase.severity = warning +dotnet_naming_rule.localmembers_should_be_camelcase.symbols = localmembers +dotnet_naming_rule.localmembers_should_be_camelcase.style = camelcase + +dotnet_naming_rule.privatfealds_should_be__privatcamalcase.severity = warning +dotnet_naming_rule.privatfealds_should_be__privatcamalcase.symbols = privatfealds +dotnet_naming_rule.privatfealds_should_be__privatcamalcase.style = _privatcamalcase + +dotnet_naming_rule.interface_should_be_begins_with_i.severity = warning +dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface +dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i + +dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = warning +dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members +dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case + +dotnet_naming_rule.types_should_be_pascal_case.severity = warning +dotnet_naming_rule.types_should_be_pascal_case.symbols = types +dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case + +# Спецификации символов + +dotnet_naming_symbols.interface.applicable_kinds = interface +dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.interface.required_modifiers = + +dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum +dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.types.required_modifiers = + +dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method +dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.non_field_members.required_modifiers = + +dotnet_naming_symbols.asyncmethods.applicable_kinds = method +dotnet_naming_symbols.asyncmethods.applicable_accessibilities = * +dotnet_naming_symbols.asyncmethods.required_modifiers = async + +dotnet_naming_symbols.staticasyncmethods.applicable_kinds = method, local_function +dotnet_naming_symbols.staticasyncmethods.applicable_accessibilities = * +dotnet_naming_symbols.staticasyncmethods.required_modifiers = async, static + +dotnet_naming_symbols.constmember.applicable_kinds = property, field +dotnet_naming_symbols.constmember.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.constmember.required_modifiers = const + +dotnet_naming_symbols.localmembers.applicable_kinds = property, field, parameter, local, method +dotnet_naming_symbols.localmembers.applicable_accessibilities = local +dotnet_naming_symbols.localmembers.required_modifiers = + +dotnet_naming_symbols.privatfealds.applicable_kinds = property, field +dotnet_naming_symbols.privatfealds.applicable_accessibilities = private +dotnet_naming_symbols.privatfealds.required_modifiers = + +dotnet_naming_symbols.genericparametrs.applicable_kinds = type_parameter +dotnet_naming_symbols.genericparametrs.applicable_accessibilities = * +dotnet_naming_symbols.genericparametrs.required_modifiers = + +# Стили именования + +dotnet_naming_style.pascal_case.required_prefix = +dotnet_naming_style.pascal_case.required_suffix = +dotnet_naming_style.pascal_case.word_separator = +dotnet_naming_style.pascal_case.capitalization = pascal_case + +dotnet_naming_style.begins_with_i.required_prefix = I +dotnet_naming_style.begins_with_i.required_suffix = +dotnet_naming_style.begins_with_i.word_separator = +dotnet_naming_style.begins_with_i.capitalization = pascal_case + +dotnet_naming_style.camelcase.required_prefix = +dotnet_naming_style.camelcase.required_suffix = +dotnet_naming_style.camelcase.word_separator = +dotnet_naming_style.camelcase.capitalization = camel_case + +dotnet_naming_style.constant_case.required_prefix = +dotnet_naming_style.constant_case.required_suffix = +dotnet_naming_style.constant_case.word_separator = _ +dotnet_naming_style.constant_case.capitalization = all_upper + +dotnet_naming_style._privatcamalcase.required_prefix = _ +dotnet_naming_style._privatcamalcase.required_suffix = +dotnet_naming_style._privatcamalcase.word_separator = +dotnet_naming_style._privatcamalcase.capitalization = camel_case + +dotnet_naming_style.pascalcaseasync.required_prefix = +dotnet_naming_style.pascalcaseasync.required_suffix = Async +dotnet_naming_style.pascalcaseasync.word_separator = +dotnet_naming_style.pascalcaseasync.capitalization = pascal_case + +dotnet_naming_style.typepascalcase.required_prefix = T +dotnet_naming_style.typepascalcase.required_suffix = +dotnet_naming_style.typepascalcase.word_separator = +dotnet_naming_style.typepascalcase.capitalization = pascal_case diff --git a/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Components/CustomPdfTableWithGrouping.Designer.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Components/CustomPdfTableWithGrouping.Designer.cs new file mode 100644 index 0000000..8f614a5 --- /dev/null +++ b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Components/CustomPdfTableWithGrouping.Designer.cs @@ -0,0 +1,36 @@ +namespace Cop.Borovkov.Var3.Components +{ + partial class CustomPdfTableWithGrouping + { + /// + /// Обязательная переменная конструктора. + /// + 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/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Components/CustomPdfTableWithGrouping.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Components/CustomPdfTableWithGrouping.cs new file mode 100644 index 0000000..e187fbc --- /dev/null +++ b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Components/CustomPdfTableWithGrouping.cs @@ -0,0 +1,73 @@ +using Cop.Borovkov.Var3.Models; +using PIHelperSh.PdfCreator.Models.TableModels; +using PIHelperSh.PdfCreator; +using System.ComponentModel; +using PIHelperSh.PdfCreator.Enums; +using PIHelperSh.PdfCreator.Interfaces; + +namespace Cop.Borovkov.Var3.Components +{ + /// + /// Компонент создающий таблицу и группирует элементы по 1 столбцу + /// + public partial class CustomPdfTableWithGrouping : Component + { + /// + /// + public CustomPdfTableWithGrouping() + { + InitializeComponent(); + } + + /// + /// + /// + public CustomPdfTableWithGrouping(IContainer container) + { + container.Add(this); + InitializeComponent(); + } + + /// + /// Сохранить набор таблиц в пдф + /// + /// + /// + /// + public void SaveToPdf(PdfTableWithGroupingInfo tableInfo) where TType : class + { + if (!tableInfo.Columns.Any() || !tableInfo.Rows.Any()) + { + return; + } + + PdfCreator creator = new PdfCreator(); + + creator.AddParagraph(new() + { + Style = PdfStyleType.Title, + Text = tableInfo.Title, + MarginAfter = PdfMargin.Smal, + }); + + creator.AddTable(new PdfTable() + { + Header = tableInfo.Columns.Select(c => new PdfTableColumn() + { + Title = c.Header, + Size = c.Width, + PropertyName = c.PropertyName, + } as IPdfColumnItem).ToList(), + + Records = tableInfo.Rows + .OrderBy(r => typeof(TType) + .GetProperty(tableInfo.Columns.First().PropertyName)!.GetValue(r.Value)) + .Select(r => (r.Value, r.Height)) + .ToList(), + HeaderHeaight = tableInfo.HeaderHeight, + }); + + creator.SavePdf(tableInfo.FilePath); + } + } +} diff --git a/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Models/ColumnInfo.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Models/ColumnInfo.cs new file mode 100644 index 0000000..ea874e1 --- /dev/null +++ b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Models/ColumnInfo.cs @@ -0,0 +1,9 @@ +namespace Cop.Borovkov.Var3.Models +{ + public record ColumnInfo + { + public string Header { get; init; } = null!; + public string PropertyName { get; init; } = null!; + public float Width { get; init; } = 3; + } +} diff --git a/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Models/PdfTableWithGroupingInfo.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Models/PdfTableWithGroupingInfo.cs new file mode 100644 index 0000000..f920b4e --- /dev/null +++ b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Models/PdfTableWithGroupingInfo.cs @@ -0,0 +1,33 @@ +namespace Cop.Borovkov.Var3.Models +{ + /// + /// Параметры для создания таблици в пдф с группировкой по 1 столбцу + /// + public class PdfTableWithGroupingInfo where TType : class + { + /// + /// имя файла (включая путь до файла) + /// + public string FilePath { get; init; } = @"C:\pdfTable.pdf"; + + /// + /// название документа(заголовок в документе) + /// + public string Title { get; init; } = "Таблица"; + + /// + /// Высота заголовков + /// + public float HeaderHeight { get; init; } = 0.5f; + + /// + /// Параметры столбцов + /// + public IEnumerable Columns { get; init; } = []; + + /// + /// Список таблиц + /// + public IEnumerable> Rows { get; init; } = []; + } +} diff --git a/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Models/RowInfo.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Models/RowInfo.cs new file mode 100644 index 0000000..1693002 --- /dev/null +++ b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Models/RowInfo.cs @@ -0,0 +1,19 @@ +namespace Cop.Borovkov.Var3.Models +{ + /// + /// Информация о строке + /// + /// + public record RowInfo where T : class + { + /// + /// Высота строки + /// + public float Height { get; set; } = 0.5f; + + /// + /// Значение строки + /// + public T Value { get; set; } = null!; + } +} diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/TableModels/PdfTable.cs b/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/TableModels/PdfTable.cs index 81b483b..8941931 100644 --- a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/TableModels/PdfTable.cs +++ b/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/TableModels/PdfTable.cs @@ -27,7 +27,7 @@ namespace PIHelperSh.PdfCreator.Models.TableModels /// /// Список объектов, информация о которых будет в таблице. /// - public List Records { get; set; } = new(); + public List<(T value, float height)> Records { get; set; } = new(); /// /// Стиль объектов в таблице (по умолчанию - базовый) @@ -38,5 +38,10 @@ namespace PIHelperSh.PdfCreator.Models.TableModels /// Выравнивание текста объектов в таблице (по умолчанию - по левой строне) /// public PdfAlignmentType RecordHorizontalAlignment { get; set; } = PdfAlignmentType.Left; + + /// + /// Высота заголовка + /// + public float HeaderHeaight { get; set; } } } diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/PdfCreator.cs b/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/PdfCreator.cs index ca7eb08..ea5110e 100644 --- a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/PdfCreator.cs +++ b/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/PdfCreator.cs @@ -253,6 +253,9 @@ namespace PIHelperSh.PdfCreator } } + upRow.Height = header.HeaderHeaight; + downRow.Height = header.HeaderHeaight; + return objectFields; } @@ -428,9 +431,12 @@ namespace PIHelperSh.PdfCreator foreach (var item in header.Records) { var row = table.AddRow(); + + row.Height = item.height; + for (int i = 0; i < maper.Count; i++) { - ConfigurateCell(row.Cells[i], maper[i](item)?.ToString()!, header.RecordHorizontalAlignment, header.RecordStyle); + ConfigurateCell(row.Cells[i], maper[i](item.value)?.ToString()!, header.RecordHorizontalAlignment, header.RecordStyle); } } } diff --git a/Cop.Borovkov.Var3/TestCustomComponents/Forms/Form2.Designer.cs b/Cop.Borovkov.Var3/TestCustomComponents/Forms/Form2.Designer.cs index 28464d4..c080162 100644 --- a/Cop.Borovkov.Var3/TestCustomComponents/Forms/Form2.Designer.cs +++ b/Cop.Borovkov.Var3/TestCustomComponents/Forms/Form2.Designer.cs @@ -31,24 +31,39 @@ components = new System.ComponentModel.Container(); customPdfTable1 = new Cop.Borovkov.Var3.Components.CustomPdfTable(components); button1 = new Button(); + button2 = new Button(); + customPdfTableWithGrouping1 = new Cop.Borovkov.Var3.Components.CustomPdfTableWithGrouping(components); SuspendLayout(); // // button1 // - button1.Location = new Point(12, 12); + button1.Location = new Point(14, 16); + button1.Margin = new Padding(3, 4, 3, 4); button1.Name = "button1"; - button1.Size = new Size(75, 23); + button1.Size = new Size(86, 31); button1.TabIndex = 0; button1.Text = "button1"; button1.UseVisualStyleBackColor = true; button1.Click += button1_Click; // + // button2 + // + button2.Location = new Point(106, 16); + button2.Name = "button2"; + button2.Size = new Size(94, 29); + button2.TabIndex = 1; + button2.Text = "button2"; + button2.UseVisualStyleBackColor = true; + button2.Click += button2_Click; + // // Form2 // - AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 450); + ClientSize = new Size(914, 600); + Controls.Add(button2); Controls.Add(button1); + Margin = new Padding(3, 4, 3, 4); Name = "Form2"; Text = "Form2"; ResumeLayout(false); @@ -58,5 +73,7 @@ private Cop.Borovkov.Var3.Components.CustomPdfTable customPdfTable1; private Button button1; + private Button button2; + private Cop.Borovkov.Var3.Components.CustomPdfTableWithGrouping customPdfTableWithGrouping1; } } \ No newline at end of file diff --git a/Cop.Borovkov.Var3/TestCustomComponents/Forms/Form2.cs b/Cop.Borovkov.Var3/TestCustomComponents/Forms/Form2.cs index 9787dc0..0b6b9a4 100644 --- a/Cop.Borovkov.Var3/TestCustomComponents/Forms/Form2.cs +++ b/Cop.Borovkov.Var3/TestCustomComponents/Forms/Form2.cs @@ -1,4 +1,7 @@ -namespace TestCustomComponents.Forms +using Newtonsoft.Json.Serialization; +using TestCustomComponents.Models; + +namespace TestCustomComponents.Forms { public partial class Form2 : Form { @@ -11,9 +14,9 @@ { customPdfTable1.SaveToPdf(new() { - FilePath = @"F:\test\test.pdf", + FilePath = @"E:\test\test.pdf", Title = "Текст заголовка", - Tables = [new[,] + Tables = [new[,] { { "00", "01", "02" }, { "10", "11", "12" }, @@ -23,7 +26,7 @@ customPdfTable1.SaveToPdf(new() { - FilePath = @"F:\test\test.pdf", + FilePath = @"E:\test\test.pdf", Title = "Текст заголовка", Tables = [new[,] { @@ -38,5 +41,71 @@ }], }); } + + private void button2_Click(object sender, EventArgs e) + { + customPdfTableWithGrouping1.SaveToPdf(new() + { + FilePath = @"E:\test\test.pdf", + Title = "Текст заголовка", + Columns = [ + new() { + Header = "1", + PropertyName = nameof(TestModel.Height), + }, + new() { + Header = "2", + PropertyName = nameof(TestModel.Name), + }, + new() { + Header = "3", + PropertyName = nameof(TestModel.Id), + }, + new() { + Header = "4", + PropertyName = nameof(TestModel.Age), + } + ], + Rows = [ + new() { + Value = new TestModel() { + Id = 1, + Name = "Vasya", + Age = 5, + Height = "low", + }, + Height = 100f, + }, + new() { + Value = new TestModel() { + Id = 2, + Name = "Masya", + Age = 8, + Height = "hi", + }, + Height = 100f, + }, + new() { + Value = new TestModel() { + Id = 3, + Name = "Kasya", + Age = 3, + Height = "low", + }, + Height = 10f, + }, + new() { + Value = new TestModel() { + Id = 4, + Name = "Asya", + Age = 100, + Height = "hi", + }, + Height = 50f, + }, + ], + HeaderHeight = 100f, + }); + } } } diff --git a/Cop.Borovkov.Var3/TestCustomComponents/Forms/Form2.resx b/Cop.Borovkov.Var3/TestCustomComponents/Forms/Form2.resx index b5ff85f..f501082 100644 --- a/Cop.Borovkov.Var3/TestCustomComponents/Forms/Form2.resx +++ b/Cop.Borovkov.Var3/TestCustomComponents/Forms/Form2.resx @@ -1,7 +1,7 @@  + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Cop.Borovkov.Var3/Lab3/Lab3.csproj b/Cop.Borovkov.Var3/Lab3/Lab3.csproj new file mode 100644 index 0000000..c1f50c7 --- /dev/null +++ b/Cop.Borovkov.Var3/Lab3/Lab3.csproj @@ -0,0 +1,19 @@ + + + + WinExe + net8.0-windows + enable + true + enable + + + + + + + + + + + \ No newline at end of file diff --git a/Cop.Borovkov.Var3/Lab3/MappingProfiles/StudentViewMappingProfile.cs b/Cop.Borovkov.Var3/Lab3/MappingProfiles/StudentViewMappingProfile.cs new file mode 100644 index 0000000..1df0214 --- /dev/null +++ b/Cop.Borovkov.Var3/Lab3/MappingProfiles/StudentViewMappingProfile.cs @@ -0,0 +1,15 @@ +using AutoMapper; +using Lab3.Database.DTO; +using Lab3.Models; + +namespace Lab3.MappingProfiles +{ + public class StudentViewMappingProfile : Profile + { + public StudentViewMappingProfile() + { + _ = CreateMap()\ + ; + } + } +} diff --git a/Cop.Borovkov.Var3/Lab3/Models/StudentViewModel.cs b/Cop.Borovkov.Var3/Lab3/Models/StudentViewModel.cs new file mode 100644 index 0000000..54e9145 --- /dev/null +++ b/Cop.Borovkov.Var3/Lab3/Models/StudentViewModel.cs @@ -0,0 +1,15 @@ +using Lab3.Database.DTO; +using System.Globalization; + +namespace Lab3.Models +{ + public record StudentViewModel : StudentDTO + { + public string SessionMarks => string.Join("; ", StudentSessions + .Select(s => string.Format( + CultureInfo.InvariantCulture, + "сессия{}: {0:f2}", + s.Number, + s.Score))); + } +} diff --git a/Cop.Borovkov.Var3/Lab3/Program.cs b/Cop.Borovkov.Var3/Lab3/Program.cs new file mode 100644 index 0000000..f7a9a87 --- /dev/null +++ b/Cop.Borovkov.Var3/Lab3/Program.cs @@ -0,0 +1,17 @@ +namespace Lab3 +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + Application.Run(new Form1()); + } + } +} \ No newline at end of file diff --git a/Cop.Borovkov.Var3/Lab3/appsettings.json b/Cop.Borovkov.Var3/Lab3/appsettings.json new file mode 100644 index 0000000..751a2b0 --- /dev/null +++ b/Cop.Borovkov.Var3/Lab3/appsettings.json @@ -0,0 +1,5 @@ +{ + "ConnectionStrings": { + "COPDataBase": "Host=localhost;Username=postgres;Password=postgres;Database=COP" + } +} From d9abe592503d169c1a9edefb6b283424919b11d1 Mon Sep 17 00:00:00 2001 From: bekodeg Date: Wed, 6 Nov 2024 23:06:47 +0400 Subject: [PATCH 05/20] =?UTF-8?q?=D0=A1=D0=B2=D0=B5=D1=80=D1=81=D1=82?= =?UTF-8?q?=D0=B0=D0=BB=20=D0=BF=D0=B5=D1=80=D0=B2=D1=8B=D0=B5=20=D1=84?= =?UTF-8?q?=D0=BE=D1=80=D0=BC=D1=8B,=20=D0=BD=D0=B0=D1=81=D1=82=D1=80?= =?UTF-8?q?=D0=BE=D0=B8=D0=BB=20di?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StartEducationConfiguration.cs | 31 -- .../Lab3.Database/Extensions/DIExtension.cs | 10 + .../Lab3.Database/Lab3.Database.csproj | 4 - .../MappingProfiles/SessionMappingProfile.cs | 2 +- .../Implementations/StudentRepository.cs | 35 +++ .../Lab3/Extensions/DIExtension.cs | 19 ++ .../Lab3/Forms/CreateForm.Designer.cs | 291 ++++++++++++++++++ Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs | 20 ++ Cop.Borovkov.Var3/Lab3/Forms/CreateForm.resx | 120 ++++++++ .../Lab3/Forms/MainForm.Designer.cs | 29 +- Cop.Borovkov.Var3/Lab3/Forms/MainForm.cs | 27 +- Cop.Borovkov.Var3/Lab3/Forms/MainForm.resx | 54 ++-- Cop.Borovkov.Var3/Lab3/Lab3.csproj | 14 + .../StudentViewMappingProfile.cs | 2 +- Cop.Borovkov.Var3/Lab3/Program.cs | 27 +- 15 files changed, 606 insertions(+), 79 deletions(-) delete mode 100644 Cop.Borovkov.Var3/Lab3.Database/Context/Configurations/StartEducationConfiguration.cs create mode 100644 Cop.Borovkov.Var3/Lab3.Database/Repository/Implementations/StudentRepository.cs create mode 100644 Cop.Borovkov.Var3/Lab3/Forms/CreateForm.Designer.cs create mode 100644 Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs create mode 100644 Cop.Borovkov.Var3/Lab3/Forms/CreateForm.resx diff --git a/Cop.Borovkov.Var3/Lab3.Database/Context/Configurations/StartEducationConfiguration.cs b/Cop.Borovkov.Var3/Lab3.Database/Context/Configurations/StartEducationConfiguration.cs deleted file mode 100644 index c3b3f33..0000000 --- a/Cop.Borovkov.Var3/Lab3.Database/Context/Configurations/StartEducationConfiguration.cs +++ /dev/null @@ -1,31 +0,0 @@ -// This file has been auto generated by EF Core Power Tools. -using Lab3.Database.Context; -using Lab3.Database.Models; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Metadata.Builders; -using System; -using System.Collections.Generic; - -namespace Lab3.Database.Context.Configurations -{ - public partial class StartEducationConfiguration : IEntityTypeConfiguration - { - public void Configure(EntityTypeBuilder entity) - { - entity.HasKey(e => e.Id).HasName("StartEducation_pkey"); - - entity.ToTable("StartEducation"); - - entity.Property(e => e.Id).ValueGeneratedNever(); - entity.Property(e => e.DateTime).HasColumnType("timestamp without time zone"); - - entity.HasOne(d => d.Student).WithMany(p => p.StartEducations) - .HasForeignKey(d => d.StudentId) - .HasConstraintName("StartEducation_StudentId_fkey"); - - OnConfigurePartial(entity); - } - - partial void OnConfigurePartial(EntityTypeBuilder entity); - } -} diff --git a/Cop.Borovkov.Var3/Lab3.Database/Extensions/DIExtension.cs b/Cop.Borovkov.Var3/Lab3.Database/Extensions/DIExtension.cs index 291cb2d..d749c36 100644 --- a/Cop.Borovkov.Var3/Lab3.Database/Extensions/DIExtension.cs +++ b/Cop.Borovkov.Var3/Lab3.Database/Extensions/DIExtension.cs @@ -1,5 +1,7 @@ using Lab3.Database.Context; using Lab3.Database.MappingProfiles; +using Lab3.Database.Repository.Implementations; +using Lab3.Database.Repository.Interfaces; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -34,5 +36,13 @@ namespace Lab3.Database.Extensions return services; } + + public static IServiceCollection AddRepositories( + this IServiceCollection services) + { + services.AddScoped(); + + return services; + } } } diff --git a/Cop.Borovkov.Var3/Lab3.Database/Lab3.Database.csproj b/Cop.Borovkov.Var3/Lab3.Database/Lab3.Database.csproj index 29b0575..6ac96a7 100644 --- a/Cop.Borovkov.Var3/Lab3.Database/Lab3.Database.csproj +++ b/Cop.Borovkov.Var3/Lab3.Database/Lab3.Database.csproj @@ -11,8 +11,4 @@ - - - - diff --git a/Cop.Borovkov.Var3/Lab3.Database/MappingProfiles/SessionMappingProfile.cs b/Cop.Borovkov.Var3/Lab3.Database/MappingProfiles/SessionMappingProfile.cs index 251c789..31b547a 100644 --- a/Cop.Borovkov.Var3/Lab3.Database/MappingProfiles/SessionMappingProfile.cs +++ b/Cop.Borovkov.Var3/Lab3.Database/MappingProfiles/SessionMappingProfile.cs @@ -6,7 +6,7 @@ namespace Lab3.Database.MappingProfiles { public class SessionMappingProfile : Profile { - SessionMappingProfile() + public SessionMappingProfile() { _ = CreateMap(); _ = CreateMap(); diff --git a/Cop.Borovkov.Var3/Lab3.Database/Repository/Implementations/StudentRepository.cs b/Cop.Borovkov.Var3/Lab3.Database/Repository/Implementations/StudentRepository.cs new file mode 100644 index 0000000..1db612e --- /dev/null +++ b/Cop.Borovkov.Var3/Lab3.Database/Repository/Implementations/StudentRepository.cs @@ -0,0 +1,35 @@ +using AutoMapper; +using Lab3.Database.Context; +using Lab3.Database.DTO; +using Lab3.Database.Repository.Interfaces; +using Microsoft.EntityFrameworkCore; + +namespace Lab3.Database.Repository.Implementations +{ + public class StudentRepository : IStudentRepository + { + private readonly IMapper _mapper; + + private readonly COPContext _context; + + public StudentRepository(IMapper mapper, COPContext context) + { + _mapper = mapper; + _context = context; + } + + public Task> Create(StudentDTO studentDTO) => throw new NotImplementedException(); + public Task Delete(Guid id) => throw new NotImplementedException(); + + public async Task> Get(int limit = 10000, int offset = 0) + => _mapper.Map>( + await _context.Students + .Include(s => s.StudentSessions) + .Skip(offset) + .Take(limit) + .ToListAsync()); + + public Task Get(Guid id) => throw new NotImplementedException(); + public Task Update(StudentDTO studentDTO) => throw new NotImplementedException(); + } +} diff --git a/Cop.Borovkov.Var3/Lab3/Extensions/DIExtension.cs b/Cop.Borovkov.Var3/Lab3/Extensions/DIExtension.cs index 8d3ade7..5962a2f 100644 --- a/Cop.Borovkov.Var3/Lab3/Extensions/DIExtension.cs +++ b/Cop.Borovkov.Var3/Lab3/Extensions/DIExtension.cs @@ -1,4 +1,6 @@ using Lab3.Database.Extensions; +using Lab3.Forms; +using Lab3.MappingProfiles; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -12,6 +14,23 @@ namespace Lab3.Extensions { services.AddDatabase(configuration); services.AddDbMapping(); + services.AddRepositories(); + + return services; + } + + public static IServiceCollection AddForms( + this IServiceCollection services) + { + services.AddScoped(); + + return services; + } + + public static IServiceCollection AddMapping( + this IServiceCollection services) + { + services.AddAutoMapper(typeof(StudentViewMappingProfile)); return services; } diff --git a/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.Designer.cs b/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.Designer.cs new file mode 100644 index 0000000..be38e3e --- /dev/null +++ b/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.Designer.cs @@ -0,0 +1,291 @@ +namespace Lab3.Forms +{ + partial class CreateForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + customDateTimePicker1 = new CustomsComponentsVar2.CustomDateTimePicker(); + visualSelectionComponent1 = new ComponentsLab.VisualSelectionComponent(); + label1 = new Label(); + label2 = new Label(); + textBox1 = new TextBox(); + label3 = new Label(); + numericUpDown1 = new NumericUpDown(); + label4 = new Label(); + label5 = new Label(); + label6 = new Label(); + numericUpDown2 = new NumericUpDown(); + label7 = new Label(); + numericUpDown3 = new NumericUpDown(); + label8 = new Label(); + numericUpDown4 = new NumericUpDown(); + label9 = new Label(); + numericUpDown5 = new NumericUpDown(); + label10 = new Label(); + numericUpDown6 = new NumericUpDown(); + ((System.ComponentModel.ISupportInitialize)numericUpDown1).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDown2).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDown3).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDown4).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDown5).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDown6).BeginInit(); + SuspendLayout(); + // + // customDateTimePicker1 + // + customDateTimePicker1.Location = new Point(430, 32); + customDateTimePicker1.Name = "customDateTimePicker1"; + customDateTimePicker1.Size = new Size(456, 55); + customDateTimePicker1.TabIndex = 0; + customDateTimePicker1.Value = new DateTime(2024, 11, 6, 22, 54, 54, 353); + // + // visualSelectionComponent1 + // + visualSelectionComponent1.BorderStyle = BorderStyle.FixedSingle; + visualSelectionComponent1.comboBoxSelectedValue = ""; + visualSelectionComponent1.Location = new Point(430, 114); + visualSelectionComponent1.Margin = new Padding(3, 4, 3, 4); + visualSelectionComponent1.Name = "visualSelectionComponent1"; + visualSelectionComponent1.Size = new Size(211, 109); + visualSelectionComponent1.TabIndex = 1; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(430, 9); + label1.Name = "label1"; + label1.Size = new Size(134, 20); + label1.TabIndex = 2; + label1.Text = "Дата поступления"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(436, 90); + label2.Name = "label2"; + label2.Size = new Size(128, 20); + label2.TabIndex = 3; + label2.Text = "Форма обучения"; + // + // textBox1 + // + textBox1.Location = new Point(12, 60); + textBox1.Name = "textBox1"; + textBox1.Size = new Size(315, 27); + textBox1.TabIndex = 4; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(12, 18); + label3.Name = "label3"; + label3.Size = new Size(42, 20); + label3.TabIndex = 5; + label3.Text = "ФИО"; + // + // numericUpDown1 + // + numericUpDown1.DecimalPlaces = 2; + numericUpDown1.Increment = new decimal(new int[] { 1, 0, 0, 131072 }); + numericUpDown1.Location = new Point(12, 156); + numericUpDown1.Maximum = new decimal(new int[] { 5, 0, 0, 0 }); + numericUpDown1.Name = "numericUpDown1"; + numericUpDown1.Size = new Size(150, 27); + numericUpDown1.TabIndex = 6; + // + // label4 + // + label4.AutoSize = true; + label4.Location = new Point(12, 101); + label4.Name = "label4"; + label4.Size = new Size(107, 20); + label4.TabIndex = 7; + label4.Text = "Успеваемость"; + // + // label5 + // + label5.AutoSize = true; + label5.Location = new Point(12, 133); + label5.Name = "label5"; + label5.Size = new Size(65, 20); + label5.TabIndex = 8; + label5.Text = "Сессия1"; + // + // label6 + // + label6.AutoSize = true; + label6.Location = new Point(12, 188); + label6.Name = "label6"; + label6.Size = new Size(65, 20); + label6.TabIndex = 10; + label6.Text = "Сессия2"; + // + // numericUpDown2 + // + numericUpDown2.DecimalPlaces = 2; + numericUpDown2.Increment = new decimal(new int[] { 1, 0, 0, 131072 }); + numericUpDown2.Location = new Point(12, 211); + numericUpDown2.Maximum = new decimal(new int[] { 5, 0, 0, 0 }); + numericUpDown2.Name = "numericUpDown2"; + numericUpDown2.Size = new Size(150, 27); + numericUpDown2.TabIndex = 9; + // + // label7 + // + label7.AutoSize = true; + label7.Location = new Point(12, 247); + label7.Name = "label7"; + label7.Size = new Size(65, 20); + label7.TabIndex = 12; + label7.Text = "Сессия3"; + // + // numericUpDown3 + // + numericUpDown3.DecimalPlaces = 2; + numericUpDown3.Increment = new decimal(new int[] { 1, 0, 0, 131072 }); + numericUpDown3.Location = new Point(12, 270); + numericUpDown3.Maximum = new decimal(new int[] { 5, 0, 0, 0 }); + numericUpDown3.Name = "numericUpDown3"; + numericUpDown3.Size = new Size(150, 27); + numericUpDown3.TabIndex = 11; + // + // label8 + // + label8.AutoSize = true; + label8.Location = new Point(177, 247); + label8.Name = "label8"; + label8.Size = new Size(65, 20); + label8.TabIndex = 18; + label8.Text = "Сессия6"; + // + // numericUpDown4 + // + numericUpDown4.DecimalPlaces = 2; + numericUpDown4.Increment = new decimal(new int[] { 1, 0, 0, 131072 }); + numericUpDown4.Location = new Point(177, 270); + numericUpDown4.Maximum = new decimal(new int[] { 5, 0, 0, 0 }); + numericUpDown4.Name = "numericUpDown4"; + numericUpDown4.Size = new Size(150, 27); + numericUpDown4.TabIndex = 17; + // + // label9 + // + label9.AutoSize = true; + label9.Location = new Point(177, 188); + label9.Name = "label9"; + label9.Size = new Size(65, 20); + label9.TabIndex = 16; + label9.Text = "Сессия5"; + // + // numericUpDown5 + // + numericUpDown5.DecimalPlaces = 2; + numericUpDown5.Increment = new decimal(new int[] { 1, 0, 0, 131072 }); + numericUpDown5.Location = new Point(177, 211); + numericUpDown5.Maximum = new decimal(new int[] { 5, 0, 0, 0 }); + numericUpDown5.Name = "numericUpDown5"; + numericUpDown5.Size = new Size(150, 27); + numericUpDown5.TabIndex = 15; + // + // label10 + // + label10.AutoSize = true; + label10.Location = new Point(177, 133); + label10.Name = "label10"; + label10.Size = new Size(65, 20); + label10.TabIndex = 14; + label10.Text = "Сессия4"; + // + // numericUpDown6 + // + numericUpDown6.DecimalPlaces = 2; + numericUpDown6.Increment = new decimal(new int[] { 1, 0, 0, 131072 }); + numericUpDown6.Location = new Point(177, 156); + numericUpDown6.Maximum = new decimal(new int[] { 5, 0, 0, 0 }); + numericUpDown6.Name = "numericUpDown6"; + numericUpDown6.Size = new Size(150, 27); + numericUpDown6.TabIndex = 13; + // + // CreateForm + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 309); + Controls.Add(label8); + Controls.Add(numericUpDown4); + Controls.Add(label9); + Controls.Add(numericUpDown5); + Controls.Add(label10); + Controls.Add(numericUpDown6); + Controls.Add(label7); + Controls.Add(numericUpDown3); + Controls.Add(label6); + Controls.Add(numericUpDown2); + Controls.Add(label5); + Controls.Add(label4); + Controls.Add(numericUpDown1); + Controls.Add(label3); + Controls.Add(textBox1); + Controls.Add(label2); + Controls.Add(label1); + Controls.Add(customDateTimePicker1); + Controls.Add(visualSelectionComponent1); + Name = "CreateForm"; + Text = "Сессия1"; + ((System.ComponentModel.ISupportInitialize)numericUpDown1).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDown2).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDown3).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDown4).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDown5).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDown6).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private CustomsComponentsVar2.CustomDateTimePicker customDateTimePicker1; + private ComponentsLab.VisualSelectionComponent visualSelectionComponent1; + private Label label1; + private Label label2; + private TextBox textBox1; + private Label label3; + private NumericUpDown numericUpDown1; + private Label label4; + private Label label5; + private Label label6; + private NumericUpDown numericUpDown2; + private Label label7; + private NumericUpDown numericUpDown3; + private Label label8; + private NumericUpDown numericUpDown4; + private Label label9; + private NumericUpDown numericUpDown5; + private Label label10; + private NumericUpDown numericUpDown6; + } +} \ No newline at end of file diff --git a/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs b/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs new file mode 100644 index 0000000..c1d3860 --- /dev/null +++ b/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs @@ -0,0 +1,20 @@ +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 Lab3.Forms +{ + public partial class CreateForm : Form + { + public CreateForm() + { + InitializeComponent(); + } + } +} diff --git a/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.resx b/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Cop.Borovkov.Var3/Lab3/Forms/MainForm.Designer.cs b/Cop.Borovkov.Var3/Lab3/Forms/MainForm.Designer.cs index 1675ede..0e30590 100644 --- a/Cop.Borovkov.Var3/Lab3/Forms/MainForm.Designer.cs +++ b/Cop.Borovkov.Var3/Lab3/Forms/MainForm.Designer.cs @@ -28,12 +28,33 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "MainForm"; + StudentsListBox = new ComponentsLibrary.ListBoxValues(); + SuspendLayout(); + // + // StudentsListBox + // + StudentsListBox.Dock = DockStyle.Fill; + StudentsListBox.Location = new Point(0, 0); + StudentsListBox.Margin = new Padding(3, 4, 3, 4); + StudentsListBox.Name = "StudentsListBox"; + StudentsListBox.SelectedIndex = -1; + StudentsListBox.Size = new Size(800, 450); + StudentsListBox.TabIndex = 0; + // + // MainForm + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(StudentsListBox); + Name = "MainForm"; + Text = "MainForm"; + Load += MainForm_LoadAsync; + ResumeLayout(false); } #endregion + + private ComponentsLibrary.ListBoxValues StudentsListBox; } } \ No newline at end of file diff --git a/Cop.Borovkov.Var3/Lab3/Forms/MainForm.cs b/Cop.Borovkov.Var3/Lab3/Forms/MainForm.cs index 7f63187..5bdb12e 100644 --- a/Cop.Borovkov.Var3/Lab3/Forms/MainForm.cs +++ b/Cop.Borovkov.Var3/Lab3/Forms/MainForm.cs @@ -1,20 +1,27 @@ -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; +using AutoMapper; +using Lab3.Database.Repository.Interfaces; +using Lab3.Models; namespace Lab3.Forms { public partial class MainForm : Form { - public MainForm() + private readonly IStudentRepository _studentRepository; + private readonly IMapper _mapper; + + public MainForm( + IStudentRepository repository, + IMapper mapper) { + _studentRepository = repository; + _mapper = mapper; InitializeComponent(); } + + private async void MainForm_LoadAsync(object sender, EventArgs e) + { + var students = _mapper.Map>(await _studentRepository.Get()); + StudentsListBox.FillListBox(students); + } } } diff --git a/Cop.Borovkov.Var3/Lab3/Forms/MainForm.resx b/Cop.Borovkov.Var3/Lab3/Forms/MainForm.resx index 1af7de1..8b2ff64 100644 --- a/Cop.Borovkov.Var3/Lab3/Forms/MainForm.resx +++ b/Cop.Borovkov.Var3/Lab3/Forms/MainForm.resx @@ -1,17 +1,17 @@  - diff --git a/Cop.Borovkov.Var3/Lab3/Lab3.csproj b/Cop.Borovkov.Var3/Lab3/Lab3.csproj index c1f50c7..db1aab1 100644 --- a/Cop.Borovkov.Var3/Lab3/Lab3.csproj +++ b/Cop.Borovkov.Var3/Lab3/Lab3.csproj @@ -12,8 +12,22 @@ + + + + + + + + + + + Always + + + \ No newline at end of file diff --git a/Cop.Borovkov.Var3/Lab3/MappingProfiles/StudentViewMappingProfile.cs b/Cop.Borovkov.Var3/Lab3/MappingProfiles/StudentViewMappingProfile.cs index 1df0214..7be214c 100644 --- a/Cop.Borovkov.Var3/Lab3/MappingProfiles/StudentViewMappingProfile.cs +++ b/Cop.Borovkov.Var3/Lab3/MappingProfiles/StudentViewMappingProfile.cs @@ -8,7 +8,7 @@ namespace Lab3.MappingProfiles { public StudentViewMappingProfile() { - _ = CreateMap()\ + _ = CreateMap() ; } } diff --git a/Cop.Borovkov.Var3/Lab3/Program.cs b/Cop.Borovkov.Var3/Lab3/Program.cs index f7a9a87..2ac9d73 100644 --- a/Cop.Borovkov.Var3/Lab3/Program.cs +++ b/Cop.Borovkov.Var3/Lab3/Program.cs @@ -1,3 +1,10 @@ +using Lab3.Database.Extensions; +using Lab3.Extensions; +using Lab3.Forms; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; + namespace Lab3 { internal static class Program @@ -11,7 +18,25 @@ namespace Lab3 // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + + var app = CreateHostBuilder().Build(); + + Application.Run(app.Services.GetRequiredService()); + } + + static IHostBuilder CreateHostBuilder() + { + return Host.CreateDefaultBuilder() + .ConfigureAppConfiguration(c + => c.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)) + .ConfigureServices((context, services) => { + + services.ConfigureDAL(context.Configuration); + + services.AddMapping(); + + services.AddForms(); + }); } } } \ No newline at end of file From 8563387642f75f185a16b039a5cc34f8e879450a Mon Sep 17 00:00:00 2001 From: bekodeg Date: Wed, 6 Nov 2024 23:20:09 +0400 Subject: [PATCH 06/20] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8F=20=D1=80=D0=B5=D0=BF=D0=BE=D0=B7=D0=B8?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=B8=D1=8F=20=D0=B4=D0=BB=D1=8F=20=D1=81?= =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BE=D1=87=D0=BD=D0=BE=D0=B9=20=D1=82?= =?UTF-8?q?=D0=B0=D0=B1=D0=BB=D0=B8=D1=86=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Lab3.Database/Extensions/DIExtension.cs | 1 + .../EducationFormRepository.cs | 34 +++++++++++++++++++ .../Interfaces/IEducationFormRepository.cs | 9 +++++ .../Lab3/Extensions/DIExtension.cs | 1 + .../Lab3/Forms/CreateForm.Designer.cs | 27 ++++++++++++++- Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs | 17 ++++------ Cop.Borovkov.Var3/Lab3/Program.cs | 2 +- 7 files changed, 79 insertions(+), 12 deletions(-) create mode 100644 Cop.Borovkov.Var3/Lab3.Database/Repository/Implementations/EducationFormRepository.cs create mode 100644 Cop.Borovkov.Var3/Lab3.Database/Repository/Interfaces/IEducationFormRepository.cs diff --git a/Cop.Borovkov.Var3/Lab3.Database/Extensions/DIExtension.cs b/Cop.Borovkov.Var3/Lab3.Database/Extensions/DIExtension.cs index d749c36..f623e96 100644 --- a/Cop.Borovkov.Var3/Lab3.Database/Extensions/DIExtension.cs +++ b/Cop.Borovkov.Var3/Lab3.Database/Extensions/DIExtension.cs @@ -41,6 +41,7 @@ namespace Lab3.Database.Extensions this IServiceCollection services) { services.AddScoped(); + services.AddScoped(); return services; } diff --git a/Cop.Borovkov.Var3/Lab3.Database/Repository/Implementations/EducationFormRepository.cs b/Cop.Borovkov.Var3/Lab3.Database/Repository/Implementations/EducationFormRepository.cs new file mode 100644 index 0000000..5bcb5d9 --- /dev/null +++ b/Cop.Borovkov.Var3/Lab3.Database/Repository/Implementations/EducationFormRepository.cs @@ -0,0 +1,34 @@ +using Lab3.Database.Context; +using Lab3.Database.Models; +using Lab3.Database.Repository.Interfaces; +using Microsoft.EntityFrameworkCore; + +namespace Lab3.Database.Repository.Implementations +{ + public class EducationFormRepository : IEducationFormRepository + { + private readonly COPContext _context; + + public EducationFormRepository(COPContext context) + { + _context = context; + } + + public async Task> Get() + { + return await _context.EducationForms + .Select(f => f.Name) + .ToListAsync(); + } + + public async Task Update(IEnumerable educationForms) + { + await _context.EducationForms.ExecuteDeleteAsync(); + await _context.EducationForms.AddRangeAsync(educationForms.Select(f => new EducationForm() + { + Id = Guid.NewGuid(), + Name = f, + })); + } + } +} diff --git a/Cop.Borovkov.Var3/Lab3.Database/Repository/Interfaces/IEducationFormRepository.cs b/Cop.Borovkov.Var3/Lab3.Database/Repository/Interfaces/IEducationFormRepository.cs new file mode 100644 index 0000000..355c69e --- /dev/null +++ b/Cop.Borovkov.Var3/Lab3.Database/Repository/Interfaces/IEducationFormRepository.cs @@ -0,0 +1,9 @@ +namespace Lab3.Database.Repository.Interfaces +{ + public interface IEducationFormRepository + { + Task> Get(); + + Task Update(IEnumerable educationForms); + } +} diff --git a/Cop.Borovkov.Var3/Lab3/Extensions/DIExtension.cs b/Cop.Borovkov.Var3/Lab3/Extensions/DIExtension.cs index 5962a2f..d209df7 100644 --- a/Cop.Borovkov.Var3/Lab3/Extensions/DIExtension.cs +++ b/Cop.Borovkov.Var3/Lab3/Extensions/DIExtension.cs @@ -23,6 +23,7 @@ namespace Lab3.Extensions this IServiceCollection services) { services.AddScoped(); + services.AddScoped(); return services; } diff --git a/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.Designer.cs b/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.Designer.cs index be38e3e..fdc03ad 100644 --- a/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.Designer.cs +++ b/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.Designer.cs @@ -47,6 +47,8 @@ numericUpDown5 = new NumericUpDown(); label10 = new Label(); numericUpDown6 = new NumericUpDown(); + button1 = new Button(); + button2 = new Button(); ((System.ComponentModel.ISupportInitialize)numericUpDown1).BeginInit(); ((System.ComponentModel.ISupportInitialize)numericUpDown2).BeginInit(); ((System.ComponentModel.ISupportInitialize)numericUpDown3).BeginInit(); @@ -230,11 +232,31 @@ numericUpDown6.Size = new Size(150, 27); numericUpDown6.TabIndex = 13; // + // button1 + // + button1.Location = new Point(430, 258); + button1.Name = "button1"; + button1.Size = new Size(164, 39); + button1.TabIndex = 19; + button1.Text = "Сохранить"; + button1.UseVisualStyleBackColor = true; + // + // button2 + // + button2.Location = new Point(624, 258); + button2.Name = "button2"; + button2.Size = new Size(164, 39); + button2.TabIndex = 20; + button2.Text = "Отмена"; + button2.UseVisualStyleBackColor = true; + // // CreateForm // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(800, 309); + Controls.Add(button2); + Controls.Add(button1); Controls.Add(label8); Controls.Add(numericUpDown4); Controls.Add(label9); @@ -255,7 +277,8 @@ Controls.Add(customDateTimePicker1); Controls.Add(visualSelectionComponent1); Name = "CreateForm"; - Text = "Сессия1"; + Text = "CreateForm"; + Load += CreateForm_Load; ((System.ComponentModel.ISupportInitialize)numericUpDown1).EndInit(); ((System.ComponentModel.ISupportInitialize)numericUpDown2).EndInit(); ((System.ComponentModel.ISupportInitialize)numericUpDown3).EndInit(); @@ -287,5 +310,7 @@ private NumericUpDown numericUpDown5; private Label label10; private NumericUpDown numericUpDown6; + private Button button1; + private Button button2; } } \ No newline at end of file diff --git a/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs b/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs index c1d3860..e3bb90c 100644 --- a/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs +++ b/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs @@ -1,20 +1,17 @@ -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; +using Lab3.Database.Repository.Interfaces; namespace Lab3.Forms { public partial class CreateForm : Form { - public CreateForm() + public CreateForm(IStudentRepository student) { InitializeComponent(); } + + private void CreateForm_Load(object sender, EventArgs e) + { + + } } } diff --git a/Cop.Borovkov.Var3/Lab3/Program.cs b/Cop.Borovkov.Var3/Lab3/Program.cs index 2ac9d73..46a396d 100644 --- a/Cop.Borovkov.Var3/Lab3/Program.cs +++ b/Cop.Borovkov.Var3/Lab3/Program.cs @@ -21,7 +21,7 @@ namespace Lab3 var app = CreateHostBuilder().Build(); - Application.Run(app.Services.GetRequiredService()); + Application.Run(app.Services.GetRequiredService()); } static IHostBuilder CreateHostBuilder() From 2c0e6b13f594663cd20e8029f96802bab1535f77 Mon Sep 17 00:00:00 2001 From: bekodeg Date: Thu, 7 Nov 2024 13:41:24 +0400 Subject: [PATCH 07/20] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B7=D0=B0=D0=BF=D0=B8=D1=81=D0=B8?= =?UTF-8?q?=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Lab3.Database/DTO/StudentSessionDTO.cs | 2 - .../MappingProfiles/SessionMappingProfile.cs | 3 +- .../Implementations/StudentRepository.cs | 45 ++- .../Interfaces/IStudentRepository.cs | 10 +- .../Lab3/Extensions/DIExtension.cs | 12 +- .../Lab3/Forms/CreateForm.Designer.cs | 257 +++++++++--------- Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs | 76 +++++- Cop.Borovkov.Var3/Lab3/Forms/MainForm.cs | 2 +- Cop.Borovkov.Var3/Lab3/Lab3.csproj | 4 +- Cop.Borovkov.Var3/Lab3/Program.cs | 2 +- 10 files changed, 263 insertions(+), 150 deletions(-) diff --git a/Cop.Borovkov.Var3/Lab3.Database/DTO/StudentSessionDTO.cs b/Cop.Borovkov.Var3/Lab3.Database/DTO/StudentSessionDTO.cs index 8155a74..52da42d 100644 --- a/Cop.Borovkov.Var3/Lab3.Database/DTO/StudentSessionDTO.cs +++ b/Cop.Borovkov.Var3/Lab3.Database/DTO/StudentSessionDTO.cs @@ -2,8 +2,6 @@ { public record StudentSessionDTO { - public Guid Id { get; init; } - public decimal Score { get; init; } public int Number { get; init; } diff --git a/Cop.Borovkov.Var3/Lab3.Database/MappingProfiles/SessionMappingProfile.cs b/Cop.Borovkov.Var3/Lab3.Database/MappingProfiles/SessionMappingProfile.cs index 31b547a..b56d35b 100644 --- a/Cop.Borovkov.Var3/Lab3.Database/MappingProfiles/SessionMappingProfile.cs +++ b/Cop.Borovkov.Var3/Lab3.Database/MappingProfiles/SessionMappingProfile.cs @@ -9,7 +9,8 @@ namespace Lab3.Database.MappingProfiles public SessionMappingProfile() { _ = CreateMap(); - _ = CreateMap(); + _ = CreateMap() + .ForMember(s => s.Id, opt => opt.MapFrom(s => Guid.NewGuid())); } } } diff --git a/Cop.Borovkov.Var3/Lab3.Database/Repository/Implementations/StudentRepository.cs b/Cop.Borovkov.Var3/Lab3.Database/Repository/Implementations/StudentRepository.cs index 1db612e..8f0d2f0 100644 --- a/Cop.Borovkov.Var3/Lab3.Database/Repository/Implementations/StudentRepository.cs +++ b/Cop.Borovkov.Var3/Lab3.Database/Repository/Implementations/StudentRepository.cs @@ -1,6 +1,7 @@ using AutoMapper; using Lab3.Database.Context; using Lab3.Database.DTO; +using Lab3.Database.Models; using Lab3.Database.Repository.Interfaces; using Microsoft.EntityFrameworkCore; @@ -18,10 +19,19 @@ namespace Lab3.Database.Repository.Implementations _context = context; } - public Task> Create(StudentDTO studentDTO) => throw new NotImplementedException(); - public Task Delete(Guid id) => throw new NotImplementedException(); + public async Task CreateAsync(StudentDTO studentDTO) + { + var student = _mapper.Map(studentDTO); - public async Task> Get(int limit = 10000, int offset = 0) + var result = await _context.Students.AddAsync(student); + await _context.SaveChangesAsync(); + + return _mapper.Map(result.Entity); + } + + public Task DeleteAsync(Guid id) => throw new NotImplementedException(); + + public async Task> GetAsync(int limit = 10000, int offset = 0) => _mapper.Map>( await _context.Students .Include(s => s.StudentSessions) @@ -29,7 +39,32 @@ namespace Lab3.Database.Repository.Implementations .Take(limit) .ToListAsync()); - public Task Get(Guid id) => throw new NotImplementedException(); - public Task Update(StudentDTO studentDTO) => throw new NotImplementedException(); + public Task GetAsync(Guid id) => throw new NotImplementedException(); + + public async Task UpdateAsync(StudentDTO studentDTO) + { + var student = _mapper.Map(studentDTO); + + var currStudent = await _context.Students.FindAsync(student.Id); + + if (currStudent == null) + { + return null; + } + + currStudent.Name = student.Name; + currStudent.StartEducation = student.StartEducation; + currStudent.EducationForm = student.EducationForm; + + foreach (var session in currStudent.StudentSessions) + { + session.Score = student.StudentSessions + .FirstOrDefault(s => s.Number == session.Number)?.Score ?? session.Score; + } + + await _context.SaveChangesAsync(); + + return _mapper.Map(currStudent); + } } } diff --git a/Cop.Borovkov.Var3/Lab3.Database/Repository/Interfaces/IStudentRepository.cs b/Cop.Borovkov.Var3/Lab3.Database/Repository/Interfaces/IStudentRepository.cs index 968ded3..6561dc0 100644 --- a/Cop.Borovkov.Var3/Lab3.Database/Repository/Interfaces/IStudentRepository.cs +++ b/Cop.Borovkov.Var3/Lab3.Database/Repository/Interfaces/IStudentRepository.cs @@ -4,14 +4,14 @@ namespace Lab3.Database.Repository.Interfaces { public interface IStudentRepository { - public Task> Get(int limit = 10000, int offset = 0); + public Task> GetAsync(int limit = 10000, int offset = 0); - public Task Get(Guid id); + public Task GetAsync(Guid id); - public Task Update(StudentDTO studentDTO); + public Task UpdateAsync(StudentDTO studentDTO); - public Task Delete(Guid id); + public Task DeleteAsync(Guid id); - public Task> Create(StudentDTO studentDTO); + public Task CreateAsync(StudentDTO studentDTO); } } diff --git a/Cop.Borovkov.Var3/Lab3/Extensions/DIExtension.cs b/Cop.Borovkov.Var3/Lab3/Extensions/DIExtension.cs index d209df7..11ef788 100644 --- a/Cop.Borovkov.Var3/Lab3/Extensions/DIExtension.cs +++ b/Cop.Borovkov.Var3/Lab3/Extensions/DIExtension.cs @@ -1,4 +1,6 @@ -using Lab3.Database.Extensions; +using DocumentFormat.OpenXml.Office2010.Excel; +using Lab3.Database.Extensions; +using Lab3.Database.Repository.Interfaces; using Lab3.Forms; using Lab3.MappingProfiles; using Microsoft.Extensions.Configuration; @@ -23,7 +25,13 @@ namespace Lab3.Extensions this IServiceCollection services) { services.AddScoped(); - services.AddScoped(); + + services.AddScoped>(sp => (id + => new CreateForm( + sp.GetRequiredService(), + sp.GetRequiredService(), + id + ))); return services; } diff --git a/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.Designer.cs b/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.Designer.cs index fdc03ad..aab5988 100644 --- a/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.Designer.cs +++ b/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.Designer.cs @@ -28,52 +28,52 @@ /// private void InitializeComponent() { - customDateTimePicker1 = new CustomsComponentsVar2.CustomDateTimePicker(); - visualSelectionComponent1 = new ComponentsLab.VisualSelectionComponent(); + StartEducationDataPicker = new CustomsComponentsVar2.CustomDateTimePicker(); + FormSelector = new ComponentsLab.VisualSelectionComponent(); label1 = new Label(); label2 = new Label(); - textBox1 = new TextBox(); + NameTextBox = new TextBox(); label3 = new Label(); - numericUpDown1 = new NumericUpDown(); + session1Score = new NumericUpDown(); label4 = new Label(); label5 = new Label(); label6 = new Label(); - numericUpDown2 = new NumericUpDown(); + session2Score = new NumericUpDown(); label7 = new Label(); - numericUpDown3 = new NumericUpDown(); + session3Score = new NumericUpDown(); label8 = new Label(); - numericUpDown4 = new NumericUpDown(); + session6Score = new NumericUpDown(); label9 = new Label(); - numericUpDown5 = new NumericUpDown(); + session5Score = new NumericUpDown(); label10 = new Label(); - numericUpDown6 = new NumericUpDown(); - button1 = new Button(); - button2 = new Button(); - ((System.ComponentModel.ISupportInitialize)numericUpDown1).BeginInit(); - ((System.ComponentModel.ISupportInitialize)numericUpDown2).BeginInit(); - ((System.ComponentModel.ISupportInitialize)numericUpDown3).BeginInit(); - ((System.ComponentModel.ISupportInitialize)numericUpDown4).BeginInit(); - ((System.ComponentModel.ISupportInitialize)numericUpDown5).BeginInit(); - ((System.ComponentModel.ISupportInitialize)numericUpDown6).BeginInit(); + session4Score = new NumericUpDown(); + ButtonSave = new Button(); + buttonCancel = new Button(); + ((System.ComponentModel.ISupportInitialize)session1Score).BeginInit(); + ((System.ComponentModel.ISupportInitialize)session2Score).BeginInit(); + ((System.ComponentModel.ISupportInitialize)session3Score).BeginInit(); + ((System.ComponentModel.ISupportInitialize)session6Score).BeginInit(); + ((System.ComponentModel.ISupportInitialize)session5Score).BeginInit(); + ((System.ComponentModel.ISupportInitialize)session4Score).BeginInit(); SuspendLayout(); // - // customDateTimePicker1 + // StartEducationDataPicker // - customDateTimePicker1.Location = new Point(430, 32); - customDateTimePicker1.Name = "customDateTimePicker1"; - customDateTimePicker1.Size = new Size(456, 55); - customDateTimePicker1.TabIndex = 0; - customDateTimePicker1.Value = new DateTime(2024, 11, 6, 22, 54, 54, 353); + StartEducationDataPicker.Location = new Point(430, 32); + StartEducationDataPicker.Name = "StartEducationDataPicker"; + StartEducationDataPicker.Size = new Size(456, 55); + StartEducationDataPicker.TabIndex = 0; + StartEducationDataPicker.Value = new DateTime(2024, 11, 6, 22, 54, 54, 353); // - // visualSelectionComponent1 + // FormSelector // - visualSelectionComponent1.BorderStyle = BorderStyle.FixedSingle; - visualSelectionComponent1.comboBoxSelectedValue = ""; - visualSelectionComponent1.Location = new Point(430, 114); - visualSelectionComponent1.Margin = new Padding(3, 4, 3, 4); - visualSelectionComponent1.Name = "visualSelectionComponent1"; - visualSelectionComponent1.Size = new Size(211, 109); - visualSelectionComponent1.TabIndex = 1; + FormSelector.BorderStyle = BorderStyle.FixedSingle; + FormSelector.ComboBoxSelectedValue = ""; + FormSelector.Location = new Point(436, 133); + FormSelector.Margin = new Padding(3, 4, 3, 4); + FormSelector.Name = "FormSelector"; + FormSelector.Size = new Size(352, 31); + FormSelector.TabIndex = 1; // // label1 // @@ -87,18 +87,18 @@ // label2 // label2.AutoSize = true; - label2.Location = new Point(436, 90); + label2.Location = new Point(436, 101); label2.Name = "label2"; label2.Size = new Size(128, 20); label2.TabIndex = 3; label2.Text = "Форма обучения"; // - // textBox1 + // NameTextBox // - textBox1.Location = new Point(12, 60); - textBox1.Name = "textBox1"; - textBox1.Size = new Size(315, 27); - textBox1.TabIndex = 4; + NameTextBox.Location = new Point(12, 60); + NameTextBox.Name = "NameTextBox"; + NameTextBox.Size = new Size(315, 27); + NameTextBox.TabIndex = 4; // // label3 // @@ -109,15 +109,15 @@ label3.TabIndex = 5; label3.Text = "ФИО"; // - // numericUpDown1 + // session1Score // - numericUpDown1.DecimalPlaces = 2; - numericUpDown1.Increment = new decimal(new int[] { 1, 0, 0, 131072 }); - numericUpDown1.Location = new Point(12, 156); - numericUpDown1.Maximum = new decimal(new int[] { 5, 0, 0, 0 }); - numericUpDown1.Name = "numericUpDown1"; - numericUpDown1.Size = new Size(150, 27); - numericUpDown1.TabIndex = 6; + session1Score.DecimalPlaces = 2; + session1Score.Increment = new decimal(new int[] { 1, 0, 0, 131072 }); + session1Score.Location = new Point(12, 156); + session1Score.Maximum = new decimal(new int[] { 5, 0, 0, 0 }); + session1Score.Name = "session1Score"; + session1Score.Size = new Size(150, 27); + session1Score.TabIndex = 6; // // label4 // @@ -146,15 +146,15 @@ label6.TabIndex = 10; label6.Text = "Сессия2"; // - // numericUpDown2 + // session2Score // - numericUpDown2.DecimalPlaces = 2; - numericUpDown2.Increment = new decimal(new int[] { 1, 0, 0, 131072 }); - numericUpDown2.Location = new Point(12, 211); - numericUpDown2.Maximum = new decimal(new int[] { 5, 0, 0, 0 }); - numericUpDown2.Name = "numericUpDown2"; - numericUpDown2.Size = new Size(150, 27); - numericUpDown2.TabIndex = 9; + session2Score.DecimalPlaces = 2; + session2Score.Increment = new decimal(new int[] { 1, 0, 0, 131072 }); + session2Score.Location = new Point(12, 211); + session2Score.Maximum = new decimal(new int[] { 5, 0, 0, 0 }); + session2Score.Name = "session2Score"; + session2Score.Size = new Size(150, 27); + session2Score.TabIndex = 9; // // label7 // @@ -165,15 +165,15 @@ label7.TabIndex = 12; label7.Text = "Сессия3"; // - // numericUpDown3 + // session3Score // - numericUpDown3.DecimalPlaces = 2; - numericUpDown3.Increment = new decimal(new int[] { 1, 0, 0, 131072 }); - numericUpDown3.Location = new Point(12, 270); - numericUpDown3.Maximum = new decimal(new int[] { 5, 0, 0, 0 }); - numericUpDown3.Name = "numericUpDown3"; - numericUpDown3.Size = new Size(150, 27); - numericUpDown3.TabIndex = 11; + session3Score.DecimalPlaces = 2; + session3Score.Increment = new decimal(new int[] { 1, 0, 0, 131072 }); + session3Score.Location = new Point(12, 270); + session3Score.Maximum = new decimal(new int[] { 5, 0, 0, 0 }); + session3Score.Name = "session3Score"; + session3Score.Size = new Size(150, 27); + session3Score.TabIndex = 11; // // label8 // @@ -184,15 +184,15 @@ label8.TabIndex = 18; label8.Text = "Сессия6"; // - // numericUpDown4 + // session6Score // - numericUpDown4.DecimalPlaces = 2; - numericUpDown4.Increment = new decimal(new int[] { 1, 0, 0, 131072 }); - numericUpDown4.Location = new Point(177, 270); - numericUpDown4.Maximum = new decimal(new int[] { 5, 0, 0, 0 }); - numericUpDown4.Name = "numericUpDown4"; - numericUpDown4.Size = new Size(150, 27); - numericUpDown4.TabIndex = 17; + session6Score.DecimalPlaces = 2; + session6Score.Increment = new decimal(new int[] { 1, 0, 0, 131072 }); + session6Score.Location = new Point(177, 270); + session6Score.Maximum = new decimal(new int[] { 5, 0, 0, 0 }); + session6Score.Name = "session6Score"; + session6Score.Size = new Size(150, 27); + session6Score.TabIndex = 17; // // label9 // @@ -203,15 +203,15 @@ label9.TabIndex = 16; label9.Text = "Сессия5"; // - // numericUpDown5 + // session5Score // - numericUpDown5.DecimalPlaces = 2; - numericUpDown5.Increment = new decimal(new int[] { 1, 0, 0, 131072 }); - numericUpDown5.Location = new Point(177, 211); - numericUpDown5.Maximum = new decimal(new int[] { 5, 0, 0, 0 }); - numericUpDown5.Name = "numericUpDown5"; - numericUpDown5.Size = new Size(150, 27); - numericUpDown5.TabIndex = 15; + session5Score.DecimalPlaces = 2; + session5Score.Increment = new decimal(new int[] { 1, 0, 0, 131072 }); + session5Score.Location = new Point(177, 211); + session5Score.Maximum = new decimal(new int[] { 5, 0, 0, 0 }); + session5Score.Name = "session5Score"; + session5Score.Size = new Size(150, 27); + session5Score.TabIndex = 15; // // label10 // @@ -222,95 +222,96 @@ label10.TabIndex = 14; label10.Text = "Сессия4"; // - // numericUpDown6 + // session4Score // - numericUpDown6.DecimalPlaces = 2; - numericUpDown6.Increment = new decimal(new int[] { 1, 0, 0, 131072 }); - numericUpDown6.Location = new Point(177, 156); - numericUpDown6.Maximum = new decimal(new int[] { 5, 0, 0, 0 }); - numericUpDown6.Name = "numericUpDown6"; - numericUpDown6.Size = new Size(150, 27); - numericUpDown6.TabIndex = 13; + session4Score.DecimalPlaces = 2; + session4Score.Increment = new decimal(new int[] { 1, 0, 0, 131072 }); + session4Score.Location = new Point(177, 156); + session4Score.Maximum = new decimal(new int[] { 5, 0, 0, 0 }); + session4Score.Name = "session4Score"; + session4Score.Size = new Size(150, 27); + session4Score.TabIndex = 13; // - // button1 + // ButtonSave // - button1.Location = new Point(430, 258); - button1.Name = "button1"; - button1.Size = new Size(164, 39); - button1.TabIndex = 19; - button1.Text = "Сохранить"; - button1.UseVisualStyleBackColor = true; + ButtonSave.Location = new Point(430, 258); + ButtonSave.Name = "ButtonSave"; + ButtonSave.Size = new Size(164, 39); + ButtonSave.TabIndex = 19; + ButtonSave.Text = "Сохранить"; + ButtonSave.UseVisualStyleBackColor = true; + ButtonSave.Click += ButtonSave_ClickAsync; // - // button2 + // buttonCancel // - button2.Location = new Point(624, 258); - button2.Name = "button2"; - button2.Size = new Size(164, 39); - button2.TabIndex = 20; - button2.Text = "Отмена"; - button2.UseVisualStyleBackColor = true; + buttonCancel.Location = new Point(624, 258); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(164, 39); + buttonCancel.TabIndex = 20; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; // // CreateForm // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(800, 309); - Controls.Add(button2); - Controls.Add(button1); + Controls.Add(buttonCancel); + Controls.Add(ButtonSave); Controls.Add(label8); - Controls.Add(numericUpDown4); + Controls.Add(session6Score); Controls.Add(label9); - Controls.Add(numericUpDown5); + Controls.Add(session5Score); Controls.Add(label10); - Controls.Add(numericUpDown6); + Controls.Add(session4Score); Controls.Add(label7); - Controls.Add(numericUpDown3); + Controls.Add(session3Score); Controls.Add(label6); - Controls.Add(numericUpDown2); + Controls.Add(session2Score); Controls.Add(label5); Controls.Add(label4); - Controls.Add(numericUpDown1); + Controls.Add(session1Score); Controls.Add(label3); - Controls.Add(textBox1); + Controls.Add(NameTextBox); Controls.Add(label2); Controls.Add(label1); - Controls.Add(customDateTimePicker1); - Controls.Add(visualSelectionComponent1); + Controls.Add(StartEducationDataPicker); + Controls.Add(FormSelector); Name = "CreateForm"; Text = "CreateForm"; - Load += CreateForm_Load; - ((System.ComponentModel.ISupportInitialize)numericUpDown1).EndInit(); - ((System.ComponentModel.ISupportInitialize)numericUpDown2).EndInit(); - ((System.ComponentModel.ISupportInitialize)numericUpDown3).EndInit(); - ((System.ComponentModel.ISupportInitialize)numericUpDown4).EndInit(); - ((System.ComponentModel.ISupportInitialize)numericUpDown5).EndInit(); - ((System.ComponentModel.ISupportInitialize)numericUpDown6).EndInit(); + Load += CreateForm_LoadAsync; + ((System.ComponentModel.ISupportInitialize)session1Score).EndInit(); + ((System.ComponentModel.ISupportInitialize)session2Score).EndInit(); + ((System.ComponentModel.ISupportInitialize)session3Score).EndInit(); + ((System.ComponentModel.ISupportInitialize)session6Score).EndInit(); + ((System.ComponentModel.ISupportInitialize)session5Score).EndInit(); + ((System.ComponentModel.ISupportInitialize)session4Score).EndInit(); ResumeLayout(false); PerformLayout(); } #endregion - private CustomsComponentsVar2.CustomDateTimePicker customDateTimePicker1; - private ComponentsLab.VisualSelectionComponent visualSelectionComponent1; + private CustomsComponentsVar2.CustomDateTimePicker StartEducationDataPicker; + private ComponentsLab.VisualSelectionComponent FormSelector; private Label label1; private Label label2; - private TextBox textBox1; + private TextBox NameTextBox; private Label label3; - private NumericUpDown numericUpDown1; + private NumericUpDown session1Score; private Label label4; private Label label5; private Label label6; - private NumericUpDown numericUpDown2; + private NumericUpDown session2Score; private Label label7; - private NumericUpDown numericUpDown3; + private NumericUpDown session3Score; private Label label8; - private NumericUpDown numericUpDown4; + private NumericUpDown session6Score; private Label label9; - private NumericUpDown numericUpDown5; + private NumericUpDown session5Score; private Label label10; - private NumericUpDown numericUpDown6; - private Button button1; - private Button button2; + private NumericUpDown session4Score; + private Button ButtonSave; + private Button buttonCancel; } } \ No newline at end of file diff --git a/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs b/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs index e3bb90c..e9a5049 100644 --- a/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs +++ b/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs @@ -1,17 +1,87 @@ -using Lab3.Database.Repository.Interfaces; +using Lab3.Database.DTO; +using Lab3.Database.Models; +using Lab3.Database.Repository.Interfaces; namespace Lab3.Forms { public partial class CreateForm : Form { - public CreateForm(IStudentRepository student) + private readonly IStudentRepository _studentRepository; + + private readonly IEducationFormRepository _educationFormRepository; + + private readonly Guid? _updatedStudentGuid = null; + + public CreateForm( + IStudentRepository studentRepository, + IEducationFormRepository educationFormRepository, + Guid? updatedStudentGuid) { + _studentRepository = studentRepository; + _educationFormRepository = educationFormRepository; + + _updatedStudentGuid = updatedStudentGuid; + InitializeComponent(); } - private void CreateForm_Load(object sender, EventArgs e) + private async void CreateForm_LoadAsync(object sender, EventArgs e) { + FormSelector.Fill(await _educationFormRepository.Get()); + StartEducationDataPicker.DateStart = DateTime.Now.AddYears(-6); + StartEducationDataPicker.DateEnd = DateTime.Now; + } + private async void ButtonSave_ClickAsync(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(NameTextBox.Text) + || string.IsNullOrEmpty(FormSelector.ComboBoxSelectedValue)) + { + throw new Exception(); + } + + StudentDTO student = new() + { + Id = _updatedStudentGuid ?? Guid.NewGuid(), + Name = NameTextBox.Text, + StartEducation = StartEducationDataPicker.Value, + EducationForm = FormSelector.ComboBoxSelectedValue, + StudentSessions = [ + new(){ + Score = session1Score.Value, + Number = 1, + }, + new(){ + Score = session2Score.Value, + Number = 2, + }, + new(){ + Score = session3Score.Value, + Number = 3, + }, + new(){ + Score = session4Score.Value, + Number = 4, + }, + new(){ + Score = session5Score.Value, + Number = 5, + }, + new(){ + Score = session6Score.Value, + Number = 6, + }, + ], + }; + + if (_updatedStudentGuid != null) + { + await _studentRepository.UpdateAsync(student); + } + else + { + await _studentRepository.CreateAsync(student); + } } } } diff --git a/Cop.Borovkov.Var3/Lab3/Forms/MainForm.cs b/Cop.Borovkov.Var3/Lab3/Forms/MainForm.cs index 5bdb12e..5a84939 100644 --- a/Cop.Borovkov.Var3/Lab3/Forms/MainForm.cs +++ b/Cop.Borovkov.Var3/Lab3/Forms/MainForm.cs @@ -20,7 +20,7 @@ namespace Lab3.Forms private async void MainForm_LoadAsync(object sender, EventArgs e) { - var students = _mapper.Map>(await _studentRepository.Get()); + var students = _mapper.Map>(await _studentRepository.GetAsync()); StudentsListBox.FillListBox(students); } } diff --git a/Cop.Borovkov.Var3/Lab3/Lab3.csproj b/Cop.Borovkov.Var3/Lab3/Lab3.csproj index db1aab1..19346e9 100644 --- a/Cop.Borovkov.Var3/Lab3/Lab3.csproj +++ b/Cop.Borovkov.Var3/Lab3/Lab3.csproj @@ -13,8 +13,8 @@ - - + + diff --git a/Cop.Borovkov.Var3/Lab3/Program.cs b/Cop.Borovkov.Var3/Lab3/Program.cs index 46a396d..b98c3b6 100644 --- a/Cop.Borovkov.Var3/Lab3/Program.cs +++ b/Cop.Borovkov.Var3/Lab3/Program.cs @@ -21,7 +21,7 @@ namespace Lab3 var app = CreateHostBuilder().Build(); - Application.Run(app.Services.GetRequiredService()); + Application.Run(app.Services.GetRequiredService>()(null)); } static IHostBuilder CreateHostBuilder() From 09a8bc1857afe257ee27c9c6e68e18e20054d99f Mon Sep 17 00:00:00 2001 From: bekodeg Date: Thu, 7 Nov 2024 14:04:13 +0400 Subject: [PATCH 08/20] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B8=D0=BB=20=D0=B4?= =?UTF-8?q?=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B8?= =?UTF-8?q?=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implementations/StudentRepository.cs | 8 ++++++- .../Interfaces/IStudentRepository.cs | 10 ++++---- Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs | 23 +++++++++++++++++++ Cop.Borovkov.Var3/Lab3/Program.cs | 2 +- 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/Cop.Borovkov.Var3/Lab3.Database/Repository/Implementations/StudentRepository.cs b/Cop.Borovkov.Var3/Lab3.Database/Repository/Implementations/StudentRepository.cs index 8f0d2f0..0b13144 100644 --- a/Cop.Borovkov.Var3/Lab3.Database/Repository/Implementations/StudentRepository.cs +++ b/Cop.Borovkov.Var3/Lab3.Database/Repository/Implementations/StudentRepository.cs @@ -39,7 +39,13 @@ namespace Lab3.Database.Repository.Implementations .Take(limit) .ToListAsync()); - public Task GetAsync(Guid id) => throw new NotImplementedException(); + public async Task GetAsync(Guid id) + { + return _mapper.Map( + await _context.Students + .Include(s => s.StudentSessions) + .FirstOrDefaultAsync()); + } public async Task UpdateAsync(StudentDTO studentDTO) { diff --git a/Cop.Borovkov.Var3/Lab3.Database/Repository/Interfaces/IStudentRepository.cs b/Cop.Borovkov.Var3/Lab3.Database/Repository/Interfaces/IStudentRepository.cs index 6561dc0..4b1873f 100644 --- a/Cop.Borovkov.Var3/Lab3.Database/Repository/Interfaces/IStudentRepository.cs +++ b/Cop.Borovkov.Var3/Lab3.Database/Repository/Interfaces/IStudentRepository.cs @@ -4,14 +4,14 @@ namespace Lab3.Database.Repository.Interfaces { public interface IStudentRepository { - public Task> GetAsync(int limit = 10000, int offset = 0); + Task> GetAsync(int limit = 10000, int offset = 0); - public Task GetAsync(Guid id); + Task GetAsync(Guid id); - public Task UpdateAsync(StudentDTO studentDTO); + Task UpdateAsync(StudentDTO studentDTO); - public Task DeleteAsync(Guid id); + Task DeleteAsync(Guid id); - public Task CreateAsync(StudentDTO studentDTO); + Task CreateAsync(StudentDTO studentDTO); } } diff --git a/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs b/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs index e9a5049..9a6cb6f 100644 --- a/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs +++ b/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs @@ -30,6 +30,29 @@ namespace Lab3.Forms FormSelector.Fill(await _educationFormRepository.Get()); StartEducationDataPicker.DateStart = DateTime.Now.AddYears(-6); StartEducationDataPicker.DateEnd = DateTime.Now; + + if (_updatedStudentGuid == null) + { + return; + } + var student = await _studentRepository.GetAsync(_updatedStudentGuid.Value); + + NameTextBox.Text = student.Name; + StartEducationDataPicker.Value = student.StartEducation; + FormSelector.ComboBoxSelectedValue = student.EducationForm; + + session1Score.Value = student.StudentSessions + .FirstOrDefault(s => s.Number == 1)?.Score ?? decimal.Zero; + session2Score.Value = student.StudentSessions + .FirstOrDefault(s => s.Number == 2)?.Score ?? decimal.Zero; + session3Score.Value = student.StudentSessions + .FirstOrDefault(s => s.Number == 3)?.Score ?? decimal.Zero; + session4Score.Value = student.StudentSessions + .FirstOrDefault(s => s.Number == 4)?.Score ?? decimal.Zero; + session5Score.Value = student.StudentSessions + .FirstOrDefault(s => s.Number == 5)?.Score ?? decimal.Zero; + session6Score.Value = student.StudentSessions + .FirstOrDefault(s => s.Number == 6)?.Score ?? decimal.Zero; } private async void ButtonSave_ClickAsync(object sender, EventArgs e) diff --git a/Cop.Borovkov.Var3/Lab3/Program.cs b/Cop.Borovkov.Var3/Lab3/Program.cs index b98c3b6..2ac9d73 100644 --- a/Cop.Borovkov.Var3/Lab3/Program.cs +++ b/Cop.Borovkov.Var3/Lab3/Program.cs @@ -21,7 +21,7 @@ namespace Lab3 var app = CreateHostBuilder().Build(); - Application.Run(app.Services.GetRequiredService>()(null)); + Application.Run(app.Services.GetRequiredService()); } static IHostBuilder CreateHostBuilder() From e825cc46c2fccde685e278ed34939f98f17d858d Mon Sep 17 00:00:00 2001 From: bekodeg Date: Thu, 7 Nov 2024 15:54:02 +0400 Subject: [PATCH 09/20] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BA=D0=B0=D1=82=D0=B0=D0=BB=D0=BE=D0=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EducationFormRepository.cs | 1 + .../Lab3/Extensions/DIExtension.cs | 1 + .../Lab3/Forms/CatalogForm.Designer.cs | 76 +++++++++++ Cop.Borovkov.Var3/Lab3/Forms/CatalogForm.cs | 97 ++++++++++++++ Cop.Borovkov.Var3/Lab3/Forms/CatalogForm.resx | 123 ++++++++++++++++++ .../Lab3/Forms/MainForm.Designer.cs | 8 +- Cop.Borovkov.Var3/Lab3/Forms/MainForm.cs | 43 +++++- .../Lab3/Models/StudentViewModel.cs | 7 +- Cop.Borovkov.Var3/Lab3/Program.cs | 3 +- 9 files changed, 345 insertions(+), 14 deletions(-) create mode 100644 Cop.Borovkov.Var3/Lab3/Forms/CatalogForm.Designer.cs create mode 100644 Cop.Borovkov.Var3/Lab3/Forms/CatalogForm.cs create mode 100644 Cop.Borovkov.Var3/Lab3/Forms/CatalogForm.resx diff --git a/Cop.Borovkov.Var3/Lab3.Database/Repository/Implementations/EducationFormRepository.cs b/Cop.Borovkov.Var3/Lab3.Database/Repository/Implementations/EducationFormRepository.cs index 5bcb5d9..19b88c1 100644 --- a/Cop.Borovkov.Var3/Lab3.Database/Repository/Implementations/EducationFormRepository.cs +++ b/Cop.Borovkov.Var3/Lab3.Database/Repository/Implementations/EducationFormRepository.cs @@ -29,6 +29,7 @@ namespace Lab3.Database.Repository.Implementations Id = Guid.NewGuid(), Name = f, })); + await _context.SaveChangesAsync(); } } } diff --git a/Cop.Borovkov.Var3/Lab3/Extensions/DIExtension.cs b/Cop.Borovkov.Var3/Lab3/Extensions/DIExtension.cs index 11ef788..9199bff 100644 --- a/Cop.Borovkov.Var3/Lab3/Extensions/DIExtension.cs +++ b/Cop.Borovkov.Var3/Lab3/Extensions/DIExtension.cs @@ -25,6 +25,7 @@ namespace Lab3.Extensions this IServiceCollection services) { services.AddScoped(); + services.AddScoped(); services.AddScoped>(sp => (id => new CreateForm( diff --git a/Cop.Borovkov.Var3/Lab3/Forms/CatalogForm.Designer.cs b/Cop.Borovkov.Var3/Lab3/Forms/CatalogForm.Designer.cs new file mode 100644 index 0000000..671312e --- /dev/null +++ b/Cop.Borovkov.Var3/Lab3/Forms/CatalogForm.Designer.cs @@ -0,0 +1,76 @@ +namespace Lab3.Forms +{ + partial class CatalogForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + Catalog = new DataGridView(); + EducationForm = new DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)Catalog).BeginInit(); + SuspendLayout(); + // + // Catalog + // + Catalog.AllowUserToAddRows = false; + Catalog.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + Catalog.Columns.AddRange(new DataGridViewColumn[] { EducationForm }); + Catalog.Dock = DockStyle.Fill; + Catalog.Location = new Point(0, 0); + Catalog.Name = "Catalog"; + Catalog.RowHeadersWidth = 51; + Catalog.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + Catalog.Size = new Size(800, 450); + Catalog.TabIndex = 0; + Catalog.CellEndEdit += Catalog_CellEndEditAsync; + Catalog.KeyDown += Catalog_KeyDownAsync; + // + // EducationForm + // + EducationForm.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + EducationForm.HeaderText = "Форма обучения"; + EducationForm.MinimumWidth = 6; + EducationForm.Name = "EducationForm"; + // + // CatalogForm + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(Catalog); + Name = "CatalogForm"; + Text = "CatalogForm"; + Load += CatalogForm_LoadAsync; + ((System.ComponentModel.ISupportInitialize)Catalog).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView Catalog; + private DataGridViewTextBoxColumn EducationForm; + } +} \ No newline at end of file diff --git a/Cop.Borovkov.Var3/Lab3/Forms/CatalogForm.cs b/Cop.Borovkov.Var3/Lab3/Forms/CatalogForm.cs new file mode 100644 index 0000000..03cbaa6 --- /dev/null +++ b/Cop.Borovkov.Var3/Lab3/Forms/CatalogForm.cs @@ -0,0 +1,97 @@ +using Lab3.Database.Repository.Interfaces; + +namespace Lab3.Forms +{ + public partial class CatalogForm : Form + { + private readonly IEducationFormRepository _repository; + + public CatalogForm(IEducationFormRepository educationFormRepository) + { + _repository = educationFormRepository; + InitializeComponent(); + } + + private async void CatalogForm_LoadAsync(object sender, EventArgs e) + { + Catalog.Rows.Clear(); + + var values = (await _repository.Get()).ToList(); + for (int i = 0; i < values.Count; i++) + { + Catalog.Rows.Add(); + Catalog.Rows[i].Cells[0].Value = values[i]; + } + } + + private async void Catalog_CellEndEditAsync(object sender, DataGridViewCellEventArgs e) + { + await LoadAsync(); + } + + private async Task LoadAsync() + { + try + { + List values = new List(); + + for (int i = 0; i < Catalog.Rows.Count; ++i) + { + string? val = (string?)Catalog.Rows[i].Cells[0].Value; + if (string.IsNullOrEmpty(val)) + { + MessageBox.Show( + "Неверные данные", + "Ошибка", + MessageBoxButtons.OK, + MessageBoxIcon.Error); + return; + } + values.Add(val); + } + + await _repository.Update(values); + } + catch (Exception ex) + { + MessageBox.Show( + ex.Message, + "Ошибка", + MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private async void Catalog_KeyDownAsync(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Insert) + { + Catalog.Rows.Add(); + } + + if (e.KeyCode == Keys.Delete && Catalog.SelectedRows.Count == 1) + { + if (MessageBox.Show( + "Удалить?", + "Удаление", + MessageBoxButtons.YesNo, + MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + Catalog.Rows.RemoveAt(Catalog.SelectedRows[0].Index); + await LoadAsync(); + } + catch (Exception ex) + { + MessageBox.Show( + ex.Message, + "Ошибка", + MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + } + } +} diff --git a/Cop.Borovkov.Var3/Lab3/Forms/CatalogForm.resx b/Cop.Borovkov.Var3/Lab3/Forms/CatalogForm.resx new file mode 100644 index 0000000..f789fea --- /dev/null +++ b/Cop.Borovkov.Var3/Lab3/Forms/CatalogForm.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + \ No newline at end of file diff --git a/Cop.Borovkov.Var3/Lab3/Forms/MainForm.Designer.cs b/Cop.Borovkov.Var3/Lab3/Forms/MainForm.Designer.cs index 0e30590..383fc4f 100644 --- a/Cop.Borovkov.Var3/Lab3/Forms/MainForm.Designer.cs +++ b/Cop.Borovkov.Var3/Lab3/Forms/MainForm.Designer.cs @@ -28,16 +28,15 @@ /// private void InitializeComponent() { - StudentsListBox = new ComponentsLibrary.ListBoxValues(); + StudentsListBox = new Cop.Borovkov.Var3.Components.CustomListBox(); SuspendLayout(); // // StudentsListBox // StudentsListBox.Dock = DockStyle.Fill; StudentsListBox.Location = new Point(0, 0); - StudentsListBox.Margin = new Padding(3, 4, 3, 4); StudentsListBox.Name = "StudentsListBox"; - StudentsListBox.SelectedIndex = -1; + StudentsListBox.Selected = ""; StudentsListBox.Size = new Size(800, 450); StudentsListBox.TabIndex = 0; // @@ -50,11 +49,12 @@ Name = "MainForm"; Text = "MainForm"; Load += MainForm_LoadAsync; + KeyDown += MainForm_KeyDown; ResumeLayout(false); } #endregion - private ComponentsLibrary.ListBoxValues StudentsListBox; + private Cop.Borovkov.Var3.Components.CustomListBox StudentsListBox; } } \ No newline at end of file diff --git a/Cop.Borovkov.Var3/Lab3/Forms/MainForm.cs b/Cop.Borovkov.Var3/Lab3/Forms/MainForm.cs index 5a84939..d6754c4 100644 --- a/Cop.Borovkov.Var3/Lab3/Forms/MainForm.cs +++ b/Cop.Borovkov.Var3/Lab3/Forms/MainForm.cs @@ -8,20 +8,57 @@ namespace Lab3.Forms { private readonly IStudentRepository _studentRepository; private readonly IMapper _mapper; + private readonly Func _getCreateOrUpdateForm; public MainForm( IStudentRepository repository, - IMapper mapper) + IMapper mapper, + Func getCreateOrUpdateForm) { - _studentRepository = repository; + _studentRepository = repository; _mapper = mapper; + + _getCreateOrUpdateForm = getCreateOrUpdateForm; + InitializeComponent(); } private async void MainForm_LoadAsync(object sender, EventArgs e) { var students = _mapper.Map>(await _studentRepository.GetAsync()); - StudentsListBox.FillListBox(students); + StudentsListBox.FillValues( + students.Select(s => string.Join(" ", + [ + s.Id, + s.Name, + s.EducationForm, + s.StartEducation.ToLongDateString(), + s.SessionMarks, + ] + )) + ); + } + + private void MainForm_KeyDown(object sender, KeyEventArgs e) + { + if (e.Modifiers != Keys.Control) + { + return; + } + + switch (e.KeyCode) + { + case Keys.A: + _getCreateOrUpdateForm(null).Show(this); + break; + case Keys.U: + _getCreateOrUpdateForm( + Guid.Parse(StudentsListBox.Selected.Split()[0]) + ).Show(this); + break; + default: + return; + } } } } diff --git a/Cop.Borovkov.Var3/Lab3/Models/StudentViewModel.cs b/Cop.Borovkov.Var3/Lab3/Models/StudentViewModel.cs index 54e9145..9e9ca4a 100644 --- a/Cop.Borovkov.Var3/Lab3/Models/StudentViewModel.cs +++ b/Cop.Borovkov.Var3/Lab3/Models/StudentViewModel.cs @@ -6,10 +6,7 @@ namespace Lab3.Models public record StudentViewModel : StudentDTO { public string SessionMarks => string.Join("; ", StudentSessions - .Select(s => string.Format( - CultureInfo.InvariantCulture, - "сессия{}: {0:f2}", - s.Number, - s.Score))); + .OrderBy(s => s.Number) + .Select(s => $"сессия{s.Number:d}: {s.Score:n2}")); } } diff --git a/Cop.Borovkov.Var3/Lab3/Program.cs b/Cop.Borovkov.Var3/Lab3/Program.cs index 2ac9d73..ff96b66 100644 --- a/Cop.Borovkov.Var3/Lab3/Program.cs +++ b/Cop.Borovkov.Var3/Lab3/Program.cs @@ -1,4 +1,3 @@ -using Lab3.Database.Extensions; using Lab3.Extensions; using Lab3.Forms; using Microsoft.Extensions.Configuration; @@ -21,7 +20,7 @@ namespace Lab3 var app = CreateHostBuilder().Build(); - Application.Run(app.Services.GetRequiredService()); + Application.Run(app.Services.GetRequiredService()); } static IHostBuilder CreateHostBuilder() From 7ca62ddb1dd9931a62338ae8d2523e6fef17760e Mon Sep 17 00:00:00 2001 From: bekodeg Date: Thu, 7 Nov 2024 17:36:09 +0400 Subject: [PATCH 10/20] =?UTF-8?q?=D0=9F=D0=BE=D1=87=D1=82=D0=B8=20=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cop.Borovkov.Var3/Cop.Borovkov.Var3.sln | 10 +- .../Cop.Borovkov.Var3.csproj | 19 +- .../PdfCreator}/Enums/PdfAlignmentType.cs | 0 .../PdfCreator}/Enums/PdfLegendPosition.cs | 0 .../PdfCreator}/Enums/PdfMargin.cs | 0 .../PdfCreator}/Enums/PdfStyleType.cs | 0 .../PdfCreator}/Interfaces/IPdfColumnItem.cs | 0 .../PdfCreator}/Interfaces/IPdfCreator.cs | 0 .../PdfCreator}/Interfaces/IPdfElement.cs | 0 .../Models/ImageModels/MiraDocImage.cs | 0 .../Models/ImageModels/PdfImage.cs | 0 .../Models/PieChartModel/PdfHistogramData.cs | 0 .../Models/PieChartModel/PdfHistogramModel.cs | 0 .../Models/PieChartModel/PdfPieChartData.cs | 0 .../Models/PieChartModel/PdfPieChartModel.cs | 0 .../Models/TableModels/PDFSimpleTable.cs | 0 .../Models/TableModels/PDFSimpleTableRow.cs | 0 .../Models/TableModels/PdfTable.cs | 0 .../Models/TableModels/PdfTableColumn.cs | 0 .../Models/TableModels/PdfTableColumnGroup.cs | 0 .../PdfCreator}/Models/TextModels/PdfList.cs | 0 .../Models/TextModels/PdfParagraph.cs | 0 .../PdfCreator}/PdfCreator.cs | 13 +- .../PdfCreator}/README.md | 0 .../Implementations/StudentRepository.cs | 15 +- .../Interfaces/IStudentRepository.cs | 2 +- Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs | 44 ++-- .../Lab3/Forms/MainForm.Designer.cs | 8 +- Cop.Borovkov.Var3/Lab3/Forms/MainForm.cs | 233 ++++++++++++++++-- Cop.Borovkov.Var3/Lab3/Forms/MainForm.resx | 9 + Cop.Borovkov.Var3/Lab3/Lab3.csproj | 2 +- Cop.Borovkov.Var3/Lab3/Program.cs | 2 +- .../PIHelperSh.PdfCreator.csproj | 14 -- 33 files changed, 294 insertions(+), 77 deletions(-) rename Cop.Borovkov.Var3/{PIHelperSh.PdfCreater => Cop.Borovkov.Var3/PdfCreator}/Enums/PdfAlignmentType.cs (100%) rename Cop.Borovkov.Var3/{PIHelperSh.PdfCreater => Cop.Borovkov.Var3/PdfCreator}/Enums/PdfLegendPosition.cs (100%) rename Cop.Borovkov.Var3/{PIHelperSh.PdfCreater => Cop.Borovkov.Var3/PdfCreator}/Enums/PdfMargin.cs (100%) rename Cop.Borovkov.Var3/{PIHelperSh.PdfCreater => Cop.Borovkov.Var3/PdfCreator}/Enums/PdfStyleType.cs (100%) rename Cop.Borovkov.Var3/{PIHelperSh.PdfCreater => Cop.Borovkov.Var3/PdfCreator}/Interfaces/IPdfColumnItem.cs (100%) rename Cop.Borovkov.Var3/{PIHelperSh.PdfCreater => Cop.Borovkov.Var3/PdfCreator}/Interfaces/IPdfCreator.cs (100%) rename Cop.Borovkov.Var3/{PIHelperSh.PdfCreater => Cop.Borovkov.Var3/PdfCreator}/Interfaces/IPdfElement.cs (100%) rename Cop.Borovkov.Var3/{PIHelperSh.PdfCreater => Cop.Borovkov.Var3/PdfCreator}/Models/ImageModels/MiraDocImage.cs (100%) rename Cop.Borovkov.Var3/{PIHelperSh.PdfCreater => Cop.Borovkov.Var3/PdfCreator}/Models/ImageModels/PdfImage.cs (100%) rename Cop.Borovkov.Var3/{PIHelperSh.PdfCreater => Cop.Borovkov.Var3/PdfCreator}/Models/PieChartModel/PdfHistogramData.cs (100%) rename Cop.Borovkov.Var3/{PIHelperSh.PdfCreater => Cop.Borovkov.Var3/PdfCreator}/Models/PieChartModel/PdfHistogramModel.cs (100%) rename Cop.Borovkov.Var3/{PIHelperSh.PdfCreater => Cop.Borovkov.Var3/PdfCreator}/Models/PieChartModel/PdfPieChartData.cs (100%) rename Cop.Borovkov.Var3/{PIHelperSh.PdfCreater => Cop.Borovkov.Var3/PdfCreator}/Models/PieChartModel/PdfPieChartModel.cs (100%) rename Cop.Borovkov.Var3/{PIHelperSh.PdfCreater => Cop.Borovkov.Var3/PdfCreator}/Models/TableModels/PDFSimpleTable.cs (100%) rename Cop.Borovkov.Var3/{PIHelperSh.PdfCreater => Cop.Borovkov.Var3/PdfCreator}/Models/TableModels/PDFSimpleTableRow.cs (100%) rename Cop.Borovkov.Var3/{PIHelperSh.PdfCreater => Cop.Borovkov.Var3/PdfCreator}/Models/TableModels/PdfTable.cs (100%) rename Cop.Borovkov.Var3/{PIHelperSh.PdfCreater => Cop.Borovkov.Var3/PdfCreator}/Models/TableModels/PdfTableColumn.cs (100%) rename Cop.Borovkov.Var3/{PIHelperSh.PdfCreater => Cop.Borovkov.Var3/PdfCreator}/Models/TableModels/PdfTableColumnGroup.cs (100%) rename Cop.Borovkov.Var3/{PIHelperSh.PdfCreater => Cop.Borovkov.Var3/PdfCreator}/Models/TextModels/PdfList.cs (100%) rename Cop.Borovkov.Var3/{PIHelperSh.PdfCreater => Cop.Borovkov.Var3/PdfCreator}/Models/TextModels/PdfParagraph.cs (100%) rename Cop.Borovkov.Var3/{PIHelperSh.PdfCreater => Cop.Borovkov.Var3/PdfCreator}/PdfCreator.cs (97%) rename Cop.Borovkov.Var3/{PIHelperSh.PdfCreater => Cop.Borovkov.Var3/PdfCreator}/README.md (100%) diff --git a/Cop.Borovkov.Var3/Cop.Borovkov.Var3.sln b/Cop.Borovkov.Var3/Cop.Borovkov.Var3.sln index 2f42979..1c8d7d9 100644 --- a/Cop.Borovkov.Var3/Cop.Borovkov.Var3.sln +++ b/Cop.Borovkov.Var3/Cop.Borovkov.Var3.sln @@ -7,11 +7,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cop.Borovkov.Var3", "Cop.Bo EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestCustomComponents", "TestCustomComponents\TestCustomComponents.csproj", "{E2C46D08-ACCE-4547-922B-E92AD76D99C8}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PIHelperSh.PdfCreator", "PIHelperSh.PdfCreater\PIHelperSh.PdfCreator.csproj", "{572BD835-A500-43C9-A66F-648540F4A1C8}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lab3", "Lab3\Lab3.csproj", "{1E630CC7-090F-471C-ADA1-74107CF3DC2A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab3", "Lab3\Lab3.csproj", "{1E630CC7-090F-471C-ADA1-74107CF3DC2A}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab3.Database", "Lab3.Database\Lab3.Database.csproj", "{698DE9E8-7885-4F98-AFE3-9A9C6CD2FCF5}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lab3.Database", "Lab3.Database\Lab3.Database.csproj", "{698DE9E8-7885-4F98-AFE3-9A9C6CD2FCF5}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -27,10 +25,6 @@ Global {E2C46D08-ACCE-4547-922B-E92AD76D99C8}.Debug|Any CPU.Build.0 = Debug|Any CPU {E2C46D08-ACCE-4547-922B-E92AD76D99C8}.Release|Any CPU.ActiveCfg = Release|Any CPU {E2C46D08-ACCE-4547-922B-E92AD76D99C8}.Release|Any CPU.Build.0 = Release|Any CPU - {572BD835-A500-43C9-A66F-648540F4A1C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {572BD835-A500-43C9-A66F-648540F4A1C8}.Debug|Any CPU.Build.0 = Debug|Any CPU - {572BD835-A500-43C9-A66F-648540F4A1C8}.Release|Any CPU.ActiveCfg = Release|Any CPU - {572BD835-A500-43C9-A66F-648540F4A1C8}.Release|Any CPU.Build.0 = Release|Any CPU {1E630CC7-090F-471C-ADA1-74107CF3DC2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {1E630CC7-090F-471C-ADA1-74107CF3DC2A}.Debug|Any CPU.Build.0 = Debug|Any CPU {1E630CC7-090F-471C-ADA1-74107CF3DC2A}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Cop.Borovkov.Var3.csproj b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Cop.Borovkov.Var3.csproj index e32cffc..7fd5f42 100644 --- a/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Cop.Borovkov.Var3.csproj +++ b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Cop.Borovkov.Var3.csproj @@ -7,11 +7,26 @@ enable True $(AssemblyName) - $(VersionPrefix)8.0.1 + $(VersionPrefix)8.0.2 - + + \ + True + + + + + + + + + + + \ + True + diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Enums/PdfAlignmentType.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Enums/PdfAlignmentType.cs similarity index 100% rename from Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Enums/PdfAlignmentType.cs rename to Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Enums/PdfAlignmentType.cs diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Enums/PdfLegendPosition.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Enums/PdfLegendPosition.cs similarity index 100% rename from Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Enums/PdfLegendPosition.cs rename to Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Enums/PdfLegendPosition.cs diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Enums/PdfMargin.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Enums/PdfMargin.cs similarity index 100% rename from Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Enums/PdfMargin.cs rename to Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Enums/PdfMargin.cs diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Enums/PdfStyleType.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Enums/PdfStyleType.cs similarity index 100% rename from Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Enums/PdfStyleType.cs rename to Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Enums/PdfStyleType.cs diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Interfaces/IPdfColumnItem.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Interfaces/IPdfColumnItem.cs similarity index 100% rename from Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Interfaces/IPdfColumnItem.cs rename to Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Interfaces/IPdfColumnItem.cs diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Interfaces/IPdfCreator.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Interfaces/IPdfCreator.cs similarity index 100% rename from Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Interfaces/IPdfCreator.cs rename to Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Interfaces/IPdfCreator.cs diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Interfaces/IPdfElement.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Interfaces/IPdfElement.cs similarity index 100% rename from Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Interfaces/IPdfElement.cs rename to Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Interfaces/IPdfElement.cs diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/ImageModels/MiraDocImage.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/ImageModels/MiraDocImage.cs similarity index 100% rename from Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/ImageModels/MiraDocImage.cs rename to Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/ImageModels/MiraDocImage.cs diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/ImageModels/PdfImage.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/ImageModels/PdfImage.cs similarity index 100% rename from Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/ImageModels/PdfImage.cs rename to Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/ImageModels/PdfImage.cs diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/PieChartModel/PdfHistogramData.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/PieChartModel/PdfHistogramData.cs similarity index 100% rename from Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/PieChartModel/PdfHistogramData.cs rename to Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/PieChartModel/PdfHistogramData.cs diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/PieChartModel/PdfHistogramModel.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/PieChartModel/PdfHistogramModel.cs similarity index 100% rename from Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/PieChartModel/PdfHistogramModel.cs rename to Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/PieChartModel/PdfHistogramModel.cs diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/PieChartModel/PdfPieChartData.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/PieChartModel/PdfPieChartData.cs similarity index 100% rename from Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/PieChartModel/PdfPieChartData.cs rename to Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/PieChartModel/PdfPieChartData.cs diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/PieChartModel/PdfPieChartModel.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/PieChartModel/PdfPieChartModel.cs similarity index 100% rename from Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/PieChartModel/PdfPieChartModel.cs rename to Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/PieChartModel/PdfPieChartModel.cs diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/TableModels/PDFSimpleTable.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TableModels/PDFSimpleTable.cs similarity index 100% rename from Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/TableModels/PDFSimpleTable.cs rename to Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TableModels/PDFSimpleTable.cs diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/TableModels/PDFSimpleTableRow.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TableModels/PDFSimpleTableRow.cs similarity index 100% rename from Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/TableModels/PDFSimpleTableRow.cs rename to Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TableModels/PDFSimpleTableRow.cs diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/TableModels/PdfTable.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TableModels/PdfTable.cs similarity index 100% rename from Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/TableModels/PdfTable.cs rename to Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TableModels/PdfTable.cs diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/TableModels/PdfTableColumn.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TableModels/PdfTableColumn.cs similarity index 100% rename from Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/TableModels/PdfTableColumn.cs rename to Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TableModels/PdfTableColumn.cs diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/TableModels/PdfTableColumnGroup.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TableModels/PdfTableColumnGroup.cs similarity index 100% rename from Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/TableModels/PdfTableColumnGroup.cs rename to Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TableModels/PdfTableColumnGroup.cs diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/TextModels/PdfList.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TextModels/PdfList.cs similarity index 100% rename from Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/TextModels/PdfList.cs rename to Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TextModels/PdfList.cs diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/TextModels/PdfParagraph.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TextModels/PdfParagraph.cs similarity index 100% rename from Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/TextModels/PdfParagraph.cs rename to Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TextModels/PdfParagraph.cs diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/PdfCreator.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/PdfCreator.cs similarity index 97% rename from Cop.Borovkov.Var3/PIHelperSh.PdfCreater/PdfCreator.cs rename to Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/PdfCreator.cs index e5dfad9..3fecdf0 100644 --- a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/PdfCreator.cs +++ b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/PdfCreator.cs @@ -1,8 +1,6 @@ using MigraDoc.DocumentObjectModel; -using System.Text; using MigraDoc.Rendering; using MigraDoc.DocumentObjectModel.Tables; -using System.Reflection; using MigraDoc.DocumentObjectModel.Shapes.Charts; using PIHelperSh.Core.Extensions; using PIHelperSh.PdfCreator.Enums; @@ -11,6 +9,11 @@ using PIHelperSh.PdfCreator.Models.TextModels; using PIHelperSh.PdfCreator.Models.ImageModels; using PIHelperSh.PdfCreator.Models.PieChartModel; using PIHelperSh.PdfCreator.Interfaces; +using System.Text; +using TabAlignment = MigraDoc.DocumentObjectModel.TabAlignment; +using System.Reflection; +using HorizontalAlignment = MigraDoc.DocumentObjectModel.Shapes.Charts.HorizontalAlignment; +using Color = MigraDoc.DocumentObjectModel.Color; namespace PIHelperSh.PdfCreator { @@ -413,7 +416,7 @@ namespace PIHelperSh.PdfCreator if (rowHeaded) { - _section!.PageSetup.Orientation = Orientation.Landscape; + _section!.PageSetup.Orientation = MigraDoc.DocumentObjectModel.Orientation.Landscape; _section.PageSetup.LeftMargin = 10; MakeTableWithHederInRow(_document.LastSection.AddTable(), header); return; @@ -456,7 +459,7 @@ namespace PIHelperSh.PdfCreator if (tableData.ChangePageOrientation) { - _section!.PageSetup.Orientation = Orientation.Landscape; + _section!.PageSetup.Orientation = MigraDoc.DocumentObjectModel.Orientation.Landscape; _section.PageSetup.LeftMargin = 10; _section.PageSetup.BottomMargin = 5; } @@ -535,7 +538,7 @@ namespace PIHelperSh.PdfCreator if (item.Color.HasValue) { - series.FillFormat.Color = new Color((uint)item.Color.Value.ToArgb()); + series.FillFormat.Color = new MigraDoc.DocumentObjectModel.Color((uint)item.Color.Value.ToArgb()); } } diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/README.md b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/README.md similarity index 100% rename from Cop.Borovkov.Var3/PIHelperSh.PdfCreater/README.md rename to Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/README.md diff --git a/Cop.Borovkov.Var3/Lab3.Database/Repository/Implementations/StudentRepository.cs b/Cop.Borovkov.Var3/Lab3.Database/Repository/Implementations/StudentRepository.cs index 0b13144..108f8cf 100644 --- a/Cop.Borovkov.Var3/Lab3.Database/Repository/Implementations/StudentRepository.cs +++ b/Cop.Borovkov.Var3/Lab3.Database/Repository/Implementations/StudentRepository.cs @@ -29,7 +29,20 @@ namespace Lab3.Database.Repository.Implementations return _mapper.Map(result.Entity); } - public Task DeleteAsync(Guid id) => throw new NotImplementedException(); + public async Task DeleteAsync(Guid id) + { + var student = await _context.Students.FindAsync(id); + + if (student == null) + { + return null; + } + + var result = _context.Students.Remove(student); + await _context.SaveChangesAsync(); + + return _mapper.Map(result.Entity); + } public async Task> GetAsync(int limit = 10000, int offset = 0) => _mapper.Map>( diff --git a/Cop.Borovkov.Var3/Lab3.Database/Repository/Interfaces/IStudentRepository.cs b/Cop.Borovkov.Var3/Lab3.Database/Repository/Interfaces/IStudentRepository.cs index 4b1873f..e653df3 100644 --- a/Cop.Borovkov.Var3/Lab3.Database/Repository/Interfaces/IStudentRepository.cs +++ b/Cop.Borovkov.Var3/Lab3.Database/Repository/Interfaces/IStudentRepository.cs @@ -10,7 +10,7 @@ namespace Lab3.Database.Repository.Interfaces Task UpdateAsync(StudentDTO studentDTO); - Task DeleteAsync(Guid id); + Task DeleteAsync(Guid id); Task CreateAsync(StudentDTO studentDTO); } diff --git a/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs b/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs index 9a6cb6f..1929461 100644 --- a/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs +++ b/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs @@ -57,20 +57,22 @@ namespace Lab3.Forms private async void ButtonSave_ClickAsync(object sender, EventArgs e) { - if (string.IsNullOrEmpty(NameTextBox.Text) + try + { + if (string.IsNullOrEmpty(NameTextBox.Text) || string.IsNullOrEmpty(FormSelector.ComboBoxSelectedValue)) - { - throw new Exception(); - } + { + throw new Exception(); + } - StudentDTO student = new() - { - Id = _updatedStudentGuid ?? Guid.NewGuid(), - Name = NameTextBox.Text, - StartEducation = StartEducationDataPicker.Value, - EducationForm = FormSelector.ComboBoxSelectedValue, - StudentSessions = [ - new(){ + StudentDTO student = new() + { + Id = _updatedStudentGuid ?? Guid.NewGuid(), + Name = NameTextBox.Text, + StartEducation = StartEducationDataPicker.Value, + EducationForm = FormSelector.ComboBoxSelectedValue, + StudentSessions = [ + new(){ Score = session1Score.Value, Number = 1, }, @@ -95,15 +97,21 @@ namespace Lab3.Forms Number = 6, }, ], - }; + }; - if (_updatedStudentGuid != null) - { - await _studentRepository.UpdateAsync(student); + if (_updatedStudentGuid != null) + { + await _studentRepository.UpdateAsync(student); + } + else + { + await _studentRepository.CreateAsync(student); + } + Close(); } - else + catch (Exception ex) { - await _studentRepository.CreateAsync(student); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } diff --git a/Cop.Borovkov.Var3/Lab3/Forms/MainForm.Designer.cs b/Cop.Borovkov.Var3/Lab3/Forms/MainForm.Designer.cs index 383fc4f..c90e979 100644 --- a/Cop.Borovkov.Var3/Lab3/Forms/MainForm.Designer.cs +++ b/Cop.Borovkov.Var3/Lab3/Forms/MainForm.Designer.cs @@ -28,7 +28,11 @@ /// private void InitializeComponent() { + components = new System.ComponentModel.Container(); StudentsListBox = new Cop.Borovkov.Var3.Components.CustomListBox(); + SimpleTableCreator = new Cop.Borovkov.Var3.Components.CustomPdfTable(components); + ExcelTableCreator = new CustomComponentsVar2.CustomExcelTable(components); + WordDiogramCreator = new ComponentsLibrary.ComponentDiagram(components); SuspendLayout(); // // StudentsListBox @@ -49,12 +53,14 @@ Name = "MainForm"; Text = "MainForm"; Load += MainForm_LoadAsync; - KeyDown += MainForm_KeyDown; ResumeLayout(false); } #endregion private Cop.Borovkov.Var3.Components.CustomListBox StudentsListBox; + private Cop.Borovkov.Var3.Components.CustomPdfTable SimpleTableCreator; + private CustomComponentsVar2.CustomExcelTable ExcelTableCreator; + private ComponentsLibrary.ComponentDiagram WordDiogramCreator; } } \ No newline at end of file diff --git a/Cop.Borovkov.Var3/Lab3/Forms/MainForm.cs b/Cop.Borovkov.Var3/Lab3/Forms/MainForm.cs index d6754c4..ba949f3 100644 --- a/Cop.Borovkov.Var3/Lab3/Forms/MainForm.cs +++ b/Cop.Borovkov.Var3/Lab3/Forms/MainForm.cs @@ -1,6 +1,13 @@ using AutoMapper; +using ComponentsLibrary.entities; +using ComponentsLibrary.entities.enums; +using DocumentFormat.OpenXml.Bibliography; +using DocumentFormat.OpenXml.Drawing; +using DocumentFormat.OpenXml.Spreadsheet; +using Lab3.Database.DTO; using Lab3.Database.Repository.Interfaces; using Lab3.Models; +using NPOI.OpenXml4Net.OPC.Internal; namespace Lab3.Forms { @@ -10,6 +17,8 @@ namespace Lab3.Forms private readonly IMapper _mapper; private readonly Func _getCreateOrUpdateForm; + private bool _cont = false; + public MainForm( IStudentRepository repository, IMapper mapper, @@ -23,42 +32,216 @@ namespace Lab3.Forms InitializeComponent(); } - private async void MainForm_LoadAsync(object sender, EventArgs e) + private void MainForm_LoadAsync(object sender, EventArgs e) { - var students = _mapper.Map>(await _studentRepository.GetAsync()); - StudentsListBox.FillValues( - students.Select(s => string.Join(" ", - [ - s.Id, + LoadAsync(); + } + + private async void LoadAsync() + { + try + { + var students = _mapper.Map>(await _studentRepository.GetAsync()); + StudentsListBox.FillValues( + students.Select(s => string.Join(" ", + [ + s.Id, s.Name, s.EducationForm, s.StartEducation.ToLongDateString(), s.SessionMarks, - ] - )) - ); + ] + )) + ); + } + catch (Exception ex) + { + MessageBox.Show( + ex.Message, + "Ошибка", + MessageBoxButtons.OK, + MessageBoxIcon.Error); + } } - private void MainForm_KeyDown(object sender, KeyEventArgs e) + private async void RemoveStudentAsync() { - if (e.Modifiers != Keys.Control) + if (MessageBox.Show("Удалить запись", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { - return; + try + { + await _studentRepository + .DeleteAsync(Guid.Parse(StudentsListBox.Selected.Split()[0])); + LoadAsync(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private async void CreateSimpleDocAsync() + { + try + { + using var saveFileDialog = new SaveFileDialog + { + Filter = "pdf|*.pdf" + }; + if (saveFileDialog.ShowDialog() != DialogResult.OK) + { + return; + } + + var values = (await _studentRepository.GetAsync()) + .Select(s => s.StudentSessions + .OrderBy(x => x.Number) + .Select(x => x.Score.ToString()) + .ToArray()) + .ToArray(); + var tables = new string[values.Length, 6]; + + for (int i = 0; i < values.Length; ++i) + { + for (int j = 0; j < 6; ++j) + { + tables[i, j] = values[i][j]; + } + } + + SimpleTableCreator.SaveToPdf(new() + { + FilePath = saveFileDialog.FileName, + Title = "Сессии", + Tables = [tables] + }); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private async void CreateTableAsync() + { + try + { + using var saveFileDialog = new SaveFileDialog + { + Filter = "xlsx|*.xlsx" + }; + if (saveFileDialog.ShowDialog() != DialogResult.OK) + { + return; + } + ExcelTableCreator.SaveToExcel(new() + { + FilePath = saveFileDialog.FileName, + Title = "Студенты", + Headers = + [ + ("Id", nameof(StudentDTO.Id)), + ("ФИО", nameof(StudentDTO.Name)), + ("Форма обучения", nameof(StudentDTO.EducationForm)), + ("Дата поступления", nameof(StudentDTO.StartEducation)), + ], + HeaderGroups = [new() { + GroupHeader = "Образование", + FirstHeader = 2, + LastHeader = 3, + }], + Values = await _studentRepository.GetAsync() + }); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private async void CreateWordDocAsync() + { + try + { + using var saveFileDialog = new SaveFileDialog + { + Filter = "docx|*.docx" + }; + if (saveFileDialog.ShowDialog() != DialogResult.OK) + { + return; + } + + var data = (await _studentRepository.GetAsync()) + .GroupBy(s => s.EducationForm) + .Select(s => new DataLine( + s.Key, + s.GroupBy(x => x.StartEducation.Year) + .Select(x => (year: x.Key.ToString(), count: (double)x.Count())) + .ToArray())) + .ToList(); + + WordDiogramCreator.AddDiagram( + new( + saveFileDialog.FileName, + "Поступления", + "Диограмма", + + EnumAreaLegend.Bottom, + data + ) + ); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + protected override bool ProcessCmdKey(ref Message msg, Keys keyData) + { + if (keyData == (Keys.ControlKey | Keys.Control)) _cont = true; + + if (_cont && keyData == Keys.A) + { + _getCreateOrUpdateForm(null).ShowDialog(this); + LoadAsync(); + } + else if (_cont && keyData == Keys.U) + { + var elem = StudentsListBox.Selected; + _getCreateOrUpdateForm( + Guid.Parse(elem.Split()[0]) + ).ShowDialog(this); + LoadAsync(); + } + else if (_cont && keyData == Keys.D) + { + RemoveStudentAsync(); + } + else if (_cont && keyData == Keys.S) + { + CreateSimpleDocAsync(); + } + else if (_cont && keyData == Keys.T) + { + CreateTableAsync(); + } + else if (_cont && keyData == Keys.C) + { + CreateWordDocAsync(); } - switch (e.KeyCode) - { - case Keys.A: - _getCreateOrUpdateForm(null).Show(this); - break; - case Keys.U: - _getCreateOrUpdateForm( - Guid.Parse(StudentsListBox.Selected.Split()[0]) - ).Show(this); - break; - default: - return; - } + if (keyData == Keys.A || + keyData == Keys.U || + keyData == Keys.D || + keyData == Keys.S || + keyData == Keys.T || + keyData == Keys.C) _cont = false; + //if (keyData != Keys.None && keyData != (System.Windows.Forms.Keys.ControlKey | System.Windows.Forms.Keys.Control)) cont = false; + return true; + return base.ProcessCmdKey(ref msg, keyData); } } } diff --git a/Cop.Borovkov.Var3/Lab3/Forms/MainForm.resx b/Cop.Borovkov.Var3/Lab3/Forms/MainForm.resx index 8b2ff64..8579cb7 100644 --- a/Cop.Borovkov.Var3/Lab3/Forms/MainForm.resx +++ b/Cop.Borovkov.Var3/Lab3/Forms/MainForm.resx @@ -117,4 +117,13 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + + + 203, 17 + + + 377, 17 + \ No newline at end of file diff --git a/Cop.Borovkov.Var3/Lab3/Lab3.csproj b/Cop.Borovkov.Var3/Lab3/Lab3.csproj index 19346e9..8a7a992 100644 --- a/Cop.Borovkov.Var3/Lab3/Lab3.csproj +++ b/Cop.Borovkov.Var3/Lab3/Lab3.csproj @@ -15,7 +15,7 @@ - + diff --git a/Cop.Borovkov.Var3/Lab3/Program.cs b/Cop.Borovkov.Var3/Lab3/Program.cs index ff96b66..8cbc6aa 100644 --- a/Cop.Borovkov.Var3/Lab3/Program.cs +++ b/Cop.Borovkov.Var3/Lab3/Program.cs @@ -20,7 +20,7 @@ namespace Lab3 var app = CreateHostBuilder().Build(); - Application.Run(app.Services.GetRequiredService()); + Application.Run(app.Services.GetRequiredService()); } static IHostBuilder CreateHostBuilder() diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/PIHelperSh.PdfCreator.csproj b/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/PIHelperSh.PdfCreator.csproj index ebb8d93..99f55df 100644 --- a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/PIHelperSh.PdfCreator.csproj +++ b/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/PIHelperSh.PdfCreator.csproj @@ -16,23 +16,9 @@ True - - - True - \ - - - - - - True - \ - - - From 2bb8b42453731bedfeb1528fcf860f5da34d95c1 Mon Sep 17 00:00:00 2001 From: bekodeg Date: Sun, 24 Nov 2024 13:20:49 +0400 Subject: [PATCH 11/20] =?UTF-8?q?=D1=84=D0=B8=D0=BA=D1=81=D1=8B=20=D0=BD?= =?UTF-8?q?=D0=B5=D0=B1=D0=BE=D0=BB=D1=8C=D1=88=D0=B8=D1=85=20=D0=BC=D0=BE?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implementations/StudentRepository.cs | 2 +- Cop.Borovkov.Var3/Lab3/Forms/MainForm.cs | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Cop.Borovkov.Var3/Lab3.Database/Repository/Implementations/StudentRepository.cs b/Cop.Borovkov.Var3/Lab3.Database/Repository/Implementations/StudentRepository.cs index 108f8cf..da6b94a 100644 --- a/Cop.Borovkov.Var3/Lab3.Database/Repository/Implementations/StudentRepository.cs +++ b/Cop.Borovkov.Var3/Lab3.Database/Repository/Implementations/StudentRepository.cs @@ -57,7 +57,7 @@ namespace Lab3.Database.Repository.Implementations return _mapper.Map( await _context.Students .Include(s => s.StudentSessions) - .FirstOrDefaultAsync()); + .FirstOrDefaultAsync(s =>s.Id == id)); } public async Task UpdateAsync(StudentDTO studentDTO) diff --git a/Cop.Borovkov.Var3/Lab3/Forms/MainForm.cs b/Cop.Borovkov.Var3/Lab3/Forms/MainForm.cs index ba949f3..5e388a6 100644 --- a/Cop.Borovkov.Var3/Lab3/Forms/MainForm.cs +++ b/Cop.Borovkov.Var3/Lab3/Forms/MainForm.cs @@ -1,13 +1,9 @@ using AutoMapper; using ComponentsLibrary.entities; using ComponentsLibrary.entities.enums; -using DocumentFormat.OpenXml.Bibliography; -using DocumentFormat.OpenXml.Drawing; -using DocumentFormat.OpenXml.Spreadsheet; using Lab3.Database.DTO; using Lab3.Database.Repository.Interfaces; using Lab3.Models; -using NPOI.OpenXml4Net.OPC.Internal; namespace Lab3.Forms { @@ -16,18 +12,21 @@ namespace Lab3.Forms private readonly IStudentRepository _studentRepository; private readonly IMapper _mapper; private readonly Func _getCreateOrUpdateForm; + private readonly CatalogForm _catalogForm; private bool _cont = false; public MainForm( IStudentRepository repository, IMapper mapper, - Func getCreateOrUpdateForm) + Func getCreateOrUpdateForm, + CatalogForm catalogForm) { _studentRepository = repository; _mapper = mapper; _getCreateOrUpdateForm = getCreateOrUpdateForm; + _catalogForm = catalogForm; InitializeComponent(); } @@ -232,16 +231,20 @@ namespace Lab3.Forms { CreateWordDocAsync(); } + else if (_cont && keyData == Keys.G) + { + _catalogForm.ShowDialog(this); + } if (keyData == Keys.A || keyData == Keys.U || keyData == Keys.D || keyData == Keys.S || keyData == Keys.T || - keyData == Keys.C) _cont = false; - //if (keyData != Keys.None && keyData != (System.Windows.Forms.Keys.ControlKey | System.Windows.Forms.Keys.Control)) cont = false; + keyData == Keys.C || + keyData == Keys.G) _cont = false; + return true; - return base.ProcessCmdKey(ref msg, keyData); } } } From 3873ce4e957d5b51fd7f6986316c82c8a4a2f5cf Mon Sep 17 00:00:00 2001 From: bekodeg Date: Sun, 24 Nov 2024 13:30:55 +0400 Subject: [PATCH 12/20] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=B8=D0=BD=D1=84=D0=BE=D1=80=D0=BC=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BE=20=D1=81=D0=BE=D0=B7?= =?UTF-8?q?=D0=B4=D0=B0=D0=BD=D0=B8=D0=B8=20=D0=B4=D0=BE=D0=BA=D1=83=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cop.Borovkov.Var3/Lab3/Forms/MainForm.cs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/Cop.Borovkov.Var3/Lab3/Forms/MainForm.cs b/Cop.Borovkov.Var3/Lab3/Forms/MainForm.cs index 5e388a6..4b5049f 100644 --- a/Cop.Borovkov.Var3/Lab3/Forms/MainForm.cs +++ b/Cop.Borovkov.Var3/Lab3/Forms/MainForm.cs @@ -115,10 +115,15 @@ namespace Lab3.Forms Title = "Сессии", Tables = [tables] }); + + _ = MessageBox.Show("Простой документ сформирован", + "Успешный результат", + MessageBoxButtons.OK, + MessageBoxIcon.Information); } catch (Exception ex) { - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + _ = MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } @@ -152,10 +157,15 @@ namespace Lab3.Forms }], Values = await _studentRepository.GetAsync() }); + + _ = MessageBox.Show("Документ с таблицей сформирован", + "Успешный результат", + MessageBoxButtons.OK, + MessageBoxIcon.Information); } catch (Exception ex) { - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + _ = MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } @@ -185,16 +195,21 @@ namespace Lab3.Forms new( saveFileDialog.FileName, "Поступления", - "Диограмма", + "Диаграмма", EnumAreaLegend.Bottom, data ) ); + + _ = MessageBox.Show("Документ с диаграммой сформирован", + "Успешный результат", + MessageBoxButtons.OK, + MessageBoxIcon.Information); } catch (Exception ex) { - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + _ = MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } From 871774e43343b534177c7b66b6c78ffc90cb1a75 Mon Sep 17 00:00:00 2001 From: bekodeg Date: Sun, 24 Nov 2024 13:46:01 +0400 Subject: [PATCH 13/20] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=20=D0=B3=D1=80=D0=B0=D0=BC?= =?UTF-8?q?=D0=BC=D0=B0=D1=82=D0=B8=D1=87=D0=B5=D1=81=D0=BA=D0=B8=D1=85=20?= =?UTF-8?q?=D0=BE=D1=88=D0=B8=D0=B1=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cop.Borovkov.Var3/Cop.Borovkov.Var3.sln | 6 ++ .../Models/PdfHistigramInfo.cs | 4 +- .../Models/PdfTableWithGroupingInfo.cs | 2 +- .../PdfCreator/Enums/PdfMargin.cs | 2 +- .../PdfCreator/Models/ImageModels/PdfImage.cs | 2 +- .../Models/PieChartModel/PdfHistogramData.cs | 2 +- .../Models/PieChartModel/PdfHistogramModel.cs | 2 +- .../Models/PieChartModel/PdfPieChartData.cs | 2 +- .../Models/TableModels/PDFSimpleTable.cs | 2 +- .../Models/TableModels/PDFSimpleTableRow.cs | 2 +- .../PdfCreator/Models/TableModels/PdfTable.cs | 2 +- .../PdfCreator/Models/TextModels/PdfList.cs | 7 +- .../Models/TextModels/PdfParagraph.cs | 2 +- .../Forms/Interfaces/IPluginsConvention.cs | 65 +++++++++++++++++++ Cop.Borovkov.Var3/Lab4/Lab4.csproj | 11 ++++ .../Lab4/Models/PluginsConventionElement.cs | 7 ++ Cop.Borovkov.Var3/Lab4/Program.cs | 17 +++++ 17 files changed, 119 insertions(+), 18 deletions(-) create mode 100644 Cop.Borovkov.Var3/Lab4/Forms/Interfaces/IPluginsConvention.cs create mode 100644 Cop.Borovkov.Var3/Lab4/Lab4.csproj create mode 100644 Cop.Borovkov.Var3/Lab4/Models/PluginsConventionElement.cs create mode 100644 Cop.Borovkov.Var3/Lab4/Program.cs diff --git a/Cop.Borovkov.Var3/Cop.Borovkov.Var3.sln b/Cop.Borovkov.Var3/Cop.Borovkov.Var3.sln index 1c8d7d9..ac79906 100644 --- a/Cop.Borovkov.Var3/Cop.Borovkov.Var3.sln +++ b/Cop.Borovkov.Var3/Cop.Borovkov.Var3.sln @@ -11,6 +11,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lab3", "Lab3\Lab3.csproj", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lab3.Database", "Lab3.Database\Lab3.Database.csproj", "{698DE9E8-7885-4F98-AFE3-9A9C6CD2FCF5}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab4", "Lab4\Lab4.csproj", "{FAE92C0B-0A2D-48B6-A55C-DE58A310CD58}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -33,6 +35,10 @@ Global {698DE9E8-7885-4F98-AFE3-9A9C6CD2FCF5}.Debug|Any CPU.Build.0 = Debug|Any CPU {698DE9E8-7885-4F98-AFE3-9A9C6CD2FCF5}.Release|Any CPU.ActiveCfg = Release|Any CPU {698DE9E8-7885-4F98-AFE3-9A9C6CD2FCF5}.Release|Any CPU.Build.0 = Release|Any CPU + {FAE92C0B-0A2D-48B6-A55C-DE58A310CD58}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FAE92C0B-0A2D-48B6-A55C-DE58A310CD58}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FAE92C0B-0A2D-48B6-A55C-DE58A310CD58}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FAE92C0B-0A2D-48B6-A55C-DE58A310CD58}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Models/PdfHistigramInfo.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Models/PdfHistigramInfo.cs index 5b5f839..607fad5 100644 --- a/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Models/PdfHistigramInfo.cs +++ b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Models/PdfHistigramInfo.cs @@ -3,7 +3,7 @@ namespace Cop.Borovkov.Var3.Models { /// - /// Параметры для создания линейной диограммы + /// Параметры для создания линейной диаграммы /// public record PdfHistigramInfo { @@ -18,7 +18,7 @@ namespace Cop.Borovkov.Var3.Models public string DocumentTitle { get; init; } = "Гистограмма"; /// - /// Заголовок диограммы + /// Заголовок диаграммы /// public string HistogramTitle { get; init; } = "Гистограмма"; diff --git a/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Models/PdfTableWithGroupingInfo.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Models/PdfTableWithGroupingInfo.cs index f920b4e..20f5b1f 100644 --- a/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Models/PdfTableWithGroupingInfo.cs +++ b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Models/PdfTableWithGroupingInfo.cs @@ -1,7 +1,7 @@ namespace Cop.Borovkov.Var3.Models { /// - /// Параметры для создания таблици в пдф с группировкой по 1 столбцу + /// Параметры для создания таблицы в пдф с группировкой по 1 столбцу /// public class PdfTableWithGroupingInfo where TType : class { diff --git a/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Enums/PdfMargin.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Enums/PdfMargin.cs index 6553cec..fed1c83 100644 --- a/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Enums/PdfMargin.cs +++ b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Enums/PdfMargin.cs @@ -15,7 +15,7 @@ namespace PIHelperSh.PdfCreator.Enums /// /// Отступа нет /// - [TypeValue("ocm")] + [TypeValue("0cm")] None, /// /// Отступ небольшой diff --git a/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/ImageModels/PdfImage.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/ImageModels/PdfImage.cs index 60d52a5..6b52099 100644 --- a/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/ImageModels/PdfImage.cs +++ b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/ImageModels/PdfImage.cs @@ -29,7 +29,7 @@ namespace PIHelperSh.PdfCreator.Models.ImageModels public int? Height { get; set; } = null; /// - /// Выравнивание текста внутри параграфа (по умолчанию - по левой строне) + /// Выравнивание текста внутри параграфа (по умолчанию - по левой стороне) /// public PdfAlignmentType ImageAlignment { get; set; } = PdfAlignmentType.Left; diff --git a/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/PieChartModel/PdfHistogramData.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/PieChartModel/PdfHistogramData.cs index b518631..6bb07bb 100644 --- a/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/PieChartModel/PdfHistogramData.cs +++ b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/PieChartModel/PdfHistogramData.cs @@ -18,7 +18,7 @@ namespace PIHelperSh.PdfCreator.Models.PieChartModel public IEnumerable<(string Name, double Value)> Value { get; set; } /// - /// Цвет области на диаграме. При null будет использоватсся выдача цветов по умолчанию) + /// Цвет области на диаграмме. При null будет использоваться выдача цветов по умолчанию) /// public Color? Color { get; set; } = null; diff --git a/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/PieChartModel/PdfHistogramModel.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/PieChartModel/PdfHistogramModel.cs index b6c7bb2..c4fe900 100644 --- a/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/PieChartModel/PdfHistogramModel.cs +++ b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/PieChartModel/PdfHistogramModel.cs @@ -1,7 +1,7 @@ namespace PIHelperSh.PdfCreator.Models.PieChartModel { /// - /// Модель линейной диограммы + /// Модель линейной диаграммы /// public class PdfHistogramModel : PdfPieChartModel { diff --git a/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/PieChartModel/PdfPieChartData.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/PieChartModel/PdfPieChartData.cs index 4542f04..2ac3137 100644 --- a/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/PieChartModel/PdfPieChartData.cs +++ b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/PieChartModel/PdfPieChartData.cs @@ -18,7 +18,7 @@ namespace PIHelperSh.PdfCreator.Models.PieChartModel public double Value { get; set; } /// - /// Цвет области на диаграме. При null будет использоватсся выдача цветов по умолчанию) + /// Цвет области на диаграмме. При null будет использоваться выдача цветов по умолчанию) /// public Color? Color { get; set; } = null; diff --git a/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TableModels/PDFSimpleTable.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TableModels/PDFSimpleTable.cs index 9c93e1b..c87f560 100644 --- a/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TableModels/PDFSimpleTable.cs +++ b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TableModels/PDFSimpleTable.cs @@ -34,7 +34,7 @@ namespace PIHelperSh.PdfCreator.Models.TableModels public PdfStyleType RowStyle = PdfStyleType.Basic; /// - /// Базовое выравнивание элементов сторок + /// Базовое выравнивание элементов в строке /// public PdfAlignmentType RowHorizontalAlignment = PdfAlignmentType.Rigth; diff --git a/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TableModels/PDFSimpleTableRow.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TableModels/PDFSimpleTableRow.cs index 8b7e30a..cda561a 100644 --- a/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TableModels/PDFSimpleTableRow.cs +++ b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TableModels/PDFSimpleTableRow.cs @@ -13,7 +13,7 @@ namespace PIHelperSh.PdfCreator.Models.TableModels public class PDFSimpleTableRow { /// - /// Элемменты данной стоки + /// Элементы данной стоки /// public List Items = new List(); diff --git a/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TableModels/PdfTable.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TableModels/PdfTable.cs index 8941931..5812616 100644 --- a/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TableModels/PdfTable.cs +++ b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TableModels/PdfTable.cs @@ -35,7 +35,7 @@ namespace PIHelperSh.PdfCreator.Models.TableModels public PdfStyleType RecordStyle { get; set; } = PdfStyleType.Basic; /// - /// Выравнивание текста объектов в таблице (по умолчанию - по левой строне) + /// Выравнивание текста объектов в таблице (по умолчанию - по левой стороне) /// public PdfAlignmentType RecordHorizontalAlignment { get; set; } = PdfAlignmentType.Left; diff --git a/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TextModels/PdfList.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TextModels/PdfList.cs index 17b210e..4ae06ae 100644 --- a/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TextModels/PdfList.cs +++ b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TextModels/PdfList.cs @@ -1,10 +1,5 @@ using PIHelperSh.PdfCreator.Enums; using PIHelperSh.PdfCreator.Interfaces; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace PIHelperSh.PdfCreator.Models.TextModels { @@ -14,7 +9,7 @@ namespace PIHelperSh.PdfCreator.Models.TextModels public class PdfList : IPdfElement { /// - /// Элементы списка (параграфы или иные спсики) + /// Элементы списка (параграфы или иные списки) /// public List Content { get; set; } = new(); diff --git a/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TextModels/PdfParagraph.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TextModels/PdfParagraph.cs index 60282bd..d3df994 100644 --- a/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TextModels/PdfParagraph.cs +++ b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TextModels/PdfParagraph.cs @@ -24,7 +24,7 @@ namespace PIHelperSh.PdfCreator.Models.TextModels public PdfStyleType Style { get; set; } = PdfStyleType.Basic; /// - /// Выравнивание текста внутри параграфа (по умолчанию - по левой строне) + /// Выравнивание текста внутри параграфа (по умолчанию - по левой стороне) /// public PdfAlignmentType ParagraphAlignment { get; set; } = PdfAlignmentType.Left; diff --git a/Cop.Borovkov.Var3/Lab4/Forms/Interfaces/IPluginsConvention.cs b/Cop.Borovkov.Var3/Lab4/Forms/Interfaces/IPluginsConvention.cs new file mode 100644 index 0000000..5046865 --- /dev/null +++ b/Cop.Borovkov.Var3/Lab4/Forms/Interfaces/IPluginsConvention.cs @@ -0,0 +1,65 @@ +namespace Lab4.Forms.Interfaces +{ + public interface IPluginsConvention + { + /// + /// Название плагина + /// + string PluginName { get; } + + /// + /// Получение контрола для вывода набора данных + /// + UserControl GetControl { get; } + + /// + /// Получение элемента, выбранного в контроле + /// + PluginsConventionElement GetElement { get; } + /// + /// Получение формы для создания/редактирования объекта + /// + /// + /// + Form GetForm(PluginsConventionElement element); + /// + /// Получение формы для работы со справочником + /// + /// + Form GetThesaurus(); + + /// + /// Удаление элемента + /// + /// + /// + bool DeleteElement(PluginsConventionElement element); + + /// + /// Обновление набора данных в контроле + /// + void ReloadData(); + + /// + /// Создание простого документа + /// + /// + /// + bool CreateSimpleDocument(PluginsConventionSaveDocument saveDocument); + + /// + /// Создание простого документа + /// + /// + /// + bool CreateTableDocument(PluginsConventionSaveDocument saveDocument); + + /// + /// Создание документа с диаграммой + /// + /// + /// + bool CreateChartDocument(PluginsConventionSaveDocument saveDocument); + } + +} diff --git a/Cop.Borovkov.Var3/Lab4/Lab4.csproj b/Cop.Borovkov.Var3/Lab4/Lab4.csproj new file mode 100644 index 0000000..663fdb8 --- /dev/null +++ b/Cop.Borovkov.Var3/Lab4/Lab4.csproj @@ -0,0 +1,11 @@ + + + + WinExe + net8.0-windows + enable + true + enable + + + \ No newline at end of file diff --git a/Cop.Borovkov.Var3/Lab4/Models/PluginsConventionElement.cs b/Cop.Borovkov.Var3/Lab4/Models/PluginsConventionElement.cs new file mode 100644 index 0000000..c5b9472 --- /dev/null +++ b/Cop.Borovkov.Var3/Lab4/Models/PluginsConventionElement.cs @@ -0,0 +1,7 @@ +namespace Lab4.Models +{ + public class PluginsConventionElement + { + public Guid Id { get; set; } + } +} diff --git a/Cop.Borovkov.Var3/Lab4/Program.cs b/Cop.Borovkov.Var3/Lab4/Program.cs new file mode 100644 index 0000000..6270a9b --- /dev/null +++ b/Cop.Borovkov.Var3/Lab4/Program.cs @@ -0,0 +1,17 @@ +namespace Lab4 +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + Application.Run(new Form1()); + } + } +} \ No newline at end of file From 2513ebcc8e3cd9fffabe6d77ec70687a9d1eceeb Mon Sep 17 00:00:00 2001 From: bekodeg Date: Sun, 24 Nov 2024 14:12:26 +0400 Subject: [PATCH 14/20] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=BF=D0=B8?= =?UTF-8?q?=D1=81=D0=B0=D0=BB=20=D1=88=D0=B0=D0=B1=D0=BB=D0=BE=D0=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Lab4/Forms/FormMain.Designer.cs | 188 ++++++++++++++++++ Cop.Borovkov.Var3/Lab4/Forms/FormMain.cs | 186 +++++++++++++++++ Cop.Borovkov.Var3/Lab4/Forms/FormMain.resx | 120 +++++++++++ .../Interfaces/IPluginsConvention.cs | 9 +- .../Models/PluginsConventionSaveDocument.cs | 7 + 5 files changed, 507 insertions(+), 3 deletions(-) create mode 100644 Cop.Borovkov.Var3/Lab4/Forms/FormMain.Designer.cs create mode 100644 Cop.Borovkov.Var3/Lab4/Forms/FormMain.cs create mode 100644 Cop.Borovkov.Var3/Lab4/Forms/FormMain.resx rename Cop.Borovkov.Var3/Lab4/{Forms => }/Interfaces/IPluginsConvention.cs (94%) create mode 100644 Cop.Borovkov.Var3/Lab4/Models/PluginsConventionSaveDocument.cs diff --git a/Cop.Borovkov.Var3/Lab4/Forms/FormMain.Designer.cs b/Cop.Borovkov.Var3/Lab4/Forms/FormMain.Designer.cs new file mode 100644 index 0000000..4951763 --- /dev/null +++ b/Cop.Borovkov.Var3/Lab4/Forms/FormMain.Designer.cs @@ -0,0 +1,188 @@ +using System.ComponentModel; + +namespace Lab4.Forms +{ + partial class FormMain + { + /// + /// Required designer variable. + /// + private IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.menuStrip = new MenuStrip(); + this.ControlsStripMenuItem = new ToolStripMenuItem(); + this.ActionsToolStripMenuItem = new ToolStripMenuItem(); + this.DocsToolStripMenuItem = new ToolStripMenuItem(); + this.SimpleDocToolStripMenuItem = new ToolStripMenuItem(); + this.TableDocToolStripMenuItem = new ToolStripMenuItem(); + this.ChartDocToolStripMenuItem = new ToolStripMenuItem(); + this.panelControl = new Panel(); + this.ThesaurusToolStripMenuItem = new ToolStripMenuItem(); + this.AddElementToolStripMenuItem = new ToolStripMenuItem(); + this.UpdElementToolStripMenuItem = new ToolStripMenuItem(); + this.DelElementToolStripMenuItem = new ToolStripMenuItem(); + this.menuStrip.SuspendLayout(); + this.SuspendLayout(); + // + // menuStrip + // + this.menuStrip.Items.AddRange(new ToolStripItem[] { + this.ControlsStripMenuItem, + this.ActionsToolStripMenuItem, + this.DocsToolStripMenuItem}); + this.menuStrip.Location = new Point(0, 0); + this.menuStrip.Name = "menuStrip"; + this.menuStrip.Size = new Size(800, 24); + this.menuStrip.TabIndex = 0; + this.menuStrip.Text = "Меню"; + // + // ControlsStripMenuItem + // + this.ControlsStripMenuItem.Name = "ControlsStripMenuItem"; + this.ControlsStripMenuItem.Size = new Size(94, 20); + this.ControlsStripMenuItem.Text = "Компоненты"; + // + // ActionsToolStripMenuItem + // + this.ActionsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { + this.ThesaurusToolStripMenuItem, + this.AddElementToolStripMenuItem, + this.UpdElementToolStripMenuItem, + this.DelElementToolStripMenuItem}); + this.ActionsToolStripMenuItem.Name = "ActionsToolStripMenuItem"; + this.ActionsToolStripMenuItem.Size = new Size(70, 20); + this.ActionsToolStripMenuItem.Text = "Действия"; + // + // DocsToolStripMenuItem + // + this.DocsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { + this.SimpleDocToolStripMenuItem, + this.TableDocToolStripMenuItem, + this.ChartDocToolStripMenuItem}); + this.DocsToolStripMenuItem.Name = "DocsToolStripMenuItem"; + this.DocsToolStripMenuItem.Size = new Size(82, 20); + this.DocsToolStripMenuItem.Text = "Документы"; + // + // SimpleDocToolStripMenuItem + // + this.SimpleDocToolStripMenuItem.Name = "SimpleDocToolStripMenuItem"; + this.SimpleDocToolStripMenuItem.ShortcutKeys = ((Keys)((Keys.Control | Keys.S))); + this.SimpleDocToolStripMenuItem.Size = new Size(233, 22); + this.SimpleDocToolStripMenuItem.Text = "Простой документ"; + this.SimpleDocToolStripMenuItem.Click += new EventHandler(this.SimpleDocToolStripMenuItem_Click); + // + // TableDocToolStripMenuItem + // + this.TableDocToolStripMenuItem.Name = "TableDocToolStripMenuItem"; + this.TableDocToolStripMenuItem.ShortcutKeys = ((Keys)((Keys.Control | Keys.T))); + this.TableDocToolStripMenuItem.Size = new Size(233, 22); + this.TableDocToolStripMenuItem.Text = "Документ с таблицей"; + this.TableDocToolStripMenuItem.Click += new EventHandler(this.TableDocToolStripMenuItem_Click); + // + // ChartDocToolStripMenuItem + // + this.ChartDocToolStripMenuItem.Name = "ChartDocToolStripMenuItem"; + this.ChartDocToolStripMenuItem.ShortcutKeys = ((Keys)((Keys.Control | Keys.C))); + this.ChartDocToolStripMenuItem.Size = new Size(233, 22); + this.ChartDocToolStripMenuItem.Text = "Диаграмма"; + this.ChartDocToolStripMenuItem.Click += new EventHandler(this.ChartDocToolStripMenuItem_Click); + // + // panelControl + // + this.panelControl.Dock = DockStyle.Fill; + this.panelControl.Location = new Point(0, 24); + this.panelControl.Name = "panelControl"; + this.panelControl.Size = new Size(800, 426); + this.panelControl.TabIndex = 1; + // + // ThesaurusToolStripMenuItem + // + this.ThesaurusToolStripMenuItem.Name = "ThesaurusToolStripMenuItem"; + this.ThesaurusToolStripMenuItem.ShortcutKeys = ((Keys)((Keys.Control | Keys.I))); + this.ThesaurusToolStripMenuItem.Size = new Size(180, 22); + this.ThesaurusToolStripMenuItem.Text = "Справочник"; + this.ThesaurusToolStripMenuItem.Click += new EventHandler(this.ThesaurusToolStripMenuItem_Click); + // + // AddElementToolStripMenuItem + // + this.AddElementToolStripMenuItem.Name = "AddElementToolStripMenuItem"; + this.AddElementToolStripMenuItem.ShortcutKeys = ((Keys)((Keys.Control | Keys.A))); + this.AddElementToolStripMenuItem.Size = new Size(180, 22); + this.AddElementToolStripMenuItem.Text = "Добавить"; + this.AddElementToolStripMenuItem.Click += new EventHandler(this.AddElementToolStripMenuItem_Click); + // + // UpdElementToolStripMenuItem + // + this.UpdElementToolStripMenuItem.Name = "UpdElementToolStripMenuItem"; + this.UpdElementToolStripMenuItem.ShortcutKeys = ((Keys)((Keys.Control | Keys.U))); + this.UpdElementToolStripMenuItem.Size = new Size(180, 22); + this.UpdElementToolStripMenuItem.Text = "Изменить"; + this.UpdElementToolStripMenuItem.Click += new EventHandler(this.UpdElementToolStripMenuItem_Click); + // + // DelElementToolStripMenuItem + // + this.DelElementToolStripMenuItem.Name = "DelElementToolStripMenuItem"; + this.DelElementToolStripMenuItem.ShortcutKeys = ((Keys)((Keys.Control | Keys.D))); + this.DelElementToolStripMenuItem.Size = new Size(180, 22); + this.DelElementToolStripMenuItem.Text = "Удалить"; + this.DelElementToolStripMenuItem.Click += new EventHandler(this.DelElementToolStripMenuItem_Click); + // + // FormMain + // + this.AutoScaleDimensions = new SizeF(7F, 15F); + this.AutoScaleMode = AutoScaleMode.Font; + this.ClientSize = new Size(800, 450); + this.Controls.Add(this.panelControl); + this.Controls.Add(this.menuStrip); + this.MainMenuStrip = this.menuStrip; + this.Name = "FormMain"; + this.StartPosition = + FormStartPosition.CenterScreen; + this.Text = "Главная форма"; + this.WindowState = + FormWindowState.Maximized; + this.KeyDown += new + KeyEventHandler(this.FormMain_KeyDown); + this.menuStrip.ResumeLayout(false); + this.menuStrip.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + } + + #endregion + + private MenuStrip menuStrip; + private ToolStripMenuItem ControlsStripMenuItem; + private ToolStripMenuItem DocsToolStripMenuItem; + private ToolStripMenuItem SimpleDocToolStripMenuItem; + private ToolStripMenuItem TableDocToolStripMenuItem; + private ToolStripMenuItem ChartDocToolStripMenuItem; + private Panel panelControl; + private ToolStripMenuItem ActionsToolStripMenuItem; + private ToolStripMenuItem ThesaurusToolStripMenuItem; + private ToolStripMenuItem AddElementToolStripMenuItem; + private ToolStripMenuItem UpdElementToolStripMenuItem; + private ToolStripMenuItem DelElementToolStripMenuItem; + } +} \ No newline at end of file diff --git a/Cop.Borovkov.Var3/Lab4/Forms/FormMain.cs b/Cop.Borovkov.Var3/Lab4/Forms/FormMain.cs new file mode 100644 index 0000000..87a0204 --- /dev/null +++ b/Cop.Borovkov.Var3/Lab4/Forms/FormMain.cs @@ -0,0 +1,186 @@ +using Lab4.Interfaces; +using Lab4.Models; + +namespace Lab4.Forms +{ + public partial class FormMain : Form + { + private readonly Dictionary _plugins; + private string _selectedPlugin; + + public FormMain() + { + InitializeComponent(); + + _plugins = LoadPlugins(); + _selectedPlugin = string.Empty; + } + + private Dictionary LoadPlugins() + { + // TODO Заполнить IPluginsConvention + // TODO Заполнить пункт меню "Компоненты" на основе IPluginsConvention.PluginName + // TODO Например, создавать ToolStripMenuItem, привязывать к ним обработку событий и добавлять в menuStrip + // TODO При выборе пункта меню получать UserControl и заполнять элемент panelControl этим контролом на всю площадь + // Пример: panelControl.Controls.Clear(); + // panelControl.Controls.Add(ctrl); + return []; + } + + private void FormMain_KeyDown(object sender, KeyEventArgs e) + { + if (string.IsNullOrEmpty(_selectedPlugin) || !_plugins.ContainsKey(_selectedPlugin)) + { + return; + } + + if (!e.Control) + { + return; + } + + switch (e.KeyCode) + { + case Keys.I: + ShowThesaurus(); + break; + case Keys.A: + AddNewElement(); + break; + case Keys.U: + UpdateElement(); + break; + case Keys.D: + DeleteElement(); + break; + case Keys.S: + CreateSimpleDoc(); + break; + case Keys.T: + CreateTableDoc(); + break; + case Keys.C: + CreateChartDoc(); + break; + } + } + + private void ShowThesaurus() + { + _plugins[_selectedPlugin].GetThesaurus()?.Show(); + } + + private void AddNewElement() + { + var form = _plugins[_selectedPlugin].GetForm(); + + if (form != null && form.ShowDialog() == DialogResult.OK) + { + _plugins[_selectedPlugin].ReloadData(); + } + } + + private void UpdateElement() + { + var element = _plugins[_selectedPlugin].GetElement; + + if (element == null) + { + _ = MessageBox.Show("Нет выбранного элемента", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + var form = _plugins[_selectedPlugin].GetForm(element); + + if (form != null && form.ShowDialog() == DialogResult.OK) + { + _plugins[_selectedPlugin].ReloadData(); + } + } + private void DeleteElement() + { + if (MessageBox.Show("Удалить выбранный элемент", "Удаление", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) + { + return; + } + + var element = _plugins[_selectedPlugin].GetElement; + + if (element == null) + { + _ = MessageBox.Show("Нет выбранного элемента", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (_plugins[_selectedPlugin].DeleteElement(element)) + { + _plugins[_selectedPlugin].ReloadData(); + } + } + + private void CreateSimpleDoc() + { + // TODO узнать где сохранять + if (_plugins[_selectedPlugin].CreateSimpleDocument(new PluginsConventionSaveDocument())) + { + _ = MessageBox.Show("Документ сохранен", + "Создание документа", + MessageBoxButtons.OK, + MessageBoxIcon.Information); + } + else + { + _ = MessageBox.Show("Ошибка при создании документа", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void CreateTableDoc() + { + // TODO узнать где сохранять + if (_plugins[_selectedPlugin].CreateTableDocument(new + PluginsConventionSaveDocument())) + { + _ = MessageBox.Show("Документ сохранен", + "Создание документа", + MessageBoxButtons.OK, + MessageBoxIcon.Information); + } + else + { + _ = MessageBox.Show("Ошибка при создании документа", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void CreateChartDoc() + { + // TODO узнать где сохранять + if (_plugins[_selectedPlugin].CreateChartDocument(new PluginsConventionSaveDocument())) + { + _ = MessageBox.Show("Документ сохранен", + "Создание документа", + MessageBoxButtons.OK, + MessageBoxIcon.Information); + } + else + { + _ = MessageBox.Show("Ошибка при создании документа", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ThesaurusToolStripMenuItem_Click(object sender, EventArgs e) => ShowThesaurus(); + + private void AddElementToolStripMenuItem_Click(object sender, EventArgs e) => AddNewElement(); + + private void UpdElementToolStripMenuItem_Click(object sender, EventArgs e) => UpdateElement(); + + private void DelElementToolStripMenuItem_Click(object sender, EventArgs e) => DeleteElement(); + + private void SimpleDocToolStripMenuItem_Click(object sender, EventArgs e) => CreateSimpleDoc(); + + private void TableDocToolStripMenuItem_Click(object sender, EventArgs e) => CreateTableDoc(); + + private void ChartDocToolStripMenuItem_Click(object sender, EventArgs e) => CreateChartDoc(); + + } +} diff --git a/Cop.Borovkov.Var3/Lab4/Forms/FormMain.resx b/Cop.Borovkov.Var3/Lab4/Forms/FormMain.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Cop.Borovkov.Var3/Lab4/Forms/FormMain.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Cop.Borovkov.Var3/Lab4/Forms/Interfaces/IPluginsConvention.cs b/Cop.Borovkov.Var3/Lab4/Interfaces/IPluginsConvention.cs similarity index 94% rename from Cop.Borovkov.Var3/Lab4/Forms/Interfaces/IPluginsConvention.cs rename to Cop.Borovkov.Var3/Lab4/Interfaces/IPluginsConvention.cs index 5046865..52dda70 100644 --- a/Cop.Borovkov.Var3/Lab4/Forms/Interfaces/IPluginsConvention.cs +++ b/Cop.Borovkov.Var3/Lab4/Interfaces/IPluginsConvention.cs @@ -1,4 +1,6 @@ -namespace Lab4.Forms.Interfaces +using Lab4.Models; + +namespace Lab4.Interfaces { public interface IPluginsConvention { @@ -16,12 +18,14 @@ /// Получение элемента, выбранного в контроле /// PluginsConventionElement GetElement { get; } + /// /// Получение формы для создания/редактирования объекта /// /// /// - Form GetForm(PluginsConventionElement element); + Form GetForm(PluginsConventionElement? element = null); + /// /// Получение формы для работы со справочником /// @@ -61,5 +65,4 @@ /// bool CreateChartDocument(PluginsConventionSaveDocument saveDocument); } - } diff --git a/Cop.Borovkov.Var3/Lab4/Models/PluginsConventionSaveDocument.cs b/Cop.Borovkov.Var3/Lab4/Models/PluginsConventionSaveDocument.cs new file mode 100644 index 0000000..d5e4fc7 --- /dev/null +++ b/Cop.Borovkov.Var3/Lab4/Models/PluginsConventionSaveDocument.cs @@ -0,0 +1,7 @@ +namespace Lab4.Models +{ + public class PluginsConventionSaveDocument + { + public string FileName { get; set; } = null!; + } +} From 5ee30cdde5b8131ccdc709ee4c42182e3d804ce8 Mon Sep 17 00:00:00 2001 From: bekodeg Date: Sun, 24 Nov 2024 15:22:18 +0400 Subject: [PATCH 15/20] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8F=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84?= =?UTF-8?q?=D0=B5=D0=B9=D1=81=D0=B0=20=D0=BF=D0=BB=D0=B0=D0=B3=D0=B8=D0=BD?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/CustomDataTable.cs | 6 +- .../Lab3.Database/Extensions/DIExtension.cs | 2 +- Cop.Borovkov.Var3/Lab3/Forms/CatalogForm.cs | 10 +- Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs | 6 +- .../Lab4/Implementations/PluginsConvention.cs | 233 ++++++++++++++++++ .../Lab4/Interfaces/IPluginsConvention.cs | 2 +- Cop.Borovkov.Var3/Lab4/Lab4.csproj | 4 + Cop.Borovkov.Var3/Lab4/Program.cs | 4 +- 8 files changed, 253 insertions(+), 14 deletions(-) create mode 100644 Cop.Borovkov.Var3/Lab4/Implementations/PluginsConvention.cs diff --git a/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Components/CustomDataTable.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Components/CustomDataTable.cs index 477bb22..0169e86 100644 --- a/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Components/CustomDataTable.cs +++ b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Components/CustomDataTable.cs @@ -41,7 +41,7 @@ namespace Cop.Borovkov.Var3.Components column.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells; } - outDataGridView.Columns.Add(column); + _ = outDataGridView.Columns.Add(column); } } @@ -108,10 +108,10 @@ namespace Cop.Borovkov.Var3.Components Type type = typeof(TType); - for (int i = 0; i < insertValues.Count(); ++i) + for (int i = 0; i < insertValues.Count; ++i) { var row = insertValues[i]; - outDataGridView.Rows.Add(); + _ = outDataGridView.Rows.Add(); for (int j = 0; j < outDataGridView.ColumnCount; ++j) { diff --git a/Cop.Borovkov.Var3/Lab3.Database/Extensions/DIExtension.cs b/Cop.Borovkov.Var3/Lab3.Database/Extensions/DIExtension.cs index f623e96..3aeb93a 100644 --- a/Cop.Borovkov.Var3/Lab3.Database/Extensions/DIExtension.cs +++ b/Cop.Borovkov.Var3/Lab3.Database/Extensions/DIExtension.cs @@ -14,7 +14,7 @@ namespace Lab3.Database.Extensions this IServiceCollection services, IConfiguration configuration) { - services.AddDbContextPool( + _ = services.AddDbContextPool( dbContextOptions => { AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); diff --git a/Cop.Borovkov.Var3/Lab3/Forms/CatalogForm.cs b/Cop.Borovkov.Var3/Lab3/Forms/CatalogForm.cs index 03cbaa6..5481f1d 100644 --- a/Cop.Borovkov.Var3/Lab3/Forms/CatalogForm.cs +++ b/Cop.Borovkov.Var3/Lab3/Forms/CatalogForm.cs @@ -19,7 +19,7 @@ namespace Lab3.Forms var values = (await _repository.Get()).ToList(); for (int i = 0; i < values.Count; i++) { - Catalog.Rows.Add(); + _ = Catalog.Rows.Add(); Catalog.Rows[i].Cells[0].Value = values[i]; } } @@ -40,7 +40,7 @@ namespace Lab3.Forms string? val = (string?)Catalog.Rows[i].Cells[0].Value; if (string.IsNullOrEmpty(val)) { - MessageBox.Show( + _ = MessageBox.Show( "Неверные данные", "Ошибка", MessageBoxButtons.OK, @@ -54,7 +54,7 @@ namespace Lab3.Forms } catch (Exception ex) { - MessageBox.Show( + _ = MessageBox.Show( ex.Message, "Ошибка", MessageBoxButtons.OK, @@ -66,7 +66,7 @@ namespace Lab3.Forms { if (e.KeyCode == Keys.Insert) { - Catalog.Rows.Add(); + _ = Catalog.Rows.Add(); } if (e.KeyCode == Keys.Delete && Catalog.SelectedRows.Count == 1) @@ -84,7 +84,7 @@ namespace Lab3.Forms } catch (Exception ex) { - MessageBox.Show( + _ = MessageBox.Show( ex.Message, "Ошибка", MessageBoxButtons.OK, diff --git a/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs b/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs index 1929461..c7b6c4b 100644 --- a/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs +++ b/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs @@ -37,7 +37,7 @@ namespace Lab3.Forms } var student = await _studentRepository.GetAsync(_updatedStudentGuid.Value); - NameTextBox.Text = student.Name; + NameTextBox.Text = student!.Name; StartEducationDataPicker.Value = student.StartEducation; FormSelector.ComboBoxSelectedValue = student.EducationForm; @@ -101,11 +101,11 @@ namespace Lab3.Forms if (_updatedStudentGuid != null) { - await _studentRepository.UpdateAsync(student); + _ = await _studentRepository.UpdateAsync(student); } else { - await _studentRepository.CreateAsync(student); + _ = await _studentRepository.CreateAsync(student); } Close(); } diff --git a/Cop.Borovkov.Var3/Lab4/Implementations/PluginsConvention.cs b/Cop.Borovkov.Var3/Lab4/Implementations/PluginsConvention.cs new file mode 100644 index 0000000..373b463 --- /dev/null +++ b/Cop.Borovkov.Var3/Lab4/Implementations/PluginsConvention.cs @@ -0,0 +1,233 @@ +using Cop.Borovkov.Var3.Components; +using Lab4.Interfaces; +using Lab4.Models; +using Lab3.Database.Repository.Interfaces; +using ComponentsLibrary.entities; +using ComponentsLibrary; +using ComponentsLibrary.entities.enums; +using Lab3.Database.DTO; +using CustomComponentsVar2; +using Lab3.Forms; +using Lab3.Models; +using AutoMapper; + +namespace Lab4.Implementations +{ + public class PluginsConvention : IPluginsConvention + { + private readonly IMapper _mapper; + private readonly IStudentRepository _studentRepository; + private readonly IEducationFormRepository _educationFormRepository; + + private readonly CustomListBox _control; + private readonly CustomPdfTable _simpleDocumentCreator; + private readonly CustomExcelTable _tableCreator; + private readonly ComponentDiagram _chartCreator; + + public PluginsConvention( + IMapper mapper, + IStudentRepository studentRepository, + IEducationFormRepository educationFormRepository) + { + _mapper = mapper; + _studentRepository = studentRepository; + _educationFormRepository = educationFormRepository; + + _control = new(); + _chartCreator = new(); + _tableCreator = new(); + _simpleDocumentCreator = new(); + } + + public string PluginName => throw new NotImplementedException(); + + public UserControl GetControl => _control; + + public PluginsConventionElement GetElement { + get + { + var filds = _control.Selected.Split(); + + Guid id = Guid.Parse(filds[0]); + + return new() + { + Id = id, + }; + } + } + + public bool CreateChartDocument(PluginsConventionSaveDocument saveDocument) + { + try + { + using var saveFileDialog = new SaveFileDialog + { + Filter = "docx|*.docx" + }; + + if (saveFileDialog.ShowDialog() != DialogResult.OK) + { + return false; + } + + var data = _studentRepository.GetAsync().Result + .GroupBy(s => s.EducationForm) + .Select(s => new DataLine( + s.Key, + s.GroupBy(x => x.StartEducation.Year) + .Select(x => (year: x.Key.ToString(), count: (double)x.Count())) + .ToArray())) + .ToList(); + + _chartCreator.AddDiagram( + new( + saveFileDialog.FileName, + "Поступления", + "Диаграмма", + + EnumAreaLegend.Bottom, + data + ) + ); + + return true; + } + catch + { + return false; + } + } + + public bool CreateSimpleDocument(PluginsConventionSaveDocument saveDocument) + { + try + { + using var saveFileDialog = new SaveFileDialog + { + Filter = "pdf|*.pdf" + }; + + if (saveFileDialog.ShowDialog() != DialogResult.OK) + { + return false; + } + + var values = (_studentRepository.GetAsync()).Result + .Select(s => s.StudentSessions + .OrderBy(x => x.Number) + .Select(x => x.Score.ToString()) + .ToArray()) + .ToArray(); + + var tables = new string[values.Length, 6]; + + for (int i = 0; i < values.Length; ++i) + { + for (int j = 0; j < 6; ++j) + { + tables[i, j] = values[i][j]; + } + } + + _simpleDocumentCreator.SaveToPdf(new() + { + FilePath = saveFileDialog.FileName, + Title = "Сессии", + Tables = [tables] + }); + + return true; + } + catch + { + return false; + } + } + + public bool CreateTableDocument(PluginsConventionSaveDocument saveDocument) + { + try + { + using var saveFileDialog = new SaveFileDialog + { + Filter = "xlsx|*.xlsx" + }; + if (saveFileDialog.ShowDialog() != DialogResult.OK) + { + return false; + } + + _tableCreator.SaveToExcel(new() + { + FilePath = saveFileDialog.FileName, + Title = "Студенты", + Headers = + [ + ("Id", nameof(StudentDTO.Id)), + ("ФИО", nameof(StudentDTO.Name)), + ("Форма обучения", nameof(StudentDTO.EducationForm)), + ("Дата поступления", nameof(StudentDTO.StartEducation)), + ], + HeaderGroups = [new() { + GroupHeader = "Образование", + FirstHeader = 2, + LastHeader = 3, + }], + Values = _studentRepository.GetAsync().Result + }); + + return true; + } + catch + { + return false; + } + } + + public bool DeleteElement(PluginsConventionElement element) + { + try + { + _studentRepository + .DeleteAsync(element.Id).Wait(); + + return true; + } + catch + { + return false; + } + } + + public Form GetForm(PluginsConventionElement? element = null) + => new CreateForm(_studentRepository, _educationFormRepository, element?.Id); + + public Form GetThesaurus() + => new CatalogForm(_educationFormRepository); + + public void ReloadData() + { + try + { + var students = _mapper.Map>(_studentRepository.GetAsync().Result); + + _control.FillValues( + students.Select(s => string.Join(" ", + [ + s.Id, + s.Name, + s.EducationForm, + s.StartEducation.ToLongDateString(), + s.SessionMarks, + ] + )) + ); + } + catch + { + + } + } + } +} diff --git a/Cop.Borovkov.Var3/Lab4/Interfaces/IPluginsConvention.cs b/Cop.Borovkov.Var3/Lab4/Interfaces/IPluginsConvention.cs index 52dda70..43b757b 100644 --- a/Cop.Borovkov.Var3/Lab4/Interfaces/IPluginsConvention.cs +++ b/Cop.Borovkov.Var3/Lab4/Interfaces/IPluginsConvention.cs @@ -12,7 +12,7 @@ namespace Lab4.Interfaces /// /// Получение контрола для вывода набора данных /// - UserControl GetControl { get; } + UserControl GetControl { get; } /// /// Получение элемента, выбранного в контроле diff --git a/Cop.Borovkov.Var3/Lab4/Lab4.csproj b/Cop.Borovkov.Var3/Lab4/Lab4.csproj index 663fdb8..3b383bd 100644 --- a/Cop.Borovkov.Var3/Lab4/Lab4.csproj +++ b/Cop.Borovkov.Var3/Lab4/Lab4.csproj @@ -8,4 +8,8 @@ enable + + + + \ No newline at end of file diff --git a/Cop.Borovkov.Var3/Lab4/Program.cs b/Cop.Borovkov.Var3/Lab4/Program.cs index 6270a9b..17d2a90 100644 --- a/Cop.Borovkov.Var3/Lab4/Program.cs +++ b/Cop.Borovkov.Var3/Lab4/Program.cs @@ -1,3 +1,5 @@ +using Lab4.Forms; + namespace Lab4 { internal static class Program @@ -11,7 +13,7 @@ namespace Lab4 // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + Application.Run(new FormMain()); } } } \ No newline at end of file From a474bd8bbba1029333e37480bb3b7e07a5033225 Mon Sep 17 00:00:00 2001 From: bekodeg Date: Sun, 24 Nov 2024 17:58:42 +0400 Subject: [PATCH 16/20] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=B7=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=BA=D1=83=20?= =?UTF-8?q?=D0=BF=D0=BB=D0=B0=D0=B3=D0=B8=D0=BD=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cop.Borovkov.Var3/Lab4/Forms/FormMain.cs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/Cop.Borovkov.Var3/Lab4/Forms/FormMain.cs b/Cop.Borovkov.Var3/Lab4/Forms/FormMain.cs index 87a0204..83fc957 100644 --- a/Cop.Borovkov.Var3/Lab4/Forms/FormMain.cs +++ b/Cop.Borovkov.Var3/Lab4/Forms/FormMain.cs @@ -8,19 +8,32 @@ namespace Lab4.Forms private readonly Dictionary _plugins; private string _selectedPlugin; - public FormMain() + private readonly Func _pluginsConventionFunc; + + public FormMain(Func pluginsConventionFunc) { InitializeComponent(); + _pluginsConventionFunc = pluginsConventionFunc; + _plugins = LoadPlugins(); _selectedPlugin = string.Empty; } private Dictionary LoadPlugins() { - // TODO Заполнить IPluginsConvention - // TODO Заполнить пункт меню "Компоненты" на основе IPluginsConvention.PluginName - // TODO Например, создавать ToolStripMenuItem, привязывать к ним обработку событий и добавлять в menuStrip + Dictionary result = []; + + List keys = ["Успеваемость"]; + result = keys.Select(k => KeyValuePair.Create(k, _pluginsConventionFunc(k))).ToDictionary(); + foreach (string key in keys) + { + var item = new ToolStripMenuItem(key); + item.Click += (s, e) => _selectedPlugin = key; + + ControlsStripMenuItem.Container!.Add(item); + } + // TODO При выборе пункта меню получать UserControl и заполнять элемент panelControl этим контролом на всю площадь // Пример: panelControl.Controls.Clear(); // panelControl.Controls.Add(ctrl); From e66e721e98938d920078eb33d8c4e8da83135270 Mon Sep 17 00:00:00 2001 From: bekodeg Date: Mon, 25 Nov 2024 20:48:20 +0400 Subject: [PATCH 17/20] =?UTF-8?q?=D0=9F=D0=BE=D1=87=D1=82=D0=B8=20=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Lab3/Extensions/DIExtension.cs | 2 +- Cop.Borovkov.Var3/Lab3/Program.cs | 4 +- .../Lab4/Extensions/DiExtensions.cs | 29 +++++++ Cop.Borovkov.Var3/Lab4/Forms/FormMain.cs | 86 ++++++++++++++----- .../Lab4/Implementations/PluginsConvention.cs | 37 +------- Cop.Borovkov.Var3/Lab4/Lab4.csproj | 6 ++ Cop.Borovkov.Var3/Lab4/Program.cs | 31 ++++++- Cop.Borovkov.Var3/Lab4/appsettings.json | 5 ++ 8 files changed, 141 insertions(+), 59 deletions(-) create mode 100644 Cop.Borovkov.Var3/Lab4/Extensions/DiExtensions.cs create mode 100644 Cop.Borovkov.Var3/Lab4/appsettings.json diff --git a/Cop.Borovkov.Var3/Lab3/Extensions/DIExtension.cs b/Cop.Borovkov.Var3/Lab3/Extensions/DIExtension.cs index 9199bff..f98f440 100644 --- a/Cop.Borovkov.Var3/Lab3/Extensions/DIExtension.cs +++ b/Cop.Borovkov.Var3/Lab3/Extensions/DIExtension.cs @@ -21,7 +21,7 @@ namespace Lab3.Extensions return services; } - public static IServiceCollection AddForms( + public static IServiceCollection AddLab3Forms( this IServiceCollection services) { services.AddScoped(); diff --git a/Cop.Borovkov.Var3/Lab3/Program.cs b/Cop.Borovkov.Var3/Lab3/Program.cs index 8cbc6aa..c9c3cbb 100644 --- a/Cop.Borovkov.Var3/Lab3/Program.cs +++ b/Cop.Borovkov.Var3/Lab3/Program.cs @@ -9,7 +9,7 @@ namespace Lab3 internal static class Program { /// - /// The main entry point for the application. + /// The main entry point for the application. /// [STAThread] static void Main() @@ -34,7 +34,7 @@ namespace Lab3 services.AddMapping(); - services.AddForms(); + services.AddLab3Forms(); }); } } diff --git a/Cop.Borovkov.Var3/Lab4/Extensions/DiExtensions.cs b/Cop.Borovkov.Var3/Lab4/Extensions/DiExtensions.cs new file mode 100644 index 0000000..ec824e1 --- /dev/null +++ b/Cop.Borovkov.Var3/Lab4/Extensions/DiExtensions.cs @@ -0,0 +1,29 @@ +using Lab4.Forms; +using Lab4.Implementations; +using Lab4.Interfaces; +using Microsoft.Extensions.DependencyInjection; + +namespace Lab4.Extensions +{ + public static class DiExtensions + { + public static IServiceCollection AddLab4Forms( + this IServiceCollection services) + { + services.AddScoped(); + + services.AddScoped(); + + return services; + } + + public static IServiceCollection AddScopes( + this IServiceCollection services) + { + services.AddScoped>(sp + => (type) => (sp.GetRequiredService(type) as IPluginsConvention)!); + + return services; + } + } +} diff --git a/Cop.Borovkov.Var3/Lab4/Forms/FormMain.cs b/Cop.Borovkov.Var3/Lab4/Forms/FormMain.cs index 83fc957..e2b5c8e 100644 --- a/Cop.Borovkov.Var3/Lab4/Forms/FormMain.cs +++ b/Cop.Borovkov.Var3/Lab4/Forms/FormMain.cs @@ -8,13 +8,13 @@ namespace Lab4.Forms private readonly Dictionary _plugins; private string _selectedPlugin; - private readonly Func _pluginsConventionFunc; + private readonly Func _getPluginObjectFunc; - public FormMain(Func pluginsConventionFunc) + public FormMain(Func getPluginObjectFunc) { InitializeComponent(); - _pluginsConventionFunc = pluginsConventionFunc; + _getPluginObjectFunc = getPluginObjectFunc; _plugins = LoadPlugins(); _selectedPlugin = string.Empty; @@ -24,20 +24,30 @@ namespace Lab4.Forms { Dictionary result = []; - List keys = ["Успеваемость"]; - result = keys.Select(k => KeyValuePair.Create(k, _pluginsConventionFunc(k))).ToDictionary(); - foreach (string key in keys) + var plurinType = typeof(IPluginsConvention); + + foreach (var type in AppDomain.CurrentDomain + .GetAssemblies() + .SelectMany(x => x.GetTypes()) + .Where(x => plurinType.IsAssignableFrom(x) && x != plurinType)) { + var plugin = _getPluginObjectFunc(type); + + string key = plugin.PluginName; + result[key] = plugin; + var item = new ToolStripMenuItem(key); - item.Click += (s, e) => _selectedPlugin = key; - - ControlsStripMenuItem.Container!.Add(item); + item.Click += (s, e) => + { + _selectedPlugin = key; + + panelControl.Controls.Clear(); + panelControl.Controls.Add(_plugins[key].GetControl); + }; + ControlsStripMenuItem.DropDownItems!.Add(item); } - - // TODO При выборе пункта меню получать UserControl и заполнять элемент panelControl этим контролом на всю площадь - // Пример: panelControl.Controls.Clear(); - // panelControl.Controls.Add(ctrl); - return []; + + return result; } private void FormMain_KeyDown(object sender, KeyEventArgs e) @@ -136,8 +146,19 @@ namespace Lab4.Forms private void CreateSimpleDoc() { - // TODO узнать где сохранять - if (_plugins[_selectedPlugin].CreateSimpleDocument(new PluginsConventionSaveDocument())) + using var saveFileDialog = new SaveFileDialog + { + Filter = "pdf|*.pdf" + }; + if (saveFileDialog.ShowDialog() != DialogResult.OK) + { + return; + } + + if (_plugins[_selectedPlugin].CreateSimpleDocument(new PluginsConventionSaveDocument() + { + FileName = saveFileDialog.FileName, + })) { _ = MessageBox.Show("Документ сохранен", "Создание документа", @@ -151,9 +172,21 @@ namespace Lab4.Forms } private void CreateTableDoc() { - // TODO узнать где сохранять + using var saveFileDialog = new SaveFileDialog + { + Filter = "xlsx|*.xlsx" + }; + + if (saveFileDialog.ShowDialog() != DialogResult.OK) + { + return; + } + if (_plugins[_selectedPlugin].CreateTableDocument(new - PluginsConventionSaveDocument())) + PluginsConventionSaveDocument() + { + FileName = saveFileDialog.FileName, + })) { _ = MessageBox.Show("Документ сохранен", "Создание документа", @@ -167,8 +200,20 @@ namespace Lab4.Forms } private void CreateChartDoc() { - // TODO узнать где сохранять - if (_plugins[_selectedPlugin].CreateChartDocument(new PluginsConventionSaveDocument())) + using var saveFileDialog = new SaveFileDialog + { + Filter = "docx|*.docx" + }; + + if (saveFileDialog.ShowDialog() != DialogResult.OK) + { + return; + } + + if (_plugins[_selectedPlugin].CreateChartDocument(new PluginsConventionSaveDocument() + { + FileName= saveFileDialog.FileName, + })) { _ = MessageBox.Show("Документ сохранен", "Создание документа", @@ -180,7 +225,6 @@ namespace Lab4.Forms _ = MessageBox.Show("Ошибка при создании документа", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } - private void ThesaurusToolStripMenuItem_Click(object sender, EventArgs e) => ShowThesaurus(); private void AddElementToolStripMenuItem_Click(object sender, EventArgs e) => AddNewElement(); diff --git a/Cop.Borovkov.Var3/Lab4/Implementations/PluginsConvention.cs b/Cop.Borovkov.Var3/Lab4/Implementations/PluginsConvention.cs index 373b463..e2683c5 100644 --- a/Cop.Borovkov.Var3/Lab4/Implementations/PluginsConvention.cs +++ b/Cop.Borovkov.Var3/Lab4/Implementations/PluginsConvention.cs @@ -39,7 +39,7 @@ namespace Lab4.Implementations _simpleDocumentCreator = new(); } - public string PluginName => throw new NotImplementedException(); + public string PluginName => "Успеваемость"; public UserControl GetControl => _control; @@ -61,16 +61,6 @@ namespace Lab4.Implementations { try { - using var saveFileDialog = new SaveFileDialog - { - Filter = "docx|*.docx" - }; - - if (saveFileDialog.ShowDialog() != DialogResult.OK) - { - return false; - } - var data = _studentRepository.GetAsync().Result .GroupBy(s => s.EducationForm) .Select(s => new DataLine( @@ -82,7 +72,7 @@ namespace Lab4.Implementations _chartCreator.AddDiagram( new( - saveFileDialog.FileName, + saveDocument.FileName, "Поступления", "Диаграмма", @@ -103,16 +93,6 @@ namespace Lab4.Implementations { try { - using var saveFileDialog = new SaveFileDialog - { - Filter = "pdf|*.pdf" - }; - - if (saveFileDialog.ShowDialog() != DialogResult.OK) - { - return false; - } - var values = (_studentRepository.GetAsync()).Result .Select(s => s.StudentSessions .OrderBy(x => x.Number) @@ -132,7 +112,7 @@ namespace Lab4.Implementations _simpleDocumentCreator.SaveToPdf(new() { - FilePath = saveFileDialog.FileName, + FilePath = saveDocument.FileName, Title = "Сессии", Tables = [tables] }); @@ -149,18 +129,9 @@ namespace Lab4.Implementations { try { - using var saveFileDialog = new SaveFileDialog - { - Filter = "xlsx|*.xlsx" - }; - if (saveFileDialog.ShowDialog() != DialogResult.OK) - { - return false; - } - _tableCreator.SaveToExcel(new() { - FilePath = saveFileDialog.FileName, + FilePath = saveDocument.FileName, Title = "Студенты", Headers = [ diff --git a/Cop.Borovkov.Var3/Lab4/Lab4.csproj b/Cop.Borovkov.Var3/Lab4/Lab4.csproj index 3b383bd..13f756f 100644 --- a/Cop.Borovkov.Var3/Lab4/Lab4.csproj +++ b/Cop.Borovkov.Var3/Lab4/Lab4.csproj @@ -12,4 +12,10 @@ + + + Always + + + \ No newline at end of file diff --git a/Cop.Borovkov.Var3/Lab4/Program.cs b/Cop.Borovkov.Var3/Lab4/Program.cs index 17d2a90..e6464cf 100644 --- a/Cop.Borovkov.Var3/Lab4/Program.cs +++ b/Cop.Borovkov.Var3/Lab4/Program.cs @@ -1,11 +1,17 @@ +using Lab3.Extensions; +using Lab3.Forms; +using Lab4.Extensions; using Lab4.Forms; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; namespace Lab4 { internal static class Program { /// - /// The main entry point for the application. + /// The main entry point for the application. /// [STAThread] static void Main() @@ -13,7 +19,28 @@ namespace Lab4 // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormMain()); + + var app = CreateHostBuilder().Build(); + + Application.Run(app.Services.GetRequiredService()); + } + + static IHostBuilder CreateHostBuilder() + { + return Host.CreateDefaultBuilder() + .ConfigureAppConfiguration(c + => c.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)) + .ConfigureServices((context, services) => { + + services.ConfigureDAL(context.Configuration); + + services.AddMapping(); + + services.AddLab3Forms(); + services.AddLab4Forms(); + + services.AddScopes(); + }); } } } \ No newline at end of file diff --git a/Cop.Borovkov.Var3/Lab4/appsettings.json b/Cop.Borovkov.Var3/Lab4/appsettings.json new file mode 100644 index 0000000..751a2b0 --- /dev/null +++ b/Cop.Borovkov.Var3/Lab4/appsettings.json @@ -0,0 +1,5 @@ +{ + "ConnectionStrings": { + "COPDataBase": "Host=localhost;Username=postgres;Password=postgres;Database=COP" + } +} From d9dea309c59bc97611e3ef242e9d60ea9ee45ea4 Mon Sep 17 00:00:00 2001 From: bekodeg Date: Mon, 25 Nov 2024 21:07:27 +0400 Subject: [PATCH 18/20] =?UTF-8?q?=D0=9F=D0=BE=D1=87=D0=B8=D0=BD=D0=B8?= =?UTF-8?q?=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cop.Borovkov.Var3/Lab4/Extensions/DiExtensions.cs | 4 ++-- Cop.Borovkov.Var3/Lab4/Forms/FormMain.cs | 12 +++++++++++- .../Lab4/Implementations/PluginsConvention.cs | 4 ++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Cop.Borovkov.Var3/Lab4/Extensions/DiExtensions.cs b/Cop.Borovkov.Var3/Lab4/Extensions/DiExtensions.cs index ec824e1..129b87a 100644 --- a/Cop.Borovkov.Var3/Lab4/Extensions/DiExtensions.cs +++ b/Cop.Borovkov.Var3/Lab4/Extensions/DiExtensions.cs @@ -12,14 +12,14 @@ namespace Lab4.Extensions { services.AddScoped(); - services.AddScoped(); - return services; } public static IServiceCollection AddScopes( this IServiceCollection services) { + services.AddScoped(); + services.AddScoped>(sp => (type) => (sp.GetRequiredService(type) as IPluginsConvention)!); diff --git a/Cop.Borovkov.Var3/Lab4/Forms/FormMain.cs b/Cop.Borovkov.Var3/Lab4/Forms/FormMain.cs index e2b5c8e..bc5a9c1 100644 --- a/Cop.Borovkov.Var3/Lab4/Forms/FormMain.cs +++ b/Cop.Borovkov.Var3/Lab4/Forms/FormMain.cs @@ -42,7 +42,13 @@ namespace Lab4.Forms _selectedPlugin = key; panelControl.Controls.Clear(); - panelControl.Controls.Add(_plugins[key].GetControl); + + _plugins[_selectedPlugin].ReloadData(); + var control = _plugins[key].GetControl; + control.Parent = panelControl; + control.Dock = DockStyle.Fill; + + panelControl.Controls.Add(control); }; ControlsStripMenuItem.DropDownItems!.Add(item); } @@ -121,6 +127,7 @@ namespace Lab4.Forms _plugins[_selectedPlugin].ReloadData(); } } + private void DeleteElement() { if (MessageBox.Show("Удалить выбранный элемент", "Удаление", @@ -170,6 +177,7 @@ namespace Lab4.Forms _ = MessageBox.Show("Ошибка при создании документа", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } + private void CreateTableDoc() { using var saveFileDialog = new SaveFileDialog @@ -198,6 +206,7 @@ namespace Lab4.Forms _ = MessageBox.Show("Ошибка при создании документа", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } + private void CreateChartDoc() { using var saveFileDialog = new SaveFileDialog @@ -225,6 +234,7 @@ namespace Lab4.Forms _ = MessageBox.Show("Ошибка при создании документа", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } + private void ThesaurusToolStripMenuItem_Click(object sender, EventArgs e) => ShowThesaurus(); private void AddElementToolStripMenuItem_Click(object sender, EventArgs e) => AddNewElement(); diff --git a/Cop.Borovkov.Var3/Lab4/Implementations/PluginsConvention.cs b/Cop.Borovkov.Var3/Lab4/Implementations/PluginsConvention.cs index e2683c5..9f1253b 100644 --- a/Cop.Borovkov.Var3/Lab4/Implementations/PluginsConvention.cs +++ b/Cop.Borovkov.Var3/Lab4/Implementations/PluginsConvention.cs @@ -177,11 +177,11 @@ namespace Lab4.Implementations public Form GetThesaurus() => new CatalogForm(_educationFormRepository); - public void ReloadData() + public async void ReloadData() { try { - var students = _mapper.Map>(_studentRepository.GetAsync().Result); + var students = _mapper.Map>(await _studentRepository.GetAsync()); _control.FillValues( students.Select(s => string.Join(" ", From feb13d4d0f8d52d0e7be51aa5800fd120d08618b Mon Sep 17 00:00:00 2001 From: bekodeg Date: Mon, 9 Dec 2024 20:23:39 +0400 Subject: [PATCH 19/20] + --- Cop.Borovkov.Var3/Cop.Borovkov.Var3.sln | 8 +- .../Lab4.Plugins/Extensions/DiExtensions.cs | 20 +++ .../Implementations/PluginsConvention.cs | 59 ++++++--- .../Lab4.Plugins/Lab4.Plugins.csproj | 13 ++ .../Configurations/PluginsConfigurations.cs | 7 + .../Lab4/Extensions/DiExtensions.cs | 15 +-- Cop.Borovkov.Var3/Lab4/Forms/FormMain.cs | 56 ++++---- .../Lab4/Interfaces/IPluginsConvention.cs | 6 +- Cop.Borovkov.Var3/Lab4/Lab4.csproj | 4 +- .../Lab4/Models/PluginsConventionElement.cs | 2 +- .../Models/PluginsConventionSaveDocument.cs | 2 +- Cop.Borovkov.Var3/Lab4/Program.cs | 16 +-- Cop.Borovkov.Var3/Lab4/appsettings.json | 3 + .../Forms/Form3.Designer.cs | 59 +++++++++ .../TestCustomComponents/Forms/Form3.cs | 28 ++++ .../TestCustomComponents/Forms/Form3.resx | 120 ++++++++++++++++++ .../TestCustomComponents/Program.cs | 2 +- .../TestCustomComponents.csproj | 2 +- 18 files changed, 343 insertions(+), 79 deletions(-) create mode 100644 Cop.Borovkov.Var3/Lab4.Plugins/Extensions/DiExtensions.cs rename Cop.Borovkov.Var3/{Lab4 => Lab4.Plugins}/Implementations/PluginsConvention.cs (80%) create mode 100644 Cop.Borovkov.Var3/Lab4.Plugins/Lab4.Plugins.csproj create mode 100644 Cop.Borovkov.Var3/Lab4/Configurations/PluginsConfigurations.cs create mode 100644 Cop.Borovkov.Var3/TestCustomComponents/Forms/Form3.Designer.cs create mode 100644 Cop.Borovkov.Var3/TestCustomComponents/Forms/Form3.cs create mode 100644 Cop.Borovkov.Var3/TestCustomComponents/Forms/Form3.resx diff --git a/Cop.Borovkov.Var3/Cop.Borovkov.Var3.sln b/Cop.Borovkov.Var3/Cop.Borovkov.Var3.sln index ac79906..f71bc15 100644 --- a/Cop.Borovkov.Var3/Cop.Borovkov.Var3.sln +++ b/Cop.Borovkov.Var3/Cop.Borovkov.Var3.sln @@ -11,7 +11,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lab3", "Lab3\Lab3.csproj", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lab3.Database", "Lab3.Database\Lab3.Database.csproj", "{698DE9E8-7885-4F98-AFE3-9A9C6CD2FCF5}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab4", "Lab4\Lab4.csproj", "{FAE92C0B-0A2D-48B6-A55C-DE58A310CD58}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lab4", "Lab4\Lab4.csproj", "{FAE92C0B-0A2D-48B6-A55C-DE58A310CD58}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab4.Plugins", "Lab4.Plugins\Lab4.Plugins.csproj", "{F30C8C78-98CB-4C5E-BEE8-125791A9D7AF}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -39,6 +41,10 @@ Global {FAE92C0B-0A2D-48B6-A55C-DE58A310CD58}.Debug|Any CPU.Build.0 = Debug|Any CPU {FAE92C0B-0A2D-48B6-A55C-DE58A310CD58}.Release|Any CPU.ActiveCfg = Release|Any CPU {FAE92C0B-0A2D-48B6-A55C-DE58A310CD58}.Release|Any CPU.Build.0 = Release|Any CPU + {F30C8C78-98CB-4C5E-BEE8-125791A9D7AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F30C8C78-98CB-4C5E-BEE8-125791A9D7AF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F30C8C78-98CB-4C5E-BEE8-125791A9D7AF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F30C8C78-98CB-4C5E-BEE8-125791A9D7AF}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Cop.Borovkov.Var3/Lab4.Plugins/Extensions/DiExtensions.cs b/Cop.Borovkov.Var3/Lab4.Plugins/Extensions/DiExtensions.cs new file mode 100644 index 0000000..46e0253 --- /dev/null +++ b/Cop.Borovkov.Var3/Lab4.Plugins/Extensions/DiExtensions.cs @@ -0,0 +1,20 @@ +using Lab4.Interfaces; +using Lab4.Plugins.Implementations; +using Microsoft.Extensions.DependencyInjection; + +namespace Lab4.Plugins.Extensions +{ + public static class DiExtensions + { + public static IServiceCollection AddScopes( + this IServiceCollection services) + { + services.AddScoped(); + + services.AddScoped>(sp + => (type) => (sp.GetRequiredService(type) as IPluginsConvention)!); + + return services; + } + } +} diff --git a/Cop.Borovkov.Var3/Lab4/Implementations/PluginsConvention.cs b/Cop.Borovkov.Var3/Lab4.Plugins/Implementations/PluginsConvention.cs similarity index 80% rename from Cop.Borovkov.Var3/Lab4/Implementations/PluginsConvention.cs rename to Cop.Borovkov.Var3/Lab4.Plugins/Implementations/PluginsConvention.cs index 9f1253b..fe1997b 100644 --- a/Cop.Borovkov.Var3/Lab4/Implementations/PluginsConvention.cs +++ b/Cop.Borovkov.Var3/Lab4.Plugins/Implementations/PluginsConvention.cs @@ -1,17 +1,22 @@ -using Cop.Borovkov.Var3.Components; -using Lab4.Interfaces; -using Lab4.Models; +using Lab4.Plugins.Models; +using AutoMapper; using Lab3.Database.Repository.Interfaces; -using ComponentsLibrary.entities; +using Cop.Borovkov.Var3.Components; +using CustomComponentsVar2; using ComponentsLibrary; +using System.Windows.Forms; +using ComponentsLibrary.entities; using ComponentsLibrary.entities.enums; using Lab3.Database.DTO; -using CustomComponentsVar2; using Lab3.Forms; using Lab3.Models; -using AutoMapper; +using Lab4.Interfaces; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Configuration; +using Lab3.Extensions; +using Microsoft.Extensions.DependencyInjection; -namespace Lab4.Implementations +namespace Lab4.Plugins.Implementations { public class PluginsConvention : IPluginsConvention { @@ -24,26 +29,26 @@ namespace Lab4.Implementations private readonly CustomExcelTable _tableCreator; private readonly ComponentDiagram _chartCreator; - public PluginsConvention( - IMapper mapper, - IStudentRepository studentRepository, - IEducationFormRepository educationFormRepository) + public PluginsConvention() { - _mapper = mapper; - _studentRepository = studentRepository; - _educationFormRepository = educationFormRepository; - _control = new(); _chartCreator = new(); _tableCreator = new(); _simpleDocumentCreator = new(); + + var serviceProvider = CreateServiceProvider(); + + _mapper = serviceProvider.GetRequiredService(); + _studentRepository = serviceProvider.GetRequiredService(); + _educationFormRepository = serviceProvider.GetRequiredService(); } public string PluginName => "Успеваемость"; public UserControl GetControl => _control; - public PluginsConventionElement GetElement { + public PluginsConventionElement GetElement + { get { var filds = _control.Selected.Split(); @@ -93,7 +98,7 @@ namespace Lab4.Implementations { try { - var values = (_studentRepository.GetAsync()).Result + var values = _studentRepository.GetAsync().Result .Select(s => s.StudentSessions .OrderBy(x => x.Number) .Select(x => x.Score.ToString()) @@ -171,10 +176,10 @@ namespace Lab4.Implementations } } - public Form GetForm(PluginsConventionElement? element = null) + public Form GetForm(PluginsConventionElement? element = null) => new CreateForm(_studentRepository, _educationFormRepository, element?.Id); - public Form GetThesaurus() + public Form GetThesaurus() => new CatalogForm(_educationFormRepository); public async void ReloadData() @@ -182,7 +187,7 @@ namespace Lab4.Implementations try { var students = _mapper.Map>(await _studentRepository.GetAsync()); - + _control.FillValues( students.Select(s => string.Join(" ", [ @@ -200,5 +205,19 @@ namespace Lab4.Implementations } } + + static IServiceProvider CreateServiceProvider() + { + var builder = Host.CreateDefaultBuilder() + .ConfigureAppConfiguration(c + => c.AddJsonFile("appsettings.plugins.json", optional: true, reloadOnChange: true)) + .ConfigureServices((context, services) => { + services.ConfigureDAL(context.Configuration); + services.AddMapping(); + services.AddLab3Forms(); + }); + + return builder.Build().Services; + } } } diff --git a/Cop.Borovkov.Var3/Lab4.Plugins/Lab4.Plugins.csproj b/Cop.Borovkov.Var3/Lab4.Plugins/Lab4.Plugins.csproj new file mode 100644 index 0000000..5b7c256 --- /dev/null +++ b/Cop.Borovkov.Var3/Lab4.Plugins/Lab4.Plugins.csproj @@ -0,0 +1,13 @@ + + + + net8.0-windows7.0 + enable + enable + + + + + + + diff --git a/Cop.Borovkov.Var3/Lab4/Configurations/PluginsConfigurations.cs b/Cop.Borovkov.Var3/Lab4/Configurations/PluginsConfigurations.cs new file mode 100644 index 0000000..93085bb --- /dev/null +++ b/Cop.Borovkov.Var3/Lab4/Configurations/PluginsConfigurations.cs @@ -0,0 +1,7 @@ +namespace Lab4 +{ + public record PluginsConfigurations + { + public string FolderPath { get; set; } = string.Empty; + } +} diff --git a/Cop.Borovkov.Var3/Lab4/Extensions/DiExtensions.cs b/Cop.Borovkov.Var3/Lab4/Extensions/DiExtensions.cs index 129b87a..58f150c 100644 --- a/Cop.Borovkov.Var3/Lab4/Extensions/DiExtensions.cs +++ b/Cop.Borovkov.Var3/Lab4/Extensions/DiExtensions.cs @@ -1,29 +1,16 @@ using Lab4.Forms; -using Lab4.Implementations; -using Lab4.Interfaces; using Microsoft.Extensions.DependencyInjection; namespace Lab4.Extensions { public static class DiExtensions { - public static IServiceCollection AddLab4Forms( + public static IServiceCollection AddForms( this IServiceCollection services) { services.AddScoped(); return services; } - - public static IServiceCollection AddScopes( - this IServiceCollection services) - { - services.AddScoped(); - - services.AddScoped>(sp - => (type) => (sp.GetRequiredService(type) as IPluginsConvention)!); - - return services; - } } } diff --git a/Cop.Borovkov.Var3/Lab4/Forms/FormMain.cs b/Cop.Borovkov.Var3/Lab4/Forms/FormMain.cs index bc5a9c1..b01a42d 100644 --- a/Cop.Borovkov.Var3/Lab4/Forms/FormMain.cs +++ b/Cop.Borovkov.Var3/Lab4/Forms/FormMain.cs @@ -1,40 +1,48 @@ using Lab4.Interfaces; -using Lab4.Models; +using Lab4.Plugins.Models; +using Microsoft.Extensions.Options; +using System.Reflection; namespace Lab4.Forms { public partial class FormMain : Form { private readonly Dictionary _plugins; - private string _selectedPlugin; + private readonly PluginsConfigurations _pluginsConfigurations; + private string _selectedPlugin = string.Empty; - private readonly Func _getPluginObjectFunc; - - public FormMain(Func getPluginObjectFunc) + public FormMain(IOptions pluginsConfigs) { InitializeComponent(); - - _getPluginObjectFunc = getPluginObjectFunc; + + _pluginsConfigurations = pluginsConfigs.Value; _plugins = LoadPlugins(); - _selectedPlugin = string.Empty; } private Dictionary LoadPlugins() { Dictionary result = []; - var plurinType = typeof(IPluginsConvention); + var plurinInterface = typeof(IPluginsConvention); - foreach (var type in AppDomain.CurrentDomain - .GetAssemblies() + foreach (var type in Directory + .GetFiles(_pluginsConfigurations.FolderPath, "*.dll", SearchOption.AllDirectories) + .Select(Assembly.LoadFrom) .SelectMany(x => x.GetTypes()) - .Where(x => plurinType.IsAssignableFrom(x) && x != plurinType)) + .Where(x => plurinInterface.IsAssignableFrom(x) && !x.IsInterface)) { - var plugin = _getPluginObjectFunc(type); + var plugin = type.GetConstructor([])?.Invoke([]); - string key = plugin.PluginName; - result[key] = plugin; + if (plugin == null) + { + continue; + } + + IPluginsConvention pluginObject = (plugin as IPluginsConvention)!; + + string key = pluginObject.PluginName; + result[key] = pluginObject; var item = new ToolStripMenuItem(key); item.Click += (s, e) => @@ -127,7 +135,7 @@ namespace Lab4.Forms _plugins[_selectedPlugin].ReloadData(); } } - + private void DeleteElement() { if (MessageBox.Show("Удалить выбранный элемент", "Удаление", @@ -177,7 +185,7 @@ namespace Lab4.Forms _ = MessageBox.Show("Ошибка при создании документа", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } - + private void CreateTableDoc() { using var saveFileDialog = new SaveFileDialog @@ -206,7 +214,7 @@ namespace Lab4.Forms _ = MessageBox.Show("Ошибка при создании документа", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } - + private void CreateChartDoc() { using var saveFileDialog = new SaveFileDialog @@ -221,7 +229,7 @@ namespace Lab4.Forms if (_plugins[_selectedPlugin].CreateChartDocument(new PluginsConventionSaveDocument() { - FileName= saveFileDialog.FileName, + FileName = saveFileDialog.FileName, })) { _ = MessageBox.Show("Документ сохранен", @@ -234,15 +242,15 @@ namespace Lab4.Forms _ = MessageBox.Show("Ошибка при создании документа", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } - + private void ThesaurusToolStripMenuItem_Click(object sender, EventArgs e) => ShowThesaurus(); - + private void AddElementToolStripMenuItem_Click(object sender, EventArgs e) => AddNewElement(); - + private void UpdElementToolStripMenuItem_Click(object sender, EventArgs e) => UpdateElement(); - + private void DelElementToolStripMenuItem_Click(object sender, EventArgs e) => DeleteElement(); - + private void SimpleDocToolStripMenuItem_Click(object sender, EventArgs e) => CreateSimpleDoc(); private void TableDocToolStripMenuItem_Click(object sender, EventArgs e) => CreateTableDoc(); diff --git a/Cop.Borovkov.Var3/Lab4/Interfaces/IPluginsConvention.cs b/Cop.Borovkov.Var3/Lab4/Interfaces/IPluginsConvention.cs index 43b757b..b59da6b 100644 --- a/Cop.Borovkov.Var3/Lab4/Interfaces/IPluginsConvention.cs +++ b/Cop.Borovkov.Var3/Lab4/Interfaces/IPluginsConvention.cs @@ -1,4 +1,4 @@ -using Lab4.Models; +using Lab4.Plugins.Models; namespace Lab4.Interfaces { @@ -12,7 +12,7 @@ namespace Lab4.Interfaces /// /// Получение контрола для вывода набора данных /// - UserControl GetControl { get; } + UserControl GetControl { get; } /// /// Получение элемента, выбранного в контроле @@ -25,7 +25,7 @@ namespace Lab4.Interfaces /// /// Form GetForm(PluginsConventionElement? element = null); - + /// /// Получение формы для работы со справочником /// diff --git a/Cop.Borovkov.Var3/Lab4/Lab4.csproj b/Cop.Borovkov.Var3/Lab4/Lab4.csproj index 13f756f..7231068 100644 --- a/Cop.Borovkov.Var3/Lab4/Lab4.csproj +++ b/Cop.Borovkov.Var3/Lab4/Lab4.csproj @@ -9,7 +9,9 @@ - + + + diff --git a/Cop.Borovkov.Var3/Lab4/Models/PluginsConventionElement.cs b/Cop.Borovkov.Var3/Lab4/Models/PluginsConventionElement.cs index c5b9472..4f1670e 100644 --- a/Cop.Borovkov.Var3/Lab4/Models/PluginsConventionElement.cs +++ b/Cop.Borovkov.Var3/Lab4/Models/PluginsConventionElement.cs @@ -1,4 +1,4 @@ -namespace Lab4.Models +namespace Lab4.Plugins.Models { public class PluginsConventionElement { diff --git a/Cop.Borovkov.Var3/Lab4/Models/PluginsConventionSaveDocument.cs b/Cop.Borovkov.Var3/Lab4/Models/PluginsConventionSaveDocument.cs index d5e4fc7..aac33c1 100644 --- a/Cop.Borovkov.Var3/Lab4/Models/PluginsConventionSaveDocument.cs +++ b/Cop.Borovkov.Var3/Lab4/Models/PluginsConventionSaveDocument.cs @@ -1,4 +1,4 @@ -namespace Lab4.Models +namespace Lab4.Plugins.Models { public class PluginsConventionSaveDocument { diff --git a/Cop.Borovkov.Var3/Lab4/Program.cs b/Cop.Borovkov.Var3/Lab4/Program.cs index e6464cf..0df2534 100644 --- a/Cop.Borovkov.Var3/Lab4/Program.cs +++ b/Cop.Borovkov.Var3/Lab4/Program.cs @@ -1,5 +1,3 @@ -using Lab3.Extensions; -using Lab3.Forms; using Lab4.Extensions; using Lab4.Forms; using Microsoft.Extensions.Configuration; @@ -31,16 +29,10 @@ namespace Lab4 .ConfigureAppConfiguration(c => c.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)) .ConfigureServices((context, services) => { - - services.ConfigureDAL(context.Configuration); - - services.AddMapping(); - - services.AddLab3Forms(); - services.AddLab4Forms(); - - services.AddScopes(); - }); + services.AddForms(); + services.Configure( + context.Configuration.GetSection(nameof(PluginsConfigurations))); + }); } } } \ No newline at end of file diff --git a/Cop.Borovkov.Var3/Lab4/appsettings.json b/Cop.Borovkov.Var3/Lab4/appsettings.json index 751a2b0..9ce9598 100644 --- a/Cop.Borovkov.Var3/Lab4/appsettings.json +++ b/Cop.Borovkov.Var3/Lab4/appsettings.json @@ -1,4 +1,7 @@ { + "PluginsConfigurations": { + "FolderPath": "C:\\data\\Plugins" + }, "ConnectionStrings": { "COPDataBase": "Host=localhost;Username=postgres;Password=postgres;Database=COP" } diff --git a/Cop.Borovkov.Var3/TestCustomComponents/Forms/Form3.Designer.cs b/Cop.Borovkov.Var3/TestCustomComponents/Forms/Form3.Designer.cs new file mode 100644 index 0000000..c8a9ddf --- /dev/null +++ b/Cop.Borovkov.Var3/TestCustomComponents/Forms/Form3.Designer.cs @@ -0,0 +1,59 @@ +namespace TestCustomComponents.Forms +{ + partial class Form3 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + button1 = new Button(); + SuspendLayout(); + // + // button1 + // + button1.Location = new Point(103, 83); + button1.Name = "button1"; + button1.Size = new Size(94, 29); + button1.TabIndex = 0; + button1.Text = "button1"; + button1.UseVisualStyleBackColor = true; + button1.Click += button1_Click; + // + // Form3 + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(button1); + Name = "Form3"; + Text = "Form3"; + ResumeLayout(false); + } + + #endregion + + private Button button1; + } +} \ No newline at end of file diff --git a/Cop.Borovkov.Var3/TestCustomComponents/Forms/Form3.cs b/Cop.Borovkov.Var3/TestCustomComponents/Forms/Form3.cs new file mode 100644 index 0000000..5dc6cb1 --- /dev/null +++ b/Cop.Borovkov.Var3/TestCustomComponents/Forms/Form3.cs @@ -0,0 +1,28 @@ +using Lab4.Plugins.Implementations; +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 TestCustomComponents.Forms +{ + public partial class Form3 : Form + { + public Form3() + { + InitializeComponent(); + } + + private void button1_Click(object sender, EventArgs e) + { + var test = new PluginsConvention(); + + int a = 1; + } + } +} diff --git a/Cop.Borovkov.Var3/TestCustomComponents/Forms/Form3.resx b/Cop.Borovkov.Var3/TestCustomComponents/Forms/Form3.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/Cop.Borovkov.Var3/TestCustomComponents/Forms/Form3.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Cop.Borovkov.Var3/TestCustomComponents/Program.cs b/Cop.Borovkov.Var3/TestCustomComponents/Program.cs index 13d3c8d..d570b34 100644 --- a/Cop.Borovkov.Var3/TestCustomComponents/Program.cs +++ b/Cop.Borovkov.Var3/TestCustomComponents/Program.cs @@ -13,7 +13,7 @@ namespace TestCustomComponents // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form2()); + Application.Run(new Form3()); } } } \ No newline at end of file diff --git a/Cop.Borovkov.Var3/TestCustomComponents/TestCustomComponents.csproj b/Cop.Borovkov.Var3/TestCustomComponents/TestCustomComponents.csproj index 588393f..5158f8d 100644 --- a/Cop.Borovkov.Var3/TestCustomComponents/TestCustomComponents.csproj +++ b/Cop.Borovkov.Var3/TestCustomComponents/TestCustomComponents.csproj @@ -9,7 +9,7 @@ - + \ No newline at end of file From af90779d63c389eca1852e2ea6b73229933f4502 Mon Sep 17 00:00:00 2001 From: bekodeg Date: Mon, 9 Dec 2024 20:29:56 +0400 Subject: [PATCH 20/20] + fix --- Cop.Borovkov.Var3/TestCustomComponents/Program.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Cop.Borovkov.Var3/TestCustomComponents/Program.cs b/Cop.Borovkov.Var3/TestCustomComponents/Program.cs index d7fd2d1..d570b34 100644 --- a/Cop.Borovkov.Var3/TestCustomComponents/Program.cs +++ b/Cop.Borovkov.Var3/TestCustomComponents/Program.cs @@ -1,3 +1,5 @@ +using TestCustomComponents.Forms; + namespace TestCustomComponents { internal static class Program