⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 城市公交路线查询
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
//using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.IO;

namespace BYBUS
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            skinEngine1.SkinFile = "OneGreen.ssk";
        }
#region 界面风格设计
        private void radBlackStyle_CheckedChanged(object sender, EventArgs e)
        {
            skinEngine1.SkinFile = "SteelBlack.ssk";
        }

        private void radBlueStyle_CheckedChanged(object sender, EventArgs e)
        {
            skinEngine1.SkinFile = "DiamondBlue.ssk";
        }

        private void radDefaultStyle_CheckedChanged(object sender, EventArgs e)
        {
            skinEngine1.SkinFile = "OneGreen.ssk";
        }
#endregion
        private ByBus bus;
        private List<int> time;
        private List<int> pay;
        private List<string> lineName;
        private List<string> lines;
       // private StringBuilder outtxt;
        private StringBuilder resulttxt;
        private void Form1_Load(object sender, EventArgs e)
        {
            bus = new ByBus();

            resulttxt = new StringBuilder();
        }
        #region 对文本框的设定
        private void txtStartstation_TextChanged(object sender, EventArgs e)
        {
            if (txtStartstation.Text.Length == 5)
            {
                btnSeek.Enabled = true;
            }
            else
            {
                btnSeek.Enabled = false;
            }
        }

        private void txtStartstation_Click(object sender, EventArgs e)
        {
            txtStartstation.Text = "";
            txtStartstation.MaxLength=5;
            
        }

        private void txtFinishstation_Click(object sender, EventArgs e)
        {
            txtFinishstation.Text = "";
            txtFinishstation.MaxLength = 5;
        }
        #endregion

        private void btnSeek_Click(object sender, EventArgs e)
        {

            if (txtStartstation.Text.StartsWith("S") && txtStartstation.Text.Length == 5
                && txtFinishstation.Text.StartsWith("S") && txtFinishstation.Text.Length == 5)
            {
                string repeatline = "";
               
                if (bus.change0station(txtStartstation.Text,txtFinishstation.Text,out time,out pay,out lineName,out lines))
                {   
                    for(int i=0;i<lineName.Count;i++)
                    {
                        resulttxt.AppendLine(lineName[i]);
                        resulttxt.AppendLine(lines[i]);
                        resulttxt.AppendLine("总时间:"+time[i]+" 总费用:"+pay[i]);
                    }

                    resulttxt.AppendLine();
                }
                else
                {
                    resulttxt.AppendLine("无从"+txtStartstation.Text+"到"+txtFinishstation.Text+"的直达线路");
                    resulttxt.AppendLine();
                }

                if (bus.change1station(txtStartstation.Text, txtFinishstation.Text, out time, out pay, out lineName, out lines, repeatline))
                {
                    for (int i = 0; i < lineName.Count && i<3; i++)
                    {
                       
                        {
                            resulttxt.AppendLine(lineName[i]);
                            resulttxt.AppendLine(lines[i]);
                            resulttxt.AppendLine("总时间:" + time[i] + " 总费用:" + pay[i]);
                            resulttxt.AppendLine();
                        }   
                    }
                    resulttxt.AppendLine();
                   // resulttxt.AppendLine();
                }
                else
                {
                    resulttxt.AppendLine("无从" + txtStartstation.Text + "到" + txtFinishstation.Text + "换乘一次的线路");
                    resulttxt.AppendLine();
  
                }
                if (bus.change2station(txtStartstation.Text, txtFinishstation.Text, out time, out pay, out lineName, out lines))
                {
                    for (int i = 0; i < lineName.Count && i<3; i++)
                    {
                        
                        {
                            resulttxt.AppendLine(lineName[i]);
                            resulttxt.AppendLine(lines[i]);
                            resulttxt.AppendLine("总时间:" + time[i] + " 总费用:" + pay[i]);
                            resulttxt.AppendLine();
                        }
                    }
 
                }
                else
                {
                    resulttxt.AppendLine("无从" + txtStartstation.Text + "到" + txtFinishstation.Text + "换乘两次的线路");
                    resulttxt.AppendLine();
                }
               
                ResultForm resutlForm = new ResultForm(this.skinEngine1.SkinFile.ToString(), resulttxt);
                resutlForm.ShowDialog();
                resulttxt.Remove(0, resulttxt.Length);
                
            }
            else
            {
                MessageBox.Show("输入错误,请确保你所输入字符长度为5且以S开头", "错误提醒",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                btnSeek.Enabled = false;
                return;
            }

        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
        #region 初始化,从文件读入数据
        private void button1_Click(object sender, EventArgs e)
        {
            bus.LoadFromFile();
            txtStartstation.Enabled = true;
            txtFinishstation.Enabled = true;
            button1.Visible = false;
        }
        #endregion



    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -