224 lines
8.2 KiB
C#
224 lines
8.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Windows.Forms;
|
|
using System.Windows.Input;
|
|
using Prism.Services.Dialogs;
|
|
using SWS.CAD.Base;
|
|
using SWS.Commons;
|
|
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 DialogTest2ViewModel : DialogBase, IDialogAware
|
|
{
|
|
private string _dwgID = "82cbfe10-2368-4d4d-9045-bd3f1bbfb614";
|
|
/// <summary>
|
|
/// 图纸Id
|
|
/// </summary>
|
|
public string dwgID
|
|
{
|
|
get { return _dwgID; }
|
|
set { _dwgID = value; OnPropertyChanged(nameof(dwgID)); }
|
|
}
|
|
private string _blockDwg = "D:\\Temp\\3\\opc_上右.dwg";
|
|
/// <summary>
|
|
/// 图纸块
|
|
/// </summary>
|
|
public string blockDwg
|
|
{
|
|
get { return _blockDwg; }
|
|
set { _blockDwg = value; OnPropertyChanged(nameof(blockDwg)); }
|
|
}
|
|
private string _tagNumber = "AAA";
|
|
/// <summary>
|
|
/// 位号
|
|
/// </summary>
|
|
public string tagNumber
|
|
{
|
|
get { return _tagNumber; }
|
|
set { _tagNumber = value; OnPropertyChanged(nameof(tagNumber)); }
|
|
}
|
|
|
|
private Visibility _isShow = Visibility.Visible;
|
|
/// <summary>
|
|
/// 是否显示
|
|
/// </summary>
|
|
public Visibility isShow
|
|
{
|
|
get { return _isShow; }
|
|
set { _isShow = value; OnPropertyChanged(nameof(isShow)); }
|
|
}
|
|
/// <summary>
|
|
/// 命令事件
|
|
/// </summary>
|
|
public ICommand Command_OpenFile { get; set; }
|
|
/// <summary>
|
|
/// 命令事件
|
|
/// </summary>
|
|
public ICommand Command_OpenDwg { get; set; }
|
|
/// <summary>
|
|
/// 命令事件
|
|
/// </summary>
|
|
public ICommand Command_AddBlock { get; set; }
|
|
|
|
DrawingServce _ServiceDrawing;
|
|
DrawingCatalogueService _ServiceDrawingCatalogue;
|
|
ObjectTypeService _ServiceObjectType;
|
|
LibraryFileService _ServiceLibraryFile;
|
|
public DialogTest2ViewModel()
|
|
{
|
|
Command_OpenDwg = new DelegateCommand(onOpenDwg);
|
|
Command_OpenFile = new DelegateCommand(onOpenFile);
|
|
Command_AddBlock = new DelegateCommand(onAddBlock);
|
|
title = "绘图测试页面";
|
|
_ServiceDrawing = GlobalObject.container.Resolve<DrawingServce>();
|
|
_ServiceDrawingCatalogue = GlobalObject.container.Resolve<DrawingCatalogueService>();
|
|
_ServiceObjectType = GlobalObject.container.Resolve<ObjectTypeService>();
|
|
_ServiceLibraryFile = GlobalObject.container.Resolve<LibraryFileService>();
|
|
}
|
|
|
|
public string Title => "";
|
|
|
|
public event Action<IDialogResult> RequestClose;
|
|
|
|
public bool CanCloseDialog()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public void OnDialogClosed()
|
|
{
|
|
|
|
}
|
|
|
|
public void OnDialogOpened(IDialogParameters parameters)
|
|
{
|
|
|
|
}
|
|
string fullpath = string.Empty;//图纸文件完整路径
|
|
public async void onOpenDwg(object o)
|
|
{
|
|
if (string.IsNullOrEmpty(dwgID))
|
|
{
|
|
MessageBox.Show("请输入图纸ID");
|
|
return;
|
|
}
|
|
|
|
string dwgName = General.GetDwgName();
|
|
var dwgObj = await _ServiceDrawing.GetDrawingFile(dwgID);
|
|
var cate = await _ServiceDrawingCatalogue.GetEntity(dwgObj.DrawingCatalogueID);
|
|
if (cate.FullPath != cate.DrawingCatalogueID)
|
|
{
|
|
foreach (var id in cate.FullPath.Split(',').ToList())
|
|
{
|
|
cate = await _ServiceDrawingCatalogue.GetEntity(id);
|
|
fullpath += $"{cate.DrawingCatalogueName}\\";
|
|
}
|
|
}
|
|
else { fullpath = $"{cate.DrawingCatalogueName}\\"; }
|
|
fullpath += dwgObj.DrawingFileName;
|
|
fullpath = Path.Combine(GlobalObj.LocalWorkDir, GlobalObject.curProject.ProjectName, fullpath);
|
|
var listName = General.GetAllOpenDrawingNames();
|
|
if (!listName.Contains(fullpath))
|
|
{
|
|
General.OpenDwg(fullpath);
|
|
}
|
|
else { General.SwitchToDocument(fullpath); }
|
|
}
|
|
public void onOpenFile(object o)
|
|
{
|
|
OpenFileDialog dialog = new OpenFileDialog();
|
|
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.Yes)
|
|
{
|
|
blockDwg = dialog.FileName;
|
|
}
|
|
blockDwg = dialog.FileName;
|
|
}
|
|
string objTypeId = "1410523e-d594-4527-9f04-130bb89c1cf0";
|
|
string objTypeName = "OPC";
|
|
public async void onAddBlock(object o)
|
|
{
|
|
try
|
|
{
|
|
string tagNum = string.Empty;
|
|
isShow = Visibility.Hidden;
|
|
var objId = General.InsertExternalDWG(blockDwg, tagNumber, ref tagNum);
|
|
#region 图纸上保存图元属性
|
|
if (!objId.IsNull)
|
|
{
|
|
isShow = Visibility.Hidden;
|
|
var dwgLibrary = await _ServiceLibraryFile.GetEntity("80052993-fb30-41f0-98f2-95f5b6647b72");
|
|
List<ec_enginedata_property> listPro = new List<ec_enginedata_property>();
|
|
var handlid = objId.Handle.ToString();//添加图元返回的句柄
|
|
ec_enginedata item = new ec_enginedata();
|
|
item.TagNumber = tagNum;
|
|
item.ObjectTypeID = objTypeId;
|
|
item.Layout_Block_File = dwgLibrary;
|
|
var res = await _ServiceObjectType.GetObjectTypePById(objTypeId);//添加属性
|
|
if (res.Any())
|
|
{
|
|
foreach (var dto in res)
|
|
{
|
|
listPro.Add(new ec_enginedata_property()
|
|
{
|
|
EngineDataPropertyID = dto.PropertyID,
|
|
PropertyName = dto.PropertyName,
|
|
PropertyNameEN = dto.PropertyNameEN,
|
|
PropertyValue = dto.DefaultValue,
|
|
MeasuringUnit = dto.MeasuringUnitTypeName,
|
|
PropertyGID = dto.PropertyGID,
|
|
PropertyGroupName = dto.PropertyGroupName
|
|
});
|
|
}
|
|
}
|
|
item.EngineDataProperty = listPro;
|
|
List<ec_enginedata_pixel> listPixel = new List<ec_enginedata_pixel>();
|
|
var pixelDto = new ec_enginedata_pixel()
|
|
{
|
|
TagNumber = tagNum,
|
|
DrawingFileID = dwgID,
|
|
LibraryFileID = dwgLibrary.LibraryFileID,
|
|
PixelCode = handlid,
|
|
ObjectTypeID = objTypeId,
|
|
ObjectTypeName = objTypeName,
|
|
EngineDataProperty = listPro
|
|
};
|
|
listPixel.Add(pixelDto);
|
|
item.EngineDataPixel = listPixel;
|
|
string msg = string.Empty;
|
|
msg = await _ServiceObjectType.UpdatePixelAndProp(item);
|
|
if (msg != string.Empty)
|
|
{
|
|
MessageBox.Show("保存图元属性至图纸异常:" + msg);
|
|
isShow = Visibility.Visible;
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("添加图块成功!");
|
|
isShow = Visibility.Visible;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("添加失败");
|
|
isShow = Visibility.Visible;
|
|
}
|
|
#endregion
|
|
}
|
|
catch (System.Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message);
|
|
isShow = Visibility.Visible;
|
|
}
|
|
}
|
|
}
|
|
}
|