예제 #1
0
 public GanjoorVerse(int PoemID, int Order, VersePosition Position, string Text)
 {
     _PoemID   = PoemID;
     _Order    = Order;
     _Position = Position;
     _Text     = Text;
 }
예제 #2
0
        public int GetVerseCoupletNumber(GanjoorVerseViewModel verse)
        {
            int           n   = 1;
            VersePosition pre = VersePosition.Right;

            foreach (var v in PageInformation.Poem.Verses)
            {
                if (v.Id == verse.Id)
                {
                    if (pre == VersePosition.CenteredVerse1 && v.VersePosition != VersePosition.CenteredVerse2)
                    {
                        n++;
                    }
                    return(n);
                }
                if (v.VersePosition == VersePosition.Left || v.VersePosition == VersePosition.CenteredVerse2 ||
                    v.VersePosition == VersePosition.Single || v.VersePosition == VersePosition.Paragraph)
                {
                    n++;
                }
                else
                if (pre == VersePosition.CenteredVerse1)
                {
                    n++;
                }
                pre = v.VersePosition;
            }
            return(-1);
        }
예제 #3
0
        public void GetVerseTest_Strict_Last_VerseTooLarge()
        {
            //Repository_Accessor target = new Repository_Accessor();
            string         book     = "lev";
            int            chapter  = 5;
            int            verse    = 5000;
            string         suffix   = null;
            VersePosition  position = VersePosition.Last;
            RepositoryMode mode     = RepositoryMode.Strict;
            Verse          expected = null;
            Verse          actual;

            actual = Verse.Create(si, book, chapter, verse, suffix, position, mode);
            Assert.AreEqual(expected, actual);
        }
예제 #4
0
        public void GetVerseTest_Optimistic_First_BadBook()
        {
            //Repository_Accessor target = new Repository_Accessor();
            string         book     = "not a book";
            int            chapter  = 5;
            int            verse    = 19;
            string         suffix   = "b";
            VersePosition  position = VersePosition.First;
            RepositoryMode mode     = RepositoryMode.Optimistic;
            Verse          expected = null;
            Verse          actual;

            actual = Verse.Create(si, book, chapter, verse, suffix, position, mode);
            Assert.AreEqual(expected, actual);
        }
예제 #5
0
        private void btnFixFirstVerse_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("آیا از ادامهٔ عملیات اطمینان دارید؟",
                                "تأییدیه", MessageBoxButtons.YesNo) == DialogResult.No)
            {
                return;
            }
            if (MessageBox.Show("آیا تمایل دارید ادامه ندهید؟",
                                "تأییدیه", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                return;
            }
            if (MessageBox.Show("آیا واقعاً از ادامهٔ عملیات اطمینان دارید؟",
                                "تأییدیه", MessageBoxButtons.YesNo) == DialogResult.No)
            {
                return;
            }


            foreach (DataGridViewRow row in grdMain.SelectedRows)
            {
                Application.DoEvents();
                int poemId = Convert.ToInt32(row.Cells[ClmnID].Value);
                var verses = _db.GetVerses(poemId);

                List <int> versesToDelete = new List <int>();
                foreach (GanjoorVerse Verse in verses)
                {
                    versesToDelete.Add(Verse._Order);
                }

                if (_db.DeleteVerses(poemId, versesToDelete))
                {
                    VersePosition pos = VersePosition.Right;
                    for (int i = 1; i < verses.Count; i++)
                    {
                        var v = _db.CreateNewVerse(poemId, i - 1, pos);
                        _db.SetVerseText(poemId, v._Order, verses[i]._Text);
                        pos = pos == VersePosition.Right ? VersePosition.Left : VersePosition.Right;
                    }

                    _db.SetPoemTitle(poemId, verses[0]._Text);
                }
            }

            LoadGridData();
        }
예제 #6
0
        public void GetVerseTest_Strict_Last_NoVerse()
        {
            //Repository_Accessor target = new Repository_Accessor();
            string         book     = "lev";
            int            chapter  = 5;
            int            verse    = -1;
            string         suffix   = null;
            VersePosition  position = VersePosition.Last;
            RepositoryMode mode     = RepositoryMode.Strict;
            Verse          expected = new Verse
            {
                Index         = 2850,
                BookName      = "Leviticus",
                BookNumber    = 3,
                ChapterNumber = 5,
                VerseNumber   = 19,
                Suffix        = null
            };
            Verse actual;

            actual = Verse.Create(si, book, chapter, verse, suffix, position, mode);
            Assert.AreEqual(expected, actual);
        }
예제 #7
0
        public void GetVerseTest_Optimistic_First_Normal()
        {
            //Repository_Accessor target = new Repository_Accessor();
            string         book     = "lev";
            int            chapter  = 5;
            int            verse    = 19;
            string         suffix   = "b";
            VersePosition  position = VersePosition.First;
            RepositoryMode mode     = RepositoryMode.Optimistic;
            Verse          expected = new Verse
            {
                Index         = 2850,
                BookName      = "Leviticus",
                BookNumber    = 3,
                ChapterNumber = 5,
                VerseNumber   = 19,
                Suffix        = "b"
            };
            Verse actual;

            actual = Verse.Create(si, book, chapter, verse, suffix, position, mode);
            Assert.AreEqual(expected, actual);
        }
