Example #1
0
        private void Mnu2verseSplit_Click(object sender, EventArgs e)
        {
            int nPoemId = ganjoorView.CurrentPoemId;

            if (nPoemId < 1)
            {
                MessageBox.Show("لطفا شعری را انتخاب کنید.");
                return;
            }
            if (MessageBox.Show("با اجرای این فرمان هر دو بیت شعر جدیدی محسوب می‌شود. شعرهای جدید به بخش جاری اضافه می‌شوند.\n\rآیا ادامه می‌دهید؟", "تأییدیه", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign | MessageBoxOptions.RtlReading) == DialogResult.Yes)
            {
                DbBrowser           dbBrowser = new DbBrowser();
                List <GanjoorVerse> verses    = dbBrowser.GetVerses(nPoemId);

                int nCatId      = ganjoorView.CurrentCatId;
                int nPoemNo     = 0;
                int nLastPoemId = nPoemId;

                for (int nIndex = 0; nIndex < verses.Count; nIndex += 4)
                {
                    nPoemNo++;
                    dbBrowser.BeginBatchOperation();
                    GanjoorPoem newPoem = dbBrowser.CreateNewPoem("شمارهٔ " + GPersianTextSync.Sync(nPoemNo.ToString()), nCatId);
                    nLastPoemId = newPoem._ID;
                    for (int i = 0; i < 4; i++)
                    {
                        GanjoorVerse v = dbBrowser.CreateNewVerse(newPoem._ID, i, verses[nIndex + i]._Position);
                        dbBrowser.SetVerseText(newPoem._ID, v._Order, verses[nIndex + i]._Text);
                    }
                    dbBrowser.CommitBatchOperation();
                }
                ganjoorView.ShowPoem(dbBrowser.GetPoem(nLastPoemId), true);
                dbBrowser.CloseDb();
            }
        }
Example #2
0
 private void grdList_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.RowIndex != -1)
     {
         SelectedPoem = _DbBrowser.GetPoem((grdList.Rows[e.RowIndex].Tag as PoemAudio).PoemId);
         if (SelectedPoem != null)
         {
             DialogResult = System.Windows.Forms.DialogResult.OK;
         }
     }
 }
Example #3
0
        private static void ReArrangeTabularVerses(GanjoorPoem curPoem, DbBrowser dbBrowser)
        {
            if (curPoem != null)
            {
                List <GanjoorVerse> verses = dbBrowser.GetVerses(curPoem._ID);

                int nVIndex = 0;
                while (nVIndex < verses.Count)
                {
                    if (verses[nVIndex]._Position == VersePosition.Right)
                    {
                        List <string> vTexts = new List <string>();
                        vTexts.Add(verses[nVIndex]._Text);
                        int nStart = nVIndex;
                        nVIndex++;
                        if (nVIndex < verses.Count)
                        {
                            while (
                                nVIndex < verses.Count
                                &&
                                (
                                    verses[nVIndex]._Position == VersePosition.Left
                                    ||
                                    verses[nVIndex]._Position == VersePosition.Right
                                )
                                )
                            {
                                vTexts.Add(verses[nVIndex]._Text);
                                nVIndex++;
                            }
                            int nEndPlusOne = nVIndex;
                            if ((nEndPlusOne - nStart) > 2)
                            {
                                int nText = 0;
                                for (int nRight = nStart; nRight < nEndPlusOne; nRight += 2, nText++)
                                {
                                    dbBrowser.SetVerseText(curPoem._ID, verses[nRight]._Order, vTexts[nText]);
                                }
                                for (int nLeft = nStart + 1; nLeft < nEndPlusOne; nLeft += 2, nText++)
                                {
                                    dbBrowser.SetVerseText(curPoem._ID, verses[nLeft]._Order, vTexts[nText]);
                                }
                            }
                            nVIndex--;
                        }
                    }
                    nVIndex++;
                }
            }
        }
