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

📄 schedule.cs

📁 列车时刻查询Visual Studio 2005 + sql2005
💻 CS
字号:
using System;
using System.Data;

namespace train
{
	/// <summary>
	/// Schedule:负责与数据层的交互
	/// </summary>
	public class Schedule
	{
		private DataBaseOperate db;
	    private	DataTable table;
		private DataTable tableresult;
		private DataTable tabledetails;
		public Schedule()
		{
			db=new DataBaseOperate();
			table=new DataTable();
		}

		/// <summary>
		/// 根据起点站、终点站搜索列车信息
		/// </summary>
		/// <param name="fromcity">起点站</param>
		/// <param name="tocity">终点站</param>
		/// <returns>返回列车信息的表DataTable</returns>
		public DataTable SearchScheduleList(string fromcity,string tocity)
		{
			string sql="select 车次=code,起点站=fromcity,终点站=tocity,发车时间=LeaveTime,"+
				"到达时间=ArriveTime,列车信息=trainType,时速=speed,距离=distance "+
				"from T_train where fromcity='"+fromcity+"' and toCity='"+ tocity+"'";
			table=db.search(sql);
			tableresult=CalculatePrice(table);				
			return tableresult;
		}
		/// <summary>
		/// 计算票价
		/// </summary>
		/// <param name="table">需要计算票价的DataTable</param>
		/// <returns>返回已经计算票价的DataTable</returns>
		public DataTable CalculatePrice(DataTable tables)
		{
			double price;
			tables.Columns.Add("价格",typeof(int));	
			for(int i=0;i<table.Rows.Count;i++)
			{
				
				price=(double.Parse(tables.Rows[i]["距离"].ToString()))/100*10;
				if((double.Parse(tables.Rows[i]["距离"].ToString()))%100!=0)
				{
					price=price+10;
				}
				switch(tables.Rows[i]["列车信息"].ToString())
				{
					case "特快":
						price=price*2;
						break;
					case "空调":
						price=price*2;
						break;
					case "快车":
						price=price*1.2;
						break;
					default:
						break;
				}
				tables.Rows[i]["价格"]=price;
			}
			return tables;
		}


		/// <summary>
		///  显示用用户选择的列车的详细信息
		/// </summary>
		/// <param name="code">列车的车次</param>
		/// <returns>返回列车信息的表DataTable</returns>
		public DataTable SearchMidScheduleList(string code)
		{
			string sql="select 车次=code,经停站=cityname,发车时间=leavetime,里程=distance,天数=days from T_traindetails where code='"+code+"'";
			tabledetails=db.search(sql);
			return tabledetails;
		}

		/// <summary>
		/// 根据终点站得到中间站的信息
		/// </summary>
		/// <param name="tocity">终点站的名字</param>
		/// <returns>返回包含中间站信息的DataTable</returns>
		public DataTable SearchMidList(string tocity)
		{
			string sql="select distinct cityname from T_traindetails where cityname not like '%"+tocity+"%' and code in"+
						"(select code from T_traindetails where cityname like '%"+tocity+"%')";
			return db.search(sql);
		}

		/// <summary>
		///  根据选择的中间站返回起点站、中间站、终点站的详细信息
		/// </summary>
		/// <param name="fromcity">起点站</param>
		/// <param name="midcity">中间站</param>
		/// <param name="finalcity">终点站</param>
		/// <returns>返回包含起点站、中间站、终点站的详细信息DataTable</returns>
		public DataTable SearchMidStation(string fromcity,string midcity,string finalcity)
		{
			string sql="select 车次=code,起点站=fromcity,终点站=tocity,发车时间=LeaveTime,"+
				"到达时间=ArriveTime,列车信息=trainType,时速=speed,距离=distance "+
				"from T_train where fromcity='"+fromcity+"' and toCity='"+ midcity+"'"+
				" union "+
				"select 车次=code,起点站=fromcity,终点站=tocity,发车时间=LeaveTime,"+
				"到达时间=ArriveTime,列车信息=trainType,时速=speed,距离=distance "+
				"from T_train where fromcity='"+midcity+"' and toCity='"+ finalcity+"'";
			table=db.search(sql);
			tableresult=CalculatePrice(table);
			return tableresult;
		}


		/// <summary>
		/// 根据列车的车次获得列车的详细信息
		/// </summary>
		/// <param name="code">列车的车次</param>
		/// <returns>返回列车信息的表DataTable</returns>
		public DataTable SearchScheduleByCode(string code)
		{
			string sql="select 车次=code,起点站=fromcity,终点站=tocity,发车时间=LeaveTime,"+
				"到达时间=ArriveTime,列车信息=trainType,时速=speed,距离=distance "+
				"from T_train where code='"+code+"'";
			table=db.search(sql);
			tableresult=CalculatePrice(table);
			return tableresult;
		}
		public DataTable GetTableResult()
		{
			return this.tableresult;
		}
		public DataTable GetTableDetails()
		{
			return this.tabledetails;
		}
	}
}

⌨️ 快捷键说明

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