예제 #8
0
        public void GetVerseTest_Optimistic_Last_ChapterTooLarge()
        {
            //Repository_Accessor target = new Repository_Accessor();
            string         book     = "lev";
            int            chapter  = 5000;
            int            verse    = -1;
            string         suffix   = null;
            VersePosition  position = VersePosition.Last;
            RepositoryMode mode     = RepositoryMode.Optimistic;
            Verse          expected = new Verse
            {
                Index         = 3605,
                BookName      = "Leviticus",
                BookNumber    = 3,
                ChapterNumber = 27,
                VerseNumber   = 34,
                Suffix        = null
            };
            Verse actual;

            actual = Verse.Create(si, book, chapter, verse, suffix, position, mode);
            Assert.AreEqual(expected, actual);
        }
예제 #9
0
        private static string _DefHtmlText(GanjoorVerseViewModel[] verses)
        {
            string        htmlText     = "";
            int           coupletIndex = 0;
            VersePosition position     = VersePosition.Right;

            for (int vIndex = 0; vIndex < verses.Length; vIndex++)
            {
                GanjoorVerseViewModel v = verses[vIndex];
                if (position == VersePosition.Right)
                {
                    coupletIndex++;
                    htmlText += $"<div class=\"b\" id=\"bn{coupletIndex}\"><div class=\"m1\"><p>{v.Text}</p></div>{Environment.NewLine}";
                    position  = VersePosition.Left;
                }
                else
                {
                    htmlText += $"<div class=\"m2\"><p>{v.Text}</p></div></div>{Environment.NewLine}";
                    position  = VersePosition.Right;
                }
            }
            return(htmlText.Trim());
        }
예제 #10
0
        internal static Verse Create(Scripture.Version.ScriptureInfo scriptureInfo, BookInfo bookInfo, int chapter, int verse, string suffix, VersePosition position, RepositoryMode mode)
        {
            Verse result = new Verse();

            result._scriptureInfo = scriptureInfo;

            result._bookInfo = bookInfo; // scriptureInfo.GetBookInfo(bookNumber);

            if (result._bookInfo == null)
            {
                result = null;
            }
            else
            {
                switch (position)
                {
                case VersePosition.First:
                    if (chapter < 1)
                    {
                        if (chapter == -1 || mode == RepositoryMode.Optimistic)
                        {
                            chapter = 1;
                            verse   = -1;
                        }
                        else
                        {
                            result = null;
                        }
                    }

                    if (result != null && verse < 1)
                    {
                        if (verse == -1 || mode == RepositoryMode.Optimistic)
                        {
                            verse = 1;
                        }
                        else
                        {
                            result = null;
                        }
                    }
                    break;

                case VersePosition.Last:
                    if (chapter < 1)
                    {
                        if (chapter == -1 || mode == RepositoryMode.Optimistic)
                        {
                            chapter = scriptureInfo.GetLastChapter(result._bookInfo.Number);
                            verse   = -1;
                        }
                        else
                        {
                            result = null;
                        }
                    }

                    if (result != null && verse < 0)
                    {
                        if (verse == -1 || mode == RepositoryMode.Optimistic)
                        {
                            try
                            {
                                verse = scriptureInfo.GetLastVerse(result._bookInfo.Number, chapter);
                            }
                            catch (Exception)
                            {
                                if (mode == RepositoryMode.Optimistic)
                                {
                                    chapter = scriptureInfo.GetLastChapter(result._bookInfo.Number);
                                    verse   = scriptureInfo.GetLastVerse(result._bookInfo.Number, chapter);
                                }
                                else
                                {
                                    result = null;
                                }
                            }
                        }
                        else
                        {
                            result = null;
                        }
                    }

                    break;
                }

                int maxChapter = scriptureInfo.GetLastChapter(result._bookInfo.Number);
                if (chapter > maxChapter)
                {
                    if (mode == RepositoryMode.Optimistic)
                    {
                        chapter = maxChapter;
                        verse   = int.MaxValue;
                    }
                    else
                    {
                        result = null;
                    }
                }
                if (result != null)
                {
                    int maxVerse = scriptureInfo.GetLastVerse(result._bookInfo.Number, chapter);
                    if (verse > maxVerse)
                    {
                        if (mode == RepositoryMode.Optimistic)
                        {
                            verse = maxVerse;
                        }
                        else
                        {
                            result = null;
                        }
                    }
                }

                if (result != null)
                {
                    int index         = -1;
                    int chapterResult = -1;
                    int verseResult   = -1;

                    scriptureInfo.GetVerseData(result._bookInfo.Number, chapter, verse, out index, out chapterResult, out verseResult);

                    result.Index         = index;
                    result.ChapterNumber = chapterResult;
                    result.VerseNumber   = verseResult;
                    result.Suffix        = string.IsNullOrWhiteSpace(suffix) ? null : suffix.Trim().ToLower();
                }
            }

            return(result);
        }
예제 #11
0
        internal static Verse Create(Scripture.Version.ScriptureInfo scriptureInfo, string book, int chapter, int verse, string suffix, VersePosition position, RepositoryMode mode)
        {
            BookInfo bookInfo = scriptureInfo.GetBookInfo(book);

            return(Create(scriptureInfo, bookInfo, chapter, verse, suffix, position, mode));
        }