123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782 |
- using Sunny.UI;
- using SuperMap.Data;
- using SuperMap.Mapping;
- using SuperMap.UI;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using WeifenLuo.WinFormsUI.Docking;
- namespace WWPipeLine.MapBasic
- {
- public class ComsStatic
- {
- //private static ComsStatic m_Instance;
- public static ComsStatic Instance { get => new ComsStatic(); }
- //public static ComsStatic Instance
- //{
- // get
- // {
- // if (m_Instance == null)
- // m_Instance = new ComsStatic();
- // return m_Instance;
- // }
- //}
- //private static Workspace m_Workspace;
- //public void SetWorkspace(Workspace ws) { m_Workspace = ws; }
- private static MapControl m_MapControl;
- public void SetMapControl(MapControl mp) { m_MapControl = mp; }
- private static DockPanel m_DockPanel;
- public void SetDockPanel(DockPanel dp) { m_DockPanel = dp; }
- private static IMessageInterface m_IMessageInterface;
- public void SetIMessageInterface(IMessageInterface mi) { m_IMessageInterface = mi; }
- #region Workspace MapControl DatasetVector
- /// <summary>
- /// 当前工作空间的地图索引值
- /// <para>0:DaAnPostgres 包括供水和底图</para>
- /// </summary>
- public static Int32 WorkspaceMapIndex = 0;
- /// <summary>
- /// 当前工作空间的数据源索引值
- /// <para>0:MapWorld_vec 1:MapWorld_cva 2:DaAnPostgres</para>
- /// </summary>
- public static Datasource Datasource { get => m_MapControl.Map.Workspace.Datasources[2]; }
- public static Workspace Workspace { get => m_MapControl.Map.Workspace; }
- public static MapControl MapControl { get => m_MapControl; }
- public static IMessageInterface MessageInterface { get => m_IMessageInterface; }
- public static DockPanel DockPanel { get => m_DockPanel; }
- /// <summary>
- /// 配置表
- /// </summary>
- public static DatasetVector dvJSLK_PZ
- {
- get => Datasource.Datasets["JSLK_PZ"] as DatasetVector;
- }
- /// <summary>
- /// 供水节点表
- /// </summary>
- public static DatasetVector dvJSJDPT
- {
- get => Datasource.Datasets["JSJDPT"] as DatasetVector;
- }
- /// <summary>
- /// 供水管线表
- /// </summary>
- public static DatasetVector dvJSLK
- {
- get => Datasource.Datasets["JSLK"] as DatasetVector;
- }
- /// <summary>
- /// 网络数据集 分析用
- /// </summary>
- public static DatasetVector dvNetwork
- {
- get => Datasource.Datasets["CL_PostGreSQL_Network"] as DatasetVector;
- }
- public static Layers MapLayers { get => m_MapControl.Map.Layers; }
-
- public static DataTable getLayers()
- {
- DataTable dt = new DataTable { TableName = "LayersDataTable" };
- dt.Columns.Add("LayerName"); dt.Columns.Add("LayerCaption"); dt.Columns.Add("LayerDatasetName");
- DataRow dataRow;
- foreach (Layer r in MapLayers)
- {
- if (r.Caption.Contains("矢量")) continue;
- dataRow = dt.NewRow();
- dataRow[0] = r.Name;
- dataRow[1] = r.Caption;
- dataRow[2] = r.Dataset.Name;
- dt.Rows.Add(dataRow);
- }
- return dt;
- }
- ///// <summary>
- ///// 删除除2个底图外的图层
- ///// </summary>
- //public static void CreateLayers()
- //{
- // if (m_MapControl.Map.Layers.Count > 2)
- // m_MapControl.Map.Layers.RemoveRange(0, m_MapControl.Map.Layers.Count - 2);
- // LayerSettingVector layerSetting;
- // GeoStyle style;
- // Layer lyr = null;
- // foreach (LayerEx layerEx in layerExs)
- // {
- // Dataset ds = Datasource.Datasets[layerEx.Dataset];
- // if (ds is null) continue;
- // layerSetting = new LayerSettingVector();
- // style = new GeoStyle();
- // style.LineColor = layerEx.LineColor;
- // style.LineWidth = layerEx.LineWidth;
- // layerSetting.Style = style;
- // lyr = m_MapControl.Map.Layers.Add(ds, layerSetting, true);
- // lyr.Caption = layerEx.Caption;
- // }
- //}
- /// <summary>
- /// 设置所有图层为不可编辑状态
- /// </summary>
- public static void SetLayerIsEditableFalse()
- {
- foreach (Layer r in MapLayers)
- {
- r.IsEditable = false;
- }
- }
- public static void SetLayerIsEditableFalse(string layerName, bool isEditable)
- {
- foreach (Layer r in MapLayers)
- {
- if (r.Name == layerName || r.Caption == layerName || r.Dataset.Name == layerName)
- r.IsEditable = isEditable;
- else
- r.IsEditable = !isEditable;
- }
- }
- /// <summary>
- /// 设置图层是否可选择
- /// </summary>
- /// <param name="layerName"></param>
- /// <param name="isSelect"></param>
- public static void SetLayersIsSelectableFalse(string layerName, bool isSelect)
- {
- foreach (Layer r in MapLayers)
- {
- if (r.Name == layerName || r.Caption == layerName || r.Dataset.Name == layerName)
- r.IsSelectable = isSelect;
- else
- r.IsSelectable = !isSelect;
- }
- }
- /// <summary>
- /// 依据TrackingLayer的Name清空
- /// </summary>
- /// <param name="tag"></param>
- public static void TrackingLayerRemove(string tag)
- {
- int index = MapControl.Map.TrackingLayer.IndexOf(tag);
- while (index != -1)
- {
- MapControl.Map.TrackingLayer.Remove(index);
- index = MapControl.Map.TrackingLayer.IndexOf(tag);
- }
- }
- /// <summary>
- /// 关闭当前主程序中除了Tag=MainControls的其他所有窗体
- /// <para>默认4个主要窗体: 主窗体 工具栏 鹰眼 图层</para>
- /// </summary>
- public static void closeFormTagMainControls()
- {
- foreach (Form form in Application.OpenForms)
- {
- if (form.Tag?.ToString() != "MainControls")
- {
- form.Close(); break;
- }
- }
- if (Application.OpenForms.Count > 4)
- {
- closeFormTagMainControls();
- }
- }
- #endregion
- #region SuperMap.Data相关操作
- public static Recordset QueryRecordset(DatasetVector dv, string sqlWhere, string[] resultFields = null, string[] groupBy = null, string[] orderBy = null)
- {
- QueryParameter para = new QueryParameter();
- if (sqlWhere != null) para.AttributeFilter = sqlWhere;
- if (resultFields != null) para.ResultFields = Commons.StringEx.setToLower(resultFields);
- if (groupBy != null) para.GroupBy = Commons.StringEx.setToLower(groupBy);
- if (orderBy != null) para.OrderBy = Commons.StringEx.setToLower(orderBy);
- para.CursorType = CursorType.Static;
- return dv.Query(para);
- }
- public static Recordset QueryRecordsetDynamic(DatasetVector dv, string sqlWhere, string[] resultFields = null, string[] groupBy = null, string[] orderBy = null)
- {
- QueryParameter para = new QueryParameter();
- if (sqlWhere != null) para.AttributeFilter = sqlWhere;
- if (resultFields != null) para.ResultFields = Commons.StringEx.setToLower(resultFields);
- if (groupBy != null) para.GroupBy = Commons.StringEx.setToLower(groupBy);
- if (orderBy != null) para.OrderBy = Commons.StringEx.setToLower(orderBy);
- para.CursorType = CursorType.Dynamic;
- return dv.Query(para);
- }
- public static DataTable QueryDataTable(DatasetVector dv, string sqlWhere, string[] resultFields = null, string[] groupBy = null, string[] orderBy = null)
- {
- QueryParameter para = new QueryParameter();
- if (sqlWhere != null) para.AttributeFilter = sqlWhere;
- if (resultFields != null) para.ResultFields = Commons.StringEx.setToLower(resultFields);
- if (groupBy != null) para.GroupBy = Commons.StringEx.setToLower(groupBy);
- if (orderBy != null) para.OrderBy = Commons.StringEx.setToLower(orderBy);
- para.CursorType = CursorType.Static;
- Recordset rd = dv.Query(para);
- return RecordsetToDataTable(rd, dv.Name);
- }
- public static DataTable RecordsetToDataTable(Recordset recordset, string tableName = null)
- {
- if (string.IsNullOrEmpty(tableName)) tableName = recordset.Dataset.Name;
- DataTable dt = new DataTable { TableName = tableName };
- FieldInfos fieldInfos = recordset.GetFieldInfos();
- Int32 count = fieldInfos.Count;
- DataColumn dataColumn;
- for (Int32 i = 0; i < count; i++)
- {
- dataColumn = new DataColumn { ColumnName = fieldInfos[i].Name, Caption = fieldInfos[i].Caption };
- dt.Columns.Add(dataColumn);
- }
- recordset.MoveFirst();
- Int32 length = recordset.RecordCount;
- DataRow dr;
- for (int i = 0; i < length; i++)
- {
- dr = dt.NewRow();
- var actIndex = 0;
- for (Int32 j = 0; j < count; j++)
- {
- var objValue = recordset.GetFieldValue(j);
- string value = objValue?.ToString();
- dr[actIndex++] = value;
- }
- dt.Rows.Add(dr);
- recordset.MoveNext();
- }
- return dt;
- }
- public static List<DataTable> TongJiFieldGroupCount(DatasetVector dv, string[] strField)
- {
- Recordset rd = null;
- List<DataTable> dts = new List<DataTable>();
- DataTable dt;
- DataRow dr;
- string fieldValue = string.Empty;
- foreach (string field in strField)
- {
- string[] ck = new string[] { field };
- rd = ComsStatic.QueryRecordset(dv, null, ck, ck, ck);
- dt = new DataTable(); dt.Columns.Add("类别"); dt.Columns.Add("数量");
- if (!HasField(dv, field)) continue;
- dt.TableName = rd.GetFieldInfos()[field].Caption;
- if (rd.RecordCount == 0)//该字段所有值均为null 不能GroupBy
- {
- dr = dt.NewRow();
- dr["类别"] = "未知"; dr["数量"] = dv.RecordCount;
- dt.Rows.Add(dr);
- }
- else
- {
- rd.MoveFirst();
- while (!rd.IsEOF)
- {
- dr = dt.NewRow();
- fieldValue = rd.GetFieldValue(field)?.ToString();
- if (string.IsNullOrEmpty(fieldValue))
- {
- dr["类别"] = "未知";
- dr["数量"] = dv.Query(string.Format("{0} is null", field), CursorType.Static).RecordCount;
- }
- else
- {
- dr["类别"] = fieldValue;
- dr["数量"] = dv.Query(string.Format("{0}='{1}'", field, fieldValue), CursorType.Static).RecordCount;
- }
- dt.Rows.Add(dr);
- rd.MoveNext();
- }
- }
- dr = dt.NewRow();
- dr["类别"] = dt.TableName + "总量"; dr["数量"] = dv.RecordCount;
- dt.Rows.Add(dr);
- dts.Add(dt);
- }
- ComsStatic.RecordsetDispose(rd);
- return dts;
- }
- public static string getSqlCheckListBox(CheckedListBox clb, string field)
- {
- StringBuilder sb = new StringBuilder();
- if (clb.CheckedItems.Count > 0)
- {
- sb.Append(" AND (1=2 ");
- foreach (string str in clb.CheckedItems)
- {
- if (str == "未知")
- sb.AppendFormat(" OR {0} is null ", field);
- else
- sb.AppendFormat(" OR {0}='{1}'", field, str);
- }
- sb.Append(" ) ");
- }
- return sb.ToString();
- }
- public static bool HasField(DatasetVector m_DatasetVector, string _field)
- {
- bool hasField = false;
- FieldInfos fieldInfos = m_DatasetVector.FieldInfos;
- for (int i = 0; i < fieldInfos.Count; i++)
- {
- if (fieldInfos[i].Name.ToLower() == _field)
- {
- hasField = true; break;
- }
- }
- return hasField;
- }
- public static bool HasField(Recordset m_Recordset, string _field)
- {
- bool hasField = false;
- FieldInfos fieldInfos = m_Recordset.GetFieldInfos();
- for (int i = 0; i < fieldInfos.Count; i++)
- {
- if (fieldInfos[i].Name.ToLower() == _field)
- {
- hasField = true; break;
- }
- }
- return hasField;
- }
- public static void RecordsetDispose(Recordset rd)
- {
- if (!(rd == null)) { rd.Close(); rd.Dispose(); }
- }
- public static void EditHistoryUndo(EditHistory eh)
- {
- while (eh.CanUndo) { eh.Undo(); }
- eh.Clear(); eh.Dispose();
- }
- public static DataTable GetJSLKbyJSJDPT(DataTable dt)
- {
- #region 构造 管线的起始管点和终点管点 信息
- DataColumn dataColumn;
- dataColumn = new DataColumn { ColumnName = "qdsmid", Caption = "起点SmID" }; dt.Columns.Add(dataColumn);
- dataColumn = new DataColumn { ColumnName = "qdsmx", Caption = "起点X坐标" }; dt.Columns.Add(dataColumn);
- dataColumn = new DataColumn { ColumnName = "qdsmy", Caption = "起点Y坐标" }; dt.Columns.Add(dataColumn);
- dataColumn = new DataColumn { ColumnName = "qddmgc", Caption = "起点地面高程" }; dt.Columns.Add(dataColumn);
- dataColumn = new DataColumn { ColumnName = "qdgdms", Caption = "起点埋深" }; dt.Columns.Add(dataColumn);
- dataColumn = new DataColumn { ColumnName = "qdgc", Caption = "起点高程" }; dt.Columns.Add(dataColumn);
- dataColumn = new DataColumn { ColumnName = "zdsmid", Caption = "终点SmID" }; dt.Columns.Add(dataColumn);
- dataColumn = new DataColumn { ColumnName = "zdsmx", Caption = "终点X坐标" }; dt.Columns.Add(dataColumn);
- dataColumn = new DataColumn { ColumnName = "zdsmy", Caption = "终点Y坐标" }; dt.Columns.Add(dataColumn);
- dataColumn = new DataColumn { ColumnName = "zddmgc", Caption = "终点地面高程" }; dt.Columns.Add(dataColumn);
- dataColumn = new DataColumn { ColumnName = "zdgdms", Caption = "终点埋深" }; dt.Columns.Add(dataColumn);
- dataColumn = new DataColumn { ColumnName = "zdgc", Caption = "终点高程" }; dt.Columns.Add(dataColumn);
- #endregion
- DataTable dtJSJDPT;
- foreach (DataRow dr in dt.Rows)
- {
- dtJSJDPT = QueryDataTable(dvJSJDPT, string.Format(" bsm='{0}' ", dr["qsdh"]));
- if (dtJSJDPT.Rows.Count == 1)
- {
- dr["qdsmid"] = dtJSJDPT.Rows[0]["smid"]; dr["qdsmx"] = dtJSJDPT.Rows[0]["x"]; dr["qdsmy"] = dtJSJDPT.Rows[0]["y"];
- dr["qddmgc"] = dtJSJDPT.Rows[0]["dmgc"]; dr["qdgdms"] = dtJSJDPT.Rows[0]["ms"];
- //dr["qdgc"] = Math.Round(double.Parse(dtJSJDPT.Rows[0]["dmgc"]?.ToString()) - double.Parse(dtJSJDPT.Rows[0]["ms"]?.ToString()), 2);
- dr["qdgc"] = StringToDouble(dtJSJDPT.Rows[0]["dmgc"], 2) - StringToDouble(dtJSJDPT.Rows[0]["ms"], 2);
- }
- dtJSJDPT = QueryDataTable(dvJSJDPT, string.Format(" bsm='{0}' ", dr["zddh"]));
- if (dtJSJDPT.Rows.Count == 1)
- {
- dr["zdsmid"] = dtJSJDPT.Rows[0]["smid"]; dr["zdsmx"] = dtJSJDPT.Rows[0]["x"]; dr["zdsmy"] = dtJSJDPT.Rows[0]["y"];
- dr["zddmgc"] = dtJSJDPT.Rows[0]["dmgc"]; dr["zdgdms"] = dtJSJDPT.Rows[0]["ms"];
- //dr["zdgc"] = Math.Round(double.Parse(dtJSJDPT.Rows[0]["dmgc"]?.ToString()) - double.Parse(dtJSJDPT.Rows[0]["ms"]?.ToString()), 2);
- dr["zdgc"] = StringToDouble(dtJSJDPT.Rows[0]["dmgc"], 2) - StringToDouble(dtJSJDPT.Rows[0]["ms"], 2);
- }
- }
- return dt;
- }
- public static Dictionary<string, object> getGuanXianPeiZhi(string pzlx)
- {
- DatasetVector dv = ComsStatic.dvJSLK_PZ;
- Dictionary<string, object> dic = new Dictionary<string, object>();
- Recordset _rd = dv.Query(string.Format(" gxpzlx='{0}' ", pzlx), CursorType.Static);
- if (_rd.RecordCount == 0) return dic;
- _rd.MoveFirst();
- while (!_rd.IsEOF)
- {
- string gxcz = _rd.GetFieldValue("gxcz").ToString();
- dic.Add(gxcz + "_gxyjnx", _rd.GetFieldValue("gxyjnx"));
- dic.Add(gxcz + "_gxbznx", _rd.GetFieldValue("gxbznx"));
- dic.Add(gxcz + "_gxms", _rd.GetFieldValue("gxms"));
- _rd.MoveNext();
- }
- return dic;
- }
- #region 在当前的DatasetVector中,获取指定列名的最大值和最小值
- /// <summary>
- /// 在当前的DatasetVector中,获取指定列名的最大值
- /// </summary>
- /// <param name="fieldName"></param>
- /// <returns></returns>
- public static double GetMaxValue(DatasetVector dv, string fieldName)
- {
- var val = MinMaxValue(dv, fieldName, 1);
- if (val == null) return double.NaN;
- else return double.Parse(val.ToString());
- }
- /// <summary>
- /// 在当前的DatasetVector中,获取指定列名的最小值
- /// </summary>
- /// <param name="fieldName"></param>
- /// <returns></returns>
- public static double GetMinValue(DatasetVector dv, string fieldName)
- {
- var val = MinMaxValue(dv, fieldName, -1);
- if (val == null) return double.NaN;
- else return double.Parse(val.ToString());
- }
- /// <summary>
- /// 在当前的DatasetVector中,获取指定列名的最大值和最小值
- /// </summary>
- /// <param name="fieldName"></param>
- /// <returns></returns>
- public static double[] GetMinMaxValue(DatasetVector dv, string fieldName)
- {
- var val = MinMaxValue(dv, fieldName, 0);
- if (val == null) return new double[] { };
- else return (double[])val;
- }
- /// <summary>
- /// 在当前的DatasetVector中,获取指定列名的最大值、最小值
- /// </summary>
- /// <param name="fieldName">列名</param>
- /// <param name="min">min = 0,获取最小值和最大值;-1时获取最小值,1时获取最大值</param>
- /// <returns></returns>
- private static object MinMaxValue(DatasetVector dv, string fieldName, int minMax = 0)
- {
- object result = null;
- if (minMax == 1)// 最大值
- {
- result = dv.Statistic(fieldName, StatisticMode.Max);
- }
- else if (minMax == -1)//最小值
- {
- result = dv.Statistic(fieldName, StatisticMode.Min);
- }
- else //最大值和最小值
- {
- result = new double[] { dv.Statistic(fieldName, StatisticMode.Max), dv.Statistic(fieldName, StatisticMode.Min) };
- }
- return result;
- }
- #endregion
- #endregion
- #region ShowUIMessageTip界面提示信息
- public static void ShowUIMessageTipOKorError(bool _result, string msg = "")
- {
- if (_result)
- {
- ShowOKLog(msg + " 操作成功!");
- }
- else
- {
- ShowErrorLog(msg + " 操作失败!");
- }
- }
- public static void ShowErrorLog(string msg)
- {
- Commons.LogHelper.Error(msg);
- Sunny.UI.UIMessageTip.ShowError(msg, 2000, false, new Point(800, 400), true);
- }
- public static void ShowOKLog(string msg)
- {
- Commons.LogHelper.Info(msg);
- Sunny.UI.UIMessageTip.ShowOk(msg, 2000, false, new Point(800, 400), true);
- }
- #endregion
- #region String操作
- public static double StringToDouble(object str, int dleng = -1)
- {
- if (str is null) return 0;
- double result = 0.0D;
- double.TryParse(str.ToString(), out result);
- if (dleng != -1)
- {
- result = Math.Round(result, dleng);
- }
- return result;
- }
- public static int StringToInt(object str)
- {
- int result = 0;
- int.TryParse(str.ToString(), out result);
- return result;
- }
- public static string GetStrAddChar(object str, char ch)
- {
- return ch + str.ToString() + ch;
- }
- #endregion
- #region SummyUI的控件设置和数据绑定
- public static void setDataGridView(UIDataGridView dgv, DataTable dt = null)
- {
- dgv.Dock = DockStyle.Fill;
- dgv.ShowEditingIcon = false;
- dgv.ShowCellToolTips = false;
- dgv.AllowUserToAddRows = false;
- dgv.AllowUserToResizeRows = false;
- dgv.AllowUserToDeleteRows = false;
- dgv.AllowUserToOrderColumns = false;
- dgv.ReadOnly = true;
- dgv.MultiSelect = false;
- dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
- dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells;
- dgv.Style = UIStyle.Gray;
- dgv.RowPostPaint += Dgv_RowPostPaint;
- if (dt != null)
- {
- dgv.DataSource = dt;
- for (int i = 0; i < dgv.Columns.Count; i++)
- {
- dgv.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
- dgv.Columns[i].HeaderText = dt.Columns[i].Caption;
- string hideColums = ",enabled,shape_length,objectid,tcdw,cqbh,gcbh,zcbh,ancillaryrole,rotateangle,tfh,".ToUpper();
- bool isVisible = hideColums.Contains("," + dgv.Columns[i].Name.ToUpper() + ",") ? true : false;
- if ((dgv.Columns[i].Name.ToUpper().StartsWith("SM") && dgv.Columns[i].Name.ToUpper() != "SMID") || isVisible)//不显示SM开头的列 排除SMID显示
- {
- dgv.Columns[i].Visible = false;
- }
- }
- }
- }
- private static void Dgv_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
- {
- var dgv = sender as DataGridView;
- Rectangle rect = new Rectangle(e.RowBounds.Location.X, e.RowBounds.Location.Y, dgv.RowHeadersWidth - 4, e.RowBounds.Height);
- TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(), dgv.RowHeadersDefaultCellStyle.Font, rect, dgv.RowHeadersDefaultCellStyle.ForeColor, TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
- }
- public static void BindDataTableOnCheckedListBox(DatasetVector _dv, CheckedListBox _cbg, string _ziduan)
- {
- Recordset rd = QueryRecordset(_dv, null, new string[] { _ziduan }, new string[] { _ziduan }, new string[] { _ziduan });
- rd.MoveFirst();
- string fieldValue = string.Empty;
- _cbg.Items.Clear();
- while (!rd.IsEOF)
- {
- fieldValue = rd.GetFieldValue(_ziduan)?.ToString();
- if (string.IsNullOrEmpty(fieldValue))
- _cbg.Items.Add("未知");
- else
- _cbg.Items.Add(fieldValue);
- rd.MoveNext();
- }
- }
- public static void BindDataTableOnComboBox(DatasetVector _dv, UIComboBox _cbg, string _ziduan)
- {
- Recordset rd = QueryRecordset(_dv, null, new string[] { _ziduan }, new string[] { _ziduan }, new string[] { _ziduan });
- rd.MoveFirst();
- _cbg.Items.Clear();
- string fieldValue = string.Empty;
- while (!rd.IsEOF)
- {
- fieldValue = rd.GetFieldValue(_ziduan)?.ToString();
- if (string.IsNullOrEmpty(fieldValue))
- _cbg.Items.Add("未知");
- else
- _cbg.Items.Add(fieldValue);
- rd.MoveNext();
- }
- }
- public static void AddUICheckBox(Control parentControl, Dictionary<string, string> keyValuePairs)
- {
- UICheckBox uiCheckBox;
- foreach (string key in keyValuePairs.Keys)
- {
- uiCheckBox = new UICheckBox() { Name = key, Text = keyValuePairs[key], Location = new Point(20, 20 + parentControl.Controls.Count * 28), Style = Sunny.UI.UIStyle.Gray };
- parentControl.Controls.Add(uiCheckBox);
- }
- }
- /// <summary>
- /// 设置CheckedListBox的选择状态
- /// </summary>
- /// <param name="clb"></param>
- /// <param name="doState">1全选 2反选 3全不选</param>
- public static void CheckListBoxDo(CheckedListBox clb, int doState)
- {
- switch (doState)
- {
- case 1://全选
- for (int i = 0; i < clb.Items.Count; i++)
- {
- clb.SetItemChecked(i, true);
- }
- break;
- case 2://反选
- for (int i = 0; i < clb.Items.Count; i++)
- {
- bool ck = clb.GetItemChecked(i);
- clb.SetItemChecked(i, !ck);
- }
- break;
- case 3://清空
- for (int i = 0; i < clb.Items.Count; i++)
- {
- clb.SetItemChecked(i, false);
- }
- break;
- default:
- break;
- }
- }
- #endregion
- #region 其他计算操作
- /// <summary>
- /// 通过起点的坐标和高程、终点的坐标和高程,计算线上交点的高程
- /// </summary>
- /// <param name="gx_start">起点坐标</param>
- /// <param name="gx_start_gc">起点高程</param>
- /// <param name="gx_end">终点坐标</param>
- /// <param name="gx_end_gc">终点高程</param>
- /// <param name="JiaoDian">线上的交点坐标</param>
- /// <returns></returns>
- public static double getPointHeight(Point2D gx_start, double gx_start_gc, Point2D gx_end, double gx_end_gc, Point2D JiaoDian)
- {
- if (!Geometrist.IsPointOnLine(JiaoDian, gx_start, gx_end, false))
- return 0.0;
- double JiaoDian_gc = 0.0D;
- if (gx_start_gc == gx_end_gc)
- {
- JiaoDian_gc = gx_start_gc;
- }
- else
- {
- if (gx_start_gc < gx_end_gc)//确保起点高程 大于 终点高程
- {
- double temp = gx_start_gc;
- gx_start_gc = gx_end_gc;
- gx_end_gc = temp;
- Point2D temPoint = gx_start;
- gx_start = gx_end;
- gx_end = temPoint;
- }
- // 参考链接 https://zhuanlan.zhihu.com/p/43660758 下面的公式可以用,是正式的,这里备份一下
- //JiaoDian_gc = gx_end_gc + (gx_start_gc - gx_end_gc) * (Math.Sqrt(Math.Pow((JiaoDian.X - gx_end.X), 2.0) + Math.Pow((JiaoDian.Y - gx_end.Y), 2.0))) / (Math.Sqrt(Math.Pow((gx_start.X - gx_end.X), 2.0) + Math.Pow((gx_start.Y - gx_end.Y), 2.0)));
- 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)));
- if (JiaoDian_gc == double.PositiveInfinity || JiaoDian_gc == double.NegativeInfinity)
- {
- JiaoDian_gc = gx_end_gc;
- }
- }
- return Math.Round(JiaoDian_gc, 2);
- }
- /// <summary>
- /// 返回Double数组的最大值或者最小值
- /// </summary>
- /// <param name="dblist"></param>
- /// <param name="isMax">True表示最大值,false表示最小值</param>
- /// <returns></returns>
- public static double getMaxMin(double[] dblist, bool isMax)
- {
- double finalValue = dblist[0];
- if (isMax)//最大值
- {
- for (int i = 0; i < dblist.Length; i++)
- {
- if (finalValue < dblist[i])
- finalValue = dblist[i];
- }
- }
- else
- {
- for (int i = 0; i < dblist.Length; i++)
- {
- if (finalValue > dblist[i])
- finalValue = dblist[i];
- }
- }
- return finalValue;
- }
- #endregion
- #region 管网标注的配置
- /// <summary>
- /// GeoStyle LineColor = Color.Brown, LineWidth = 0.5
- /// </summary>
- public static GeoStyle geoStyle_Brown_05mm = new GeoStyle() { LineColor = Color.Brown, LineWidth = 0.5 };
- /// <summary>
- /// TextStyle ForeColor = Color.Brown, IsSizeFixed = true, FontHeight = 6, Alignment = TextAlignment.BottomLeft
- /// </summary>
- public static TextStyle textStyle_Brown_6mm_BottomLeft = new TextStyle { ForeColor = Color.Brown, IsSizeFixed = true, FontHeight = 6, Alignment = TextAlignment.BottomLeft };
- /// <summary>
- /// 红色线条 宽度1mm 背景透明度10
- /// </summary>
- public static GeoStyle geoStyle_Red_1mm_OpaqueRate = new GeoStyle { LineColor = Color.Red, LineWidth = 1, FillBackOpaque = false, FillOpaqueRate = 10 };
- #endregion
- }
- public class LayerEx
- {
- public static LayerEx[] layerExs = new LayerEx[]{
- new LayerEx{ Index = 9, Caption = "供水管线", Dataset = "JSLK", LineWidth = 1, LineColor = Color.FromArgb(84, 141, 212) },
- new LayerEx{ Index = 8, Caption = "供水水表", Dataset = "JSSBPT", LineWidth = 2.4, LineColor = Color.FromArgb(206, 137, 102) },
- new LayerEx{ Index = 7, Caption = "供水阀门", Dataset = "JSFMPT", LineWidth = 2.4, LineColor = Color.FromArgb(0, 160, 233) },
- new LayerEx{ Index = 6, Caption = "供水节点", Dataset = "JSJDPT", LineWidth = 2.4, LineColor = Color.FromArgb(127, 194, 105) }
- };
- public LayerEx() { }
- private string caption;
- private string name;
- private string dataset;
- private int opaqueRate = 0;
- private double maxVisibleScale = 0;
- private double minVisibleScale = 0;
- private bool isEditable = true;
- private bool isVisible = true;
- private int index;
- private Color lineColor = Color.FromArgb(0, 0, 0);
- private double lineWidth;
- public string Caption { get => caption; set => caption = value; }
- public string Name { get => name; set => name = value; }
- public string Dataset { get => dataset; set => dataset = value; }
- public int OpaqueRate { get => opaqueRate; set => opaqueRate = value; }
- public double MaxVisibleScale { get => maxVisibleScale; set => maxVisibleScale = value; }
- public double MinVisibleScale { get => minVisibleScale; set => minVisibleScale = value; }
- public bool IsEditable { get => isEditable; set => isEditable = value; }
- public bool IsVisible { get => isVisible; set => isVisible = value; }
- public int Index { get => index; set => index = value; }
- public double LineWidth { get => lineWidth; set => lineWidth = value; }
- public Color LineColor { get => lineColor; set => lineColor = value; }
- }
- }
|