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

📄 stop.cs

📁 工交车查询系统
💻 CS
字号:
using System;
using System.Data;
using System.Data.OleDb;
using Sun188.iSBus.Common;

namespace Sun188.iSBus.DataAccess
{
	/// <summary>
	/// Stop 的摘要说明。
	/// </summary>
	public class Stop
	{
		private int stopID;
		private int cityID;
		private string stopName;
		private string stopDescription;
		private OleDbConnection conn = null;

		public Stop()
		{
			this.conn = new Conn().Connection();
		}

		#region 根据BUSID返回站点数据集=======================================
		/// <summary>
		/// 根据BUSID返回站点数据集
		/// </summary>
		/// <param name="busID">站点ID</param>
		/// <returns>DATASET</returns>
		public DataSet GetStopDataset(int busID)
		{
			//定义SQL语句
			string sql = "Select * from V_Stop Where BusID = "+busID;			
			//创建数据库连接实例
			OleDbConnection conn = new Conn().Connection();
			//创建数据库适配器
			OleDbDataAdapter da = new OleDbDataAdapter(sql,conn);
			//创建DATASET实例
			DataSet ds = new DataSet();					
			try
			{				
				da.Fill(ds);
				return ds;
			}
			catch(Exception ex)
			{	
				throw new Exception(ex.ToString());
			}
			finally
			{
				//释放资源
				conn.Close();
				conn.Dispose();
				ds.Dispose();
				da.Dispose();				
			}			
		}
		#endregion

		#region 根据CotyID返回站点数据集======================================
		/// <summary>
		/// 根据CotyID返回站点数据集
		/// </summary>
		/// <param name="CotyID">站点ID</param>
		/// <returns>DATASET</returns>
		public DataSet StopDataset(int cityID)
		{
			//定义SQL语句
			string sql = "Select * from Stop Where CityID = "+cityID;			
			//创建数据库连接实例
			OleDbConnection conn = new Conn().Connection();
			//创建数据库适配器
			OleDbDataAdapter da = new OleDbDataAdapter(sql,conn);
			//创建DATASET实例
			DataSet ds = new DataSet();					
			try
			{				
				da.Fill(ds);
				return ds;
			}
			catch(Exception ex)
			{	
				throw new Exception(ex.ToString());
			}
			finally
			{
				//释放资源
				conn.Close();
				conn.Dispose();
				ds.Dispose();
				da.Dispose();				
			}			
		}
		#endregion

		#region 站点数据处理==================================================
		/// <summary>
		/// 新增站点资料
		/// </summary>
		/// <param name="name">站点名称</param>
		/// <param name="description">站点描述</param>
		/// <param name="id">所属省市</param>
		/// <returns>true/false</returns>
		public bool AddNewStop(string name,string description,int id)
		{
			bool result = false;
			this.stopName = name;
			this.stopDescription = description;
			this.cityID = id;
			result = this.StopProcess(PublicEnum.ProcessType.AddNew);
			return result;
		}

		/// <summary>
		/// 修改站点资料
		/// </summary>
		/// <param name="name">站点名称</param>
		/// <param name="description">站点描述</param>
		/// <param name="id">站点ID</param>
		/// <returns>true/false</returns>
		public bool ModifyStop(string name,string description,int id)
		{
			bool result = false;
			this.stopName = name;
			this.stopDescription = description;
			this.stopID = id;
			result = this.StopProcess(PublicEnum.ProcessType.Modify);
			return result;
		}

		/// <summary>
		/// 删除站点资料
		/// </summary>
		/// <param name="id">站点ID</param>
		/// <returns>true/false</returns>
		public bool DeleteStop(int id)
		{
			bool result = false;
			this.stopID = id;
			result = this.StopProcess(PublicEnum.ProcessType.Delete);
			return result;
		}

		/// <summary>
		///数据处理
		/// </summary>
		/// <param name="processType">操作类型</param>
		/// <returns>true/false</returns>
		private bool StopProcess(PublicEnum.ProcessType processType)
		{
			string sql = "";			
			bool result = false;

			switch(processType)
			{
				case PublicEnum.ProcessType.AddNew://新增
					sql = "insert into Stop (StopName,CityID,StopDescription) values ('"+this.stopName+"',"+this.cityID+",'"+this.stopDescription+"')";
					break;
				case PublicEnum.ProcessType.Modify://修改
					sql = "Update Stop Set StopName='"+stopName+"',StopDescription='"+stopDescription+"' Where StopID="+this.stopID+"";
					break;
				case PublicEnum.ProcessType.Delete://删除
					sql = "Delete * From Stop Where StopID="+this.stopID+"";
					break;
			}

			//创建COMMAND
			OleDbCommand cmd = new OleDbCommand(sql,this.conn);
			//打开数据库连接
			if(conn.State != ConnectionState.Open)
			{
				this.conn.Open();
			}
			try
			{
				cmd.ExecuteNonQuery();
				result = true;
			}
			catch
			{
				result = false;
			}
			finally
			{
				this.conn.Close();
				this.conn.Dispose();
			}

			return result;

		}
		#endregion

		#region 根据CityID返回数据集==========================================
		/// <summary>
		/// 根据BUSID返回数据集
		/// </summary>
		/// <param name="cityID">城市ID</param>
		/// <returns>DATASET</returns>
		public DataSet GetStopData(int cityID)
		{
			//定义SQL语句
			string sql = "Select * from Stop Where CityID = "+cityID;			
			//创建数据库连接实例
			OleDbConnection conn = new Conn().Connection();
			//创建数据库适配器
			OleDbDataAdapter da = new OleDbDataAdapter(sql,conn);
			//创建DATASET实例
			DataSet ds = new DataSet();					
			try
			{				
				da.Fill(ds);
				return ds;
			}
			catch(Exception ex)
			{	
				throw new Exception(ex.ToString());
			}
			finally
			{
				//释放资源
				conn.Close();
				conn.Dispose();
				ds.Dispose();
				da.Dispose();				
			}			
		}
		#endregion

	}
}

⌨️ 快捷键说明

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