451 lines
15 KiB
C#
451 lines
15 KiB
C#
using IniParser;
|
|
using Prism.Ioc;
|
|
using SWS.Commons;
|
|
using SWS.Model;
|
|
using SWS.Service;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net.Http;
|
|
using System.Text.RegularExpressions;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Media;
|
|
using Unity;
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;
|
|
|
|
namespace SWS.CAD
|
|
{
|
|
public class GlobalObje
|
|
{
|
|
public static string templateForDrawing = "普通图框";
|
|
public static string editorPre = "DI_Electrical ";
|
|
public static string TemplateFile_Template = "普通图框";
|
|
public enum DBConst
|
|
{
|
|
/// <summary>
|
|
/// 图纸类型
|
|
/// </summary>
|
|
Be_DrawingType,
|
|
/// <summary>
|
|
/// 图纸阶段
|
|
/// </summary>
|
|
Be_DrawingStage,
|
|
/// <summary>
|
|
/// 图纸系统
|
|
/// </summary>
|
|
Be_DrawingSystem,
|
|
/// <summary>
|
|
/// 材料统计
|
|
/// </summary>
|
|
Be_MaterialCensus,
|
|
/// <summary>
|
|
/// 材料范围
|
|
/// </summary>
|
|
Be_MaterialRange
|
|
|
|
}
|
|
|
|
#region 图纸类型
|
|
static List<SWS.Model.ec_dataitemdetail> _dwgType;
|
|
/// <summary>
|
|
/// 初始化图纸类型列表
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static List<SWS.Model.ec_dataitemdetail> DwgType()
|
|
{
|
|
var res0 = new ec_dataitem { DataItemName = "图纸类型", DataItemCode = DBConst.Be_DrawingType.ToString() };
|
|
|
|
if (_dwgType == null)
|
|
{
|
|
var serv = GlobalObject.container.Resolve<DataItemService>();
|
|
var res = Task.Run(() => serv.GetDetails(DBConst.Be_DrawingType.ToString()));
|
|
var res2 = res.Result;
|
|
return res2;
|
|
}
|
|
else
|
|
{
|
|
return _dwgType;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 材料范围
|
|
static List<SWS.Model.ec_dataitemdetail> _dwgMaterialRange;
|
|
/// <summary>
|
|
/// 初始化材料材料范围
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static List<SWS.Model.ec_dataitemdetail> DwgMaterialRange()
|
|
{
|
|
var res0 = new ec_dataitem { DataItemName = "材料范围", DataItemCode = DBConst.Be_MaterialRange.ToString() };
|
|
|
|
if (_dwgMaterialRange == null)
|
|
{
|
|
var serv = GlobalObject.container.Resolve<DataItemService>();
|
|
var res = Task.Run(() => serv.GetDetails(DBConst.Be_MaterialRange.ToString()));
|
|
var res2 = res.Result;
|
|
return res2;
|
|
}
|
|
else
|
|
{
|
|
return _dwgMaterialRange;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 材料统计
|
|
static List<SWS.Model.ec_dataitemdetail> _dwgMaterialCensus;
|
|
/// <summary>
|
|
/// 初始化材料统计列表
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static List<SWS.Model.ec_dataitemdetail> DwgMaterialCensus()
|
|
{
|
|
var res0 = new ec_dataitem { DataItemName = "材料统计", DataItemCode = DBConst.Be_MaterialCensus.ToString() };
|
|
|
|
if (_dwgMaterialCensus == null)
|
|
{
|
|
var serv = GlobalObject.container.Resolve<DataItemService>();
|
|
var res = Task.Run(() => serv.GetDetails(DBConst.Be_MaterialCensus.ToString()));
|
|
var res2 = res.Result;
|
|
return res2;
|
|
}
|
|
else
|
|
{
|
|
return _dwgMaterialCensus;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 图纸阶段
|
|
static List<SWS.Model.ec_dataitemdetail> _dwgStage;
|
|
/// <summary>
|
|
/// 初始化图纸阶段列表
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static List<SWS.Model.ec_dataitemdetail> DwgStage()
|
|
{
|
|
var res0 = new ec_dataitem { DataItemName = "图纸阶段", DataItemCode = DBConst.Be_DrawingStage.ToString() };
|
|
|
|
if (_dwgStage == null)
|
|
{
|
|
var serv =GlobalObject.container.Resolve<DataItemService>();
|
|
var res = Task.Run(() => serv.GetDetails(DBConst.Be_DrawingStage.ToString()));
|
|
var res2 = res.Result;
|
|
return res2;
|
|
}
|
|
else
|
|
{
|
|
return _dwgStage;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 图纸系统
|
|
static ObservableCollection<Model.TreeModel> _dwgSystem;
|
|
/// <summary>
|
|
/// 初始化图纸系统列表
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static ObservableCollection<Model.TreeModel> DwgSystem()
|
|
{
|
|
var res0 = new ec_dataitem { DataItemName = "图纸系统", DataItemCode = DBConst.Be_DrawingSystem.ToString() };
|
|
|
|
if (_dwgSystem == null)
|
|
{
|
|
var serv = GlobalObject.container.Resolve<DataItemService>();
|
|
var res = Task.Run(() => serv.GetDetails(DBConst.Be_DrawingSystem.ToString()));
|
|
var res2 = res.Result;
|
|
var res3 = DataItemDetailsToTree(res2);
|
|
return res3;
|
|
}
|
|
else
|
|
{
|
|
return _dwgSystem;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region DataItemDetail列表转换成树形结果
|
|
/// <summary>
|
|
/// DataItemDetail列表转换成树形结果
|
|
/// </summary>
|
|
/// <param name="listData">列表数据</param>
|
|
/// <param name="isChildres">是否子节点遍历添加</param>
|
|
/// <returns></returns>
|
|
public static ObservableCollection<Model.TreeModel> DataItemDetailsToTree(List<SWS.Model.ec_dataitemdetail> listData, bool isChildres = false)
|
|
{
|
|
ObservableCollection<Model.TreeModel> result = new ObservableCollection<Model.TreeModel>();
|
|
List<SWS.Model.ec_dataitemdetail> list = new List<SWS.Model.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 Model.TreeModel
|
|
{
|
|
ID = data.DataItemDetailID,
|
|
Text = data.DataItemName,
|
|
ChildNodes = childrens
|
|
});
|
|
}
|
|
else
|
|
{
|
|
//没有子节点就添加当前节点Node
|
|
result.Add(new Model.TreeModel
|
|
{
|
|
ID = data.DataItemDetailID,
|
|
Text = data.DataItemName,
|
|
});
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 对象类型树
|
|
/// <summary>
|
|
/// 对象类型树
|
|
/// </summary>
|
|
public static List<Model.TreeModel> objectTypeTree = new List<Model.TreeModel>();
|
|
#endregion
|
|
|
|
#region 设计浏览树
|
|
/// <summary>
|
|
/// 设计浏览树
|
|
/// </summary>
|
|
public static List<Model.TreeModel> designTree = new List<Model.TreeModel>();
|
|
#endregion
|
|
|
|
public enum dialogPar
|
|
{
|
|
id,
|
|
textYes,
|
|
textNo,
|
|
title,
|
|
OK,
|
|
unitTypeId,
|
|
info,
|
|
unit,
|
|
para1,
|
|
para2
|
|
}
|
|
//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 Style TransparentComboBoxStyle;
|
|
public static Style WhiteStyle;
|
|
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))
|
|
{
|
|
string path = Environment.ExpandEnvironmentVariables(@"%USERPROFILE%\AppData\Roaming\SWS\Config.ini");
|
|
FileIniDataParser parser = new FileIniDataParser();
|
|
var data = parser.ReadFile(path);
|
|
_LocalFileDirectory = data["Profile"]["Directory"];
|
|
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>
|
|
/// <typeparam name="T">子控件的类型</typeparam>
|
|
/// <param name="obj">要找的是obj的子控件</param>
|
|
/// <param name="name">想找的子控件的Name属性</param>
|
|
/// <returns>目标子控件</returns>
|
|
public static T GetChildObject<T>(DependencyObject obj, string name) where T : FrameworkElement
|
|
{
|
|
DependencyObject child = null;
|
|
T grandChild = null;
|
|
for (int i = 0; i <= VisualTreeHelper.GetChildrenCount(obj) - 1; i++)
|
|
{
|
|
child = VisualTreeHelper.GetChild(obj, i);
|
|
|
|
if (child is T && (((T)child).Name == name | string.IsNullOrEmpty(name)))
|
|
{
|
|
return (T)child;
|
|
}
|
|
else
|
|
{
|
|
// 在下一级中没有找到指定名字的子控件,就再往下一级找
|
|
grandChild = GetChildObject<T>(child, name);
|
|
if (grandChild != null)
|
|
return grandChild;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
#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
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="resName">包括命名空间</param>
|
|
/// <returns></returns>
|
|
public static System.Windows.Media.ImageSource ImageSourceFromEmbeddedResourceStream(string resName)
|
|
{
|
|
System.Reflection.Assembly assy = System.Reflection.Assembly.GetExecutingAssembly();
|
|
//foreach (string resource in assy.GetManifestResourceNames())
|
|
//{
|
|
// Console.WriteLine(resource);//遍历所有的内嵌资源
|
|
//}
|
|
System.IO.Stream stream = assy.GetManifestResourceStream(resName);
|
|
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} 用户";
|
|
}
|
|
|
|
}
|
|
}
|