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 DuanMianAnalystResult : Sunny.UI.UIForm { private DataTable m_dt; public DuanMianAnalystResult(DataTable dt) { InitializeComponent(); //this.Size = new Size(820, 720); this.Style = Sunny.UI.UIStyle.Gray; this.StartPosition = FormStartPosition.Manual; this.Location = new System.Drawing.Point(10, 10); m_dt = dt; } private void AnalystResultForm_Load(object sender, EventArgs e) { DataColumn dataColumn; dataColumn = new DataColumn { ColumnName = "x", Caption = "X坐标" }; m_dt.Columns.Add(dataColumn); dataColumn = new DataColumn { ColumnName = "y", Caption = "Y坐标" }; m_dt.Columns.Add(dataColumn); 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; 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 = "gxgc DESC"; double gxgcMax = 0.0; double.TryParse(m_dt_dv[0]["gxgc"].ToString(), out gxgcMax); gxgcMax = Math.Round(gxgcMax, 2); double gxgcMin = 0.0; double.TryParse(m_dt_dv[m_dt_dv.Count - 1]["gxgc"].ToString(), out gxgcMin); gxgcMin = Math.Round(gxgcMin, 2); double gxgcChaZhi = Math.Round(gxgcMax - (gxgcMax + gxgcMin) / 2, 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 gxgcMax + gxgcChaZhi * 2; case 1: return gxgcMax + gxgcChaZhi; case 2: return gxgcMax; case 3: return gxgcMax - gxgcChaZhi; case 4: return gxgcMin; case 5: return gxgcMin - gxgcChaZhi; case 6: return gxgcMin - gxgcChaZhi * 2; default: return 0.0; } } double UnitY = yHeight / ((gxgcMax - (gxgcMax + gxgcMin) / 2) * 6); #endregion #region X轴 计算UnitX 并配置断面的X坐标 int xWidth = 700; double tbJuLiSum = 0.0D; foreach (DataRow dr in m_dt.Rows) { tbJuLiSum += double.Parse(string.IsNullOrEmpty(dr["jl"].ToString()) ? "0" : dr["jl"].ToString()); } double UnitX = (xWidth - 150) / tbJuLiSum; double tbJuLiX = 150.0D; foreach (DataRow dr in m_dt.Rows) { tbJuLiX += UnitX * double.Parse(string.IsNullOrEmpty(dr["jl"].ToString()) ? "0" : dr["jl"].ToString()); dr["x"] = tbJuLiX; } #endregion #region 绘制 底部的表格横线 表格数据展示 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 == "jl")//距离直接显示,这个地方可以 设置 距离在2个断面的中间 //{ // g.DrawString(m_dt.Rows[j]["jl"].ToString(), fontNormal, defaultBrush, float.Parse(m_dt.Rows[j]["x"].ToString()), StringY); // continue; //} g.DrawString(m_dt.Rows[j][tbZiDuan].ToString(), fontNormal, defaultBrush, float.Parse(m_dt.Rows[j]["x"].ToString()), StringY); if (tbZiDuan == "gxgc")//计算Y坐标,只需要计算一次 { m_dt.Rows[j]["Y"] = (50 + UnitY * (gxgcMax + gxgcChaZhi * 2 - Double.Parse(m_dt.Rows[j]["gxgc"].ToString()))); } } } void GetTableColumsCaption(int i) { switch (i) { case 1: tbTitle = "距 离(M)"; tbZiDuan = "jl"; break; case 2: tbTitle = "管 径(MM)"; tbZiDuan = "gxgj"; break; case 3: tbTitle = "管线埋深(M)"; tbZiDuan = "gxms"; break; case 4: tbTitle = "管线高程(M)"; tbZiDuan = "gxgc"; break; case 5: tbTitle = "地面高程(M)"; tbZiDuan = "dmgc"; break; default: tbTitle = "未知"; tbZiDuan = ""; break; } } #endregion #region 绘制 断面管线 double gxgj = 0; double banjing = 0; Pen PenXuxian = new Pen(Color.Blue, 2); PenXuxian.DashStyle = DashStyle.Dash; for (int j = 0; j < m_dt.Rows.Count; j++) { double.TryParse(m_dt.Rows[j]["gxgj"].ToString(), out gxgj); banjing = gxgj / 1000 * UnitY; g.DrawEllipse(PenXYLine, (float)(float.Parse(m_dt.Rows[j]["x"].ToString()) - banjing), (float)(float.Parse(m_dt.Rows[j]["y"].ToString()) - banjing), (float)(banjing * 2), (float)(banjing * 2)); g.DrawLine(PenXuxian, float.Parse(m_dt.Rows[j]["x"].ToString()), (float)(float.Parse(m_dt.Rows[j]["y"].ToString()) + banjing), float.Parse(m_dt.Rows[j]["x"].ToString()), 596); } #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; uiDataGridView1.DataSource = m_dt; } protected override void WndProc(ref Message m) { //禁止双击标题栏关闭窗体 0xF093 //禁止拖拽标题栏还原窗体 0xF010 //禁止双击标题栏 0xf122 //禁止关闭按钮 0xF060 //禁止最大化按钮 0xf020 //禁止最小化按钮 0xf030 //禁止还原按钮 0xf120 if (m.Msg != 0xA3 && m.Msg != 0x0003 && m.WParam != (IntPtr)0xF012) { base.WndProc(ref m); } } 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; } } }