Пример #1
0
        private void LoadGridData()
        {
            if (_db == null)
            {
                _db = new DbBrowser();
            }

            _OriginalIdSet.Clear();
            grdMain.Rows.Clear();

            List <GanjoorCat> Cats = _db.GetSubCategories(Settings.Default.LastCat);

            grdMain.SuspendLayout();
            foreach (GanjoorCat Cat in Cats)
            {
                int rowIndex = grdMain.Rows.Add();

                _OriginalIdSet.Add(Cat._ID);

                grdMain.Rows[rowIndex].Cells[ClmnID].Value = Cat._ID;

                grdMain.Rows[rowIndex].Cells[ClmnTitle].Value = Cat._Text;
            }
            grdMain.ResumeLayout();
            lblCatCount.Text = String.Format("{0} بخش", grdMain.RowCount);
        }
Пример #2
0
        private void FillTree(int PoetID)
        {
            DbBrowser db = _RefDb == null ? new DbBrowser() : _RefDb;

            treeCats.Nodes.Clear();
            if (PoetID == 0)
            {
                treeCats.Nodes.Add("همه").Tag = 0;
                foreach (GanjoorPoet poet in db.Poets)
                {
                    TreeNode newPoet = treeCats.Nodes.Add(poet._Name);
                    newPoet.Tag = poet._CatID;
                    AddSubCats(db, newPoet, poet._CatID);
                }
            }
            else
            {
                GanjoorPoet poet    = db.GetPoet(PoetID);
                TreeNode    newPoet = treeCats.Nodes.Add(poet._Name);
                newPoet.Tag = poet._CatID;
                AddSubCats(db, newPoet, poet._CatID);
            }
            if (_RefDb == null)
            {
                db.CloseDb();
            }
        }
Пример #3
0
        private GDBInfo ExtracInfoFromGDBFileAndAddToGrid(string FileName, string ext, int FileSize)
        {
            GDBInfo   gdb        = null;
            DbBrowser gdbBrowser = new DbBrowser(FileName);

            if (gdbBrowser.Poets.Count != 1)
            {
                MessageBox.Show("این ابزار در حال حاضر تنها مجموعه‌های حاوی یک شاعر را پشتیبانی می‌کند.");
            }
            else
            {
                GanjoorPoet poet = gdbBrowser.Poets[0];
                gdb         = new GDBInfo();
                gdb.CatName = poet._Name;
                gdb.PoetID  = poet._ID;
                int minCatID, minPoemID;
                gdbBrowser.GetMinIDs(poet._ID, out minCatID, out minPoemID);
                gdb.CatID          = minCatID;
                gdb.FileExt        = ext;
                gdb.FileSizeInByte = FileSize;
                gdb.LowestPoemID   = minPoemID;
                gdb.PubDate        = DateTime.Now;
            }
            gdbBrowser.CloseDb();
            return(gdb);
        }
Пример #4
0
 private void ImportGdb(string FileName, DbBrowser db)
 {
     if (Path.GetExtension(FileName).Equals(".zip", StringComparison.InvariantCultureIgnoreCase))
     {
         using (ZipStorer zip = ZipStorer.Open(FileName, FileAccess.Read))
         {
             List <ZipStorer.ZipFileEntry> dir = zip.ReadCentralDir();
             foreach (ZipStorer.ZipFileEntry entry in dir)
             {
                 string gdbFileName = Path.GetFileName(entry.FilenameInZip);
                 if (Path.GetExtension(gdbFileName).Equals(".gdb") || Path.GetExtension(gdbFileName).Equals(".s3db"))
                 {
                     string ganjoorPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "ganjoor");
                     if (!Directory.Exists(ganjoorPath))
                     {
                         Directory.CreateDirectory(ganjoorPath);
                     }
                     string gdbExtractPath = Path.Combine(ganjoorPath, gdbFileName);
                     if (zip.ExtractFile(entry, gdbExtractPath))
                     {
                         ImportDb(gdbExtractPath, db);
                         File.Delete(gdbExtractPath);
                     }
                 }
             }
         }
     }
     else
     {
         ImportDb(FileName, db);
     }
 }
