using Sunny.UI;
using SuperMap.Data;
using SuperMap.Mapping;
using System;
using System.Drawing;
using WeifenLuo.WinFormsUI.Docking;
using WWPipeLine.MapBasic.Conditions;
using System.Windows.Forms;
using WWPipeLine.MapBasic;
namespace WWPipeLine.MapTools.Conditions.EditGuanWang
{
public class GuanDianXinZeng : ConditionPanel
{
private GeoPoint _geoPoint = null;
private UICheckBox uiCBpol;
private LayerWithDataListPanel LayerPanel;
private Panel panel1;
private Label label1;
private TextBox textBoxX;
private Label label2;
private TextBox textBoxY;
private Button button1;
private int gxSMID = 0;
public GuanDianXinZeng() : base()
{
this.ConditionPanelName = "新增管点信息";
this.SetSize(300, 550);
InitializeComponent();
this.IsShowResultWindow = false;
LayerPanel = new LayerWithDataListPanel();
LayerPanel.LoadToVector(false, false);
panel1.Controls.Add(LayerPanel);
}
protected override void OnLoad(EventArgs e)
{
MapControl.MouseDoubleClick += MapControl_MouseDoubleClick;
}
private void MapControl_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (LayerPanel.SelectLayers.Count != 1)
{
Sunny.UI.UIMessageTip.ShowError("请选择需要编辑的图层"); return;
}
Point2D pClick = MapControl.Map.PixelToMap(new Point(e.X, e.Y));
//限制线上点(即执行管线打断功能)
if (uiCBpol.Checked)
{
GeoPoint pointClick = new GeoPoint(pClick);
Recordset rdJSLK = ComsStatic.gsGuanXian.Query(pointClick, 3, CursorType.Static);
if (rdJSLK.RecordCount == 0)
{
Sunny.UI.UIMessageTip.ShowError("当前鼠标双击点附近没有找到管线信息"); return;
}
double distance_temp = 0.0D;
double distance = 0.0D;
GeoLine _rd_temp;
GeoLine _rd_line = new GeoLine();
rdJSLK.MoveFirst();
while (!rdJSLK.IsEOF)
{
_rd_temp = rdJSLK.GetGeometry() as GeoLine;
distance_temp = Geometrist.Distance(pointClick, _rd_temp);
if (distance_temp <= distance || distance == 0.0D)
{
distance = distance_temp;
_rd_line = _rd_temp;
gxSMID = Int32.Parse(rdJSLK.GetFieldValue("smid").ToString());
}
rdJSLK.MoveNext();
}
ComsStatic.RecordsetDispose(rdJSLK);
pClick = Geometrist.NearestPointToVertex(pClick, _rd_line);
//bool PointOnLine = Geometrist.HasCommonPoint(new GeoPoint(pClick), _rd_line);
}
#region 限制于节点重合 已取消该功能
//if (uiCheckBox1.Checked)//限制于节点重合
//{
// GeoPoint pointClick = new GeoPoint(pClick);
// Recordset rdJSJDPT = ComsStatic.gsGuanDian.Query(pointClick, 3, CursorType.Static);
// if (rdJSJDPT.RecordCount == 0)
// {
// Sunny.UI.UIMessageTip.ShowError("当前鼠标双击点附近没有找到节点信息"); return;
// }
// double distance_temp = 0.0D;
// double distance = 0.0D;
// GeoPoint p_temp;
// rdJSJDPT.MoveFirst();
// while (!rdJSJDPT.IsEOF)
// {
// p_temp = rdJSJDPT.GetGeometry() as GeoPoint;
// distance_temp = Geometrist.Distance(pointClick, p_temp);
// if (distance_temp <= distance || distance == 0.0D)
// {
// distance = distance_temp;
// pClick = p_temp.InnerPoint;
// }
// rdJSJDPT.MoveNext();
// }
//}
#endregion
_geoPoint = new GeoPoint(pClick);
_geoPoint.Style = ComsStatic.geoStyle_Red_Mark5mm;
MapControl.Map.TrackingLayer.Clear();
MapControl.Map.TrackingLayer.Add(_geoPoint, "jiedian");
MapControl.Map.RefreshTrackingLayer();
}
public override object Do(DockPanel dockPanel = null)
{
if (LayerPanel.SelectLayers.Count != 1 || _geoPoint is null)
{
Sunny.UI.UIMessageTip.ShowError("请选择需要新增节点的图层,并在界面中点选节点位置"); return false;
}
EditHistory m_EditHistory = new EditHistory();
m_EditHistory.Capacity = 5;
Layer lyr = LayerPanel.SelectLayers[0];
Int32 objID = ComsStatic.GetMaxValueInt(ComsStatic.gsGuanDian, "objectid") + 1;
string bsmGDNew = lyr.Dataset.Name + objID;
Recordset rdGD = ComsStatic.gsGuanDian.GetRecordset(true, CursorType.Dynamic);
rdGD.AddNew(_geoPoint);
m_EditHistory.Add(SuperMap.Data.EditType.AddNew, rdGD, false);
m_EditHistory.Add(SuperMap.Data.EditType.Modify, rdGD, false);
rdGD.Edit();
rdGD.SetFieldValue("x", _geoPoint.X);
rdGD.SetFieldValue("y", _geoPoint.Y);
rdGD.SetFieldValue("lrrq", DateTime.Now.ToLocalTime());
rdGD.SetFieldValue("bsm", bsmGDNew);
rdGD.SetFieldValue("fldm", lyr.Caption);
rdGD.SetFieldValue("objectid", objID);
//限制线上点(即执行管线打断功能)
if (uiCBpol.Checked)
{
if (gxSMID == 0)
{
Sunny.UI.UIMessageTip.ShowError("请先勾选“限制线上点”后再双击确认位置!"); return false;
}
try
{
//1 新增 节点信息
rdGD.SetFieldValue("cqbh", "管点新增且打断管线-新增节点");
if (rdGD.Update())
{
Commons.LogHelper.Info("管点新增且打断管线-新增管线节点成功。新节点标识码" + bsmGDNew);
}
else
{
ComsStatic.EditHistoryUndo(m_EditHistory);
ComsStatic.ShowErrorLog(lyr.Caption + "新增失败", "管点新增且打断管线-新增管线节点失败 ");
return false;
}
//2 用新增的节点 打断管线 参考打断管线的预览打断管线功能
Recordset rsGXyuan = ComsStatic.gsGuanXian.Query(new int[] { gxSMID }, CursorType.Dynamic);
Recordset rsGDtemp = ComsStatic.gsGuanDian.Query(string.Format("bsm='{0}'", rsGXyuan.GetString("qsdh")), CursorType.Static);
if (rsGDtemp.RecordCount != 1)
{
ComsStatic.EditHistoryUndo(m_EditHistory);
ComsStatic.ShowErrorLog(lyr.Caption + "新增失败", "管点新增且打断管线-管线起始点号不存在 " + rsGXyuan.GetString("qsdh"));
return false;
}
Point2D startPoint = new Point2D(rsGDtemp.GetDouble("x"), rsGDtemp.GetDouble("y"));
rsGDtemp = ComsStatic.gsGuanDian.Query(string.Format("bsm='{0}'", rsGXyuan.GetString("zddh")), CursorType.Static);
if (rsGDtemp.RecordCount != 1)
{
ComsStatic.EditHistoryUndo(m_EditHistory);
ComsStatic.ShowErrorLog(lyr.Caption + "新增失败", "管点新增且打断管线-管线终点点号不存在 " + rsGXyuan.GetString("zddh"));
return false;
}
Point2D endPoint = new Point2D(rsGDtemp.GetDouble("x"), rsGDtemp.GetDouble("y"));
ComsStatic.RecordsetDispose(rsGDtemp);
//3 新增 起始管线
Recordset _rd = ComsStatic.gsGuanXian.GetRecordset(true, CursorType.Dynamic);
GeoLine geoLine = new GeoLine(new Point2Ds(new Point2D[] { startPoint, _geoPoint.InnerPoint }));
_rd.AddNew(geoLine);
m_EditHistory.Add(SuperMap.Data.EditType.AddNew, _rd, false);
m_EditHistory.Add(SuperMap.Data.EditType.Modify, _rd, false);
_rd.Edit();
_rd.SetFieldValue("qsdh", rsGXyuan.GetString("qsdh"));
_rd.SetFieldValue("zddh", bsmGDNew);
_rd.SetFieldValue("lrrq", DateTime.Now.ToLocalTime());
_rd.SetFieldValue("gj", rsGXyuan.GetInt16("gj"));
objID = ComsStatic.GetMaxValueInt(ComsStatic.gsGuanXian, "objectid") + 1;
_rd.SetFieldValue("objectid", objID);
_rd.SetFieldValue("fldm", ComsStatic.dvGXCaption);
_rd.SetFieldValue("bsm", ComsStatic.dvGXDatasetName + objID);
_rd.SetFieldValue("cd", ComsStatic.StringToDouble(geoLine.Length, 2));
_rd.SetFieldValue("shape_length", geoLine.Length);
_rd.SetFieldValue("cqbh", "管点新增且打断管线-新增起始管线");
if (_rd.Update())
{
Commons.LogHelper.Info(string.Format("管点新增且打断管线-新增起始管线成功 {0}。", ComsStatic.dvGXDatasetName + objID));
}
else
{
ComsStatic.EditHistoryUndo(m_EditHistory);
ComsStatic.ShowErrorLog(lyr.Caption + "新增失败", "管点新增且打断管线-新增起始管线失败 "); return false;
}
//4 新增 结束管线
_rd = ComsStatic.gsGuanXian.GetRecordset(true, CursorType.Dynamic);
geoLine = new GeoLine(new Point2Ds(new Point2D[] { _geoPoint.InnerPoint, endPoint }));
_rd.AddNew(geoLine);
m_EditHistory.Add(SuperMap.Data.EditType.AddNew, _rd, false);
m_EditHistory.Add(SuperMap.Data.EditType.Modify, _rd, false);
_rd.Edit();
_rd.SetFieldValue("qsdh", bsmGDNew);
_rd.SetFieldValue("zddh", rsGXyuan.GetString("zddh"));
_rd.SetFieldValue("lrrq", DateTime.Now.ToLocalTime());
_rd.SetFieldValue("gj", rsGXyuan.GetInt16("gj"));
objID = ComsStatic.GetMaxValueInt(ComsStatic.gsGuanXian, "objectid") + 1;
_rd.SetFieldValue("objectid", objID);
_rd.SetFieldValue("fldm", ComsStatic.dvGXCaption);
_rd.SetFieldValue("bsm", ComsStatic.dvGXDatasetName + objID);
_rd.SetFieldValue("cd", ComsStatic.StringToDouble(geoLine.Length, 2));
_rd.SetFieldValue("shape_length", geoLine.Length);
_rd.SetFieldValue("cqbh", "管点新增且打断管线-新增结束管线");
if (_rd.Update())
{
Commons.LogHelper.Info(string.Format("管点新增且打断管线-新增结束管线成功 {0}。", ComsStatic.dvGXDatasetName + objID));
}
else
{
ComsStatic.EditHistoryUndo(m_EditHistory);
ComsStatic.ShowErrorLog(lyr.Caption + "新增失败", "管点新增且打断管线-新增结束管线失败 "); return false;
}
//5 删除 原管线
m_EditHistory.Add(SuperMap.Data.EditType.Delete, rsGXyuan, false);
if (rsGXyuan.Delete())
{
(lyr.Dataset as DatasetVector).Append(rdGD);
ComsStatic.ShowOKLog(lyr.Caption + "新增成功", string.Format("删除管线{0},新增节点{1}", gxSMID, bsmGDNew));
}
else
{
ComsStatic.EditHistoryUndo(m_EditHistory);
ComsStatic.ShowErrorLog("原管线删除失败!"); return false;
}
}
catch (Exception e)
{
ComsStatic.EditHistoryUndo(m_EditHistory);
ComsStatic.ShowErrorLog(lyr.Caption + "新增失败!", e.Message); return false;
}
}
//新增管点
else
{
rdGD.SetFieldValue("cqbh", "管点新增");
if (rdGD.Update())
{
(lyr.Dataset as DatasetVector).Append(rdGD);
ComsStatic.ShowOKLog(lyr.Caption + "新增成功", bsmGDNew);
}
else
{
ComsStatic.EditHistoryUndo(m_EditHistory);
ComsStatic.ShowErrorLog(lyr.Caption + "新增失败");
}
}
ComsStatic.RecordsetDispose(rdGD);
_geoPoint = null;
MapControl.Map.TrackingLayer.Clear();
MapControl.Map.RefreshEx(MapControl.Map.Bounds);
return null;
}
public override void AfterClose()
{
MapControl.MouseDoubleClick -= MapControl_MouseDoubleClick;
base.AfterClose();
}
private void InitializeComponent()
{
this.uiCBpol = new Sunny.UI.UICheckBox();
this.panel1 = new System.Windows.Forms.Panel();
this.label1 = new System.Windows.Forms.Label();
this.textBoxX = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.textBoxY = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// uiCBpol
//
this.uiCBpol.CheckBoxColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
this.uiCBpol.Cursor = System.Windows.Forms.Cursors.Hand;
this.uiCBpol.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiCBpol.Location = new System.Drawing.Point(3, 283);
this.uiCBpol.MinimumSize = new System.Drawing.Size(1, 1);
this.uiCBpol.Name = "uiCBpol";
this.uiCBpol.Padding = new System.Windows.Forms.Padding(22, 0, 0, 0);
this.uiCBpol.Size = new System.Drawing.Size(282, 29);
this.uiCBpol.Style = Sunny.UI.UIStyle.Gray;
this.uiCBpol.TabIndex = 0;
this.uiCBpol.Text = "限制线上点(即执行管线打断功能)";
//
// panel1
//
this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(300, 277);
this.panel1.TabIndex = 1;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(27, 327);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(52, 21);
this.label1.TabIndex = 2;
this.label1.Text = "X坐标";
//
// textBoxX
//
this.textBoxX.Location = new System.Drawing.Point(85, 326);
this.textBoxX.Name = "textBoxX";
this.textBoxX.Size = new System.Drawing.Size(180, 29);
this.textBoxX.TabIndex = 3;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(27, 371);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(52, 21);
this.label2.TabIndex = 4;
this.label2.Text = "Y坐标";
//
// textBoxY
//
this.textBoxY.Location = new System.Drawing.Point(85, 368);
this.textBoxY.Name = "textBoxY";
this.textBoxY.Size = new System.Drawing.Size(180, 29);
this.textBoxY.TabIndex = 5;
//
// button1
//
this.button1.Location = new System.Drawing.Point(190, 403);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 32);
this.button1.TabIndex = 6;
this.button1.Text = "定位";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// GuanDianXinZeng
//
this.Controls.Add(this.button1);
this.Controls.Add(this.textBoxY);
this.Controls.Add(this.label2);
this.Controls.Add(this.textBoxX);
this.Controls.Add(this.label1);
this.Controls.Add(this.panel1);
this.Controls.Add(this.uiCBpol);
this.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(242)))), ((int)(((byte)(242)))), ((int)(((byte)(244)))));
this.Name = "GuanDianXinZeng";
this.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
this.Size = new System.Drawing.Size(300, 438);
this.Style = Sunny.UI.UIStyle.Gray;
this.ResumeLayout(false);
this.PerformLayout();
}
private void button1_Click(object sender, EventArgs e)
{
double pointX = 0.0d;
double pointY = 0.0d;
if (!double.TryParse(textBoxX.Text, out pointX) || !double.TryParse(textBoxY.Text, out pointY))
{
Sunny.UI.UIMessageTip.ShowError("请选择需要新增节点的图层,并输入正确的坐标!仅能输入数字、小数点"); return;
}
Point2D pClickTmp = new Point2D(pointX, pointY);
Point2Ds point2Ds = new Point2Ds();
point2Ds.Add(pClickTmp);
PrjCoordSys srcTY = GetTargetPrjCoordSys(1); // 原坐标系(大安中央子午线是123)
PrjCoordSys desTY = new PrjCoordSys(4549); // 目标坐标系
bool forward = CoordSysTranslator.Convert(point2Ds, srcTY, desTY, new CoordSysTransParameter(), CoordSysTransMethod.GeocentricTranslation);
Point2D pClick = point2Ds[0];
MapControl.Map.Center = pClick;
MapControl.Map.Refresh();
//限制线上点(即执行管线打断功能)
if (uiCBpol.Checked)
{
GeoPoint pointClick = new GeoPoint(pClick);
Recordset rdJSLK = ComsStatic.gsGuanXian.Query(pointClick, 3, CursorType.Static);
if (rdJSLK.RecordCount == 0)
{
Sunny.UI.UIMessageTip.ShowError("当前鼠标双击点附近没有找到管线信息"); return;
}
double distance_temp = 0.0D;
double distance = 0.0D;
GeoLine _rd_temp;
GeoLine _rd_line = new GeoLine();
rdJSLK.MoveFirst();
while (!rdJSLK.IsEOF)
{
_rd_temp = rdJSLK.GetGeometry() as GeoLine;
distance_temp = Geometrist.Distance(pointClick, _rd_temp);
if (distance_temp <= distance || distance == 0.0D)
{
distance = distance_temp;
_rd_line = _rd_temp;
gxSMID = Int32.Parse(rdJSLK.GetFieldValue("smid").ToString());
}
rdJSLK.MoveNext();
}
ComsStatic.RecordsetDispose(rdJSLK);
pClick = Geometrist.NearestPointToVertex(pClick, _rd_line);
}
_geoPoint = new GeoPoint(pClick);
_geoPoint.Style = ComsStatic.geoStyle_Red_Mark5mm;
MapControl.Map.TrackingLayer.Clear();
MapControl.Map.TrackingLayer.Add(_geoPoint, "jiedian");
MapControl.Map.RefreshTrackingLayer();
}
///
/// 按照不同的投影类型,初始化投影坐标系
///
/// 1:高斯投影;2:UTM投影;3:兰勃脱投影
///
private PrjCoordSys GetTargetPrjCoordSys(int type)
{
PrjCoordSys targetPrjCoordSys = null;
PrjParameter parameter = null;
Projection projection = null;
switch (type)
{
case 1:
{
targetPrjCoordSys = new PrjCoordSys(PrjCoordSysType.UserDefined);
projection = new Projection(ProjectionType.GaussKruger);
targetPrjCoordSys.Projection = projection;
parameter = new PrjParameter();
parameter.CentralMeridian = 123;
parameter.FalseEasting = 500000;
parameter.ScaleFactor = 1;
GeoCoordSys geoCoordSys = new GeoCoordSys();
geoCoordSys.Type = GeoCoordSysType.China2000;
targetPrjCoordSys.GeoCoordSys = geoCoordSys;
targetPrjCoordSys.PrjParameter = parameter;
}
break;
case 2:
{
targetPrjCoordSys = new PrjCoordSys(PrjCoordSysType.UserDefined);
projection = new Projection(ProjectionType.TransverseMercator);
targetPrjCoordSys.Projection = projection;
parameter = new PrjParameter();
parameter.CentralMeridian = 110;
parameter.StandardParallel1 = 0;
targetPrjCoordSys.PrjParameter = parameter;
}
break;
case 3:
{
targetPrjCoordSys = new PrjCoordSys(PrjCoordSysType.UserDefined);
projection = new Projection(ProjectionType.LambertConformalConic);
targetPrjCoordSys.Projection = projection;
parameter = new PrjParameter();
parameter.CentralMeridian = 110;
parameter.StandardParallel1 = 30;
targetPrjCoordSys.PrjParameter = parameter;
}
break;
default:
break;
}
return targetPrjCoordSys;
}
}
}