Esempio n. 1
0
        // Save the map to the context
        public void Save(Episode episode)
        {
            // First, find if another episode was inserted before
            if (this.EpisodeHasBeenLoaded(episode.EpisodeNumber, episode.Idiom) == false)
            {
                // If is not, insert a new episode
                var sqlCommand = new SqlCommand("INSERT INTO EPISODES(EpisodeNumber, IDIOM, Prologue, Title, ImgHeaderPath) VALUES(@EPISODENUMBER, @IDIOM, @Prologue, @Title, @ImgHeaderPath)");
                // Set parameters
                sqlCommand.Parameters.AddWithValue("EPISODENUMBER", episode.EpisodeNumber);
                sqlCommand.Parameters.AddWithValue("IDIOM", episode.Idiom);
                sqlCommand.Parameters.AddWithValue("Prologue", episode.Prologue);
                sqlCommand.Parameters.AddWithValue("Title", episode.Title);
                sqlCommand.Parameters.AddWithValue("ImgHeaderPath", episode.ImgHeaderPath);

                SQLOperation.ExecuteSQLCommand(sqlCommand);
            }


            // Adding all pages
            var pageRep = new PageRepository();

            foreach (Page page in episode.Pages)
            {
                page.episodeNumber = episode.EpisodeNumber;
                pageRep.Save(page);
            }
        }
        // Save the map to the database
        public void Save(Map map)
        {
            var sqlCommand = new SqlCommand("INSERT INTO Maps(scale, X, Y, PageId) VALUES(@SCALE, @X, @Y, @PAGEID)");

            // Set parameters
            sqlCommand.Parameters.AddWithValue("SCALE", map.Scale);
            sqlCommand.Parameters.AddWithValue("X", map.X);
            sqlCommand.Parameters.AddWithValue("Y", map.Y);
            sqlCommand.Parameters.AddWithValue("PAGEID", map.PageId);

            SQLOperation.ExecuteSQLCommand(sqlCommand);
        }
Esempio n. 3
0
        public void SaveTextRepository(ITextRepository <Dictionary <string, string> > textRepository)
        {
            // After, run all the translations, and add
            foreach (KeyValuePair <string, string> _idiomTranslation in textRepository.translations())
            {
                var sqlCommand = new SqlCommand("INSERT INTO TEXT_TRANSLATIONS(DOM_ELEMENT_ID, IDIOM, TRANSLATION) VALUES(@DOM_ELEMENT_ID, @IDIOM, @TRANSLATION)");

                // Set parameters
                sqlCommand.Parameters.AddWithValue("DOM_ELEMENT_ID", textRepository.DOMElementID);
                sqlCommand.Parameters.AddWithValue("IDIOM", _idiomTranslation.Key);
                sqlCommand.Parameters.AddWithValue("TRANSLATION", _idiomTranslation.Value);

                SQLOperation.ExecuteSQLCommand(sqlCommand);
            }
        }
Esempio n. 4
0
        public TextRepository_SQLToJSON(bool addNewRecords)
        {
            SqlCommand sqlCommand = null;

            try
            {
                if (addNewRecords == true) // Only remove the existing records if is necessary
                {
                    // First of all, remove all translation records
                    sqlCommand = new SqlCommand("DELETE FROM TEXT_TRANSLATIONS");
                    SQLOperation.ExecuteSQLCommand(sqlCommand);
                }
            }
            catch (Exception e)
            {
                // If ocourrs an SQL error, telling the table don't exists, create the table.
                CreateRepositoryOnBase();
            }
        }
Esempio n. 5
0
        // 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);
            }
        }
Esempio n. 6
0
        // Function to create the table to the base, if it don't exist
        public void CreateRepositoryOnBase()
        {
            var sqlCommand = new SqlCommand("CREATE TABLE TEXT_TRANSLATIONS (DOM_ELEMENT_ID varchar(100) null, IDIOM varchar(10) null, TRANSLATION text)");

            SQLOperation.ExecuteSQLCommand(sqlCommand);
        }