Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RevitDeclarations: Исправлены ошибки форматирования Excel #138

Merged
merged 12 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public ErrorsListViewModel CheckRoomAreasEquality() {

foreach(Apartment apartment in _roomGroups) {
if(!apartment.CheckEqualityOfRoomAreas()) {
string apartInfo = $"Квартира № {apartment.Number} на этаже {apartment.Level}";
string apartInfo = $"Группа помещений № {apartment.Number} на этаже {apartment.Level}";
string apartAreas = "Площади квартиры (без коэффициента/с коэффициентом/жилая/без ЛП) " +
"должны быть одинаковыми для каждого помещения квартиры";
errorListVM.Errors.Add(new ErrorElement(apartInfo, apartAreas));
Expand All @@ -55,7 +55,7 @@ public ErrorsListViewModel CheckActualApartmentAreas() {

foreach(Apartment apartment in _roomGroups) {
if(!apartment.CheckActualApartmentAreas()) {
string apartInfo = $"Квартира № {apartment.Number} на этаже {apartment.Level}";
string apartInfo = $"Группа помещений № {apartment.Number} на этаже {apartment.Level}";
string apartAreas = "Площади квартиры, рассчитанные квартирографией " +
"отличаются от суммы актуальных системных площадей этой квартиры. " +
"Проверьте общую площадь квартиры, площадь с коэффициентом, " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public ErrorsListViewModel CheckActualRoomAreas() {

foreach(RoomGroup roomGroup in _roomGroups) {
if(!roomGroup.CheckActualRoomAreas()) {
string groupInfo = $"Квартира № {roomGroup.Number} на этаже {roomGroup.Level}";
string groupInfo = $"Группа помещений № {roomGroup.Number} на этаже {roomGroup.Level}";
string groupAreas = "Площади помещений, рассчитанные квартирографией " +
"отличаются от актуальной системной площадей помещения.";
errorListVM.Errors.Add(new ErrorElement(groupInfo, groupAreas));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace RevitDeclarations.Models {
internal class ApartmentsDataTable : DeclarationDataTable {
public ApartmentsDataTable(ApartmentsTableInfo tableInfo) : base(tableInfo) {
public ApartmentsDataTable(string name, ApartmentsTableInfo tableInfo) : base(name,tableInfo) {
}

protected override void FillTableHeader() {
Expand All @@ -17,7 +17,7 @@ protected override void FillTableHeader() {
_headerTable.Rows[0][6] = "Номер ОКС";
_headerTable.Rows[0][7] = "Общая площадь с пониж. коэффициентом, м²";
_headerTable.Rows[0][8] = "Количество комнат";
_headerTable.Rows[0][9] = "Жилая площадь, м²";
_headerTable.Rows[0][9] = "Общая жилая площадь, м²";
_headerTable.Rows[0][10] = "Высота потолков, м";
_headerTable.Rows[0][11] = "ИД Объекта";
_headerTable.Rows[0][12] = "Номер на площадке";
Expand Down Expand Up @@ -46,7 +46,7 @@ private void FillTableRoomsHeader() {
int columnIndex = columnNumber + k * ApartmentsTableInfo.SummerRoomCells;
_headerTable.Rows[0][columnIndex] = "№ Пом.";
_headerTable.Rows[0][columnIndex + 1] = "Наименование на планировке";
_headerTable.Rows[0][columnIndex + 2] = $"{priority.Name} {k + 1}, без коэф.";
_headerTable.Rows[0][columnIndex + 2] = $"{priority.Name} {k + 1}, площадь без коэф.";
_headerTable.Rows[0][columnIndex + 3] = $"{priority.Name} {k + 1}, площадь с коэф.";
}
columnNumber += priority.MaxRoomAmount * ApartmentsTableInfo.SummerRoomCells;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace RevitDeclarations.Models {
internal class CommercialDataTable : DeclarationDataTable {
public CommercialDataTable(CommercialTableInfo tableInfo) : base(tableInfo) {
public CommercialDataTable(string name, CommercialTableInfo tableInfo) : base(name, tableInfo) {
}

protected override void FillTableHeader() {
Expand Down Expand Up @@ -51,17 +51,19 @@ protected override void FillAdditionalInfo() {
}

private void GenerateSubTables() {
List<CommercialRooms> rooms = new List<CommercialRooms>();
foreach(var commercialRooms in _tableInfo.RoomGroups.Cast<CommercialRooms>()) {
if(!commercialRooms.IsOneRoomGroup) {
List<CommercialRooms> rooms = new List<CommercialRooms> { commercialRooms };

CommercialGroupTableInfo tableInfo = new CommercialGroupTableInfo(rooms, _settings);
CommercialGroupDataTable table = new CommercialGroupDataTable(tableInfo);
table.GenerateTable();

_subTables.Add(table);
rooms.Add(commercialRooms);
}
}

CommercialGroupTableInfo tableInfo = new CommercialGroupTableInfo(rooms, _settings);
CommercialGroupDataTable table =
new CommercialGroupDataTable("15.3 Части нежилых помещения", tableInfo);
table.GenerateTable();

_subTables.Add(table);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Windows.Documents;

namespace RevitDeclarations.Models {
internal class CommercialGroupDataTable : DeclarationDataTable {
public CommercialGroupDataTable(CommercialGroupTableInfo tableInfo) : base(tableInfo) {
public CommercialGroupDataTable(string name, CommercialGroupTableInfo tableInfo) : base(name, tableInfo) {
}

protected override void FillTableHeader() {
Expand All @@ -15,16 +17,14 @@ protected override void FillTableHeader() {
protected override void FillMainTable() {
int rowNumber = 0;

CommercialRooms commercialRooms = _tableInfo.RoomGroups
.Cast<CommercialRooms>()
.First();
foreach(CommercialRooms commercialRooms in _tableInfo.RoomGroups) {
foreach(RoomElement room in commercialRooms.Rooms) {
_mainTable.Rows[rowNumber][0] = room.Name ?? "";
_mainTable.Rows[rowNumber][1] = room.Area;
_mainTable.Rows[rowNumber][2] = commercialRooms.DeclarationNumber ?? "";

foreach(RoomElement room in commercialRooms.Rooms) {
_mainTable.Rows[rowNumber][0] = room.Name ?? "";
_mainTable.Rows[rowNumber][1] = room.Area;
_mainTable.Rows[rowNumber][2] = commercialRooms.DeclarationNumber ?? "";

rowNumber++;
rowNumber++;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,23 @@

namespace RevitDeclarations.Models {
internal abstract class DeclarationDataTable : IDeclarationDataTable {
protected readonly string _name;
protected readonly ITableInfo _tableInfo;
protected readonly DeclarationSettings _settings;
protected readonly DataTable _mainTable;
protected readonly DataTable _headerTable;
protected readonly List<IDeclarationDataTable> _subTables = new List<IDeclarationDataTable>();

protected DeclarationDataTable(ITableInfo tableInfo) {
protected DeclarationDataTable(string name, ITableInfo tableInfo) {
_name = name;
_tableInfo = tableInfo;
_settings = tableInfo.Settings;

_mainTable = new DataTable();
_headerTable = new DataTable();
}

public string Name => _name;
public DataTable MainDataTable => _mainTable;
public DataTable HeaderDataTable => _headerTable;
public ITableInfo TableInfo => _tableInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace RevitDeclarations.Models {
internal interface IDeclarationDataTable {
string Name { get; }
DataTable HeaderDataTable { get; }
DataTable MainDataTable { get; }
List<IDeclarationDataTable> SubTables { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace RevitDeclarations.Models {
internal class PublicAreasDataTable : DeclarationDataTable {
public PublicAreasDataTable(PublicAreasTableInfo tableInfo) : base(tableInfo) {
public PublicAreasDataTable(string name, PublicAreasTableInfo tableInfo) : base(name, tableInfo) {
}

protected override void FillTableHeader() {
Expand All @@ -27,7 +27,7 @@ protected override void FillMainTable() {
_mainTable.Rows[rowNumber][2] = publicArea.RoomPosition ?? "";
_mainTable.Rows[rowNumber][3] = publicArea.Department ?? "";
_mainTable.Rows[rowNumber][4] = publicArea.AreaMain;
_mainTable.Rows[rowNumber][5] = "";
_mainTable.Rows[rowNumber][5] = _settings.ProjectName ?? "";

rowNumber++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ internal class ApartmentsTableInfo : ITableInfo {
private readonly int _rowsTotalNumber;
private readonly int _groupsInfoColumnsNumber;
private readonly int[] _numericColumnsIndexes;
private readonly int[] _areaTypeColumnsIndexes;
private readonly int[] _lengthTypeColumnsIndexes;
private readonly int _utpWidth = 9;

private readonly DeclarationSettings _settings;
Expand Down Expand Up @@ -36,10 +38,15 @@ public ApartmentsTableInfo(IReadOnlyCollection<Apartment> apartments, Declaratio
CountRoomsForPriorities();
CalculateTableSizes();

int[] mainColumnsIndexes = new int[] { 7, 8, 9, 10, 13, 14 };
_numericColumnsIndexes = mainColumnsIndexes
int[] mainColumnsNumIndexes = new int[] { 7, 8, 9, 13, 14 };
_areaTypeColumnsIndexes = mainColumnsNumIndexes
.Concat(FindNumericColumns())
.ToArray();
_lengthTypeColumnsIndexes = new int[] { 10 };

_numericColumnsIndexes = _areaTypeColumnsIndexes
.Concat(_lengthTypeColumnsIndexes)
.ToArray();
}

public int ColumnsTotalNumber => _columnsTotalNumber;
Expand All @@ -50,6 +57,8 @@ public ApartmentsTableInfo(IReadOnlyCollection<Apartment> apartments, Declaratio
public int OtherRoomsStart => _otherRoomsStart;
public int UtpStart => _utpStart;
public int[] NumericColumnsIndexes => _numericColumnsIndexes;
public int[] AreaTypeColumnsIndexes => _areaTypeColumnsIndexes;
public int[] LengthTypeColumnsIndexes => _lengthTypeColumnsIndexes;

public DeclarationSettings Settings => _settings;
public IReadOnlyCollection<RoomGroup> RoomGroups => _apartments;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ internal class CommercialGroupTableInfo : ITableInfo {
private readonly int _otherRoomsStart;
private readonly int _utpStart;
private readonly int[] _numericColumnsIndexes;
private readonly int[] _areaTypeColumnsIndexes;
private readonly int[] _lengthTypeColumnsIndexes;

private readonly DeclarationSettings _settings;
private readonly IReadOnlyCollection<CommercialRooms> _roomGroups;
Expand All @@ -22,8 +24,14 @@ public CommercialGroupTableInfo(IReadOnlyCollection<CommercialRooms> roomGroups,
_summerRoomsStart = 0;
_otherRoomsStart = 0;
_utpStart = 0;
_numericColumnsIndexes = new int[] { 1 };
_rowsTotalNumber = RoomGroups.First().Rooms.Count();

_areaTypeColumnsIndexes = new int[] { 1 };
_lengthTypeColumnsIndexes = new int[] { };
_numericColumnsIndexes = _areaTypeColumnsIndexes
.Concat(_lengthTypeColumnsIndexes)
.ToArray();

_rowsTotalNumber = RoomGroups.Select(x => x.Rooms.Count()).Sum();
}

public int ColumnsTotalNumber => _columnsTotalNumber;
Expand All @@ -34,6 +42,8 @@ public CommercialGroupTableInfo(IReadOnlyCollection<CommercialRooms> roomGroups,
public int OtherRoomsStart => _otherRoomsStart;
public int UtpStart => _utpStart;
public int[] NumericColumnsIndexes => _numericColumnsIndexes;
public int[] AreaTypeColumnsIndexes => _areaTypeColumnsIndexes;
public int[] LengthTypeColumnsIndexes => _lengthTypeColumnsIndexes;

public DeclarationSettings Settings => _settings;
public IReadOnlyCollection<RoomGroup> RoomGroups => _roomGroups;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ internal class CommercialTableInfo : ITableInfo {
private readonly int _otherRoomsStart;
private readonly int _utpStart;
private readonly int[] _numericColumnsIndexes;
private readonly int[] _areaTypeColumnsIndexes;
private readonly int[] _lengthTypeColumnsIndexes;

private readonly DeclarationSettings _settings;
private readonly IReadOnlyCollection<CommercialRooms> _commercialRooms;
Expand All @@ -27,6 +29,12 @@ public CommercialTableInfo(IReadOnlyCollection<CommercialRooms> commercialRooms,
_utpStart = 0;
_numericColumnsIndexes = new int[] { 7, 8 };
_rowsTotalNumber = RoomGroups.Count;

_areaTypeColumnsIndexes = new int[] { 7 };
_lengthTypeColumnsIndexes = new int[] { 8 };
_numericColumnsIndexes = _areaTypeColumnsIndexes
.Concat(_lengthTypeColumnsIndexes)
.ToArray();
}

public int ColumnsTotalNumber => _columnsTotalNumber;
Expand All @@ -36,6 +44,8 @@ public CommercialTableInfo(IReadOnlyCollection<CommercialRooms> commercialRooms,
public int OtherRoomsStart => _otherRoomsStart;
public int UtpStart => _utpStart;
public int[] NumericColumnsIndexes => _numericColumnsIndexes;
public int[] AreaTypeColumnsIndexes => _areaTypeColumnsIndexes;
public int[] LengthTypeColumnsIndexes => _lengthTypeColumnsIndexes;

public DeclarationSettings Settings => _settings;
public IReadOnlyCollection<RoomGroup> RoomGroups => _commercialRooms;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RevitDeclarations.Models {
internal interface ITableInfo {
Expand All @@ -14,6 +10,8 @@ internal interface ITableInfo {
int OtherRoomsStart { get; }
int UtpStart { get; }
int[] NumericColumnsIndexes { get; }
int[] AreaTypeColumnsIndexes { get; }
int[] LengthTypeColumnsIndexes { get; }

DeclarationSettings Settings { get; }
IReadOnlyCollection<RoomGroup> RoomGroups { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ internal class PublicAreasTableInfo : ITableInfo {
private readonly int _otherRoomsStart;
private readonly int _utpStart;
private readonly int[] _numericColumnsIndexes;
private readonly int[] _areaTypeColumnsIndexes;
private readonly int[] _lengthTypeColumnsIndexes;

private readonly DeclarationSettings _settings;
private readonly IReadOnlyCollection<PublicArea> _publicAreas;
Expand All @@ -26,8 +28,13 @@ public PublicAreasTableInfo(IReadOnlyCollection<PublicArea> publicAreas,
_summerRoomsStart = 0;
_otherRoomsStart = 0;
_utpStart = 0;
_numericColumnsIndexes = new int[] { 4 };
_rowsTotalNumber = RoomGroups.Count;

_areaTypeColumnsIndexes = new int[] { 4 };
_lengthTypeColumnsIndexes = new int[] { };
_numericColumnsIndexes = _areaTypeColumnsIndexes
.Concat(_lengthTypeColumnsIndexes)
.ToArray();
}

public int ColumnsTotalNumber => _columnsTotalNumber;
Expand All @@ -37,6 +44,8 @@ public PublicAreasTableInfo(IReadOnlyCollection<PublicArea> publicAreas,
public int OtherRoomsStart => _otherRoomsStart;
public int UtpStart => _utpStart;
public int[] NumericColumnsIndexes => _numericColumnsIndexes;
public int[] AreaTypeColumnsIndexes => _areaTypeColumnsIndexes;
public int[] LengthTypeColumnsIndexes => _lengthTypeColumnsIndexes;

public DeclarationSettings Settings => _settings;
public IReadOnlyCollection<RoomGroup> RoomGroups => _publicAreas;
Expand Down
13 changes: 11 additions & 2 deletions src/RevitDeclarations/Models/Export/Exporters/CsvExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,22 @@
namespace RevitDeclarations.Models {
internal class CsvExporter : ITableExporter {
public void Export(string path, IDeclarationDataTable table) {
path = Path.ChangeExtension(path, "csv");
string fullPath = Path.ChangeExtension(path, "csv");

string strData = ConvertDataTableToString(table);

using(StreamWriter file = File.CreateText(path)) {
using(StreamWriter file = File.CreateText(fullPath)) {
file.Write(strData);
}

if(table.SubTables.Any()) {
int tableNumber = 1;
foreach(var subTable in table.SubTables) {
path = $"{path}-{tableNumber}";
Export(path, subTable);
tableNumber++;
}
}
}

private string ConvertDataTableToString(IDeclarationDataTable table) {
Expand Down
Loading