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()); }
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); } }
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(); } }
private void txtHighlight_TextChanged(object sender, EventArgs e) { if (processTextChanged) { iLastFoundItems = ganjoorView.HighlightText(GPersianTextSync.Sync(txtHighlight.Text)); iLastHighlightedFoundItem = 0; if (lblFoundItemCount.Visible = !string.IsNullOrEmpty(txtHighlight.Text)) { lblFoundItemCount.Text = String.Format("{0} مورد یافت شد.", iLastFoundItems); } btnScrollToNext.Visible = iLastFoundItems > 1; } }
private void btnGroupNaming_Click(object sender, EventArgs e) { bool bPrefix = MessageBox.Show("آیا تمایل دارید این نام به عنوان پیشوند به عنوان فعلی اضافه شود (در غیر این صورت عنوان فعلی حذف میشود)؟", "تأییدیه", MessageBoxButtons.YesNo) == DialogResult.Yes; if (MessageBox.Show("آیا از ادامهٔ عملیات اطمینان دارید؟", "تأییدیه", MessageBoxButtons.YesNo) == DialogResult.No) { return; } _db.BeginBatchOperation(); int nNum = 0; foreach (DataGridViewRow Row in grdMain.Rows) { nNum++; string newTitle = $"شمارهٔ { GPersianTextSync.Sync(nNum.ToString())}"; if (bPrefix) { string title = Row.Cells[ClmnTitle].Value.ToString().Trim(); string verse1 = Row.Cells[ClmnVerse1].Value.ToString().Trim(); if (title == verse1) { title = ""; } if (title.StartsWith("شمارهٔ ")) { if (title.IndexOf(" - ") != -1) { title = title.Substring(title.IndexOf(" - ") + " - ".Length); newTitle = $"{newTitle} - {title}"; } } else if (!string.IsNullOrEmpty(title)) { newTitle = $"{newTitle} - {Row.Cells[ClmnTitle].Value}"; } } _db.SetPoemTitle(Convert.ToInt32(Row.Cells[ClmnID].Value), newTitle); } _db.CommitBatchOperation(); LoadGridData(); }
private void btnScrollToNext_Click(object sender, EventArgs e) { iLastHighlightedFoundItem++; ganjoorView.HighlightText(GPersianTextSync.Sync(txtHighlight.Text), iLastHighlightedFoundItem); btnScrollToNext.Visible = (iLastHighlightedFoundItem + 1 < iLastFoundItems); }
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(); } } }