trainaccess.cs

来自「用C#编写的实现火车查询功能的程序功能比较完整」· CS 代码 · 共 94 行

CS
94
字号
using System;
using System.Collections.Generic;
using System.Text;
using TrainSystem.Common;
using System.Data;

namespace TrainSystem.Access
{
    public class TrainAccess
    {
        private DataBaseOperate DBOperate = null;
        DataSet ds = new DataSet();
        public TrainAccess()
        {
            DBOperate = new DataBaseOperate();
            
        }

        public DataSet SelectNonstop(string StarCity,string EndCity)
        {
            string sql;
            sql = "select * from trainlist where traincode in("+
                    "select traincode from  trainDetails ta "+
                    "where cityname='" + EndCity + "' and traincode in(" +
                    "select traincode from  trainDetails tb where cityname='" + StarCity + "' and ta.trainid>tb.trainid))";

            
            try
            {
                ds = DBOperate.Search(sql, "trainlist");
            }
            catch (Exception ex)
            {
                throw ex ; 
            }
            return ds;
        }

        public DataSet SelectChangeTrains(string StarCity,string EndCity)
        {
            string sql;
            sql = "select distinct cityname from  TrainDetails where TrainCode in(" +
            "select TrainCode from  TrainDetails where cityname='" + EndCity + "') and " +
            "cityname<>'" + EndCity + "' and cityname in(select distinct cityname from  TrainDetails " +
            "where TrainCode in(select TrainCode from  TrainDetails " +
            "where cityname='" + StarCity + "') and cityname<>'" + StarCity + "')";
            
            try
            {
                ds = DBOperate.Search(sql, "TrainDetails");
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return ds;

        }


        public DataSet SelectTrainInfo(string traincode)
        {
            string sql;
            sql = "select * from traindetails where traincode='"+traincode+"'";
           
            try
            {
                ds = DBOperate.Search(sql, "traindetails");
            }
            catch ( Exception ex)
            {
                
                throw ex;
            }
            return ds;
        }
        public DataSet SelectTrainCode(string traincode)
        {
            string sql;
            sql = "select * from trainlist where traincode='" + traincode + "'";
           
            try
            {
                ds = DBOperate.Search(sql, "traindetails");
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return ds;
        }
    }
}

⌨️ 快捷键说明

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