148 lines
5.2 KiB
C#
148 lines
5.2 KiB
C#
using System.Collections;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
using System.Windows;
|
|
|
|
using Autodesk.Revit.DB;
|
|
|
|
using EPPlus.Core.Extensions;
|
|
using EPPlus.Core.Extensions.Attributes;
|
|
|
|
using Microsoft.Win32;
|
|
|
|
using OfficeOpenXml;
|
|
|
|
using Szmedi.RvKits.MEPTools;
|
|
|
|
namespace Szmedi.RvKits.ModelManager
|
|
{
|
|
public partial class ProjectComparatorViewModel : ObservableObject
|
|
{
|
|
public ProjectComparatorViewModel()
|
|
{
|
|
OldDocuments = [.. GlobalVariables.UIApplication.Application.Documents.OfType<Document>().Where(d => !d.IsFamilyDocument)];
|
|
DesignParameters = new ObservableCollection<ParameterItem>
|
|
{
|
|
new ("长度"),
|
|
new ("宽度"),
|
|
new ("高度"),
|
|
new ("抗渗等级"),
|
|
new ("结构材质"),
|
|
new ("混凝土标号"),
|
|
new ("基础编号"),
|
|
};
|
|
QuantityParameters = new ObservableCollection<ParameterItem>
|
|
{
|
|
new ("体积"),
|
|
new ("面积"),
|
|
};
|
|
}
|
|
[RelayCommand]
|
|
private void AddCustomDesignParameter()
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(CustomDesignParamName))
|
|
{
|
|
// 防止重复添加
|
|
if (!DesignParameters.Any(p => p.Name.Equals(CustomDesignParamName)))
|
|
{
|
|
DesignParameters.Add(new ParameterItem(CustomDesignParamName));
|
|
}
|
|
CustomDesignParamName = string.Empty; // 清空输入框
|
|
}
|
|
}
|
|
[RelayCommand]
|
|
private void RemoveCustomDesignParameter(IList list)
|
|
{
|
|
var designParams = list.Cast<object>().Where(p => p is ParameterItem).Cast<ParameterItem>();
|
|
List<ParameterItem> items = [.. designParams];
|
|
foreach (var item in items)
|
|
{
|
|
DesignParameters.Remove(item);
|
|
}
|
|
|
|
}
|
|
[RelayCommand]
|
|
private void AddCustomQuantityParameter()
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(CustomQuantityParamName))
|
|
{
|
|
// 防止重复添加
|
|
if (!QuantityParameters.Any(p => p.Name.Equals(CustomQuantityParamName)))
|
|
{
|
|
QuantityParameters.Add(new ParameterItem(CustomQuantityParamName));
|
|
}
|
|
CustomQuantityParamName = string.Empty; // 清空输入框
|
|
}
|
|
}
|
|
[RelayCommand]
|
|
private void RemoveCustomQuantityParameter(IList list)
|
|
{
|
|
var quantityParams = list.Cast<object>().Where(p => p is ParameterItem).Cast<ParameterItem>();
|
|
List<ParameterItem> items = [.. quantityParams];
|
|
foreach (var item in items)
|
|
{
|
|
QuantityParameters.Remove(item);
|
|
}
|
|
|
|
}
|
|
// 用户自定义输入的新参数名
|
|
[ObservableProperty]
|
|
public partial string CustomDesignParamName { get; set; }
|
|
[ObservableProperty]
|
|
public partial string CustomQuantityParamName { get; set; }
|
|
|
|
public ObservableCollection<ParameterItem> DesignParameters { get; set; }
|
|
public ObservableCollection<ParameterItem> QuantityParameters { get; set; }
|
|
|
|
public ObservableCollection<Document> OldDocuments { get; private set; }
|
|
|
|
public ObservableCollection<Document> NewDocuments { get; private set; } = [];
|
|
|
|
|
|
[ObservableProperty]
|
|
[NotifyCanExecuteChangedFor(nameof(StartCompareCommand))]
|
|
public partial Document OldDocument { get; set; }
|
|
|
|
partial void OnOldDocumentChanged(Document value)
|
|
{
|
|
NewDocuments.Clear();
|
|
foreach (var item in OldDocuments)
|
|
{
|
|
if (item.PathName == value.PathName)
|
|
{
|
|
continue;
|
|
}
|
|
NewDocuments.Add(item);
|
|
}
|
|
}
|
|
[ObservableProperty]
|
|
[NotifyCanExecuteChangedFor(nameof(StartCompareCommand))]
|
|
public partial Document NewDocument { get; set; }
|
|
private bool CanCompare => OldDocument != null && NewDocument != null && !OldDocument.Equals(NewDocument);
|
|
|
|
[RelayCommand(CanExecute = nameof(CanCompare))]
|
|
private void StartCompare()
|
|
{
|
|
if (OldDocument.PathName == NewDocument.PathName)
|
|
{
|
|
MessageBox.Show("请选择不同的文档进行比较", "错误", MessageBoxButton.OK);
|
|
return;
|
|
}
|
|
var designParameters = new List<string>(
|
|
DesignParameters.Select(p => p.Name));
|
|
var quantityParameters = new List<string>(
|
|
QuantityParameters.Select(p => p.Name));
|
|
|
|
ProjectComparer comparer = new ProjectComparer(designParameters, quantityParameters);
|
|
var infos = comparer.CompareDocuments(OldDocument, NewDocument);
|
|
string excelPath = Path.Combine(
|
|
Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
|
|
$"构件对比报告_{DateTime.Now:yyyyMMdd_HHmmss}.xlsx"
|
|
);
|
|
ReportGenerator.Export(infos, excelPath);
|
|
MessageBox.Show("报告输出完成,请查看桌面的构件对比报告");
|
|
|
|
}
|
|
}
|
|
|
|
} |