ComsStatic.cs 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292
  1. using Sunny.UI;
  2. using SuperMap.Data;
  3. using SuperMap.Layout;
  4. using SuperMap.Mapping;
  5. using SuperMap.UI;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Data;
  9. using System.Drawing;
  10. using System.IO;
  11. using System.Linq;
  12. using System.Net;
  13. using System.Security.Cryptography;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. using System.Windows.Forms;
  17. using WeifenLuo.WinFormsUI.Docking;
  18. using WWPipeLine.Commons;
  19. namespace WWPipeLine.MapBasic
  20. {
  21. public class ComsStatic
  22. {
  23. #region Instance
  24. private static ComsStatic m_Instance;
  25. public static ComsStatic Instance
  26. {
  27. get
  28. {
  29. if (m_Instance == null)
  30. m_Instance = new ComsStatic();
  31. return m_Instance;
  32. }
  33. }
  34. private static Workspace m_Workspace;
  35. public void SetWorkspace(Workspace ws) { m_Workspace = ws; }
  36. private static MapControl m_MapControl;
  37. public void SetMapControl(MapControl mp) { m_MapControl = mp; }
  38. private static DockPanel m_DockPanel;
  39. public void SetDockPanel(DockPanel dp) { m_DockPanel = dp; }
  40. private static Datasource m_MemoryDatasource;
  41. public void SetMemoryDatasource(Datasource ds) { m_MemoryDatasource = ds; }
  42. private static IMessageInterface m_IMessageInterface;
  43. public void SetIMessageInterface(IMessageInterface mi) { m_IMessageInterface = mi; }
  44. public static IMessageInterface MessageInterface { get => m_IMessageInterface; }
  45. #endregion
  46. #region 用户信息
  47. public void SetUserID(int uid) { m_UserID = uid; }
  48. private static int m_UserID;
  49. public static int UserID { get => m_UserID; }
  50. public void SetUserName(string uNick) { m_UserNick = uNick; }
  51. private static string m_UserNick;
  52. public static string UserNick { get => m_UserNick; }
  53. public void SetLoginID(int uid) { m_LoginID = uid; }
  54. private static int m_LoginID;
  55. public static int LoginID { get => m_LoginID; }
  56. #endregion
  57. #region Workspace MapControl DatasetVector
  58. public static Int32 WorkspaceMapIndex
  59. {
  60. get
  61. {
  62. string index = IniHelper.Read(IniHelper.KEY_WorkspaceMapIndex_PATH);
  63. return StringToInt(index);
  64. }
  65. }
  66. private static Int32 WorkspaceDatasourceIndex
  67. {
  68. get
  69. {
  70. string index = IniHelper.Read(IniHelper.KEY_WorkspaceDatasourceIndex_PATH);
  71. return StringToInt(index);
  72. }
  73. }
  74. public static Datasource Datasource { get => m_Workspace.Datasources[WorkspaceDatasourceIndex]; }
  75. public static Datasource DatasourceMemory { get => m_MemoryDatasource; }
  76. public static Workspace Workspace { get => m_Workspace; }
  77. public static MapControl MapControl { get => m_MapControl; }
  78. public static DockPanel DockPanel { get => m_DockPanel; }
  79. public static DatasetVector dvConfig { get => Datasource.Datasets["wwconfig"] as DatasetVector; }
  80. public static DatasetVector gsGuanXian { get => Datasource.Datasets[dvGXDatasetName] as DatasetVector; }
  81. public static DatasetVector gsGuanDian { get => Datasource.Datasets["gsGD"] as DatasetVector; }
  82. /// <summary>
  83. /// B/S端用到的网络数据集名称
  84. /// </summary>
  85. public static readonly string NetworkDatasetName = "DaAnPostgrsSQL_Network";
  86. /// <summary>
  87. /// 供水管线的数据集 Name=gsGX
  88. /// </summary>
  89. public static readonly string dvGXDatasetName = "gsGX";
  90. /// <summary>
  91. /// 供水管线的图层名称 Caption=供水管线
  92. /// </summary>
  93. public static readonly string dvGXCaption = "供水管线";
  94. #region 软件打开时 动态加载图层 这种情况需要确定工作空间内只有管线和其他图层,不能包含管点图层
  95. public static List<LayerEx> layerExList
  96. {
  97. get
  98. {
  99. //备注:1、节点图层的DatasetName必须带有dv,系统中会通过该字母判断是否选择的是节点图层
  100. List<LayerEx> list = new List<LayerEx>();
  101. list.Add(new LayerEx { Index = 0, Caption = "供水节点", Dataset = "dvJD", MarkerSymbolID = 14, MarkerSize = 2 });
  102. list.Add(new LayerEx { Index = 0, Caption = "供水阀门", Dataset = "dvFM", MarkerSymbolID = 13, MarkerSize = 3 });
  103. list.Add(new LayerEx { Index = 0, Caption = "消防栓", Dataset = "dvXFS", MarkerSymbolID = 19, MarkerSize = 3 });
  104. list.Add(new LayerEx { Index = 0, Caption = "压力监测点", Dataset = "dvYL", MarkerSymbolID = 20, MarkerSize = 3 });
  105. list.Add(new LayerEx { Index = 0, Caption = "流量监测点", Dataset = "dvLL", MarkerSymbolID = 15, MarkerSize = 3 });
  106. list.Add(new LayerEx { Index = 0, Caption = "水质监测点", Dataset = "dvSZ", MarkerSymbolID = 18, MarkerSize = 3 });
  107. list.Add(new LayerEx { Index = 0, Caption = "水表", Dataset = "dvSB", MarkerSymbolID = 17, MarkerSize = 3 });
  108. list.Add(new LayerEx { Index = 0, Caption = "供水水厂", Dataset = "dvSC", MarkerSymbolID = 21, MarkerSize = 3 });
  109. list.Add(new LayerEx { Index = 0, Caption = "排气阀", Dataset = "dvPQF", MarkerSymbolID = 16, MarkerSize = 3 });
  110. list.Add(new LayerEx { Index = 0, Caption = "调压站", Dataset = "dvJY", MarkerSymbolID = 20, MarkerSize = 3 });
  111. return list;
  112. }
  113. }
  114. public static void SetDatasetVectorAddLayer()
  115. {
  116. DatasetVector dv = null;
  117. LayerSettingVector layerSettingVector;
  118. string[] strField = GetFieldInfos(gsGuanDian);
  119. foreach (LayerEx lyrEx in layerExList.ToArray())
  120. {
  121. if (!Datasource.Datasets.Contains(lyrEx.Dataset))
  122. {
  123. dv = Datasource.Datasets.Create(new DatasetVectorInfo() { Name = lyrEx.Dataset, Type = DatasetType.Point });
  124. bool result = dv.AppendFields(gsGuanDian, "smid", "smuserid", strField);
  125. }
  126. else
  127. {
  128. dv = Datasource.Datasets[lyrEx.Dataset] as DatasetVector;
  129. dv.Truncate();
  130. }
  131. dv.Append(gsGuanDian.Query("FLDM='" + lyrEx.Caption + "'", CursorType.Static));
  132. LayerGroup lg = m_MapControl.Map.Layers.FindLayer("LayerGroup") as LayerGroup;
  133. if (lg == null) continue;
  134. layerSettingVector = new LayerSettingVector();
  135. //默认GeoStyle
  136. //{ FillBackColor=Color [A=255, R=255, G=255, B=255],FillForeColor=Color [A=255, R=189, G=235, B=255],
  137. // FillGradientAngle=0,FillGradientMode=None,FillGradientOffsetRatioX=0,FillGradientOffsetRatioY=0,
  138. // FillOpaqueRate=100,FillSymbolID=0,LineColor=Color [A=255, R=0, G=0, B=0],LineSymbolID=0,LineWidth=1,
  139. // MarkerAngle=0,MarkerSize={Width=2,Height=-0.1},MarkerSymbolID=0}
  140. GeoStyle geoStyle = new GeoStyle();
  141. geoStyle.MarkerSize = new Size2D(lyrEx.MarkerSize, lyrEx.MarkerSize);
  142. geoStyle.LineColor = lyrEx.LineColor;
  143. geoStyle.MarkerSymbolID = lyrEx.MarkerSymbolID;
  144. layerSettingVector.Style = geoStyle;
  145. Layer layer = Layer.CreateLayer(dv, layerSettingVector);
  146. layer.Caption = lyrEx.Caption;
  147. layer.Selection.IsDefaultStyleEnabled = false;
  148. layer.Selection.Style = geoStyle_Selection;
  149. layer.Selection.SetStyleOptions(StyleOptions.MarkerSymbolID, true);
  150. layer.Selection.SetStyleOptions(StyleOptions.LineColor, true);
  151. layer.Selection.SetStyleOptions(StyleOptions.MarkerSize, true);
  152. lg.Insert(0, layer);
  153. }
  154. }
  155. public static bool SetDatasetVector()
  156. {
  157. try
  158. {
  159. DatasetVector dv = null;
  160. string[] strField = GetFieldInfos(gsGuanDian);
  161. foreach (LayerEx lyrEx in layerExList.ToArray())
  162. {
  163. if (!Datasource.Datasets.Contains(lyrEx.Dataset))
  164. {
  165. dv = Datasource.Datasets.Create(new DatasetVectorInfo() { Name = lyrEx.Dataset, Type = DatasetType.Point });
  166. bool result = dv.AppendFields(gsGuanDian, "smid", "smuserid", strField);
  167. }
  168. else
  169. {
  170. dv = Datasource.Datasets[lyrEx.Dataset] as DatasetVector;
  171. dv.Truncate();
  172. }
  173. dv.Append(gsGuanDian.Query("FLDM='" + lyrEx.Caption + "'", CursorType.Static));
  174. }
  175. return true;
  176. }
  177. catch (Exception ex) { LogHelper.Fatal(ex); return false; }
  178. }
  179. public static GeoStyle geoStyle_Selection = new GeoStyle { MarkerSymbolID = 0, LineColor = Color.Red, MarkerSize = new Size2D(4, 4) };
  180. #endregion
  181. public static Layer LayerGuanXian
  182. {
  183. get
  184. {
  185. LayerGroup lg = m_MapControl.Map.Layers.FindLayer("LayerGroup") as LayerGroup;
  186. if (lg.Count == 0) return null;
  187. Layer lyr = null;
  188. foreach (Layer lyrr in lg)
  189. {
  190. if (lyrr.Dataset == gsGuanXian) { lyr = lyrr; break; }
  191. }
  192. return lyr;
  193. }
  194. }
  195. //public static Layers MapLayers { get => m_MapControl.Map.Layers; }
  196. /// <summary>
  197. /// 管点管线图层
  198. /// </summary>
  199. public static List<Layer> MapLayers
  200. {
  201. get
  202. {
  203. List<Layer> layerList = new List<Layer>();
  204. LayerGroup lg = m_MapControl.Map.Layers.FindLayer("LayerGroup") as LayerGroup;
  205. if (lg.Count == 0) return null;
  206. foreach (Layer lyrr in lg)
  207. {
  208. if (lyrr.Dataset == null || lyrr.Dataset.Datasource.Alias != Datasource.Alias) continue;
  209. layerList.Add(lyrr);
  210. }
  211. return layerList;
  212. }
  213. }
  214. /// <summary>
  215. /// 管点管线图层 + 用水单位图层
  216. /// </summary>
  217. public static List<Layer> MapLayersUsed
  218. {
  219. get
  220. {
  221. List<Layer> layerList = MapLayers;
  222. LayerGroup lg = m_MapControl.Map.Layers.FindLayer("LayerGroup#1") as LayerGroup;
  223. if (lg.Count == 0) return layerList;
  224. foreach (Layer lyrr in lg)
  225. {
  226. if (lyrr.Dataset == null || lyrr.Dataset.Datasource.Alias != Datasource.Alias) continue;
  227. if (!",pyunit,".ToLower().Contains(lyrr.Dataset.Name.ToLower())) continue;
  228. layerList.Add(lyrr);
  229. }
  230. return layerList;
  231. }
  232. }
  233. /// <summary>
  234. /// 当前数据集的所有图层
  235. /// </summary>
  236. public static List<Layer> MapLayersAll
  237. {
  238. get
  239. {
  240. List<Layer> layerList = new List<Layer>();
  241. foreach (Layer lyr in m_MapControl.Map.Layers)
  242. {
  243. if (lyr.Name.ToLower().Contains("layergroup"))
  244. {
  245. LayerGroup lyrG = lyr as LayerGroup;
  246. foreach (Layer lyrr in lyrG.Layers)
  247. {
  248. if (lyrr.Dataset.Datasource.Alias == Datasource.Alias)
  249. layerList.Add(lyrr);
  250. }
  251. }
  252. else if (lyr.Dataset.Datasource.Alias == Datasource.Alias)
  253. {
  254. layerList.Add(lyr);
  255. }
  256. }
  257. return layerList;
  258. }
  259. }
  260. public static void SetLayersIsSelectableFalse(string layerName, bool isSelect)
  261. {
  262. foreach (Layer r in MapLayers)
  263. {
  264. if (r.Name == layerName || r.Caption == layerName || r.Dataset.Name == layerName)
  265. r.IsSelectable = isSelect;
  266. else
  267. r.IsSelectable = !isSelect;
  268. }
  269. }
  270. public static void SetLayersIsVisibleFalse(string layerName, bool isSelect)
  271. {
  272. foreach (Layer r in MapLayers)
  273. {
  274. if (r.Name == layerName || r.Caption == layerName || r.Dataset.Name == layerName)
  275. r.IsVisible = isSelect;
  276. else
  277. r.IsVisible = !isSelect;
  278. }
  279. }
  280. /// <summary>
  281. /// 依据TrackingLayer的Name清空
  282. /// </summary>
  283. /// <param name="tag"></param>
  284. public static void TrackingLayerRemove(string tag)
  285. {
  286. int index = MapControl.Map.TrackingLayer.IndexOf(tag);
  287. while (index != -1)
  288. {
  289. MapControl.Map.TrackingLayer.Remove(index);
  290. index = MapControl.Map.TrackingLayer.IndexOf(tag);
  291. }
  292. }
  293. public static readonly string ControlToolsTrackingName = "ControlToolAddGeoRegion";
  294. public static void MapControl_Tracked_TrackingName(object sender, SuperMap.UI.TrackedEventArgs e)
  295. {
  296. m_MapControl.Tracked -= MapControl_Tracked_TrackingName;
  297. m_MapControl.Action = SuperMap.UI.Action.Select;
  298. m_MapControl.Action = SuperMap.UI.Action.Pan;
  299. if (e.Geometry is null) { Sunny.UI.UIMessageTip.ShowError("区域绘制失败"); return; }
  300. GeoRegion m_geo = e.Geometry.Clone() as GeoRegion;
  301. if (m_geo is null) { Sunny.UI.UIMessageTip.ShowError("区域绘制失败"); return; }
  302. m_geo.Style = ComsStatic.geoStyle_Red_1mm_OpaqueRate;
  303. m_MapControl.Map.TrackingLayer.Clear();
  304. m_MapControl.Map.TrackingLayer.Add(m_geo, ComsStatic.ControlToolsTrackingName);
  305. m_MapControl.Map.RefreshTrackingLayer();
  306. }
  307. /// <summary>
  308. /// 关闭当前主程序中除了Tag=MainControls的其他所有窗体
  309. /// <para>默认4个主要窗体: 主窗体 工具栏 鹰眼 图层</para>
  310. /// </summary>
  311. public static void closeFormTagMainControls()
  312. {
  313. try
  314. {
  315. foreach (Form form in Application.OpenForms)
  316. {
  317. if (form.Tag?.ToString() != "MainControls" && form.Text?.ToString() != "工具栏")
  318. {
  319. form.Close(); break;
  320. }
  321. }
  322. if (Application.OpenForms.Count > 6)
  323. {
  324. closeFormTagMainControls();
  325. }
  326. }
  327. catch (Exception ex)
  328. {
  329. ComsStatic.ShowErrorLog(ex);
  330. }
  331. }
  332. #endregion
  333. #region SuperMap.Data相关操作
  334. public static readonly string[] resultFieldsGX = new string[] { "fldm", "cz", "gj", "cd", "yl", "msfs", "dzms", "qsdw", "tcdw" };
  335. public static readonly string[] resultFieldsGD = new string[] { "fldm", "fsw", "xh", "gg", "cz", "kj", "gj", "yl", "dmgc", "ms", "msfs", "dzms", "qsdw", "tcdw" };
  336. public static Recordset QueryRecordset(DatasetVector dv, string sqlWhere, string[] resultFields = null, string[] groupBy = null, string[] orderBy = null)
  337. {
  338. QueryParameter para = new QueryParameter();
  339. if (sqlWhere != null) para.AttributeFilter = sqlWhere;
  340. if (resultFields != null) para.ResultFields = Commons.StringEx.setToLower(resultFields);
  341. if (groupBy != null) para.GroupBy = Commons.StringEx.setToLower(groupBy);
  342. if (orderBy != null) para.OrderBy = Commons.StringEx.setToLower(orderBy);
  343. para.CursorType = CursorType.Static;
  344. return dv.Query(para);
  345. }
  346. public static Recordset QueryRecordsetDynamic(DatasetVector dv, string sqlWhere, string[] resultFields = null, string[] groupBy = null, string[] orderBy = null)
  347. {
  348. QueryParameter para = new QueryParameter();
  349. if (sqlWhere != null) para.AttributeFilter = sqlWhere;
  350. if (resultFields != null) para.ResultFields = Commons.StringEx.setToLower(resultFields);
  351. if (groupBy != null) para.GroupBy = Commons.StringEx.setToLower(groupBy);
  352. if (orderBy != null) para.OrderBy = Commons.StringEx.setToLower(orderBy);
  353. para.CursorType = CursorType.Dynamic;
  354. return dv.Query(para);
  355. }
  356. public static DataTable QueryDataTable(DatasetVector dv, string sqlWhere, string[] resultFields = null, string[] groupBy = null, string[] orderBy = null)
  357. {
  358. QueryParameter para = new QueryParameter();
  359. if (sqlWhere != null) para.AttributeFilter = sqlWhere;
  360. if (resultFields != null) para.ResultFields = Commons.StringEx.setToLower(resultFields);
  361. if (groupBy != null) para.GroupBy = Commons.StringEx.setToLower(groupBy);
  362. if (orderBy != null) para.OrderBy = Commons.StringEx.setToLower(orderBy);
  363. para.CursorType = CursorType.Static;
  364. return RecordsetToDataTable(dv.Query(para), true, dv.Name);
  365. }
  366. public static List<object> QueryFieldsValueList(DatasetVector dv, string sqlWhere, string resultFields, string[] groupBy = null, string[] orderBy = null)
  367. {
  368. Recordset rd = QueryRecordset(dv, sqlWhere, new string[] { resultFields }, groupBy, orderBy);
  369. List<object> result = new List<object>();
  370. rd.MoveFirst();
  371. if (!rd.IsEOF)
  372. {
  373. result.Add(rd.GetFieldValue(resultFields));
  374. rd.MoveNext();
  375. }
  376. return result;
  377. }
  378. public static DataTable RecordsetToDataTable(Recordset recordset, bool isDispose = true, string tableName = null)
  379. {
  380. if (string.IsNullOrEmpty(tableName)) tableName = recordset.Dataset.Name;
  381. DataTable dt = new DataTable { TableName = tableName };
  382. foreach (FieldInfo info in recordset.GetFieldInfos())
  383. {
  384. dt.Columns.Add(new DataColumn { ColumnName = info.Name, Caption = info.Caption });
  385. }
  386. DataRow dr;
  387. recordset.MoveFirst();
  388. while (!recordset.IsEOF)
  389. {
  390. dr = dt.NewRow();
  391. foreach (DataColumn dc in dt.Columns)
  392. {
  393. dr[dc] = recordset.GetFieldValue(dc.ColumnName)?.ToString();
  394. }
  395. dt.Rows.Add(dr);
  396. recordset.MoveNext();
  397. }
  398. if (isDispose) RecordsetDispose(recordset);
  399. return dt;
  400. }
  401. //public static DataTable RecordsetToDataTable(Recordset recordset, bool isDispose = true, string tableName = null)
  402. //{
  403. // if (string.IsNullOrEmpty(tableName)) tableName = recordset.Dataset.Name;
  404. // DataTable dt = new DataTable { TableName = tableName };
  405. // FieldInfos fieldInfos = recordset.GetFieldInfos();
  406. // Int32 count = fieldInfos.Count;
  407. // DataColumn dataColumn;
  408. // for (Int32 i = 0; i < count; i++)
  409. // {
  410. // dataColumn = new DataColumn { ColumnName = fieldInfos[i].Name, Caption = fieldInfos[i].Caption };
  411. // dt.Columns.Add(dataColumn);
  412. // }
  413. // recordset.MoveFirst();
  414. // Int32 length = recordset.RecordCount;
  415. // DataRow dr;
  416. // for (int i = 0; i < length; i++)
  417. // {
  418. // dr = dt.NewRow();
  419. // var actIndex = 0;
  420. // for (Int32 j = 0; j < count; j++)
  421. // {
  422. // var objValue = recordset.GetFieldValue(j);
  423. // string value = objValue?.ToString();
  424. // dr[actIndex++] = value;
  425. // }
  426. // dt.Rows.Add(dr);
  427. // recordset.MoveNext();
  428. // }
  429. // if (isDispose) RecordsetDispose(recordset);
  430. // return dt;
  431. //}
  432. public static List<DataTable> TongJiFieldGroupCount(DatasetVector dv, string[] strField)
  433. {
  434. Recordset rd = null;
  435. List<DataTable> dts = new List<DataTable>();
  436. DataTable dt;
  437. DataRow dr;
  438. string fieldValue = string.Empty;
  439. foreach (string field in strField)
  440. {
  441. string[] ck = new string[] { field };
  442. rd = ComsStatic.QueryRecordset(dv, null, ck, ck, ck);
  443. dt = new DataTable(); dt.Columns.Add("类别"); dt.Columns.Add("数量");
  444. if (!HasField(dv, field)) continue;
  445. dt.TableName = rd.GetFieldInfos()[field].Caption;
  446. if (rd.RecordCount == 0)//该字段所有值均为null 不能GroupBy
  447. {
  448. dr = dt.NewRow();
  449. dr["类别"] = "未知"; dr["数量"] = dv.RecordCount;
  450. dt.Rows.Add(dr);
  451. }
  452. else
  453. {
  454. rd.MoveFirst();
  455. while (!rd.IsEOF)
  456. {
  457. dr = dt.NewRow();
  458. fieldValue = rd.GetFieldValue(field)?.ToString();
  459. if (string.IsNullOrEmpty(fieldValue))
  460. {
  461. dr["类别"] = "未知";
  462. dr["数量"] = dv.Query(string.Format("{0} is null", field), CursorType.Static).RecordCount;
  463. }
  464. else
  465. {
  466. dr["类别"] = fieldValue;
  467. dr["数量"] = dv.Query(string.Format("{0}='{1}'", field, fieldValue), CursorType.Static).RecordCount;
  468. }
  469. dt.Rows.Add(dr);
  470. rd.MoveNext();
  471. }
  472. }
  473. dr = dt.NewRow();
  474. dr["类别"] = dt.TableName + "总量"; dr["数量"] = dv.RecordCount;
  475. dt.Rows.Add(dr);
  476. dts.Add(dt);
  477. }
  478. ComsStatic.RecordsetDispose(rd);
  479. return dts;
  480. }
  481. public static string getSqlCheckListBox(Dictionary<string, CheckedListBox> dic, string otherWhere = null)
  482. {
  483. if (string.IsNullOrEmpty(otherWhere))
  484. otherWhere = " 1=1 ";
  485. StringBuilder sb = new StringBuilder(otherWhere);
  486. foreach (string key in dic.Keys)
  487. {
  488. if (dic[key].CheckedItems.Count > 0)
  489. {
  490. sb.Append(" AND (1=2 ");
  491. foreach (string clbItem in dic[key].CheckedItems)
  492. {
  493. if (clbItem == "未知")
  494. sb.AppendFormat(" OR {0} is null ", key);
  495. else
  496. sb.AppendFormat(" OR {0}='{1}' ", key, clbItem);
  497. }
  498. sb.Append(" ) ");
  499. }
  500. }
  501. return sb.ToString();
  502. }
  503. /// <summary>
  504. /// 获取DatasetVector的FieldInfos数组 不包含系统字段
  505. /// </summary>
  506. /// <param name="dv"></param>
  507. /// <returns></returns>
  508. public static string[] GetFieldInfos(DatasetVector dv)
  509. {
  510. List<string> listStr = new List<string>();
  511. foreach (FieldInfo f in dv.FieldInfos)
  512. {
  513. if (f.IsSystemField || f.Name.ToLower() == "smuserid") continue;
  514. listStr.Add(f.Name);
  515. }
  516. return listStr.ToArray();
  517. }
  518. public static bool HasField(DatasetVector m_DatasetVector, string _field)
  519. {
  520. bool hasField = false;
  521. FieldInfos fieldInfos = m_DatasetVector.FieldInfos;
  522. for (int i = 0; i < fieldInfos.Count; i++)
  523. {
  524. if (fieldInfos[i].Name.ToLower() == _field.ToLower())
  525. {
  526. hasField = true; break;
  527. }
  528. }
  529. return hasField;
  530. }
  531. public static bool HasField(Recordset m_Recordset, string _field)
  532. {
  533. bool hasField = false;
  534. FieldInfos fieldInfos = m_Recordset.GetFieldInfos();
  535. for (int i = 0; i < fieldInfos.Count; i++)
  536. {
  537. if (fieldInfos[i].Name.ToLower() == _field.ToLower())
  538. {
  539. hasField = true; break;
  540. }
  541. }
  542. return hasField;
  543. }
  544. public static void RecordsetDispose(Recordset rd)
  545. {
  546. if (rd != null) { rd.Close(); rd.Dispose(); }
  547. }
  548. public static void EditHistoryUndo(EditHistory eh)
  549. {
  550. while (eh.CanUndo)
  551. {
  552. bool isSuccess = eh.Undo();
  553. }
  554. eh.Clear(); eh.Dispose();
  555. }
  556. public static DataTable GetJSLKbyJSJDPT(DataTable dt)
  557. {
  558. #region 构造 管线的起始管点和终点管点 信息
  559. dt.Columns.Add(new DataColumn { ColumnName = "qdsmid", Caption = "起点SmID" });
  560. dt.Columns.Add(new DataColumn { ColumnName = "qdsmx", Caption = "起点X坐标" });
  561. dt.Columns.Add(new DataColumn { ColumnName = "qdsmy", Caption = "起点Y坐标" });
  562. dt.Columns.Add(new DataColumn { ColumnName = "qddmgc", Caption = "起点地面高程" });
  563. dt.Columns.Add(new DataColumn { ColumnName = "qdgdms", Caption = "起点埋深" });
  564. dt.Columns.Add(new DataColumn { ColumnName = "qdgc", Caption = "起点高程" });
  565. dt.Columns.Add(new DataColumn { ColumnName = "zdsmid", Caption = "终点SmID" });
  566. dt.Columns.Add(new DataColumn { ColumnName = "zdsmx", Caption = "终点X坐标" });
  567. dt.Columns.Add(new DataColumn { ColumnName = "zdsmy", Caption = "终点Y坐标" });
  568. dt.Columns.Add(new DataColumn { ColumnName = "zddmgc", Caption = "终点地面高程" });
  569. dt.Columns.Add(new DataColumn { ColumnName = "zdgdms", Caption = "终点埋深" });
  570. dt.Columns.Add(new DataColumn { ColumnName = "zdgc", Caption = "终点高程" });
  571. #endregion
  572. DataTable dtJSJDPT;
  573. foreach (DataRow dr in dt.Rows)
  574. {
  575. dtJSJDPT = QueryDataTable(gsGuanDian, string.Format(" bsm='{0}' ", dr["qsdh"]));
  576. if (dtJSJDPT.Rows.Count == 1)
  577. {
  578. dr["qdsmid"] = dtJSJDPT.Rows[0]["smid"]; dr["qdsmx"] = dtJSJDPT.Rows[0]["x"]; dr["qdsmy"] = dtJSJDPT.Rows[0]["y"];
  579. dr["qddmgc"] = dtJSJDPT.Rows[0]["dmgc"]; dr["qdgdms"] = dtJSJDPT.Rows[0]["ms"];
  580. dr["qdgc"] = StringToDouble(dtJSJDPT.Rows[0]["dmgc"], 2) - StringToDouble(dtJSJDPT.Rows[0]["ms"], 2);
  581. }
  582. dtJSJDPT = QueryDataTable(gsGuanDian, string.Format(" bsm='{0}' ", dr["zddh"]));
  583. if (dtJSJDPT.Rows.Count == 1)
  584. {
  585. dr["zdsmid"] = dtJSJDPT.Rows[0]["smid"]; dr["zdsmx"] = dtJSJDPT.Rows[0]["x"]; dr["zdsmy"] = dtJSJDPT.Rows[0]["y"];
  586. dr["zddmgc"] = dtJSJDPT.Rows[0]["dmgc"]; dr["zdgdms"] = dtJSJDPT.Rows[0]["ms"];
  587. dr["zdgc"] = StringToDouble(dtJSJDPT.Rows[0]["dmgc"], 2) - StringToDouble(dtJSJDPT.Rows[0]["ms"], 2);
  588. }
  589. }
  590. return dt;
  591. }
  592. public static Dictionary<string, object> getGuanXianPeiZhi(string pzlx)
  593. {
  594. Dictionary<string, object> dic = new Dictionary<string, object>();
  595. Recordset _rd = dvConfig.Query(string.Format(" pzlx='{0}' ", pzlx), CursorType.Static);
  596. if (_rd.RecordCount == 0) return dic;
  597. _rd.MoveFirst();
  598. while (!_rd.IsEOF)
  599. {
  600. string gxcz = _rd.GetFieldValue("gxcz").ToString();
  601. dic.Add(gxcz + "_gxyjnx", _rd.GetFieldValue("gxyjnx"));
  602. dic.Add(gxcz + "_gxbznx", _rd.GetFieldValue("gxbznx"));
  603. dic.Add(gxcz + "_gxms", _rd.GetFieldValue("gxms"));
  604. _rd.MoveNext();
  605. }
  606. ComsStatic.RecordsetDispose(_rd);
  607. return dic;
  608. }
  609. public static double GetMaxValue(DatasetVector dv, string fieldName)
  610. {
  611. return dv.Statistic(fieldName, StatisticMode.Max);
  612. }
  613. public static int GetMaxValueInt(DatasetVector dv, string fieldName)
  614. {
  615. return StringToInt(dv.Statistic(fieldName, StatisticMode.Max));
  616. }
  617. public static object GetOnlyValueByField(DatasetVector dv, string sqlWhere, string field)
  618. {
  619. Recordset rd = dv.Query(sqlWhere, CursorType.Static);
  620. if (rd is null || rd.RecordCount != 1) return null;
  621. return rd.GetFieldValue(field);
  622. }
  623. /// <summary>
  624. /// 在当前的DatasetVector中,获取指定列名的最小值
  625. /// </summary>
  626. /// <param name="fieldName"></param>
  627. /// <returns></returns>
  628. public static double GetMinValue(DatasetVector dv, string fieldName)
  629. {
  630. return dv.Statistic(fieldName, StatisticMode.Min);
  631. }
  632. #endregion
  633. #region ShowUIMessageTip界面提示信息
  634. public static void ShowUIMessageTipOKorError(bool _result, string msg, string logMsg = "")
  635. {
  636. if (_result)
  637. {
  638. ShowOKLog(msg + "操作成功", logMsg);
  639. }
  640. else
  641. {
  642. ShowErrorLog(msg + "操作失败", logMsg);
  643. }
  644. }
  645. public static void ShowErrorLog(object msg, string logMsg = "")
  646. {
  647. LogHelper.Error(string.Format("{0} {1}", msg, logMsg));
  648. UIMessageTip.ShowError(msg.ToString(), 2000, false);
  649. //UIMessageTip.ShowError(msg.ToString(), 2000, false, new Point(800, 400), true);
  650. }
  651. public static void ShowOK(string msg)
  652. {
  653. UIMessageTip.ShowOk(msg.ToString(), 2000, false);
  654. //UIMessageTip.ShowOk(msg, 2000, false, new Point(800, 400), true);
  655. }
  656. public static void ShowOKLog(object msg, string logMsg = "")
  657. {
  658. //pgAddLoginm(string.Format("{0} {1}", msg, logMsg));
  659. LogHelper.Info(string.Format("{0} {1}", msg, logMsg));
  660. UIMessageTip.ShowOk(msg.ToString(), 2000, false);
  661. //UIMessageTip.ShowOk(msg.ToString(), 2000, false, new Point(800, 400), true);
  662. }
  663. #endregion
  664. #region String操作
  665. public static double StringToDouble(object str, int dleng = -1)
  666. {
  667. if (str is null) return 0;
  668. double result = 0.0D;
  669. double.TryParse(str.ToString(), out result);
  670. if (dleng != -1)
  671. {
  672. result = Math.Round(result, dleng);
  673. }
  674. return result;
  675. }
  676. /// <summary>
  677. /// Object转Int Ojbect=null或者转换失败时返回0;
  678. /// </summary>
  679. /// <param name="str"></param>
  680. /// <returns></returns>
  681. public static int StringToInt(object str)
  682. {
  683. if (str is null) return 0;
  684. Int32 result = 0;
  685. Int32.TryParse(str.ToString(), out result);
  686. return result;
  687. }
  688. public static Int16 StringToInt16(object str)
  689. {
  690. if (str is null) return 0;
  691. Int16 result = 0;
  692. Int16.TryParse(str.ToString(), out result);
  693. return result;
  694. }
  695. public static float StringToFloat(object str)
  696. {
  697. if (str is null) return 0.0F;
  698. float result = 0.0F;
  699. float.TryParse(str.ToString(), out result);
  700. return result;
  701. }
  702. public static string getMd5Hash(string input, string key)
  703. {
  704. MD5 md5Hasher = MD5.Create();
  705. string str = input + key;
  706. byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(str));
  707. StringBuilder sBuilder = new StringBuilder();
  708. for (int i = 0; i < data.Length; i++)
  709. {
  710. sBuilder.Append(data[i].ToString("x2"));
  711. }
  712. return sBuilder.ToString();
  713. }
  714. #endregion
  715. #region SummyUI的控件设置和数据绑定
  716. public static readonly UIStyle uiStyleCom = UIStyle.Blue; //R 80 G 160 B 255
  717. 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();
  718. public static void setUIDataGridView(UIDataGridView dgv, DataTable dt = null, string showTag = null, string hideTag = null)
  719. {
  720. dgv.Dock = DockStyle.Fill;
  721. dgv.ShowEditingIcon = false;
  722. dgv.ShowCellToolTips = false;
  723. dgv.AllowUserToAddRows = false;
  724. dgv.AllowUserToResizeRows = false;
  725. dgv.AllowUserToDeleteRows = false;
  726. dgv.AllowUserToOrderColumns = false;
  727. dgv.ReadOnly = true;
  728. dgv.MultiSelect = false;
  729. dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
  730. dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells;
  731. dgv.Style = UIStyle.Gray;// ComsStatic.uiStyleCom;
  732. dgv.RowPostPaint += Dgv_RowPostPaint;
  733. if (dt != null)
  734. {
  735. dgv.DataSource = dt;
  736. if (showTag != null)
  737. {
  738. string[] strShow = showTag.ToLower().Split(',');
  739. int indexStr = 0;
  740. for (int i = 0; i < dgv.Columns.Count; i++)
  741. {
  742. dgv.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
  743. dgv.Columns[i].HeaderText = dt.Columns[i].Caption;
  744. indexStr = strShow.ToList().IndexOf(dgv.Columns[i].Name.ToLower());
  745. if (indexStr > -1)
  746. dgv.Columns[i].DisplayIndex = indexStr;
  747. else
  748. dgv.Columns[i].Visible = false;
  749. }
  750. return;
  751. }
  752. if (string.IsNullOrEmpty(hideTag))
  753. {
  754. for (int i = 0; i < dgv.Columns.Count; i++)
  755. {
  756. dgv.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
  757. dgv.Columns[i].HeaderText = dt.Columns[i].Caption;
  758. if (HideEnableTag.Contains("," + dgv.Columns[i].Name.ToLower() + ","))
  759. {
  760. dgv.Columns[i].Visible = false;
  761. }
  762. }
  763. }
  764. else
  765. {
  766. for (int i = 0; i < dgv.Columns.Count; i++)
  767. {
  768. dgv.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
  769. dgv.Columns[i].HeaderText = dt.Columns[i].Caption;
  770. if (HideEnableTag.Contains("," + dgv.Columns[i].Name.ToLower() + ",") || hideTag.ToLower().Contains("," + dgv.Columns[i].Name.ToLower() + ","))
  771. {
  772. dgv.Columns[i].Visible = false;
  773. }
  774. }
  775. }
  776. }
  777. }
  778. private static void Dgv_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
  779. {
  780. DataGridView dgv = sender as DataGridView;
  781. Rectangle rect = new Rectangle(e.RowBounds.Location.X, e.RowBounds.Location.Y, dgv.RowHeadersWidth - 4, e.RowBounds.Height);
  782. TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(), dgv.RowHeadersDefaultCellStyle.Font, rect, dgv.RowHeadersDefaultCellStyle.ForeColor, TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
  783. }
  784. public static void BindUICombox(UIComboBox cbx, bool hasGX = true)
  785. {
  786. foreach (Layer lyr in ComsStatic.MapLayers)
  787. {
  788. if (!hasGX && lyr.Dataset.Name == ComsStatic.gsGuanXian.Name) continue;
  789. cbx.Items.Add(new DoListItem(lyr.Dataset.Name, lyr.Caption));
  790. }
  791. cbx.SelectedIndex = 0;
  792. }
  793. public static void BindDataTableOnCheckedListBox(DatasetVector _dv, CheckedListBox _cbg, string _ziduan)
  794. {
  795. Recordset rd = QueryRecordset(_dv, null, new string[] { _ziduan }, new string[] { _ziduan }, new string[] { _ziduan });
  796. rd.MoveFirst();
  797. string fieldValue = string.Empty;
  798. _cbg.Items.Clear();
  799. while (!rd.IsEOF)
  800. {
  801. fieldValue = rd.GetFieldValue(_ziduan)?.ToString();
  802. if (string.IsNullOrEmpty(fieldValue))
  803. _cbg.Items.Add("未知");
  804. else
  805. _cbg.Items.Add(fieldValue);
  806. rd.MoveNext();
  807. }
  808. ComsStatic.RecordsetDispose(rd);
  809. }
  810. public static void BindDataTableOnCheckedListBox(string gdFLDM, CheckedListBox _cbg, string _ziduan)
  811. {
  812. Recordset rd = QueryRecordset(ComsStatic.gsGuanDian, string.Format("FLDM='{0}'", gdFLDM), new string[] { _ziduan }, new string[] { _ziduan }, new string[] { _ziduan });
  813. rd.MoveFirst();
  814. string fieldValue = string.Empty;
  815. _cbg.Items.Clear();
  816. while (!rd.IsEOF)
  817. {
  818. fieldValue = rd.GetFieldValue(_ziduan)?.ToString();
  819. if (string.IsNullOrEmpty(fieldValue))
  820. _cbg.Items.Add("未知");
  821. else
  822. _cbg.Items.Add(fieldValue);
  823. rd.MoveNext();
  824. }
  825. ComsStatic.RecordsetDispose(rd);
  826. }
  827. public static void BindDataTableOnComboBox(DatasetVector _dv, UIComboBox _cbg, string _ziduan)
  828. {
  829. Recordset rd = QueryRecordset(_dv, null, new string[] { _ziduan }, new string[] { _ziduan }, new string[] { _ziduan });
  830. rd.MoveFirst();
  831. _cbg.Items.Clear();
  832. string fieldValue = string.Empty;
  833. while (!rd.IsEOF)
  834. {
  835. fieldValue = rd.GetFieldValue(_ziduan)?.ToString();
  836. if (string.IsNullOrEmpty(fieldValue))
  837. _cbg.Items.Add("未知");
  838. else
  839. _cbg.Items.Add(fieldValue);
  840. rd.MoveNext();
  841. }
  842. _cbg.SelectedIndex = 0;
  843. ComsStatic.RecordsetDispose(rd);
  844. }
  845. public static DataTable getPaperSize()
  846. {
  847. DataTable dt = new DataTable { TableName = "PaperSizeTable" };
  848. dt.Columns.Add("sizekey"); dt.Columns.Add("sizedesc");
  849. dt.Rows.Add("A4", "A4 210x297mm");
  850. dt.Rows.Add("A3", "A3 297x420mm");
  851. dt.Rows.Add("ISOA2", "标准纸面大小(A2)");
  852. dt.Rows.Add("ISOA1", "标准纸面大小(A1)");
  853. dt.Rows.Add("ISOA0", "标准纸面大小(A0)");
  854. return dt;
  855. }
  856. public static PaperSize getPaperSize(string size)
  857. {
  858. PaperSize ps = PaperSize.A4;
  859. switch (size)
  860. {
  861. case "A4": ps = PaperSize.A4; break;
  862. case "A3": ps = PaperSize.A3; break;
  863. case "ISOA2": ps = PaperSize.ISOA2; break;
  864. case "ISOA1": ps = PaperSize.ISOA1; break;
  865. case "ISOA0": ps = PaperSize.ISOA0; break;
  866. default: break;
  867. }
  868. return ps;
  869. }
  870. /// <summary>
  871. /// 设置CheckedListBox的选择状态 1全选 2反选 3全不选
  872. /// </summary>
  873. /// <param name="clb"></param>
  874. /// <param name="doState">1全选 2反选 3全不选</param>
  875. public static void CheckListBoxDo(CheckedListBox clb, int doState)
  876. {
  877. switch (doState)
  878. {
  879. case 1://全选
  880. for (int i = 0; i < clb.Items.Count; i++)
  881. {
  882. clb.SetItemChecked(i, true);
  883. }
  884. break;
  885. case 2://反选
  886. for (int i = 0; i < clb.Items.Count; i++)
  887. {
  888. bool ck = clb.GetItemChecked(i);
  889. clb.SetItemChecked(i, !ck);
  890. }
  891. break;
  892. case 3://全不选
  893. for (int i = 0; i < clb.Items.Count; i++)
  894. {
  895. clb.SetItemChecked(i, false);
  896. }
  897. break;
  898. default:
  899. break;
  900. }
  901. }
  902. private static ToolTip toolTips = new ToolTip();
  903. public static void CheckedListBox_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
  904. {
  905. CheckedListBox clb = sender as CheckedListBox;
  906. int index = clb.IndexFromPoint(e.Location);
  907. if (index != -1 && toolTips.GetToolTip(clb) != clb.Items[index].ToString())
  908. {
  909. toolTips.SetToolTip(clb, clb.Items[index].ToString());
  910. }
  911. }
  912. //2021年12月27日 15:22:36 18个引用
  913. public static void uiTextBox_num_KeyPress(object sender, KeyPressEventArgs e)
  914. {
  915. // 横向数字键的1-9 小键盘数字键的1-9 BackSpace 小键盘 . Del 字母按键 .>
  916. if ((e.KeyChar >= 48 || e.KeyChar <= 57) || (e.KeyChar >= 96 || e.KeyChar <= 105) || (e.KeyChar == 8) || (e.KeyChar == 110) || (e.KeyChar == 190))
  917. e.Handled = false;//可以输入
  918. else
  919. e.Handled = true;
  920. }
  921. public static void UIListBox_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
  922. {
  923. UIListBox clb = sender as UIListBox;
  924. int index = clb.IndexFromPoint(e.Location);
  925. if (index != -1 && toolTips.GetToolTip(clb) != clb.Items[index].ToString())
  926. {
  927. toolTips.SetToolTip(clb, clb.Items[index].ToString());
  928. }
  929. }
  930. #endregion
  931. #region 其他计算操作
  932. /// <summary>
  933. /// 通过起点的坐标和数值、终点的坐标和数值,计算线上交点的数值
  934. /// </summary>
  935. /// <param name="gx_start">起点坐标</param>
  936. /// <param name="gx_start_gc">起点数值</param>
  937. /// <param name="gx_end">终点坐标</param>
  938. /// <param name="gx_end_gc">终点数值</param>
  939. /// <param name="JiaoDian">线上的交点坐标</param>
  940. /// <returns>交点数值</returns>
  941. public static double getPointHeight(Point2D start, double startValue, Point2D end, double endValue, Point2D JiaoDian)
  942. {
  943. if (!Geometrist.IsPointOnLine(JiaoDian, start, end, false)) return 0.0;
  944. if (startValue == endValue) return Math.Round(startValue, 2);
  945. double JiaoDianValue = 0.0D;
  946. if (startValue < endValue)//确保起点数据 大于 终点数据
  947. {
  948. double temp = startValue;
  949. startValue = endValue;
  950. endValue = temp;
  951. Point2D temPoint = start;
  952. start = end;
  953. end = temPoint;
  954. }
  955. // 参考链接 https://zhuanlan.zhihu.com/p/43660758 下面的公式可以用,是正式的,这里备份一下
  956. //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)));
  957. 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)));
  958. if (JiaoDianValue == double.PositiveInfinity || JiaoDianValue == double.NegativeInfinity)
  959. {
  960. JiaoDianValue = endValue;
  961. }
  962. return Math.Round(JiaoDianValue, 2);
  963. }
  964. /// <summary>
  965. /// 返回Double数组的最大值或者最小值
  966. /// </summary>
  967. /// <param name="dblist"></param>
  968. /// <param name="isMax">True表示最大值,false表示最小值</param>
  969. /// <returns></returns>
  970. public static double getMaxMin(double[] dblist, bool isMax)
  971. {
  972. double finalValue = dblist[0];
  973. if (isMax)//最大值
  974. {
  975. for (int i = 0; i < dblist.Length; i++)
  976. {
  977. if (finalValue < dblist[i])
  978. finalValue = dblist[i];
  979. }
  980. }
  981. else
  982. {
  983. for (int i = 0; i < dblist.Length; i++)
  984. {
  985. if (finalValue > dblist[i])
  986. finalValue = dblist[i];
  987. }
  988. }
  989. return finalValue;
  990. }
  991. /// <summary>
  992. /// 将逗号分隔的csv格式文件,转换为DataTable
  993. /// </summary>
  994. /// <param name="filePath">csv文件路径</param>
  995. /// <param name="FirstField">首行是否是标题行</param>
  996. /// <returns></returns>
  997. public static DataTable CSVToDataTable(string filePath, bool FirstField)
  998. {
  999. DataTable table = new DataTable();
  1000. bool isField = true;
  1001. using (StreamReader reader = new StreamReader(filePath, Encoding.GetEncoding("gb2312"), false))
  1002. {
  1003. string line = string.Empty;
  1004. while (reader.Peek() > 0)
  1005. {
  1006. line = reader.ReadLine();
  1007. if (string.IsNullOrEmpty(line) || line.Split(',').Length == 0) continue;
  1008. string[] split = line.Split(',');
  1009. if (isField)
  1010. {
  1011. isField = false;
  1012. if (FirstField)//首行是标题
  1013. {
  1014. foreach (string str in split) table.Columns.Add(str);
  1015. continue;
  1016. }
  1017. else
  1018. {
  1019. for (int i = 0; i < split.Length; i++) table.Columns.Add("列" + i.ToString());
  1020. }
  1021. }
  1022. DataRow newRow = table.NewRow();
  1023. for (int j = 0; j < split.Length; j++)
  1024. {
  1025. newRow[j] = split[j].Trim('"');
  1026. }
  1027. table.Rows.Add(newRow);
  1028. }
  1029. return table;
  1030. }
  1031. }
  1032. #endregion
  1033. #region postgresSql
  1034. /// <summary>
  1035. /// 获取本机所有IPV4地址列表
  1036. /// </summary>
  1037. /// <returns>本机所有IPV4地址列表,以分号分隔</returns>
  1038. public static string GetSelfIpv4List()
  1039. {
  1040. StringBuilder ips = new StringBuilder();
  1041. try
  1042. {
  1043. IPHostEntry IpEntry = Dns.GetHostEntry(Dns.GetHostName());
  1044. foreach (IPAddress ipa in IpEntry.AddressList)
  1045. {
  1046. if (ipa.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
  1047. { ips.AppendFormat("{0};", ipa.ToString()); break; }
  1048. }
  1049. }
  1050. catch { }
  1051. return ips.ToString();
  1052. }
  1053. public static string GetSql(string select, List<string> wheres, string orderby = null, string groupby = null)
  1054. {
  1055. StringBuilder sb = new StringBuilder(select);
  1056. if (wheres.Count > 0)
  1057. {
  1058. sb.Append(" where " + string.Join(" and ", wheres.ToArray()));
  1059. }
  1060. if (!string.IsNullOrEmpty(orderby)) sb.Append(orderby);
  1061. if (!string.IsNullOrEmpty(groupby)) sb.Append(groupby);
  1062. return sb.ToString();
  1063. }
  1064. public static void pgAddLogin(string n, string p, string c)
  1065. {
  1066. string sql = string.Format(" INSERT INTO userlogin(lgName,lgtime,lgIP,lgCup)VALUES('{0}','{1}','{2}','{3}') returning id;", n, DateTime.Now.ToLocalTime(), p, c);
  1067. object obj = new NpgsqlHelper().ExecuteScalar(sql);
  1068. ComsStatic.Instance.SetLoginID(StringToInt(obj));
  1069. }
  1070. public static void pgAddLoginm(string n)
  1071. {
  1072. if (ComsStatic.LoginID == 0) return;
  1073. string sql = string.Format(" INSERT INTO userloginm(lgid,czms,cztime)VALUES('{0}','{1}','{2}') returning id;", ComsStatic.LoginID, n, DateTime.Now.ToLocalTime());
  1074. new NpgsqlHelper().ExecuteScalar(sql);
  1075. }
  1076. //public static bool pgDeleteGuanDian(string bsm)
  1077. //{
  1078. // string sql = string.Format(" DELETE FROM {0} WHERE bsm='{1}' RETURNING bsm ", gsGuanDian.TableName, bsm);
  1079. // object obj = new NpgsqlHelper().ExecuteScalar(sql);
  1080. // if (obj == null) return false;
  1081. // return true;
  1082. //}
  1083. //public static bool pgDeleteGuanDian(string dvTableName, string bsm)
  1084. //{
  1085. // string sql = string.Format(" DELETE FROM {0} WHERE bsm='{1}' RETURNING bsm ", dvTableName, bsm);
  1086. // object obj = new NpgsqlHelper().ExecuteScalar(sql);
  1087. // if (obj == null) return false;
  1088. // return true;
  1089. //}
  1090. #endregion
  1091. #region 管网标注的配置
  1092. /// <summary>
  1093. ///线样式 LineColor = Color.Brown, LineWidth = 0.5
  1094. /// </summary>
  1095. public static GeoStyle geoStyle_Brown_05mm = new GeoStyle() { LineColor = Color.Brown, LineWidth = 0.5 };
  1096. /// <summary>
  1097. ///点样式 LineColor = Color.Red, MarkerSize = new Size2D(5, 5)
  1098. /// </summary>
  1099. public static GeoStyle geoStyle_Red_Mark5mm = new GeoStyle { LineColor = Color.Red, MarkerSize = new Size2D(5, 5) };
  1100. /// <summary>
  1101. /// 标注样式 ForeColor = Color.Brown, IsSizeFixed = true, FontHeight = 6, Alignment = TextAlignment.BottomLeft
  1102. /// </summary>
  1103. public static TextStyle textStyle_Brown_6mm_BottomLeft = new TextStyle { ForeColor = Color.Brown, IsSizeFixed = true, FontHeight = 6, Alignment = TextAlignment.BottomLeft };
  1104. /// <summary>
  1105. ///边框线样式 LineColor = Color.Red, LineWidth = 1, FillOpaqueRate = 10
  1106. /// </summary>
  1107. public static GeoStyle geoStyle_Red_1mm_OpaqueRate = new GeoStyle { LineColor = Color.Red, LineWidth = 1, FillOpaqueRate = 10 };
  1108. public static Point2D GetPoint2D(object x, object y)
  1109. {
  1110. return new Point2D(StringToDouble(x), StringToDouble(y));
  1111. }
  1112. /// <summary>
  1113. /// 获取标注风格配置的TextStyle
  1114. /// </summary>
  1115. /// <returns></returns>
  1116. public static TextStyle BiaoZhuFengGe()
  1117. {
  1118. QueryParameter queryParameter = new QueryParameter
  1119. {
  1120. AttributeFilter = " pzlx='标注风格配置' and pzKey='TextStyleKey' ",
  1121. ResultFields = new string[] { "pzValue" },
  1122. CursorType = CursorType.Static
  1123. };
  1124. Recordset _rd = ComsStatic.dvConfig.Query(queryParameter);
  1125. if (_rd.RecordCount != 1) return textStyle_Brown_6mm_BottomLeft;
  1126. TextStyle ts = new TextStyle();
  1127. bool fromResult = ts.FromXML(_rd.GetFieldValue("pzValue").ToString());
  1128. ComsStatic.RecordsetDispose(_rd);
  1129. if (!fromResult) return textStyle_Brown_6mm_BottomLeft;
  1130. return ts;
  1131. }
  1132. #endregion
  1133. }
  1134. public class DoListItem
  1135. {
  1136. private string _key = string.Empty;
  1137. private string _value = string.Empty;
  1138. public DoListItem(string pKey, string pValue) { _key = pKey; _value = pValue; }
  1139. public override string ToString() { return _value; }
  1140. public string Key { get => _key; set => _key = value; }
  1141. public string Value { get => _value; set => _value = value; }
  1142. }
  1143. public class DoTrackingPoint
  1144. {
  1145. private Timer timer = new Timer() { Enabled = false, Interval = 300 };
  1146. private int Timertag = 1;
  1147. private GeoPoint markPoint = null;
  1148. public void Doing(double x, double y)
  1149. {
  1150. timer.Tick += Timer_Tick;
  1151. Point2D p2d = new Point2D(x, y);
  1152. ComsStatic.MapControl.Map.Center = p2d;
  1153. ComsStatic.MapControl.Map.Refresh();
  1154. markPoint = new GeoPoint(p2d);
  1155. markPoint.Style = new GeoStyle() { MarkerSize = new Size2D(5, 5), LineColor = Color.Red };
  1156. timer.Enabled = true; timer.Start();
  1157. }
  1158. private void Timer_Tick(object sender, EventArgs e)
  1159. {
  1160. if (Timertag == 6)
  1161. {
  1162. timer.Stop();
  1163. timer.Enabled = false;
  1164. Timertag = 1;
  1165. int index = ComsStatic.MapControl.Map.TrackingLayer.IndexOf("DoInterestPoint");
  1166. if (index > -1) ComsStatic.MapControl.Map.TrackingLayer.Remove(index);
  1167. ComsStatic.MapControl.Map.RefreshTrackingLayer();
  1168. return;
  1169. }
  1170. else if (Timertag % 2 == 1 && markPoint != null)
  1171. {
  1172. ComsStatic.MapControl.Map.TrackingLayer.Add(markPoint, "DoInterestPoint");
  1173. }
  1174. else //if (Timertag % 2 == 0)
  1175. {
  1176. int index = ComsStatic.MapControl.Map.TrackingLayer.IndexOf("DoInterestPoint");
  1177. if (index > -1) ComsStatic.MapControl.Map.TrackingLayer.Remove(index);
  1178. }
  1179. Timertag++;
  1180. ComsStatic.MapControl.Map.RefreshTrackingLayer();
  1181. }
  1182. }
  1183. public class LayerEx
  1184. {
  1185. //public LayerEx() { }
  1186. private string caption;
  1187. private string fldm;
  1188. private string dataset;
  1189. private DatasetVector datasetVector;
  1190. private int markerSymbolID = 0;
  1191. private double markerSize = 0;
  1192. private double maxVisibleScale = 0;
  1193. private double minVisibleScale = 0;
  1194. private bool isEditable = false;
  1195. private bool isVisible = true;
  1196. private int index;
  1197. private Color lineColor = Color.Blue;
  1198. private double lineWidth;
  1199. public string Caption { get => caption; set => caption = value; }
  1200. public string FLDM { get => fldm; set => fldm = value; }
  1201. public string Dataset { get => dataset; set => dataset = value; }
  1202. public DatasetVector DatasetVector { get => datasetVector; set => datasetVector = value; }
  1203. public int MarkerSymbolID { get => markerSymbolID; set => markerSymbolID = value; }
  1204. public double MarkerSize { get => markerSize; set => markerSize = value; }
  1205. public double MaxVisibleScale { get => maxVisibleScale; set => maxVisibleScale = value; }
  1206. public double MinVisibleScale { get => minVisibleScale; set => minVisibleScale = value; }
  1207. public bool IsEditable { get => isEditable; set => isEditable = value; }
  1208. public bool IsVisible { get => isVisible; set => isVisible = value; }
  1209. public int Index { get => index; set => index = value; }
  1210. public double LineWidth { get => lineWidth; set => lineWidth = value; }
  1211. public Color LineColor { get => lineColor; set => lineColor = value; }
  1212. }
  1213. }