using Sunny.UI;
using SuperMap.Data;
using SuperMap.Layout;
using SuperMap.Mapping;
using SuperMap.UI;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using WWPipeLine.Commons;
namespace WWPipeLine.MapBasic
{
public class ComsStatic
{
#region Instance
private static ComsStatic m_Instance;
public static ComsStatic Instance
{
get
{
if (m_Instance == null)
m_Instance = new ComsStatic();
return m_Instance;
}
}
private static Workspace m_Workspace;
public void SetWorkspace(Workspace ws) { m_Workspace = ws; }
private static MapControl m_MapControl;
public void SetMapControl(MapControl mp) { m_MapControl = mp; }
private static DockPanel m_DockPanel;
public void SetDockPanel(DockPanel dp) { m_DockPanel = dp; }
private static Datasource m_MemoryDatasource;
public void SetMemoryDatasource(Datasource ds) { m_MemoryDatasource = ds; }
private static IMessageInterface m_IMessageInterface;
public void SetIMessageInterface(IMessageInterface mi) { m_IMessageInterface = mi; }
public static IMessageInterface MessageInterface { get => m_IMessageInterface; }
#endregion
#region 配置文件信息
public static readonly string ConfigsNpgsql = ComsStatic.DesDecrypt(ConfigurationManager.AppSettings["ConfigsNpgsql"], "wwwwwwwwww");
public static string ConfigsNpgsqlServer { get => ConfigsNpgsql.Split('=')[1].Split(';')[0]; }
public static readonly string MenusPath = ConfigurationManager.AppSettings["MenusPath"];
public static readonly string WorkspaceName = ConfigurationManager.AppSettings["WorkspaceName"];
public static readonly int WorkspaceMapIndex = StringToInt(ConfigurationManager.AppSettings["WorkspaceMapIndex"]);
public static readonly double MapCenterX = StringToDouble(ConfigurationManager.AppSettings["MapCenterX"]);
public static readonly double MapCenterY = StringToDouble(ConfigurationManager.AppSettings["MapCenterY"]);
public static readonly double MapScale = StringToDouble(ConfigurationManager.AppSettings["MapScale"]);
public static readonly int WorkspaceDatasourceIndex = StringToInt(ConfigurationManager.AppSettings["WorkspaceDatasourceIndex"]);
public static readonly string bsURL = ConfigurationManager.AppSettings["bsURL"];
public static readonly string webTool = ConfigurationManager.AppSettings["webTool"];
public static readonly string GISversion = ConfigurationManager.AppSettings["GISversion"];
#endregion
#region 用户信息
//public void SetUserID(int uid) { m_UserID = uid; }
//private static int m_UserID;
//public static int UserID { get => m_UserID; }
//public void SetUserNick(string uNick) { m_UserNick = uNick; }
//private static string m_UserNick;
//public static string UserNick { get => m_UserNick; }
public void SetLoginID(int uid) { m_LoginID = uid; }
private static int m_LoginID;
public static int LoginID { get => m_LoginID; }
#endregion
#region Workspace MapControl DatasetVector
public static Datasource Datasource { get => m_Workspace.Datasources[WorkspaceDatasourceIndex]; }
public static Datasource DatasourceMemory { get => m_MemoryDatasource; }
public static Workspace Workspace { get => m_Workspace; }
public static MapControl MapControl { get => m_MapControl; }
public static DockPanel DockPanel { get => m_DockPanel; }
public static DatasetVector dvConfig { get => Datasource.Datasets["wwconfig"] as DatasetVector; }
public static DatasetVector gsGuanXian { get => Datasource.Datasets[dvGXDatasetName] as DatasetVector; }
public static DatasetVector gsGuanDian { get => Datasource.Datasets["gsGD"] as DatasetVector; }
///
/// B/S端用到的网络数据集名称
///
public static readonly string NetworkDatasetName = "DaAnPostgrsSQL_Network";
///
/// 供水管线的数据集 Name=gsGX
///
public static readonly string dvGXDatasetName = "gsGX";
///
/// 供水管线的图层名称 Caption=供水管线
///
public static readonly string dvGXCaption = "供水管线";
#region 软件打开时 动态加载图层 这种情况需要确定工作空间内只有管线和其他图层,不能包含管点图层
public static List layerExList
{
get
{
//备注:1、节点图层的DatasetName必须带有dv,系统中会通过该字母判断是否选择的是节点图层
List list = new List();
list.Add(new LayerEx { Index = 0, Caption = "供水节点", Dataset = "dvJD", MarkerSymbolID = 14, MarkerSize = 2 });
list.Add(new LayerEx { Index = 0, Caption = "供水阀门", Dataset = "dvFM", MarkerSymbolID = 13, MarkerSize = 3 });
list.Add(new LayerEx { Index = 0, Caption = "消防栓", Dataset = "dvXFS", MarkerSymbolID = 19, MarkerSize = 3 });
list.Add(new LayerEx { Index = 0, Caption = "压力监测点", Dataset = "dvYL", MarkerSymbolID = 20, MarkerSize = 3 });
list.Add(new LayerEx { Index = 0, Caption = "流量监测点", Dataset = "dvLL", MarkerSymbolID = 15, MarkerSize = 3 });
list.Add(new LayerEx { Index = 0, Caption = "水质监测点", Dataset = "dvSZ", MarkerSymbolID = 18, MarkerSize = 3 });
list.Add(new LayerEx { Index = 0, Caption = "水表", Dataset = "dvSB", MarkerSymbolID = 17, MarkerSize = 3 });
list.Add(new LayerEx { Index = 0, Caption = "供水水厂", Dataset = "dvSC", MarkerSymbolID = 21, MarkerSize = 3 });
list.Add(new LayerEx { Index = 0, Caption = "排气阀", Dataset = "dvPQF", MarkerSymbolID = 16, MarkerSize = 3 });
list.Add(new LayerEx { Index = 0, Caption = "调压站", Dataset = "dvJY", MarkerSymbolID = 20, MarkerSize = 3 });
return list;
}
}
public static void SetDatasetVectorAddLayer()
{
DatasetVector dv = null;
LayerSettingVector layerSettingVector;
string[] strField = GetFieldInfos(gsGuanDian);
foreach (LayerEx lyrEx in layerExList.ToArray())
{
if (!Datasource.Datasets.Contains(lyrEx.Dataset))
{
dv = Datasource.Datasets.Create(new DatasetVectorInfo() { Name = lyrEx.Dataset, Type = DatasetType.Point });
bool result = dv.AppendFields(gsGuanDian, "smid", "smuserid", strField);
}
else
{
dv = Datasource.Datasets[lyrEx.Dataset] as DatasetVector;
dv.Truncate();
}
dv.Append(gsGuanDian.Query("FLDM='" + lyrEx.Caption + "'", CursorType.Static));
LayerGroup lg = m_MapControl.Map.Layers.FindLayer("LayerGroup") as LayerGroup;
if (lg == null) continue;
layerSettingVector = new LayerSettingVector();
//默认GeoStyle
//{ FillBackColor=Color [A=255, R=255, G=255, B=255],FillForeColor=Color [A=255, R=189, G=235, B=255],
// FillGradientAngle=0,FillGradientMode=None,FillGradientOffsetRatioX=0,FillGradientOffsetRatioY=0,
// FillOpaqueRate=100,FillSymbolID=0,LineColor=Color [A=255, R=0, G=0, B=0],LineSymbolID=0,LineWidth=1,
// MarkerAngle=0,MarkerSize={Width=2,Height=-0.1},MarkerSymbolID=0}
GeoStyle geoStyle = new GeoStyle();
geoStyle.MarkerSize = new Size2D(lyrEx.MarkerSize, lyrEx.MarkerSize);
geoStyle.LineColor = lyrEx.LineColor;
geoStyle.MarkerSymbolID = lyrEx.MarkerSymbolID;
layerSettingVector.Style = geoStyle;
Layer layer = Layer.CreateLayer(dv, layerSettingVector);
layer.Caption = lyrEx.Caption;
layer.Selection.IsDefaultStyleEnabled = false;
layer.Selection.Style = geoStyle_Selection;
layer.Selection.SetStyleOptions(StyleOptions.MarkerSymbolID, true);
layer.Selection.SetStyleOptions(StyleOptions.LineColor, true);
layer.Selection.SetStyleOptions(StyleOptions.MarkerSize, true);
lg.Insert(0, layer);
}
}
public static bool SetDatasetVector()
{
try
{
DatasetVector dv = null;
string[] strField = GetFieldInfos(gsGuanDian);
foreach (LayerEx lyrEx in layerExList.ToArray())
{
if (!Datasource.Datasets.Contains(lyrEx.Dataset))
{
dv = Datasource.Datasets.Create(new DatasetVectorInfo() { Name = lyrEx.Dataset, Type = DatasetType.Point });
bool result = dv.AppendFields(gsGuanDian, "smid", "smuserid", strField);
}
else
{
dv = Datasource.Datasets[lyrEx.Dataset] as DatasetVector;
dv.Truncate();
}
dv.Append(gsGuanDian.Query("FLDM='" + lyrEx.Caption + "'", CursorType.Static));
}
return true;
}
catch (Exception ex) { LogHelper.Fatal(ex); return false; }
}
public static GeoStyle geoStyle_Selection = new GeoStyle { MarkerSymbolID = 0, LineColor = Color.Red, MarkerSize = new Size2D(4, 4) };
#endregion
public static Layer LayerGuanXian
{
get
{
LayerGroup lg = m_MapControl.Map.Layers.FindLayer("LayerGroup") as LayerGroup;
if (lg.Count == 0) return null;
Layer lyr = null;
foreach (Layer lyrr in lg)
{
if (lyrr.Dataset == gsGuanXian) { lyr = lyrr; break; }
}
return lyr;
}
}
//public static Layers MapLayers { get => m_MapControl.Map.Layers; }
///
/// 管点管线图层
///
public static List MapLayers
{
get
{
List layerList = new List();
LayerGroup lg = m_MapControl.Map.Layers.FindLayer("LayerGroup") as LayerGroup;
if (lg.Count == 0) return null;
foreach (Layer lyrr in lg)
{
if (lyrr.Dataset == null || lyrr.Dataset.Datasource.Alias != Datasource.Alias) continue;
layerList.Add(lyrr);
}
return layerList;
}
}
///
/// 管点管线图层 + 用水单位图层
///
public static List MapLayersUsed
{
get
{
List layerList = MapLayers;
LayerGroup lg = m_MapControl.Map.Layers.FindLayer("LayerGroup#1") as LayerGroup;
if (lg.Count == 0) return layerList;
foreach (Layer lyrr in lg)
{
if (lyrr.Dataset == null || lyrr.Dataset.Datasource.Alias != Datasource.Alias) continue;
if (!",pyunit,".ToLower().Contains(lyrr.Dataset.Name.ToLower())) continue;
layerList.Add(lyrr);
}
return layerList;
}
}
///
/// 当前数据集的所有图层
///
public static List MapLayersAll
{
get
{
List layerList = new List();
foreach (Layer lyr in m_MapControl.Map.Layers)
{
if (lyr.Name.ToLower().Contains("layergroup"))
{
LayerGroup lyrG = lyr as LayerGroup;
foreach (Layer lyrr in lyrG.Layers)
{
if (lyrr.Dataset.Datasource.Alias == Datasource.Alias)
layerList.Add(lyrr);
}
}
else if (lyr.Dataset.Datasource.Alias == Datasource.Alias)
{
layerList.Add(lyr);
}
}
return layerList;
}
}
public static void SetLayersIsSelectableFalse(string layerName, bool isSelect)
{
foreach (Layer r in MapLayers)
{
if (r.Name == layerName || r.Caption == layerName || r.Dataset.Name == layerName)
r.IsSelectable = isSelect;
else
r.IsSelectable = !isSelect;
}
}
public static void SetLayersIsVisibleFalse(string layerName, bool isSelect)
{
foreach (Layer r in MapLayers)
{
if (r.Name == layerName || r.Caption == layerName || r.Dataset.Name == layerName)
r.IsVisible = isSelect;
else
r.IsVisible = !isSelect;
}
}
///
/// 依据TrackingLayer的Name清空
///
///
public static void TrackingLayerRemove(string tag)
{
int index = MapControl.Map.TrackingLayer.IndexOf(tag);
while (index != -1)
{
MapControl.Map.TrackingLayer.Remove(index);
index = MapControl.Map.TrackingLayer.IndexOf(tag);
}
}
public static readonly string ControlToolsTrackingName = "ControlToolAddGeoRegion";
public static void MapControl_Tracked_TrackingName(object sender, SuperMap.UI.TrackedEventArgs e)
{
m_MapControl.Tracked -= MapControl_Tracked_TrackingName;
m_MapControl.Action = SuperMap.UI.Action.Select;
m_MapControl.Action = SuperMap.UI.Action.Pan;
if (e.Geometry is null) { Sunny.UI.UIMessageTip.ShowError("区域绘制失败"); return; }
GeoRegion m_geo = e.Geometry.Clone() as GeoRegion;
if (m_geo is null) { Sunny.UI.UIMessageTip.ShowError("区域绘制失败"); return; }
m_geo.Style = ComsStatic.geoStyle_Red_1mm_OpaqueRate;
m_MapControl.Map.TrackingLayer.Clear();
m_MapControl.Map.TrackingLayer.Add(m_geo, ComsStatic.ControlToolsTrackingName);
m_MapControl.Map.RefreshTrackingLayer();
}
///
/// 关闭当前主程序中除了Tag=MainControls的其他所有窗体
/// 默认4个主要窗体: 主窗体 工具栏 鹰眼 图层
///
public static void closeFormTagMainControls()
{
try
{
foreach (Form form in Application.OpenForms)
{
if (form.Tag?.ToString() != "MainControls" && form.Text?.ToString() != "工具栏")
{
form.Close(); break;
}
}
if (Application.OpenForms.Count > 6)
{
closeFormTagMainControls();
}
}
catch (Exception ex)
{
ComsStatic.ShowErrorLog(ex);
}
}
#endregion
#region SuperMap.Data相关操作
public static readonly string[] resultFieldsGX = new string[] { "fldm", "cz", "gj", "cd", "yl", "msfs", "dzms", "qsdw", "tcdw" };
public static readonly string[] resultFieldsGD = new string[] { "fldm", "fsw", "xh", "gg", "cz", "kj", "gj", "yl", "dmgc", "ms", "msfs", "dzms", "qsdw", "tcdw" };
public static Recordset QueryRecordset(DatasetVector dv, string sqlWhere, string[] resultFields = null, string[] groupBy = null, string[] orderBy = null)
{
QueryParameter para = new QueryParameter();
if (sqlWhere != null) para.AttributeFilter = sqlWhere;
if (resultFields != null) para.ResultFields = Commons.StringEx.setToLower(resultFields);
if (groupBy != null) para.GroupBy = Commons.StringEx.setToLower(groupBy);
if (orderBy != null) para.OrderBy = Commons.StringEx.setToLower(orderBy);
para.CursorType = CursorType.Static;
return dv.Query(para);
}
public static Recordset QueryRecordsetDynamic(DatasetVector dv, string sqlWhere, string[] resultFields = null, string[] groupBy = null, string[] orderBy = null)
{
QueryParameter para = new QueryParameter();
if (sqlWhere != null) para.AttributeFilter = sqlWhere;
if (resultFields != null) para.ResultFields = Commons.StringEx.setToLower(resultFields);
if (groupBy != null) para.GroupBy = Commons.StringEx.setToLower(groupBy);
if (orderBy != null) para.OrderBy = Commons.StringEx.setToLower(orderBy);
para.CursorType = CursorType.Dynamic;
return dv.Query(para);
}
public static DataTable QueryDataTable(DatasetVector dv, string sqlWhere, string[] resultFields = null, string[] groupBy = null, string[] orderBy = null)
{
QueryParameter para = new QueryParameter();
if (sqlWhere != null) para.AttributeFilter = sqlWhere;
if (resultFields != null) para.ResultFields = Commons.StringEx.setToLower(resultFields);
if (groupBy != null) para.GroupBy = Commons.StringEx.setToLower(groupBy);
if (orderBy != null) para.OrderBy = Commons.StringEx.setToLower(orderBy);
para.CursorType = CursorType.Static;
return RecordsetToDataTable(dv.Query(para), true, dv.Name);
}
public static List