PouMianAnalystResult.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. using SuperMap.Data;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Drawing.Drawing2D;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. namespace WWPipeLine.MapTools.Conditions.AnalystToolBar
  13. {
  14. public partial class PouMianAnalystResult : Sunny.UI.UIForm
  15. {
  16. private DataTable m_dt;
  17. public PouMianAnalystResult(DataTable dt)
  18. {
  19. InitializeComponent();
  20. this.StartPosition = FormStartPosition.Manual;
  21. this.Location = new System.Drawing.Point(10, 10);
  22. m_dt = dt;
  23. }
  24. private void AnalystResultForm_Load(object sender, EventArgs e)
  25. {
  26. int width = 800;// pictureBox.Width;
  27. int height = 600;// pictureBox.Height;
  28. Bitmap image = new Bitmap(width, height);
  29. //创建Graphics类对象
  30. Graphics g = Graphics.FromImage(image);
  31. g.SmoothingMode = SmoothingMode.AntiAlias;
  32. g.InterpolationMode = InterpolationMode.HighQualityBicubic;
  33. g.CompositingQuality = CompositingQuality.HighQuality;
  34. g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
  35. g.Clear(Color.White);
  36. Pen PenXYLine = Pens.Blue;
  37. Pen PenBlack = Pens.Black;
  38. Brush defaultBrush = Brushes.Black;
  39. Font fontNormal = new Font("Arial", 9, FontStyle.Regular);
  40. Font fontTitle = new Font("Arial", 16, FontStyle.Bold);
  41. //顶部标题
  42. g.DrawString(uitxtTitle.Text, fontTitle, defaultBrush, new PointF(width / 3, 10));
  43. //画图片的边框线
  44. g.DrawRectangle(PenXYLine, 0, 50, width - 2, height - 52);
  45. //绘制 Y轴线,直接从顶到底
  46. g.DrawLine(PenXYLine, 100, 50, 100, height);
  47. int yHeight = 450;// height - 50 - TableLineHeight * 5;
  48. int gxgcFenDuanHeight = 75;// (int)450 / 6; //(int)((height - 55 - TableLineHeight * 6) / 6
  49. #region 计算 Y轴 最大值与最小值 Y轴设置横线5根,数据值5个,分为6段,7个节点
  50. DataView m_dt_dv = m_dt.DefaultView;
  51. //高程最大值 取地面高程的最大值
  52. m_dt_dv.Sort = "dmgc DESC"; double gcMax = Math.Round(double.Parse(m_dt_dv[0]["dmgc"].ToString()), 2);
  53. //高程最小值 =管顶高程最小值-管点埋深最大值
  54. m_dt_dv.Sort = "gdgc ASC"; double gdgcMin = Math.Round(double.Parse(m_dt_dv[0]["gdgc"].ToString()), 2);
  55. m_dt_dv.Sort = "gdms DESC"; double gdmsMin = Math.Round(double.Parse(m_dt_dv[0]["gdms"].ToString()), 2);
  56. double gcMin = gdgcMin - gdmsMin;
  57. //Y轴共计6段,计算每一段的差值
  58. double gdgcChaZhi = Math.Round(gcMax - (gcMax + gcMin) / 2, 2);
  59. if (gdgcChaZhi == 0 || gdgcChaZhi == double.PositiveInfinity || gdgcChaZhi == double.NegativeInfinity)
  60. {
  61. gdgcChaZhi = 1;
  62. }
  63. double gdgcTop = gcMax + gdgcChaZhi * 2;
  64. for (int i = 0; i <= 6; i++)//Y轴分为6段,除了顶部和底部,需要绘制5个 短横线和坐标值
  65. {
  66. if (i == 0 || i == 6) continue;
  67. g.DrawLine(PenXYLine, 95, 50 + i * gxgcFenDuanHeight, 100, 50 + i * gxgcFenDuanHeight);
  68. g.DrawString(GetGxgcY(i).ToString(), fontNormal, defaultBrush, 50, 50 + i * gxgcFenDuanHeight - 5);
  69. }
  70. double GetGxgcY(int i)
  71. {
  72. switch (i)
  73. {
  74. case 0: return gdgcTop;
  75. case 1: return gdgcTop - gdgcChaZhi;
  76. case 2: return gcMax;
  77. case 3: return gcMax - gdgcChaZhi;
  78. case 4: return gcMax - gdgcChaZhi * 2;
  79. case 5: return gcMax - gdgcChaZhi * 3;
  80. case 6: return gcMax - gdgcChaZhi * 4;
  81. default: return 0.0;
  82. }
  83. }
  84. double UnitY = yHeight / (gdgcChaZhi * 6);
  85. #endregion
  86. #region X轴 计算UnitX 并配置断面的X坐标
  87. int xWidth = 700;
  88. double tbJuLiSum = 0.0D;
  89. foreach (DataRow dr in m_dt.Rows)
  90. {
  91. if (m_dt.Rows.IndexOf(dr) == m_dt.Rows.Count - 1) continue;
  92. tbJuLiSum += double.Parse(dr["gxcd"].ToString());
  93. }
  94. if (tbJuLiSum == 0 || tbJuLiSum == double.PositiveInfinity || tbJuLiSum == double.NegativeInfinity)
  95. {
  96. tbJuLiSum = 1;
  97. }
  98. double UnitX = (xWidth - 120) / tbJuLiSum;
  99. double tbJuLiX = 120.0D;
  100. foreach (DataRow dr in m_dt.Rows)
  101. {
  102. double newJuli = UnitX * double.Parse(dr["gxcd"].ToString());
  103. dr["xLeft"] = newJuli * 0.6;
  104. if (m_dt.Rows.IndexOf(dr) == 0) { dr["x"] = tbJuLiX; continue; }
  105. tbJuLiX += newJuli;
  106. dr["x"] = tbJuLiX;
  107. }
  108. #endregion
  109. #region 绘制 底部的表格横线 表格数据展示
  110. g.DrawString("地面高程(M)", fontNormal, defaultBrush, 40, 60);
  111. int TableLineHeight = 20;
  112. string tbTitle = "";
  113. string tbZiDuan = "";
  114. for (int i = 1; i <= 5; i++)
  115. {
  116. g.DrawLine(PenXYLine, 0, height - i * TableLineHeight, width, height - i * TableLineHeight);
  117. GetTableColumsCaption(i);
  118. float StringY = height - i * TableLineHeight + 5;
  119. g.DrawString(tbTitle, fontNormal, defaultBrush, 20, StringY);
  120. for (int j = 0; j < m_dt.Rows.Count; j++)
  121. {
  122. if (tbZiDuan == "gxgj" || tbZiDuan == "gxcd")
  123. {
  124. if (j == m_dt.Rows.Count - 1) continue;
  125. 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);
  126. continue;
  127. }
  128. g.DrawString(m_dt.Rows[j][tbZiDuan].ToString(), fontNormal, defaultBrush, float.Parse(m_dt.Rows[j]["x"].ToString()), StringY);
  129. if (tbZiDuan == "dmgc")//计算Y坐标,只需要计算一次
  130. {
  131. m_dt.Rows[j]["y"] = 50 + UnitY * (gdgcTop - Double.Parse(m_dt.Rows[j]["dmgc"].ToString()));
  132. m_dt.Rows[j]["ygd"] = double.Parse(m_dt.Rows[j]["y"].ToString()) + UnitY * Double.Parse(m_dt.Rows[j]["gdms"].ToString());
  133. }
  134. }
  135. }
  136. void GetTableColumsCaption(int i)
  137. {
  138. switch (i)
  139. {
  140. case 1: tbTitle = "管线长度(M)"; tbZiDuan = "gxcd"; break;
  141. case 2: tbTitle = "管线管径(MM)"; tbZiDuan = "gxgj"; break;
  142. case 3: tbTitle = "管点埋深(M)"; tbZiDuan = "gdms"; break;
  143. case 4: tbTitle = "管顶高程(M)"; tbZiDuan = "gdgc"; break;
  144. case 5: tbTitle = "地面高程(M)"; tbZiDuan = "dmgc"; break;
  145. default: tbTitle = "未知"; tbZiDuan = ""; break;
  146. }
  147. }
  148. #endregion
  149. #region 绘制 断面管线
  150. float gxgj = 0;
  151. float Ydmgc = 0.0F;
  152. float Xdmgc = 0.0F;
  153. float Ygdgc = 0.0F;
  154. for (int j = 0; j < m_dt.Rows.Count; j++)
  155. {
  156. float.TryParse(m_dt.Rows[j]["gxgj"].ToString(), out gxgj);
  157. gxgj = (float)(gxgj / 1000 * UnitY);
  158. Xdmgc = float.Parse(m_dt.Rows[j]["x"].ToString());
  159. Ydmgc = float.Parse(m_dt.Rows[j]["y"].ToString());
  160. Ygdgc = float.Parse(m_dt.Rows[j]["ygd"].ToString());
  161. //绘制 地面高程 到 管顶高程的 竖线 该管点为管线的起始管点
  162. //g.DrawLine(PenXYLine, Xdmgc, Ydmgc, Xdmgc, Ygdgc);
  163. if (j == 0)//第一行 只需要绘制地面高程到管顶高程的竖线
  164. {
  165. g.DrawLine(PenBlack, Xdmgc, Ygdgc, Xdmgc, Ygdgc + gxgj);
  166. continue;
  167. }
  168. //绘制地面高程线 管线的 起始管点 到 终点管点
  169. g.DrawLine(PenBlack, float.Parse(m_dt.Rows[j - 1]["x"].ToString()), float.Parse(m_dt.Rows[j - 1]["y"].ToString()), Xdmgc, Ydmgc);
  170. //绘制管顶高程线 管线的 起始管点 到 终点管点的 管顶
  171. g.DrawLine(PenBlack, float.Parse(m_dt.Rows[j - 1]["x"].ToString()), float.Parse(m_dt.Rows[j - 1]["ygd"].ToString()), Xdmgc, Ygdgc);
  172. //绘制管底高程线
  173. 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);
  174. //绘制管头的竖线
  175. g.DrawLine(PenBlack, Xdmgc, Ygdgc, Xdmgc, Ygdgc + gxgj);
  176. }
  177. #endregion
  178. //显示 比例尺
  179. string bilichi = string.Format("水平比例尺 1:{0} 垂直比例尺 1:{1} ", Math.Round(UnitX, 0), Math.Round(UnitY, 0));
  180. g.DrawString(bilichi, fontNormal, defaultBrush, width / 3, 60);
  181. pictureBox.Image = image;
  182. }
  183. private void uibtnSave_Click(object sender, EventArgs e)
  184. {
  185. SaveFileDialog save = new SaveFileDialog();
  186. save.FileName = uitxtTitle.Text;
  187. save.Filter = "Jpg 图片|*.jpg|Bmp 图片|*.bmp|Png 图片|*.png";
  188. if (save.ShowDialog() == DialogResult.OK)
  189. {
  190. pictureBox.Image.Save(save.FileName);
  191. }
  192. }
  193. private void uibtnQuantu_Click(object sender, EventArgs e)
  194. {
  195. pictureBox.MouseUp -= PictureBox_MouseUp;
  196. pictureBox.Width = 800;
  197. pictureBox.Height = 600;
  198. pictureBox.SizeMode = PictureBoxSizeMode.AutoSize;
  199. pictureBox.Refresh();
  200. }
  201. private void uiIbtnFangda_Click(object sender, EventArgs e)
  202. {
  203. pictureBox.MouseUp -= PictureBox_MouseUp;
  204. pictureBox.SizeMode = PictureBoxSizeMode.StretchImage;
  205. pictureBox.Width = (int)(pictureBox.Width * 1.2);
  206. pictureBox.Height = (int)(pictureBox.Height * 1.2);
  207. pictureBox.Refresh();
  208. }
  209. private void uibtnSuoxiao_Click(object sender, EventArgs e)
  210. {
  211. pictureBox.MouseUp -= PictureBox_MouseUp;
  212. pictureBox.SizeMode = PictureBoxSizeMode.StretchImage;
  213. pictureBox.Width = (int)(pictureBox.Width * 0.8);
  214. pictureBox.Height = (int)(pictureBox.Height * 0.8);
  215. pictureBox.Refresh();
  216. }
  217. private void uibtnPingyi_Click(object sender, EventArgs e)
  218. {
  219. pictureBox.SizeMode = PictureBoxSizeMode.AutoSize;
  220. pictureBox.Cursor = Cursors.Hand;
  221. pictureBox.MouseUp += PictureBox_MouseUp;
  222. }
  223. private void PictureBox_MouseUp(object sender, MouseEventArgs e)
  224. {
  225. }
  226. private void AnalystResultForm_FormClosing(object sender, FormClosingEventArgs e)
  227. {
  228. pictureBox.MouseUp -= PictureBox_MouseUp;
  229. }
  230. }
  231. }