/// <summary> /// 退出浏览器控件 /// </summary> public void ExitWebBrowser() { if (this.m_webExternalHost != null) { this.m_webExternalHost.Destroy(); this.m_webExternalHost.Dispose(); this.m_webExternalHost = null; } }
/// <summary> /// 初始化浏览器控件 /// </summary> public void InitialWebBrowser() { this.m_webExternalHost = new WebExternalHost(); this.m_webExternalHost.IsBelongToHoverWindow = true; // 表示自己就是hover窗口 // webbrowser this.m_webExternalHost.Initial(this.MainForm, this.webBrowser_html); this.webBrowser_html.ObjectForScripting = this.m_webExternalHost; }
// 根据读者证条码号,装入读者记录 // parameters: // edit 读者编辑控件。可以==null // webbHtml 用于显示HTML的WebBrowser控件。可以==null // webbXml 用于显示XML的WebBrowser控件。可以==null // return: // 0 cancelled internal int LoadRecord(ref string strBarcode, ReaderEditControl edit, WebExternalHost external_html, // WebBrowser webbHtml, WebBrowser webbXml) { string strError = ""; int nRet = 0; if (edit != null && edit.Changed == true) { // 警告尚未保存 DialogResult result = MessageBox.Show(this, "当前有信息被修改后尚未保存。若此时装载新内容,现有未保存信息将丢失。\r\n\r\n确实要根据证条码号重新装载内容? ", "ActivateForm", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (result != DialogResult.Yes) return 0; // cancelled } stop.OnStop += new StopEventHandler(this.DoStop); stop.Initial("正在初始化浏览器组件 ..."); stop.BeginLoop(); this.Update(); this.MainForm.Update(); EnableControls(false); if (edit != null) edit.Clear(); #if NO if (webbHtml != null) { Global.ClearHtmlPage(webbHtml, this.MainForm.DataDir); } #endif if (external_html != null) { external_html.ClearHtmlPage(); } if (webbXml != null) { Global.ClearHtmlPage(webbXml, this.MainForm.DataDir); } try { byte[] baTimestamp = null; string strRecPath = ""; int nRedoCount = 0; REDO: stop.SetMessage("正在装入读者记录 " + strBarcode + " ..."); string[] results = null; long lRet = Channel.GetReaderInfo( stop, strBarcode, "xml,html", out results, out strRecPath, out baTimestamp, out strError); if (lRet == -1) goto ERROR1; if (lRet == 0) goto ERROR1; if (lRet > 1) { // 如果重试后依然发生重复 if (nRedoCount > 0) { strError = "条码 " + strBarcode + " 命中记录 " + lRet.ToString() + " 条,放弃装入读者记录。\r\n\r\n注意这是一个严重错误,请系统管理员尽快排除。"; goto ERROR1; // 当出错处理 } SelectPatronDialog dlg = new SelectPatronDialog(); dlg.Overflow = StringUtil.SplitList(strRecPath).Count < lRet; nRet = dlg.Initial( this.MainForm, this.Channel, this.stop, StringUtil.SplitList(strRecPath), "请选择一个读者记录", out strError); if (nRet == -1) goto ERROR1; // TODO: 保存窗口内的尺寸状态 this.MainForm.AppInfo.LinkFormState(dlg, "ActivateForm_SelectPatronDialog_state"); dlg.ShowDialog(this); this.MainForm.AppInfo.UnlinkFormState(dlg); if (dlg.DialogResult == System.Windows.Forms.DialogResult.Cancel) { strError = "放弃选择"; return 0; } strBarcode = dlg.SelectedBarcode; nRedoCount++; goto REDO; } // this.ReaderBarcode = strBarcode; if (results == null || results.Length < 2) { strError = "返回的results不正常。"; goto ERROR1; } string strXml = ""; strXml = results[0]; string strHtml = results[1]; if (edit != null) { nRet = edit.SetData( strXml, strRecPath, baTimestamp, out strError); if (nRet == -1) goto ERROR1; } if (webbXml != null) { /* SetXmlToWebbrowser(webbXml, strXml); * */ Global.SetXmlToWebbrowser(webbXml, this.MainForm.DataDir, "xml", strXml); } // this.m_strSetAction = "change"; #if NO if (webbHtml != null) { Global.SetHtmlString(webbHtml, strHtml, this.MainForm.DataDir, "activateform_html"); } #endif if (external_html != null) external_html.SetHtmlString(strHtml, "activateform_html"); } finally { EnableControls(true); stop.EndLoop(); stop.OnStop -= new StopEventHandler(this.DoStop); stop.Initial(""); } return 1; ERROR1: MessageBox.Show(this, strError); return -1; }
// 打印解释内容 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); }
/// <summary> /// 关闭当前对象。包括关闭通讯通道 /// </summary> public void Close() { #if USE_THREAD this.StopThread(false); #endif if (this.m_webExternalHost != null) { this.m_webExternalHost.Destroy(); this.m_webExternalHost.Dispose(); this.m_webExternalHost = null; } #if USE_LOCAL_CHANNEL if (this.Channel != null) { this.Channel.Close(); this.Channel = null; } #endif }
// 根据读者证条码号,装入读者记录 // parameters: // edit 读者编辑控件。可以==null // webbHtml 用于显示HTML的WebBrowser控件。可以==null // webbXml 用于显示XML的WebBrowser控件。可以==null // return: // 0 cancelled internal int LoadRecord(ref string strBarcode, ReaderEditControl edit, WebExternalHost external_html, // WebBrowser webbHtml, WebBrowser webbXml) { string strError = ""; int nRet = 0; if (edit != null && edit.Changed == true) { // 警告尚未保存 DialogResult result = MessageBox.Show(this, "当前有信息被修改后尚未保存。若此时装载新内容,现有未保存信息将丢失。\r\n\r\n确实要根据证条码号重新装载内容? ", "ActivateForm", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (result != DialogResult.Yes) { return(0); // cancelled } } stop.OnStop += new StopEventHandler(this.DoStop); stop.Initial("正在初始化浏览器组件 ..."); stop.BeginLoop(); this.Update(); Program.MainForm.Update(); EnableControls(false); if (edit != null) { edit.Clear(); } #if NO if (webbHtml != null) { Global.ClearHtmlPage(webbHtml, Program.MainForm.DataDir); } #endif if (external_html != null) { external_html.ClearHtmlPage(); } if (webbXml != null) { Global.ClearHtmlPage(webbXml, Program.MainForm.DataDir); } try { byte[] baTimestamp = null; string strRecPath = ""; int nRedoCount = 0; REDO: stop.SetMessage("正在装入读者记录 " + strBarcode + " ..."); long lRet = Channel.GetReaderInfo( stop, strBarcode, "xml,html", out string[] results, out strRecPath, out baTimestamp, out strError); if (lRet == -1) { goto ERROR1; } if (lRet == 0) { goto ERROR1; } if (lRet > 1) { // 如果重试后依然发生重复 if (nRedoCount > 0) { strError = "条码 " + strBarcode + " 命中记录 " + lRet.ToString() + " 条,放弃装入读者记录。\r\n\r\n注意这是一个严重错误,请系统管理员尽快排除。"; goto ERROR1; // 当出错处理 } SelectPatronDialog dlg = new SelectPatronDialog(); dlg.Overflow = StringUtil.SplitList(strRecPath).Count < lRet; nRet = dlg.Initial( // Program.MainForm, StringUtil.SplitList(strRecPath), "请选择一个读者记录", out strError); if (nRet == -1) { goto ERROR1; } // TODO: 保存窗口内的尺寸状态 Program.MainForm.AppInfo.LinkFormState(dlg, "ActivateForm_SelectPatronDialog_state"); dlg.ShowDialog(this); Program.MainForm.AppInfo.UnlinkFormState(dlg); if (dlg.DialogResult == System.Windows.Forms.DialogResult.Cancel) { strError = "放弃选择"; return(0); } // strBarcode = dlg.SelectedBarcode; strBarcode = "@path:" + dlg.SelectedRecPath; // 2015/11/16 nRedoCount++; goto REDO; } // this.ReaderBarcode = strBarcode; if (results == null || results.Length < 2) { strError = "返回的results不正常。"; goto ERROR1; } string strXml = ""; strXml = results[0]; string strHtml = results[1]; if (edit != null) { nRet = edit.SetData( strXml, strRecPath, baTimestamp, out strError); if (nRet == -1) { goto ERROR1; } } if (webbXml != null) { /* * SetXmlToWebbrowser(webbXml, * strXml); * */ Global.SetXmlToWebbrowser(webbXml, Program.MainForm.DataDir, "xml", strXml); } // this.m_strSetAction = "change"; #if NO if (webbHtml != null) { Global.SetHtmlString(webbHtml, strHtml, Program.MainForm.DataDir, "activateform_html"); } #endif if (external_html != null) { external_html.SetHtmlString(strHtml, "activateform_html"); } } finally { EnableControls(true); stop.EndLoop(); stop.OnStop -= new StopEventHandler(this.DoStop); stop.Initial(""); } return(1); ERROR1: MessageBox.Show(this, strError); return(-1); }