Exemple #1
0
 private static void RemoveSittingFarmer_Postfix(MapSeat __instance, Farmer farmer)
 {
     if (__instance.seatType == "stool expert sitting mod")
     {
         farmer.currentLocation.mapSeats.Remove(__instance);
     }
 }
 private static void RemoveSittingFarmer_Postfix(MapSeat __instance, Farmer farmer)
 {
     if (__instance.seatType.Value.EndsWith("expert sitting mod"))
     {
         farmer.currentLocation.mapSeats.Remove(__instance);
     }
 }
        public ActionResult SeatMap(int id)
        {
            MapSeat mapSeat = GetSeatMapByRouteId(id);

            ViewBag.Message = "Your contact page.";

            return(View("BusModel1", mapSeat.MapSeats));
        }
        MapSeat GetSeatMapByRouteId(int routeId)
        {
            SqlConnection myConnection = new SqlConnection();

            myConnection.ConnectionString = ConfigurationManager.ConnectionStrings["ReservationSystem"].ConnectionString; // Configuration.GetConnectionString();
            MapSeat mapSeat = new MapSeat();

            mapSeat.MapSeats = new List <Seat>();
            try
            {
                myConnection.Open();
                string query = @"SELECT [Id]
                                  ,[Price]
                                  ,[SeatNumber]
                                  ,[PassengerId]
                                  ,[RouteId]
                                  ,[IsTaken]
                                  FROM [IncidentManager].[dbo].[Seats]
                                  where RouteId = @id order by SeatNumber";


                SqlCommand myCommand = new SqlCommand();
                myCommand.Connection  = myConnection;
                myCommand.CommandText = query;
                myCommand.Parameters.AddWithValue("@id", routeId);

                SqlDataReader myReader = myCommand.ExecuteReader();

                while (myReader.Read())
                {
                    Seat seat = new Seat()
                    {
                        Id          = myReader["Id"].ToString(),
                        IsTaken     = (bool)myReader["IsTaken"],
                        PassengerId = myReader["PassengerId"] is DBNull ? "0" : myReader["PassengerId"].ToString(),
                        Price       = Convert.ToInt32(myReader["Price"]),
                        RouteId     = myReader["RouteId"].ToString(),
                        SeatNumber  = myReader["SeatNumber"].ToString()
                    };
                    mapSeat.MapSeats.Add(seat);
                }
            }
            catch (Exception ex)
            {
                string.Format("{0:d}", DateTime.Today.ToShortDateString());
            }
            finally
            {
                myConnection.Close();
            }

            return(mapSeat);
        }
        private List <Seat> GetSeats(string route, string[] seatNumbers)
        {
            SqlConnection myConnection = new SqlConnection();

            myConnection.ConnectionString = ConfigurationManager.ConnectionStrings["ReservationSystem"].ConnectionString; // Configuration.GetConnectionString();
            MapSeat     mapSeat = new MapSeat();
            List <Seat> seats   = new List <Seat>();

            try
            {
                myConnection.Open();
                string query = @"SELECT [Id]
      ,[Price]
      ,[SeatNumber]
      ,[PassengerId]
      ,[RouteId]
      ,[IsTaken]
  FROM [IncidentManager].[dbo].[Seats]
  where RouteId = @routeId";

                SqlCommand myCommand = new SqlCommand();
                myCommand.Connection  = myConnection;
                myCommand.CommandText = query;
                myCommand.Parameters.AddWithValue("@routeId", route);

                SqlDataReader myReader = myCommand.ExecuteReader();

                while (myReader.Read())
                {
                    Seat seat = new Seat()
                    {
                        Id          = myReader["Id"].ToString(),
                        RouteId     = myReader["RouteId"].ToString(),
                        Price       = Convert.ToDecimal(myReader["Price"]),
                        PassengerId = myReader["PassengerId"].ToString(),
                        IsTaken     = (bool)myReader["IsTaken"],
                        SeatNumber  = myReader["SeatNumber"].ToString()
                    };
                    seats.Add(seat);
                }

                seats = seats.Where(x => seatNumbers.Contains(x.SeatNumber)).ToList();
            }
            catch (SqlException ex)
            {
                return(null);
            }

            return(seats);
        }
        private Route GetSelectedRoute(string route)
        {
            SqlConnection myConnection = new SqlConnection();

            myConnection.ConnectionString = ConfigurationManager.ConnectionStrings["ReservationSystem"].ConnectionString; // Configuration.GetConnectionString();
            MapSeat mapSeat = new MapSeat();

            mapSeat.MapSeats = new List <Seat>();
            try
            {
                myConnection.Open();
                string query = @"SELECT [Id]
      ,[Origin]
      ,[Destination]
      ,[IsActive]
      ,[DepartureDate]
      ,[Duration]
  FROM [IncidentManager].[dbo].[Routes]
  where Id = @id";

                SqlCommand myCommand = new SqlCommand();
                myCommand.Connection  = myConnection;
                myCommand.CommandText = query;
                myCommand.Parameters.AddWithValue("@id", route);

                SqlDataReader myReader = myCommand.ExecuteReader();

                while (myReader.Read())
                {
                    Route r = new Route()
                    {
                        Id            = myReader["Id"].ToString(),
                        DepartureDate = Convert.ToDateTime(myReader["DepartureDate"]),
                        Destination   = myReader["Destination"].ToString(),
                        Origin        = myReader["Origin"].ToString(),
                        Duration      = myReader["Duration"].ToString(),
                        IsActive      = (bool)myReader["IsActive"]
                    };
                    return(r);
                }
            }
            catch (SqlException ex)
            {
                return(null);
            }

            return(null);
        }
        private Passenger CheckIfPassengerIsAlreadyInDb(Passenger passenger)
        {
            SqlConnection myConnection = new SqlConnection();

            myConnection.ConnectionString = ConfigurationManager.ConnectionStrings["ReservationSystem"].ConnectionString; // Configuration.GetConnectionString();
            MapSeat mapSeat = new MapSeat();

            mapSeat.MapSeats = new List <Seat>();
            try
            {
                myConnection.Open();
                string query = @"SELECT TOP (1000) [FirstName]
                              ,[LastName]
                              ,[Id]
                              ,[Identification]
                              ,[Email]
                                FROM [IncidentManager].[dbo].[Passenger]
                                where Identification = @identification";

                SqlCommand myCommand = new SqlCommand();
                myCommand.Connection  = myConnection;
                myCommand.CommandText = query;
                myCommand.Parameters.AddWithValue("@identification", passenger.Identification);

                SqlDataReader myReader = myCommand.ExecuteReader();

                while (myReader.Read())
                {
                    Passenger px = new Passenger()
                    {
                        Id             = myReader["Id"].ToString(),
                        Email          = myReader["Email"].ToString(),
                        FirstName      = myReader["FirstName"].ToString(),
                        Identification = myReader["Identification"].ToString(),
                        LastName       = myReader["LastName"].ToString(),
                    };
                    return(px);
                }
            }
            catch (SqlException ex)
            {
                return(null);
            }

            return(null);
        }
        private static void checkAction_Postfix(GameLocation __instance, ref bool __result, Location tileLocation, xTile.Dimensions.Rectangle viewport, Farmer who)
        {
            if (!Config.EnableMod || __result)
            {
                return;
            }

            //SMonitor.Log($"Checking for seat");

            foreach (Object obj in __instance.objects.Values)
            {
                if (obj.TileLocation == new Vector2(tileLocation.X, tileLocation.Y) && Config.SeatTypes.Contains(obj.name))
                {
                    SMonitor.Log($"Got object seat");
                    MapSeat ms = new MapSeat();
                    ms.tilePosition.Value = new Vector2(tileLocation.X, tileLocation.Y);
                    ms.seatType.Value     = "stool expert sitting mod";
                    ms.size.Value         = new Vector2(1, 1);
                    __instance.mapSeats.Add(ms);
                    who.BeginSitting(ms);
                    __result = true;
                    break;
                }
            }
            if (__result)
            {
                return;
            }

            foreach (ResourceClump rc in __instance.resourceClumps)
            {
                if (rc.occupiesTile(tileLocation.X, tileLocation.Y - 1))
                {
                    SMonitor.Log($"Got clump seat");
                    MapSeat ms = new MapSeat();
                    ms.tilePosition.Value = new Vector2(tileLocation.X, tileLocation.Y);
                    ms.seatType.Value     = "clump expert sitting mod";
                    switch (who.FacingDirection)
                    {
                    case 0:
                    case 2:
                        ms.direction.Value = 2;
                        break;

                    default:
                        if (rc.occupiesTile(tileLocation.X - 1, tileLocation.Y - 1))
                        {
                            ms.direction.Value = 1;
                        }
                        else
                        {
                            ms.direction.Value = 3;
                        }
                        break;
                    }
                    ms.size.Value = new Vector2(1, 1);
                    __instance.mapSeats.Add(ms);
                    who.BeginSitting(ms);
                    __result = true;
                    break;
                }
            }

            if (__result)
            {
                return;
            }

            if (Config.AllowMapSit && (Config.MapSitModKey == SButton.None || context.Helper.Input.IsDown(Config.MapSitModKey)) && __instance.map.GetLayer("Buildings")?.PickTile(tileLocation * Game1.tileSize, Game1.viewport.Size) != null && __instance.map.GetLayer("Building")?.PickTile(new Location(tileLocation.X, tileLocation.Y + 1) * Game1.tileSize, Game1.viewport.Size) == null)
            {
                SMonitor.Log($"Got map seat");
                MapSeat ms = new MapSeat();
                ms.tilePosition.Value = new Vector2(tileLocation.X, tileLocation.Y);
                ms.size.Value         = new Vector2(1, 1);
                ms.seatType.Value     = "map expert sitting mod";
                __instance.mapSeats.Add(ms);
                ms.direction.Value = 2;
                who.BeginSitting(ms);
                __result = true;
            }
        }