Пример #5
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();
            }
        }
Пример #6
0
        public override void OnActivated()
        {
            if (OnInstallStarted != null)
            {
                OnInstallStarted(this, new EventArgs());
            }
            DbBrowser db = new DbBrowser();

            Application.DoEvents();
            if (DownloadedFiles != null)
            {
                foreach (string gdb in DownloadedFiles)
                {
                    grdList.Rows[grdList.Rows.Add()].Cells[0].Value = Path.GetFileName(gdb);
                    ImportGdb(gdb, db);
                    if (Settings.Default.DeleteDownloadedFiles)
                    {
                        File.Delete(gdb);
                    }
                    Application.DoEvents();
                }
            }
            db.CloseDb();
            if (OnInstallFinished != null)
            {
                OnInstallFinished(this, new EventArgs());
            }
        }
Пример #7
0
        public SyncPoemAudio(DbBrowser dbBrowser, PoemAudio poemAudio)
        {
            InitializeComponent();

            _DbBrowser = dbBrowser;
            _PoemAudio = poemAudio;

            _PoemAudioPlayer = new PoemAudioPlayer();
            _PoemAudioPlayer.PlaybackStarted += new EventHandler(_PoemAudioPlayer_PlaybackStarted);
            _PoemAudioPlayer.PlaybackStopped += new EventHandler <NAudio.Wave.StoppedEventArgs>(_PoemAudioPlayer_PlaybackStopped);

            _Modified       = false;
            _Saved          = false;
            _SyncOrder      = -1;
            _LastSearchText = "";
            if (poemAudio.SyncArray != null)
            {
                _VerseMilisecPositions = new List <PoemAudio.SyncInfo>(poemAudio.SyncArray);
            }
            else
            {
                _VerseMilisecPositions = new List <PoemAudio.SyncInfo>();
            }

            _PoemVerses = _DbBrowser.GetVerses(poemAudio.PoemId).ToArray();

            EnableButtons();
        }
Пример #8
0
        private void ExportPoetToTextFile(GanjoorPoet poet, string targetFolder, DbBrowser dbBrowser)
        {
            if (!Directory.Exists(targetFolder))
            {
                Directory.CreateDirectory(targetFolder);
            }

            StringBuilder sb = new StringBuilder();

            if (Settings.Default.ExportPoetName)
            {
                string poetNameSeparator = Settings.Default.ExportPoetSep;
                if (!string.IsNullOrEmpty(poetNameSeparator))
                {
                    sb.AppendLine(poetNameSeparator);
                }
                sb.AppendLine(poet._Name);
                if (!string.IsNullOrEmpty(poetNameSeparator))
                {
                    sb.AppendLine(poetNameSeparator);
                }
            }

            GanjoorCat poetCat = dbBrowser.GetCategory(poet._CatID);

            DRY_ExportCat(dbBrowser, poetCat, sb);

            List <int> lstSubCategories = dbBrowser.GetAllSubCats(poetCat._ID);

            foreach (int catId in lstSubCategories)
            {
                DRY_ExportCat(dbBrowser, dbBrowser.GetCategory(catId), sb);
            }
            File.WriteAllText(Path.Combine(targetFolder, GPersianTextSync.Farglisize(poet._Name) + ".txt"), sb.ToString());
        }
