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

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 frmBus.
  10. /// </summary>
  11. public class frmBus : System.Windows.Forms.Form
  12. {
  13. private frmMain _frmMain;
  14. private bool _bTextBox1 = true;
  15. private bool _bTextBox2 = true;
  16. private System.Windows.Forms.Label _label_end;
  17. private System.Windows.Forms.Label _label_start;
  18. private System.Windows.Forms.ListBox _listBox_end;
  19. private System.Windows.Forms.ListBox _listBox_start;
  20. private System.Windows.Forms.Button _button_search;
  21. private System.Windows.Forms.TextBox _textBox_end;
  22. private System.Windows.Forms.TextBox _textBox_start;
  23. /// <summary>
  24. /// Required designer variable.
  25. /// </summary>
  26. private System.ComponentModel.Container components = null;
  27. public frmBus(frmMain frm)
  28. {
  29. _frmMain = frm;
  30. InitializeComponent();
  31. }
  32. /// <summary>
  33. /// Clean up any resources being used.
  34. /// </summary>
  35. protected override void Dispose( bool disposing )
  36. {
  37. if( disposing )
  38. {
  39. if(components != null)
  40. {
  41. components.Dispose();
  42. }
  43. }
  44. base.Dispose( disposing );
  45. }
  46. #region Windows Form Designer generated code
  47. /// <summary>
  48. /// Required method for Designer support - do not modify
  49. /// the contents of this method with the code editor.
  50. /// </summary>
  51. private void InitializeComponent()
  52. {
  53. this._label_end = new System.Windows.Forms.Label();
  54. this._label_start = new System.Windows.Forms.Label();
  55. this._listBox_end = new System.Windows.Forms.ListBox();
  56. this._listBox_start = new System.Windows.Forms.ListBox();
  57. this._button_search = new System.Windows.Forms.Button();
  58. this._textBox_end = new System.Windows.Forms.TextBox();
  59. this._textBox_start = new System.Windows.Forms.TextBox();
  60. this.SuspendLayout();
  61. // 
  62. // _label_end
  63. // 
  64. this._label_end.Font = new System.Drawing.Font("SimSun", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
  65. this._label_end.Location = new System.Drawing.Point(152, 8);
  66. this._label_end.Name = "_label_end";
  67. this._label_end.Size = new System.Drawing.Size(80, 16);
  68. this._label_end.TabIndex = 14;
  69. this._label_end.Text = "终点站:";
  70. // 
  71. // _label_start
  72. // 
  73. this._label_start.Font = new System.Drawing.Font("SimSun", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
  74. this._label_start.Location = new System.Drawing.Point(8, 8);
  75. this._label_start.Name = "_label_start";
  76. this._label_start.Size = new System.Drawing.Size(80, 16);
  77. this._label_start.TabIndex = 13;
  78. this._label_start.Text = "起点站:";
  79. // 
  80. // _listBox_end
  81. // 
  82. this._listBox_end.ItemHeight = 12;
  83. this._listBox_end.Location = new System.Drawing.Point(152, 56);
  84. this._listBox_end.Name = "_listBox_end";
  85. this._listBox_end.Size = new System.Drawing.Size(128, 208);
  86. this._listBox_end.TabIndex = 12;
  87. this._listBox_end.MouseDown += new System.Windows.Forms.MouseEventHandler(this._listBox_end_MouseDown);
  88. this._listBox_end.SelectedIndexChanged += new System.EventHandler(this._listBox_end_SelectedIndexChanged);
  89. // 
  90. // _listBox_start
  91. // 
  92. this._listBox_start.ItemHeight = 12;
  93. this._listBox_start.Location = new System.Drawing.Point(8, 56);
  94. this._listBox_start.Name = "_listBox_start";
  95. this._listBox_start.Size = new System.Drawing.Size(128, 208);
  96. this._listBox_start.TabIndex = 11;
  97. this._listBox_start.MouseDown += new System.Windows.Forms.MouseEventHandler(this._listBox_start_MouseDown);
  98. this._listBox_start.SelectedIndexChanged += new System.EventHandler(this._listBox_start_SelectedIndexChanged);
  99. // 
  100. // _button_search
  101. // 
  102. this._button_search.Location = new System.Drawing.Point(296, 24);
  103. this._button_search.Name = "_button_search";
  104. this._button_search.Size = new System.Drawing.Size(72, 24);
  105. this._button_search.TabIndex = 10;
  106. this._button_search.Text = "查询";
  107. this._button_search.Click += new System.EventHandler(this._button_search_Click);
  108. // 
  109. // _textBox_end
  110. // 
  111. this._textBox_end.Location = new System.Drawing.Point(152, 24);
  112. this._textBox_end.Name = "_textBox_end";
  113. this._textBox_end.Size = new System.Drawing.Size(128, 21);
  114. this._textBox_end.TabIndex = 9;
  115. this._textBox_end.Text = "";
  116. this._textBox_end.TextChanged += new System.EventHandler(this._textBox_end_TextChanged);
  117. // 
  118. // _textBox_start
  119. // 
  120. this._textBox_start.Location = new System.Drawing.Point(8, 24);
  121. this._textBox_start.Name = "_textBox_start";
  122. this._textBox_start.Size = new System.Drawing.Size(128, 21);
  123. this._textBox_start.TabIndex = 8;
  124. this._textBox_start.Text = "";
  125. this._textBox_start.TextChanged += new System.EventHandler(this._textBox_start_TextChanged);
  126. // 
  127. // frmBus
  128. // 
  129. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  130. this.ClientSize = new System.Drawing.Size(376, 273);
  131. this.Controls.AddRange(new System.Windows.Forms.Control[] {
  132.   this._label_end,
  133.   this._label_start,
  134.   this._listBox_end,
  135.   this._listBox_start,
  136.   this._button_search,
  137.   this._textBox_end,
  138.   this._textBox_start});
  139. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
  140. this.Name = "frmBus";
  141. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  142. this.Text = "选择乘车路线";
  143. this.Load += new System.EventHandler(this.frmBus_Load);
  144. this.ResumeLayout(false);
  145. }
  146. #endregion
  147. private void frmBus_Load(object sender, System.EventArgs e)
  148. {
  149. LoadListBox();
  150. }
  151. private void LoadListBox()
  152. {
  153. _listBox_start.DataSource  = _frmMain._environment.m_dataSet.Tables["公交车站"];
  154. _listBox_start.DisplayMember = "站名";
  155. _listBox_end.DataSource  = _frmMain._environment.m_dataSet.Tables["公交车站2"];
  156. _listBox_end.DisplayMember = "站名";
  157. }
  158. private void _listBox_start_SelectedIndexChanged(object sender, System.EventArgs e)
  159. {
  160. if (!_bTextBox1)
  161. this._textBox_start.Text = _listBox_start.Text;
  162. }
  163. private void _listBox_end_SelectedIndexChanged(object sender, System.EventArgs e)
  164. {
  165. if (!_bTextBox2)
  166. this._textBox_end.Text = _listBox_end.Text;
  167. }
  168. private void _textBox_start_TextChanged(object sender, System.EventArgs e)
  169. {
  170. int nIndex = this._listBox_start.FindString(this._textBox_start.Text,-1); 
  171. if (nIndex != ListBox.NoMatches )
  172. {
  173. _listBox_start.SelectedIndex = nIndex;
  174. }
  175. if ((this._textBox_end.Text != "") && (this._textBox_start.Text != ""))
  176. this._button_search.Enabled = true;
  177. else
  178. this._button_search.Enabled = false; 
  179. _bTextBox1 = true;
  180. }
  181. private void _textBox_end_TextChanged(object sender, System.EventArgs e)
  182. {
  183. int nIndex = this._listBox_end.FindString(this._textBox_end.Text,-1); 
  184. if (nIndex != ListBox.NoMatches )
  185. {
  186. _listBox_end.SelectedIndex = nIndex;
  187. }
  188. if (this._textBox_end.Text != "" && this._textBox_start.Text != "")
  189. this._button_search.Enabled = true;
  190. else
  191. this._button_search.Enabled = false; 
  192. _bTextBox2 = true;
  193. }
  194. private void _listBox_start_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
  195. {
  196. _bTextBox1 = false;
  197. }
  198. private void _listBox_end_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
  199. {
  200. _bTextBox2 = false;
  201. }
  202. private void _button_search_Click(object sender, System.EventArgs e)
  203. {
  204. //判断站名的正确性
  205. if (!IsValidStation(this._textBox_start.Text))
  206. {
  207. MessageBox.Show("错误的起始站名。","北京市地理信息公众查询系统",MessageBoxButtons.OK,MessageBoxIcon.Information);
  208. return;
  209. }
  210. if (!IsValidStation(this._textBox_end.Text))
  211. {
  212. MessageBox.Show("错误的终点站名。","北京市地理信息公众查询系统",MessageBoxButtons.OK,MessageBoxIcon.Information);
  213. return;
  214. }
  215. CEnvironment env = _frmMain._environment;
  216. System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;  
  217. ArrayList array = new ArrayList();
  218. env.m_path.Search(this._textBox_start.Text,_textBox_end.Text,array);
  219. System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Arrow;  
  220.   
  221. if (array.Count ==0)
  222. {
  223. MessageBox.Show("没有合适的乘车路线。","北京市地理信息公众查询系统",MessageBoxButtons.OK,MessageBoxIcon.Information);
  224. return;
  225. }
  226. else
  227. {
  228. frmBusResult frm = new frmBusResult(this._frmMain,array);
  229. this.Visible = false;
  230. frm.ShowDialog(_frmMain); 
  231. this.Close();
  232. }
  233. }
  234. private bool IsValidStation(string szStation)
  235. {
  236. System.Data.DataTable indexTbl = _frmMain._environment.m_dataSet.Tables["公交车站"];
  237. System.Data.DataRow[] rowsType = indexTbl.Select("站名='"+szStation+"'");
  238. if (rowsType.Length > 0)
  239. return true;
  240. return false;
  241. }
  242. }
  243. }