2025-09-04 18:28:02 +08:00
|
|
|
|
using Prism.Services.Dialogs;
|
2025-10-09 18:08:19 +08:00
|
|
|
|
using SWS.CAD.Base;
|
2025-08-15 16:34:31 +08:00
|
|
|
|
using SWS.CAD.ViewModels.myViewModelBase;
|
2025-09-04 18:28:02 +08:00
|
|
|
|
using SWS.Commons;
|
|
|
|
|
using SWS.Model;
|
|
|
|
|
using SWS.Service;
|
2025-08-15 16:34:31 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using Unity;
|
|
|
|
|
|
|
|
|
|
namespace SWS.CAD.ViewModels
|
|
|
|
|
{
|
|
|
|
|
public class NewDrawingViewModel : DialogBase, IDialogAware
|
|
|
|
|
{
|
|
|
|
|
#region 数据绑定
|
2025-09-04 18:28:02 +08:00
|
|
|
|
private ObservableCollection<Model.TreeModel> _templates;
|
2025-08-15 16:34:31 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 图纸模板
|
|
|
|
|
/// </summary>
|
2025-09-04 18:28:02 +08:00
|
|
|
|
public ObservableCollection<Model.TreeModel> templates
|
2025-08-15 16:34:31 +08:00
|
|
|
|
{
|
|
|
|
|
get { return _templates; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_templates = value; RaisePropertyChanged(nameof(templates));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-04 18:28:02 +08:00
|
|
|
|
private ObservableCollection<SWS.Model.ec_dataitemdetail> _dwgType;
|
2025-08-15 16:34:31 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 图纸类型
|
|
|
|
|
/// </summary>
|
2025-09-04 18:28:02 +08:00
|
|
|
|
public ObservableCollection<SWS.Model.ec_dataitemdetail> dwgType
|
2025-08-15 16:34:31 +08:00
|
|
|
|
{
|
|
|
|
|
get { return _dwgType; }
|
|
|
|
|
set { _dwgType = value; RaisePropertyChanged(nameof(dwgType)); }
|
|
|
|
|
}
|
|
|
|
|
private ec_drawing_file _dwgObj;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 图纸实体对象
|
|
|
|
|
/// </summary>
|
|
|
|
|
public ec_drawing_file dwgObj
|
|
|
|
|
{
|
|
|
|
|
get { return _dwgObj; }
|
|
|
|
|
set { _dwgObj = value; RaisePropertyChanged(nameof(dwgObj)); }
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-04 18:28:02 +08:00
|
|
|
|
private ObservableCollection<SWS.Model.ec_dataitemdetail> _dwgMaterialRange;
|
2025-08-15 16:34:31 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 材料范围
|
|
|
|
|
/// </summary>
|
2025-09-04 18:28:02 +08:00
|
|
|
|
public ObservableCollection<SWS.Model.ec_dataitemdetail> dwgMaterialRange
|
2025-08-15 16:34:31 +08:00
|
|
|
|
{
|
|
|
|
|
get { return _dwgMaterialRange; }
|
|
|
|
|
set { _dwgMaterialRange = value; RaisePropertyChanged(nameof(dwgMaterialRange)); }
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-04 18:28:02 +08:00
|
|
|
|
private ObservableCollection<SWS.Model.ec_dataitemdetail> _dwgMaterialCensus;
|
2025-08-15 16:34:31 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 统计方式
|
|
|
|
|
/// </summary>
|
2025-09-04 18:28:02 +08:00
|
|
|
|
public ObservableCollection<SWS.Model.ec_dataitemdetail> dwgMaterialCensus
|
2025-08-15 16:34:31 +08:00
|
|
|
|
{
|
|
|
|
|
get { return _dwgMaterialCensus; }
|
|
|
|
|
set { _dwgMaterialCensus = value; RaisePropertyChanged(nameof(dwgMaterialCensus)); }
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-04 18:28:02 +08:00
|
|
|
|
private ObservableCollection<SWS.Model.ec_dataitemdetail> _dwgStage;
|
2025-08-15 16:34:31 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 设计阶段
|
|
|
|
|
/// </summary>
|
2025-09-04 18:28:02 +08:00
|
|
|
|
public ObservableCollection<SWS.Model.ec_dataitemdetail> dwgStage
|
2025-08-15 16:34:31 +08:00
|
|
|
|
{
|
|
|
|
|
get { return _dwgStage; }
|
|
|
|
|
set { _dwgStage = value; RaisePropertyChanged(nameof(dwgStage)); }
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-04 18:28:02 +08:00
|
|
|
|
private ObservableCollection<Model.TreeModel> _dwgSystem;
|
2025-08-15 16:34:31 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 所属系统
|
|
|
|
|
/// </summary>
|
2025-09-04 18:28:02 +08:00
|
|
|
|
public ObservableCollection<Model.TreeModel> dwgSystem
|
2025-08-15 16:34:31 +08:00
|
|
|
|
{
|
|
|
|
|
get { return _dwgSystem; }
|
|
|
|
|
set { _dwgSystem = value; RaisePropertyChanged(nameof(dwgSystem)); }
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-04 18:28:02 +08:00
|
|
|
|
private ObservableCollection<Model.TreeModel> _dwgCatalogueID;
|
2025-08-15 16:34:31 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 图纸目录树,不带图纸文件名,纯目录树
|
|
|
|
|
/// </summary>
|
2025-09-04 18:28:02 +08:00
|
|
|
|
public ObservableCollection<Model.TreeModel> dwgCatalogueID
|
2025-08-15 16:34:31 +08:00
|
|
|
|
{
|
|
|
|
|
get { return _dwgCatalogueID; }
|
|
|
|
|
set { _dwgCatalogueID = value; RaisePropertyChanged(nameof(dwgCatalogueID)); }
|
|
|
|
|
}
|
2025-09-04 18:28:02 +08:00
|
|
|
|
private ObservableCollection<Model.TreeModel> _tempCatalogueID;
|
2025-08-15 16:34:31 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 图纸目录树,带图纸文件名,用于新建图纸时,遍历判断目录下图纸是否有文件重名
|
|
|
|
|
/// </summary>
|
2025-09-04 18:28:02 +08:00
|
|
|
|
public ObservableCollection<Model.TreeModel> tempCatalogueID
|
2025-08-15 16:34:31 +08:00
|
|
|
|
{
|
|
|
|
|
get { return _tempCatalogueID; }
|
|
|
|
|
set { _tempCatalogueID = value; }
|
|
|
|
|
}
|
2025-09-04 18:28:02 +08:00
|
|
|
|
private Model.TreeModel _SelectedSystemItem;
|
2025-08-15 16:34:31 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 所属系统选中项
|
|
|
|
|
/// </summary>
|
2025-09-04 18:28:02 +08:00
|
|
|
|
public Model.TreeModel SelectedSystemItem
|
2025-08-15 16:34:31 +08:00
|
|
|
|
{
|
|
|
|
|
get { return _SelectedSystemItem; }
|
|
|
|
|
set { _SelectedSystemItem = value; RaisePropertyChanged(nameof(SelectedSystemItem)); }
|
|
|
|
|
}
|
2025-09-04 18:28:02 +08:00
|
|
|
|
private Model.TreeModel _SelectedTemplateItem;
|
2025-08-15 16:34:31 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 图纸模板选中项
|
|
|
|
|
/// </summary>
|
2025-09-04 18:28:02 +08:00
|
|
|
|
public Model.TreeModel SelectedTemplateItem
|
2025-08-15 16:34:31 +08:00
|
|
|
|
{
|
|
|
|
|
get { return _SelectedTemplateItem; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
_SelectedTemplateItem = value;
|
|
|
|
|
|
|
|
|
|
RaisePropertyChanged(nameof(SelectedTemplateItem));
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-09-04 18:28:02 +08:00
|
|
|
|
private Model.TreeModel _SelectedCatalogueIDItem;
|
2025-08-15 16:34:31 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 图纸目录选中项
|
|
|
|
|
/// </summary>
|
2025-09-04 18:28:02 +08:00
|
|
|
|
public Model.TreeModel SelectedCatalogueIDItem
|
2025-08-15 16:34:31 +08:00
|
|
|
|
{
|
|
|
|
|
get { return _SelectedCatalogueIDItem; }
|
|
|
|
|
set { _SelectedCatalogueIDItem = value; RaisePropertyChanged(nameof(SelectedCatalogueIDItem)); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool _IsEnableTemplate;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 模板列表是否可用
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool IsEnableTemplate
|
|
|
|
|
{
|
|
|
|
|
get { return _IsEnableTemplate; }
|
|
|
|
|
set { _IsEnableTemplate = value; OnPropertyChanged(nameof(IsEnableTemplate)); }
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
DrawingServce _drawingServce;
|
|
|
|
|
AnnexesService _annexesService;
|
|
|
|
|
TemplateFileService _templateFileService;
|
2025-09-04 18:28:02 +08:00
|
|
|
|
Model.TreeModel curTreeNode = null;
|
2025-08-15 16:34:31 +08:00
|
|
|
|
string oldDwgFileName = string.Empty;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 窗体模式 0:新建图纸,1:编辑属性
|
|
|
|
|
/// </summary>
|
|
|
|
|
int mode = 0;
|
2025-09-04 18:28:02 +08:00
|
|
|
|
public string Title => "";
|
|
|
|
|
public event Action<IDialogResult> RequestClose;
|
2025-08-15 16:34:31 +08:00
|
|
|
|
public NewDrawingViewModel() : base()
|
|
|
|
|
{
|
|
|
|
|
_drawingServce = GlobalObject.container.Resolve<DrawingServce>(); // 不要在构造函数里注入,免得报 No parameterless constructor defined for this object
|
|
|
|
|
_annexesService = GlobalObject.container.Resolve<AnnexesService>();
|
|
|
|
|
_templateFileService = GlobalObject.container.Resolve<TemplateFileService>();
|
|
|
|
|
dwgObj = new ec_drawing_file();
|
2025-09-04 18:28:02 +08:00
|
|
|
|
templates = new ObservableCollection<Model.TreeModel>();
|
|
|
|
|
dwgCatalogueID = new ObservableCollection<Model.TreeModel>();
|
|
|
|
|
dwgMaterialRange = new ObservableCollection<SWS.Model.ec_dataitemdetail>();
|
|
|
|
|
dwgMaterialCensus = new ObservableCollection<SWS.Model.ec_dataitemdetail>();
|
|
|
|
|
dwgStage = new ObservableCollection<SWS.Model.ec_dataitemdetail>();
|
2025-08-15 16:34:31 +08:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 关闭窗体
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 是否能关闭窗体
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public bool CanCloseDialog()
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 窗体关闭
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void OnDialogClosed()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 窗体打开完成,初始化数据
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 窗体打开完成,初始化数据
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="parameters"></param>
|
|
|
|
|
public async void OnDialogOpened(IDialogParameters parameters)
|
|
|
|
|
{
|
|
|
|
|
IsBusy=true;BusyContent = "加载中...";
|
2025-09-04 18:28:02 +08:00
|
|
|
|
curTreeNode = parameters.GetValue<Model.TreeModel>(nameof(ec_drawing_file.DrawingCatalogueID));
|
2025-08-15 16:34:31 +08:00
|
|
|
|
//初始化图纸目录树形下拉框
|
|
|
|
|
dwgCatalogueID = await _drawingServce.GetDrawingCatalogue("1");//参数给1,server返回的时候默认就没有.dwg的目录树了
|
|
|
|
|
tempCatalogueID = await _drawingServce.GetDrawingCatalogue(); //返回带.dwg文件的目录树,方便后续校验是否文件重名
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//初始化图纸类型下拉框
|
2025-09-04 18:28:02 +08:00
|
|
|
|
dwgType = new ObservableCollection<SWS.Model.ec_dataitemdetail>(GlobalObje.DwgType());
|
2025-08-15 16:34:31 +08:00
|
|
|
|
//初始化材料范围下拉框
|
2025-09-04 18:28:02 +08:00
|
|
|
|
dwgMaterialRange = new ObservableCollection<SWS.Model.ec_dataitemdetail>(GlobalObje.DwgMaterialRange());
|
2025-08-15 16:34:31 +08:00
|
|
|
|
//初始化材料统计下拉框
|
2025-09-04 18:28:02 +08:00
|
|
|
|
dwgMaterialCensus = new ObservableCollection<SWS.Model.ec_dataitemdetail>(GlobalObje.DwgMaterialCensus());
|
2025-08-15 16:34:31 +08:00
|
|
|
|
//初始化设计阶段下拉框
|
2025-09-04 18:28:02 +08:00
|
|
|
|
dwgStage = new ObservableCollection<SWS.Model.ec_dataitemdetail>(GlobalObje.DwgStage());
|
2025-08-15 16:34:31 +08:00
|
|
|
|
//初始化所属系统下拉框
|
2025-09-04 18:28:02 +08:00
|
|
|
|
dwgSystem = new ObservableCollection<Model.TreeModel>(GlobalObje.DwgSystem());
|
2025-08-15 16:34:31 +08:00
|
|
|
|
//判断窗体是新建图纸或编辑属性
|
|
|
|
|
if (curTreeNode.Text.ToLower().EndsWith(".dwg"))
|
|
|
|
|
{
|
|
|
|
|
mode = 1;//编辑属性
|
|
|
|
|
title = "编辑图纸";
|
|
|
|
|
//编辑属性时,禁用模板列表,无需加载
|
|
|
|
|
IsEnableTemplate = false;
|
|
|
|
|
dwgObj = await _drawingServce.GetDrawingFile(curTreeNode.ID);
|
|
|
|
|
oldDwgFileName = dwgObj.DrawingFileName;
|
|
|
|
|
InitCombobox(dwgObj);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
mode = 0; //新建图纸
|
|
|
|
|
title = "新建图纸";
|
|
|
|
|
IsEnableTemplate = true;
|
|
|
|
|
dwgObj.DrawingFileName = "新图纸";
|
|
|
|
|
dwgObj.OrderID = 0;
|
|
|
|
|
SelectedCatalogueIDItem = curTreeNode;
|
|
|
|
|
SelectedSystemItem = dwgSystem[0];
|
|
|
|
|
dwgObj.DrawingStage= dwgStage[0].DataItemDetailID;
|
|
|
|
|
//初始化图纸模板树形下拉框
|
|
|
|
|
var allTemplates = await _templateFileService.GetTemplateCatalogue();
|
|
|
|
|
allTemplates = allTemplates.Where(x => x.Text == GlobalObject.templateForDrawing).ToList();
|
2025-09-04 18:28:02 +08:00
|
|
|
|
templates = new ObservableCollection<Model.TreeModel>(allTemplates);
|
2025-08-15 16:34:31 +08:00
|
|
|
|
}
|
|
|
|
|
IsBusy = false; BusyContent = "";
|
|
|
|
|
OnPropertyChanged(nameof(dwgObj));
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 编辑属性时,赋值下拉框初始值
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="dwgFile"></param>
|
|
|
|
|
private void InitCombobox(ec_drawing_file dwgFile)
|
|
|
|
|
{
|
|
|
|
|
//所属系统下拉框
|
|
|
|
|
foreach (var item in dwgSystem)
|
|
|
|
|
{
|
2025-09-23 16:38:40 +08:00
|
|
|
|
var node = TreeHelper.GetTreeModel(item, dwgFile.DrawingSystem);
|
2025-08-15 16:34:31 +08:00
|
|
|
|
if (node != null)
|
|
|
|
|
{
|
|
|
|
|
SelectedSystemItem = node;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//图纸目录下拉框
|
|
|
|
|
foreach (var item in dwgCatalogueID)
|
|
|
|
|
{
|
2025-09-23 16:38:40 +08:00
|
|
|
|
var node = TreeHelper.GetTreeModel(item, dwgFile.DrawingCatalogueID);
|
2025-08-15 16:34:31 +08:00
|
|
|
|
if (node != null)
|
|
|
|
|
{
|
|
|
|
|
SelectedCatalogueIDItem = node;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 提交数据
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 提交数据
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="para"></param>
|
|
|
|
|
public override async void ExecuteOKCommandAsync(object para)
|
|
|
|
|
{
|
|
|
|
|
//赋值 图纸目录和所属系统
|
|
|
|
|
dwgObj.DrawingCatalogueID = SelectedCatalogueIDItem == null ? "" : SelectedCatalogueIDItem.ID;
|
|
|
|
|
dwgObj.DrawingSystem = SelectedSystemItem == null ? "" : SelectedSystemItem.ID;
|
|
|
|
|
|
|
|
|
|
#region check
|
|
|
|
|
//id不需要,server端会新建的
|
|
|
|
|
if (string.IsNullOrEmpty(dwgObj.DrawingFileName))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("图纸名称不能为空。"); return;
|
|
|
|
|
}
|
|
|
|
|
else if (!FileHelper.IsValidFileName(dwgObj.DrawingFileName))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("图纸名称含有特殊字符,请检查。"); return;
|
|
|
|
|
}
|
|
|
|
|
else if (string.IsNullOrEmpty(dwgObj.DrawingCatalogueID))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("图纸所在目录不能为空。"); return;
|
|
|
|
|
}
|
|
|
|
|
else if (string.IsNullOrEmpty(dwgObj.DrawingType))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("图纸类型不能为空,从列表里选一个。"); return;
|
|
|
|
|
}
|
|
|
|
|
else if (SelectedSystemItem == null)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("图纸的所属系统不能为空。从列表里选一个。"); return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
//IsBusy = true; BusyContent = "新建图纸中。";
|
|
|
|
|
//#region 是否有重名
|
|
|
|
|
//var curDwgs = SelectedCatalogueIDItem.ChildNodes.Select(X => X.Text).ToList();
|
|
|
|
|
//if (curDwgs.Any(X => X.ToLower() == dwgObj.DrawingFileName.ToLower() + ".dwg"))
|
|
|
|
|
//{
|
|
|
|
|
// MessageBox.Show($"图纸名称不能和当前目录 {SelectedCatalogueIDItem.Text} 下的其他图纸同名。"); return;
|
|
|
|
|
//}
|
|
|
|
|
//#endregion
|
|
|
|
|
if (mode == 0)
|
|
|
|
|
{
|
|
|
|
|
#region 新建图纸
|
|
|
|
|
|
|
|
|
|
IsBusy = true; BusyContent = "新建图纸中...";
|
|
|
|
|
//当文件名结尾没有.dwg时,自动添加文件格式后缀
|
|
|
|
|
if (!dwgObj.DrawingFileName.ToLower().EndsWith(".dwg"))
|
|
|
|
|
{
|
|
|
|
|
dwgObj.DrawingFileName += ".dwg";
|
|
|
|
|
}
|
|
|
|
|
#region 是否有重名
|
|
|
|
|
//用户可能更改目录,所以要判断当前选中目录下是否重名
|
|
|
|
|
if (CheckDwgName(SelectedCatalogueIDItem, dwgObj.DrawingFileName))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show($"图纸名称不能和当前目录:[{SelectedCatalogueIDItem.Text}] 下的其他图纸同名!");
|
|
|
|
|
IsBusy = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
#region 创建本地图纸
|
|
|
|
|
if (SelectedTemplateItem == null)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("图纸模板不能为空。从列表里选一个。"); IsBusy = false; return;
|
|
|
|
|
}
|
|
|
|
|
//获取模板ID
|
|
|
|
|
var templateId = SelectedTemplateItem.ID;
|
|
|
|
|
//根据模板ID获取模板实体
|
|
|
|
|
var templatefileDto = await _templateFileService.GetTemplateFile(templateId);
|
|
|
|
|
if (templatefileDto == null)
|
|
|
|
|
{ MessageBox.Show("请选择模板!"); IsBusy = false; return; }
|
|
|
|
|
//根据模板实体的FolderId,获取上传文件的实体
|
|
|
|
|
var dwgfileDto = await _annexesService.GetAnnexesFile(templatefileDto.FolderId);
|
|
|
|
|
// 指定新 DWG 文件的保存路径
|
|
|
|
|
string folderPath = GlobalObject.GetDwgFileFolder();
|
|
|
|
|
string filePath = Path.Combine(folderPath, dwgObj.DrawingFileName);
|
|
|
|
|
var msg = await _annexesService.DownloadFile(filePath, dwgfileDto.F_Id);
|
|
|
|
|
if (!string.IsNullOrEmpty(msg))
|
|
|
|
|
{ MessageBox.Show("模板文件下载失败,信息:" + msg); IsBusy = false; return; }
|
|
|
|
|
|
|
|
|
|
#region annexes 上传文件
|
|
|
|
|
var newFolderId = await _annexesService.UploadFile(Path.Combine(folderPath, dwgObj.DrawingFileName), dwgObj.DrawingFileName);
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 提交数据库,默认是检出状态
|
|
|
|
|
dwgObj.CreateUserID = GlobalObject.userInfo.userId;
|
|
|
|
|
dwgObj.FolderId = newFolderId;
|
|
|
|
|
dwgObj.FileMD5 = FileHelper.GetFileMD5(Path.Combine(folderPath, dwgObj.DrawingFileName));
|
|
|
|
|
dwgObj.IsEngineDWG = 1;
|
|
|
|
|
dwgObj.IsCheckOut = 1;
|
|
|
|
|
dwgObj.PCInfo = GlobalObject.GetPCInfo();
|
|
|
|
|
|
|
|
|
|
dwgObj = await _drawingServce.AddDrawingFile(dwgObj);
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
IsBusy = false;
|
|
|
|
|
if (string.IsNullOrEmpty(dwgObj.DrawingFileID))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("新建图纸失败!");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("新建图纸成功!");
|
|
|
|
|
//新建图纸完,自动打开图纸
|
2025-10-09 18:08:19 +08:00
|
|
|
|
msg = General.OpenDwg(filePath);
|
2025-08-15 16:34:31 +08:00
|
|
|
|
if (!string.IsNullOrEmpty(msg))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show($"本地图纸文件:{dwgObj.DrawingFileName} 打开失败,信息:{msg}");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-09-04 18:28:02 +08:00
|
|
|
|
DialogResult res = new DialogResult(ButtonResult.OK);
|
|
|
|
|
RequestClose.Invoke(res);
|
2025-08-15 16:34:31 +08:00
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
else if (mode == 1)
|
|
|
|
|
{
|
|
|
|
|
#region 编辑属性
|
|
|
|
|
IsBusy = true; BusyContent = "保存图纸中...";
|
|
|
|
|
if (!dwgObj.DrawingFileName.ToLower().EndsWith(".dwg"))
|
|
|
|
|
{
|
|
|
|
|
dwgObj.DrawingFileName += ".dwg";
|
|
|
|
|
}
|
|
|
|
|
var msg = await _drawingServce.UpdateDrawingFile(dwgObj);
|
|
|
|
|
if (!string.IsNullOrEmpty(msg))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("修改图纸数据失败,信息:" + msg); return;
|
|
|
|
|
}
|
|
|
|
|
IsBusy = false;
|
|
|
|
|
MessageBox.Show("保存成功!");
|
|
|
|
|
//旧图纸文件名和新图纸文件名不一致,则修改本地图纸文件名
|
|
|
|
|
if (oldDwgFileName != dwgObj.DrawingFileName)
|
|
|
|
|
{
|
|
|
|
|
string folderPath = GlobalObject.GetDwgFileFolder();
|
|
|
|
|
var oldFilePath = Path.Combine(folderPath, oldDwgFileName);
|
|
|
|
|
if (FileHelper.IsFileLocked(oldFilePath))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show($"本地图纸文件:[{oldFilePath}]已被打开,无法重命名,请手动处理!");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var newFilePath = Path.Combine(folderPath, dwgObj.DrawingFileName);
|
|
|
|
|
File.Move(oldFilePath, newFilePath);//本地图纸重命名
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-09-04 18:28:02 +08:00
|
|
|
|
DialogResult res = new DialogResult(ButtonResult.OK);
|
|
|
|
|
RequestClose.Invoke(res);
|
2025-08-15 16:34:31 +08:00
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 过滤.dwg文件
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 过滤.dwg文件,只留下目录
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="nodes">完整的节点</param>
|
|
|
|
|
/// <returns></returns>
|
2025-09-04 18:28:02 +08:00
|
|
|
|
private ObservableCollection<Model.TreeModel> FilterTree(ObservableCollection<Model.TreeModel> nodes, string text)
|
2025-08-15 16:34:31 +08:00
|
|
|
|
{
|
2025-09-04 18:28:02 +08:00
|
|
|
|
ObservableCollection<Model.TreeModel> result = new ObservableCollection<Model.TreeModel>();
|
2025-08-15 16:34:31 +08:00
|
|
|
|
|
|
|
|
|
foreach (var node in nodes.Where(X => !X.Text.Contains("设计说明") && !X.Text.Contains("材料表")))
|
|
|
|
|
{
|
|
|
|
|
// 先检查节点本身是否匹配
|
|
|
|
|
var filteredChildren = FilterTree(node.ChildNodes, text);
|
|
|
|
|
|
|
|
|
|
// 如果节点匹配,或者它有匹配的子节点,添加当前节点到结果
|
|
|
|
|
if (!node.Text.ToUpper().EndsWith(text.ToUpper()))
|
|
|
|
|
{
|
2025-09-04 18:28:02 +08:00
|
|
|
|
result.Add(new Model.TreeModel
|
2025-08-15 16:34:31 +08:00
|
|
|
|
{
|
|
|
|
|
ID = node.ID,
|
|
|
|
|
Text = node.Text,
|
|
|
|
|
ChildNodes = filteredChildren
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 校验图纸文件在目录下是否重名
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 校验图纸文件在目录下是否重名
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="name"></param>
|
|
|
|
|
/// <returns></returns>
|
2025-09-04 18:28:02 +08:00
|
|
|
|
private bool CheckDwgName(Model.TreeModel dwgNode, string name)
|
2025-08-15 16:34:31 +08:00
|
|
|
|
{
|
|
|
|
|
if (tempCatalogueID == null)
|
|
|
|
|
{ return false; }
|
2025-09-04 18:28:02 +08:00
|
|
|
|
Model.TreeModel node = null;
|
2025-08-15 16:34:31 +08:00
|
|
|
|
foreach (var catalogueId in tempCatalogueID)
|
|
|
|
|
{
|
|
|
|
|
//遍历获取当前节点数据
|
2025-09-23 16:38:40 +08:00
|
|
|
|
node = TreeHelper.GetTreeModel(catalogueId, dwgNode.ID);
|
2025-08-15 16:34:31 +08:00
|
|
|
|
if (node != null)
|
|
|
|
|
{ break; }
|
|
|
|
|
}
|
|
|
|
|
var curDwgs = node.ChildNodes.Select(X => X.Text).ToList();
|
|
|
|
|
if (curDwgs.Any(X => X.ToLower() == dwgObj.DrawingFileName.ToLower()))
|
|
|
|
|
{
|
|
|
|
|
//目录节点下有文件重名
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else { return false; }
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|