2024-12-08 18:01:44 +04:00
|
|
|
|
using DocumentFormat.OpenXml.Packaging;
|
|
|
|
|
using DocumentFormat.OpenXml.Spreadsheet;
|
|
|
|
|
using DocumentFormat.OpenXml;
|
|
|
|
|
using EmployeeManagmentBusinessLogic.BusinessLogic;
|
2024-12-07 23:36:29 +04:00
|
|
|
|
using EmployeeManagmentContracts.BusinessLogicContracts;
|
2024-12-02 23:48:58 +04:00
|
|
|
|
using EmployeeManagmentContracts.ViewModels;
|
2024-12-01 16:34:36 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
using System.Windows.Data;
|
|
|
|
|
using System.Windows.Documents;
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
using System.Windows.Media.Imaging;
|
2024-12-08 18:01:44 +04:00
|
|
|
|
using System.IO;
|
|
|
|
|
using Microsoft.Win32;
|
2024-12-01 16:34:36 +04:00
|
|
|
|
|
|
|
|
|
namespace EmployeeManagmentView.Employee.Vacation
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Логика взаимодействия для ViewVacationWindow.xaml
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class ViewVacationWindow : Window
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
private readonly IVacationLogic _vacationLogic;
|
2024-12-07 23:36:29 +04:00
|
|
|
|
private readonly IEmployeeLogic _employeeLogic;
|
|
|
|
|
private readonly IPhisicalPersonLogic _phisicalPersonLogic;
|
2024-12-02 23:48:58 +04:00
|
|
|
|
private IEnumerable<VacationViewModel> _allVacations;
|
2024-12-07 23:36:29 +04:00
|
|
|
|
private List<EmployeeViewModel> _employees;
|
2024-12-01 16:34:36 +04:00
|
|
|
|
|
2024-12-07 23:36:29 +04:00
|
|
|
|
public ViewVacationWindow(IVacationLogic vacationLogic, IEmployeeLogic employeeLogic, IPhisicalPersonLogic phisicalPersonLogic)
|
2024-12-01 16:34:36 +04:00
|
|
|
|
{
|
|
|
|
|
_vacationLogic = vacationLogic;
|
2024-12-07 23:36:29 +04:00
|
|
|
|
_employeeLogic = employeeLogic;
|
|
|
|
|
_phisicalPersonLogic = phisicalPersonLogic;
|
2024-12-01 16:34:36 +04:00
|
|
|
|
InitializeComponent();
|
2024-12-02 23:48:58 +04:00
|
|
|
|
LoadVacations();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LoadVacations()
|
|
|
|
|
{
|
|
|
|
|
_allVacations = _vacationLogic.GetFullList(); // Загрузка всех данных
|
|
|
|
|
VacationsDataGrid.ItemsSource = _allVacations;
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-08 18:01:44 +04:00
|
|
|
|
private void ExportToExcelButton_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var vacations = _vacationLogic.GetFullList();
|
|
|
|
|
|
|
|
|
|
if (vacations == null || !vacations.Any())
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Нет данных для экспорта.", "Внимание", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Открытие диалогового окна для сохранения файла
|
|
|
|
|
SaveFileDialog saveFileDialog = new SaveFileDialog
|
|
|
|
|
{
|
|
|
|
|
Filter = "Excel файлы (*.xlsx)|*.xlsx",
|
|
|
|
|
Title = "Сохранить отчет об отпусках",
|
|
|
|
|
FileName = "Отчет_отпуска.xlsx"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (saveFileDialog.ShowDialog() == true)
|
|
|
|
|
{
|
|
|
|
|
string filePath = saveFileDialog.FileName; // Путь и имя файла
|
|
|
|
|
GenerateExcelReport(filePath, vacations); // Генерация отчета
|
|
|
|
|
MessageBox.Show($"Отчет успешно сохранен: {filePath}", "Успех", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show($"Ошибка экспорта: {ex.Message}", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GenerateExcelReport(string filePath, List<VacationViewModel> vacations)
|
|
|
|
|
{
|
|
|
|
|
using (SpreadsheetDocument document = SpreadsheetDocument.Create(filePath, SpreadsheetDocumentType.Workbook))
|
|
|
|
|
{
|
|
|
|
|
// Создаем Workbook
|
|
|
|
|
WorkbookPart workbookPart = document.AddWorkbookPart();
|
|
|
|
|
workbookPart.Workbook = new Workbook();
|
|
|
|
|
|
|
|
|
|
// Создаем Worksheet
|
|
|
|
|
WorksheetPart worksheetPart = workbookPart.AddNewPart<WorksheetPart>();
|
|
|
|
|
worksheetPart.Worksheet = new Worksheet(new SheetData());
|
|
|
|
|
|
|
|
|
|
// Добавляем лист в Workbook
|
|
|
|
|
Sheets sheets = document.WorkbookPart.Workbook.AppendChild(new Sheets());
|
|
|
|
|
Sheet sheet = new Sheet()
|
|
|
|
|
{
|
|
|
|
|
Id = document.WorkbookPart.GetIdOfPart(worksheetPart),
|
|
|
|
|
SheetId = 1,
|
|
|
|
|
Name = "Отпуска"
|
|
|
|
|
};
|
|
|
|
|
sheets.Append(sheet);
|
|
|
|
|
|
|
|
|
|
// Получаем SheetData
|
|
|
|
|
SheetData sheetData = worksheetPart.Worksheet.GetFirstChild<SheetData>();
|
|
|
|
|
|
|
|
|
|
// Заполняем заголовки
|
|
|
|
|
Row headerRow = new Row();
|
|
|
|
|
headerRow.Append(
|
|
|
|
|
CreateTextCell("A", "ID"),
|
|
|
|
|
CreateTextCell("B", "Сотрудник"),
|
|
|
|
|
CreateTextCell("C", "Дата начала"),
|
|
|
|
|
CreateTextCell("D", "Дата окончания"),
|
|
|
|
|
CreateTextCell("E", "Статус")
|
|
|
|
|
);
|
|
|
|
|
sheetData.AppendChild(headerRow);
|
|
|
|
|
|
|
|
|
|
// Заполняем данные
|
|
|
|
|
foreach (var vacation in vacations)
|
|
|
|
|
{
|
|
|
|
|
Row row = new Row();
|
|
|
|
|
row.Append(
|
|
|
|
|
CreateTextCell("A", vacation.Id.ToString()),
|
|
|
|
|
CreateTextCell("B", vacation.EmployeeName),
|
|
|
|
|
CreateTextCell("C", vacation.StartData.ToString("dd.MM.yyyy")),
|
|
|
|
|
CreateTextCell("D", vacation.EndData.ToString("dd.MM.yyyy")),
|
|
|
|
|
CreateTextCell("E", vacation.Passed ? "Проведен" : "Не проведен")
|
|
|
|
|
);
|
|
|
|
|
sheetData.AppendChild(row);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
workbookPart.Workbook.Save();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Метод для создания текстовой ячейки
|
|
|
|
|
private Cell CreateTextCell(string columnName, string text)
|
|
|
|
|
{
|
|
|
|
|
return new Cell
|
|
|
|
|
{
|
|
|
|
|
DataType = CellValues.String,
|
|
|
|
|
CellReference = columnName,
|
|
|
|
|
CellValue = new CellValue(text)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-07 23:36:29 +04:00
|
|
|
|
|
2024-12-02 23:48:58 +04:00
|
|
|
|
private void SearchTextBox_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
string query = SearchTextBox.Text.ToLower();
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(query))
|
|
|
|
|
{
|
|
|
|
|
// Отображаем все записи
|
|
|
|
|
VacationsDataGrid.ItemsSource = _allVacations;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Фильтрация по всем полям сущности
|
|
|
|
|
var filteredList = _allVacations.Where(vac =>
|
|
|
|
|
(vac.EmployeeName?.ToLower().Contains(query) ?? false) ||
|
|
|
|
|
(vac.StartData.ToString("dd.MM.yyyy").Contains(query)) ||
|
|
|
|
|
(vac.EndData.ToString("dd.MM.yyyy").Contains(query)) ||
|
|
|
|
|
(vac.Passed.ToString().ToLower().Contains(query))
|
|
|
|
|
).ToList();
|
|
|
|
|
|
|
|
|
|
VacationsDataGrid.ItemsSource = filteredList;
|
|
|
|
|
}
|
2024-12-01 16:34:36 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|