Compare commits
2 Commits
ffe926af5d
...
45fd65dbd2
Author | SHA1 | Date | |
---|---|---|---|
45fd65dbd2 | |||
b59f5ac4a8 |
@ -1,84 +1,107 @@
|
|||||||
using LawFirmBusinessLogic.OfficePackages.HelperEnums;
|
using LawFirmBusinessLogic.OfficePackages.HelperEnums;
|
||||||
using LawFirmBusinessLogic.OfficePackages.HelperModels;
|
using LawFirmBusinessLogic.OfficePackages.HelperModels;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
namespace LawFirmBusinessLogic.OfficePackages
|
namespace LawFirmBusinessLogic.OfficePackages
|
||||||
{
|
{
|
||||||
public abstract class AbstractSaveToExcelClientsConsultation
|
public abstract class AbstractSaveToExcelClientsConsultation
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Создание отчета
|
/// Создание отчета
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="info"></param>
|
/// <param name="info"></param>
|
||||||
public void CreateReport(ExcelClientsConsultationInfo info)
|
public void CreateReport(ExcelClientsConsultationInfo info)
|
||||||
{
|
{
|
||||||
CreateExcel(info);
|
CreateExcel(info);
|
||||||
InsertCellInWorksheet(new ExcelCellParameters
|
InsertCellInWorksheet(new ExcelCellParameters
|
||||||
{
|
{
|
||||||
ColumnName = "A",
|
ColumnName = "A",
|
||||||
RowIndex = 1,
|
RowIndex = 1,
|
||||||
Text = info.Title,
|
Text = info.Title,
|
||||||
StyleInfo = ExcelStyleInfoType.Title
|
StyleInfo = ExcelStyleInfoType.Title
|
||||||
});
|
});
|
||||||
MergeCells(new ExcelMergeParameters
|
InsertCellInWorksheet(new ExcelCellParameters
|
||||||
{
|
{
|
||||||
CellFromName = "A1",
|
ColumnName = "A",
|
||||||
CellToName = "C1"
|
RowIndex = 2,
|
||||||
});
|
Text = "Клиент",
|
||||||
uint rowIndex = 2;
|
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
||||||
foreach (var ch in info.ClientsConsultation)
|
});
|
||||||
{
|
InsertCellInWorksheet(new ExcelCellParameters
|
||||||
InsertCellInWorksheet(new ExcelCellParameters
|
{
|
||||||
{
|
ColumnName = "B",
|
||||||
ColumnName = "A",
|
RowIndex = 2,
|
||||||
RowIndex = rowIndex,
|
Text = "Дата консультации",
|
||||||
Text = ch.ClientFIO,
|
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
||||||
StyleInfo = ExcelStyleInfoType.Text
|
});
|
||||||
});
|
InsertCellInWorksheet(new ExcelCellParameters
|
||||||
rowIndex++;
|
{
|
||||||
foreach (var consultation in ch.Consultations)
|
ColumnName = "C",
|
||||||
{
|
RowIndex = 2,
|
||||||
InsertCellInWorksheet(new ExcelCellParameters
|
Text = "Цена консультации",
|
||||||
{
|
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
||||||
ColumnName = "B",
|
});
|
||||||
RowIndex = rowIndex,
|
MergeCells(new ExcelMergeParameters
|
||||||
Text = consultation.Cost.ToString(),
|
{
|
||||||
StyleInfo =
|
CellFromName = "A1",
|
||||||
ExcelStyleInfoType.TextWithBroder
|
CellToName = "C1"
|
||||||
});
|
});
|
||||||
InsertCellInWorksheet(new ExcelCellParameters
|
uint rowIndex = 4;
|
||||||
{
|
|
||||||
ColumnName = "C",
|
|
||||||
RowIndex = rowIndex,
|
|
||||||
Text = consultation.ConsultationDate.ToString(),
|
|
||||||
StyleInfo =
|
|
||||||
ExcelStyleInfoType.TextWithBroder
|
|
||||||
});
|
|
||||||
rowIndex++;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
foreach (var vl in info.ClientsConsultation)
|
||||||
SaveExcel(info);
|
{
|
||||||
}
|
InsertCellInWorksheet(new ExcelCellParameters
|
||||||
/// <summary>
|
{
|
||||||
/// Создание excel-файла
|
ColumnName = "A",
|
||||||
/// </summary>
|
RowIndex = rowIndex,
|
||||||
/// <param name="info"></param>
|
Text = vl.ClientFIO,
|
||||||
protected abstract void CreateExcel(ExcelClientsConsultationInfo info);
|
StyleInfo = ExcelStyleInfoType.Text
|
||||||
/// <summary>
|
});
|
||||||
/// Добавляем новую ячейку в лист
|
rowIndex++;
|
||||||
/// </summary>
|
foreach (var cons in vl.Consultations)
|
||||||
/// <param name="cellParameters"></param>
|
{
|
||||||
protected abstract void InsertCellInWorksheet(ExcelCellParameters
|
InsertCellInWorksheet(new ExcelCellParameters
|
||||||
excelParams);
|
{
|
||||||
/// <summary>
|
ColumnName = "B",
|
||||||
/// Объединение ячеек
|
RowIndex = rowIndex,
|
||||||
/// </summary>
|
Text = cons.ConsultationDate.ToShortDateString(),
|
||||||
/// <param name="mergeParameters"></param>
|
StyleInfo =
|
||||||
protected abstract void MergeCells(ExcelMergeParameters excelParams);
|
ExcelStyleInfoType.Text
|
||||||
/// <summary>
|
});
|
||||||
/// Сохранение файла
|
InsertCellInWorksheet(new ExcelCellParameters
|
||||||
/// </summary>
|
{
|
||||||
/// <param name="info"></param>
|
ColumnName = "C",
|
||||||
protected abstract void SaveExcel(ExcelClientsConsultationInfo info);
|
RowIndex = rowIndex,
|
||||||
}
|
Text = cons.Cost.ToString(),
|
||||||
|
StyleInfo =
|
||||||
|
ExcelStyleInfoType.Text
|
||||||
|
});
|
||||||
|
rowIndex++;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SaveExcel(info);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Создание excel-файла
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="info"></param>
|
||||||
|
protected abstract void CreateExcel(ExcelClientsConsultationInfo info);
|
||||||
|
/// <summary>
|
||||||
|
/// Добавляем новую ячейку в лист
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cellParameters"></param>
|
||||||
|
protected abstract void InsertCellInWorksheet(ExcelCellParameters
|
||||||
|
excelParams);
|
||||||
|
/// <summary>
|
||||||
|
/// Объединение ячеек
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="mergeParameters"></param>
|
||||||
|
protected abstract void MergeCells(ExcelMergeParameters excelParams);
|
||||||
|
/// <summary>
|
||||||
|
/// Сохранение файла
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="info"></param>
|
||||||
|
protected abstract void SaveExcel(ExcelClientsConsultationInfo info);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,333 +18,330 @@ namespace LawFirmBusinessLogic.OfficePackages.Implements
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="workbookpart"></param>
|
/// <param name="workbookpart"></param>
|
||||||
private static void CreateStyles(WorkbookPart workbookpart)
|
private static void CreateStyles(WorkbookPart workbookpart)
|
||||||
{
|
{
|
||||||
var sp = workbookpart.AddNewPart<WorkbookStylesPart>();
|
var sp = workbookpart.AddNewPart<WorkbookStylesPart>();
|
||||||
sp.Stylesheet = new Stylesheet();
|
sp.Stylesheet = new Stylesheet();
|
||||||
var fonts = new Fonts() { Count = 2U, KnownFonts = true };
|
var fonts = new Fonts() { Count = 2U, KnownFonts = true };
|
||||||
var fontUsual = new Font();
|
var fontUsual = new Font();
|
||||||
fontUsual.Append(new FontSize() { Val = 12D });
|
fontUsual.Append(new FontSize() { Val = 12D });
|
||||||
fontUsual.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color()
|
fontUsual.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color()
|
||||||
{ Theme = 1U });
|
{ Theme = 1U });
|
||||||
fontUsual.Append(new FontName() { Val = "Times New Roman" });
|
fontUsual.Append(new FontName() { Val = "Times New Roman" });
|
||||||
fontUsual.Append(new FontFamilyNumbering() { Val = 2 });
|
fontUsual.Append(new FontFamilyNumbering() { Val = 2 });
|
||||||
fontUsual.Append(new FontScheme() { Val = FontSchemeValues.Minor });
|
fontUsual.Append(new FontScheme() { Val = FontSchemeValues.Minor });
|
||||||
var fontTitle = new Font();
|
var fontTitle = new Font();
|
||||||
fontTitle.Append(new Bold());
|
fontTitle.Append(new Bold());
|
||||||
fontTitle.Append(new FontSize() { Val = 14D });
|
fontTitle.Append(new FontSize() { Val = 14D });
|
||||||
fontTitle.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color()
|
fontTitle.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color()
|
||||||
{ Theme = 1U });
|
{ Theme = 1U });
|
||||||
fontTitle.Append(new FontName() { Val = "Times New Roman" });
|
fontTitle.Append(new FontName() { Val = "Times New Roman" });
|
||||||
fontTitle.Append(new FontFamilyNumbering() { Val = 2 });
|
fontTitle.Append(new FontFamilyNumbering() { Val = 2 });
|
||||||
fontTitle.Append(new FontScheme() { Val = FontSchemeValues.Minor });
|
fontTitle.Append(new FontScheme() { Val = FontSchemeValues.Minor });
|
||||||
fonts.Append(fontUsual);
|
fonts.Append(fontUsual);
|
||||||
fonts.Append(fontTitle);
|
fonts.Append(fontTitle);
|
||||||
var fills = new Fills() { Count = 2U };
|
var fills = new Fills() { Count = 2U };
|
||||||
var fill1 = new Fill();
|
var fill1 = new Fill();
|
||||||
fill1.Append(new PatternFill() { PatternType = PatternValues.None });
|
fill1.Append(new PatternFill() { PatternType = PatternValues.None });
|
||||||
var fill2 = new Fill();
|
var fill2 = new Fill();
|
||||||
fill2.Append(new PatternFill()
|
fill2.Append(new PatternFill()
|
||||||
{
|
{
|
||||||
PatternType = PatternValues.Gray125
|
PatternType = PatternValues.Gray125
|
||||||
});
|
});
|
||||||
fills.Append(fill1);
|
fills.Append(fill1);
|
||||||
fills.Append(fill2);
|
fills.Append(fill2);
|
||||||
var borders = new Borders() { Count = 2U };
|
var borders = new Borders() { Count = 2U };
|
||||||
var borderNoBorder = new Border();
|
var borderNoBorder = new Border();
|
||||||
borderNoBorder.Append(new LeftBorder());
|
borderNoBorder.Append(new LeftBorder());
|
||||||
borderNoBorder.Append(new RightBorder());
|
borderNoBorder.Append(new RightBorder());
|
||||||
borderNoBorder.Append(new TopBorder());
|
borderNoBorder.Append(new TopBorder());
|
||||||
borderNoBorder.Append(new BottomBorder());
|
borderNoBorder.Append(new BottomBorder());
|
||||||
borderNoBorder.Append(new DiagonalBorder());
|
borderNoBorder.Append(new DiagonalBorder());
|
||||||
var borderThin = new Border();
|
var borderThin = new Border();
|
||||||
var leftBorder = new LeftBorder() { Style = BorderStyleValues.Thin };
|
var leftBorder = new LeftBorder() { Style = BorderStyleValues.Thin };
|
||||||
leftBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color()
|
leftBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color()
|
||||||
{ Indexed = 64U });
|
{ Indexed = 64U });
|
||||||
var rightBorder = new RightBorder()
|
var rightBorder = new RightBorder()
|
||||||
{
|
{
|
||||||
Style = BorderStyleValues.Thin
|
Style = BorderStyleValues.Thin
|
||||||
};
|
};
|
||||||
rightBorder.Append(new
|
rightBorder.Append(new
|
||||||
DocumentFormat.OpenXml.Office2010.Excel.Color()
|
DocumentFormat.OpenXml.Office2010.Excel.Color()
|
||||||
{ Indexed = 64U });
|
{ Indexed = 64U });
|
||||||
var topBorder = new TopBorder() { Style = BorderStyleValues.Thin };
|
var topBorder = new TopBorder() { Style = BorderStyleValues.Thin };
|
||||||
topBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color()
|
topBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color()
|
||||||
{ Indexed = 64U });
|
{ Indexed = 64U });
|
||||||
var bottomBorder = new BottomBorder()
|
var bottomBorder = new BottomBorder()
|
||||||
{
|
{
|
||||||
Style =
|
Style =
|
||||||
BorderStyleValues.Thin
|
BorderStyleValues.Thin
|
||||||
};
|
};
|
||||||
bottomBorder.Append(new
|
bottomBorder.Append(new
|
||||||
DocumentFormat.OpenXml.Office2010.Excel.Color()
|
DocumentFormat.OpenXml.Office2010.Excel.Color()
|
||||||
{ Indexed = 64U });
|
{ Indexed = 64U });
|
||||||
borderThin.Append(leftBorder);
|
borderThin.Append(leftBorder);
|
||||||
borderThin.Append(rightBorder);
|
borderThin.Append(rightBorder);
|
||||||
borderThin.Append(topBorder);
|
borderThin.Append(topBorder);
|
||||||
borderThin.Append(bottomBorder);
|
borderThin.Append(bottomBorder);
|
||||||
borderThin.Append(new DiagonalBorder());
|
borderThin.Append(new DiagonalBorder());
|
||||||
borders.Append(borderNoBorder);
|
borders.Append(borderNoBorder);
|
||||||
borders.Append(borderThin);
|
borders.Append(borderThin);
|
||||||
var cellStyleFormats = new CellStyleFormats() { Count = 1U };
|
var cellStyleFormats = new CellStyleFormats() { Count = 1U };
|
||||||
var cellFormatStyle = new CellFormat()
|
var cellFormatStyle = new CellFormat()
|
||||||
{
|
{
|
||||||
NumberFormatId = 0U,
|
NumberFormatId = 0U,
|
||||||
FontId
|
FontId = 0U,
|
||||||
= 0U,
|
FillId = 0U,
|
||||||
FillId = 0U,
|
BorderId = 0U
|
||||||
BorderId = 0U
|
};
|
||||||
};
|
cellStyleFormats.Append(cellFormatStyle);
|
||||||
cellStyleFormats.Append(cellFormatStyle);
|
var cellFormats = new CellFormats() { Count = 3U };
|
||||||
var cellFormats = new CellFormats() { Count = 3U };
|
var cellFormatFont = new CellFormat()
|
||||||
var cellFormatFont = new CellFormat()
|
{
|
||||||
{
|
NumberFormatId = 0U,
|
||||||
NumberFormatId = 0U,
|
FontId = 0U,
|
||||||
FontId =
|
FillId = 0U,
|
||||||
0U,
|
BorderId = 0U,
|
||||||
FillId = 0U,
|
FormatId = 0U,
|
||||||
BorderId = 0U,
|
ApplyFont = true
|
||||||
FormatId = 0U,
|
};
|
||||||
ApplyFont = true
|
var cellFormatFontAndBorder = new CellFormat()
|
||||||
};
|
{
|
||||||
var cellFormatFontAndBorder = new CellFormat()
|
NumberFormatId = 0U,
|
||||||
{
|
FontId = 0U,
|
||||||
NumberFormatId = 0U,
|
FillId = 0U,
|
||||||
FontId = 0U,
|
BorderId = 1U,
|
||||||
FillId = 0U,
|
FormatId = 0U,
|
||||||
BorderId = 1U,
|
ApplyFont = true,
|
||||||
FormatId = 0U,
|
ApplyBorder = true
|
||||||
ApplyFont = true,
|
};
|
||||||
ApplyBorder = true
|
var cellFormatTitle = new CellFormat()
|
||||||
};
|
{
|
||||||
var cellFormatTitle = new CellFormat()
|
NumberFormatId = 0U,
|
||||||
{
|
FontId = 1U,
|
||||||
NumberFormatId = 0U,
|
FillId = 0U,
|
||||||
FontId
|
BorderId = 0U,
|
||||||
= 1U,
|
FormatId = 0U,
|
||||||
FillId = 0U,
|
Alignment = new Alignment()
|
||||||
BorderId = 0U,
|
{
|
||||||
FormatId = 0U,
|
Vertical = VerticalAlignmentValues.Center,
|
||||||
Alignment = new Alignment()
|
WrapText = true,
|
||||||
{
|
Horizontal =
|
||||||
Vertical = VerticalAlignmentValues.Center,
|
HorizontalAlignmentValues.Center
|
||||||
WrapText = true,
|
},
|
||||||
Horizontal =
|
ApplyFont = true
|
||||||
HorizontalAlignmentValues.Center
|
};
|
||||||
},
|
cellFormats.Append(cellFormatFont);
|
||||||
ApplyFont = true
|
cellFormats.Append(cellFormatFontAndBorder);
|
||||||
};
|
cellFormats.Append(cellFormatTitle);
|
||||||
cellFormats.Append(cellFormatFont);
|
var cellStyles = new CellStyles() { Count = 1U };
|
||||||
cellFormats.Append(cellFormatFontAndBorder);
|
cellStyles.Append(new CellStyle()
|
||||||
cellFormats.Append(cellFormatTitle);
|
{
|
||||||
var cellStyles = new CellStyles() { Count = 1U };
|
Name = "Normal",
|
||||||
cellStyles.Append(new CellStyle()
|
FormatId = 0U,
|
||||||
{
|
BuiltinId = 0U
|
||||||
Name = "Normal",
|
});
|
||||||
FormatId = 0U,
|
var differentialFormats = new
|
||||||
BuiltinId = 0U
|
DocumentFormat.OpenXml.Office2013.Excel.DifferentialFormats()
|
||||||
});
|
{ Count = 0U };
|
||||||
var differentialFormats = new
|
|
||||||
DocumentFormat.OpenXml.Office2013.Excel.DifferentialFormats()
|
|
||||||
{ Count = 0U };
|
|
||||||
|
|
||||||
var tableStyles = new TableStyles()
|
var tableStyles = new TableStyles()
|
||||||
{
|
{
|
||||||
Count = 0U,
|
Count = 0U,
|
||||||
DefaultTableStyle =
|
DefaultTableStyle =
|
||||||
"TableStyleMedium2",
|
"TableStyleMedium2",
|
||||||
DefaultPivotStyle = "PivotStyleLight16"
|
DefaultPivotStyle = "PivotStyleLight16"
|
||||||
};
|
};
|
||||||
var stylesheetExtensionList = new StylesheetExtensionList();
|
var stylesheetExtensionList = new StylesheetExtensionList();
|
||||||
var stylesheetExtension1 = new StylesheetExtension()
|
var stylesheetExtension1 = new StylesheetExtension()
|
||||||
{
|
{
|
||||||
Uri =
|
Uri =
|
||||||
"{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}"
|
"{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}"
|
||||||
};
|
};
|
||||||
stylesheetExtension1.AddNamespaceDeclaration("x14",
|
stylesheetExtension1.AddNamespaceDeclaration("x14",
|
||||||
"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main");
|
"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main");
|
||||||
stylesheetExtension1.Append(new SlicerStyles()
|
stylesheetExtension1.Append(new SlicerStyles()
|
||||||
{
|
{
|
||||||
DefaultSlicerStyle =
|
DefaultSlicerStyle =
|
||||||
"SlicerStyleLight1"
|
"SlicerStyleLight1"
|
||||||
});
|
});
|
||||||
var stylesheetExtension2 = new StylesheetExtension()
|
var stylesheetExtension2 = new StylesheetExtension()
|
||||||
{
|
{
|
||||||
Uri =
|
Uri =
|
||||||
"{9260A510-F301-46a8-8635-F512D64BE5F5}"
|
"{9260A510-F301-46a8-8635-F512D64BE5F5}"
|
||||||
};
|
};
|
||||||
stylesheetExtension2.AddNamespaceDeclaration("x15",
|
stylesheetExtension2.AddNamespaceDeclaration("x15",
|
||||||
"http://schemas.microsoft.com/office/spreadsheetml/2010/11/main");
|
"http://schemas.microsoft.com/office/spreadsheetml/2010/11/main");
|
||||||
stylesheetExtension2.Append(new TimelineStyles()
|
stylesheetExtension2.Append(new TimelineStyles()
|
||||||
{
|
{
|
||||||
DefaultTimelineStyle = "TimeSlicerStyleLight1"
|
DefaultTimelineStyle = "TimeSlicerStyleLight1"
|
||||||
});
|
});
|
||||||
stylesheetExtensionList.Append(stylesheetExtension1);
|
stylesheetExtensionList.Append(stylesheetExtension1);
|
||||||
stylesheetExtensionList.Append(stylesheetExtension2);
|
stylesheetExtensionList.Append(stylesheetExtension2);
|
||||||
sp.Stylesheet.Append(fonts);
|
sp.Stylesheet.Append(fonts);
|
||||||
sp.Stylesheet.Append(fills);
|
sp.Stylesheet.Append(fills);
|
||||||
sp.Stylesheet.Append(borders);
|
sp.Stylesheet.Append(borders);
|
||||||
sp.Stylesheet.Append(cellStyleFormats);
|
sp.Stylesheet.Append(cellStyleFormats);
|
||||||
sp.Stylesheet.Append(cellFormats);
|
sp.Stylesheet.Append(cellFormats);
|
||||||
sp.Stylesheet.Append(cellStyles);
|
sp.Stylesheet.Append(cellStyles);
|
||||||
sp.Stylesheet.Append(differentialFormats);
|
sp.Stylesheet.Append(differentialFormats);
|
||||||
sp.Stylesheet.Append(tableStyles);
|
sp.Stylesheet.Append(tableStyles);
|
||||||
sp.Stylesheet.Append(stylesheetExtensionList);
|
sp.Stylesheet.Append(stylesheetExtensionList);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получение номера стиля из типа
|
/// Получение номера стиля из типа
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="styleInfo"></param>
|
/// <param name="styleInfo"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private static uint GetStyleValue(ExcelStyleInfoType styleInfo)
|
private static uint GetStyleValue(ExcelStyleInfoType styleInfo)
|
||||||
{
|
{
|
||||||
return styleInfo switch
|
return styleInfo switch
|
||||||
{
|
{
|
||||||
ExcelStyleInfoType.Title => 2U,
|
ExcelStyleInfoType.Title => 2U,
|
||||||
ExcelStyleInfoType.TextWithBroder => 1U,
|
ExcelStyleInfoType.TextWithBroder => 1U,
|
||||||
ExcelStyleInfoType.Text => 0U,
|
ExcelStyleInfoType.Text => 0U,
|
||||||
_ => 0U,
|
_ => 0U,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
protected override void CreateExcel(ExcelClientsConsultationInfo info)
|
protected override void CreateExcel(ExcelClientsConsultationInfo info)
|
||||||
{
|
{
|
||||||
_spreadsheetDocument = SpreadsheetDocument.Create(info.FileName,
|
_spreadsheetDocument = SpreadsheetDocument.Create(info.FileName,
|
||||||
SpreadsheetDocumentType.Workbook);
|
SpreadsheetDocumentType.Workbook);
|
||||||
// Создаем книгу (в ней хранятся листы)
|
// Создаем книгу (в ней хранятся листы)
|
||||||
var workbookpart = _spreadsheetDocument.AddWorkbookPart();
|
var workbookpart = _spreadsheetDocument.AddWorkbookPart();
|
||||||
workbookpart.Workbook = new Workbook();
|
workbookpart.Workbook = new Workbook();
|
||||||
CreateStyles(workbookpart);
|
CreateStyles(workbookpart);
|
||||||
// Получаем/создаем хранилище текстов для книги
|
// Получаем/создаем хранилище текстов для книги
|
||||||
_shareStringPart =
|
_shareStringPart =
|
||||||
_spreadsheetDocument.WorkbookPart!.GetPartsOfType<SharedStringTablePart>().Any()
|
_spreadsheetDocument.WorkbookPart!.GetPartsOfType<SharedStringTablePart>().Any()
|
||||||
?
|
?
|
||||||
_spreadsheetDocument.WorkbookPart.GetPartsOfType<SharedStringTablePart>().First()
|
_spreadsheetDocument.WorkbookPart.GetPartsOfType<SharedStringTablePart>().First()
|
||||||
:
|
:
|
||||||
_spreadsheetDocument.WorkbookPart.AddNewPart<SharedStringTablePart>();
|
_spreadsheetDocument.WorkbookPart.AddNewPart<SharedStringTablePart>();
|
||||||
// Создаем SharedStringTable, если его нет
|
// Создаем SharedStringTable, если его нет
|
||||||
if (_shareStringPart.SharedStringTable == null)
|
if (_shareStringPart.SharedStringTable == null)
|
||||||
{
|
{
|
||||||
_shareStringPart.SharedStringTable = new SharedStringTable();
|
_shareStringPart.SharedStringTable = new SharedStringTable();
|
||||||
}
|
}
|
||||||
// Создаем лист в книгу
|
// Создаем лист в книгу
|
||||||
var worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
|
var worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
|
||||||
worksheetPart.Worksheet = new Worksheet(new SheetData());
|
worksheetPart.Worksheet = new Worksheet(new SheetData());
|
||||||
// Добавляем лист в книгу
|
// Добавляем лист в книгу
|
||||||
var sheets =
|
var sheets =
|
||||||
_spreadsheetDocument.WorkbookPart.Workbook.AppendChild(new Sheets());
|
_spreadsheetDocument.WorkbookPart.Workbook.AppendChild(new Sheets());
|
||||||
var sheet = new Sheet()
|
var sheet = new Sheet()
|
||||||
{
|
{
|
||||||
Id =
|
Id =
|
||||||
_spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart),
|
_spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart),
|
||||||
SheetId = 1,
|
SheetId = 1,
|
||||||
Name = "Лист"
|
Name = "Лист"
|
||||||
};
|
};
|
||||||
sheets.Append(sheet);
|
sheets.Append(sheet);
|
||||||
_worksheet = worksheetPart.Worksheet;
|
_worksheet = worksheetPart.Worksheet;
|
||||||
}
|
}
|
||||||
protected override void InsertCellInWorksheet(ExcelCellParameters
|
protected override void InsertCellInWorksheet(ExcelCellParameters
|
||||||
excelParams)
|
excelParams)
|
||||||
{
|
{
|
||||||
if (_worksheet == null || _shareStringPart == null)
|
if (_worksheet == null || _shareStringPart == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var sheetData = _worksheet.GetFirstChild<SheetData>();
|
var sheetData = _worksheet.GetFirstChild<SheetData>();
|
||||||
if (sheetData == null)
|
if (sheetData == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Ищем строку, либо добавляем ее
|
// Ищем строку, либо добавляем ее
|
||||||
Row row;
|
Row row;
|
||||||
if (sheetData.Elements<Row>().Where(r => r.RowIndex! ==
|
if (sheetData.Elements<Row>().Where(r => r.RowIndex! ==
|
||||||
excelParams.RowIndex).Any())
|
excelParams.RowIndex).Any())
|
||||||
{
|
{
|
||||||
row = sheetData.Elements<Row>().Where(r => r.RowIndex! ==
|
row = sheetData.Elements<Row>().Where(r => r.RowIndex! ==
|
||||||
excelParams.RowIndex).First();
|
excelParams.RowIndex).First();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
row = new Row() { RowIndex = excelParams.RowIndex };
|
row = new Row() { RowIndex = excelParams.RowIndex };
|
||||||
sheetData.Append(row);
|
sheetData.Append(row);
|
||||||
}
|
}
|
||||||
// Ищем нужную ячейку
|
// Ищем нужную ячейку
|
||||||
Cell cell;
|
Cell cell;
|
||||||
if (row.Elements<Cell>().Where(c => c.CellReference!.Value ==
|
if (row.Elements<Cell>().Where(c => c.CellReference!.Value ==
|
||||||
excelParams.CellReference).Any())
|
excelParams.CellReference).Any())
|
||||||
{
|
{
|
||||||
cell = row.Elements<Cell>().Where(c => c.CellReference!.Value ==
|
cell = row.Elements<Cell>().Where(c => c.CellReference!.Value ==
|
||||||
excelParams.CellReference).First();
|
excelParams.CellReference).First();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Все ячейки должны быть последовательно друг за другом расположены
|
// Все ячейки должны быть последовательно друг за другом расположены
|
||||||
// нужно определить, после какой вставлять
|
// нужно определить, после какой вставлять
|
||||||
Cell? refCell = null;
|
Cell? refCell = null;
|
||||||
foreach (Cell rowCell in row.Elements<Cell>())
|
foreach (Cell rowCell in row.Elements<Cell>())
|
||||||
{
|
{
|
||||||
if (string.Compare(rowCell.CellReference!.Value,
|
if (string.Compare(rowCell.CellReference!.Value,
|
||||||
excelParams.CellReference, true) > 0)
|
excelParams.CellReference, true) > 0)
|
||||||
{
|
{
|
||||||
refCell = rowCell;
|
refCell = rowCell;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var newCell = new Cell()
|
var newCell = new Cell()
|
||||||
{
|
{
|
||||||
CellReference =
|
CellReference =
|
||||||
excelParams.CellReference
|
excelParams.CellReference
|
||||||
};
|
};
|
||||||
row.InsertBefore(newCell, refCell);
|
row.InsertBefore(newCell, refCell);
|
||||||
cell = newCell;
|
cell = newCell;
|
||||||
}
|
}
|
||||||
// вставляем новый текст
|
// вставляем новый текст
|
||||||
_shareStringPart.SharedStringTable.AppendChild(new
|
_shareStringPart.SharedStringTable.AppendChild(new
|
||||||
SharedStringItem(new DocumentFormat.OpenXml.Drawing.Text(excelParams.Text)));
|
SharedStringItem(new Text(excelParams.Text)));
|
||||||
_shareStringPart.SharedStringTable.Save();
|
_shareStringPart.SharedStringTable.Save();
|
||||||
cell.CellValue = new
|
cell.CellValue = new
|
||||||
CellValue((_shareStringPart.SharedStringTable.Elements<SharedStringItem>().Count(
|
CellValue((_shareStringPart.SharedStringTable.Elements<SharedStringItem>().Count(
|
||||||
) - 1).ToString());
|
) - 1).ToString());
|
||||||
cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);
|
cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);
|
||||||
cell.StyleIndex = GetStyleValue(excelParams.StyleInfo);
|
cell.StyleIndex = GetStyleValue(excelParams.StyleInfo);
|
||||||
}
|
}
|
||||||
protected override void MergeCells(ExcelMergeParameters excelParams)
|
protected override void MergeCells(ExcelMergeParameters excelParams)
|
||||||
{
|
{
|
||||||
if (_worksheet == null)
|
if (_worksheet == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MergeCells mergeCells;
|
MergeCells mergeCells;
|
||||||
if (_worksheet.Elements<MergeCells>().Any())
|
if (_worksheet.Elements<MergeCells>().Any())
|
||||||
{
|
{
|
||||||
mergeCells = _worksheet.Elements<MergeCells>().First();
|
mergeCells = _worksheet.Elements<MergeCells>().First();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mergeCells = new MergeCells();
|
mergeCells = new MergeCells();
|
||||||
if (_worksheet.Elements<CustomSheetView>().Any())
|
if (_worksheet.Elements<CustomSheetView>().Any())
|
||||||
{
|
{
|
||||||
_worksheet.InsertAfter(mergeCells,
|
_worksheet.InsertAfter(mergeCells,
|
||||||
_worksheet.Elements<CustomSheetView>().First());
|
_worksheet.Elements<CustomSheetView>().First());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_worksheet.InsertAfter(mergeCells,
|
_worksheet.InsertAfter(mergeCells,
|
||||||
_worksheet.Elements<SheetData>().First());
|
_worksheet.Elements<SheetData>().First());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var mergeCell = new MergeCell()
|
var mergeCell = new MergeCell()
|
||||||
{
|
{
|
||||||
Reference = new StringValue(excelParams.Merge)
|
Reference = new StringValue(excelParams.Merge)
|
||||||
};
|
};
|
||||||
mergeCells.Append(mergeCell);
|
mergeCells.Append(mergeCell);
|
||||||
}
|
}
|
||||||
protected override void SaveExcel(ExcelClientsConsultationInfo info)
|
protected override void SaveExcel(ExcelClientsConsultationInfo info)
|
||||||
{
|
{
|
||||||
if (_spreadsheetDocument == null)
|
if (_spreadsheetDocument == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_spreadsheetDocument.WorkbookPart!.Workbook.Save();
|
_spreadsheetDocument.WorkbookPart!.Workbook.Save();
|
||||||
_spreadsheetDocument.Dispose();
|
_spreadsheetDocument.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,9 +11,9 @@ namespace LawFirmDatabaseImplement
|
|||||||
{
|
{
|
||||||
if (optionsBuilder.IsConfigured == false)
|
if (optionsBuilder.IsConfigured == false)
|
||||||
{
|
{
|
||||||
//optionsBuilder.UseSqlServer(@"Data Source=ZIRAEL\SQLEXPRESS;Initial Catalog=LawFirmDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
optionsBuilder.UseSqlServer(@"Data Source=ZIRAEL\SQLEXPRESS;Initial Catalog=LawFirmDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||||
|
|
||||||
optionsBuilder.UseSqlServer(@"Data Source=PC-Anna\SQLEXPRESS;Initial Catalog=LawFirmDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
//optionsBuilder.UseSqlServer(@"Data Source=PC-Anna\SQLEXPRESS;Initial Catalog=LawFirmDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||||
}
|
}
|
||||||
base.OnConfiguring(optionsBuilder);
|
base.OnConfiguring(optionsBuilder);
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ namespace LawFirmExecutorApp.Controllers
|
|||||||
[HttpGet]
|
[HttpGet]
|
||||||
public IActionResult UpdateClient()
|
public IActionResult UpdateClient()
|
||||||
{
|
{
|
||||||
ViewBag.Clients = APIClient.GetRequest<List<ClientViewModel>>($"api/client/getclientlist?guarantorid={APIClient.Executor.Id}");
|
ViewBag.Clients = APIClient.GetRequest<List<ClientViewModel>>($"api/client/getclientlist?executorid={APIClient.Executor.Id}");
|
||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
@ -73,5 +73,64 @@ namespace LawFirmExecutorApp.Controllers
|
|||||||
});
|
});
|
||||||
Response.Redirect("/Home/Clients");
|
Response.Redirect("/Home/Clients");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult GetFile()
|
||||||
|
{
|
||||||
|
ViewBag.Clients = APIClient.GetRequest<List<ClientViewModel>>($"api/client/getclientlist?executorid={APIClient.Executor.Id}");
|
||||||
|
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void GetFile(int clientId, string type)
|
||||||
|
{
|
||||||
|
if (APIClient.Executor == null)
|
||||||
|
{
|
||||||
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (clientId == 0)
|
||||||
|
{
|
||||||
|
throw new Exception("Выберите клиента");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(type))
|
||||||
|
{
|
||||||
|
throw new Exception("Неверный тип отчета");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == "docx")
|
||||||
|
{
|
||||||
|
APIClient.PostRequest("api/ReportExecutor/SaveClientsWordFile", new ReportBindingModel
|
||||||
|
{
|
||||||
|
ClientId = clientId,
|
||||||
|
ExecutorId = APIClient.Executor.Id,
|
||||||
|
FileName = "E:\\reports\\wordfileTest.docx"
|
||||||
|
});
|
||||||
|
Response.Redirect("GetWordFile");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
APIClient.PostRequest("api/ReportExecutor/SaveClientsExcelFile", new ReportBindingModel
|
||||||
|
{
|
||||||
|
ClientId = clientId,
|
||||||
|
ExecutorId = APIClient.Executor.Id,
|
||||||
|
FileName = "E:\\reports\\excelfileTest.xlsx"
|
||||||
|
});
|
||||||
|
Response.Redirect("GetExcelFile");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult GetWordFile()
|
||||||
|
{
|
||||||
|
return new PhysicalFileResult("E:\\reports\\wordclientsreport.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
|
||||||
|
}
|
||||||
|
|
||||||
|
public IActionResult GetExcelFile()
|
||||||
|
{
|
||||||
|
return new PhysicalFileResult("E:\\reports\\excelclientsreport.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
31
LawFim/LawFirmExecutorApp/Views/Client/GetFile.cshtml
Normal file
31
LawFim/LawFirmExecutorApp/Views/Client/GetFile.cshtml
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
@using LawFirmContracts.ViewModels;
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Слушания по клиентам";
|
||||||
|
}
|
||||||
|
|
||||||
|
<div class="text-center">
|
||||||
|
<h2 class="display-4">Создать списки слушаний по клиентам</h2>
|
||||||
|
</div>
|
||||||
|
<form method="post">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-4">Клиент:</div>
|
||||||
|
<div class="col-8">
|
||||||
|
<select id="clientId" name="clientId" class="form-control" asp-items="@(new SelectList(@ViewBag.Clients,"Id", "FIO"))"></select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="file-format">
|
||||||
|
<label class="form-label">Выберите формат файла:</label>
|
||||||
|
<div class="form-check">
|
||||||
|
<input class="form-check-input" type="radio" name="type" value="docx" id="docx">
|
||||||
|
<label class="form-check-label" for="docx">Word-файл</label>
|
||||||
|
</div>
|
||||||
|
<div class="form-check">
|
||||||
|
<input class="form-check-input" type="radio" name="type" value="xlsx" id="xlsx" checked>
|
||||||
|
<label class="form-check-label" for="xlsx">Excel-файл</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="d-flex justify-content-center">
|
||||||
|
<button type="submit" class="btn btn-block btn-outline-dark w-100">Создать</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
@ -69,5 +69,12 @@
|
|||||||
}
|
}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<form action="/Client/GetFile">
|
||||||
|
<button type="submit" class="btn btn-danger">Получить docx/xlsx файл</button>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
@ -34,6 +34,9 @@
|
|||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Личные данные</a>
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Личные данные</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Report">Отчеты</a>
|
||||||
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Register">Регистрация</a>
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Register">Регистрация</a>
|
||||||
</li>
|
</li>
|
||||||
|
Loading…
Reference in New Issue
Block a user