// Lookup one Episode and return it if is found public Episode Load(int episodeNumber, string episodeIdiom) { var sqlCommand = new SqlCommand("SELECT * FROM EPISODES WHERE EPISODENUMBER = @EPISODENUMBER"); sqlCommand.Parameters.AddWithValue("EPISODENUMBER", episodeNumber); var dt = SQLOperation.ExecuteSQLCommandWithResult(sqlCommand); if (dt.Tables[0].Rows.Count <= 0) { return(null); } //Setting a loaded episode var episode = new Episode(); episode.EpisodeNumber = Int16.Parse(dt.Tables[0].Rows[0]["EPISODENUMBER"].ToString()); episode.Idiom = dt.Tables[0].Rows[0]["idiom"].ToString(); // Loading all Episode pages var pageRep = new PageRepository(); episode.Pages = pageRep.LoadFromEpisode(episode.EpisodeNumber); // Sending the episode return(episode); }
// Lookup one Map and return it if is found public List <Page> LoadFromEpisode(int episodeNumber) { var sqlCommand = new SqlCommand("SELECT PAGEID, PATH from PAGES WHERE EPISODENUMBER = @EPISODENUMBER ORDER BY PAGEID ASC"); sqlCommand.Parameters.AddWithValue("EPISODENUMBER", episodeNumber); var dt = SQLOperation.ExecuteSQLCommandWithResult(sqlCommand); if (dt.Tables[0].Rows.Count <= 0) { return(null); } // Getting all pages var PageList = new List <Page>(dt.Tables[0].Rows.Count); var mapRep = new MapRepository(); for (int count = 0; count <= dt.Tables[0].Rows.Count - 1; count++) { var newPage = new Page(); newPage.episodeNumber = episodeNumber; newPage.pageID = Int16.Parse(dt.Tables[0].Rows[count]["PAGEID"].ToString()); newPage.Path = dt.Tables[0].Rows[count]["Path"].ToString(); // Getting the maps of each page newPage.Maps = mapRep.LoadMapsByPageID(newPage.pageID); PageList.Add(newPage); } return(PageList); }
// Lookup one Map and return it if is found public List <Map> LoadMapsByPageID(int pageId) { var sqlCommand = new SqlCommand("SELECT mapid, scale, X, y from MAPS WHERE PAGEID = @PAGEID order by mapid asc"); sqlCommand.Parameters.AddWithValue("PAGEID", pageId); var dt = SQLOperation.ExecuteSQLCommandWithResult(sqlCommand); if (dt.Tables[0].Rows.Count <= 0) { return(null); } var mapList = new List <Map>(dt.Tables[0].Rows.Count); for (int count = 0; count <= dt.Tables[0].Rows.Count - 1; count++) { var newMap = new Map(); newMap.PageId = pageId; newMap.mapID = Int16.Parse(dt.Tables[0].Rows[count]["mapid"].ToString()); newMap.Scale = Double.Parse(dt.Tables[0].Rows[count]["scale"].ToString()); newMap.X = Int16.Parse(dt.Tables[0].Rows[count]["x"].ToString()); newMap.Y = Int16.Parse(dt.Tables[0].Rows[count]["y"].ToString()); mapList.Add(newMap); } return(mapList); }
public List <SimpleTranslation> LoadTextRepository() { SqlCommand sqlCommand = null; var translationList = new List <SimpleTranslation>(); try { // Searching all repository sqlCommand = new SqlCommand("SELECT * FROM TEXT_TRANSLATIONS ORDER BY DOM_ELEMENT_ID"); DataSet dataSet = SQLOperation.ExecuteSQLCommandWithResult(sqlCommand); SimpleTranslation simpleTranslation = new SimpleTranslation(); int contRows = 0; do { // Running all content, and build the repository. if (simpleTranslation.DOMElementID != dataSet.Tables[0].Rows[contRows]["DOM_ELEMENT_ID"].ToString()) { if (simpleTranslation.DOMElementID != null) { //Save the last translation repository translationList.Add(simpleTranslation); } simpleTranslation = new SimpleTranslation(); simpleTranslation.DOMElementID = dataSet.Tables[0].Rows[contRows]["DOM_ELEMENT_ID"].ToString(); } // Now, set the translation if (dataSet.Tables[0].Rows[contRows]["IDIOM"].ToString() == "PT") { simpleTranslation.PortugueseContent = dataSet.Tables[0].Rows[contRows]["TRANSLATION"].ToString(); } else { simpleTranslation.EnglishContent = dataSet.Tables[0].Rows[contRows]["TRANSLATION"].ToString(); } contRows++; } while (contRows < dataSet.Tables[0].Rows.Count); //Save the last translation repository translationList.Add(simpleTranslation); // With the translation repository complete, generate the JSON format return(translationList); } catch (Exception e) // Em qualquer caso de erro, retornar nulo. { return(null); } finally { // In all errors, return null sqlCommand.Dispose(); } }
// Lookup one Episode and return it if is found public bool EpisodeHasBeenLoaded(int episodeNumber, string episodeIdiom) { var sqlCommand = new SqlCommand("SELECT * FROM EPISODES WHERE EPISODENUMBER = @EPISODENUMBER"); sqlCommand.Parameters.AddWithValue("EPISODENUMBER", episodeNumber); var dt = SQLOperation.ExecuteSQLCommandWithResult(sqlCommand); if (dt.Tables[0].Rows.Count <= 0) { return(false); } else { return(true); } }
// Return the list of all episodes of the page. It will just load the header of episodes, not the entire page and map list public List <Episode> AllEpisodeList() { // If is not, insert a new episode var sqlCommand = new SqlCommand("SELECT * FROM EPISODES ORDER BY EPISODENUMBER ASC"); var dt = SQLOperation.ExecuteSQLCommandWithResult(sqlCommand); var episodeList = new List <Episode>(dt.Tables[0].Rows.Count); for (int count = 0; count <= dt.Tables[0].Rows.Count - 1; count++) { //Setting a loaded episode var episode = new Episode(); episode.EpisodeNumber = Int16.Parse(dt.Tables[0].Rows[count]["EPISODENUMBER"].ToString()); episode.Idiom = dt.Tables[0].Rows[count]["idiom"].ToString(); episode.Title = dt.Tables[0].Rows[count]["Title"].ToString(); episode.Prologue = dt.Tables[0].Rows[count]["Prologue"].ToString(); episode.ImgHeaderPath = dt.Tables[0].Rows[count]["ImgHeaderPath"].ToString(); episodeList.Add(episode); } return(episodeList); }
// Save the map to the context public void Save(Page page) { var sqlCommand = new SqlCommand("INSERT INTO Pages(path, EpisodeNumber) VALUES(@path, @EPISODENUMBER)"); // Set parameters sqlCommand.Parameters.AddWithValue("PATH", page.Path); sqlCommand.Parameters.AddWithValue("EPISODENUMBER", page.episodeNumber); SQLOperation.ExecuteSQLCommand(sqlCommand); // Select its ID sqlCommand = new SqlCommand("SELECT MAX (PAGEID) as PAGEID FROM PAGES"); var dt = SQLOperation.ExecuteSQLCommandWithResult(sqlCommand); // Adding all maps var mapRep = new MapRepository(); foreach (Map newMap in page.Maps) { newMap.PageId = Int16.Parse(dt.Tables[0].Rows[0]["PAGEID"].ToString()); mapRep.Save(newMap); } }