Пример #9
0
        private void btnSelect_Click(object sender, EventArgs e)
        {
            DbBrowser db = new DbBrowser();

            using (ItemSelector poetSeletor = new ItemSelector("انتخاب شاعر", db.Poets.ToArray(), null))
            {
                if (poetSeletor.ShowDialog(this) == DialogResult.OK)
                {
                    GanjoorPoet poet = poetSeletor.SelectedItem as GanjoorPoet;
                    PoetId = poet._ID;
                    txtSelectedPoetOrCategory.Text = poet._Name;
                    if (MessageBox.Show(
                            $"آیا تمایل دارید خوانش‌های بخش خاصی از آثار {poet._Name} را دریافت کنید؟",
                            "تأییدیه", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2,
                            MessageBoxOptions.RtlReading | MessageBoxOptions.RightAlign) == System.Windows.Forms.DialogResult.No)
                    {
                        db.CloseDb();

                        return;
                    }
                    using (CategorySelector catSelector = new CategorySelector(poet._ID, db))
                    {
                        if (catSelector.ShowDialog(this) == DialogResult.OK)
                        {
                            CatId = catSelector.SelectedCatID;
                            txtSelectedPoetOrCategory.Text = $"{poet._Name} » {db.GetCategory(CatId)._Text}";
                            db.CloseDb();
                        }
                    }
                }
            }
        }
Пример #10
0
        public AudioFiles(int nPoemId = -1)
        {
            InitializeComponent();


            _PoemId    = nPoemId;
            _DbBrowser = new DbBrowser();
        }
Пример #11
0
 private void AddSubCats(DbBrowser db, TreeNode Node, int CatID)
 {
     foreach (GanjoorCat Cat in db.GetSubCategories(CatID))
     {
         TreeNode catNode = Node.Nodes.Add(Cat._Text);
         catNode.Tag = Cat._ID;
         AddSubCats(db, catNode, Cat._ID);
     }
 }
Пример #12
0
        public override void OnActivated()
        {
            if (OnInstallStarted != null)
            {
                OnInstallStarted(this, new EventArgs());
            }
            DbBrowser db = new DbBrowser();

            Application.DoEvents();
            string targetDir = DownloadableAudioListProcessor.SoundsPath;

            if (DownloadedSounds != null)
            {
                foreach (Dictionary <string, string> audioInfo in DownloadedSounds)
                {
                    grdList.Rows[grdList.Rows.Add()].Cells[0].Value = DownloadableAudioListProcessor.SuggestTitle(audioInfo);
                    string    mp3FilePath = Path.Combine(targetDir, Path.GetFileName(new Uri(audioInfo["audio_mp3"]).LocalPath));
                    PoemAudio poemAudio   = db.AddAudio(
                        Int32.Parse(audioInfo["audio_post_ID"]),
                        mp3FilePath,
                        DownloadableAudioListProcessor.SuggestTitle(audioInfo),
                        Int32.Parse(audioInfo["audio_order"])
                        );
                    string           xmlFilePath  = Path.Combine(targetDir, Path.GetFileName(new Uri(audioInfo["audio_xml"]).LocalPath));
                    List <PoemAudio> lstPoemAudio = PoemAudioListProcessor.Load(xmlFilePath);
                    if (lstPoemAudio.Count == 1)
                    {
                        foreach (PoemAudio xmlAudio in lstPoemAudio)
                        {
                            if (xmlAudio.PoemId == poemAudio.PoemId)
                            {
                                poemAudio.SyncArray = xmlAudio.SyncArray;
                                db.SavePoemSync(poemAudio, poemAudio.SyncArray, false);
                                poemAudio.SyncGuid = Guid.Parse(audioInfo["audio_guid"]);
                                db.WritePoemAudioGuid(poemAudio);
                                db.DeleteAudioWithSync(xmlAudio.PoemId, xmlAudio.SyncGuid, poemAudio.Id);
                                File.Delete(xmlFilePath); //not needed any more
                                grdList.Rows[grdList.RowCount - 1].Cells[1].Value = "نصب شد.";
                                InstalledFilesCount++;
                            }
                        }
                    }
                    else
                    {
                        grdList.Rows[grdList.RowCount - 1].Cells[1].Value = "خطا: فایل xml محتوی اطلاعات همگامسازی یک سطر نیست.";
                    }
                    Application.DoEvents();
                }
            }
            db.CloseDb();
            if (OnInstallFinished != null)
            {
                OnInstallFinished(this, new EventArgs());
            }
        }
