12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238 |
- 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; }
- /// <summary>
- /// 管点管线图层
- /// </summary>
- public static List<Layer> MapLayers
- {
- get
- {
- List<Layer> layerList = new List<Layer>();
- 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;
- }
- }
- /// <summary>
- /// 管点管线图层 + 用水单位图层
- /// </summary>
- public static List<Layer> MapLayersUsed
- {
- get
- {
- List<Layer> 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;
- }
- }
- /// <summary>
- /// 当前数据集的所有图层
- /// </summary>
- public static List<Layer> MapLayersAll
- {
- get
- {
- List<Layer> layerList = new List<Layer>();
- 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<LayerEx> layerExList
- {
- get
- {
- //备注:1、节点图层的DatasetName必须带有dv,系统中会通过该字母判断是否选择的是节点图层
- List<LayerEx> list = new List<LayerEx>();
- 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;
- }
- }
- /// <summary>
- /// 依据TrackingLayer的Name清空
- /// </summary>
- /// <param name="tag"></param>
- 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();
- }
- /// <summary>
- /// 关闭当前主程序中除了Tag=MainControls的其他所有窗体
- /// <para>默认4个主要窗体: 主窗体 工具栏 鹰眼 图层</para>
- /// </summary>
- 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<object> QueryFieldsValueList(DatasetVector dv, string sqlWhere, string resultFields, string[] groupBy = null, string[] orderBy = null)
- {
- Recordset rd = QueryRecordset(dv, sqlWhere, new string[] { resultFields }, groupBy, orderBy);
- List<object> result = new List<object>();
- rd.MoveFirst();
- if (!rd.IsEOF)
- {
- result.Add(rd.GetFieldValue(resultFields));
- rd.MoveNext();
- }
- return result;
- }
- public static DataTable RecordsetToDataTable(Recordset recordset, bool isDispose = true, string tableName = null)
- {
- if (string.IsNullOrEmpty(tableName)) tableName = recordset.Dataset.Name;
- DataTable dt = new DataTable { TableName = tableName };
- foreach (FieldInfo info in recordset.GetFieldInfos())
- {
- dt.Columns.Add(new DataColumn { ColumnName = info.Name, Caption = info.Caption });
- }
- DataRow dr;
- recordset.MoveFirst();
- while (!recordset.IsEOF)
- {
- dr = dt.NewRow();
- foreach (DataColumn dc in dt.Columns)
- {
- dr[dc] = recordset.GetFieldValue(dc.ColumnName)?.ToString();
- }
- dt.Rows.Add(dr);
- recordset.MoveNext();
- }
- if (isDispose) RecordsetDispose(recordset);
- return dt;
- }
- //public static DataTable RecordsetToDataTable(Recordset recordset, bool isDispose = true, string tableName = null)
- //{
- // if (string.IsNullOrEmpty(tableName)) tableName = recordset.Dataset.Name;
- // DataTable dt = new DataTable { TableName = tableName };
- // FieldInfos fieldInfos = recordset.GetFieldInfos();
- // Int32 count = fieldInfos.Count;
- // DataColumn dataColumn;
- // for (Int32 i = 0; i < count; i++)
- // {
- // dataColumn = new DataColumn { ColumnName = fieldInfos[i].Name, Caption = fieldInfos[i].Caption };
- // dt.Columns.Add(dataColumn);
- // }
- // recordset.MoveFirst();
- // Int32 length = recordset.RecordCount;
- // DataRow dr;
- // for (int i = 0; i < length; i++)
- // {
- // dr = dt.NewRow();
- // var actIndex = 0;
- // for (Int32 j = 0; j < count; j++)
- // {
- // var objValue = recordset.GetFieldValue(j);
- // string value = objValue?.ToString();
- // dr[actIndex++] = value;
- // }
- // dt.Rows.Add(dr);
- // recordset.MoveNext();
- // }
- // if (isDispose) RecordsetDispose(recordset);
- // return dt;
- //}
- public static List<DataTable> TongJiFieldGroupCount(DatasetVector dv, string[] strField)
- {
- Recordset rd = null;
- List<DataTable> dts = new List<DataTable>();
- DataTable dt;
- DataRow dr;
- string fieldValue = string.Empty;
- foreach (string field in strField)
- {
- string[] ck = new string[] { field };
- rd = ComsStatic.QueryRecordset(dv, null, ck, ck, ck);
- dt = new DataTable(); dt.Columns.Add("类别"); dt.Columns.Add("数量");
- if (!HasField(dv, field)) continue;
- dt.TableName = rd.GetFieldInfos()[field].Caption;
- if (rd.RecordCount == 0)//该字段所有值均为null 不能GroupBy
- {
- dr = dt.NewRow();
- dr["类别"] = "未知"; dr["数量"] = dv.RecordCount;
- dt.Rows.Add(dr);
- }
- else
- {
- rd.MoveFirst();
- while (!rd.IsEOF)
- {
- dr = dt.NewRow();
- fieldValue = rd.GetFieldValue(field)?.ToString();
- if (string.IsNullOrEmpty(fieldValue))
- {
- dr["类别"] = "未知";
- dr["数量"] = dv.Query(string.Format("{0} is null", field), CursorType.Static).RecordCount;
- }
- else
- {
- dr["类别"] = fieldValue;
- dr["数量"] = dv.Query(string.Format("{0}='{1}'", field, fieldValue), CursorType.Static).RecordCount;
- }
- dt.Rows.Add(dr);
- rd.MoveNext();
- }
- }
- dr = dt.NewRow();
- dr["类别"] = dt.TableName + "总量"; dr["数量"] = dv.RecordCount;
- dt.Rows.Add(dr);
- dts.Add(dt);
- }
- ComsStatic.RecordsetDispose(rd);
- return dts;
- }
- public static string getSqlCheckListBox(Dictionary<string, CheckedListBox> dic)
- {
- StringBuilder sb = new StringBuilder(" 1=1 ");
- foreach (string key in dic.Keys)
- {
- if (dic[key].CheckedItems.Count > 0)
- {
- sb.Append(" AND (1=2 ");
- foreach (string clbItem in dic[key].CheckedItems)
- {
- if (clbItem == "未知")
- sb.AppendFormat(" OR {0} is null ", key);
- else
- sb.AppendFormat(" OR {0}='{1}' ", key, clbItem);
- }
- sb.Append(" ) ");
- }
- }
- return sb.ToString();
- }
- /// <summary>
- /// 获取DatasetVector的FieldInfos数组 不包含系统字段
- /// </summary>
- /// <param name="dv"></param>
- /// <returns></returns>
- public static string[] GetFieldInfos(DatasetVector dv)
- {
- List<string> listStr = new List<string>();
- foreach (FieldInfo f in dv.FieldInfos)
- {
- if (f.IsSystemField || f.Name.ToLower() == "smuserid") continue;
- listStr.Add(f.Name);
- }
- return listStr.ToArray();
- }
- public static bool HasField(DatasetVector m_DatasetVector, string _field)
- {
- bool hasField = false;
- FieldInfos fieldInfos = m_DatasetVector.FieldInfos;
- for (int i = 0; i < fieldInfos.Count; i++)
- {
- if (fieldInfos[i].Name.ToLower() == _field.ToLower())
- {
- hasField = true; break;
- }
- }
- return hasField;
- }
- public static bool HasField(Recordset m_Recordset, string _field)
- {
- bool hasField = false;
- FieldInfos fieldInfos = m_Recordset.GetFieldInfos();
- for (int i = 0; i < fieldInfos.Count; i++)
- {
- if (fieldInfos[i].Name.ToLower() == _field.ToLower())
- {
- hasField = true; break;
- }
- }
- return hasField;
- }
- public static void RecordsetDispose(Recordset rd)
- {
- if (rd != null) { rd.Close(); rd.Dispose(); }
- }
- public static void EditHistoryUndo(EditHistory eh)
- {
- while (eh.CanUndo) { eh.Undo(); }
- eh.Clear(); eh.Dispose();
- }
- public static DataTable GetJSLKbyJSJDPT(DataTable dt)
- {
- #region 构造 管线的起始管点和终点管点 信息
- dt.Columns.Add(new DataColumn { ColumnName = "qdsmid", Caption = "起点SmID" });
- dt.Columns.Add(new DataColumn { ColumnName = "qdsmx", Caption = "起点X坐标" });
- dt.Columns.Add(new DataColumn { ColumnName = "qdsmy", Caption = "起点Y坐标" });
- dt.Columns.Add(new DataColumn { ColumnName = "qddmgc", Caption = "起点地面高程" });
- dt.Columns.Add(new DataColumn { ColumnName = "qdgdms", Caption = "起点埋深" });
- dt.Columns.Add(new DataColumn { ColumnName = "qdgc", Caption = "起点高程" });
- dt.Columns.Add(new DataColumn { ColumnName = "zdsmid", Caption = "终点SmID" });
- dt.Columns.Add(new DataColumn { ColumnName = "zdsmx", Caption = "终点X坐标" });
- dt.Columns.Add(new DataColumn { ColumnName = "zdsmy", Caption = "终点Y坐标" });
- dt.Columns.Add(new DataColumn { ColumnName = "zddmgc", Caption = "终点地面高程" });
- dt.Columns.Add(new DataColumn { ColumnName = "zdgdms", Caption = "终点埋深" });
- dt.Columns.Add(new DataColumn { ColumnName = "zdgc", Caption = "终点高程" });
- #endregion
- DataTable dtJSJDPT;
- foreach (DataRow dr in dt.Rows)
- {
- dtJSJDPT = QueryDataTable(gsGuanDian, string.Format(" bsm='{0}' ", dr["qsdh"]));
- if (dtJSJDPT.Rows.Count == 1)
- {
- dr["qdsmid"] = dtJSJDPT.Rows[0]["smid"]; dr["qdsmx"] = dtJSJDPT.Rows[0]["x"]; dr["qdsmy"] = dtJSJDPT.Rows[0]["y"];
- dr["qddmgc"] = dtJSJDPT.Rows[0]["dmgc"]; dr["qdgdms"] = dtJSJDPT.Rows[0]["ms"];
- dr["qdgc"] = StringToDouble(dtJSJDPT.Rows[0]["dmgc"], 2) - StringToDouble(dtJSJDPT.Rows[0]["ms"], 2);
- }
- dtJSJDPT = QueryDataTable(gsGuanDian, string.Format(" bsm='{0}' ", dr["zddh"]));
- if (dtJSJDPT.Rows.Count == 1)
- {
- dr["zdsmid"] = dtJSJDPT.Rows[0]["smid"]; dr["zdsmx"] = dtJSJDPT.Rows[0]["x"]; dr["zdsmy"] = dtJSJDPT.Rows[0]["y"];
- dr["zddmgc"] = dtJSJDPT.Rows[0]["dmgc"]; dr["zdgdms"] = dtJSJDPT.Rows[0]["ms"];
- dr["zdgc"] = StringToDouble(dtJSJDPT.Rows[0]["dmgc"], 2) - StringToDouble(dtJSJDPT.Rows[0]["ms"], 2);
- }
- }
- return dt;
- }
- public static Dictionary<string, object> getGuanXianPeiZhi(string pzlx)
- {
- Dictionary<string, object> dic = new Dictionary<string, object>();
- Recordset _rd = dvConfig.Query(string.Format(" pzlx='{0}' ", pzlx), CursorType.Static);
- if (_rd.RecordCount == 0) return dic;
- _rd.MoveFirst();
- while (!_rd.IsEOF)
- {
- string gxcz = _rd.GetFieldValue("gxcz").ToString();
- dic.Add(gxcz + "_gxyjnx", _rd.GetFieldValue("gxyjnx"));
- dic.Add(gxcz + "_gxbznx", _rd.GetFieldValue("gxbznx"));
- dic.Add(gxcz + "_gxms", _rd.GetFieldValue("gxms"));
- _rd.MoveNext();
- }
- ComsStatic.RecordsetDispose(_rd);
- return dic;
- }
- public static double GetMaxValue(DatasetVector dv, string fieldName)
- {
- return dv.Statistic(fieldName, StatisticMode.Max);
- }
- public static int GetMaxValueInt(DatasetVector dv, string fieldName)
- {
- return StringToInt(dv.Statistic(fieldName, StatisticMode.Max));
- }
- public static object GetOnlyValueByField(DatasetVector dv, string sqlWhere, string field)
- {
- Recordset rd = dv.Query(sqlWhere, CursorType.Static);
- if (rd is null || rd.RecordCount != 1) return null;
- return rd.GetFieldValue(field);
- }
- /// <summary>
- /// 在当前的DatasetVector中,获取指定列名的最小值
- /// </summary>
- /// <param name="fieldName"></param>
- /// <returns></returns>
- public static double GetMinValue(DatasetVector dv, string fieldName)
- {
- return dv.Statistic(fieldName, StatisticMode.Min);
- }
- #endregion
- #region ShowUIMessageTip界面提示信息
- public static void ShowUIMessageTipOKorError(bool _result, string msg, string logMsg = "")
- {
- if (_result)
- {
- ShowOKLog(msg + "操作成功!", logMsg);
- }
- else
- {
- ShowErrorLog(msg + "操作失败!", logMsg);
- }
- }
- public static void ShowErrorLog(object msg, string logMsg = "")
- {
- LogHelper.Error(string.Format("{0}.{1}", msg, logMsg));
- UIMessageTip.ShowError(msg.ToString(), 2000, false);
- //UIMessageTip.ShowError(msg.ToString(), 2000, false, new Point(800, 400), true);
- }
- public static void ShowOK(string msg)
- {
- UIMessageTip.ShowOk(msg.ToString(), 2000, false);
- //UIMessageTip.ShowOk(msg, 2000, false, new Point(800, 400), true);
- }
- public static void ShowOKLog(object msg, string logMsg = "")
- {
- pgAddLoginm(string.Format("{0}.{1}", msg, logMsg));
- LogHelper.Info(string.Format("{0}.{1}", msg, logMsg));
- UIMessageTip.ShowOk(msg.ToString(), 2000, false);
- //UIMessageTip.ShowOk(msg.ToString(), 2000, false, new Point(800, 400), true);
- }
- #endregion
- #region String操作
- public static double StringToDouble(object str, int dleng = -1)
- {
- if (str is null) return 0;
- double result = 0.0D;
- double.TryParse(str.ToString(), out result);
- if (dleng != -1)
- {
- result = Math.Round(result, dleng);
- }
- return result;
- }
- /// <summary>
- /// Object转Int Ojbect=null或者转换失败时返回0;
- /// </summary>
- /// <param name="str"></param>
- /// <returns></returns>
- public static int StringToInt(object str)
- {
- if (str is null) return 0;
- Int32 result = 0;
- Int32.TryParse(str.ToString(), out result);
- return result;
- }
- public static Int16 StringToInt16(object str)
- {
- if (str is null) return 0;
- Int16 result = 0;
- Int16.TryParse(str.ToString(), out result);
- return result;
- }
- public static float StringToFloat(object str)
- {
- if (str is null) return 0.0F;
- float result = 0.0F;
- float.TryParse(str.ToString(), out result);
- return result;
- }
- public static string GetStrAddChar(object str, char ch)
- {
- return ch + str.ToString() + ch;
- }
- public static string getMd5Hash(string input, string key)
- {
- MD5 md5Hasher = MD5.Create();
- string str = input + key;
- byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(str));
- StringBuilder sBuilder = new StringBuilder();
- for (int i = 0; i < data.Length; i++)
- {
- sBuilder.Append(data[i].ToString("x2"));
- }
- return sBuilder.ToString();
- }
- #endregion
- #region SummyUI的控件设置和数据绑定
- public static readonly UIStyle uiStyleCom = UIStyle.Blue; //R 80 G 160 B 255
- public static readonly string HideEnableTag = ",smid,smx,smy,smkey,smsdriw,smsdrin,smsdrie,smsdris,smgranule,SmGeometry,smlength,smtopoerror,smlibtileid,smperimeter,smarea,smnodeid,smuserid,smgeometrysize,smgeoposition,objectid,bsm,wth,tfh,dmt,x,y,dinggc,digc,cqbh,tsdh,ssbh,ROTATEANGLE,lrrq,enabled,zcbh,qdms,zdms,shape_length,shape_area,lx,qsdh,zddh,fmlx,sblx,sbsl,sbdz,qdsmid,qdsmx,qdsmy,zdsmid,zdsmx,zdsmy,".ToLower();
- public static void setUIDataGridView(UIDataGridView dgv, DataTable dt = null, string showTag = null, string hideTag = null)
- {
- dgv.Dock = DockStyle.Fill;
- dgv.ShowEditingIcon = false;
- dgv.ShowCellToolTips = false;
- dgv.AllowUserToAddRows = false;
- dgv.AllowUserToResizeRows = false;
- dgv.AllowUserToDeleteRows = false;
- dgv.AllowUserToOrderColumns = false;
- dgv.ReadOnly = true;
- dgv.MultiSelect = false;
- dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
- dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells;
- dgv.Style = UIStyle.Gray;// ComsStatic.uiStyleCom;
- //dgv.RowPostPaint += Dgv_RowPostPaint;
- if (dt != null)
- {
- dgv.DataSource = dt;
- if (showTag != null)
- {
- string[] strShow = showTag.ToLower().Split(',');
- int indexStr = 0;
- for (int i = 0; i < dgv.Columns.Count; i++)
- {
- dgv.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
- dgv.Columns[i].HeaderText = dt.Columns[i].Caption;
- indexStr = strShow.ToList().IndexOf(dgv.Columns[i].Name.ToLower());
- if (indexStr > -1)
- dgv.Columns[i].DisplayIndex = indexStr;
- else
- dgv.Columns[i].Visible = false;
- }
- return;
- }
- if (string.IsNullOrEmpty(hideTag))
- {
- for (int i = 0; i < dgv.Columns.Count; i++)
- {
- dgv.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
- dgv.Columns[i].HeaderText = dt.Columns[i].Caption;
- if (HideEnableTag.Contains("," + dgv.Columns[i].Name.ToLower() + ","))
- {
- dgv.Columns[i].Visible = false;
- }
- }
- }
- else
- {
- for (int i = 0; i < dgv.Columns.Count; i++)
- {
- dgv.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
- dgv.Columns[i].HeaderText = dt.Columns[i].Caption;
- if (HideEnableTag.Contains("," + dgv.Columns[i].Name.ToLower() + ",") || hideTag.ToLower().Contains("," + dgv.Columns[i].Name.ToLower() + ","))
- {
- dgv.Columns[i].Visible = false;
- }
- }
- }
- }
- }
- private static void Dgv_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
- {
- var dgv = sender as DataGridView;
- Rectangle rect = new Rectangle(e.RowBounds.Location.X, e.RowBounds.Location.Y, dgv.RowHeadersWidth - 4, e.RowBounds.Height);
- TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(), dgv.RowHeadersDefaultCellStyle.Font, rect, dgv.RowHeadersDefaultCellStyle.ForeColor, TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
- }
- public static void BindUICombox(UIComboBox cbx, bool hasGX = true)
- {
- foreach (Layer lyr in ComsStatic.MapLayers)
- {
- if (!hasGX && lyr.Dataset.Name == ComsStatic.gsGuanXian.Name) continue;
- cbx.Items.Add(new DoListItem(lyr.Dataset.Name, lyr.Caption));
- }
- cbx.SelectedIndex = 0;
- }
- public static void BindDataTableOnCheckedListBox(DatasetVector _dv, CheckedListBox _cbg, string _ziduan)
- {
- Recordset rd = QueryRecordset(_dv, null, new string[] { _ziduan }, new string[] { _ziduan }, new string[] { _ziduan });
- rd.MoveFirst();
- string fieldValue = string.Empty;
- _cbg.Items.Clear();
- while (!rd.IsEOF)
- {
- fieldValue = rd.GetFieldValue(_ziduan)?.ToString();
- if (string.IsNullOrEmpty(fieldValue))
- _cbg.Items.Add("未知");
- else
- _cbg.Items.Add(fieldValue);
- rd.MoveNext();
- }
- ComsStatic.RecordsetDispose(rd);
- }
- public static void BindDataTableOnComboBox(DatasetVector _dv, UIComboBox _cbg, string _ziduan)
- {
- Recordset rd = QueryRecordset(_dv, null, new string[] { _ziduan }, new string[] { _ziduan }, new string[] { _ziduan });
- rd.MoveFirst();
- _cbg.Items.Clear();
- string fieldValue = string.Empty;
- while (!rd.IsEOF)
- {
- fieldValue = rd.GetFieldValue(_ziduan)?.ToString();
- if (string.IsNullOrEmpty(fieldValue))
- _cbg.Items.Add("未知");
- else
- _cbg.Items.Add(fieldValue);
- rd.MoveNext();
- }
- _cbg.SelectedIndex = 0;
- ComsStatic.RecordsetDispose(rd);
- }
- public static DataTable getPaperSize()
- {
- DataTable dt = new DataTable { TableName = "PaperSizeTable" };
- dt.Columns.Add("sizekey"); dt.Columns.Add("sizedesc");
- dt.Rows.Add("A4", "A4 210x297mm");
- dt.Rows.Add("A3", "A3 297x420mm");
- dt.Rows.Add("ISOA2", "标准纸面大小(A2)");
- dt.Rows.Add("ISOA1", "标准纸面大小(A1)");
- dt.Rows.Add("ISOA0", "标准纸面大小(A0)");
- return dt;
- }
- public static PaperSize getPaperSize(string size)
- {
- PaperSize ps = PaperSize.A4;
- switch (size)
- {
- case "A4": ps = PaperSize.A4; break;
- case "A3": ps = PaperSize.A3; break;
- case "ISOA2": ps = PaperSize.ISOA2; break;
- case "ISOA1": ps = PaperSize.ISOA1; break;
- case "ISOA0": ps = PaperSize.ISOA0; break;
- default: break;
- }
- return ps;
- }
- /// <summary>
- /// 设置CheckedListBox的选择状态 1全选 2反选 3全不选
- /// </summary>
- /// <param name="clb"></param>
- /// <param name="doState">1全选 2反选 3全不选</param>
- public static void CheckListBoxDo(CheckedListBox clb, int doState)
- {
- switch (doState)
- {
- case 1://全选
- for (int i = 0; i < clb.Items.Count; i++)
- {
- clb.SetItemChecked(i, true);
- }
- break;
- case 2://反选
- for (int i = 0; i < clb.Items.Count; i++)
- {
- bool ck = clb.GetItemChecked(i);
- clb.SetItemChecked(i, !ck);
- }
- break;
- case 3://全不选
- for (int i = 0; i < clb.Items.Count; i++)
- {
- clb.SetItemChecked(i, false);
- }
- break;
- default:
- break;
- }
- }
- private static ToolTip toolTips = new ToolTip();
- public static void CheckedListBox_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
- {
- CheckedListBox clb = sender as CheckedListBox;
- int index = clb.IndexFromPoint(e.X, e.Y);
- //if (index != -1)
- if (index != -1 && toolTips.GetToolTip(clb) != clb.Items[index].ToString())
- {
- toolTips.SetToolTip(clb, clb.Items[index].ToString());
- }
- }
- public static void uiTextBox_num_KeyPress(object sender, KeyPressEventArgs e)
- {
- // 横向数字键的1-9 小键盘数字键的1-9 BackSpace 小键盘 . Del 字母按键 .>
- if ((e.KeyChar >= 48 || e.KeyChar <= 57) || (e.KeyChar >= 96 || e.KeyChar <= 105) || (e.KeyChar == 8) || (e.KeyChar == 110) || (e.KeyChar == 190))
- e.Handled = false;//可以输入
- else
- e.Handled = true;
- }
- public static void UIListBox_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
- {
- UIListBox clb = sender as UIListBox;
- int index = clb.IndexFromPoint(e.X, e.Y);
- if (index != -1 && toolTips.GetToolTip(clb) != clb.Items[index].ToString())
- {
- toolTips.SetToolTip(clb, clb.Items[index].ToString());
- }
- }
- #endregion
- #region 其他计算操作
- /// <summary>
- /// 通过起点的坐标和数值、终点的坐标和数值,计算线上交点的数值
- /// </summary>
- /// <param name="gx_start">起点坐标</param>
- /// <param name="gx_start_gc">起点数值</param>
- /// <param name="gx_end">终点坐标</param>
- /// <param name="gx_end_gc">终点数值</param>
- /// <param name="JiaoDian">线上的交点坐标</param>
- /// <returns>交点数值</returns>
- public static double getPointHeight(Point2D start, double startValue, Point2D end, double endValue, Point2D JiaoDian)
- {
- if (!Geometrist.IsPointOnLine(JiaoDian, start, end, false)) return 0.0;
- if (startValue == endValue) return Math.Round(startValue, 2);
- double JiaoDianValue = 0.0D;
- if (startValue < endValue)//确保起点数据 大于 终点数据
- {
- double temp = startValue;
- startValue = endValue;
- endValue = temp;
- Point2D temPoint = start;
- start = end;
- end = temPoint;
- }
- // 参考链接 https://zhuanlan.zhihu.com/p/43660758 下面的公式可以用,是正式的,这里备份一下
- //JiaoDian_gc = gx_end_gc + (gx_start_gc - gx_end_gc) * (Math.Sqrt(Math.Pow((JiaoDian.X - gx_end.X), 2.0) + Math.Pow((JiaoDian.Y - gx_end.Y), 2.0))) / (Math.Sqrt(Math.Pow((gx_start.X - gx_end.X), 2.0) + Math.Pow((gx_start.Y - gx_end.Y), 2.0)));
- JiaoDianValue = endValue + (startValue - endValue) * (Math.Sqrt(Math.Pow((JiaoDian.X - end.X), 2.0) + Math.Pow((JiaoDian.Y - end.Y), 2.0))) / (Math.Sqrt(Math.Pow((start.X - end.X), 2.0) + Math.Pow((start.Y - end.Y), 2.0)));
- if (JiaoDianValue == double.PositiveInfinity || JiaoDianValue == double.NegativeInfinity)
- {
- JiaoDianValue = endValue;
- }
- return Math.Round(JiaoDianValue, 2);
- }
- /// <summary>
- /// 返回Double数组的最大值或者最小值
- /// </summary>
- /// <param name="dblist"></param>
- /// <param name="isMax">True表示最大值,false表示最小值</param>
- /// <returns></returns>
- public static double getMaxMin(double[] dblist, bool isMax)
- {
- double finalValue = dblist[0];
- if (isMax)//最大值
- {
- for (int i = 0; i < dblist.Length; i++)
- {
- if (finalValue < dblist[i])
- finalValue = dblist[i];
- }
- }
- else
- {
- for (int i = 0; i < dblist.Length; i++)
- {
- if (finalValue > dblist[i])
- finalValue = dblist[i];
- }
- }
- return finalValue;
- }
- /// <summary>
- /// 将逗号分隔的csv格式文件,转换为DataTable
- /// </summary>
- /// <param name="filePath">csv文件路径</param>
- /// <param name="FirstField">首行是否是标题行</param>
- /// <returns></returns>
- public static DataTable CSVToDataTable(string filePath, bool FirstField)
- {
- DataTable table = new DataTable();
- bool isField = true;
- using (StreamReader reader = new StreamReader(filePath, Encoding.GetEncoding("gb2312"), false))
- {
- string line = string.Empty;
- while (reader.Peek() > 0)
- {
- line = reader.ReadLine();
- if (string.IsNullOrEmpty(line) || line.Split(',').Length == 0) continue;
- string[] split = line.Split(',');
- if (isField)
- {
- isField = false;
- if (FirstField)//首行是标题
- {
- foreach (string str in split) table.Columns.Add(str);
- continue;
- }
- else
- {
- for (int i = 0; i < split.Length; i++) table.Columns.Add("列" + i.ToString());
- }
- }
- DataRow newRow = table.NewRow();
- for (int j = 0; j < split.Length; j++)
- {
- newRow[j] = split[j].Trim('"');
- }
- table.Rows.Add(newRow);
- }
- return table;
- }
- }
- #endregion
- #region postgresSql
- /// <summary>
- /// 获取本机所有IPV4地址列表
- /// </summary>
- /// <returns>本机所有IPV4地址列表,以分号分隔</returns>
- public static string GetSelfIpv4List()
- {
- StringBuilder ips = new StringBuilder();
- try
- {
- IPHostEntry IpEntry = Dns.GetHostEntry(Dns.GetHostName());
- foreach (IPAddress ipa in IpEntry.AddressList)
- {
- if (ipa.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
- { ips.AppendFormat("{0};", ipa.ToString()); break; }
- }
- }
- catch { }
- return ips.ToString();
- }
- public static string GetSql(string select, List<string> wheres, string orderby = null, string groupby = null)
- {
- StringBuilder sb = new StringBuilder(select);
- if (wheres.Count > 0)
- {
- sb.Append(" where " + string.Join(" and ", wheres.ToArray()));
- }
- if (!string.IsNullOrEmpty(orderby)) sb.Append(orderby);
- if (!string.IsNullOrEmpty(groupby)) sb.Append(groupby);
- return sb.ToString();
- }
- public static void pgAddLogin(string n, string p, string c)
- {
- string sql = string.Format(" INSERT INTO userlogin(lgName,lgtime,lgIP,lgCup)VALUES('{0}','{1}','{2}','{3}') returning id;", n, DateTime.Now.ToLocalTime(), p, c);
- object obj = new NpgsqlHelper().ExecuteScalar(sql);
- ComsStatic.Instance.SetLoginID(StringToInt(obj));
- }
- public static void pgAddLoginm(string n)
- {
- if (ComsStatic.LoginID == 0) return;
- string sql = string.Format(" INSERT INTO userloginm(lgid,czms,cztime)VALUES('{0}','{1}','{2}') returning id;", ComsStatic.LoginID, n, DateTime.Now.ToLocalTime());
- new NpgsqlHelper().ExecuteScalar(sql);
- }
- //public static bool pgDeleteGuanDian(string bsm)
- //{
- // string sql = string.Format(" DELETE FROM {0} WHERE bsm='{1}' RETURNING bsm ", gsGuanDian.TableName, bsm);
- // object obj = new NpgsqlHelper().ExecuteScalar(sql);
- // if (obj == null) return false;
- // return true;
- //}
- public static bool pgDeleteGuanDian(string dvTableName, string bsm)
- {
- string sql = string.Format(" DELETE FROM {0} WHERE bsm='{1}' RETURNING bsm ", dvTableName, bsm);
- object obj = new NpgsqlHelper().ExecuteScalar(sql);
- if (obj == null) return false;
- return true;
- }
- #endregion
- #region 管网标注的配置
- /// <summary>
- ///线样式 LineColor = Color.Brown, LineWidth = 0.5
- /// </summary>
- public static GeoStyle geoStyle_Brown_05mm = new GeoStyle() { LineColor = Color.Brown, LineWidth = 0.5 };
- /// <summary>
- ///点样式 LineColor = Color.Red, MarkerSize = new Size2D(5, 5)
- /// </summary>
- public static GeoStyle geoStyle_Red_Mark5mm = new GeoStyle { LineColor = Color.Red, MarkerSize = new Size2D(5, 5) };
- /// <summary>
- /// 标注样式 ForeColor = Color.Brown, IsSizeFixed = true, FontHeight = 6, Alignment = TextAlignment.BottomLeft
- /// </summary>
- public static TextStyle textStyle_Brown_6mm_BottomLeft = new TextStyle { ForeColor = Color.Brown, IsSizeFixed = true, FontHeight = 6, Alignment = TextAlignment.BottomLeft };
- /// <summary>
- ///边框线样式 LineColor = Color.Red, LineWidth = 1, FillOpaqueRate = 10
- /// </summary>
- public static GeoStyle geoStyle_Red_1mm_OpaqueRate = new GeoStyle { LineColor = Color.Red, LineWidth = 1, FillOpaqueRate = 10 };
- public static Point2D GetPoint2D(object x, object y)
- {
- return new Point2D(StringToDouble(x), StringToDouble(y));
- }
- /// <summary>
- /// 获取标注风格配置的TextStyle
- /// </summary>
- /// <returns></returns>
- public static TextStyle BiaoZhuFengGe()
- {
- QueryParameter queryParameter = new QueryParameter
- {
- AttributeFilter = " pzlx='标注风格配置' and pzKey='TextStyleKey' ",
- ResultFields = new string[] { "pzValue" },
- CursorType = CursorType.Static
- };
- Recordset _rd = ComsStatic.dvConfig.Query(queryParameter);
- if (_rd.RecordCount != 1) return textStyle_Brown_6mm_BottomLeft;
- TextStyle ts = new TextStyle();
- bool fromResult = ts.FromXML(_rd.GetFieldValue("pzValue").ToString());
- ComsStatic.RecordsetDispose(_rd);
- if (!fromResult) return textStyle_Brown_6mm_BottomLeft;
- return ts;
- }
- #endregion
- }
- public class DoListItem
- {
- private string _key = string.Empty;
- private string _value = string.Empty;
- public DoListItem(string pKey, string pValue) { _key = pKey; _value = pValue; }
- public override string ToString() { return _value; }
- public string Key { get => _key; set => _key = value; }
- public string Value { get => _value; set => _value = value; }
- }
- public class DoTrackingPoint
- {
- private Timer timer = new Timer() { Enabled = false, Interval = 300 };
- private int Timertag = 1;
- private GeoPoint markPoint = null;
- public void Doing(double x, double y)
- {
- timer.Tick += Timer_Tick;
- Point2D p2d = new Point2D(x, y);
- ComsStatic.MapControl.Map.Center = p2d;
- ComsStatic.MapControl.Map.Refresh();
- markPoint = new GeoPoint(p2d);
- markPoint.Style = new GeoStyle() { MarkerSize = new Size2D(5, 5), LineColor = Color.Red };
- timer.Enabled = true; timer.Start();
- }
- private void Timer_Tick(object sender, EventArgs e)
- {
- if (Timertag == 6)
- {
- timer.Stop();
- timer.Enabled = false;
- Timertag = 1;
- int index = ComsStatic.MapControl.Map.TrackingLayer.IndexOf("DoInterestPoint");
- if (index > -1) ComsStatic.MapControl.Map.TrackingLayer.Remove(index);
- ComsStatic.MapControl.Map.RefreshTrackingLayer();
- return;
- }
- else if (Timertag % 2 == 1 && markPoint != null)
- {
- ComsStatic.MapControl.Map.TrackingLayer.Add(markPoint, "DoInterestPoint");
- }
- else //if (Timertag % 2 == 0)
- {
- int index = ComsStatic.MapControl.Map.TrackingLayer.IndexOf("DoInterestPoint");
- if (index > -1) ComsStatic.MapControl.Map.TrackingLayer.Remove(index);
- }
- Timertag++;
- ComsStatic.MapControl.Map.RefreshTrackingLayer();
- }
- }
- public class LayerEx
- {
- //public LayerEx() { }
- private string caption;
- private string fldm;
- private string dataset;
- private DatasetVector datasetVector;
- private int markerSymbolID = 0;
- private double maxVisibleScale = 0;
- private double minVisibleScale = 0;
- private bool isEditable = false;
- private bool isVisible = true;
- private int index;
- private Color lineColor = Color.Blue;
- private double lineWidth;
- public string Caption { get => caption; set => caption = value; }
- public string FLDM { get => fldm; set => fldm = value; }
- public string Dataset { get => dataset; set => dataset = value; }
- public DatasetVector DatasetVector { get => datasetVector; set => datasetVector = value; }
- public int MarkerSymbolID { get => markerSymbolID; set => markerSymbolID = value; }
- public double MaxVisibleScale { get => maxVisibleScale; set => maxVisibleScale = value; }
- public double MinVisibleScale { get => minVisibleScale; set => minVisibleScale = value; }
- public bool IsEditable { get => isEditable; set => isEditable = value; }
- public bool IsVisible { get => isVisible; set => isVisible = value; }
- public int Index { get => index; set => index = value; }
- public double LineWidth { get => lineWidth; set => lineWidth = value; }
- public Color LineColor { get => lineColor; set => lineColor = value; }
- }
- }
|