Ejemplo n.º 1
0
        public static ReadingTag createReadingTag(int readingId, String tagText)
        {
            ReadingTag tag;

            using (SqlConnection con = new SqlConnection(databaseConnectionStr))
            {
                con.Open();
                //first check database for already existing Tag text
                int?tagId = checkForTag(tagText, con);
                //if none, must create
                if (tagId == null)
                {
                    tagId = addTagToDB(tagText, con);
                }
                //then simply add an entry to the ReadingTags table to connect the reading to the tag
                addReadingTagLinkToDB(readingId, (int)tagId, con);
                tag = new ReadingTag((int)tagId, readingId, tagText);
                con.Close();
            }
            return(tag);
        }
Ejemplo n.º 2
0
        //call this function whenever saving a modified project file, saves everything within
        public static Boolean updateProject(Project project)
        {
            int updatedReadings = 0;
            int updatedWritings = 0;

            foreach (Reading r in project.readings)
            {
                if (r.deleted)
                {
                    deleteReading(r);
                }
                else if (r.readingId <= 0) //if true, reading is new
                {
                    Reading tempReading = createReading(r.projectId, r.title, "", r.text, "", new DateTime(r.dateYear, getMonthNum(r.dateMonth), r.dateDay), r.publisherName, r.city, r.yearPublished);
                    r.readingId = tempReading.readingId;
                }
                else if (r.modified)
                {
                    updateReading(r.readingId, r.title, r.text, "", new DateTime(r.dateYear, getMonthNum(r.dateMonth), r.dateDay), r.publisherName, "", r.yearPublished);
                    updatedReadings++;
                }
                //Authors
                deleteAuthors(r.readingId);
                foreach (Author author in r.authors)
                {
                    Author tempAuthor = createAuthor(r.readingId, author.first, author.middle, author.last);
                    author.authorId = tempAuthor.authorId;
                }
                //ReadingTags
                deleteReadingTagLinks(r.readingId);
                foreach (ReadingTag tag in r.readingTags)
                {
                    ReadingTag tempRTag = createReadingTag(r.readingId, tag.tag);
                    tag.tagId = tempRTag.tagId;
                }
                //Highlights and HighlightTags
                foreach (Highlight highlight in r.highlights)
                {
                    deleteHighlightTagLinks(highlight.highlightId);
                }
                deleteHighlights(r.readingId);
                foreach (Highlight highlight in r.highlights)
                {
                    Highlight tempHighlight = createHighlight(r.readingId, highlight.isQuote, highlight.charNum, highlight.charCount);
                    foreach (HighlightTag tag in highlight.highlightTags)
                    {
                        HighlightTag tempHTag = createHighlightTag(tempHighlight.highlightId, tag.tag);
                        tag.tagId = tempHTag.tagId;
                    }
                    highlight.highlightId = tempHighlight.highlightId;
                }
                r.modified = false;
            }
            for (int i = project.readings.Count - 1; i >= 0; i--) //loop through backwards and delete as encountered
            {
                if (project.readings.ElementAt(i).modified)
                {
                    project.readings.RemoveAt(i);
                }
            }

            foreach (Writing w in project.writings)
            {
                if (w.deleted)
                {
                    deleteWriting(w);
                }
                else if (w.writingId <= 0)
                {
                    Writing tempWriting = createWriting(w.projectId, w.text);
                    w.writingId = tempWriting.writingId;
                }
                else if (w.modified)
                {
                    updateWriting(w);
                    updatedWritings++;
                }
                w.modified = false;
            }
            for (int i = project.writings.Count - 1; i >= 0; i--)
            {
                if (project.writings.ElementAt(i).modified)
                {
                    project.writings.RemoveAt(i);
                }
            }
            String message = "";

            if (updatedReadings == 0 && updatedWritings != 0)
            {
                message = updatedWritings + " Writings Updated.";
            }
            else if (updatedWritings == 0 && updatedReadings != 0)
            {
                message = updatedReadings + " Readings Updated.";
            }
            else if (updatedWritings != 0 && updatedReadings != 0)
            {
                message = updatedReadings + " Readings Updated and " + updatedWritings + " Writings Updated.";
            }
            if (updatedWritings != 0 || updatedReadings != 0)
            {
                PopupForm popup = new PopupForm(message);
                popup.Show();
            }
            return(true);
        }