148 lines
4.9 KiB
C#
148 lines
4.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using Autodesk.Revit.DB;
|
|
using Autodesk.Revit.UI;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using Sai.Database.Shared;
|
|
using Sai.RvKits.Operation;
|
|
using SZBIM.StandardTools;
|
|
|
|
namespace Sai.Common.Shared.WBSCoder
|
|
{
|
|
/// <summary>
|
|
/// 主窗口viewmodel
|
|
/// </summary>
|
|
public partial class CheckCodeViewModel : ObservableObject
|
|
{
|
|
public CheckCodeViewModel(UIDocument uidoc, SqliteUtil sqliteUtil)
|
|
{
|
|
SqliteUtil = sqliteUtil;
|
|
Uidoc = uidoc;
|
|
Index = 0;
|
|
Init(archiDatabase);
|
|
}
|
|
|
|
public const int WM_CLOSE = 0x10;
|
|
private readonly string archiDatabase = $"{RelativePaths.DirAssembly}\\Database\\ArchiWBSCode.db";
|
|
private readonly string metroDatabase = $"{RelativePaths.DirAssembly}\\Database\\MetroWBSCode.db";
|
|
public readonly SqliteUtil SqliteUtil;
|
|
|
|
[ObservableProperty] private System.Windows.Media.ImageSource icon;
|
|
|
|
[ObservableProperty] private string projectPath;
|
|
|
|
public IList<Element> AllElements => GetElementInstances();
|
|
|
|
public int? Index { get; set; }
|
|
|
|
public ObservableCollection<TaskItem> LastTaskItems { get; set; } = new();
|
|
|
|
public ObservableCollection<WBSData> EngineerCategories { get; set; } = new();
|
|
|
|
public UIDocument Uidoc { get; set; }
|
|
|
|
/// <summary>
|
|
/// 获取项目中所有实例
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public IList<Element> GetElementInstances()
|
|
{
|
|
if (Uidoc == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
ElementClassFilter hostObjFilter = new ElementClassFilter(typeof(HostObject));
|
|
ElementClassFilter instanceFilter = new ElementClassFilter(typeof(FamilyInstance));
|
|
LogicalOrFilter logicalOrFilter = new LogicalOrFilter(hostObjFilter, instanceFilter);
|
|
|
|
var elems = new FilteredElementCollector(Uidoc.Document).WherePasses(logicalOrFilter).ToElements();
|
|
return elems;
|
|
}
|
|
|
|
[RelayCommand]
|
|
private void Closed()
|
|
{
|
|
SqliteUtil.CloseConnection();
|
|
var win = WinIntPtr.FindWindow(null, "打开Project文件");
|
|
WinIntPtr.SendMessage(win, WM_CLOSE, 0, 0);
|
|
}
|
|
|
|
[RelayCommand]
|
|
private void GetDataBase(object obj)
|
|
{
|
|
System.Windows.Controls.ComboBox cbb = obj as System.Windows.Controls.ComboBox;
|
|
Index = cbb?.SelectedIndex;
|
|
switch (Index)
|
|
{
|
|
case 0:
|
|
Init(archiDatabase);
|
|
break;
|
|
case 1:
|
|
Init(metroDatabase);
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void Init(string database)
|
|
{
|
|
//SqliteUtil.CloseConnection();
|
|
try
|
|
{
|
|
SqliteUtil.CreateDb(database);
|
|
var categories = (from array in SqliteUtil.QueryTable("CATEGORY")
|
|
select new WBSData { Name = array[4], WbsCode = array[3], HierarchicalCode = array[2] }).ToList();
|
|
EngineerCategories.Clear();
|
|
foreach (var wbsData in categories)
|
|
{
|
|
EngineerCategories.Add(wbsData);
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e);
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[RelayCommand]
|
|
private void OpenProjectFileDialog()
|
|
{
|
|
const string filter = "项目(*.mpp)|*.mpp";
|
|
FileOpenDialog openFileDialog = new FileOpenDialog(filter)
|
|
{
|
|
DefaultFilterEntry = filter,
|
|
ShowPreview = true,
|
|
Title = "打开Project文件"
|
|
};
|
|
if (openFileDialog.Show() == ItemSelectionDialogResult.Confirmed)
|
|
{
|
|
ModelPath mp = openFileDialog.GetSelectedModelPath();
|
|
ProjectPath = ModelPathUtils.ConvertModelPathToUserVisiblePath(mp);
|
|
ProjectUtil.GetTasks(ProjectPath, LastTaskItems);
|
|
}
|
|
}
|
|
|
|
[RelayCommand]
|
|
private static void SearchData(object obj)
|
|
{
|
|
if (!(obj is object[] multiObj)) return;
|
|
DataGrid dataGrid = multiObj[0] as DataGrid;
|
|
System.Windows.Controls.TextBox textBox = multiObj[1] as System.Windows.Controls.TextBox;
|
|
var cvs = CollectionViewSource.GetDefaultView(dataGrid.ItemsSource);
|
|
if (cvs != null && cvs.CanFilter)
|
|
{
|
|
cvs.Filter = p =>
|
|
{
|
|
TaskItem task = p as TaskItem;
|
|
return task.Name.Contains(textBox.Text);
|
|
};
|
|
}
|
|
}
|
|
}
|
|
} |