diff --git a/ProjectGSM/.idea/.idea.ProjectGSM.dir/.idea/encodings.xml b/ProjectGSM/.idea/.idea.ProjectGSM.dir/.idea/encodings.xml index df87cf9..4f8e4a9 100644 --- a/ProjectGSM/.idea/.idea.ProjectGSM.dir/.idea/encodings.xml +++ b/ProjectGSM/.idea/.idea.ProjectGSM.dir/.idea/encodings.xml @@ -1,4 +1,6 @@ - + + + \ No newline at end of file diff --git a/ProjectGSM/Documents/ChartReport.cs b/ProjectGSM/Documents/ChartReport.cs new file mode 100644 index 0000000..432c2bd --- /dev/null +++ b/ProjectGSM/Documents/ChartReport.cs @@ -0,0 +1,73 @@ +using Microsoft.Extensions.Logging; +using ProjectGSM.Repositories; + +namespace ProjectGSM.Documents; + +public class ChartReport +{ + private readonly ICaseRepository _caseRepository; + private readonly ICaseAdvocateRepository _caseAdvocateRepository; + private readonly IAdvocateRepository _advocateRepository; + private readonly ILogger _logger; + + public ChartReport(ICaseRepository caseRepository, + IAdvocateRepository advocateRepository, + ICaseAdvocateRepository caseAdvocateRepository, + ILogger logger) + { + _caseRepository = caseRepository ?? + throw new + ArgumentNullException(nameof(caseRepository)); + _advocateRepository = advocateRepository ?? + throw new ArgumentNullException(nameof(advocateRepository)); + _caseAdvocateRepository = caseAdvocateRepository ?? + throw new ArgumentNullException(nameof(caseAdvocateRepository)); + _logger = logger ?? + throw new ArgumentNullException(nameof(logger)); + } + + public bool CreateChart(string filePath, DateTime dateTime) + { + try + { + new PdfBuilder(filePath) + .AddHeader("Доля выручки адвоката") + .AddPieChart($"Всего до: {dateTime.Date}", GetData(dateTime)) + .Build(); + return true; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при формировании документа"); + return false; + } + } + + public List<(string, double)> GetData(DateTime dateTime) + { + try + { + var advocateEarnings = _caseRepository + .ReadCases() + .Where(x => x.CreatedAt.Date <= dateTime.Date) + .Join(_caseAdvocateRepository.ReadCaseAdvocates().Where(x => x.CreatedAt.Date <= dateTime.Date), + caseItem => caseItem.Id, + caseAdvocate => caseAdvocate.CaseId, + (caseItem, caseAdvocate) => new { caseItem, caseAdvocate }) + .GroupBy(x => x.caseAdvocate.AdvocateId, (key, group) => new + { + AdvocateName = _advocateRepository.ReadAdvocateById(key)?.Name ?? "Unknown", + Earnings = group.Sum(x => x.caseItem.Payment ? (x.caseItem.Verdict ? x.caseItem.VictoryPrice : x.caseItem.Price) : 0) + }) + .Select(x => (x.AdvocateName, (double)x.Earnings)) + .ToList(); + + return advocateEarnings; + } + catch (Exception ex) + { + _logger.LogError(ex, "Error occurred while calculating advocate earnings"); + return new List<(string, double)>(); + } + } +} \ No newline at end of file diff --git a/ProjectGSM/Documents/DocReport.cs b/ProjectGSM/Documents/DocReport.cs new file mode 100644 index 0000000..4ff05c0 --- /dev/null +++ b/ProjectGSM/Documents/DocReport.cs @@ -0,0 +1,113 @@ +using Microsoft.Extensions.Logging; +using ProjectGSM.Repositories; + +namespace ProjectGSM.Documents; + +public class DocReport +{ + private readonly IAdvocateRepository _advocateRepository; + private readonly IClientRepository _clientRepository; + private readonly ICourtRepository _courtRepository; + private readonly ILogger _logger; + + public DocReport(IAdvocateRepository advocateRepository, IClientRepository + clientRepository, + ICourtRepository courtRepository, ILogger logger) + { + _advocateRepository = advocateRepository ?? + throw new + ArgumentNullException(nameof(advocateRepository)); + _clientRepository = clientRepository ?? + throw new ArgumentNullException(nameof(clientRepository)); + _courtRepository = courtRepository ?? + throw new ArgumentNullException(nameof(courtRepository)); + _logger = logger ?? + throw new ArgumentNullException(nameof(logger)); + } + + public bool CreateDoc(string filePath, bool includeAdvocates, bool + includeClients, bool includeCourts) + { + try + { + var builder = new WordBuilder(filePath) + .AddHeader("Документ со справочниками"); + if (includeAdvocates) + { + builder.AddParagraph("Адвокаты") + .AddTable([2400, 1200, 2400, 1200, 1200, 1200, 2400, 2400, 2400, 5000], + GetAdvocates()); + } + + if (includeClients) + { + builder.AddParagraph("Клиенты") + .AddTable([2400, 2400, 2400, 2400, 2400, 2400], GetClients()); + } + + if (includeCourts) + { + builder.AddParagraph("Суды") + .AddTable([2400, 2400], GetCourts()); + } + + builder.Build(); + return true; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при формировании документа"); + return false; + } + } + + private List GetAdvocates() + { + return + [ + [ + "ФИО", "Пол", "Дата рождения", "Опыт", "Кол-во завершенных дел", "Рейтинг", "E-mail", "Номер телефона", + "Адрес", "Лицензии" + ], + .. _advocateRepository + .ReadAdvocates() + .Select(x => new[] + { + x.Name, + x.Sex ? "Мужчина" : "Женщина", x.DateOfBirth.ToShortDateString(), x.Experience.ToString(), + x.CompletedTasks.ToString(), x.Rating.ToString(), x.Email, x.PhoneNumber, x.Address, + x.LicenseType.ToString() + }), + ]; + } + + private List GetClients() + { + return + [ + ["ФИО", "Пол", "Дата рождения", "E-mail", "Номер телефона", "Адрес"], + .. _clientRepository + .ReadClients() + .Select(x => new[] + { + x.Name, + x.Sex ? "Мужчина" : "Женщина", x.DateOfBirth.ToShortDateString(), x.Email, x.PhoneNumber, x.Address + }), + ]; + } + + private List GetCourts() + { + return + [ + ["Название", "Адрес"], + .. _courtRepository + .ReadCourts() + .Select(x => new[] + { + x.Name, + x.Address + }), + ]; + } +} \ No newline at end of file diff --git a/ProjectGSM/Documents/ExcelBuilder.cs b/ProjectGSM/Documents/ExcelBuilder.cs new file mode 100644 index 0000000..db74429 --- /dev/null +++ b/ProjectGSM/Documents/ExcelBuilder.cs @@ -0,0 +1,286 @@ +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Spreadsheet; + +namespace ProjectGSM.Documents; + +public class ExcelBuilder +{ + private readonly string _filePath; + private readonly SheetData _sheetData; + private readonly MergeCells _mergeCells; + private readonly Columns _columns; + private uint _rowIndex = 0; + + public ExcelBuilder(string filePath) + { + if (string.IsNullOrWhiteSpace(filePath)) + { + throw new ArgumentNullException(nameof(filePath)); + } + + if (File.Exists(filePath)) + { + File.Delete(filePath); + } + + _filePath = filePath; + _sheetData = new SheetData(); + _mergeCells = new MergeCells(); + _columns = new Columns(); + _rowIndex = 1; + } + + public ExcelBuilder AddHeader(string header, int startIndex, int count) + { + CreateCell(startIndex, _rowIndex, header, + StyleIndex.BoldTextWithoutBorder); + for (int i = startIndex + 1; i < startIndex + count; ++i) + { + CreateCell(i, _rowIndex, "", + StyleIndex.BoldTextWithoutBorder); + } + + _mergeCells.Append(new MergeCell() + { + Reference = + new + StringValue( + $"{GetExcelColumnName(startIndex)}{_rowIndex}:{GetExcelColumnName(startIndex + count - 1)}{_rowIndex}") + }); + _rowIndex++; + return this; + } + + public ExcelBuilder AddParagraph(string text, int columnIndex) + { + CreateCell(columnIndex, _rowIndex++, text, + StyleIndex.SimpleTextWithoutBorder); + return this; + } + + public ExcelBuilder AddTable(int[] columnsWidths, List data) + { + if (columnsWidths == null || columnsWidths.Length == 0) + { + throw new ArgumentNullException(nameof(columnsWidths)); + } + + if (data == null || data.Count == 0) + { + throw new ArgumentNullException(nameof(data)); + } + + if (data.Any(x => x.Length != columnsWidths.Length)) + { + throw new InvalidOperationException("widths.Length != data.Length"); + } + + uint counter = 1; + int coef = 2; + _columns.Append(columnsWidths.Select(x => new Column + { + Min = counter, + Max = counter++, + Width = x * coef, + CustomWidth = true + })); + for (var j = 0; j < data.First().Length; ++j) + { + CreateCell(j, _rowIndex, data.First()[j], + StyleIndex.SimpleTextWithoutBorder); + } + + _rowIndex++; + for (var i = 1; i < data.Count - 1; ++i) + { + for (var j = 0; j < data[i].Length; ++j) + { + CreateCell(j, _rowIndex, data[i][j], + StyleIndex.SimpleTextWithoutBorder); + } + + _rowIndex++; + } + + for (var j = 0; j < data.Last().Length; ++j) + { + CreateCell(j, _rowIndex, data.Last()[j], + StyleIndex.SimpleTextWithoutBorder); + } + + _rowIndex++; + return this; + } + + public void Build() + { + using var spreadsheetDocument = SpreadsheetDocument.Create(_filePath, + SpreadsheetDocumentType.Workbook); + var workbookpart = spreadsheetDocument.AddWorkbookPart(); + GenerateStyle(workbookpart); + workbookpart.Workbook = new Workbook(); + var worksheetPart = workbookpart.AddNewPart(); + worksheetPart.Worksheet = new Worksheet(); + if (_columns.HasChildren) + { + worksheetPart.Worksheet.Append(_columns); + } + + worksheetPart.Worksheet.Append(_sheetData); + var sheets = + spreadsheetDocument.WorkbookPart!.Workbook.AppendChild(new Sheets()); + var sheet = new Sheet() + { + Id = + spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart), + SheetId = 1, + Name = "Лист 1" + }; + sheets.Append(sheet); + if (_mergeCells.HasChildren) + { + worksheetPart.Worksheet.InsertAfter(_mergeCells, + worksheetPart.Worksheet.Elements().First()); + } + } + + private static void GenerateStyle(WorkbookPart workbookPart) + { + var workbookStylesPart = + workbookPart.AddNewPart(); + workbookStylesPart.Stylesheet = new Stylesheet(); + var fonts = new Fonts() + { + Count = 2, KnownFonts = + BooleanValue.FromBoolean(true) + }; + fonts.Append(new DocumentFormat.OpenXml.Spreadsheet.Font + { + FontSize = new FontSize() { Val = 11 }, + FontName = new FontName() { Val = "Calibri" }, + FontFamilyNumbering = new FontFamilyNumbering() { Val = 2 }, + FontScheme = new FontScheme() + { + Val = new + EnumValue(FontSchemeValues.Minor) + }, + Bold = new Bold() + }); + + workbookStylesPart.Stylesheet.Append(fonts); + // Default Fill + var fills = new Fills() { Count = 1 }; + fills.Append(new Fill + { + PatternFill = new PatternFill() + { + PatternType = new + EnumValue(PatternValues.None) + } + }); + workbookStylesPart.Stylesheet.Append(fills); + // Default Border + var borders = new Borders() { Count = 2 }; + // Add a border with thin lines + borders.Append(new Border + { + LeftBorder = new LeftBorder { Style = BorderStyleValues.Thin }, + RightBorder = new RightBorder { Style = BorderStyleValues.Thin }, + TopBorder = new TopBorder { Style = BorderStyleValues.Thin }, + BottomBorder = new BottomBorder { Style = BorderStyleValues.Thin }, + DiagonalBorder = new DiagonalBorder() + }); + + workbookStylesPart.Stylesheet.Append(borders); + // Default cell format and a date cell format + var cellFormats = new CellFormats() { Count = 4 }; + + // Add additional cell formats + + // Add additional cell formats + cellFormats.Append(new CellFormat + { + NumberFormatId = 0, + FormatId = 0, + FontId = 1, // Use the bold font + BorderId = 1, // Use the thin border + FillId = 0, + Alignment = new Alignment() + { + Horizontal = HorizontalAlignmentValues.Left, + Vertical = VerticalAlignmentValues.Center, + WrapText = true + } + }); + + workbookStylesPart.Stylesheet.Append(cellFormats); + } + + private enum StyleIndex + { + SimpleTextWithoutBorder = 0, + BoldTextWithoutBorder = 1, + ItalicTextWithoutBorder = 2, + // Add more styles as needed + } + + private void CreateCell(int columnIndex, uint rowIndex, string text, + StyleIndex styleIndex) + { + var columnName = GetExcelColumnName(columnIndex); + var cellReference = columnName + rowIndex; + var row = _sheetData.Elements().FirstOrDefault(r => r.RowIndex! + == rowIndex); + if (row == null) + { + row = new Row() { RowIndex = rowIndex }; + _sheetData.Append(row); + } + + var newCell = row.Elements() + .FirstOrDefault(c => c.CellReference != null && + c.CellReference.Value == columnName + rowIndex); + if (newCell == null) + { + Cell? refCell = null; + foreach (Cell cell in row.Elements()) + { + if (cell.CellReference?.Value != null && + cell.CellReference.Value.Length == cellReference.Length) + { + if (String.Compare(cell.CellReference.Value, + cellReference, StringComparison.OrdinalIgnoreCase) > 0) + { + refCell = cell; + break; + } + } + } + + newCell = new Cell() { CellReference = cellReference }; + row.InsertBefore(newCell, refCell); + } + + newCell.CellValue = new CellValue(text); + newCell.DataType = CellValues.String; + newCell.StyleIndex = (uint)styleIndex; + } + + private static string GetExcelColumnName(int columnNumber) + { + columnNumber += 1; + int dividend = columnNumber; + string columnName = string.Empty; + int modulo; + while (dividend > 0) + { + modulo = (dividend - 1) % 26; + columnName = Convert.ToChar(65 + modulo).ToString() + + columnName; + dividend = (dividend - modulo) / 26; + } + + return columnName; + } +} \ No newline at end of file diff --git a/ProjectGSM/Documents/PdfBuilder.cs b/ProjectGSM/Documents/PdfBuilder.cs new file mode 100644 index 0000000..97777d8 --- /dev/null +++ b/ProjectGSM/Documents/PdfBuilder.cs @@ -0,0 +1,82 @@ +using MigraDoc.DocumentObjectModel; +using MigraDoc.DocumentObjectModel.Shapes.Charts; +using MigraDoc.Rendering; + +namespace ProjectGSM.Documents; + +public class PdfBuilder +{ + private readonly string _filePath; + private readonly Document _document; + + public PdfBuilder(string filePath) + { + if (string.IsNullOrWhiteSpace(filePath)) + { + throw new ArgumentNullException(nameof(filePath)); + } + + if (File.Exists(filePath)) + { + File.Delete(filePath); + } + + _filePath = filePath; + _document = new Document(); + DefineStyles(); + } + + public PdfBuilder AddHeader(string header) + { + _document.AddSection().AddParagraph(header, "NormalBold"); + return this; + } + + public PdfBuilder AddPieChart(string title, List<(string Caption, double + Value)> data) + { + if (data == null || data.Count == 0) + { + return this; + } + + var chart = new Chart(ChartType.Pie2D); + var series = chart.SeriesCollection.AddSeries(); + series.Add(data.Select(x => x.Value).ToArray()); + var xseries = chart.XValues.AddXSeries(); + xseries.Add(data.Select(x => x.Caption).ToArray()); + chart.DataLabel.Type = DataLabelType.Percent; + chart.DataLabel.Position = DataLabelPosition.OutsideEnd; + chart.Width = Unit.FromCentimeter(16); + chart.Height = Unit.FromCentimeter(12); + chart.TopArea.AddParagraph(title); + chart.XAxis.MajorTickMark = TickMarkType.Outside; + chart.YAxis.MajorTickMark = TickMarkType.Outside; + chart.YAxis.HasMajorGridlines = true; + chart.PlotArea.LineFormat.Width = 1; + chart.PlotArea.LineFormat.Visible = true; + chart.TopArea.AddLegend(); + _document.LastSection.Add(chart); + return this; + } + + public void Build() + { + var renderer = new PdfDocumentRenderer(true) + { + Document = _document + }; + renderer.RenderDocument(); + renderer.PdfDocument.Save(_filePath); + } + + private void DefineStyles() + { + var normalStyle = _document.Styles["Normal"]; + normalStyle.Font.Name = "Arial"; + normalStyle.Font.Size = 12; + + var normalBoldStyle = _document.Styles.AddStyle("NormalBold", "Normal"); + normalBoldStyle.Font.Bold = true; + } +} \ No newline at end of file diff --git a/ProjectGSM/Documents/TableReport.cs b/ProjectGSM/Documents/TableReport.cs new file mode 100644 index 0000000..e55c5f6 --- /dev/null +++ b/ProjectGSM/Documents/TableReport.cs @@ -0,0 +1,78 @@ +using Microsoft.Extensions.Logging; +using ProjectGSM.Entities; +using ProjectGSM.Repositories; + +namespace ProjectGSM.Documents; + +internal class TableReport +{ + private readonly ICaseRepository _caseRepository; + private readonly IStatusHistoryRepository _statusHistoryRepository; + private readonly ILogger _logger; + internal static readonly string[] item = ["Статусы", "Дата", "Изменений статуса"]; + + public TableReport( + ICaseRepository caseRepository, + IStatusHistoryRepository statusHistoryRepository, + ILogger logger) + { + _caseRepository = caseRepository ?? + throw new + ArgumentNullException(nameof(caseRepository)); + _statusHistoryRepository = statusHistoryRepository ?? + throw new + ArgumentNullException(nameof(statusHistoryRepository)); + _logger = logger ?? + throw new ArgumentNullException(nameof(logger)); + } + + public bool CreateTable(string filePath, int caseId, DateTime startDate, + DateTime endDate) + { + try + { + new ExcelBuilder(filePath) + .AddHeader($"Сводка по делу \"{_caseRepository.ReadCaseById(caseId).Description}\"", 0, 4) + .AddParagraph("за период", 0) + .AddTable([10, 10, 15], GetData(caseId, startDate, + endDate)) + .Build(); + return true; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при формировании документа"); + return false; + } + } + + private List GetData(int caseId, DateTime startDate, DateTime endDate) + { + var statusData = _statusHistoryRepository + .ReadStatusHistories() + .Where(x => x.CreatedAt >= startDate && x.CreatedAt <= endDate && x.CaseId == caseId) + .GroupBy(x => (x.Status, x.CreatedAt.Date)) + .Select(x => new + { + Status = x.Key.Status, + Date = x.Key.Date, + Count = x.Count() + }) + .ToList(); + + return new List() { item } + .Union( + statusData + .Select(x => new string[] + { + x.Status.ToString(), x.Date.ToString(), x.Count.ToString() + })) + .Union( + [ + [ + "Всего", "", statusData.Sum(x => x.Count).ToString() + ] + ]) + .ToList(); + } +} \ No newline at end of file diff --git a/ProjectGSM/Documents/WordBuilder.cs b/ProjectGSM/Documents/WordBuilder.cs new file mode 100644 index 0000000..f50f018 --- /dev/null +++ b/ProjectGSM/Documents/WordBuilder.cs @@ -0,0 +1,133 @@ +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Wordprocessing; + +internal class WordBuilder +{ + private readonly string _filePath; + private readonly Document _document; + private readonly Body _body; + + public WordBuilder(string filePath) + { + if (string.IsNullOrWhiteSpace(filePath)) + { + throw new ArgumentNullException(nameof(filePath)); + } + + if (File.Exists(filePath)) + { + File.Delete(filePath); + } + + _filePath = filePath; + _document = new Document(); + _body = _document.AppendChild(new Body()); + } + + public WordBuilder AddHeader(string header) + { + var paragraph = _body.AppendChild(new Paragraph()); + var run = paragraph.AppendChild(new Run()); + run.RunProperties = new RunProperties(new Bold()); + run.AppendChild(new Text(header)); + return this; + } + + public WordBuilder AddParagraph(string text) + { + var paragraph = _body.AppendChild(new Paragraph()); + var run = paragraph.AppendChild(new Run()); + run.AppendChild(new Text(text)); + return this; + } + + public WordBuilder AddTable(int[] widths, List data) + { + if (widths == null || widths.Length == 0) + { + throw new ArgumentNullException(nameof(widths)); + } + + if (data == null || data.Count == 0) + { + throw new ArgumentNullException(nameof(data)); + } + + if (data.Any(x => x.Length != widths.Length)) + { + throw new InvalidOperationException("widths.Length != data.Length"); + } + + var table = new Table(); + table.AppendChild(new TableProperties( + new TableBorders( + new TopBorder() + { + Val = new + EnumValue(BorderValues.Single), + Size = 12 + }, + new BottomBorder() + { + Val = new + EnumValue(BorderValues.Single), + Size = 12 + }, + new LeftBorder() + { + Val = new + EnumValue(BorderValues.Single), + Size = 12 + }, + new RightBorder() + { + Val = new + EnumValue(BorderValues.Single), + Size = 12 + }, + new InsideHorizontalBorder() + { + Val = new + EnumValue(BorderValues.Single), + Size = 12 + }, + new InsideVerticalBorder() + { + Val = new + EnumValue(BorderValues.Single), + Size = 12 + } + ) + )); + // Заголовок + var tr = new TableRow(); + for (var j = 0; j < widths.Length; ++j) + { + tr.Append(new TableCell( + new TableCellProperties(new TableCellWidth() + { + Width = + widths[j].ToString() + }), + new Paragraph(new Run(new RunProperties(new Bold()), new + Text(data.First()[j]))))); + } + + table.Append(tr); + // Данные + table.Append(data.Skip(1).Select(x => + new TableRow(x.Select(y => new TableCell(new Paragraph(new + Run(new Text(y)))))))); + _body.Append(table); + return this; + } + + public void Build() + { + using var wordDocument = WordprocessingDocument.Create(_filePath, + WordprocessingDocumentType.Document); + var mainPart = wordDocument.AddMainDocumentPart(); + mainPart.Document = _document; + } +} \ No newline at end of file diff --git a/ProjectGSM/FormAdvocateApp.Designer.cs b/ProjectGSM/FormAdvocateApp.Designer.cs index 05fca93..b70eb77 100644 --- a/ProjectGSM/FormAdvocateApp.Designer.cs +++ b/ProjectGSM/FormAdvocateApp.Designer.cs @@ -40,11 +40,14 @@ directoriesMenuItem = new ToolStripMenuItem(); clientsMenuItem = new ToolStripMenuItem(); advocatesMenuItem = new ToolStripMenuItem(); - casesMenuItem = new ToolStripMenuItem(); courtsToolStripMenuItem = new ToolStripMenuItem(); operationsMenuItem = new ToolStripMenuItem(); + casesMenuItem = new ToolStripMenuItem(); statusHistoryRepositoryMenuItem = new ToolStripMenuItem(); reportsMenuItem = new ToolStripMenuItem(); + infoToolStripMenuItem = new ToolStripMenuItem(); + caseToolStripMenuItem = new ToolStripMenuItem(); + statusesToolStripMenuItem = new ToolStripMenuItem(); menuStrip.SuspendLayout(); SuspendLayout(); // @@ -68,28 +71,21 @@ // clientsMenuItem // clientsMenuItem.Name = "clientsMenuItem"; - clientsMenuItem.Size = new Size(161, 22); + clientsMenuItem.Size = new Size(127, 22); clientsMenuItem.Text = "Клиенты"; clientsMenuItem.Click += clientsMenuItem_Click_1; // // advocatesMenuItem // advocatesMenuItem.Name = "advocatesMenuItem"; - advocatesMenuItem.Size = new Size(161, 22); + advocatesMenuItem.Size = new Size(127, 22); advocatesMenuItem.Text = "Адвокаты"; advocatesMenuItem.Click += advocatesMenuItem_Click; // - // casesMenuItem - // - casesMenuItem.Name = "casesMenuItem"; - casesMenuItem.Size = new Size(161, 22); - casesMenuItem.Text = "Дела"; - casesMenuItem.Click += casesMenuItem_Click; - // // courtsToolStripMenuItem // courtsToolStripMenuItem.Name = "courtsToolStripMenuItem"; - courtsToolStripMenuItem.Size = new Size(161, 22); + courtsToolStripMenuItem.Size = new Size(127, 22); courtsToolStripMenuItem.Text = "Суды"; courtsToolStripMenuItem.Click += courtsToolStripMenuItem_Click; // @@ -100,19 +96,48 @@ operationsMenuItem.Size = new Size(75, 20); operationsMenuItem.Text = "Операции"; // + // casesMenuItem + // + casesMenuItem.Name = "casesMenuItem"; + casesMenuItem.Size = new Size(191, 22); + casesMenuItem.Text = "Дела"; + casesMenuItem.Click += casesMenuItem_Click; + // // statusHistoryRepositoryMenuItem // statusHistoryRepositoryMenuItem.Name = "statusHistoryRepositoryMenuItem"; - statusHistoryRepositoryMenuItem.Size = new Size(221, 22); + statusHistoryRepositoryMenuItem.Size = new Size(191, 22); statusHistoryRepositoryMenuItem.Text = "Хронология статусов"; statusHistoryRepositoryMenuItem.Click += statusHistoryRepositoryMenuItem_Click; // // reportsMenuItem // + reportsMenuItem.DropDownItems.AddRange(new ToolStripItem[] { infoToolStripMenuItem, caseToolStripMenuItem, statusesToolStripMenuItem }); reportsMenuItem.Name = "reportsMenuItem"; reportsMenuItem.Size = new Size(60, 20); reportsMenuItem.Text = "Отчеты"; // + // infoToolStripMenuItem + // + infoToolStripMenuItem.Name = "infoToolStripMenuItem"; + infoToolStripMenuItem.Size = new Size(207, 22); + infoToolStripMenuItem.Text = "Выгрузка справочников"; + infoToolStripMenuItem.Click += infoToolStripMenuItem_Click; + // + // caseToolStripMenuItem + // + caseToolStripMenuItem.Name = "caseToolStripMenuItem"; + caseToolStripMenuItem.Size = new Size(207, 22); + caseToolStripMenuItem.Text = "Отчет по делам"; + caseToolStripMenuItem.Click += caseToolStripMenuItem_Click; + // + // statusesToolStripMenuItem + // + statusesToolStripMenuItem.Name = "statusesToolStripMenuItem"; + statusesToolStripMenuItem.Size = new Size(207, 22); + statusesToolStripMenuItem.Text = "Статусы дел"; + statusesToolStripMenuItem.Click += statusesToolStripMenuItem_Click; + // // FormAdvocateApp // AutoScaleDimensions = new SizeF(7F, 15F); @@ -134,5 +159,8 @@ #endregion private ToolStripMenuItem courtsToolStripMenuItem; + private ToolStripMenuItem infoToolStripMenuItem; + private ToolStripMenuItem caseToolStripMenuItem; + private ToolStripMenuItem statusesToolStripMenuItem; } } diff --git a/ProjectGSM/FormAdvocateApp.cs b/ProjectGSM/FormAdvocateApp.cs index 6225014..d21717e 100644 --- a/ProjectGSM/FormAdvocateApp.cs +++ b/ProjectGSM/FormAdvocateApp.cs @@ -77,5 +77,42 @@ throw new ArgumentNullException(nameof(container)); MessageBoxButtons.OK, MessageBoxIcon.Error); } } + + private void infoToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void caseToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void statusesToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } } } diff --git a/ProjectGSM/Forms/FormCaseReport.Designer.cs b/ProjectGSM/Forms/FormCaseReport.Designer.cs new file mode 100644 index 0000000..075d7f7 --- /dev/null +++ b/ProjectGSM/Forms/FormCaseReport.Designer.cs @@ -0,0 +1,163 @@ +namespace ProjectGSM.Forms +{ + partial class FormCaseReport + { + /// + /// 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() + { + textBoxFilePath = new TextBox(); + fileLabel = new Label(); + labelCase = new Label(); + comboBoxCase = new ComboBox(); + labelData1 = new Label(); + labelDate2 = new Label(); + dateTimePickerBegin = new DateTimePicker(); + dateTimePickerEnd = new DateTimePicker(); + ButtonSelectFilePath = new Button(); + buttonMakeReport = new Button(); + SuspendLayout(); + // + // textBoxFilePath + // + textBoxFilePath.Enabled = false; + textBoxFilePath.Location = new Point(124, 30); + textBoxFilePath.Name = "textBoxFilePath"; + textBoxFilePath.Size = new Size(163, 23); + textBoxFilePath.TabIndex = 0; + // + // fileLabel + // + fileLabel.AutoSize = true; + fileLabel.Location = new Point(28, 33); + fileLabel.Name = "fileLabel"; + fileLabel.Size = new Size(90, 15); + fileLabel.TabIndex = 1; + fileLabel.Text = "Путь до файла:"; + // + // labelCase + // + labelCase.AutoSize = true; + labelCase.Location = new Point(28, 77); + labelCase.Name = "labelCase"; + labelCase.Size = new Size(38, 15); + labelCase.TabIndex = 2; + labelCase.Text = "Дело:"; + // + // comboBoxCase + // + comboBoxCase.FormattingEnabled = true; + comboBoxCase.Location = new Point(124, 69); + comboBoxCase.Name = "comboBoxCase"; + comboBoxCase.Size = new Size(200, 23); + comboBoxCase.TabIndex = 3; + // + // labelData1 + // + labelData1.AutoSize = true; + labelData1.Location = new Point(28, 128); + labelData1.Name = "labelData1"; + labelData1.Size = new Size(77, 15); + labelData1.TabIndex = 4; + labelData1.Text = "Дата начала:"; + // + // labelDate2 + // + labelDate2.AutoSize = true; + labelDate2.Location = new Point(28, 177); + labelDate2.Name = "labelDate2"; + labelDate2.Size = new Size(71, 15); + labelDate2.TabIndex = 5; + labelDate2.Text = "Дата конца:"; + // + // dateTimePickerBegin + // + dateTimePickerBegin.Location = new Point(124, 122); + dateTimePickerBegin.Name = "dateTimePickerBegin"; + dateTimePickerBegin.Size = new Size(200, 23); + dateTimePickerBegin.TabIndex = 6; + // + // dateTimePickerEnd + // + dateTimePickerEnd.Location = new Point(124, 171); + dateTimePickerEnd.Name = "dateTimePickerEnd"; + dateTimePickerEnd.Size = new Size(200, 23); + dateTimePickerEnd.TabIndex = 7; + // + // ButtonSelectFilePath + // + ButtonSelectFilePath.Location = new Point(293, 30); + ButtonSelectFilePath.Name = "ButtonSelectFilePath"; + ButtonSelectFilePath.Size = new Size(31, 23); + ButtonSelectFilePath.TabIndex = 8; + ButtonSelectFilePath.Text = "..."; + ButtonSelectFilePath.UseVisualStyleBackColor = true; + ButtonSelectFilePath.Click += ButtonSelectFilePath_Click; + // + // buttonMakeReport + // + buttonMakeReport.Location = new Point(110, 221); + buttonMakeReport.Name = "buttonMakeReport"; + buttonMakeReport.Size = new Size(166, 23); + buttonMakeReport.TabIndex = 9; + buttonMakeReport.Text = "Сформировать"; + buttonMakeReport.UseVisualStyleBackColor = true; + buttonMakeReport.Click += ButtonMakeReport_Click; + // + // FormCaseReport + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(368, 257); + Controls.Add(buttonMakeReport); + Controls.Add(ButtonSelectFilePath); + Controls.Add(dateTimePickerEnd); + Controls.Add(dateTimePickerBegin); + Controls.Add(labelDate2); + Controls.Add(labelData1); + Controls.Add(comboBoxCase); + Controls.Add(labelCase); + Controls.Add(fileLabel); + Controls.Add(textBoxFilePath); + Name = "FormCaseReport"; + Text = "Отчет по статусам дела"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private TextBox textBoxFilePath; + private Label fileLabel; + private Label labelCase; + private ComboBox comboBoxCase; + private Label labelData1; + private Label labelDate2; + private DateTimePicker dateTimePickerBegin; + private DateTimePicker dateTimePickerEnd; + private Button ButtonSelectFilePath; + private Button buttonMakeReport; + } +} \ No newline at end of file diff --git a/ProjectGSM/Forms/FormCaseReport.cs b/ProjectGSM/Forms/FormCaseReport.cs new file mode 100644 index 0000000..aef9cb0 --- /dev/null +++ b/ProjectGSM/Forms/FormCaseReport.cs @@ -0,0 +1,94 @@ +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 ProjectGSM.Documents; +using ProjectGSM.Repositories; +using Unity; + +namespace ProjectGSM.Forms +{ + public partial class FormCaseReport : Form + { + private readonly IUnityContainer _container; + + public FormCaseReport(IUnityContainer container, ICaseRepository + feedRepository) + { + InitializeComponent(); + _container = container ?? + throw new ArgumentNullException(nameof(container)); + comboBoxCase.DataSource = feedRepository.ReadCases(); + comboBoxCase.DisplayMember = "Description"; + comboBoxCase.ValueMember = "Id"; + } + + private void ButtonSelectFilePath_Click(object sender, EventArgs e) + { + var sfd = new SaveFileDialog() + { + Filter = "Excel Files | *.xlsx" + }; + if (sfd.ShowDialog() != DialogResult.OK) + { + return; + } + + textBoxFilePath.Text = sfd.FileName; + } + + private void ButtonMakeReport_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(textBoxFilePath.Text)) + { + throw new Exception("Отсутствует имя файла для отчета"); + } + + if (comboBoxCase.SelectedIndex < 0) + { + throw new Exception("Не выбран корм"); + } + + if (dateTimePickerEnd.Value <= + dateTimePickerBegin.Value) + { + throw new Exception("Дата начала должна быть раньше даты окончания"); + } + + if + (_container.Resolve().CreateTable(textBoxFilePath.Text, + (int)comboBoxCase.SelectedValue!, + dateTimePickerBegin.Value, dateTimePickerEnd.Value)) + { + MessageBox.Show("Документ сформирован", + "Формирование документа", + MessageBoxButtons.OK, + MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Возникли ошибки при формировании документа. Подробности в логах", + "Формирование документа", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при создании очета", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonMakeReport_Click_1(object sender, EventArgs e) + { + + } + } +} \ No newline at end of file diff --git a/ProjectGSM/Forms/FormCaseReport.resx b/ProjectGSM/Forms/FormCaseReport.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/ProjectGSM/Forms/FormCaseReport.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/ProjectGSM/Forms/FormDirectoryReport.Designer.cs b/ProjectGSM/Forms/FormDirectoryReport.Designer.cs new file mode 100644 index 0000000..41e44e1 --- /dev/null +++ b/ProjectGSM/Forms/FormDirectoryReport.Designer.cs @@ -0,0 +1,99 @@ +namespace ProjectGSM.Forms +{ + partial class FormDirectoryReport + { + /// + /// 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() + { + checkBoxAdvocates = new CheckBox(); + checkBoxClients = new CheckBox(); + checkBoxCourts = new CheckBox(); + buttonBuild = new Button(); + SuspendLayout(); + // + // checkBoxAdvocates + // + checkBoxAdvocates.AutoSize = true; + checkBoxAdvocates.Location = new Point(58, 53); + checkBoxAdvocates.Name = "checkBoxAdvocates"; + checkBoxAdvocates.Size = new Size(79, 19); + checkBoxAdvocates.TabIndex = 0; + checkBoxAdvocates.Text = "Адвокаты"; + checkBoxAdvocates.UseVisualStyleBackColor = true; + // + // checkBoxClients + // + checkBoxClients.AutoSize = true; + checkBoxClients.Location = new Point(58, 78); + checkBoxClients.Name = "checkBoxClients"; + checkBoxClients.Size = new Size(74, 19); + checkBoxClients.TabIndex = 1; + checkBoxClients.Text = "Клиенты"; + checkBoxClients.UseVisualStyleBackColor = true; + // + // checkBoxCourts + // + checkBoxCourts.AutoSize = true; + checkBoxCourts.Location = new Point(58, 103); + checkBoxCourts.Name = "checkBoxCourts"; + checkBoxCourts.Size = new Size(55, 19); + checkBoxCourts.TabIndex = 2; + checkBoxCourts.Text = "Суды"; + checkBoxCourts.UseVisualStyleBackColor = true; + // + // buttonBuild + // + buttonBuild.Location = new Point(204, 74); + buttonBuild.Name = "buttonBuild"; + buttonBuild.Size = new Size(151, 23); + buttonBuild.TabIndex = 3; + buttonBuild.Text = "Сформировать"; + buttonBuild.UseVisualStyleBackColor = true; + buttonBuild.Click += ButtonBuild_Click; + // + // FormDirectoryReport + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(367, 173); + Controls.Add(buttonBuild); + Controls.Add(checkBoxCourts); + Controls.Add(checkBoxClients); + Controls.Add(checkBoxAdvocates); + Name = "FormDirectoryReport"; + Text = "Выгрузка справочников"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private CheckBox checkBoxAdvocates; + private CheckBox checkBoxClients; + private CheckBox checkBoxCourts; + private Button buttonBuild; + } +} \ No newline at end of file diff --git a/ProjectGSM/Forms/FormDirectoryReport.cs b/ProjectGSM/Forms/FormDirectoryReport.cs new file mode 100644 index 0000000..9d844d8 --- /dev/null +++ b/ProjectGSM/Forms/FormDirectoryReport.cs @@ -0,0 +1,66 @@ +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 ProjectGSM.Documents; +using Unity; + +namespace ProjectGSM.Forms +{ + public partial class FormDirectoryReport : Form + { + private readonly IUnityContainer _container; + public FormDirectoryReport(IUnityContainer container) + { + InitializeComponent(); + _container = container ?? + throw new ArgumentNullException(nameof(container)); + } + + private void ButtonBuild_Click(object sender, EventArgs e) + { + try + { + if (!checkBoxAdvocates.Checked && + !checkBoxClients.Checked && !checkBoxCourts.Checked) + { + throw new Exception("Не выбран ни один справочник для выгрузки"); + } + var sfd = new SaveFileDialog() + { + Filter = "Docx Files | *.docx" + }; + if (sfd.ShowDialog() != DialogResult.OK) + { + throw new Exception("Не выбран файла для отчета"); + } + if + (_container.Resolve().CreateDoc(sfd.FileName, checkBoxAdvocates.Checked, + checkBoxClients.Checked, + checkBoxCourts.Checked)) + { + MessageBox.Show("Документ сформирован", + "Формирование документа", + MessageBoxButtons.OK, + MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Возникли ошибки при формировании документа. Подробности в логах", + "Формирование документа", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при создании отчета", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + } +} diff --git a/ProjectGSM/Forms/FormDirectoryReport.resx b/ProjectGSM/Forms/FormDirectoryReport.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/ProjectGSM/Forms/FormDirectoryReport.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/ProjectGSM/Forms/FormStatusesCasesReport.Designer.cs b/ProjectGSM/Forms/FormStatusesCasesReport.Designer.cs new file mode 100644 index 0000000..99ffdde --- /dev/null +++ b/ProjectGSM/Forms/FormStatusesCasesReport.Designer.cs @@ -0,0 +1,107 @@ +namespace ProjectGSM.Forms +{ + partial class FormStatusesCasesReport + { + /// + /// 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() + { + ButtonSelectFileName = new Button(); + labelFileName = new Label(); + labelDate = new Label(); + dateTimePicker = new DateTimePicker(); + ButtonCreate = new Button(); + SuspendLayout(); + // + // ButtonSelectFileName + // + ButtonSelectFileName.Location = new Point(12, 12); + ButtonSelectFileName.Name = "ButtonSelectFileName"; + ButtonSelectFileName.Size = new Size(106, 23); + ButtonSelectFileName.TabIndex = 0; + ButtonSelectFileName.Text = "Выбрать"; + ButtonSelectFileName.UseVisualStyleBackColor = true; + ButtonSelectFileName.Click += ButtonSelectFileName_Click; + // + // labelFileName + // + labelFileName.AutoSize = true; + labelFileName.Location = new Point(202, 16); + labelFileName.Name = "labelFileName"; + labelFileName.Size = new Size(36, 15); + labelFileName.TabIndex = 1; + labelFileName.Text = "Файл"; + // + // labelDate + // + labelDate.AutoSize = true; + labelDate.Location = new Point(12, 58); + labelDate.Name = "labelDate"; + labelDate.Size = new Size(35, 15); + labelDate.TabIndex = 2; + labelDate.Text = "Дата:"; + // + // dateTimePicker + // + dateTimePicker.Location = new Point(74, 55); + dateTimePicker.Name = "dateTimePicker"; + dateTimePicker.Size = new Size(279, 23); + dateTimePicker.TabIndex = 3; + // + // ButtonCreate + // + ButtonCreate.Location = new Point(97, 97); + ButtonCreate.Name = "ButtonCreate"; + ButtonCreate.Size = new Size(154, 23); + ButtonCreate.TabIndex = 4; + ButtonCreate.Text = "Сформировать"; + ButtonCreate.UseVisualStyleBackColor = true; + ButtonCreate.Click += ButtonCreate_Click; + // + // FormStatusesCasesReport + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(365, 143); + Controls.Add(ButtonCreate); + Controls.Add(dateTimePicker); + Controls.Add(labelDate); + Controls.Add(labelFileName); + Controls.Add(ButtonSelectFileName); + Name = "FormStatusesCasesReport"; + Text = "Доля выручки адвоката"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button ButtonSelectFileName; + private Label labelFileName; + private Label labelDate; + private DateTimePicker dateTimePicker; + private Button ButtonCreate; + } +} \ No newline at end of file diff --git a/ProjectGSM/Forms/FormStatusesCasesReport.cs b/ProjectGSM/Forms/FormStatusesCasesReport.cs new file mode 100644 index 0000000..83d228a --- /dev/null +++ b/ProjectGSM/Forms/FormStatusesCasesReport.cs @@ -0,0 +1,72 @@ +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 ProjectGSM.Documents; +using Unity; + +namespace ProjectGSM.Forms +{ + public partial class FormStatusesCasesReport : Form + { + private string _fileName = string.Empty; + private readonly IUnityContainer _container; + + public FormStatusesCasesReport(IUnityContainer container) + { + InitializeComponent(); + _container = container ?? + throw new ArgumentNullException(nameof(container)); + } + + + private void ButtonSelectFileName_Click(object sender, EventArgs e) + { + var sfd = new SaveFileDialog() + { + Filter = "Pdf Files | *.pdf" + }; + if (sfd.ShowDialog() == DialogResult.OK) + { + _fileName = sfd.FileName; + labelFileName.Text = Path.GetFileName(_fileName); + } + } + + private void ButtonCreate_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(_fileName)) + { + throw new Exception("Отсутствует имя файла для отчета"); + } + + if + (_container.Resolve().CreateChart(_fileName, dateTimePicker.Value)) + { + MessageBox.Show("Документ сформирован", + "Формирование документа", + MessageBoxButtons.OK, + MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Возникли ошибки при формировании документа. Подробности в логах", + "Формирование документа", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при создании очета", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} \ No newline at end of file diff --git a/ProjectGSM/Forms/FormStatusesCasesReport.resx b/ProjectGSM/Forms/FormStatusesCasesReport.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/ProjectGSM/Forms/FormStatusesCasesReport.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/ProjectGSM/Program.cs b/ProjectGSM/Program.cs index c6cdc22..0564c54 100644 --- a/ProjectGSM/Program.cs +++ b/ProjectGSM/Program.cs @@ -1,7 +1,5 @@ -using System.Data.SqlClient; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; -using ProjectGSM.Forms; using ProjectGSM.Repositories; using ProjectGSM.Repositories.Implementations; using Serilog; @@ -33,6 +31,7 @@ namespace ProjectGSM container.RegisterType(new SingletonLifetimeManager()); + container.RegisterType(new TransientLifetimeManager()); container.RegisterType(new TransientLifetimeManager()); container.RegisterType(new TransientLifetimeManager()); container.RegisterType(new TransientLifetimeManager()); diff --git a/ProjectGSM/ProjectGSM.csproj b/ProjectGSM/ProjectGSM.csproj index dbf4ddf..cf144c9 100644 --- a/ProjectGSM/ProjectGSM.csproj +++ b/ProjectGSM/ProjectGSM.csproj @@ -51,7 +51,9 @@ + + diff --git a/ProjectGSM/Repositories/ICaseAdvocateRepository.cs b/ProjectGSM/Repositories/ICaseAdvocateRepository.cs new file mode 100644 index 0000000..441e4dc --- /dev/null +++ b/ProjectGSM/Repositories/ICaseAdvocateRepository.cs @@ -0,0 +1,10 @@ +using ProjectGSM.Entities; + +namespace ProjectGSM.Repositories; + +public interface ICaseAdvocateRepository +{ + IEnumerable ReadCaseAdvocates(DateTime? dateForm = null, DateTime? dateTo = null, + int? caseId = null, int? advocateId = null); + void CreateCaseAdvocates(CaseAdvocate caseAdvocate); +} \ No newline at end of file diff --git a/ProjectGSM/Repositories/Implementations/CaseAdvocatesRepository.cs b/ProjectGSM/Repositories/Implementations/CaseAdvocatesRepository.cs new file mode 100644 index 0000000..8c64473 --- /dev/null +++ b/ProjectGSM/Repositories/Implementations/CaseAdvocatesRepository.cs @@ -0,0 +1,64 @@ +using System.Data.SqlClient; +using System.Text.Json; +using Dapper; +using Microsoft.Extensions.Logging; +using Npgsql; +using ProjectGSM.Entities; + +namespace ProjectGSM.Repositories.Implementations; + +public class CaseAdvocatesRepository : ICaseAdvocateRepository +{ + private readonly IConnectionString _connectionString; + private readonly ILogger _logger; + + public CaseAdvocatesRepository(IConnectionString connectionString, + ILogger logger) + { + _connectionString = connectionString; + _logger = logger; + } + + public IEnumerable ReadCaseAdvocates(DateTime? dateForm = null, DateTime? dateTo = null, + int? caseId = null, int? statusId = null) + { + _logger.LogInformation("Получение всех объектов"); + try + { + using var connection = new + NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = "SELECT * FROM case_advocates"; + var caseAdvocates = + connection.Query(querySelect); + _logger.LogDebug("Полученные объекты: {json}", + JsonSerializer.Serialize(caseAdvocates)); + return caseAdvocates; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при чтении объектов"); + throw; + } + } + + public void CreateCaseAdvocates(CaseAdvocate caseAdvocate) + { + _logger.LogInformation("Добавление объекта"); + _logger.LogDebug("Объект: {json}", + JsonSerializer.Serialize(caseAdvocate)); + try + { + using var connection = new + NpgsqlConnection(_connectionString.ConnectionString); + var queryInsert = @" + INSERT INTO case_advocates (caseid, advocateid, post, createdat) + VALUES (@CaseId, @AdvocateId, @Post, @CreatedAt)"; + connection.Execute(queryInsert, caseAdvocate); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при добавлении объекта"); + throw; + } + } +} \ No newline at end of file