Пример #13
0
        void MainMenuInputCatch()
        {
            string mainMenuInput = ConsoleGUI.PromptRender("Wybór: ");

            if (char.IsDigit(mainMenuInput[0]))
            {
                switch (int.Parse(mainMenuInput[0].ToString() /* co by nikt nie żartował, że wpisze 10 */))
                {
                case 1:
                    DbBrowser.Browse(ref _mainDb);
                    break;

                case 2:
                    _mainDb.AddMedicine();
                    break;

                case 3:
                    _mainDb.RemoveMedicine();
                    break;

                case 4:
                    _mainDb.SearchMedicine();
                    break;

                case 5:
                    _userDb.ShowUsers();
                    break;

                case 6:
                    _userDb.AddUser();
                    break;

                case 7:
                    _userDb.DeleteUser();
                    break;

                case 8:
                    _userDb.LogoutUser();
                    if (!LogIn())
                    {
                        Environment.Exit((int)Program.ExitCode.Success);
                    }
                    break;
                }
                RenderWelcome();
                MainMenuInputCatch();
            }
            else
            {
                ConsoleGUI.ErrorRender("Niepoprawny wybór, naciśnij Enter by spróbować ponownie");
                Console.ReadLine();
                RenderWelcome();
                MainMenuInputCatch();
            }
        }
Пример #14
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++;
                }
            }
        }
Пример #15
0
        private void mnuExport_Click(object sender, EventArgs e)
        {
            using (TextExporter eDlg = new TextExporter())
            {
                if (eDlg.ShowDialog(this) == DialogResult.OK)
                {
                    using (FolderBrowserDialog dlg = new FolderBrowserDialog())
                    {
                        dlg.Description         = "مسیر خروجیها را انتخاب کنید";
                        dlg.ShowNewFolderButton = true;

                        if (dlg.ShowDialog(this) == DialogResult.OK)
                        {
                            Cursor.Current = Cursors.WaitCursor;
                            this.Enabled   = false;
                            Application.DoEvents();
                            string targetFolder = dlg.SelectedPath;

                            DbBrowser dbBrowser = new DbBrowser();

                            for (int i = 0; i < dbBrowser.Poets.Count; i++)
                            {
                                GanjoorPoet poet = dbBrowser.Poets[i];
                                switch (Settings.Default.ExportLevel)
                                {
                                case "Poet":
                                    ExportPoetToTextFile(poet, targetFolder, dbBrowser);
                                    break;

                                case "Cat":
                                    ExportCatToTextFile(i, dbBrowser.GetCategory(poet._CatID), targetFolder, dbBrowser);
                                    break;

                                default:
                                    ExportCatToTextFile(i, dbBrowser.GetCategory(poet._CatID), targetFolder, dbBrowser, true);
                                    break;
                                }
                            }

                            dbBrowser.CloseDb();

                            Cursor.Current = Cursors.Default;
                            this.Enabled   = true;
                            MessageBox.Show("خروجی تولید شد.", "اعلان", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading | MessageBoxOptions.RightAlign);
                        }
                    }
                }
            }
        }
Пример #16
0
        private bool DownloadList(string url)
        {
            bool reS = true;

            grdList.Rows.Clear();
            Application.DoEvents();
            string strException;

            _Lst = GDBListProcessor.RetrieveList(url, out strException);
            if (_Lst == null)
            {
                _Lst = new List <GDBInfo>();
            }
            if (!string.IsNullOrEmpty(strException))
            {
                MessageBox.Show(strException, "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error);
                reS = false;
            }


            if (_Lst.Count > 0)
            {
                DbBrowser db = new DbBrowser();
                foreach (GDBInfo gdbInfo in _Lst)
                {
                    int  RowIndex = grdList.Rows.Add();
                    bool haveIt   = (db.GetCategory(gdbInfo.CatID) != null);
                    grdList.Rows[RowIndex].Tag = haveIt;
                    if (haveIt)
                    {
                        grdList.Rows[RowIndex].DefaultCellStyle.BackColor = Color.LightGray;
                    }
                    grdList.Rows[RowIndex].Cells[GRDCLMN_CAT].Value   = gdbInfo.CatName;
                    grdList.Rows[RowIndex].Cells[GRDCLMN_DWNLD].Value = "ببینید";
                    if (!string.IsNullOrEmpty(gdbInfo.BlogUrl))
                    {
                        grdList.Rows[RowIndex].Cells[GRDCLMN_MORE].Value = "ببینید";
                    }
                    grdList.FirstDisplayedScrollingRowIndex = RowIndex;
                }
                db.CloseDb();
            }

            return(reS);
        }
Пример #17
0
        public THHelper(int nPoemId = 0)
        {
            Font = Properties.Settings.Default.ViewFont;

            InitializeComponent();

            DbBrowser dbBrowser = new DbBrowser();

            _Verses = dbBrowser.GetVerses(nPoemId);


            dbBrowser.CloseDb();

            if (_Verses.Count > 0)
            {
                lblNextVerse.Text = _Verses[0]._Text;
            }
        }
Пример #18
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);
     }
 }
