コード例 #1
0
        /// <summary>
        /// Select records for category.
        /// </summary>
        public Driver SelectDriverSession(string token)
        {
            DriverFactory        driverFactory  = new DriverFactory();
            DriverTable <Driver> instanceDriver = (DriverTable <Driver>)driverFactory.GetDriverInstance();
            Database             db             = new Database();

            db.Connect();
            SqlCommand command = db.CreateCommand(SQL_SELECT);

            command.Parameters.AddWithValue("@token", token);
            SqlDataReader reader = db.Select(command);

            Collection <T> sessions = Read(reader);

            if (sessions.Count == 1)
            {
                if (sessions[0].type == "DRIVER")
                {
                    return(instanceDriver.Select(sessions[0].user_id));
                }
            }
            reader.Close();
            db.Close();
            return(null);
        }
コード例 #2
0
ファイル: TimetableTable.cs プロジェクト: michalfalat/VIS
        /// <summary>
        /// Select the record for a name.
        /// </summary>
        //public  Timetable SelectForName(string pName, Database pDb = null)
        //{
        //    Database db;
        //    if (pDb == null)
        //    {
        //        db = new Database();
        //        db.Connect();
        //    }
        //    else
        //    {
        //        db = pDb;
        //    }

        //    SqlCommand command = db.CreateCommand(SQL_SELECT_NAME);

        //    command.Parameters.AddWithValue("@name", pName);
        //    SqlDataReader reader = db.Select(command);

        //    Collection<Timetable> timeTables = Read(reader);
        //    Timetable v = null;
        //    if (timeTables.Count == 1)
        //    {
        //        v = timeTables[0];
        //    }
        //    reader.Close();

        //    if (pDb == null)
        //    {
        //        db.Close();
        //    }

        //    return v;
        //}


        private Collection <T> Read(SqlDataReader reader)
        {
            RouteFactory       routeFactory  = new RouteFactory();
            RouteTable <Route> instanceRoute = (RouteTable <Route>)routeFactory.GetRouteInstance();

            VehicleFactory vehicleFactory  = new VehicleFactory();
            var            instanceVehicle = vehicleFactory.GetVehicleInstance();

            DriverFactory        driverFactory  = new DriverFactory();
            DriverTable <Driver> instanceDriver = (DriverTable <Driver>)driverFactory.GetDriverInstance();

            Collection <T> timeTables = new Collection <T>();

            while (reader.Read())
            {
                Timetable timeTable = new Timetable();
                int       i         = -1;
                timeTable.id        = reader.GetInt32(++i);
                timeTable.name      = reader.GetString(++i);
                timeTable.departure = reader.GetDateTime(++i);
                timeTable.arrival   = reader.GetDateTime(++i);
                var idRoute   = reader.GetInt32(++i);
                var idDriver  = reader.GetInt32(++i);
                var idVehicle = reader.GetInt32(++i);
                timeTable.route   = instanceRoute.Select(idRoute);
                timeTable.vehicle = instanceVehicle.Select(idVehicle);
                timeTable.driver  = instanceDriver.Select(idDriver);


                timeTables.Add((T)timeTable);
            }
            return(timeTables);
        }
コード例 #3
0
        /// <summary>
        /// Select the record for a name.
        /// </summary>
        //public static Timetable SelectForName(string pName, Database pDb = null)
        //{
        //    Database db;
        //    if (pDb == null)
        //    {
        //        db = new Database();
        //        db.Connect();
        //    }
        //    else
        //    {
        //        db = pDb;
        //    }

        //    SqlCommand command = db.CreateCommand(SQL_SELECT_NAME);

        //    command.Parameters.AddWithValue("@name", pName);
        //    SqlDataReader reader = db.Select(command);

        //    Collection<Timetable> timeTables = Read(reader);
        //    Timetable v = null;
        //    if (timeTables.Count == 1)
        //    {
        //        v = timeTables[0];
        //    }
        //    reader.Close();

        //    if (pDb == null)
        //    {
        //        db.Close();
        //    }

        //    return v;
        //}


        private static Collection <Timetable> Read(SqlDataReader reader)
        {
            Collection <Timetable> timeTables = new Collection <Timetable>();
            var routes   = RouteTable.Select();
            var vehicles = VehicleTable.Select();
            var drivers  = DriverTable.Select();

            while (reader.Read())
            {
                Timetable timeTable = new Timetable();
                int       i         = -1;
                timeTable.id_journey = reader.GetInt32(++i);
                timeTable.link_name  = reader.GetString(++i);
                timeTable.departure  = reader.GetDateTime(++i);
                timeTable.arrival    = reader.GetDateTime(++i);
                var idRoute   = reader.GetInt32(++i);
                var idVehicle = reader.GetInt32(++i);
                var idDriver  = reader.GetInt32(++i);
                timeTable.route   = routes.Where(r => r.id_route == idRoute).FirstOrDefault();
                timeTable.vehicle = vehicles.Where(v => v.id_vehicle == idVehicle).FirstOrDefault();
                timeTable.driver  = drivers.Where(d => d.id_driver == idDriver).FirstOrDefault();


                timeTables.Add(timeTable);
            }
            return(timeTables);
        }