예제 #1
0
        public static TrainTable GetTrainTableById(int id)
        {
            TrainTable result = null;
            Hashtable  pars   = new Hashtable();

            pars.Add("@id", id);
            try
            {
                using (DBManager db = new DBManager())
                {
                    db.Open();
                    using (SqlDataReader reader = db.ExecuteQuery(GetTrainTableByIdQuery, pars))
                    {
                        result = GetTrainTableFromDataReader(reader);
                        reader.Close();
                    }
                    db.Close();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(result);
        }
예제 #2
0
        private static TrainTable GetTrainTableFromDataReader(SqlDataReader reader)
        {
            reader.Read();
            TrainTable t = new TrainTable()
            {
                Id_Table         = reader.GetInt32(0),
                DepartureStation = StationDAL.GetStationById(reader.GetInt32(1)).Name,
                ArrivalStation   = StationDAL.GetStationById(reader.GetInt32(2)).Name,
                DepartureDate    = reader.GetDateTime(3).ToShortDateString(),
                ArrivalDate      = reader.GetDateTime(4).ToShortDateString(),
                DepartureTime    = reader.GetValue(5).ToString(),
                ArrivalTime      = reader.GetValue(6).ToString()
            };

            return(t);
        }
예제 #3
0
        private static List <TrainTable> GetTrainTablesListFromDataReader(SqlDataReader reader)
        {
            List <TrainTable> result = new List <TrainTable>();

            while (reader.Read())
            {
                TrainTable t = new TrainTable()
                {
                    Id_Table         = reader.GetInt32(0),
                    DepartureStation = StationDAL.GetStationById(reader.GetInt32(1)).Name,
                    ArrivalStation   = StationDAL.GetStationById(reader.GetInt32(2)).Name,
                    DepartureDate    = reader.GetDateTime(3).ToShortDateString(),
                    ArrivalDate      = reader.GetDateTime(4).ToShortDateString(),
                    DepartureTime    = reader.GetValue(5).ToString(),
                    ArrivalTime      = reader.GetValue(6).ToString()
                };
                result.Add(t);
            }
            return(result);
        }