using SuperMap.Data; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Drawing.Drawing2D; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WWPipeLine.MapTools.Conditions.AnalystToolBar { public partial class PouMianAnalystResult : Sunny.UI.UIForm { private DataTable m_dt; public PouMianAnalystResult(DataTable dt) { InitializeComponent(); this.StartPosition = FormStartPosition.Manual; this.Location = new System.Drawing.Point(10, 10); m_dt = dt; } private void AnalystResultForm_Load(object sender, EventArgs e) { int width = 800;// pictureBox.Width; int height = 600;// pictureBox.Height; Bitmap image = new Bitmap(width, height); //创建Graphics类对象 Graphics g = Graphics.FromImage(image); g.SmoothingMode = SmoothingMode.AntiAlias; g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.CompositingQuality = CompositingQuality.HighQuality; g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; g.Clear(Color.White); Pen PenXYLine = Pens.Blue; Pen PenBlack = Pens.Black; Brush defaultBrush = Brushes.Black; Font fontNormal = new Font("Arial", 9, FontStyle.Regular); Font fontTitle = new Font("Arial", 16, FontStyle.Bold); //顶部标题 g.DrawString(uitxtTitle.Text, fontTitle, defaultBrush, new PointF(width / 3, 10)); //画图片的边框线 g.DrawRectangle(PenXYLine, 0, 50, width - 2, height - 52); //绘制 Y轴线,直接从顶到底 g.DrawLine(PenXYLine, 100, 50, 100, height); int yHeight = 450;// height - 50 - TableLineHeight * 5; int gxgcFenDuanHeight = 75;// (int)450 / 6; //(int)((height - 55 - TableLineHeight * 6) / 6 #region 计算 Y轴 最大值与最小值 Y轴设置横线5根,数据值5个,分为6段,7个节点 DataView m_dt_dv = m_dt.DefaultView; //高程最大值 取地面高程的最大值 m_dt_dv.Sort = "dmgc DESC"; double gcMax = Math.Round(double.Parse(m_dt_dv[0]["dmgc"].ToString()), 2); //高程最小值 =管顶高程最小值-管点埋深最大值 m_dt_dv.Sort = "gdgc ASC"; double gdgcMin = Math.Round(double.Parse(m_dt_dv[0]["gdgc"].ToString()), 2); m_dt_dv.Sort = "gdms DESC"; double gdmsMin = Math.Round(double.Parse(m_dt_dv[0]["gdms"].ToString()), 2); double gcMin = gdgcMin - gdmsMin; //Y轴共计6段,计算每一段的差值 double gdgcChaZhi = Math.Round(gcMax - (gcMax + gcMin) / 2, 2); if (gdgcChaZhi == 0 || gdgcChaZhi == double.PositiveInfinity || gdgcChaZhi == double.NegativeInfinity) { gdgcChaZhi = 1; } double gdgcTop = gcMax + gdgcChaZhi * 2; for (int i = 0; i <= 6; i++)//Y轴分为6段,除了顶部和底部,需要绘制5个 短横线和坐标值 { if (i == 0 || i == 6) continue; g.DrawLine(PenXYLine, 95, 50 + i * gxgcFenDuanHeight, 100, 50 + i * gxgcFenDuanHeight); g.DrawString(GetGxgcY(i).ToString(), fontNormal, defaultBrush, 50, 50 + i * gxgcFenDuanHeight - 5); } double GetGxgcY(int i) { switch (i) { case 0: return gdgcTop; case 1: return gdgcTop - gdgcChaZhi; case 2: return gcMax; case 3: return gcMax - gdgcChaZhi; case 4: return gcMax - gdgcChaZhi * 2; case 5: return gcMax - gdgcChaZhi * 3; case 6: return gcMax - gdgcChaZhi * 4; default: return 0.0; } } double UnitY = yHeight / (gdgcChaZhi * 6); #endregion #region X轴 计算UnitX 并配置断面的X坐标 int xWidth = 700; double tbJuLiSum = 0.0D; foreach (DataRow dr in m_dt.Rows) { if (m_dt.Rows.IndexOf(dr) == m_dt.Rows.Count - 1) continue; tbJuLiSum += double.Parse(dr["gxcd"].ToString()); } if (tbJuLiSum == 0 || tbJuLiSum == double.PositiveInfinity || tbJuLiSum == double.NegativeInfinity) { tbJuLiSum = 1; } double UnitX = (xWidth - 120) / tbJuLiSum; double tbJuLiX = 120.0D; foreach (DataRow dr in m_dt.Rows) { double newJuli = UnitX * double.Parse(dr["gxcd"].ToString()); dr["xLeft"] = newJuli * 0.6; if (m_dt.Rows.IndexOf(dr) == 0) { dr["x"] = tbJuLiX; continue; } tbJuLiX += newJuli; dr["x"] = tbJuLiX; } #endregion #region 绘制 底部的表格横线 表格数据展示 g.DrawString("地面高程(M)", fontNormal, defaultBrush, 40, 60); int TableLineHeight = 20; string tbTitle = ""; string tbZiDuan = ""; for (int i = 1; i <= 5; i++) { g.DrawLine(PenXYLine, 0, height - i * TableLineHeight, width, height - i * TableLineHeight); GetTableColumsCaption(i); float StringY = height - i * TableLineHeight + 5; g.DrawString(tbTitle, fontNormal, defaultBrush, 20, StringY); for (int j = 0; j < m_dt.Rows.Count; j++) { if (tbZiDuan == "gxgj" || tbZiDuan == "gxcd") { if (j == m_dt.Rows.Count - 1) continue; g.DrawString(m_dt.Rows[j][tbZiDuan].ToString(), fontNormal, defaultBrush, float.Parse(m_dt.Rows[j]["x"].ToString()) + float.Parse(m_dt.Rows[j]["xLeft"].ToString()), StringY); continue; } g.DrawString(m_dt.Rows[j][tbZiDuan].ToString(), fontNormal, defaultBrush, float.Parse(m_dt.Rows[j]["x"].ToString()), StringY); if (tbZiDuan == "dmgc")//计算Y坐标,只需要计算一次 { m_dt.Rows[j]["y"] = 50 + UnitY * (gdgcTop - Double.Parse(m_dt.Rows[j]["dmgc"].ToString())); m_dt.Rows[j]["ygd"] = double.Parse(m_dt.Rows[j]["y"].ToString()) + UnitY * Double.Parse(m_dt.Rows[j]["gdms"].ToString()); } } } void GetTableColumsCaption(int i) { switch (i) { case 1: tbTitle = "管线长度(M)"; tbZiDuan = "gxcd"; break; case 2: tbTitle = "管线管径(MM)"; tbZiDuan = "gxgj"; break; case 3: tbTitle = "管点埋深(M)"; tbZiDuan = "gdms"; break; case 4: tbTitle = "管顶高程(M)"; tbZiDuan = "gdgc"; break; case 5: tbTitle = "地面高程(M)"; tbZiDuan = "dmgc"; break; default: tbTitle = "未知"; tbZiDuan = ""; break; } } #endregion #region 绘制 断面管线 float gxgj = 0; float Ydmgc = 0.0F; float Xdmgc = 0.0F; float Ygdgc = 0.0F; for (int j = 0; j < m_dt.Rows.Count; j++) { float.TryParse(m_dt.Rows[j]["gxgj"].ToString(), out gxgj); gxgj = (float)(gxgj / 1000 * UnitY); Xdmgc = float.Parse(m_dt.Rows[j]["x"].ToString()); Ydmgc = float.Parse(m_dt.Rows[j]["y"].ToString()); Ygdgc = float.Parse(m_dt.Rows[j]["ygd"].ToString()); //绘制 地面高程 到 管顶高程的 竖线 该管点为管线的起始管点 //g.DrawLine(PenXYLine, Xdmgc, Ydmgc, Xdmgc, Ygdgc); if (j == 0)//第一行 只需要绘制地面高程到管顶高程的竖线 { g.DrawLine(PenBlack, Xdmgc, Ygdgc, Xdmgc, Ygdgc + gxgj); continue; } //绘制地面高程线 管线的 起始管点 到 终点管点 g.DrawLine(PenBlack, float.Parse(m_dt.Rows[j - 1]["x"].ToString()), float.Parse(m_dt.Rows[j - 1]["y"].ToString()), Xdmgc, Ydmgc); //绘制管顶高程线 管线的 起始管点 到 终点管点的 管顶 g.DrawLine(PenBlack, float.Parse(m_dt.Rows[j - 1]["x"].ToString()), float.Parse(m_dt.Rows[j - 1]["ygd"].ToString()), Xdmgc, Ygdgc); //绘制管底高程线 g.DrawLine(PenBlack, float.Parse(m_dt.Rows[j - 1]["x"].ToString()), float.Parse(m_dt.Rows[j - 1]["ygd"].ToString()) + gxgj, Xdmgc, Ygdgc + gxgj); //绘制管头的竖线 g.DrawLine(PenBlack, Xdmgc, Ygdgc, Xdmgc, Ygdgc + gxgj); } #endregion //显示 比例尺 string bilichi = string.Format("水平比例尺 1:{0} 垂直比例尺 1:{1} ", Math.Round(UnitX, 0), Math.Round(UnitY, 0)); g.DrawString(bilichi, fontNormal, defaultBrush, width / 3, 60); pictureBox.Image = image; } private void uibtnSave_Click(object sender, EventArgs e) { SaveFileDialog save = new SaveFileDialog(); save.FileName = uitxtTitle.Text; save.Filter = "Jpg 图片|*.jpg|Bmp 图片|*.bmp|Png 图片|*.png"; if (save.ShowDialog() == DialogResult.OK) { pictureBox.Image.Save(save.FileName); } } private void uibtnQuantu_Click(object sender, EventArgs e) { pictureBox.MouseUp -= PictureBox_MouseUp; pictureBox.Width = 800; pictureBox.Height = 600; pictureBox.SizeMode = PictureBoxSizeMode.AutoSize; pictureBox.Refresh(); } private void uiIbtnFangda_Click(object sender, EventArgs e) { pictureBox.MouseUp -= PictureBox_MouseUp; pictureBox.SizeMode = PictureBoxSizeMode.StretchImage; pictureBox.Width = (int)(pictureBox.Width * 1.2); pictureBox.Height = (int)(pictureBox.Height * 1.2); pictureBox.Refresh(); } private void uibtnSuoxiao_Click(object sender, EventArgs e) { pictureBox.MouseUp -= PictureBox_MouseUp; pictureBox.SizeMode = PictureBoxSizeMode.StretchImage; pictureBox.Width = (int)(pictureBox.Width * 0.8); pictureBox.Height = (int)(pictureBox.Height * 0.8); pictureBox.Refresh(); } private void uibtnPingyi_Click(object sender, EventArgs e) { pictureBox.SizeMode = PictureBoxSizeMode.AutoSize; pictureBox.Cursor = Cursors.Hand; pictureBox.MouseUp += PictureBox_MouseUp; } private void PictureBox_MouseUp(object sender, MouseEventArgs e) { } private void AnalystResultForm_FormClosing(object sender, FormClosingEventArgs e) { pictureBox.MouseUp -= PictureBox_MouseUp; } } }