コード例 #1
0
ファイル: Editor.cs プロジェクト: daravi/ganjoor
        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());
        }
コード例 #2
0
ファイル: Editor.cs プロジェクト: daravi/ganjoor
        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);
            }
        }
コード例 #3
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();
                }
            }
        }