Example #4
0
 private void btnView_Click(object sender, EventArgs e)
 {
     if (grdList.SelectedRows.Count == 1)
     {
         SelectedPoem = _DbBrowser.GetPoem((grdList.SelectedRows[0].Tag as PoemAudio).PoemId);
         if (SelectedPoem != null)
         {
             DialogResult = System.Windows.Forms.DialogResult.OK;
         }
     }
     else
     {
         MessageBox.Show("ردیفی انتخاب نشده است.", "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading | MessageBoxOptions.RightAlign);
     }
 }
Example #5
0
 private void DRY_ExportPoem(DbBrowser dbBrowser, GanjoorPoem poem, StringBuilder sb, bool exportPoemName, string poemNameSeparator)
 {
     if (exportPoemName)
     {
         if (!string.IsNullOrEmpty(poemNameSeparator))
         {
             sb.AppendLine(poemNameSeparator);
         }
         sb.AppendLine(poem._Title);
         if (!string.IsNullOrEmpty(poemNameSeparator))
         {
             sb.AppendLine(poemNameSeparator);
         }
     }
     foreach (GanjoorVerse verse in dbBrowser.GetVerses(poem._ID))
     {
         sb.AppendLine(verse._Text);
     }
 }
Example #6
0
        private void mnuImport_Click(object sender, EventArgs e)
        {
            int nCurCatId  = ganjoorView.CurrentCatId;
            int nCurPoetId = ganjoorView.CurrentPoetId;

            if (nCurCatId < 0 || nCurPoetId < 0)
            {
                MessageBox.Show("لطفا ابتدا وارد آثار شاعر (و بخش مورد نظر) شوید.");
                return;
            }
            #region Old Code
            if ((ModifierKeys | Keys.Shift) == ModifierKeys)
            {
                using (TextImporter dlgOld = new TextImporter())
                {
                    if (dlgOld.ShowDialog(this) == DialogResult.OK)
                    {
                        string   fileName            = dlgOld.FileName;
                        string   mainCatText         = dlgOld.MainCatText;
                        string[] subCatTexts         = dlgOld.SubCatTexts;
                        int      nMaxVerseTextLength = dlgOld.MaxVerseTextLength;
                        bool     bTabularVerses      = dlgOld.TabularVerses;

                        Cursor = Cursors.WaitCursor;
                        Application.DoEvents();

                        string[] lines = File.ReadAllLines(fileName);

                        Application.DoEvents();



                        GanjoorCat  curMainCat = null;
                        GanjoorPoem curPoem    = null;

                        int nTotalLines = lines.Length;
                        int nCurLine    = 0;

                        int nCurVerse = 0;



                        DbBrowser dbBrowser = new DbBrowser();

                        dbBrowser.BeginBatchOperation();
                        while (nCurLine < nTotalLines)
                        {
                            if (lines[nCurLine].Contains(mainCatText))
                            {
                                curMainCat = dbBrowser.CreateNewCategory(lines[nCurLine].Trim(), nCurCatId, nCurPoetId);
                            }
                            else if (curMainCat != null)
                            {
                                bool bNewCatOrPoem = false;
                                foreach (string subCatText in subCatTexts)
                                {
                                    if (lines[nCurLine].Contains(subCatText))
                                    {
                                        if (bTabularVerses)
                                        {
                                            ReArrangeTabularVerses(curPoem, dbBrowser);
                                        }
                                        curPoem       = dbBrowser.CreateNewPoem(lines[nCurLine].Trim(), curMainCat._ID);
                                        bNewCatOrPoem = true;
                                        nCurVerse     = 0;
                                        break;
                                    }
                                }

                                if (!bNewCatOrPoem)
                                {
                                    string line = lines[nCurLine].Trim();
                                    if (!string.IsNullOrEmpty(line))
                                    {
                                        int nWordsCount = line.Split(' ').Length;

                                        bool bVerseDetected = false;

                                        if (nWordsCount <= nMaxVerseTextLength)
                                        {
                                            int nNextLine = nCurLine + 1;
                                            if (nNextLine < nTotalLines)
                                            {
                                                while (nNextLine < nTotalLines)
                                                {
                                                    string nextLine = lines[nNextLine].Trim();
                                                    if (string.IsNullOrEmpty(nextLine))
                                                    {
                                                        nNextLine++;
                                                    }
                                                    else
                                                    {
                                                        int nNextWordsCount = nextLine.Split(' ').Length;
                                                        if (nNextWordsCount <= nMaxVerseTextLength)
                                                        {
                                                            if (nextLine.Contains(mainCatText))
                                                            {
                                                                break;
                                                            }
                                                            bool bBreak = false;
                                                            foreach (string subCatText in subCatTexts)
                                                            {
                                                                if (nextLine.Contains(subCatText))
                                                                {
                                                                    bBreak = true;
                                                                    break;
                                                                }
                                                            }
                                                            if (bBreak)
                                                            {
                                                                break;
                                                            }
                                                            if (curPoem == null)
                                                            {
                                                                MessageBox.Show("curPoem == null");
                                                                return;
                                                            }
                                                            bVerseDetected = true;

                                                            GanjoorVerse v1 = dbBrowser.CreateNewVerse(curPoem._ID, nCurVerse, VersePosition.Right);
                                                            dbBrowser.SetVerseText(curPoem._ID, v1._Order, line);
                                                            nCurVerse++;
                                                            GanjoorVerse v2 = dbBrowser.CreateNewVerse(curPoem._ID, nCurVerse, VersePosition.Left);
                                                            dbBrowser.SetVerseText(curPoem._ID, v2._Order, nextLine);
                                                            nCurVerse++;

                                                            nCurLine = nNextLine;
                                                            break;
                                                        }
                                                        else
                                                        {
                                                            break;
                                                        }
                                                    }
                                                }
                                            }
                                        }

                                        if (!bVerseDetected)
                                        {
                                            if (curPoem == null)
                                            {
                                                MessageBox.Show("curPoem == null");
                                                return;
                                            }
                                            GanjoorVerse p = dbBrowser.CreateNewVerse(curPoem._ID, nCurVerse, VersePosition.Paragraph);
                                            dbBrowser.SetVerseText(curPoem._ID, p._Order, line);
                                            nCurVerse++;
                                        }
                                    }
                                }
                            }
                            nCurLine++;
                        }
                        if (bTabularVerses)
                        {
                            ReArrangeTabularVerses(curPoem, dbBrowser);
                        }
                        dbBrowser.CommitBatchOperation();
                        dbBrowser.CloseDb();


                        Cursor = Cursors.Default;
                        MessageBox.Show("انجام شد");

                        ganjoorView.Font = ganjoorView.Font;
                    }
                }
                return;
            }
            #endregion
            using (GeneralTextImporter dlg = new GeneralTextImporter())
            {
                if (dlg.ShowDialog(this) == DialogResult.OK)
                {
                    string fileName                  = dlg.FileName;
                    string nextPoemStartText         = dlg.NextPoemStartText;
                    bool   nextPoemStartIsAShortText = dlg.NextPoemStartIsAShortText;
                    int    nShortTextLength          = dlg.ShortTextLength;

                    Cursor = Cursors.WaitCursor;
                    Application.DoEvents();

                    string[] lines = File.ReadAllLines(fileName);

                    Application.DoEvents();



                    int nTotalLines = lines.Length;
                    int nCurLine    = 0;

                    int nCurVerse = 0;

                    DbBrowser  dbBrowser = new DbBrowser();
                    GanjoorCat cat       = dbBrowser.GetCategory(nCurCatId);
                    if (cat == null)
                    {
                        MessageBox.Show("cat == null");
                        dbBrowser.CloseDb();
                        return;
                    }


                    GanjoorPoem curPoem = null;

                    dbBrowser.BeginBatchOperation();
                    while (nCurLine < nTotalLines)
                    {
                        string line = lines[nCurLine].Trim();
                        if (!string.IsNullOrEmpty(line))
                        {
                            if (
                                (nextPoemStartIsAShortText && line.Length < nShortTextLength)
                                ||
                                (!nextPoemStartIsAShortText && line.IndexOf(nextPoemStartText) == 0)
                                )
                            {
                                curPoem   = dbBrowser.CreateNewPoem(line, nCurCatId);
                                nCurVerse = 0;
                            }
                            else
                            if (curPoem != null)
                            {
                                GanjoorVerse v = dbBrowser.CreateNewVerse(curPoem._ID, nCurVerse, nCurVerse % 2 == 0 ? VersePosition.Right : VersePosition.Left);
                                dbBrowser.SetVerseText(curPoem._ID, v._Order, line);
                                nCurVerse++;
                            }
                        }
                        nCurLine++;
                    }
                    dbBrowser.CommitBatchOperation();
                    dbBrowser.CloseDb();


                    Cursor = Cursors.Default;
                    MessageBox.Show("انجام شد");

                    ganjoorView.Font = ganjoorView.Font;
                }
            }
        }