/// <summary> /// Loads Active Movies to relate to a theater which use them. /// </summary> protected void poblarPeliculas() { if (log.IsDebugEnabled) { log.Debug("poblarPeliculas Starts"); } List<DetallePeliculaDto> listaPeliculas = new Pelicula().getPeliculasActivas(); listaPeliculas = listaPeliculas.OrderBy(x => x.nombrePelicula).ToList<DetallePeliculaDto>(); checkBoxPeliculas.DataSource = listaPeliculas; checkBoxPeliculas.DataTextField = "nombrePelicula"; checkBoxPeliculas.DataValueField = "idPelicula"; checkBoxPeliculas.DataBind(); if (log.IsDebugEnabled) { log.Debug("poblarPeliculas Ends "); } }
/// <summary> /// This method is named 'Horario.guardarProgramacion' and must be synced if needed. /// This method returns an int. That in Horario is void. /// </summary> /// <param name="datosProgramacion">What to save</param> private int saveSchedule(DetalleProgramacion datosProgramacion) { if (log.IsDebugEnabled) { log.Debug("Executing saveSchedule"); } int rslt = 0; if (datosProgramacion == null) { return -1; } Pelicula peliculaDao = new Pelicula(); ProgramacionPeliculaDto programacionDto = null; foreach (var itemFechas in datosProgramacion.fs) { foreach (var itemFormatos in itemFechas.fms) { programacionDto = new ProgramacionPeliculaDto(); programacionDto.idHorarioPelicula = itemFormatos.idh; String[] hhmm = itemFormatos.h.Split(','); List<string> hhmmList = new List<string>(); foreach (var shhmm in hhmm) { if (shhmm != "00:00") { hhmmList.Add(shhmm); } } programacionDto.horaMinutoPelicula = hhmmList.ToStringDelimited(","); if (!String.IsNullOrEmpty(programacionDto.horaMinutoPelicula) || programacionDto.idHorarioPelicula != 0) { if (string.IsNullOrEmpty(itemFechas.f)) { continue; } DateTime fecha = itemFechas.f.DDMMYYYYToDateTime(); programacionDto.idFormato = itemFormatos.idf; programacionDto.idPelicula = datosProgramacion.id; programacionDto.idTeatro = idTheater; programacionDto.mesHorarioPelicula = fecha.Month; programacionDto.annoHorarioPelicula = fecha.Year; programacionDto.diaHorarioPelicula = fecha.Day; programacionDto.nombreDiaSemanaHorarioPelicula = Utils.getDayNameSpanish(fecha.DayOfWeek.ToString()); programacionDto.frecuencia = Utils.getDayNameNumber(fecha.DayOfWeek.ToString()); rslt = peliculaDao.createUpdateProgramacionPelicula(programacionDto); if (log.IsDebugEnabled) { log.Debug("createUpdateProgramacionPelicula rslt=["+ rslt + "] with data=[" + programacionDto.ToString() + "]"); } programacionDto = null; } } } if (log.IsDebugEnabled) { log.Debug("Executing saveSchedule End"); } return rslt; }
/// <summary> /// Loads movies to use to make schedule on it. /// </summary> /// <param name="teatro"></param> private void poblarPeliculas(int teatro) { if (log.IsDebugEnabled) { log.Debug("poblarPeliculas Starts"); } Pelicula peliculaDao = new Pelicula(); List<PeliculaDto> listaPeliculas = peliculaDao.getPeliculasPorTeatro(teatro); listaPeliculas = listaPeliculas.OrderBy(x => x.nombrePelicula).ToList<PeliculaDto>(); ListBoxPeliculas.DataSource = listaPeliculas; ListBoxPeliculas.DataTextField = "nombrePelicula"; ListBoxPeliculas.DataValueField = "idPelicula"; ListBoxPeliculas.DataBind(); if (log.IsDebugEnabled) { log.Debug("poblarPeliculas Ends"); } }
/// <summary> /// Load movies for selected theater to check which movies it has selected. /// </summary> protected void checkPeliculas() { if (log.IsDebugEnabled) { log.Debug("checkPeliculas Starts"); } int teatroSeleccionado = Convert.ToInt32(lbTeatros.SelectedValue); List<PeliculaDto> lstPeliculasPorTeatroMemoria = new Pelicula().getPeliculasPorTeatro(teatroSeleccionado); foreach (var item in lstPeliculasPorTeatroMemoria) { foreach (ListItem pelicula in checkBoxPeliculas.Items) { if (pelicula.Value.Equals(item.idPelicula.ToString())) { pelicula.Selected = true; } } } if (log.IsDebugEnabled) { log.Debug("checkPeliculas Ends"); } }
/// <summary> /// Creates an object instance and save only one record. /// </summary> /// <returns></returns> public int executeSaveScheduleSingleTest() { if (log.IsDebugEnabled) { log.Debug("Executing executeSaveScheduleSingleTest"); } Pelicula peliculaDao = new Pelicula(); ProgramacionPeliculaDto programacionDto = new ProgramacionPeliculaDto(); int rslt = 0; DateTime fecha = DateTime.Now; programacionDto.idHorarioPelicula = 0; programacionDto.idFormato = 1; programacionDto.idPelicula = 14; programacionDto.idTeatro = idTheater; programacionDto.mesHorarioPelicula = fecha.Month; programacionDto.annoHorarioPelicula = fecha.Year; programacionDto.diaHorarioPelicula = fecha.Day; programacionDto.nombreDiaSemanaHorarioPelicula = Utils.getDayNameSpanish(fecha.DayOfWeek.ToString()); programacionDto.frecuencia = Utils.getDayNameNumber(fecha.DayOfWeek.ToString()); programacionDto.horaMinutoPelicula = "14:40,17:30,20:50"; programacionDto.sala = 2; rslt = peliculaDao.createUpdateProgramacionPelicula(programacionDto); if (log.IsDebugEnabled) { log.Debug("executeSaveScheduleSingleTest rslt=[" + rslt + "] with data=[" + programacionDto.ToString() + "]"); log.Debug("Executing executeSaveScheduleSingleTest Ends"); } return rslt; }
/// <summary> /// Main method to compute DB records to JSON files. All JSON files are stored in a /// configurable folder. /// </summary> public void CompileAllMoviesSchedule() { if (log.IsDebugEnabled) { log.Debug("CompileAllMoviesSchedule Starts"); log.Debug("Core"); } Pelicula movieDao = new Pelicula(); List<MovieFullInfo> movieFullList = movieDao.updateBillboardAndGetMovieFullInfo(); // Normalize image to conform to URI. movieFullList.ForEach(m => { if (!m.img.Contains("http")) { m.img = imgPathUrl + m.img; } }); // Create List of movies List<Movie> movieList = new List<Movie>(); Movie movieInfo = null; MovieLocation movieLocationInfo = null; MovieFormat movieFormatInfo = null; MovieShow movieShowInfo = null; movieFullList.ForEach(mfInfo => { // Let's first find movie existence var movieExist = movieList.Where(x => x.id == mfInfo.id).FirstOrDefault<Movie>(); if (movieExist != null) { movieInfo = movieExist; } else { movieInfo = new Movie() { id = mfInfo.id, name = mfInfo.name, img = mfInfo.img, url = mfInfo.url, active = mfInfo.active, idGenre = mfInfo.idGenre, genre = mfInfo.genre, premiere = mfInfo.premiere, createDate = mfInfo.createDate, locations = new List<MovieLocation>() }; movieList.Add(movieInfo); } // Fill remaining data for movieInfo record // 1. Fill Location var movieLocationExist = movieInfo.locations.Where(x => x.id == mfInfo.idLocation).FirstOrDefault<MovieLocation>(); if (movieLocationExist != null) { movieLocationInfo = movieLocationExist; } else { movieLocationInfo = new MovieLocation() { id = mfInfo.idLocation, name = mfInfo.nameLocation, branchName = mfInfo.branchName, nameFull = mfInfo.nameFullLocation, address = mfInfo.address, formats = new List<MovieFormat>() }; movieInfo.locations.Add(movieLocationInfo); } // 2. Fill Format var movieFormatExist = movieLocationInfo.formats.Where(x => x.id == mfInfo.idFormat).FirstOrDefault<MovieFormat>(); if (movieFormatExist != null) { movieFormatInfo = movieFormatExist; } else { movieFormatInfo = new MovieFormat() { id = mfInfo.idFormat, name = mfInfo.nameFormat, shows = new List<MovieShow>() }; movieLocationInfo.formats.Add(movieFormatInfo); } // 3. Fill Show var movieShowExist = movieFormatInfo.shows.Where(x => x.id == mfInfo.idShow).FirstOrDefault<MovieShow>(); if (movieShowExist != null) { movieShowInfo = movieShowExist; } else { movieShowInfo = new MovieShow() { id = mfInfo.idShow, dt = mfInfo.dt, hours = movieDao.getMovieShowHoursFor(mfInfo.idShow) }; movieFormatInfo.shows.Add(movieShowInfo); } movieFormatInfo.shows = movieFormatInfo.shows.OrderBy(x => x.dt).ToList<MovieShow>(); }); movieList = movieList.OrderByDescending(x => x.premiere).ThenBy(x => x.name).ToList<Movie>(); // Up to this point we have all movies gathered, now we build the movie Catalog in order // to ease search manipulation when required and to speed data processing. // The following steps must be fullfilled in order to gather all of the movie Catalog. // 1. Load Movie Name list // 2. Movie Formats Name list // 3. Movie Genre Name list // 4. Load all theaters referenced in the schedule. // 5. Load All Theater Name List and its associated movies. // 6. Load Movie Name List and its associated theaters where each movie is being shown. // Let's start. MovieCatalog mc = new MovieCatalog(); mc.theaters = new List<MovieLocationShort>(); mc.formats = new List<MovieFormatShort>(); mc.movies = new List<MovieShortFormat>(); mc.genres = new List<MovieGenreShort>(); // 1. Load Movie Name list movieList.ForEach(movie => { MovieShortFormat movieShort = new MovieShortFormat() { id = movie.id, name = movie.name, premiere = movie.premiere, formats = new List<MovieFormatShort>() }; // Now load formats movie.locations.ForEach(movieLocation => movieLocation.formats.ForEach( movieFormat => { var formatExist = movieShort.formats.Where(x => x.id == movieFormat.id).FirstOrDefault<MovieFormatShort>(); if (formatExist == null) { movieShort.formats.Add(new MovieFormatShort() { id = movieFormat.id, name = movieFormat.name }); } } )); movieShort.formats = movieShort.formats.OrderBy(x => x.name).ToList<MovieFormatShort>(); mc.movies.Add(movieShort); }); mc.movies = mc.movies.OrderBy(x => x.name).ToList<MovieShortFormat>(); // End 1.Load Movie Name List // 2. Movie Formats Name list and 3. Movie Genre Name list and 4. Load all theaters referenced in the schedule. movieFullList.ForEach(movie => { var movieFormatExist = mc.formats.Where(x => x.id == movie.idFormat).FirstOrDefault<MovieFormatShort>(); if (movieFormatExist == null) { mc.formats.Add(new MovieFormatShort() { id = movie.idFormat, name = movie.nameFormat }); } var movieGenreExist = mc.genres.Where(x => x.id == movie.idGenre).FirstOrDefault<MovieGenreShort>(); if (movieGenreExist == null) { mc.genres.Add(new MovieGenreShort() { id = movie.idGenre, name = movie.genre }); } var movieTheaterExist = mc.theaters.Where(x => x.id == movie.idLocation).FirstOrDefault<MovieLocationShort>(); if (movieTheaterExist == null) { mc.theaters.Add(new MovieLocationShort() { id = movie.idLocation, name = movie.nameLocation, branchName = movie.branchName, nameFull = movie.nameFullLocation }); } }); mc.formats = mc.formats.OrderBy(x => x.name).ToList<MovieFormatShort>(); mc.genres = mc.genres.OrderBy(x => x.name).ToList<MovieGenreShort>(); mc.theaters = mc.theaters.OrderBy(x => x.nameFull).ToList<MovieLocationShort>(); // End 2. Movie Formats Name list and 3. Movie Genre Name List and 4. Load all theaters referenced in the schedule. // 5. Load All Theater Name List and its associated movies. // Initialize Dictionary<int, List<MovieLocationShort>> movieInTheaters = new Dictionary<int, List<MovieLocationShort>>(); movieList.ForEach(movie => movieInTheaters.Add(movie.id, new List<MovieLocationShort>())); // Now fill locations per movie. movieList.ForEach(movie => { var movieTheaterSelected = movieInTheaters[movie.id]; movie.locations.ForEach(loc => movieTheaterSelected.Add(new MovieLocationShort() { id = loc.id, name = loc.name, branchName = loc.branchName, nameFull = loc.nameFull })); movieTheaterSelected = movieTheaterSelected.OrderBy(x => x.nameFull).ToList<MovieLocationShort>(); }); // Now store in catalog. mc.movieInTheaters = movieInTheaters; // End 5. Load All Theater Name List and its associated movies. // 6. Load Movie Name List and its associated theaters where each movie is being shown. // Initialize theaterMovies for computation. // Here we use theaterMoviesDictionary temporary variable so in the process it can be build orderd both // its keys and the values it contains. Dictionary<string, List<MovieShortFormat>> theaterMoviesDictionary = new Dictionary<string, List<MovieShortFormat>>(); // Initialize theaterMoviesDictionary with keys ordered by name. List<string> theaterNameList = new List<string>(); mc.theaters.ForEach(t => theaterNameList.Add(t.nameFull)); theaterNameList = theaterNameList.OrderBy(t => t).ToList<string>(); // Now that we have a theaterNameList and ordered, we can now start building the Dictionary values. // Initialize theaterMoviesDictionary dictionary for further processing. theaterNameList.ForEach(t => theaterMoviesDictionary.Add(t, new List<MovieShortFormat>())); // Let's add values to theaterMoviesDictionary movieList.ForEach(movie => { movie.locations.ForEach(location => { // Retrieve theater item from dictionary var theaterItem = theaterMoviesDictionary[location.nameFull]; var existMovie = theaterItem.Where(x => x.id == movie.id).FirstOrDefault<MovieShortFormat>(); if (existMovie == null) { // WARNING!: At this point and supported by mc.movies (which must be already compiled at this point. var movieFormats = mc.movies.Where(x => x.id == movie.id).FirstOrDefault(); theaterItem.Add(new MovieShortFormat() { id = movie.id, premiere = movie.premiere, name = movie.name, formats = movieFormats.formats }); } }); }); // Now it is time to copy contents from theaterMoviesDictionary to mc.theaterMovies // When traversing its contents the list is sorted as well by name. mc.theaterMovies = new Dictionary<string, List<MovieShortFormat>>(); foreach (var pair in theaterMoviesDictionary) { mc.theaterMovies.Add(pair.Key, pair.Value.OrderBy(m => m.name).ToList<MovieShortFormat>()); } // End 6. Load Movie Name List and its associated theaters where each movie is being shown. // Serialize string movieLookupJSON = JsonConvert.SerializeObject(movieList); string movieCatalogJSON = JsonConvert.SerializeObject(mc); // Now that we have just gathered all the information, create static JSON versions // Now there are two files to consume the feed // Full movie catalog (mapped from origin). string fileName = moviesFileName; using (StreamWriter writer = new StreamWriter(fileName)) { writer.Write(movieLookupJSON); } fileName = catalogNameFileName; using (StreamWriter writer = new StreamWriter(fileName)) { writer.Write(movieCatalogJSON); } if (log.IsDebugEnabled) { log.Debug("Info compiled"); log.Debug("movieLookupJSON=[" + movieLookupJSON + "]"); log.Debug("movieCatalogJSON=[" + movieCatalogJSON + "]"); log.Debug("CompileAllMoviesSchedule Ends"); } }
/// <summary> /// Operation to create or update a record in database. /// </summary> /// <param name="operacion">1: create, 2: update</param> /// <returns>0 if successful</returns> protected int CrearPelicula(int operacion) { if (log.IsDebugEnabled) { log.Debug("CrearPelicula Starts"); log.Debug("Selected operation [" + operacion + "]"); } Pelicula peliculaDao = new Pelicula(); DetallePeliculaDto datosPelicula = new DetallePeliculaDto(); if (operacion == 1) { datosPelicula.fechaCreacionPelicula = DateTime.Now.MapToLocalTimeColombia(); } if (operacion == 2) { if (log.IsDebugEnabled) { log.Debug("id to update [" + grdInfo.DataKeys[grdInfo.SelectedIndex].Value + "]"); } datosPelicula = peliculaDao.getPelicula(Convert.ToInt32(grdInfo.DataKeys[grdInfo.SelectedIndex].Value)); } // The following code has no effect if you use Updatepanel. // to upload an image it must be sent first to server and then somehow referenced for inserting/updating record. // Left here for compatibility. if (imgUpload.HasFile) { string imgFolder = Settings.ImageFolderSave; string imgName = imgFolder + @"\" + imgUpload.FileName; imgUpload.SaveAs(imgName); datosPelicula.imagenCartelera = imgUpload.FileName; } else { if (!String.IsNullOrEmpty(posterImageName.Value)) { datosPelicula.imagenCartelera = posterImageName.Value; } } datosPelicula.nombrePelicula = nombre.Text; datosPelicula.idUsuarioCreador = 1; datosPelicula.idGeneroPelicula = Convert.ToInt32(listGenero.SelectedValue); datosPelicula.sinopsis = sinopsis.Text; datosPelicula.urlArticuloEc = url.Text; if (checkEnCartelera.Checked) { datosPelicula.enCartelera = "S"; } else { datosPelicula.enCartelera = "N"; } if (log.IsDebugEnabled) { log.Debug("Record data [" + datosPelicula.ToString() + "]"); } int resultado = peliculaDao.createPelicula(datosPelicula, operacion); if (resultado == -1) { if (log.IsDebugEnabled) { log.Debug("Record not created"); } registerToastrMsg(MessageType.Error, "Registro no creado con éxito."); } txtBuscar.Text = ""; if (log.IsDebugEnabled) { log.Debug("CrearPelicula Ends"); log.Debug("Result is [" + resultado + "]"); } return resultado; }
/// <summary> /// Loads Movies into Grid View /// </summary> /// <param name="sender">Objet which sends event</param> /// <param name="e">event parameteres</param> private void CargarGridInfoData(string filtro = null, Object newPage = null) { if (log.IsDebugEnabled) { log.Debug("CargarGridInfoData Starts"); } var listaPeliculas = new Pelicula().getPeliculas(); if (!string.IsNullOrEmpty(filtro)) { listaPeliculas = listaPeliculas.Where(x => x.nombrePelicula.ToLower().Contains(filtro.ToLower())).ToList(); } if (listaPeliculas.Count > 0) { btnActualizar.Visible = false; if (!string.IsNullOrEmpty(filtro)) { if (log.IsDebugEnabled) { log.Debug("Search used with filter=[" + filtro + "] with " + listaPeliculas.Count + " matches found"); } registerToastrMsg(MessageType.Info, string.Format("Se encontraron <b>{0}</b> con el criterio de búsqueda: <b>{1}</b> ", listaPeliculas.Count, filtro.ToString())); } } else { if (!string.IsNullOrEmpty(filtro)) { if (log.IsDebugEnabled) { log.Debug("No records matched"); } registerToastrMsg(MessageType.Info, "No hay películas con el criterio de búsqueda: " + filtro.ToString()); } } grdInfo.DataSource = listaPeliculas; if (newPage != null) { grdInfo.PageIndex = Convert.ToInt32(newPage); } grdInfo.DataBind(); if (log.IsDebugEnabled) { log.Debug("CargarGridInfoData Ends"); } }
/// <summary> /// Saves all information about the schedule for movie/theater back to disk. /// </summary> /// <param name="datosProgramacion">An object representing the information to save from JSON format</param> private void guardarProgramacion(DetalleProgramacion datosProgramacion) { if (log.IsDebugEnabled) { log.Debug("guardarProgramacion Starts"); } if (datosProgramacion == null) { if (log.IsDebugEnabled) { log.Debug("Supplied parameter is not set"); } return; } Pelicula peliculaDao = new Pelicula(); ProgramacionPeliculaDto programacionDto = null; foreach (var itemFechas in datosProgramacion.fs) { foreach (var itemFormatos in itemFechas.fms) { programacionDto = new ProgramacionPeliculaDto(); programacionDto.idHorarioPelicula = itemFormatos.idh; String[] hhmm = itemFormatos.h.Split(','); List<string> hhmmList = new List<string>(); foreach (var shhmm in hhmm) { if (shhmm != "00:00") { hhmmList.Add(shhmm); } } programacionDto.horaMinutoPelicula = hhmmList.ToStringDelimited(","); if (!String.IsNullOrEmpty(programacionDto.horaMinutoPelicula) || programacionDto.idHorarioPelicula != 0) { if (string.IsNullOrEmpty(itemFechas.f)) { continue; } DateTime fecha = itemFechas.f.DDMMYYYYToDateTime(); programacionDto.idFormato = itemFormatos.idf; programacionDto.idPelicula = datosProgramacion.id; programacionDto.idTeatro = Convert.ToInt32(teatroSeleccionado.Value.ToString()); programacionDto.mesHorarioPelicula = fecha.Month; programacionDto.annoHorarioPelicula = fecha.Year; programacionDto.diaHorarioPelicula = fecha.Day; programacionDto.nombreDiaSemanaHorarioPelicula = Utils.getDayNameSpanish(fecha.DayOfWeek.ToString()); programacionDto.frecuencia = Utils.getDayNameNumber(fecha.DayOfWeek.ToString()); peliculaDao.createUpdateProgramacionPelicula(programacionDto); programacionDto = null; } } } if (log.IsDebugEnabled) { log.Debug("guardarProgramacion Starts"); } }
/// <summary> /// Retrieves the schedule so far for the supplied parameters. /// </summary> /// <param name="idPelicula">Movie Id</param> /// <param name="idTeatro">Theater Id</param> /// <returns>A list of PeliculaFullInfoDto</returns> private List<PeliculaFullInfoDto> obtenerProgramacion(int idPelicula, int idTeatro) { if (log.IsDebugEnabled) { log.Debug("obtenerProgramacion Starts"); log.Debug("idPelicula=[" + idPelicula + "]"); log.Debug("idTeatro=[" + idTeatro + "]"); } infoProgramacion.Value = ListBoxPeliculas.SelectedValue; List<PeliculaFullInfoDto> listResultado = new Pelicula().getProgramacionPelicula(idPelicula, idTeatro); if (log.IsDebugEnabled) { log.Debug("obtenerProgramacion Ends"); } return listResultado; }