Пример #19
0
        public THFirstVerse(int nPoemId = 0)
        {
            Font = Properties.Settings.Default.ViewFont;

            InitializeComponent();

            DbBrowser dbBrowser = new DbBrowser();

            var verses = dbBrowser.GetVerses(nPoemId);

            if (verses.Count > 1)
            {
                _firstVerse  = verses[0]._Text;
                _secondVerse = verses[1]._Text;
            }

            lblVerse.Text = _firstVerse;

            dbBrowser.CloseDb();
        }
Пример #20
0
        private bool DRY_ExportCat(DbBrowser dbBrowser, GanjoorCat cat, StringBuilder sb, string catFolderForSeparatePorms = "")
        {
            if (Settings.Default.ExportCatName)
            {
                string catNameSeparator = Settings.Default.ExportCatSep;
                if (!string.IsNullOrEmpty(catNameSeparator))
                {
                    sb.AppendLine(catNameSeparator);
                }
                sb.AppendLine(cat._Text);
                if (!string.IsNullOrEmpty(catNameSeparator))
                {
                    sb.AppendLine(catNameSeparator);
                }
            }

            List <GanjoorPoem> poems = dbBrowser.GetPoems(cat._ID);

            if (poems.Count > 0)
            {
                bool   exportPoemName    = Settings.Default.ExportPoemName;
                string poemNameSeparator = Settings.Default.ExportPoemSep;
                foreach (GanjoorPoem poem in poems)
                {
                    if (!string.IsNullOrEmpty(catFolderForSeparatePorms))
                    {
                        sb = new StringBuilder();
                    }
                    DRY_ExportPoem(dbBrowser, poem, sb, exportPoemName, poemNameSeparator);
                    if (!string.IsNullOrEmpty(catFolderForSeparatePorms))
                    {
                        File.WriteAllText(Path.Combine(catFolderForSeparatePorms, poem._ID.ToString() + ".txt"), sb.ToString());
                    }
                }
                return(true);
            }
            return(false);
        }
Пример #21
0
        private void LoadGridData()
        {
            if (_db == null)
            {
                _db = new DbBrowser();
            }

            _IDs.Clear();
            grdMain.Rows.Clear();

            List <GanjoorPoem> Poems = _db.GetPoems(Settings.Default.LastCat);

            grdMain.SuspendLayout();
            foreach (GanjoorPoem Poem in Poems)
            {
                int rowIndex = grdMain.Rows.Add();

                _IDs.Add(Poem._ID);

                grdMain.Rows[rowIndex].Cells[ClmnID].Value = Poem._ID;

                grdMain.Rows[rowIndex].Cells[ClmnTitle].Value = Poem._Title;

                List <GanjoorVerse> Verses = _db.GetVerses(Poem._ID, 2);
                if (Verses.Count > 0)
                {
                    grdMain.Rows[rowIndex].Cells[ClmnVerse1].Value = Verses[0]._Text;
                }
                if (Verses.Count > 1)
                {
                    grdMain.Rows[rowIndex].Cells[ClmnVerse2].Value = Verses[1]._Text;
                }
            }
            grdMain.ResumeLayout();
            lblPoemCount.Text = String.Format("{0} شعر", grdMain.RowCount);
        }
