009_DI-Elec/newFront/c#前端/SWS.Electrical/ViewModels/DialogAutoArrangeLayoutViewModel.cs

215 lines
6.8 KiB
C#
Raw Normal View History

2025-08-15 16:44:13 +08:00
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Input;
using Prism.Services.Dialogs;
using SWS.CAD.Base;
using SWS.Commons;
using SWS.Electrical.Models;
using SWS.Model;
using SWS.Service;
using SWS.WPF.ViewModels;
using Teigha.DatabaseServices;
using Telerik.Windows.Controls;
using Unity;
using Visibility = System.Windows.Visibility;
namespace SWS.Electrical.ViewModels
{
public class DialogAutoArrangeLayoutViewModel : DialogBase, IDialogAware
{
private ObservableCollection<DtoDrawing> _listDrawings;
/// <summary>
/// 布置图列表
/// </summary>
public ObservableCollection<DtoDrawing> listDrawings
{
get { return this._listDrawings; }
set
{
if (value != this._listDrawings)
{
this._listDrawings = value;
RaisePropertyChanged(nameof(listDrawings));
}
}
}
private ObservableCollection<KeyValueModel> _listRange;
/// <summary>
/// 范围
/// </summary>
public ObservableCollection<KeyValueModel> listRange
{
get { return this._listRange; }
set
{
if (value != this._listRange)
{
this._listRange = value;
RaisePropertyChanged(nameof(listRange));
}
}
}
private KeyValueModel _selectRange;
/// <summary>
/// 选中范围
/// </summary>
public KeyValueModel selectRange
{
get { return this._selectRange; }
set
{
if (value != this._selectRange)
{
this._selectRange = value;
RaisePropertyChanged(nameof(selectRange));
}
}
}
private ObservableCollection<KeyValueModel> _listOperator;
/// <summary>
/// 判断
/// </summary>
public ObservableCollection<KeyValueModel> listOperator
{
get { return this._listOperator; }
set
{
if (value != this._listOperator)
{
this._listOperator = value;
RaisePropertyChanged(nameof(listOperator));
}
}
}
private KeyValueModel _selectOperator;
/// <summary>
/// 选中判断
/// </summary>
public KeyValueModel selectOperator
{
get { return this._selectOperator; }
set
{
if (value != this._selectOperator)
{
this._selectOperator = value;
RaisePropertyChanged(nameof(selectOperator));
}
}
}
private string _inputValue = "";
/// <summary>
/// 输入值
/// </summary>
public string inputValue
{
get { return _inputValue; }
set { _inputValue = value; OnPropertyChanged(nameof(inputValue)); }
}
/// <summary>
/// 命令事件
/// </summary>
public ICommand Command_StartDrawing { get; set; }
PlotLayoutService _ServicePlotLayout;
DrawingServce _ServiceDrawing;
public DialogAutoArrangeLayoutViewModel()
{
Command_StartDrawing = new DelegateCommand(onStartDrawing);
title = "布置图自动绘制";
_ServicePlotLayout = GlobalObject.container.Resolve<PlotLayoutService>();
_ServiceDrawing = GlobalObject.container.Resolve<DrawingServce>();
listDrawings = new ObservableCollection<DtoDrawing>();
if (GlobalObj.treeDrawings.Any())
{
foreach (var model in GlobalObj.treeDrawings)
{
if (model.Text == "布置图")
{
foreach (var item in model.ChildNodes)
{
if (item.NodeType == "1")
{
listDrawings.Add(new DtoDrawing() { DrawingFileID = item.ID, DrawingFileName = item.Text });
}
}
}
}
}
var list = new ObservableCollection<KeyValueModel>();
list.Add(new KeyValueModel { Key = "甲板号", Value = "甲板号" });
list.Add(new KeyValueModel { Key = "区域", Value = "区域" });
list.Add(new KeyValueModel { Key = "系统", Value = "系统" });
listRange = new ObservableCollection<KeyValueModel>(list);
selectRange = listRange[0];
listOperator = new ObservableCollection<KeyValueModel>()
{ new KeyValueModel { Key = "等于", Value = "等于" }
};
selectOperator = listOperator[0];
}
public string Title => "";
public event Action<IDialogResult> RequestClose;
public bool CanCloseDialog()
{
return true;
}
public void OnDialogClosed()
{
}
public void OnDialogOpened(IDialogParameters parameters)
{
Task.Factory.StartNew(() =>
{
int i = 0;
while (!listDrawings.Any())
{
Thread.Sleep(100);
foreach (var model in GlobalObj.treeDrawings)
{
if (model.Text == "布置图")
{
foreach (var item in model.ChildNodes)
{
if (item.NodeType == "1")
{
listDrawings.Add(new DtoDrawing() { DrawingFileID = item.ID, DrawingFileName = item.Text });
}
}
}
}
i++;
if(i>500)
{ break; }
}
});
}
public async void onStartDrawing(object o)
{
var listSelDwg = listDrawings.Where(a => a.isChecked == true).ToList();
if (!listSelDwg.Any())
{
MessageBox.Show("请先选择布置图!");
}
foreach (var item in listSelDwg)
{
var list = await _ServicePlotLayout.GetBasePointByDwg(selectRange.Value, selectOperator.Value, inputValue, item.DrawingFileID);
}
}
}
}