ComsStatic.cs 42 KB

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