Пример #22
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;
                }
            }
        }
Пример #23
0
        public ReplaceInDb()
        {
            InitializeComponent();

            _db = new DbBrowser();
        }
Пример #24
0
        //دریافت فهرست
        private async Task <bool> RetrieveList()
        {
            bool reS = true;
            var  r   = await _RetrieveDictionaryListAsync();

            if (!string.IsNullOrEmpty(r.Item2))
            {
                MessageBox.Show(r.Item2, "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error);
                reS = false;
            }
            else
            {
                _Lst = r.Item1;

                DbBrowser db = new DbBrowser();

                //در صورتی که تمام خوانشهای موجود را دریافت می‌کنیم برای تعیین وجود فایل صوتی از روش بهینه‌تری استفاده می‌کنیم.
                PoemAudio[] poemAudios = null;
                if (_PoemId == 0)
                {
                    poemAudios = db.GetAllPoemAudioFiles();
                }

                grdList.Columns.Clear();
                DataTable tbl = new DataTable();
                tbl.Columns.Add("عنوان");
                tbl.Columns.Add("اندازه");
                tbl.Columns.Add("دریافت", typeof(bool));

                int firstSuggestableDownload = -1;
                int idx = -1;

                foreach (Dictionary <string, string> audioInfo in _Lst)
                {
                    idx++;
                    int  nPoemId = Convert.ToInt32(audioInfo["audio_post_ID"]);
                    bool haveIt  =
                        _PoemId == 0 ?
                        poemAudios.Where(p => p.SyncGuid.ToString() == audioInfo["audio_guid"]).FirstOrDefault() != null
                        :
                        db.PoemAudioExists(nPoemId, audioInfo["audio_guid"]);

                    if (!haveIt && firstSuggestableDownload == -1)
                    {
                        firstSuggestableDownload = idx;
                    }

                    tbl.Rows.Add(
                        DownloadableAudioListProcessor.SuggestTitle(audioInfo),
                        (int.Parse(audioInfo["audio_mp3bsize"]) / 1024.0 / 1024.0).ToString("0.00") + " مگابایت",
                        !haveIt
                        );
                }
                db.CloseDb();

                grdList.DataSource = tbl;

                grdList.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
                grdList.Columns[0].FillWeight   = 50;
                grdList.Columns[1].Width        = 110;
                grdList.Columns[2].Width        = 50;

                foreach (DataGridViewRow row in grdList.Rows)
                {
                    row.Tag = !((bool)row.Cells[GRDCLMN_CHECK].Value);
                }
                if (firstSuggestableDownload != -1)
                {
                    grdList.FirstDisplayedScrollingRowIndex = firstSuggestableDownload;
                }
                EnableDownloadCheckedButton();
            }


            return(reS);
        }
Пример #25
0
 public CategorySelector(int PoetID, DbBrowser refDb = null)
 {
     InitializeComponent();
     _RefDb = refDb;
     FillTree(PoetID);
 }
Пример #26
0
 public CategorySelector(DbBrowser refDb = null)
     : this(0, refDb)
 {
     treeCats.CheckBoxes = true;
 }
Пример #27
0
        private void CheckForUpdate(bool Prompt)
        {
            try
            {
                WebRequest req = WebRequest.Create("http://dg.ganjoor.net/version.xml");
                GConnectionManager.ConfigureProxy(ref req);
                using (WebResponse response = req.GetResponse())
                {
                    using (Stream stream = response.GetResponseStream())
                    {
                        using (StreamReader reader = new StreamReader(stream))
                        {
                            XmlDocument doc = new XmlDocument();
                            doc.LoadXml(reader.ReadToEnd());
                            int     MyVersionMajor = Assembly.GetExecutingAssembly().GetName().Version.Major;
                            int     MyVersionMinor = Assembly.GetExecutingAssembly().GetName().Version.Minor;
                            int     VersionMajor   = 0;
                            int     VersionMinor   = 0;
                            string  updateUrl      = string.Empty;
                            XmlNode versionNode    = doc.GetElementsByTagName("Version")[0];
                            foreach (XmlNode Node in versionNode.ChildNodes)
                            {
                                if (Node.Name == "Major")
                                {
                                    VersionMajor = Convert.ToInt32(Node.InnerText);
                                }
                                else
                                if (Node.Name == "Minor")
                                {
                                    VersionMinor = Convert.ToInt32(Node.InnerText);
                                }
                                else
                                if (Node.Name == "UpdateUrl")
                                {
                                    if (string.IsNullOrEmpty(updateUrl))
                                    {
                                        updateUrl = Node.InnerText;
                                    }
                                }
                                else
                                if (Node.Name == "UpdateUrl162Plus")
                                {
                                    updateUrl = Node.InnerText;
                                }
                            }
                            if (VersionMajor == MyVersionMajor && VersionMinor == MyVersionMinor)
                            {
                                if (Prompt)
                                {
                                    MessageBox.Show("شما آخرین ویرایش گنجور رومیزی را در اختیار دارید.", "تبریک", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading | MessageBoxOptions.RightAlign);
                                }
                            }
                            else
                            {
                                if (
                                    MessageBox.Show("ویرایش جدیدتر " + VersionMajor.ToString() + "." + VersionMinor.ToString() + " از نرم‌افزار ارائه شده است. صفحهٔ دریافت باز شود؟ ", "ویرایش جدید", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading | MessageBoxOptions.RightAlign)
                                    ==
                                    DialogResult.Yes
                                    )
                                {
                                    System.Diagnostics.Process.Start(updateUrl);
                                    if (!Prompt)//check for new gdbs
                                    {
                                        return;
                                    }
                                }
                            }
                        }
                    }
                }

                if (!Prompt)//check for new gdbs
                {
                    string         strException;
                    List <GDBInfo> Lst = GDBListProcessor.RetrieveList("http://i.ganjoor.net/android/androidgdbs.xml", out strException);
                    if (Lst != null && string.IsNullOrEmpty(strException))
                    {
                        List <GDBInfo> finalList = new List <GDBInfo>();
                        DbBrowser      db        = new DbBrowser();
                        foreach (GDBInfo gdb in Lst)
                        {
                            if (
                                !db.IsInGDBIgnoreList(gdb.CatID)
                                &&
                                db.GetCategory(gdb.CatID) == null
                                )
                            {
                                finalList.Add(gdb);
                            }
                        }
                        if (finalList.Count > 0)
                        {
                            using (NewGDBFound dlg = new NewGDBFound(finalList))
                            {
                                if (dlg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                                {
                                    using (DownloadingGdbList dwnDlg = new DownloadingGdbList(dlg.dwnldList))
                                        if (dwnDlg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                                        {
                                            foreach (string DownloadedFile in dwnDlg.DownloadedFiles)
                                            {
                                                ImportGdb(DownloadedFile);
                                                if (Settings.Default.DeleteDownloadedFiles)
                                                {
                                                    File.Delete(DownloadedFile);
                                                }
                                            }
                                        }
                                }
                                foreach (int CatID in dlg.IgnoreList)
                                {
                                    db.AddToGDBIgnoreList(CatID);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception exp)
            {
                if (Prompt)
                {
                    MessageBox.Show(exp.Message, "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Пример #28
0
        private void btnFromDb_Click(object sender, EventArgs e)
        {
            using (FolderBrowserDialog dlg = new FolderBrowserDialog())
            {
                dlg.Description         = "مسیر خروجیها را انتخاب کنید";
                dlg.ShowNewFolderButton = true;
                if (dlg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                {
                    bool   embedPictures = false;
                    string picPath       = string.Empty;
                    string picUrPrefix   = string.Empty;
                    using (GDBPictureDirSelector plg = new GDBPictureDirSelector())
                        if (plg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                        {
                            embedPictures = plg.EmbedPictures;
                            picPath       = plg.PicturesPath;
                            picUrPrefix   = plg.PicturesUrlPrefix;
                            if (!Directory.Exists(picPath))
                            {
                                embedPictures = false;
                            }
                        }
                    this.Enabled = false;

                    List <int> existingIDs = new List <int>();
                    foreach (DataGridViewRow Row in grd.Rows)
                    {
                        if (!Row.IsNewRow)
                        {
                            bool    err = false;
                            GDBInfo gdb = ConvertGridRowToGDBInfo(Row, ref err);
                            if (!err)
                            {
                                existingIDs.Add(gdb.PoetID);
                            }
                        }
                    }

                    DbBrowser db = new DbBrowser();
                    foreach (GanjoorPoet Poet in db.Poets)
                    {
                        if (existingIDs.IndexOf(Poet._ID) == -1)//existing items in grid
                        {
                            string outFile = Path.Combine(dlg.SelectedPath, GPersianTextSync.Farglisize(Poet._Name));
                            string gdbFile = outFile + ".gdb";
                            if (db.ExportPoet(gdbFile, Poet._ID))
                            {
                                string zipFile = outFile + ".zip";
                                using (ZipStorer zipStorer = ZipStorer.Create(zipFile, ""))
                                {
                                    zipStorer.AddFile(ZipStorer.Compression.Deflate, gdbFile, Path.GetFileName(gdbFile), "");
                                    if (embedPictures)
                                    {
                                        string pngPath = Path.Combine(picPath, Poet._ID.ToString() + ".png");
                                        if (File.Exists(pngPath))
                                        {
                                            zipStorer.AddFile(ZipStorer.Compression.Deflate, pngPath, Path.GetFileName(pngPath), "");
                                        }
                                    }
                                }
                                File.Delete(gdbFile);
                                int RowIndex = AddGdbOrZipFileToGrid(zipFile);
                                if (embedPictures && !string.IsNullOrEmpty(picUrPrefix))
                                {
                                    string pngPath = Path.Combine(picPath, Poet._ID.ToString() + ".png");
                                    if (File.Exists(pngPath))
                                    {
                                        grd.Rows[RowIndex].Cells[CLMN_IMAGE].Value = picUrPrefix + Path.GetFileName(pngPath);
                                    }
                                }


                                Application.DoEvents();
                            }
                            else
                            {
                                MessageBox.Show(db.LastError);
                            }
                        }
                    }
                    this.Enabled = true;
                    db.CloseDb();
                }
            }
        }
Пример #29
0
        private void ExportCatToTextFile(int nOrder, GanjoorCat cat, string targetFolder, DbBrowser dbBrowser, bool separateFiles = false)
        {
            string catInLatinLetters = (nOrder + 1).ToString("D3") + "-" + GPersianTextSync.Farglisize(cat._Text);

            if (catInLatinLetters.Length > 16)
            {
                catInLatinLetters = catInLatinLetters.Substring(0, 16);
            }
            string catFolder = Path.Combine(targetFolder, catInLatinLetters);

            if (!Directory.Exists(catFolder))
            {
                Directory.CreateDirectory(catFolder);
            }

            StringBuilder sb = new StringBuilder();

            if (DRY_ExportCat(dbBrowser, cat, sb, separateFiles ? catFolder : ""))
            {
                if (!separateFiles)
                {
                    File.WriteAllText(Path.Combine(catFolder, catInLatinLetters + ".txt"), sb.ToString());
                }
            }


            List <GanjoorCat> cats = dbBrowser.GetSubCategories(cat._ID);

            for (int i = 0; i < cats.Count; i++)
            {
                ExportCatToTextFile(i, cats[i], catFolder, dbBrowser, separateFiles);
            }
        }
Пример #30
0
 public NarratedPoems()
 {
     InitializeComponent();
     _DbBrowser   = new DbBrowser();
     SelectedPoem = null;
 }