DuanMianAnalystResult.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using WWPipeLine.MapBasic;
  12. namespace WWPipeLine.MapTools.Conditions.AnalystToolBar
  13. {
  14. public partial class DuanMianAnalystResult : Sunny.UI.UIForm
  15. {
  16. private DataTable m_dt;
  17. public DuanMianAnalystResult(DataTable dt)
  18. {
  19. InitializeComponent();
  20. this.StartPosition = FormStartPosition.Manual;
  21. this.Location = new Point(10, 10);
  22. m_dt = dt;
  23. }
  24. private void AnalystResultForm_Load(object sender, EventArgs e)
  25. {
  26. DataColumn dataColumn;
  27. dataColumn = new DataColumn { ColumnName = "x", Caption = "X坐标", DataType = Type.GetType("System.Double") }; m_dt.Columns.Add(dataColumn);
  28. dataColumn = new DataColumn { ColumnName = "y", Caption = "Y坐标", DataType = Type.GetType("System.Double") }; m_dt.Columns.Add(dataColumn);
  29. dataColumn = new DataColumn { ColumnName = "xLeft", Caption = "X坐标向左偏移", DataType = Type.GetType("System.Double") }; m_dt.Columns.Add(dataColumn);
  30. int width = 800;// pictureBox.Width;
  31. int height = 600;// pictureBox.Height;
  32. Bitmap image = new Bitmap(width, height);
  33. //创建Graphics类对象
  34. Graphics g = Graphics.FromImage(image);
  35. g.SmoothingMode = SmoothingMode.AntiAlias;
  36. g.InterpolationMode = InterpolationMode.HighQualityBicubic;
  37. g.CompositingQuality = CompositingQuality.HighQuality;
  38. g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
  39. g.Clear(Color.White);
  40. Pen PenXYLine = Pens.Blue;
  41. Brush defaultBrush = Brushes.Black;
  42. Font fontNormal = new Font("Arial", 9, FontStyle.Regular);
  43. Font fontTitle = new Font("Arial", 16, FontStyle.Bold);
  44. //顶部标题
  45. g.DrawString(uitxtTitle.Text, fontTitle, defaultBrush, new PointF(width / 3, 10));
  46. //画图片的边框线
  47. g.DrawRectangle(PenXYLine, 0, 50, width - 2, height - 52);
  48. //绘制 Y轴线,直接从顶到底
  49. g.DrawLine(PenXYLine, 100, 50, 100, height);
  50. int yHeight = 450;// height - 50 - TableLineHeight * 5;
  51. int gxgcFenDuanHeight = 75;// (int)450 / 6; //(int)((height - 55 - TableLineHeight * 6) / 6
  52. #region 计算 Y轴 最大值与最小值 Y轴设置横线5根,数据值5个,分为6段,7个节点
  53. DataView m_dt_dv = m_dt.DefaultView;
  54. m_dt_dv.Sort = "gxgc DESC";
  55. double gxgcMax = 0.0; double.TryParse(m_dt_dv[0]["gxgc"].ToString(), out gxgcMax); gxgcMax = Math.Round(gxgcMax, 2);
  56. double gxgcMin = 0.0; double.TryParse(m_dt_dv[m_dt_dv.Count - 1]["gxgc"].ToString(), out gxgcMin); gxgcMin = Math.Round(gxgcMin, 2);
  57. double gxgcChaZhi = Math.Round(gxgcMax - (gxgcMax + gxgcMin) / 2, 2);
  58. if (gxgcChaZhi == 0 || gxgcChaZhi == double.PositiveInfinity || gxgcChaZhi == double.NegativeInfinity)
  59. {
  60. gxgcChaZhi = 1;
  61. }
  62. double gxgcTop = gxgcMax + gxgcChaZhi * 2;
  63. for (int i = 0; i <= 6; i++)//Y轴分为6段,除了顶部和底部,需要绘制5个 短横线和坐标值
  64. {
  65. if (i == 0 || i == 6) continue;
  66. g.DrawLine(PenXYLine, 95, 50 + i * gxgcFenDuanHeight, 100, 50 + i * gxgcFenDuanHeight);
  67. g.DrawString(GetGxgcY(i).ToString(), fontNormal, defaultBrush, 50, 50 + i * gxgcFenDuanHeight - 5);
  68. }
  69. double GetGxgcY(int i)
  70. {
  71. switch (i)
  72. {
  73. case 0: return gxgcTop;
  74. case 1: return gxgcMax + gxgcChaZhi;
  75. case 2: return gxgcMax;
  76. case 3: return gxgcMax - gxgcChaZhi;
  77. case 4: return gxgcMin;
  78. case 5: return gxgcMin - gxgcChaZhi;
  79. case 6: return gxgcMin - gxgcChaZhi * 2;
  80. default: return 0.0;
  81. }
  82. }
  83. double UnitY = yHeight / (gxgcChaZhi * 6);
  84. #endregion
  85. #region X轴 计算UnitX 并配置断面的X坐标
  86. int xWidth = 700;
  87. double tbJuLiSum = Convert.ToDouble(m_dt.Compute("SUM(jl)", ""));
  88. if (tbJuLiSum == 0 || tbJuLiSum == double.PositiveInfinity || tbJuLiSum == double.NegativeInfinity)
  89. {
  90. tbJuLiSum = 1;
  91. }
  92. double UnitX = (xWidth - 150) / tbJuLiSum;
  93. double tbJuLiX = 150.0D;
  94. foreach (DataRow dr in m_dt.Rows)
  95. {
  96. if (m_dt.Rows.IndexOf(dr) == 0) { dr["x"] = tbJuLiX; continue; }
  97. double newJuli = UnitX * ComsStatic.StringToDouble(dr["jl"]);
  98. dr["xLeft"] = newJuli * 0.6;
  99. tbJuLiX += newJuli;
  100. dr["x"] = tbJuLiX;
  101. }
  102. #endregion
  103. #region 绘制 底部的表格横线 表格数据展示
  104. g.DrawString("管线高程(M)", fontNormal, defaultBrush, 40, 60);
  105. int TableLineHeight = 20;
  106. string tbTitle = "";
  107. string tbZiDuan = "";
  108. for (int i = 1; i <= 5; i++)
  109. {
  110. g.DrawLine(PenXYLine, 0, height - i * TableLineHeight, width, height - i * TableLineHeight);
  111. GetTableColumsCaption(i);
  112. float StringY = height - i * TableLineHeight + 5;
  113. g.DrawString(tbTitle, fontNormal, defaultBrush, 20, StringY);
  114. for (int j = 0; j < m_dt.Rows.Count; j++)
  115. {
  116. if (tbZiDuan == "jl")//距离直接显示,这个地方可以 设置 距离在2个断面的中间
  117. {
  118. if (j == 0) continue;
  119. g.DrawString(m_dt.Rows[j]["jl"].ToString(), fontNormal, defaultBrush, float.Parse(m_dt.Rows[j]["x"].ToString()) - float.Parse(m_dt.Rows[j]["xLeft"].ToString()), StringY);
  120. continue;
  121. }
  122. g.DrawString(m_dt.Rows[j][tbZiDuan].ToString(), fontNormal, defaultBrush, float.Parse(m_dt.Rows[j]["x"].ToString()), StringY);
  123. if (tbZiDuan == "gxgc")//计算Y坐标,只需要计算一次
  124. {
  125. m_dt.Rows[j]["Y"] = (50 + UnitY * (gxgcTop - Double.Parse(m_dt.Rows[j]["gxgc"].ToString())));
  126. }
  127. }
  128. }
  129. void GetTableColumsCaption(int i)
  130. {
  131. switch (i)
  132. {
  133. case 1: tbTitle = "距 离(M)"; tbZiDuan = "jl"; break;
  134. case 2: tbTitle = "管 径(MM)"; tbZiDuan = "gxgj"; break;
  135. case 3: tbTitle = "管线埋深(M)"; tbZiDuan = "gxms"; break;
  136. case 4: tbTitle = "管线高程(M)"; tbZiDuan = "gxgc"; break;
  137. case 5: tbTitle = "地面高程(M)"; tbZiDuan = "dmgc"; break;
  138. default: tbTitle = "未知"; tbZiDuan = ""; break;
  139. }
  140. }
  141. #endregion
  142. #region 绘制 断面管线
  143. double gxgj = 0;
  144. double zhijing = 0;
  145. Pen PenXuxian = new Pen(Color.Blue, 2); PenXuxian.DashStyle = DashStyle.Dash;
  146. for (int j = 0; j < m_dt.Rows.Count; j++)
  147. {
  148. double.TryParse(m_dt.Rows[j]["gxgj"].ToString(), out gxgj);
  149. zhijing = gxgj / 1000 * UnitY;
  150. g.DrawEllipse(PenXYLine, (float)(float.Parse(m_dt.Rows[j]["x"].ToString()) - zhijing * 0.5), (float)(float.Parse(m_dt.Rows[j]["y"].ToString()) - zhijing * 0.5), (float)(zhijing), (float)(zhijing));
  151. g.DrawLine(PenXuxian, float.Parse(m_dt.Rows[j]["x"].ToString()), (float)(float.Parse(m_dt.Rows[j]["y"].ToString()) + zhijing * 0.5), float.Parse(m_dt.Rows[j]["x"].ToString()), 596);
  152. }
  153. #endregion
  154. //显示 比例尺
  155. string bilichi = string.Format("水平比例尺 1:{0} 垂直比例尺 1:{1} ", Math.Round(UnitX, 0), Math.Round(UnitY, 0));
  156. g.DrawString(bilichi, fontNormal, defaultBrush, width / 3, 60);
  157. pictureBox.Image = image;
  158. }
  159. protected override void WndProc(ref Message m)
  160. {
  161. //禁止双击标题栏关闭窗体 0xF093
  162. //禁止拖拽标题栏还原窗体 0xF010
  163. //禁止双击标题栏 0xf122
  164. //禁止关闭按钮 0xF060
  165. //禁止最大化按钮 0xf020
  166. //禁止最小化按钮 0xf030
  167. //禁止还原按钮 0xf120
  168. if (m.Msg != 0xA3 && m.Msg != 0x0003 && m.WParam != (IntPtr)0xF012)
  169. {
  170. base.WndProc(ref m);
  171. }
  172. }
  173. private void uibtnSave_Click(object sender, EventArgs e)
  174. {
  175. SaveFileDialog save = new SaveFileDialog();
  176. save.FileName = uitxtTitle.Text;
  177. save.Filter = "Jpg 图片|*.jpg|Bmp 图片|*.bmp|Png 图片|*.png";
  178. if (save.ShowDialog() == DialogResult.OK)
  179. {
  180. pictureBox.Image.Save(save.FileName);
  181. }
  182. }
  183. private void uibtnQuantu_Click(object sender, EventArgs e)
  184. {
  185. pictureBox.MouseUp -= PictureBox_MouseUp;
  186. pictureBox.Width = 800;
  187. pictureBox.Height = 600;
  188. pictureBox.SizeMode = PictureBoxSizeMode.AutoSize;
  189. pictureBox.Refresh();
  190. }
  191. private void uiIbtnFangda_Click(object sender, EventArgs e)
  192. {
  193. pictureBox.MouseUp -= PictureBox_MouseUp;
  194. pictureBox.SizeMode = PictureBoxSizeMode.StretchImage;
  195. pictureBox.Width = (int)(pictureBox.Width * 1.2);
  196. pictureBox.Height = (int)(pictureBox.Height * 1.2);
  197. pictureBox.Refresh();
  198. }
  199. private void uibtnSuoxiao_Click(object sender, EventArgs e)
  200. {
  201. pictureBox.MouseUp -= PictureBox_MouseUp;
  202. pictureBox.SizeMode = PictureBoxSizeMode.StretchImage;
  203. pictureBox.Width = (int)(pictureBox.Width * 0.8);
  204. pictureBox.Height = (int)(pictureBox.Height * 0.8);
  205. pictureBox.Refresh();
  206. }
  207. private void uibtnPingyi_Click(object sender, EventArgs e)
  208. {
  209. pictureBox.SizeMode = PictureBoxSizeMode.AutoSize;
  210. pictureBox.Cursor = Cursors.Hand;
  211. pictureBox.MouseUp += PictureBox_MouseUp;
  212. }
  213. private void PictureBox_MouseUp(object sender, MouseEventArgs e)
  214. {
  215. }
  216. private void AnalystResultForm_FormClosing(object sender, FormClosingEventArgs e)
  217. {
  218. pictureBox.MouseUp -= PictureBox_MouseUp;
  219. }
  220. }
  221. }