using Sunny.UI;
using SuperMap.Data;
using SuperMap.Layout;
using SuperMap.Mapping;
using SuperMap.UI;
using System;
using System.Collections.Generic;
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 void SetUserID(int uid) { m_UserID = uid; }
private static int m_UserID;
public static int UserID { get => m_UserID; }
public void SetUserName(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 Int32 WorkspaceMapIndex
{
get
{
string index = IniHelper.Read(IniHelper.KEY_WorkspaceMapIndex_PATH);
return StringToInt(index);
}
}
private static Int32 WorkspaceDatasourceIndex
{
get
{
string index = IniHelper.Read(IniHelper.KEY_WorkspaceDatasourceIndex_PATH);
return StringToInt(index);
}
}
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; }
public static readonly string dvGXDatasetName = "gsGX";
public static readonly string dvGXCaption = "供水管线";
public static readonly string dvJDDatasetName = "dvJD";
public static readonly string dvJDCaption = "供水节点";
public static void SetDatasetVector()
{
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(2.4, 2.4);
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.MarkerSize, true);
lg.Insert(0, layer);
}
}
public static GeoStyle geoStyle_Selection = new GeoStyle { LineColor = Color.Blue, MarkerSize = new Size2D(4, 4) };
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 List layerExList
{
get
{
//备注:1、节点图层的DatasetName必须带有dv,系统中会通过该字母判断是否选择的是节点图层
List list = new List();
list.Add(new LayerEx { Index = 0, Caption = dvJDCaption, Dataset = dvJDDatasetName, MarkerSymbolID = 0, LineColor = Color.Brown });
list.Add(new LayerEx { Index = 0, Caption = "供水阀门", Dataset = "dvFM", MarkerSymbolID = 16 });
list.Add(new LayerEx { Index = 0, Caption = "消防栓", Dataset = "dvXFS", MarkerSymbolID = 20 });
list.Add(new LayerEx { Index = 0, Caption = "压力监测点", Dataset = "dvYL", MarkerSymbolID = 14 });
list.Add(new LayerEx { Index = 0, Caption = "流量监测点", Dataset = "dvLL", MarkerSymbolID = 13 });
list.Add(new LayerEx { Index = 0, Caption = "水质监测点", Dataset = "dvSZ", MarkerSymbolID = 19 });
list.Add(new LayerEx { Index = 0, Caption = "水表", Dataset = "dvSB", MarkerSymbolID = 18 });
list.Add(new LayerEx { Index = 0, Caption = "供水水厂", Dataset = "dvSC", MarkerSymbolID = 21 });
list.Add(new LayerEx { Index = 0, Caption = "排气阀", Dataset = "dvPQF", MarkerSymbolID = 17 });
list.Add(new LayerEx { Index = 0, Caption = "加压站", Dataset = "dvJY", MarkerSymbolID = 15 });
return list;
}
}
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