private void EaccForm_FormClosed(object sender, FormClosedEventArgs e) { if (stop != null) // 脱离关联 { stop.Style = StopStyle.None; // 需要强制中断 stop.DoStop(); stop.Unregister(); // 和容器关联 stop = null; } if (this.MainForm != null && this.MainForm.AppInfo != null) { MainForm.AppInfo.SetString( "eacc_form", "unihan_filename", this.textBox_unihanFilenames.Text); MainForm.AppInfo.SetString( "eacc_form", "e2u_filename", this.textBox_e2uFilename.Text); /* * MainForm.applicationInfo.SetString( * "eacc_form", * "u2e_filename", * this.textBox_u2eFilename.Text); * */ } }
private void DupForm_FormClosed(object sender, FormClosedEventArgs e) { if (stop != null) // 脱离关联 { stop.Unregister(); // 和容器关联 stop = null; } if (this.MainForm != null && this.MainForm.AppInfo != null) { this.MainForm.AppInfo.SetBoolean( "dup_form", "include_low_cols", this.checkBox_includeLowCols.Checked); this.MainForm.AppInfo.SetBoolean( "dup_form", "return_all_records", this.checkBox_returnAllRecords.Checked); this.MainForm.AppInfo.SetString( "dup_form", "projectname", this.comboBox_projectName.Text); string strWidths = ListViewUtil.GetColumnWidthListString(this.listView_browse); this.MainForm.AppInfo.SetString( "dup_form", "browse_list_column_width", strWidths); } this.Channels.BeforeLogin -= new BeforeLoginEventHandle(Channels_BeforeLogin); EventFinish.Set(); }
private void DtlpLogForm_FormClosed(object sender, FormClosedEventArgs e) { if (stop != null) // 脱离关联 { stop.Style = StopStyle.None; // 需要强制中断 stop.DoStop(); stop.Unregister(); // 和容器关联 stop = null; } if (this.MainForm != null && this.MainForm.AppInfo != null) { MainForm.AppInfo.SetString( "dtlplogform", "serveraddr", this.textBox_serverAddr.Text); MainForm.AppInfo.SetString( "dtlplogform", "logfilename", this.textBox_logFileName.Text); } channelArray.AskAccountInfo -= new AskDtlpAccountInfoEventHandle(channelArray_AskAccountInfo); }
private void HtmlPrintForm_FormClosed(object sender, FormClosedEventArgs e) { if (stop != null) // 脱离关联 { stop.Unregister(); // 和容器关联 stop = null; } }
/// <summary> /// 和停止管理器脱离关联 /// </summary> public void FinishStopManager() { if (stop != null) // 脱离关联 { stop.Unregister(); // 和容器关联 stop = null; } }
private void ChangePasswordForm_FormClosed(object sender, FormClosedEventArgs e) { if (stop != null) // 脱离关联 { stop.Unregister(); // 和容器关联 stop = null; } this.Channels.BeforeLogin -= new BeforeLoginEventHandle(Channels_BeforeLogin); }
/// <summary> /// 结束检索 /// </summary> /// <returns>返回 0</returns> int EndSearch() { if (Stop != null) // 脱离关联 { Stop.Unregister(); // 和容器关联 Stop = null; } return(0); }
private void ClockForm_FormClosed(object sender, FormClosedEventArgs e) { #if NO if (stop != null) // 脱离关联 { stop.Unregister(); // 和容器关联 stop = null; } #endif }
private void SelectDictionaryItemDialog_FormClosed(object sender, FormClosedEventArgs e) { // this.ColumnWidthList = ListViewUtil.GetColumnWidthListString(this.listView_list); this.UiStates = GetUiState(); if (_stop != null) // 脱离关联 { _stop.Unregister(); // 和容器关联 _stop = null; } }
private void Iso2709StatisForm_FormClosed(object sender, FormClosedEventArgs e) { #if NO if (stop != null) // 脱离关联 { stop.Unregister(); // 和容器关联 stop = null; } #endif if (Program.MainForm != null && Program.MainForm.AppInfo != null) { // 输入的ISO2709文件名 Program.MainForm.AppInfo.SetString( "iso2709statisform", "input_iso2709_filename", this._openMarcFileDialog.FileName); // 编码方式 Program.MainForm.AppInfo.SetString( "iso2709statisform", "input_iso2709_file_encoding", this._openMarcFileDialog.EncodingName); Program.MainForm.AppInfo.SetString( "iso2709statisform", "input_marc_syntax", this._openMarcFileDialog.MarcSyntax); Program.MainForm.AppInfo.SetBoolean( "iso2709statisform", "input_mode880", this._openMarcFileDialog.Mode880); // 方案名 Program.MainForm.AppInfo.SetString( "iso2709statisform", "projectname", this.textBox_projectName.Text); } #if NO if (this.ErrorInfoForm != null) { try { this.ErrorInfoForm.Close(); } catch { } } #endif }
private void QuickChangeBiblioForm_FormClosed(object sender, FormClosedEventArgs e) { #if NO if (stop != null) // 脱离关联 { stop.Unregister(); // 和容器关联 stop = null; } #endif // 长操作在进行中? }
public void Close() { if (stop != null) // 脱离关联 { stop.Unregister(); // 和容器关联 stop = null; } if (this.Channel != null) { this.Channel.Close(); this.Channel = null; } }
// 在 base.OnFormClosed(e); 之前调用 /// <summary> /// 窗口 Closed 时被触发。在 base.OnFormClosed(e) 之前被调用 /// </summary> public virtual void OnMyFormClosed() { if (stop != null) // 脱离关联 { stop.Unregister(); // 和容器关联 stop = null; } if (this.MainForm != null) { this.MainForm.Move -= new EventHandler(MainForm_Move); } CloseFloatingMessage(); }
private void QuickChangeEntityForm_FormClosed(object sender, FormClosedEventArgs e) { if (this.m_webExternalHost_biblio != null) { this.m_webExternalHost_biblio.Destroy(); } #if NO if (stop != null) // 脱离关联 { stop.Unregister(); // 和容器关联 stop = null; } #endif this.entityEditControl1.GetValueTable -= new GetValueTableEventHandler(entityEditControl1_GetValueTable); }
private void XmlDetailForm_FormClosed(object sender, FormClosedEventArgs e) { if (stop != null) // 脱离关联 { stop.Unregister(); // 和容器关联 stop = null; } SaveSize(); if (this.MainForm != null && this.MainForm.AppInfo != null) { this.MainForm.AppInfo.SetBoolean( "xmldetailform", "need_indent_xml", this.NeedIndentXml); } }
// 在 base.OnFormClosed(e); 之前调用 /// <summary> /// 窗口 Closed 时被触发。在 base.OnFormClosed(e) 之前被调用 /// </summary> public virtual void OnMyFormClosed() { if (this.Channel != null) { this.Channel.BeforeLogin -= new BeforeLoginEventHandle(Channel_BeforeLogin); this.Channel.AfterLogin -= new AfterLoginEventHandle(Channel_AfterLogin); this.Channel.Idle -= Channel_Idle; this.Channel.Close(); // TODO: 最好限制一个时间,超过这个时间则Abort() } if (stop != null) // 脱离关联 { stop.Unregister(); // 和容器关联 stop = null; } // 原来 if (this.MainForm != null) { this.MainForm.Move -= new EventHandler(MainForm_Move); } #if NO if (_floatingMessage != null) { _floatingMessage.Close(); } #endif CloseFloatingMessage(); /* * // 如果MDI子窗口不是MainForm刚刚准备退出时的状态,恢复它。为了记忆尺寸做准备 * if (this.WindowState != this.MainForm.MdiWindowState) * this.WindowState = this.MainForm.MdiWindowState; * */ }
private void PassGateForm_FormClosed(object sender, FormClosedEventArgs e) { this.CloseThread(); if (this.m_webExternalHost != null) { this.m_webExternalHost.Destroy(); } #if NO if (stop != null) // 脱离关联 { stop.Unregister(); // 和容器关联 stop = null; } #endif if (this.MainForm != null && this.MainForm.AppInfo != null) { this.MainForm.AppInfo.SetString( "passgate_form", "gate_name", this.textBox_gateName.Text); this.MainForm.AppInfo.SetBoolean( "passgate_form", "display_reader_detail_info", this.checkBox_displayReaderDetailInfo.Checked); this.MainForm.AppInfo.SetBoolean( "passgate_form", "hide_barcode", this.checkBox_hideBarcode.Checked); this.MainForm.AppInfo.SetBoolean( "passgate_form", "hide_readername", this.checkBox_hideReaderName.Checked); } }
private void EaccForm_FormClosed(object sender, FormClosedEventArgs e) { if (stop != null) // 脱离关联 { stop.DoStop(); stop.Unregister(); // 和容器关联 stop = null; } MainForm.applicationInfo.SetString( "eacc_form", "unihan_filename", this.textBox_unihanFilenames.Text); MainForm.applicationInfo.SetString( "eacc_form", "e2u_filename", this.textBox_e2uFilename.Text); MainForm.applicationInfo.SetString( "eacc_form", "u2e_filename", this.textBox_u2eFilename.Text); }
private void XmlStatisForm_FormClosed(object sender, FormClosedEventArgs e) { #if NO if (stop != null) // 脱离关联 { stop.Unregister(); // 和容器关联 stop = null; } #endif if (this.MainForm != null && this.MainForm.AppInfo != null) { // 输入的条码号文件名 this.MainForm.AppInfo.SetString( "xmlstatisform", "input_xml_filename", this.textBox_inputXmlFilename.Text); // 方案名 this.MainForm.AppInfo.SetString( "xmlstatisform", "projectname", this.textBox_projectName.Text); } #if NO if (this.ErrorInfoForm != null) { try { this.ErrorInfoForm.Close(); } catch { } } #endif }
// 打印解释内容 void menu_printHtml_Click(object sender, EventArgs e) { string strError = ""; if (this.listView_records.SelectedItems.Count == 0) { strError = "尚未选定要打印的行"; goto ERROR1; } List<string> filenames = new List<string>(); string strFileNamePrefix = this.MainForm.DataDir + "\\~operlog_print_"; string strFilename = strFileNamePrefix + (1).ToString() + ".html"; filenames.Add(strFilename); File.Delete(strFilename); StreamUtil.WriteText(strFilename, "<html>" + GetHeadString(false) + "<body>"); Stop stop = new DigitalPlatform.Stop(); stop.Register(MainForm.stopManager, true); // 和容器关联 stop.OnStop += new StopEventHandler(this.DoStopPrint); stop.Initial("正在创建打印页面 ..."); stop.BeginLoop(); m_webExternalHost = new WebExternalHost(); m_webExternalHost.Initial(this.MainForm, null); m_webExternalHost.IsInLoop = true; this.GetSummary += new GetSummaryEventHandler(OperLogForm_GetSummary); try { stop.SetProgressRange(0, this.listView_records.SelectedItems.Count); int i = 0; foreach (ListViewItem item in this.listView_records.SelectedItems) { Application.DoEvents(); if (stop != null && stop.State != 0) { strError = "用户中断"; goto ERROR1; } OperLogItemInfo info = (OperLogItemInfo)item.Tag; string strLogFileName = ListViewUtil.GetItemText(item, COLUMN_FILENAME); string strIndex = ListViewUtil.GetItemText(item, COLUMN_INDEX); string strXml = ""; // 从服务器获得 // return: // -1 出错 // 0 正常 // 1 用户中断 int nRet = GetXml(item, out strXml, out strError); if (nRet == 1) return; if (nRet == -1) goto ERROR1; Global.SetXmlString(this.webBrowser_xml, strXml, this.MainForm.DataDir, "operlogexml"); string strHtml = ""; // 创建解释日志记录内容的 HTML 字符串 // return: // -1 出错 // 0 成功 // 1 未知的操作类型 nRet = GetHtmlString(strXml, false, out strHtml, out strError); if (nRet == -1) goto ERROR1; if (nRet == 1) strHtml = strError; StreamUtil.WriteText(strFilename, "<p class='record_title'>" + strLogFileName + " : " + strIndex + "</p>" + strHtml); stop.SetProgressValue(i + 1); i++; } } finally { this.GetSummary -= new GetSummaryEventHandler(OperLogForm_GetSummary); if (m_webExternalHost != null) { m_webExternalHost.IsInLoop = false; m_webExternalHost.Destroy(); m_webExternalHost = null; } stop.EndLoop(); stop.OnStop -= new StopEventHandler(this.DoStopPrint); stop.Initial("打印页面创建完成"); stop.HideProgress(); if (stop != null) // 脱离关联 { stop.Unregister(); // 和容器关联 stop = null; } } StreamUtil.WriteText(strFilename, "</body></html>"); // TODO: 浏览器控件连接javascript host HtmlPrintForm printform = new HtmlPrintForm(); printform.Text = "打印解释内容"; printform.MainForm = this.MainForm; printform.Filenames = filenames; this.MainForm.AppInfo.LinkFormState(printform, "operlogform_printform_state"); printform.ShowDialog(this); this.MainForm.AppInfo.UnlinkFormState(printform); return; ERROR1: MessageBox.Show(this, strError); }
int ProcessSelectedRecords(Delegate_processLog func, out string strError) { strError = ""; if (this.listView_records.SelectedItems.Count == 0) { strError = "尚未选定要处理的行"; return -1; } Stop stop = new DigitalPlatform.Stop(); stop.Register(MainForm.stopManager, true); // 和容器关联 stop.OnStop += new StopEventHandler(this.DoStopPrint); stop.Initial("正在处理日志记录 ..."); stop.BeginLoop(); try { stop.SetProgressRange(0, this.listView_records.SelectedItems.Count); int i = 0; foreach (ListViewItem item in this.listView_records.SelectedItems) { Application.DoEvents(); if (stop != null && stop.State != 0) { strError = "用户中断"; return -1; } OperLogItemInfo info = (OperLogItemInfo)item.Tag; string strLogFileName = ListViewUtil.GetItemText(item, COLUMN_FILENAME); string strIndex = ListViewUtil.GetItemText(item, COLUMN_INDEX); string strXml = ""; // 从服务器获得 // return: // -1 出错 // 0 正常 // 1 用户中断 int nRet = GetXml(item, out strXml, out strError); if (nRet == 1) return -1; if (nRet == -1) return -1; XmlDocument dom = new XmlDocument(); try { dom.LoadXml(strXml); } catch (Exception ex) { strError = "装载日志记录 '" + strLogFileName + ":" + strIndex + "' XML 到 DOM 时发生错误: " + ex.Message; return -1; } if (func != null) { if (func(strLogFileName, Convert.ToInt32(strIndex), dom, null) == false) break; } stop.SetProgressValue(i + 1); i++; } return 0; } finally { stop.EndLoop(); stop.OnStop -= new StopEventHandler(this.DoStopPrint); stop.Initial("处理完成"); stop.HideProgress(); if (stop != null) // 脱离关联 { stop.Unregister(); // 和容器关联 stop = null; } } }
// 初始化各种参数 bool InitialProperties(bool bFullInitial, bool bRestoreLastOpenedWindow) { int nRet = 0; // 先禁止界面 if (bFullInitial == true) { EnableControls(false); this.MdiClient.Enabled = false; } try { string strError = ""; if (bFullInitial == true) { // this.Logout(); #if NO { FirstRunDialog first_dialog = new FirstRunDialog(); MainForm.SetControlFont(first_dialog, this.DefaultFont); first_dialog.MainForm = this; first_dialog.StartPosition = FormStartPosition.CenterScreen; if (first_dialog.ShowDialog(this) == System.Windows.Forms.DialogResult.Cancel) { Application.Exit(); return; } } #endif bool bFirstDialog = false; // 如果必要,首先出现配置画面,便于配置 dp2library 的 URL string strLibraryServerUrl = this.AppInfo.GetString( "config", "circulation_server_url", ""); if (String.IsNullOrEmpty(strLibraryServerUrl) == true) { // http://stackoverflow.com/questions/860459/determine-os-using-environment-osversion // 判断当前操作系统版本 if (Environment.OSVersion.Version.Major == 5) { #if NO if (Environment.OSVersion.Version.Minor == 1) { // XP } else if (Environment.OSVersion.Version.Minor == 2) { // Server 2003. XP 64-bit will also fall in here. } #endif MessageBox.Show(this, "dp2Circulation 不支持 Windows XP / Windows Server 2003 操作系统版本。请在 Windows Vista 及以上版本安装运行"); Application.Exit(); return false; } else if (Environment.OSVersion.Version.Major >= 6) { // Vista on up } FirstRunDialog first_dialog = new FirstRunDialog(); MainForm.SetControlFont(first_dialog, this.DefaultFont); first_dialog.MainForm = this; first_dialog.StartPosition = FormStartPosition.CenterScreen; if (first_dialog.ShowDialog(this) == System.Windows.Forms.DialogResult.Cancel) { Application.Exit(); return false; } bFirstDialog = true; // 首次写入 运行模式 信息 this.AppInfo.SetString("main_form", "last_mode", first_dialog.Mode); if (first_dialog.Mode == "test") { this.AppInfo.SetString("sn", "sn", "test"); this.AppInfo.Save(); } else if (first_dialog.Mode == "community") { this.AppInfo.SetString("sn", "sn", "community"); this.AppInfo.Save(); } } else { // 以前已经安装的情况 if (Environment.OSVersion.Version.Major == 5) { MessageBox.Show(this, "尊敬的用户,dp2Circulation 在 2015 年 12 月 31 日以后将不再支持 Windows XP / Windows Server 2003 操作系统版本。请尽快升级您的 Windows 操作系统到 Vista 及以上版本。祝工作顺利。\r\n\r\n数字平台敬上"); } } #if NO // 检查序列号。这里的暂时不要求各种产品功能 // DateTime start_day = new DateTime(2014, 10, 15); // 2014/10/15 以后强制启用序列号功能 // if (DateTime.Now >= start_day || IsExistsSerialNumberStatusFile() == true) { // 在用户目录中写入一个隐藏文件,表示序列号功能已经启用 // WriteSerialNumberStatusFile(); nRet = this.VerifySerialCode("", true, out strError); if (nRet == -1) { MessageBox.Show(this, "dp2Circulation 需要先设置序列号才能使用"); Application.Exit(); return false; } } #endif #if SN { _verified = false; nRet = this.VerifySerialCode("", false, out strError); if (nRet == 0) _verified = true; } #else this.MenuItem_resetSerialCode.Visible = false; #endif bool bLogin = this.AppInfo.GetBoolean( "default_account", "occur_per_start", true); if (bLogin == true && bFirstDialog == false) // 首次运行的对话框出现后,登录对话框就不必出现了 { SetDefaultAccount( null, "登录", // "指定缺省帐户", "首次登录", // "请指定后面操作中即将用到的缺省帐户信息。", LoginFailCondition.None, this, false); } else { // 2015/5/15 string strServerUrl = AppInfo.GetString("config", "circulation_server_url", "http://localhost:8001/dp2library"); if (string.Compare(strServerUrl, CirculationLoginDlg.dp2LibraryXEServerUrl, true) == 0) AutoStartDp2libraryXE(); } } nRet = PrepareSearch(); if (nRet == 1) { try { // 2013/6/18 nRet = TouchServer(false); if (nRet == -1) goto END1; // 只有在前一步没有错出的情况下才探测版本号 if (nRet == 0) { // 检查dp2Library版本号 // return: // -1 error // 0 dp2Library的版本号过低。警告信息在strError中 // 1 dp2Library版本号符合要求 nRet = CheckVersion(false, out strError); if (nRet == -1) { MessageBox.Show(this, strError); goto END1; } if (nRet == 0) MessageBox.Show(this, strError); } // 获得书目数据库From信息 nRet = GetDbFromInfos(false); if (nRet == -1) goto END1; // 获得全部数据库的定义 nRet = GetAllDatabaseInfo(false); if (nRet == -1) goto END1; // 获得书目库属性列表 nRet = InitialBiblioDbProperties(false); if (nRet == -1) goto END1; // 获得读者库名列表 /* nRet = GetReaderDbNames(); if (nRet == -1) goto END1; * */ nRet = InitialReaderDbProperties(false); if (nRet == -1) goto END1; nRet = InitialArrivedDbProperties(false); if (nRet == -1) goto END1; // 获得实用库属性列表 nRet = GetUtilDbProperties(false); if (nRet == -1) goto END1; // 2008/11/29 nRet = InitialNormalDbProperties(false); if (nRet == -1) goto END1; // 获得图书馆一般信息 nRet = GetLibraryInfo(false); if (nRet == -1) goto END1; // 获得索取号配置信息 // 2009/2/24 nRet = GetCallNumberInfo(false); if (nRet == -1) goto END1; // 获得前端交费接口配置信息 // 2009/7/20 nRet = GetClientFineInterfaceInfo(false); if (nRet == -1) goto END1; // 获得服务器映射到本地的配置文件 nRet = GetServerMappedFile(false); if (nRet == -1) goto END1; /* // 检查服务器端library.xml中<libraryserver url="???">配置是否正常 // return: // -1 error // 0 正常 // 1 不正常 nRet = CheckServerUrl(out strError); if (nRet != 0) MessageBox.Show(this, strError); * */ // 核对本地和服务器时钟 // return: // -1 error // 0 没有问题 // 1 本地时钟和服务器时钟偏差过大,超过10分钟 strError中有报错信息 nRet = CheckServerClock(false, out strError); if (nRet != 0) MessageBox.Show(this, strError); } finally { EndSearch(); } } // 安装条码字体 InstallBarcodeFont(); END1: Stop = new DigitalPlatform.Stop(); Stop.Register(stopManager, true); // 和容器关联 Stop.SetMessage("正在删除以前遗留的临时文件..."); /* Type: System.UnauthorizedAccessException Message: Access to the path 'D:\System Volume Information\' is denied. Stack: at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileSystemEnumerableIterator`1.CommonInit() at System.IO.FileSystemEnumerableIterator`1..ctor(String path, String originalUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler`1 resultHandler) at System.IO.DirectoryInfo.InternalGetFiles(String searchPattern, SearchOption searchOption) at System.IO.DirectoryInfo.GetFiles() at dp2Circulation.MainForm.DeleteAllTempFiles(String strDataDir) at dp2Circulation.MainForm.DeleteAllTempFiles(String strDataDir) at dp2Circulation.MainForm.InitialProperties(Boolean bFullInitial, Boolean bRestoreLastOpenedWindow) dp2Circulation 版本: dp2Circulation, Version=2.4.5715.19592, Culture=neutral, PublicKeyToken=null 操作系统:Microsoft Windows NT 5.1.2600 Service Pack 3 * * */ try { DeleteAllTempFiles(this.DataDir); } catch (System.UnauthorizedAccessException ex) { MessageBox.Show(this, "在试图删除数据目录 '"+this.DataDir+"' 内临时文件时出错: " + ex.Message + "\r\n\r\n既然您把软件安装到这个目录或者试图从这里运行软件,就该给当前 Windows 用户赋予针对这个目录的列目录和删除文件的权限"); Application.Exit(); return false; } try { DeleteAllTempFiles(this.UserTempDir); } catch (System.UnauthorizedAccessException ex) { MessageBox.Show(this, "在试图删除用户临时目录 '" + this.UserTempDir + "' 内临时文件时出错: " + ex.Message + "\r\n\r\n应给当前 Windows 用户赋予针对这个目录的列目录和删除文件的权限"); Application.Exit(); return false; } Stop.SetMessage("正在复制报表配置文件..."); // 拷贝目录 nRet = PathUtil.CopyDirectory(Path.Combine(this.DataDir, "report_def"), Path.Combine(this.UserDir, "report_def"), false, out strError); if (nRet == -1) MessageBox.Show(this, strError); Stop.SetMessage(""); if (Stop != null) // 脱离关联 { Stop.Unregister(); // 和容器关联 Stop = null; } // 2013/12/4 if (InitialClientScript(out strError) == -1) MessageBox.Show(this, strError); // 初始化历史对象,包括C#脚本 if (this.OperHistory == null) { this.OperHistory = new OperHistory(); nRet = this.OperHistory.Initial(this, this.webBrowser_history, out strError); if (nRet == -1) MessageBox.Show(this, strError); // this.timer_operHistory.Start(); } // if (Program.IsDevelopMode() == true) { // 初始化 MessageHub this.MessageHub = new MessageHub(); this.MessageHub.Initial(this, this.webBrowser_messageHub); } } finally { // 然后许可界面 if (bFullInitial == true) { this.MdiClient.Enabled = true; EnableControls(true); } if (this.m_backgroundForm != null) { // TODO: 最好有个淡出的功能 this.stopManager.OnDisplayMessage += new DisplayMessageEventHandler(stopManager_OnDisplayMessage); this.MdiClient.SizeChanged -= new EventHandler(MdiClient_SizeChanged); this.m_backgroundForm.Close(); this.m_backgroundForm = null; } } if (bRestoreLastOpenedWindow == true) RestoreLastOpenedMdiWindow(); if (bFullInitial == true) { #if NO // 恢复上次遗留的窗口 string strOpenedMdiWindow = this.AppInfo.GetString( "main_form", "last_opened_mdi_window", ""); RestoreLastOpenedMdiWindow(strOpenedMdiWindow); #endif // 初始化指纹高速缓存 FirstInitialFingerprintCache(); } return true; }
// 为选定的行装入Full元素集的记录 public void ReloadFullElementSet() { string strError = ""; int nRet = 0; ZConnection connection = this.GetCurrentZConnection(); if (connection == null) { strError = "当前ZConnection为空"; goto ERROR1; } if (connection.VirtualItems.SelectedIndices.Count == 0) { strError = "尚未选定要装入完整格式的浏览行"; goto ERROR1; } DigitalPlatform.Stop stop = null; stop = new DigitalPlatform.Stop(); stop.Register(this.MainForm.stopManager, true); // 和容器关联 stop.BeginLoop(); this.EnableControls(false); try { List<int> selected = new List<int>(); selected.AddRange(connection.VirtualItems.SelectedIndices); stop.SetProgressRange(0, selected.Count); for (int i = 0; i < selected.Count; i++) { Application.DoEvents(); // 出让界面控制权 if (stop != null) { if (stop.State != 0) { strError = "用户中断"; goto ERROR1; } } int index = selected[i]; stop.SetMessage("正在重新装载记录 "+(index+1).ToString()+" 的详细格式..."); byte[] baTimestamp = null; string strSavePath = ""; string strOutStyle = ""; LoginInfo logininfo = null; long lVersion = 0; string strXmlFragment = ""; DigitalPlatform.Z3950.Record record = null; Encoding currentEncoding = null; string strMARC = ""; nRet = this.GetOneRecord( "marc", index, // 即将废止 "index:" + index.ToString(), "force_full", // false, out strSavePath, out strMARC, out strXmlFragment, out strOutStyle, out baTimestamp, out lVersion, out record, out currentEncoding, out logininfo, out strError); if (nRet == -1) goto ERROR1; stop.SetProgressValue(i); } return; } finally { stop.EndLoop(); stop.SetMessage(""); stop.Unregister(); // 和容器关联 stop = null; this.EnableControls(true); } // return 0; ERROR1: MessageBox.Show(this, strError); }
// 追加保存到数据库 void menu_saveToDatabase_Click(object sender, EventArgs e) { string strError = ""; int nRet = 0; if (this.listView_browse.SelectedIndices.Count == 0) { strError = "尚未选定要保存记录的浏览行"; goto ERROR1; } string strLastSavePath = m_mainForm.LastSavePath; if (String.IsNullOrEmpty(strLastSavePath) == false) { string strOutputPath = ""; nRet = MarcDetailForm.ChangePathToAppendStyle(strLastSavePath, out strOutputPath, out strError); if (nRet == -1) { m_mainForm.LastSavePath = ""; // 避免下次继续出错 goto ERROR1; } strLastSavePath = strOutputPath; } SaveRecordDlg dlg = new SaveRecordDlg(); GuiUtil.SetControlFont(dlg, this.Font); dlg.SaveToDbMode = true; // 不允许在textbox中修改路径 dlg.MainForm = this.m_mainForm; dlg.GetDtlpSearchParam += new GetDtlpSearchParamEventHandle(dlg_GetDtlpSearchParam); dlg.GetDp2SearchParam += new GetDp2SearchParamEventHandle(dlg_GetDp2SearchParam); { dlg.RecPath = strLastSavePath; dlg.Text = "请选择目标数据库"; } // dlg.StartPosition = FormStartPosition.CenterScreen; this.MainForm.AppInfo.LinkFormState(dlg, "SaveRecordDlg_state"); dlg.UiState = this.MainForm.AppInfo.GetString("AmazonSearchForm", "SaveRecordDlg_uiState", ""); dlg.ShowDialog(this); this.MainForm.AppInfo.SetString("AmazonSearchForm", "SaveRecordDlg_uiState", dlg.UiState); if (dlg.DialogResult != DialogResult.OK) return; m_mainForm.LastSavePath = dlg.RecPath; string strProtocol = ""; string strPath = ""; nRet = Global.ParsePath(dlg.RecPath, out strProtocol, out strPath, out strError); if (nRet == -1) goto ERROR1; bool bForceFull = false; if (HasSelectionContainBriefRecords() == true) { DialogResult result = MessageBox.Show(this, "即将保存的记录中有Brief(简要)格式的记录,是否在保存前重新获取为Full(完整)格式的记录?\r\n\r\n(Yes: 是,要完整格式的记录; No: 否,依然保存简明格式的记录; Cancel: 取消,放弃整个保存操作", "AmazonSearchForm", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (result == System.Windows.Forms.DialogResult.Cancel) return; if (result == System.Windows.Forms.DialogResult.Yes) bForceFull = true; } // 首先获得详细记录 if (bForceFull == true) { ReloadFullElementSet(); bool bError = WaitSearchFinish(); } // TODO: 禁止问号以外的其它ID DigitalPlatform.Stop stop = null; stop = new DigitalPlatform.Stop(); stop.Register(m_mainForm.stopManager, true); // 和容器关联 stop.BeginLoop(); this.EnableControls(false); try { // dtlp协议的记录保存 if (strProtocol.ToLower() == "dtlp") { DtlpSearchForm dtlp_searchform = this.GetDtlpSearchForm(); if (dtlp_searchform == null) { strError = "没有连接的或者打开的DTLP检索窗,无法保存记录"; goto ERROR1; } for (int i = 0; i < this.listView_browse.SelectedIndices.Count; i++) { Application.DoEvents(); // 出让界面控制权 if (stop != null) { if (stop.State != 0) { strError = "用户中断"; goto ERROR1; } } int index = this.listView_browse.SelectedIndices[i]; byte[] baTimestamp = null; string strSavePath = ""; string strOutStyle = ""; LoginInfo logininfo = null; long lVersion = 0; string strXmlFragment = ""; DigitalPlatform.Z3950.Record record = null; Encoding currentEncoding = null; string strMARC = ""; nRet = this.GetOneRecord( "marc", index, // 即将废止 "index:" + index.ToString(), bForceFull == true ? "force_full" : "", // false, out strSavePath, out strMARC, out strXmlFragment, out strOutStyle, out baTimestamp, out lVersion, out record, out currentEncoding, out logininfo, out strError); if (nRet == -1) goto ERROR1; string strMarcSyntax = ""; if (record.m_strSyntaxOID == "1.2.840.10003.5.1") strMarcSyntax = "unimarc"; if (record.m_strSyntaxOID == "1.2.840.10003.5.10") strMarcSyntax = "usmarc"; // TODO: 有些格式不适合保存到目标数据库 byte[] baOutputTimestamp = null; string strOutputPath = ""; nRet = dtlp_searchform.SaveMarcRecord( strPath, strMARC, baTimestamp, out strOutputPath, out baOutputTimestamp, out strError); if (nRet == -1) goto ERROR1; } MessageBox.Show(this, "保存成功"); return; } else if (strProtocol.ToLower() == "dp2library") { dp2SearchForm dp2_searchform = this.GetDp2SearchForm(); if (dp2_searchform == null) { strError = "没有连接的或者打开的dp2检索窗,无法保存记录"; goto ERROR1; } string strDp2ServerName = ""; string strPurePath = ""; // 解析记录路径。 // 记录路径为如下形态 "中文图书/1 @服务器" dp2SearchForm.ParseRecPath(strPath, out strDp2ServerName, out strPurePath); string strTargetMarcSyntax = ""; try { NormalDbProperty prop = dp2_searchform.GetDbProperty(strDp2ServerName, dp2SearchForm.GetDbName(strPurePath)); strTargetMarcSyntax = prop.Syntax; if (string.IsNullOrEmpty(strTargetMarcSyntax) == true) strTargetMarcSyntax = "unimarc"; } catch (Exception ex) { strError = "在获得目标库特性时出错: " + ex.Message; goto ERROR1; } bool bSkip = false; int nSavedCount = 0; for (int i = 0; i < this.listView_browse.SelectedIndices.Count; i++) { Application.DoEvents(); // 出让界面控制权 if (stop != null) { if (stop.State != 0) { strError = "用户中断"; goto ERROR1; } } int index = this.listView_browse.SelectedIndices[i]; byte[] baTimestamp = null; string strSavePath = ""; string strOutStyle = ""; LoginInfo logininfo = null; long lVersion = 0; string strXmlFragment = ""; DigitalPlatform.Z3950.Record record = null; Encoding currentEncoding = null; string strMARC = ""; nRet = this.GetOneRecord( "marc", index, // 即将废止 "index:" + index.ToString(), bForceFull == true ? "force_full" : "", // false, out strSavePath, out strMARC, out strXmlFragment, out strOutStyle, out baTimestamp, out lVersion, out record, out currentEncoding, out logininfo, out strError); if (nRet == -1) goto ERROR1; string strMarcSyntax = ""; if (record.m_strSyntaxOID == "1.2.840.10003.5.1") strMarcSyntax = "unimarc"; if (record.m_strSyntaxOID == "1.2.840.10003.5.10") strMarcSyntax = "usmarc"; // 有些格式不适合保存到目标数据库 if (strTargetMarcSyntax != strMarcSyntax) { if (bSkip == true) continue; strError = "记录 " + (index + 1).ToString() + " 的格式类型为 '" + strMarcSyntax + "',和目标库的格式类型 '" + strTargetMarcSyntax + "' 不符合,因此无法保存到目标库"; DialogResult result = MessageBox.Show(this, strError + "\r\n\r\n要跳过这些记录而继续保存后面的记录么?\r\n\r\n(Yes: 跳过格式不吻合的记录,继续保存后面的; No: 放弃整个保存操作)", "AmazonSearchForm", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (result == System.Windows.Forms.DialogResult.No) goto ERROR1; bSkip = true; continue; } string strProtocolPath = this.CurrentProtocol + ":" + this.CurrentResultsetPath + "/" + (index + 1).ToString(); string strOutputPath = ""; byte[] baOutputTimestamp = null; string strComment = "copy from " + strProtocolPath; // strSavePath; // return: // -2 timestamp mismatch // -1 error // 0 succeed nRet = dp2_searchform.SaveMarcRecord( false, strPath, strMARC, strMarcSyntax, baTimestamp, strXmlFragment, strComment, out strOutputPath, out baOutputTimestamp, out strError); if (nRet == -1) goto ERROR1; nSavedCount++; } MessageBox.Show(this, "共保存记录 " + nSavedCount.ToString() + " 条"); return; } else if (strProtocol.ToLower() == "z3950") { strError = "目前暂不支持Z39.50协议的保存操作"; goto ERROR1; } else { strError = "无法识别的协议名 '" + strProtocol + "'"; goto ERROR1; } } finally { stop.EndLoop(); stop.Unregister(); // 和容器关联 stop = null; this.EnableControls(true); } // return 0; ERROR1: MessageBox.Show(this, strError); }
// 汉字字符串转换为拼音 // 如果函数中已经MessageBox报错,则strError第一字符会为空格 // return: // -1 出错 // 0 用户希望中断 // 1 正常 public int SmartHanziTextToPinyin( string strText, PinyinStyle style, out string strPinyin, out string strError) { strPinyin = ""; strError = ""; Stop new_stop = new DigitalPlatform.Stop(); new_stop.Register(MainForm.stopManager, true); // 和容器关联 new_stop.OnStop += new StopEventHandler(new_stop_OnStop); new_stop.Initial("正在获得 '" + strText + "' 的拼音信息 (从服务器 " + this.MainForm.PinyinServerUrl + ")..."); new_stop.BeginLoop(); m_gcatClient = null; try { m_gcatClient = GcatNew.CreateChannel(this.MainForm.PinyinServerUrl); REDO_GETPINYIN: int nStatus = -1; // 前面一个字符的类型 -1:前面没有字符 0:普通英文字母 1:空格 2:汉字 string strPinyinXml = ""; // return: // -2 strID验证失败 // -1 出错 // 0 成功 int nRet = GcatNew.GetPinyin( new_stop, m_gcatClient, m_strPinyinGcatID, strText, out strPinyinXml, out strError); if (nRet == -1) { DialogResult result = MessageBox.Show(this, "从服务器 '" + this.MainForm.PinyinServerUrl + "' 获取拼音的过程出错:\r\n" + strError + "\r\n\r\n是否要临时改为使用本机加拼音功能? \r\n\r\n(注:临时改用本机拼音的状态在程序退出时不会保留。如果要永久改用本机拼音方式,请使用主菜单的“参数配置”命令,将“服务器”属性页的“拼音服务器URL”内容清空)", "EntityForm", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (result == System.Windows.Forms.DialogResult.Yes) { this.MainForm.ForceUseLocalPinyinFunc = true; strError = "将改用本机拼音,请重新操作一次。(本次操作出错: " + strError + ")"; return -1; } strError = " " + strError; return -1; } if (nRet == -2) { IdLoginDialog login_dlg = new IdLoginDialog(); login_dlg.Text = "获得拼音 -- " + ((string.IsNullOrEmpty(this.m_strPinyinGcatID) == true) ? "请输入ID" : strError); login_dlg.ID = this.m_strPinyinGcatID; login_dlg.SaveID = this.m_bSavePinyinGcatID; login_dlg.StartPosition = FormStartPosition.CenterScreen; if (login_dlg.ShowDialog(this) == DialogResult.Cancel) { return 0; } this.m_strPinyinGcatID = login_dlg.ID; this.m_bSavePinyinGcatID = login_dlg.SaveID; goto REDO_GETPINYIN; } XmlDocument dom = new XmlDocument(); try { dom.LoadXml(strPinyinXml); } catch (Exception ex) { strError = "strPinyinXml装载到XMLDOM时出错: " + ex.Message; return -1; } foreach (XmlNode nodeWord in dom.DocumentElement.ChildNodes) { if (nodeWord.NodeType == XmlNodeType.Text) { SelPinyinDlg.AppendText(ref strPinyin, nodeWord.InnerText); nStatus = 0; continue; } if (nodeWord.NodeType != XmlNodeType.Element) continue; string strWordPinyin = DomUtil.GetAttr(nodeWord, "p"); if (string.IsNullOrEmpty(strWordPinyin) == false) strWordPinyin = strWordPinyin.Trim(); // 目前只取多套读音的第一套 nRet = strWordPinyin.IndexOf(";"); if (nRet != -1) strWordPinyin = strWordPinyin.Substring(0, nRet).Trim(); string[] pinyin_parts = strWordPinyin.Split(new char[] { ' ' }); int index = 0; // 让选择多音字 foreach (XmlNode nodeChar in nodeWord.ChildNodes) { if (nodeChar.NodeType == XmlNodeType.Text) { SelPinyinDlg.AppendText(ref strPinyin, nodeChar.InnerText); nStatus = 0; continue; } string strHanzi = nodeChar.InnerText; string strCharPinyins = DomUtil.GetAttr(nodeChar, "p"); if (String.IsNullOrEmpty(strCharPinyins) == true) { strPinyin += strHanzi; nStatus = 0; index++; continue; } if (strCharPinyins.IndexOf(";") == -1) { DomUtil.SetAttr(nodeChar, "sel", strCharPinyins); SelPinyinDlg.AppendPinyin(ref strPinyin, SelPinyinDlg.ConvertSinglePinyinByStyle( strCharPinyins, style) ); nStatus = 2; index++; continue; } #if _TEST_PINYIN // 调试! string[] parts = strCharPinyins.Split(new char[] {';'}); { DomUtil.SetAttr(nodeChar, "sel", parts[0]); AppendPinyin(ref strPinyin, parts[0]); nStatus = 2; index++; continue; } #endif string strSampleText = ""; int nOffs = -1; SelPinyinDlg.GetOffs(dom.DocumentElement, nodeChar, out strSampleText, out nOffs); { // 如果是多个拼音 SelPinyinDlg dlg = new SelPinyinDlg(); float ratio_single = dlg.listBox_multiPinyin.Font.SizeInPoints / dlg.Font.SizeInPoints; float ratio_sample = dlg.textBox_sampleText.Font.SizeInPoints / dlg.Font.SizeInPoints; GuiUtil.SetControlFont(dlg, this.Font, false); // 维持字体的原有大小比例关系 dlg.listBox_multiPinyin.Font = new Font(dlg.Font.FontFamily, ratio_single * dlg.Font.SizeInPoints, GraphicsUnit.Point); dlg.textBox_sampleText.Font = new Font(dlg.Font.FontFamily, ratio_sample * dlg.Font.SizeInPoints, GraphicsUnit.Point); // 这个对话框比较特殊 GuiUtil.SetControlFont(dlg, this.Font, false); dlg.Text = "请选择汉字 '" + strHanzi + "' 的拼音 (来自服务器 " + this.MainForm.PinyinServerUrl + ")"; dlg.SampleText = strSampleText; dlg.Offset = nOffs; dlg.Pinyins = strCharPinyins; if (index < pinyin_parts.Length) dlg.ActivePinyin = pinyin_parts[index]; dlg.Hanzi = strHanzi; MainForm.AppInfo.LinkFormState(dlg, "SelPinyinDlg_state"); dlg.ShowDialog(this); MainForm.AppInfo.UnlinkFormState(dlg); Debug.Assert(DialogResult.Cancel != DialogResult.Abort, "推断"); if (dlg.DialogResult == DialogResult.Abort) { return 0; // 用户希望整个中断 } DomUtil.SetAttr(nodeChar, "sel", dlg.ResultPinyin); if (dlg.DialogResult == DialogResult.Cancel) { SelPinyinDlg.AppendText(ref strPinyin, strHanzi); nStatus = 2; } else if (dlg.DialogResult == DialogResult.OK) { SelPinyinDlg.AppendPinyin(ref strPinyin, SelPinyinDlg.ConvertSinglePinyinByStyle( dlg.ResultPinyin, style) ); nStatus = 2; } else { Debug.Assert(false, "SelPinyinDlg返回时出现意外的DialogResult值"); } index++; } } } #if _TEST_PINYIN #else // return: // -2 strID验证失败 // -1 出错 // 0 成功 nRet = GcatNew.SetPinyin( new_stop, m_gcatClient, "", dom.DocumentElement.OuterXml, out strError); if (nRet == -1) return -1; #endif return 1; } finally { new_stop.EndLoop(); new_stop.OnStop -= new StopEventHandler(new_stop_OnStop); new_stop.Initial(""); new_stop.Unregister(); if (m_gcatClient != null) { m_gcatClient.Close(); m_gcatClient = null; } } }
private void button_test_channelAttack_Click(object sender, EventArgs e) { _stop = new DigitalPlatform.Stop(); _stop.Register(this.MainForm.stopManager, true); // 和容器关联 _stop.OnStop += new StopEventHandler(this.DoStop); _stop.Style = StopStyle.EnableHalfStop; _stop.Initial("正在测试耗费通道 ..."); _stop.BeginLoop(); this.button_test_channelAttack.Enabled = false; this.numericUpDown_test_tryChannelCount.Enabled = false; try { for (int i = 0; i < this.numericUpDown_test_tryChannelCount.Value; i++ ) { Application.DoEvents(); if (_stop != null && _stop.State != 0) break; LibraryChannel channel = new LibraryChannel(); channel.Url = this.MainForm.LibraryServerUrl; channel.BeforeLogin -= new DigitalPlatform.CirculationClient.BeforeLoginEventHandle(Channel_BeforeLogin); channel.BeforeLogin += new DigitalPlatform.CirculationClient.BeforeLoginEventHandle(Channel_BeforeLogin); string strValue = ""; string strError = ""; long lRet = channel.GetSystemParameter(_stop, "library", "name", out strValue, out strError); #if NO if (lRet == -1) { if (channel.ErrorCode == DigitalPlatform.CirculationClient.localhost.ErrorCode.OutofSession) break; } #endif _stop.SetMessage(i.ToString()); } } finally { this.numericUpDown_test_tryChannelCount.Enabled = true; this.button_test_channelAttack.Enabled = true; _stop.EndLoop(); _stop.OnStop -= new StopEventHandler(this.DoStop); _stop.Initial(""); if (_stop != null) // 脱离关联 { _stop.Unregister(); // 和容器关联 _stop = null; } } }
private void button_test_loginAttack_Click(object sender, EventArgs e) { LibraryChannel channel = new LibraryChannel(); channel.Url = this.MainForm.LibraryServerUrl; channel.BeforeLogin -= new DigitalPlatform.CirculationClient.BeforeLoginEventHandle(Channel_BeforeLogin); channel.BeforeLogin += new DigitalPlatform.CirculationClient.BeforeLoginEventHandle(Channel_BeforeLogin); _stop = new DigitalPlatform.Stop(); _stop.Register(this.MainForm.stopManager, true); // 和容器关联 _stop.OnStop += new StopEventHandler(this.DoStop); _stop.Style = StopStyle.EnableHalfStop; _stop.Initial("正在试探密码 ..."); _stop.BeginLoop(); this.button_test_loginAttack.Enabled = false; this.numericUpDown_test_tryChannelCount.Enabled = false; try { for (int i = 0; i < this.numericUpDown_test_tryChannelCount.Value; i++) { Application.DoEvents(); if (_stop != null && _stop.State != 0) break; string strUserName = "******"; string strPassword = i.ToString(); string strRights = ""; string strLibraryCode = ""; string strOutputUserName = ""; string strError = ""; long lRet = channel.Login( strUserName, strPassword, "", out strOutputUserName, out strRights, out strLibraryCode, out strError); #if NO if (lRet == -1) { if (channel.ErrorCode == DigitalPlatform.CirculationClient.localhost.ErrorCode.OutofSession) break; } #endif _stop.SetMessage(i.ToString() + " username="******" password="******" lRet = " + lRet.ToString() + " " + strError); } } finally { this.numericUpDown_test_tryChannelCount.Enabled = true; this.button_test_loginAttack.Enabled = true; _stop.EndLoop(); _stop.OnStop -= new StopEventHandler(this.DoStop); _stop.Initial(""); if (_stop != null) // 脱离关联 { _stop.Unregister(); // 和容器关联 _stop = null; } } }
// 注: Stop 的使用有 Bug 2016/6/28 int RunScript(string strProjectName, string strProjectLocate, out string strError) { EnableControls(false); #if NO // BUG!!! Stop = new DigitalPlatform.Stop(); Stop.Register(stopManager, true); // 和容器关联 #endif this.Stop.OnStop += new StopEventHandler(this.DoStop); this.Stop.Initial("正在执行脚本 ..."); this.Stop.BeginLoop(); _dllPaths.Clear(); _dllPaths.Add(strProjectLocate); AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve); try { int nRet = 0; strError = ""; this.objStatis = null; this.AssemblyMain = null; // 2009/11/5 // 防止以前残留的打开的文件依然没有关闭 Global.ForceGarbageCollection(); nRet = PrepareScript(strProjectName, strProjectLocate, out objStatis, out strError); if (nRet == -1) { goto ERROR1; } objStatis.ProjectDir = strProjectLocate; // objStatis.Console = this.Console; // 执行脚本的Main() if (objStatis != null) { EventArgs args = new EventArgs(); objStatis.Main(this, args); } return(0); ERROR1: return(-1); } catch (Exception ex) { strError = "脚本 '" + strProjectName + "' 执行过程抛出异常: \r\n" + ExceptionUtil.GetDebugText(ex); return(-1); } finally { this.Stop.EndLoop(); this.Stop.OnStop -= new StopEventHandler(this.DoStop); this.Stop.Initial(""); this.AssemblyMain = null; #if NO // BUG!!! if (Stop != null) // 脱离关联 { Stop.Unregister(); // 和容器关联 Stop = null; } #endif EnableControls(true); AppDomain.CurrentDomain.AssemblyResolve -= new ResolveEventHandler(CurrentDomain_AssemblyResolve); } }
// 汉字字符串转换为拼音。新版本 // 如果函数中已经MessageBox报错,则strError第一字符会为空格 /// <summary> /// 汉字字符串转换为拼音,智能方式 /// </summary> /// <param name="owner">用于函数中 MessageBox 和对话框 的宿主窗口</param> /// <param name="strText">输入字符串</param> /// <param name="style">转换为拼音的风格</param> /// <param name="strDuoyinStyle">是否自动选择多音字。auto/first 的一个或者组合。如果为 auto,first 表示优先按照智能拼音选择,没有智能拼音的,选择第一个</param> /// <param name="strPinyin">返回拼音字符串</param> /// <param name="strError">返回出错信息</param> /// <returns>-1: 出错; 0: 用户希望中断; 1: 正常; 2: 结果字符串中有没有找到拼音的汉字</returns> public int SmartHanziTextToPinyin( IWin32Window owner, string strText, PinyinStyle style, string strDuoyinStyle, // bool bAutoSel, out string strPinyin, out string strError) { strPinyin = ""; strError = ""; bool bAuto = StringUtil.IsInList("auto", strDuoyinStyle); bool bFirst = StringUtil.IsInList("first", strDuoyinStyle); bool bNotFoundPinyin = false; // 是否出现过没有找到拼音、只能把汉字放入结果字符串的情况 Stop new_stop = new DigitalPlatform.Stop(); new_stop.Register(this.stopManager, true); // 和容器关联 new_stop.OnStop += new StopEventHandler(new_stop_OnStop); new_stop.Initial("正在获得 '" + strText + "' 的拼音信息 (从服务器 " + this.PinyinServerUrl + ")..."); new_stop.BeginLoop(); m_gcatClient = null; try { m_gcatClient = GcatNew.CreateChannel(this.PinyinServerUrl); REDO_GETPINYIN: //int nStatus = -1; // 前面一个字符的类型 -1:前面没有字符 0:普通英文字母 1:空格 2:汉字 string strPinyinXml = ""; // return: // -2 strID验证失败 // -1 出错 // 0 成功 int nRet = GcatNew.GetPinyin( new_stop, m_gcatClient, m_strPinyinGcatID, strText, out strPinyinXml, out strError); if (nRet == -1) { if (new_stop != null && new_stop.State != 0) return 0; DialogResult result = MessageBox.Show(owner, "从服务器 '" + this.PinyinServerUrl + "' 获取拼音的过程出错:\r\n" + strError + "\r\n\r\n是否要临时改为使用本机加拼音功能? \r\n\r\n(注:临时改用本机拼音的状态在程序退出时不会保留。如果要永久改用本机拼音方式,请使用主菜单的“参数配置”命令,将“服务器”属性页的“拼音服务器URL”内容清空)", "EntityForm", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (result == System.Windows.Forms.DialogResult.Yes) { this.ForceUseLocalPinyinFunc = true; strError = "将改用本机拼音,请重新操作一次。(本次操作出错: " + strError + ")"; return -1; } strError = " " + strError; return -1; } if (nRet == -2) { IdLoginDialog login_dlg = new IdLoginDialog(); login_dlg.Text = "获得拼音 -- " + ((string.IsNullOrEmpty(this.m_strPinyinGcatID) == true) ? "请输入ID" : strError); login_dlg.ID = this.m_strPinyinGcatID; login_dlg.SaveID = this.m_bSavePinyinGcatID; login_dlg.StartPosition = FormStartPosition.CenterScreen; if (login_dlg.ShowDialog(owner) == DialogResult.Cancel) { return 0; } this.m_strPinyinGcatID = login_dlg.ID; this.m_bSavePinyinGcatID = login_dlg.SaveID; goto REDO_GETPINYIN; } XmlDocument dom = new XmlDocument(); try { dom.LoadXml(strPinyinXml); } catch (Exception ex) { strError = "strPinyinXml装载到XMLDOM时出错: " + ex.Message; return -1; } foreach (XmlNode nodeWord in dom.DocumentElement.ChildNodes) { if (nodeWord.NodeType == XmlNodeType.Text) { SelPinyinDlg.AppendText(ref strPinyin, nodeWord.InnerText); //nStatus = 0; continue; } if (nodeWord.NodeType != XmlNodeType.Element) continue; string strWordPinyin = DomUtil.GetAttr(nodeWord, "p"); if (string.IsNullOrEmpty(strWordPinyin) == false) strWordPinyin = strWordPinyin.Trim(); // 目前只取多套读音的第一套 nRet = strWordPinyin.IndexOf(";"); if (nRet != -1) strWordPinyin = strWordPinyin.Substring(0, nRet).Trim(); string[] pinyin_parts = strWordPinyin.Split(new char[] { ' ' }); int index = 0; // 让选择多音字 foreach (XmlNode nodeChar in nodeWord.ChildNodes) { if (nodeChar.NodeType == XmlNodeType.Text) { SelPinyinDlg.AppendText(ref strPinyin, nodeChar.InnerText); //nStatus = 0; continue; } string strHanzi = nodeChar.InnerText; string strCharPinyins = DomUtil.GetAttr(nodeChar, "p"); if (String.IsNullOrEmpty(strCharPinyins) == true) { strPinyin += strHanzi; //nStatus = 0; index++; continue; } if (strCharPinyins.IndexOf(";") == -1) { DomUtil.SetAttr(nodeChar, "sel", strCharPinyins); SelPinyinDlg.AppendPinyin(ref strPinyin, SelPinyinDlg.ConvertSinglePinyinByStyle( strCharPinyins, style) ); //nStatus = 2; index++; continue; } #if _TEST_PINYIN // 调试! string[] parts = strCharPinyins.Split(new char[] {';'}); { DomUtil.SetAttr(nodeChar, "sel", parts[0]); AppendPinyin(ref strPinyin, parts[0]); nStatus = 2; index++; continue; } #endif string strSampleText = ""; int nOffs = -1; SelPinyinDlg.GetOffs(dom.DocumentElement, nodeChar, out strSampleText, out nOffs); { // 如果是多个拼音 SelPinyinDlg dlg = new SelPinyinDlg(); //float ratio_single = dlg.listBox_multiPinyin.Font.SizeInPoints / dlg.Font.SizeInPoints; //float ratio_sample = dlg.textBox_sampleText.Font.SizeInPoints / dlg.Font.SizeInPoints; MainForm.SetControlFont(dlg, this.Font, false); // 维持字体的原有大小比例关系 //dlg.listBox_multiPinyin.Font = new Font(dlg.Font.FontFamily, ratio_single * dlg.Font.SizeInPoints, GraphicsUnit.Point); //dlg.textBox_sampleText.Font = new Font(dlg.Font.FontFamily, ratio_sample * dlg.Font.SizeInPoints, GraphicsUnit.Point); // 这个对话框比较特殊 MainForm.SetControlFont(dlg, this.Font, false); dlg.Text = "请选择汉字 '" + strHanzi + "' 的拼音 (来自服务器 " + this.PinyinServerUrl + ")"; dlg.SampleText = strSampleText; dlg.Offset = nOffs; dlg.Pinyins = strCharPinyins; if (index < pinyin_parts.Length) dlg.ActivePinyin = pinyin_parts[index]; dlg.Hanzi = strHanzi; #if NO if (bAutoSel == true && string.IsNullOrEmpty(dlg.ActivePinyin) == false) { dlg.ResultPinyin = dlg.ActivePinyin; dlg.DialogResult = DialogResult.OK; } else { this.AppInfo.LinkFormState(dlg, "SelPinyinDlg_state"); dlg.ShowDialog(owner); this.AppInfo.UnlinkFormState(dlg); } #endif if (bAuto == true && string.IsNullOrEmpty(dlg.ActivePinyin) == false) { dlg.ResultPinyin = dlg.ActivePinyin; dlg.DialogResult = DialogResult.OK; } else if (bFirst == true && string.IsNullOrEmpty(dlg.Pinyins) == false) { dlg.ResultPinyin = SelPinyinDlg.GetFirstPinyin(dlg.Pinyins); dlg.DialogResult = DialogResult.OK; } else { this.AppInfo.LinkFormState(dlg, "SelPinyinDlg_state"); dlg.ShowDialog(owner); this.AppInfo.UnlinkFormState(dlg); } Debug.Assert(DialogResult.Cancel != DialogResult.Abort, "推断"); if (dlg.DialogResult == DialogResult.Abort) { return 0; // 用户希望整个中断 } DomUtil.SetAttr(nodeChar, "sel", dlg.ResultPinyin); if (dlg.DialogResult == DialogResult.Cancel) { SelPinyinDlg.AppendText(ref strPinyin, strHanzi); //nStatus = 2; bNotFoundPinyin = true; } else if (dlg.DialogResult == DialogResult.OK) { SelPinyinDlg.AppendPinyin(ref strPinyin, SelPinyinDlg.ConvertSinglePinyinByStyle( dlg.ResultPinyin, style) ); //nStatus = 2; } else { Debug.Assert(false, "SelPinyinDlg返回时出现意外的DialogResult值"); } index++; } } } #if _TEST_PINYIN #else // 2014/10/22 // 删除 word 下的 Text 节点 XmlNodeList text_nodes = dom.DocumentElement.SelectNodes("word/text()"); foreach (XmlNode node in text_nodes) { Debug.Assert(node.NodeType == XmlNodeType.Text, ""); node.ParentNode.RemoveChild(node); } // 把没有p属性的<char>元素去掉,以便上传 XmlNodeList nodes = dom.DocumentElement.SelectNodes("//char"); foreach (XmlNode node in nodes) { string strP = DomUtil.GetAttr(node, "p"); string strSelValue = DomUtil.GetAttr(node, "sel"); // 2013/9/13 if (string.IsNullOrEmpty(strP) == true || string.IsNullOrEmpty(strSelValue) == true) { XmlNode parent = node.ParentNode; parent.RemoveChild(node); // 把空的<word>元素删除 if (parent.Name == "word" && parent.ChildNodes.Count == 0 && parent.ParentNode != null) { parent.ParentNode.RemoveChild(parent); } } // TODO: 一个拼音,没有其他选择的,是否就不上载了? // 注意,前端负责新创建的拼音仍需上载;只是当初原样从服务器过来的,不用上载了 } if (dom.DocumentElement.ChildNodes.Count > 0) { // return: // -2 strID验证失败 // -1 出错 // 0 成功 nRet = GcatNew.SetPinyin( new_stop, m_gcatClient, "", dom.DocumentElement.OuterXml, out strError); if (nRet == -1) { if (new_stop != null && new_stop.State != 0) return 0; return -1; } } #endif if (bNotFoundPinyin == false) return 1; // 正常结束 return 2; // 结果字符串中有没有找到拼音的汉字 } finally { new_stop.EndLoop(); new_stop.OnStop -= new StopEventHandler(new_stop_OnStop); new_stop.Initial(""); new_stop.Unregister(); if (m_gcatClient != null) { m_gcatClient.Close(); m_gcatClient = null; } } }