コード例 #1
0
        private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            timer1.Enabled = false;
            mainBody.StopNotice();
            toolStripProgressBar1.Value = toolStripProgressBar1.Maximum;
            ShowStatusMessage("转换完成", false);
            if (this.errorMessages.Length > 0)
            {
                var errForm = new ErrorLogForm(errorMessages);
                errForm.Show();
            }
            if (e.Error != null)
            {
                MessageBox.Show("不好意思,发生了错误:" + e.Error.Message);
                if (e.Error.InnerException != null)
                {
                    RichTextBoxShow(e.Error.InnerException.ToString());
                }
                return;
            }
            if (streamExport && import.IsText)
            {
                ShowStatusMessage("转换完成,词库保存到文件:" + exportPath, true);
                return;
            }
            if (exportDirectly)
            {
                richTextBox1.Text = "为提高处理速度,“高级设置”中选中了“不显示结果,直接导出”,本文本框中不显示转换后的结果,若要查看转换后的结果再确定是否保存请取消该设置。";
            }
            else if (mergeTo1File)
            {
                richTextBox1.Text = fileContent;
                //btnExport.Enabled = true;
            }
            if (!mergeTo1File || export is Win10MsPinyin || export is Win10MsWubi || export is Win10MsPinyinSelfStudy || export is Gboard)//微软拼音是二进制文件,不需要再提示保存
            {
                MessageBox.Show("转换完成!");
                return;
            }
            if (
                MessageBox.Show("是否将导入的" + mainBody.Count + "条词库保存到本地硬盘上?", "是否保存", MessageBoxButtons.YesNo,
                                MessageBoxIcon.Question) == DialogResult.Yes)
            {
                if (!string.IsNullOrEmpty(exportFileName))
                {
                    saveFileDialog1.FileName = exportFileName;
                }

                else if (export is MsPinyin)
                {
                    saveFileDialog1.DefaultExt = ".dctx";
                    saveFileDialog1.Filter     = "微软拼音2010|*.dctx";
                }
                else
                {
                    saveFileDialog1.DefaultExt = ".txt";
                    saveFileDialog1.Filter     = "文本文件|*.txt";
                }
                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    mainBody.ExportToFile(saveFileDialog1.FileName);

                    ShowStatusMessage("保存成功,词库路径:" + saveFileDialog1.FileName, true);
                }
            }
        }
コード例 #2
0
        private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            timer1.Enabled = false;
            mainBody.StopNotice();
            toolStripProgressBar1.Value = toolStripProgressBar1.Maximum;
            ShowStatusMessage("转换完成", false);
            if (this.errorMessages.Length > 0)
            {
                var errForm = new ErrorLogForm(errorMessages);
                errForm.ShowDialog();
            }
            if (e.Error != null)
            {
                MessageBox.Show("不好意思,发生了错误:" + e.Error.Message, "出错", MessageBoxButtons.OK, MessageBoxIcon.Error);
                if (e.Error.InnerException != null)
                {
                    RichTextBoxShow(e.Error.InnerException.ToString());
                }
                return;
            }
            if (streamExport && import.IsText)
            {
                ShowStatusMessage("转换完成,词库保存到文件:" + exportPath, true);
                return;
            }
            if (exportDirectly)
            {
                richTextBox1.Text = "为提高处理速度,“高级设置”中选中了“不显示结果,直接导出”,本文本框中不显示转换后的结果,若要查看转换后的结果再确定是否保存请取消该设置。";
            }
            else if (mergeTo1File)
            {
                var dataText = string.Join("\r\n", mainBody.ExportContents);
                if (toolStripMenuItemShowLess.Checked && (dataText.Length > 200000))
                {
                    richTextBox1.Text = "为避免输出时卡死,“高级设置”中选中了“结果只显示首、末10万字”,本文本框中不显示转换后的全部结果,若要查看转换后的结果再确定是否保存请取消该设置。\n\n"
                                        + dataText.Substring(0, 100000) + "\n\n\n...\n\n\n" + dataText.Substring(dataText.Length - 100000);
                }
                else if (dataText.Length > 0)
                {
                    richTextBox1.Text = dataText;
                    //btnExport.Enabled = true;
                }
            }
            if (!mergeTo1File || export is Win10MsPinyin || export is Win10MsWubi || export is Win10MsPinyinSelfStudy || export is Gboard)//微软拼音是二进制文件,不需要再提示保存
            {
                MessageBox.Show("转换完成!", "深蓝词库转换", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (mainBody.Count > 0)
            {
                if (MessageBox.Show("是否将导入的" + mainBody.Count + "条词库保存到本地硬盘上?",
                                    "是否保存", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                {
                    return;
                }
                if (!string.IsNullOrEmpty(exportFileName))
                {
                    saveFileDialog1.FileName = exportFileName;
                }

                else if (export is MsPinyin)
                {
                    saveFileDialog1.DefaultExt = ".dctx";
                    saveFileDialog1.Filter     = "微软拼音2010|*.dctx";
                }
                else
                {
                    saveFileDialog1.DefaultExt = ".txt";
                    saveFileDialog1.Filter     = "文本文件|*.txt";
                }
                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    mainBody.ExportToFile(saveFileDialog1.FileName);

                    ShowStatusMessage("保存成功,词库路径:" + saveFileDialog1.FileName, true);
                }
            }
            else
            {
                MessageBox.Show("转换失败,没有找到词条", "深蓝词库转换", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }