frmStation.cs
上传用户:xum6868
上传日期:2009-12-02
资源大小:102k
文件大小:8k
源码类别:

GIS编程

开发平台:

C#

  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. namespace MainSystem
  7. {
  8. /// <summary>
  9. /// Summary description for frmStation.
  10. /// </summary>
  11. public class frmStation : System.Windows.Forms.Form
  12. {
  13. private frmMain _frmMain;
  14. private string _szStaName;
  15. private System.Windows.Forms.Button button1;
  16. private System.Windows.Forms.Label _label2;
  17. private System.Windows.Forms.Label _label_Statation;
  18. private System.Windows.Forms.ListBox _listBox;
  19. /// <summary>
  20. /// Required designer variable.
  21. /// </summary>
  22. private System.ComponentModel.Container components = null;
  23. public frmStation(frmMain frmMain, string szStaName)
  24. {
  25. _frmMain = frmMain;
  26. _szStaName = szStaName;
  27. InitializeComponent();
  28. }
  29. /// <summary>
  30. /// Clean up any resources being used.
  31. /// </summary>
  32. protected override void Dispose( bool disposing )
  33. {
  34. if( disposing )
  35. {
  36. if(components != null)
  37. {
  38. components.Dispose();
  39. }
  40. }
  41. base.Dispose( disposing );
  42. }
  43. #region Windows Form Designer generated code
  44. /// <summary>
  45. /// Required method for Designer support - do not modify
  46. /// the contents of this method with the code editor.
  47. /// </summary>
  48. private void InitializeComponent()
  49. {
  50. this.button1 = new System.Windows.Forms.Button();
  51. this._label2 = new System.Windows.Forms.Label();
  52. this._label_Statation = new System.Windows.Forms.Label();
  53. this._listBox = new System.Windows.Forms.ListBox();
  54. this.SuspendLayout();
  55. // 
  56. // button1
  57. // 
  58. this.button1.Enabled = false;
  59. this.button1.Location = new System.Drawing.Point(152, 8);
  60. this.button1.Name = "button1";
  61. this.button1.Size = new System.Drawing.Size(56, 24);
  62. this.button1.TabIndex = 7;
  63. this.button1.Text = "定位";
  64. this.button1.Click += new System.EventHandler(this.button1_Click);
  65. // 
  66. // _label2
  67. // 
  68. this._label2.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
  69. | System.Windows.Forms.AnchorStyles.Right);
  70. this._label2.Font = new System.Drawing.Font("SimSun", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
  71. this._label2.Location = new System.Drawing.Point(8, 32);
  72. this._label2.Name = "_label2";
  73. this._label2.Size = new System.Drawing.Size(200, 24);
  74. this._label2.TabIndex = 6;
  75. // 
  76. // _label_Statation
  77. // 
  78. this._label_Statation.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
  79. | System.Windows.Forms.AnchorStyles.Right);
  80. this._label_Statation.Font = new System.Drawing.Font("SimSun", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
  81. this._label_Statation.Location = new System.Drawing.Point(8, 8);
  82. this._label_Statation.Name = "_label_Statation";
  83. this._label_Statation.Size = new System.Drawing.Size(200, 24);
  84. this._label_Statation.TabIndex = 5;
  85. // 
  86. // _listBox
  87. // 
  88. this._listBox.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
  89. | System.Windows.Forms.AnchorStyles.Left) 
  90. | System.Windows.Forms.AnchorStyles.Right);
  91. this._listBox.ItemHeight = 12;
  92. this._listBox.Location = new System.Drawing.Point(8, 56);
  93. this._listBox.Name = "_listBox";
  94. this._listBox.Size = new System.Drawing.Size(200, 220);
  95. this._listBox.TabIndex = 4;
  96. this._listBox.DoubleClick += new System.EventHandler(this._listBox_DoubleClick);
  97. this._listBox.SelectedIndexChanged += new System.EventHandler(this._listBox_SelectedIndexChanged);
  98. // 
  99. // frmStation
  100. // 
  101. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  102. this.ClientSize = new System.Drawing.Size(224, 277);
  103. this.Controls.AddRange(new System.Windows.Forms.Control[] {
  104.   this.button1,
  105.   this._label2,
  106.   this._label_Statation,
  107.   this._listBox});
  108. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
  109. this.MaximizeBox = false;
  110. this.MinimizeBox = false;
  111. this.Name = "frmStation";
  112. this.Text = "车站信息";
  113. this.TopMost = true;
  114. this.Load += new System.EventHandler(this.frmStation_Load);
  115. this.ResumeLayout(false);
  116. }
  117. #endregion
  118. //功能:单击按钮,定位指定的公交路线
  119. private void button1_Click(object sender, System.EventArgs e)
  120. {
  121. string szName = _listBox.Text; //公交路线名称
  122. string szLayer = CEnvironment.BUSLINE_LAYERNAME;//公交路线所在图层名称
  123. MapObjects2.MapLayer ly = (MapObjects2.MapLayer)_frmMain._map.Layers.Item((object)szLayer);
  124. if (ly == null)
  125. return;
  126. MapObjects2.Recordset rs = ly.SearchExpression("名称 like '"+szName +"'");;
  127. if (null == rs)
  128. {
  129. MessageBox.Show("地图上没有这条公交线路!","北京市地理信息公众查询系统",MessageBoxButtons.OK,MessageBoxIcon.Error);
  130. return;
  131. }
  132. rs.MoveFirst(); 
  133. if (rs.EOF)
  134. {
  135. MessageBox.Show("地图上没有这条公交线路!","北京市地理信息公众查询系统",MessageBoxButtons.OK,MessageBoxIcon.Error);
  136. return;
  137. }
  138. //在地图找到了这条线路,画出来
  139. //首先定位
  140. MapObjects2.Point pt;
  141. MapObjects2.Line line = (MapObjects2.Line)rs.Fields.Item("shape").Value;
  142. pt = line.Extent.Center;
  143. if (!_frmMain.IsWithin(_frmMain._map.Extent, pt))  
  144. {
  145. _frmMain._map.CenterAt(pt.X,pt.Y );   
  146. }
  147. //其次设置_environment.m_drawLine和_environment.m_buses
  148. MapObjects2.Points pts;
  149. pts = (MapObjects2.Points)line.Parts.Item(0);
  150. _frmMain._environment.m_drawLine = null;
  151. _frmMain._environment.m_drawLine = new MLine[1];
  152. _frmMain._environment.m_drawLine[0] = new MLine();
  153. _frmMain._environment.m_drawLine[0].nPointNumber = pts.Count;
  154. _frmMain._environment.m_drawLine[0].pPoint = new MPoint[pts.Count];
  155. for (int i = 0; i < pts.Count; i ++)
  156. {
  157. pt = (MapObjects2.Point)pts.Item(i);
  158. _frmMain._environment.m_drawLine[0].pPoint[i] = new MPoint();
  159. _frmMain._environment.m_drawLine[0].pPoint[i].x = pt.X;
  160. _frmMain._environment.m_drawLine[0].pPoint[i].y = pt.Y;
  161. }
  162. _frmMain._environment.m_buses = new Buses();
  163. int nCount = 0;
  164. if(!_frmMain._environment.GetStation(szName, _frmMain._environment.m_buses,ref nCount)) 
  165. _frmMain._environment.m_buses = null;
  166. else
  167. _frmMain._environment.m_buses.nNum = nCount; 
  168. //闪烁,重画
  169. _frmMain._map.FlashShape(rs.Fields.Item("shape").Value, 4);
  170. _frmMain._map.Extent = _frmMain._map.Extent; 
  171. }
  172. private void frmStation_Load(object sender, System.EventArgs e)
  173. {
  174. this._label_Statation.Text  = " 车站名称:"+this._szStaName;
  175. this._label2.Text = "经过"+this._szStaName+"的公交线路:";
  176. LoadListBox();
  177. }
  178. private void LoadListBox()
  179. {
  180. _listBox.Items.Clear();  
  181. if ("" == _szStaName)
  182. return ;
  183. System.Data.DataTable typeTbl = this._frmMain._environment.m_dataSet.Tables["公交车站路线"];
  184. string szFilter = "站名='"+_szStaName+"'";
  185. if (_frmMain._environment.m_szBusFilter != "")
  186. {
  187. szFilter += " And ";
  188. szFilter += _frmMain._environment.m_szBusFilter;
  189. }
  190. System.Data.DataRow[] rowstypes = typeTbl.Select(szFilter);
  191. foreach (System.Data.DataRow myRow in rowstypes)
  192. {
  193. this._listBox.Items.Add(myRow["线路名"]);  
  194. }
  195. }
  196. private void _listBox_SelectedIndexChanged(object sender, System.EventArgs e)
  197. {
  198. if (_listBox.Text != "")
  199. button1.Enabled = true;
  200. else
  201. button1.Enabled = false;
  202. }
  203. private void _listBox_DoubleClick(object sender, System.EventArgs e)
  204. {
  205. if (_listBox.Text == "")
  206. return;
  207. frmLine frm = new frmLine(this._frmMain,_listBox.Text );
  208. this.Visible = false;
  209. frm.ShowDialog(this._frmMain);
  210. this.Close(); 
  211. }
  212. }
  213. }