2025-08-15 15:33:20 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net.Http;
|
2025-09-04 18:28:02 +08:00
|
|
|
|
using System.Runtime.CompilerServices;
|
2025-08-15 15:33:20 +08:00
|
|
|
|
using System.Text.RegularExpressions;
|
2025-09-04 18:28:02 +08:00
|
|
|
|
using System.Threading.Tasks;
|
2025-08-15 15:33:20 +08:00
|
|
|
|
using IniParser;
|
|
|
|
|
using Prism.DryIoc;
|
|
|
|
|
using Prism.Ioc;
|
|
|
|
|
using SWS.Model;
|
|
|
|
|
using Unity;
|
|
|
|
|
|
|
|
|
|
namespace SWS.Commons
|
|
|
|
|
{
|
|
|
|
|
public class GlobalObject
|
|
|
|
|
{
|
|
|
|
|
public static string templateForDrawing = "普通图框";
|
|
|
|
|
public static string editorPre = "DI_Electrical ";
|
|
|
|
|
public static string TemplateFile_Template = "普通图框";
|
|
|
|
|
public static string configPath = Environment.ExpandEnvironmentVariables(@"%USERPROFILE%\AppData\Roaming\BricsCAD Electrical\Config\AppConfig.ini");
|
|
|
|
|
|
|
|
|
|
#region DataItemDetail列表转换成树形结果
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// DataItemDetail列表转换成树形结果
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="listData">列表数据</param>
|
|
|
|
|
/// <param name="isChildres">是否子节点遍历添加</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static ObservableCollection<TreeModel> DataItemDetailsToTree(List<ec_dataitemdetail> listData, bool isChildres = false)
|
|
|
|
|
{
|
|
|
|
|
ObservableCollection<TreeModel> result = new ObservableCollection<TreeModel>();
|
|
|
|
|
List<ec_dataitemdetail> list = new List<ec_dataitemdetail>();
|
|
|
|
|
if (isChildres)
|
|
|
|
|
{ list = listData; }
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//取所有第一级树
|
|
|
|
|
list = listData.Where(a => a.UpDataItemDetailID == "0").ToList();
|
|
|
|
|
}
|
|
|
|
|
foreach (var data in list)
|
|
|
|
|
{
|
|
|
|
|
//获取当前节点的所有子节点
|
|
|
|
|
var details = listData.Where(a => a.UpDataItemDetailID == data.DataItemDetailID).ToList();
|
|
|
|
|
if (details.Any())
|
|
|
|
|
{
|
|
|
|
|
//获取子节点
|
|
|
|
|
var childrens = DataItemDetailsToTree(details, true);
|
|
|
|
|
result.Add(new TreeModel
|
|
|
|
|
{
|
|
|
|
|
ID = data.DataItemDetailID,
|
|
|
|
|
Text = data.DataItemName,
|
|
|
|
|
ChildNodes = childrens
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//没有子节点就添加当前节点Node
|
|
|
|
|
result.Add(new TreeModel
|
|
|
|
|
{
|
|
|
|
|
ID = data.DataItemDetailID,
|
|
|
|
|
Text = data.DataItemName,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 对象类型树
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 对象类型树
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static List<TreeModel> objectTypeTree = new List<TreeModel>();
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 设计浏览树
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 设计浏览树
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static List<TreeModel> designTree = new List<TreeModel>();
|
|
|
|
|
#endregion
|
|
|
|
|
|
2025-09-04 18:28:02 +08:00
|
|
|
|
public enum DBConst
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 图纸类型
|
|
|
|
|
/// </summary>
|
|
|
|
|
Be_DrawingType,
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 图纸阶段
|
|
|
|
|
/// </summary>
|
|
|
|
|
Be_DrawingStage,
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 图纸系统
|
|
|
|
|
/// </summary>
|
|
|
|
|
Be_DrawingSystem,
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 材料统计
|
|
|
|
|
/// </summary>
|
|
|
|
|
Be_MaterialCensus,
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 材料范围
|
|
|
|
|
/// </summary>
|
|
|
|
|
Be_MaterialRange
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-15 15:33:20 +08:00
|
|
|
|
public enum dialogPar
|
|
|
|
|
{
|
|
|
|
|
id,
|
|
|
|
|
textYes,
|
|
|
|
|
textNo,
|
|
|
|
|
title,
|
|
|
|
|
OK,
|
|
|
|
|
unitTypeId,
|
|
|
|
|
info,
|
|
|
|
|
unit,
|
|
|
|
|
para1,
|
|
|
|
|
para2
|
|
|
|
|
}
|
|
|
|
|
public static IContainerRegistry containerRegistry ;
|
|
|
|
|
public static IUnityContainer container;
|
|
|
|
|
public static IContainerExtension _prismContainer ;
|
|
|
|
|
public static HttpClient client;
|
|
|
|
|
public static loginRes userInfo;
|
|
|
|
|
public static List<User> Users;
|
|
|
|
|
|
|
|
|
|
public static bool isConfigIniCreateBySys = true;
|
|
|
|
|
//public static string drawingFileId;
|
|
|
|
|
public static ec_project curProject;
|
|
|
|
|
public static DateTime preClickTime = DateTime.Now;
|
|
|
|
|
public static Unit UnitSelected;
|
|
|
|
|
public static List<ec_measuring_unit> Units;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 打开的图纸名列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static List<DrawingOpened> ListDwgOpened = new List<DrawingOpened>();
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 图纸树上的所有图纸名
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static List<string> AllDwgName = new List<string>();
|
|
|
|
|
public static string currentTagNumber;
|
|
|
|
|
#region 本地文件目录
|
|
|
|
|
static string _LocalFileDirectory;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取本地目录文件夹
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static string GetLocalFileDirectory()
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(_LocalFileDirectory))
|
|
|
|
|
{
|
2025-09-09 08:58:50 +08:00
|
|
|
|
string path = configPath;
|
2025-08-15 15:33:20 +08:00
|
|
|
|
FileIniDataParser parser = new FileIniDataParser();
|
|
|
|
|
var data = parser.ReadFile(path);
|
2025-09-09 08:58:50 +08:00
|
|
|
|
_LocalFileDirectory = data["Profile"]["strLocalWorkDir"];
|
2025-08-15 15:33:20 +08:00
|
|
|
|
return _LocalFileDirectory;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{ return _LocalFileDirectory; }
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 设置本地目录文件夹
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="dir">文件夹目录</param>
|
|
|
|
|
public static void SetLocalFileDirectory(string dir)
|
|
|
|
|
{ _LocalFileDirectory = dir; }
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 图纸文件所在文件夹
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 图纸文件所在文件夹
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static string GetDwgFileFolder()
|
|
|
|
|
{
|
|
|
|
|
string path = Path.Combine(GetLocalFileDirectory(), curProject.ProjectIndex.ToString());
|
|
|
|
|
if (!Directory.Exists(path))
|
|
|
|
|
Directory.CreateDirectory(path);
|
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 图纸文件备份文件夹
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 图纸文件备份文件夹
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static string GetBackupDwgFileFolder()
|
|
|
|
|
{
|
|
|
|
|
string path = Path.Combine(GetDwgFileFolder(), "Backup");
|
|
|
|
|
if (!Directory.Exists(path))
|
|
|
|
|
Directory.CreateDirectory(path);
|
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 根据ID获取用户名称
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据ID获取用户名称
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static string GetUserNameById(string id)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(id))
|
|
|
|
|
{ return ""; }
|
|
|
|
|
var user = Users.FirstOrDefault(a => a.F_UserId == id || a.F_Account == id);
|
|
|
|
|
if (user != null)
|
|
|
|
|
{ return user.F_RealName; }
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return "";
|
|
|
|
|
//user = GlobalObject.Users.FirstOrDefault(a => a.F_Account == id);
|
|
|
|
|
//return user != null ? user.F_RealName : "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 判断是否是电缆
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 判断是否是电缆
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static bool IsCable(ec_objecttype obj)
|
|
|
|
|
{
|
|
|
|
|
if (obj == null) { return false; }
|
|
|
|
|
var flag = obj.ObjectTypeName.EndsWith("电缆");
|
|
|
|
|
return flag;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 取字符串最后的一个或多个数字
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 取字符串最后的一个或多个数字
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input">输入字符串</param>
|
|
|
|
|
/// <param name="preInput">数字前的字符串</param>
|
|
|
|
|
/// <param name="num">最后的数字</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static bool GetLastNumber(string input, ref string preInput, ref int num)
|
|
|
|
|
{
|
|
|
|
|
string pattern = @"(\d+)$"; // 正则表达式,匹配字符串末尾的一个或多个数字
|
|
|
|
|
Match match = Regex.Match(input, pattern);
|
|
|
|
|
if (match.Success)
|
|
|
|
|
{
|
|
|
|
|
preInput = input.Substring(0, input.Length - match.Value.Length);
|
|
|
|
|
num = int.Parse(match.Value);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
2025-09-02 11:21:40 +08:00
|
|
|
|
#region 系统缓存文件夹
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 系统缓存文件夹
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static string GetCacheFolder()
|
|
|
|
|
{
|
|
|
|
|
string path = Path.Combine(GetLocalFileDirectory(), "Temp");
|
|
|
|
|
if (!Directory.Exists(path))
|
|
|
|
|
Directory.CreateDirectory(path);
|
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
2025-08-15 15:33:20 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="resName">包括命名空间</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static System.Windows.Media.ImageSource ImageSourceFromEmbeddedResourceStream(string resName)
|
|
|
|
|
{
|
|
|
|
|
string imgPath = $"SWS.Commons.Images.{resName}";
|
|
|
|
|
System.Reflection.Assembly assy = System.Reflection.Assembly.GetExecutingAssembly();
|
|
|
|
|
//foreach (string resource in assy.GetManifestResourceNames())
|
|
|
|
|
//{
|
|
|
|
|
// Console.WriteLine(resource);//遍历所有的内嵌资源
|
|
|
|
|
//}
|
|
|
|
|
System.IO.Stream stream = assy.GetManifestResourceStream(imgPath);
|
|
|
|
|
if (stream == null)
|
|
|
|
|
return null;
|
|
|
|
|
System.Windows.Media.Imaging.BitmapImage img = new System.Windows.Media.Imaging.BitmapImage();
|
|
|
|
|
img.BeginInit();
|
|
|
|
|
img.StreamSource = stream;
|
|
|
|
|
img.EndInit();
|
|
|
|
|
return img;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string GetPCInfo()
|
|
|
|
|
{
|
|
|
|
|
string computerName = Environment.MachineName; // 获取计算机名称
|
|
|
|
|
string userName = Environment.UserName; // 获取当前用户名称
|
|
|
|
|
|
|
|
|
|
return $"{computerName} 计算机{userName} 用户";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|