// 回调函数,获得名称的语言字符串 string GetKeyNameCaption(string strID) { if (this.m_facetDom == null) { goto NOTFOUND; } XmlNode node = m_facetDom.DocumentElement.SelectSingleNode("facet[@id='" + strID + "']"); if (node == null) { goto NOTFOUND; } int index = IndexOf(node.ParentNode.ChildNodes, node); string strValue = DomUtil.GetCaption(this.m_strLang, node); if (string.IsNullOrEmpty(strValue) == true) { goto NOTFOUND; } return("{" + index.ToString().PadLeft(2, '0') + "}" + strValue); NOTFOUND: return(strID); }
// 2012/10/25 public List <DbFromInfo> GetFromInfos(string strLang) { List <DbFromInfo> results = new List <DbFromInfo>(); XmlNodeList nodes = this.nodeDatabase.SelectNodes("from"); foreach (XmlNode node in nodes) { string strCaption = DomUtil.GetCaption(strLang, node); if (strCaption == null) { // 如果下面根本没有定义<caption>元素,则采用<from>元素的name属性值 strCaption = DomUtil.GetAttr(node, "name"); if (String.IsNullOrEmpty(strCaption) == true) { continue; // 实在没有,只好舍弃 } } DbFromInfo info = new DbFromInfo(); info.Caption = strCaption; info.Style = DomUtil.GetAttr(node, "style"); results.Add(info); } return(results); }
} // 对应的数据元素名 /* * <editor> * <field element="add1"> * <caption lang="zh">新增字段1</caption> * </field> * <field element="add2"> * <caption lang="zh">新增字段2</caption> * </field> * <field element="add3"> * <caption lang="zh">新增字段3</caption> * </field> * </editor> * */ // 根据 XML 构造列定义 public static List <ColumnInfo> BuildColumnInfoList(string xml, string lang = "zh") { List <ColumnInfo> results = new List <ColumnInfo>(); XmlDocument dom = new XmlDocument(); dom.LoadXml(xml); int index = 0; var nodes = dom.DocumentElement.SelectNodes("field"); foreach (XmlElement element in nodes) { ColumnInfo info = new ColumnInfo(); results.Add(info); info.Caption = DomUtil.GetCaption(lang, element); info.DataElement = element.GetAttribute("element"); int nRet = DomUtil.GetIntegerParam(element, "width", 100, out int value, out string strError); if (nRet == -1) { throw new Exception($"获得 width 属性时出错: {strError}"); } info.PixelWidth = value; info.Index = index++; } return(results); }
// 从配置文件中获得所有 SearchIndex 名称 public List <string> GetSearchIndexNames(string strLang) { List <string> results = new List <string>(); if (this.CfgDom == null || this.CfgDom.DocumentElement == null) { return(results); } // 找到 <searchIndex> 元素 XmlNodeList nodes = this.CfgDom.DocumentElement.SelectNodes("searchIndexCollection/searchIndex"); foreach (XmlNode node in nodes) { XmlElement element = (XmlElement)node; string strName = element.GetAttribute("name"); // 获得特定语言的 Caption string strCaption = DomUtil.GetCaption(strLang, element); if (string.IsNullOrEmpty(strCaption) == false) { strName = strCaption + "\t" + strName; } else { strName = "\t" + strName; } results.Add(strName); } return(results); }
static string GetTitle(string strXmlFileName) { try { XmlDocument dom = new XmlDocument(); try { dom.Load(strXmlFileName); } catch { return(""); } if (dom.DocumentElement == null) { return(""); } XmlNode node = dom.DocumentElement.SelectSingleNode("_title"); if (node == null) { return(""); } return(DomUtil.GetCaption(Lang, node)); } catch (Exception ex) { return(ex.Message); } }
int FillQuickSetMenu(string strFileName, out string strError) { strError = ""; XmlDocument dom = new XmlDocument(); try { dom.Load(strFileName); } catch (Exception ex) { strError = "装载文件 '" + strFileName + "' 时出错: " + ex.Message; return(-1); } XmlNodeList groups = dom.DocumentElement.SelectNodes("groups/group"); foreach (XmlElement group in groups) { string strCaption = DomUtil.GetCaption(this.Lang, group); ToolStripItem item = new ToolStripMenuItem(strCaption); item.Tag = group.GetAttribute("value"); item.Click += item_Click; this.toolStripDropDownButton_quickSet.DropDownItems.Add(item); } return(0); }
public string GetBiblioDbName( string strLang, string strBiblioDbName) { XmlNode node = this.OpacCfgDom.DocumentElement.SelectSingleNode("//biblioDbGroup/database[@biblioDbName='" + strBiblioDbName + "']/biblioDbName"); if (node == null) { // 可能是其他语言的数据库名 XmlNodeList nodes = this.OpacCfgDom.DocumentElement.SelectNodes("//biblioDbGroup/database/biblioDbName/caption"); foreach (XmlNode current_node in nodes) { if (strBiblioDbName == current_node.InnerText.Trim()) { node = current_node.ParentNode; strBiblioDbName = DomUtil.GetAttr(node, "biblioDbName"); } } if (node == null) { return(null); // not found } } return(DomUtil.GetCaption(strLang, node)); }
internal static void FillFieldNameList( string strLang, XmlDocument cfg_dom, List <string> used_fieldnames, ComboBox combobox) { if (cfg_dom == null || cfg_dom.DocumentElement == null) { return; } XmlNodeList nodes = cfg_dom.DocumentElement.SelectNodes("action"); foreach (XmlNode node in nodes) { string strCaption = DomUtil.GetCaption(strLang, node); #if NO if (used_fieldnames != null && used_fieldnames.IndexOf(strCaption) != -1) { continue; } #endif // 比较事项是否等同 if (used_fieldnames != null) { bool bFound = false; foreach (string s in used_fieldnames) { bool bRet = IsEqual(cfg_dom, strCaption, s); if (bRet == true) { bFound = true; break; } } if (bFound == true) { continue; } } combobox.Items.Add(strCaption); } }
// 获得特定语言下的数据库名 public string GetName(string strLang) { /* * * XmlNode node = this.nodeDatabase.SelectSingleNode("caption[@lang='" + strLang + "']"); * if (node == null) * { * string strLangLeft = ""; * string strLangRight = ""; * * SplitLang(strLang, * out strLangLeft, * out strLangRight); * * // 所有<caption>元素 * XmlNodeList nodes = this.nodeDatabase.SelectNodes("caption"); * * for (int i = 0; i < nodes.Count; i++) * { * string strThisLang = DomUtil.GetAttr(nodes[i], "lang"); * * if (strThisLang == strLangLeft) * return nodes[i].InnerText; * } * * node = this.nodeDatabase.SelectSingleNode("caption"); * if (node != null) * return node.InnerText; * return null; // not found * } * * return node.InnerText; */ // 从一个元素的下级<caption>元素中, 提取语言符合的文字值 string strCaption = DomUtil.GetCaption(strLang, this.nodeDatabase); if (String.IsNullOrEmpty(strCaption) == true) { if (IsVirtual == false) { return(DomUtil.GetAttr(this.nodeDatabase, "name")); } } return(strCaption); }
// 获得特定语言下的数据库名 public string GetName(string strLang) { // 从一个元素的下级<caption>元素中, 提取语言符合的文字值 string strCaption = DomUtil.GetCaption(strLang, this.nodeDatabase); if (String.IsNullOrEmpty(strCaption) == true) { if (IsVirtual == false) { return(DomUtil.GetAttr(this.nodeDatabase, "name")); } } return(strCaption); }
// 获得特定语言的下属数据库名 public string GetItemDbName( string strType, string strLang, string strItemDbName) { string strAttrName = ""; if (strType == "item") { strAttrName = "itemDbName"; } else if (strType == "issue") { strAttrName = "issueDbName"; } else if (strType == "order") { strAttrName = "orderDbName"; } else if (strType == "comment") { strAttrName = "commentDbName"; } XmlNode node = this.OpacCfgDom.DocumentElement.SelectSingleNode("//biblioDbGroup/database[@" + strAttrName + "='" + strItemDbName + "']/" + strAttrName); if (node == null) { // 可能是其他语言的数据库名 XmlNodeList nodes = this.OpacCfgDom.DocumentElement.SelectNodes("//biblioDbGroup/database/" + strAttrName + "/caption"); foreach (XmlNode current_node in nodes) { if (strItemDbName == current_node.InnerText.Trim()) { node = current_node.ParentNode; strItemDbName = DomUtil.GetAttr(node, strAttrName); } } if (node == null) { return(null); // not found } } return(DomUtil.GetCaption(strLang, node)); }
/* * <line name="Condition" type="comboBox"> * <item name="value1"> * <caption lang="zh-CN">值1</caption> * </item> * <item name="value2"> * <caption lang="zh-CN">值2</caption> * </item> * </line> * * */ List <ValueItem> GetValueItems(XmlElement parent) { List <ValueItem> results = new List <ValueItem>(); XmlNodeList items = parent.SelectNodes("item"); foreach (XmlNode item in items) { var element = item as XmlElement; ValueItem value = new ValueItem(); value.Name = element.GetAttribute("name"); value.Caption = DomUtil.GetCaption(this.Lang, element); results.Add(value); } return(results); }
// 获得特定语言下的From名称列表 public List <string> GetFroms(string strLang) { List <string> results = new List <string>(); XmlNodeList nodes = this.nodeDatabase.SelectNodes("from"); for (int i = 0; i < nodes.Count; i++) { string strName = DomUtil.GetCaption(strLang, nodes[i]); if (strName == null) { // 如果下面根本没有定义<caption>元素,则采用<from>元素的name属性值 strName = DomUtil.GetAttr(nodes[i], "name"); if (String.IsNullOrEmpty(strName) == true) { continue; // 实在没有,只好舍弃 } } results.Add(strName); } return(results); }
// 从配置文件中获得一个 SearchIndex 名称对应的 Caption public string GetSearchIndexCaption(string strName, string strLang) { if (this.CfgDom == null || this.CfgDom.DocumentElement == null) { return(null); } // 找到 <searchIndex> 元素 XmlNode node = this.CfgDom.DocumentElement.SelectSingleNode("searchIndexCollection/searchIndex[@name='" + strName + "']"); if (node == null) { return(null); } XmlElement element = (XmlElement)node; // 获得特定语言的 Caption return(DomUtil.GetCaption(strLang, element)); }
// 可能会抛出异常 public static List <string> ListAmazonServers(string strDataDir, string strLang) { List <string> results = new List <string>(); string strCfgFileName = Path.Combine(strDataDir, "amazon/amazon.xml"); XmlDocument dom = new XmlDocument(); dom.Load(strCfgFileName); XmlNodeList nodes = dom.DocumentElement.SelectNodes("endpoints/endpoint"); foreach (XmlNode node in nodes) { var element = node as XmlElement; string strHost = element.GetAttribute("host"); string strCaption = DomUtil.GetCaption(strLang, node); results.Add(strCaption + "\t" + strHost); } return(results); }
// 2011/1/2 static string GetBrowseFormatName( XmlNodeList format_nodes, string strName, string strLang) { for (int j = 0; j < format_nodes.Count; j++) { XmlNode node = format_nodes[j]; List <string> captions = GetAllNames(node); if (captions.IndexOf(strName) == -1) { continue; } string strFormatName = DomUtil.GetCaption(strLang, node); if (String.IsNullOrEmpty(strFormatName) == false) { return(strFormatName); } } return(null); // not found }
void FillListView(List <string> results) { string strError = ""; // int nRet = 0; this.listView_list.Items.Clear(); if (results == null || results.Count == 0) { return; } this.listView_list.ListViewItemSorter = new ItemComparer(); foreach (string line in results) { string strRecPath = ""; string strXml = ""; StringUtil.ParseTwoPart(line, "|", out strRecPath, out strXml); XmlDocument dom = new XmlDocument(); try { dom.LoadXml(strXml); } catch (Exception ex) { strError = "XML 装入 DOM 时出错: " + ex.Message; goto ERROR1; } XmlNode node = dom.DocumentElement.SelectSingleNode("key"); string strKey = DomUtil.GetAttr(node, "name"); string strKeyCaption = DomUtil.GetCaption(this.Lang, node); XmlNodeList nodes = dom.DocumentElement.SelectNodes("rel"); foreach (XmlNode rel_node in nodes) { string strRel = DomUtil.GetAttr(rel_node, "name"); string strRelCaption = DomUtil.GetCaption(this.Lang, rel_node); string strWeight = DomUtil.GetAttr(rel_node, "weight"); ListViewItem item = new ListViewItem(); ListViewUtil.ChangeItemText(item, 0, strKey); ListViewUtil.ChangeItemText(item, 1, strKeyCaption); ListViewUtil.ChangeItemText(item, 2, strRel); ListViewUtil.ChangeItemText(item, 3, strWeight); ListViewUtil.ChangeItemText(item, 4, strRelCaption); this.listView_list.Items.Add(item); } } // 按照 weight 排序 // 自动选中第一项 if (this.listView_list.Items.Count > 0) { this.listView_list.Items[0].Selected = true; } return; ERROR1: MessageBox.Show(this, strError); }
// 从特定的数据库中, 匹配出满足特定风格列表的from列表 // parameters: // strFromStyle from style的列表, 以逗号分割。 // 如果为空,表示全部途径(2007/9/13) // return: // null 没有找到 // 以逗号分割的from名列表 public string BuildCaptionListByStyleList( string strFromStyles, string strLang) { if (String.IsNullOrEmpty(strFromStyles) == true || strFromStyles == "<全部>" || strFromStyles.ToLower() == "<all>") { return("<all>"); // strFromStyles = "<all>"; } XmlNodeList nodes = null; string strResult = ""; // 拆分出单独的style字符串 string[] styles = strFromStyles.Split(new char[] { ',' }); for (int i = 0; i < styles.Length; i++) { string strStyle = styles[i].Trim(); if (String.IsNullOrEmpty(strStyle) == true) { continue; } // 忽略 _time/_freetime,_rfc1123time/_utime等表示检索特性的style if (StringUtil.HasHead(strStyle, "_") == true && StringUtil.HasHead(strStyle, "__") == false) { continue; } if (nodes == null) // 滞后获取 { nodes = this.nodeDatabase.SelectNodes("from"); } foreach (XmlNode node in nodes) { string strStyles = DomUtil.GetAttr(node, "style"); if (StringUtil.IsInList(strStyle, strStyles) == true || strStyle == "<all>") // 注:后来发现内核本来就支持<all>的from后,这里就没有必要了,但是代码仍保留 { // 从一个元素的下级<caption>元素中, 提取语言符合的文字值 string strValue = DomUtil.GetCaption(strLang, node); if (strValue == null) { // 只好用中立语言的名字 string strName = DomUtil.GetAttr(node, "name"); if (string.IsNullOrEmpty(strName) == false) { return(strName); } throw new Exception("数据库 '" + this.GetName(strLang) + "' 中没有找到style为 " + strStyles + " 的From事项的任何Caption"); } // 全部路径情况下,要不包含"__id"途径 if (strStyle == "<all>" && strValue == "__id") { continue; } if (strResult != "") { strResult += ","; } strResult += strValue; } } } return(strResult); }
// 获得一些数据库的全部浏览格式配置信息 // parameters: // dbnames 要列出哪些数据库的浏览格式?如果==null, 则表示列出全部可能的格式名 // return: // -1 出错 // >=0 formatname个数 public int GetBrowseFormatNames( string strLang, List <string> dbnames, out List <string> formatnames, out string strError) { strError = ""; formatnames = new List <string>(); XmlNode root = this.OpacCfgDom.DocumentElement.SelectSingleNode("browseformats"); if (root == null) { strError = "<browseformats>元素尚未配置..."; return(-1); } XmlNodeList dbnodes = root.SelectNodes("database"); for (int i = 0; i < dbnodes.Count; i++) { XmlNode nodeDatabase = dbnodes[i]; string strDbName = DomUtil.GetAttr(nodeDatabase, "name"); // dbnames如果==null, 则表示列出全部可能的格式名 if (dbnames != null) { if (dbnames.IndexOf(strDbName) == -1) { continue; } } XmlNodeList nodes = nodeDatabase.SelectNodes("format"); for (int j = 0; j < nodes.Count; j++) { XmlNode node = nodes[j]; string strFormatName = DomUtil.GetCaption(strLang, node); if (String.IsNullOrEmpty(strFormatName) == true) { strFormatName = DomUtil.GetAttr(node, "name"); } /* * if (String.IsNullOrEmpty(strFormatName) == true) * { * strError = "格式配置片断 '" + node.OuterXml + "' 格式不正确..."; * return -1; * }*/ if (formatnames.IndexOf(strFormatName) == -1) { formatnames.Add(strFormatName); } } } bool bMarcVisible = true; XmlNode nodeMarcControl = this.WebUiDom.DocumentElement.SelectSingleNode("marcControl"); if (nodeMarcControl != null) { bMarcVisible = DomUtil.GetBooleanParam(nodeMarcControl, "visible", true); } // 2011/1/2 // 从内置的格式里面找 // TODO: 对一些根本不是MARC格式的数据库,排除"MARC"格式名 { XmlDocument dom = new XmlDocument(); dom.LoadXml(m_strKernelBrowseFomatsXml); XmlNodeList nodes = dom.DocumentElement.SelectNodes("format"); for (int j = 0; j < nodes.Count; j++) { XmlNode node = nodes[j]; string strFormatName = DomUtil.GetCaption(strLang, node); if (String.IsNullOrEmpty(strFormatName) == true) { strFormatName = DomUtil.GetAttr(node, "name"); } // 2012/11/29 if (bMarcVisible == false && strFormatName == "MARC") { continue; } if (formatnames.IndexOf(strFormatName) == -1) { formatnames.Add(strFormatName); } } } return(formatnames.Count); }
// 从配置文件装载字段配置,初始化这些字段 public int LoadConfig(string strFileName, out string strError) { strError = ""; XmlDocument dom = new XmlDocument(); try { dom.Load(strFileName); } catch (Exception ex) { strError = "装入配置文件 '" + strFileName + "' 到 XMLDOM 时出错: " + ex.Message; return(-1); } this._configDom = dom; // 找到当前最后一行有内容的 index int nStart = FindInsertLinePos(); if (nStart == -1) { strError = "FindInsertLinePos() error"; return(-1); } XmlNodeList nodes = dom.DocumentElement.SelectNodes("field"); if (nodes.Count == 0) { return(0); } this.DisableUpdate(); try { this._tableLayoutPanel_main.RowCount += nodes.Count; int nRow = nStart; foreach (XmlElement field in nodes) { string strElement = field.GetAttribute("element"); string strCaption = DomUtil.GetCaption("zh", field); if (string.IsNullOrEmpty(strCaption) == true) { strCaption = strElement; } this._tableLayoutPanel_main.RowStyles.Insert(nRow, new System.Windows.Forms.RowStyle()); Label caption = new Label(); caption.Text = strCaption; caption.TextAlign = ContentAlignment.MiddleLeft; caption.Dock = DockStyle.Fill; Label color = new Label(); color.Dock = DockStyle.Fill; TextBox edit = new TextBox(); edit.Dock = DockStyle.Fill; this._tableLayoutPanel_main.Controls.Add(caption, 0, nRow); this._tableLayoutPanel_main.Controls.Add(color, 1, nRow); this._tableLayoutPanel_main.Controls.Add(edit, 2, nRow); FieldDef def = new FieldDef(); def.Element = strElement; caption.Tag = def; nRow++; } AddEvents(nStart, nRow, true); } finally { this.EnableUpdate(); } return(1); }
IDictionary <string, string> m_oldValues = new ParameterTable(); // 累积保存以前的值 // 构造所有事项 int BuildItems(string strSearchIndex, out string strError) { strError = ""; // 先保存现有的值内容 this.BuildParameterTable(ref m_oldValues); this.Clear(); if (this.CfgDom == null || this.CfgDom.DocumentElement == null) { return(0); } // 找到 <searchIndex> 元素 XmlNode nodeSearchIndex = this.CfgDom.DocumentElement.SelectSingleNode("searchIndexCollection/searchIndex[@name='" + strSearchIndex + "']"); if (nodeSearchIndex == null) { strError = "配置文件中没有找到 name 属性值为 '" + strSearchIndex + "' 的 searchIndexCollection/searchIndex 元素"; return(-1); } // 列出它下面的全部 <line> 元素 XmlNodeList line_nodes = nodeSearchIndex.SelectNodes("line"); if (line_nodes.Count == 0) { return(0); } foreach (XmlNode line_node in line_nodes) { XmlElement def = GetLineDefElement((XmlElement)line_node); if (def == null) { strError = "配置文件中,下列 <line> 元素没有找到 name 属性匹配的 定义元素 lineTypes/line : " + line_node.OuterXml; return(-1); } string strLineType = def.GetAttribute("type"); if (string.IsNullOrEmpty(strLineType) == true) { strLineType = "textBox"; // 缺省为 textBox } ItemType itemType = GetItemType(strLineType); if (itemType == ItemType.None) { strError = "配置文件中使用了未定义的 (<line> 元素) type 属性值 '" + strLineType + "' "; return(-1); } Item item = AppendNewItem(itemType); string strName = def.GetAttribute("name"); item.Name = strName; // 获得特定语言的 Caption string strCaption = DomUtil.GetCaption(this.Lang, def); if (string.IsNullOrEmpty(strCaption) == false) { strName = strCaption; } item.label.Text = strName; // TODO: 设置下拉列表值 List <ValueItem> values = GetValueItems(def); if (values.Count != 0) { item.FillList(values); } // this.Items.Add(item); } // 恢复值内容 if (this.m_oldValues.Count > 0 && this.Items.Count > 0) { RestoreValues(this.m_oldValues); } return(0); }
protected override void Render(HtmlTextWriter output) { string strError = ""; XmlDocument dom = new XmlDocument(); try { dom.Load(this.CfgFile); } catch (Exception ex) { strError = "装载文件 '" + this.CfgFile + "' 时出错: " + ex.Message; goto ERROR1; } // 窗口标题 string strTitle = DomUtil.GetCaption(this.Lang, dom.DocumentElement); if (this.Wrapper == true) { this.Controls.Add(new LiteralControl( this.GetPrefixString( strTitle, "command_wrapper"))); } this.Controls.Add(new LiteralControl("<table class='sidebar'>" )); if (this.LayoutStyle == SideBarLayoutStyle.Horizontal) { this.Controls.Add(new LiteralControl( "<tr>" )); } string strBaseUrl = this.Page.Request.Url.ToString(); HyperLink link = null; List <CompareInfo> compare_infos = new List <CompareInfo>(); XmlNodeList nodes = dom.DocumentElement.SelectNodes("item"); // 挑选出 active node for (int i = 0; i < nodes.Count; i++) { XmlNode nodeItem = nodes[i]; string strUrl = DomUtil.GetAttr(nodeItem, "url"); // 和当前page url比较 string strTestUrl = this.Page.Request.RawUrl; int nRet = CompareUrl(strBaseUrl, strTestUrl, strUrl); if (nRet == -1) { continue; } CompareInfo info = new CompareInfo(); info.Count = nRet; info.Node = nodeItem; compare_infos.Add(info); } compare_infos.Sort(new CountCompare()); XmlNode active_node = null; if (compare_infos.Count > 0) { active_node = compare_infos[compare_infos.Count - 1].Node; } for (int i = 0; i < nodes.Count; i++) { XmlNode nodeItem = nodes[i]; string strUrl = DomUtil.GetAttr(nodeItem, "url"); // 和当前page url比较 string strTestUrl = this.Page.Request.RawUrl; string strTitleString = DomUtil.GetAttr(nodeItem, "title"); if (string.IsNullOrEmpty(strTitleString) == false) { strTitleString = " title='" + HttpUtility.HtmlEncode(strTitleString) + "' "; } // bool bSame = IsUrlEqual(strBaseUrl, strTestUrl, strUrl); string strCssClass = "cmd"; string strClass = DomUtil.GetAttr(nodeItem, "class"); if (string.IsNullOrEmpty(strClass) == false) { strCssClass += " " + strClass; } /* * if (bSame == true) * strCssClass += " active"; * */ if (nodeItem == active_node) { strCssClass += " active"; } if (this.LayoutStyle == SideBarLayoutStyle.Vertical) { this.Controls.Add(new LiteralControl( "<tr><td class='" + strCssClass + "' " + strTitleString + ">" )); } else if (this.LayoutStyle == SideBarLayoutStyle.Horizontal) { this.Controls.Add(new LiteralControl( "<td class='" + strCssClass + "' " + strTitleString + ">" )); } string strItemTitle = DomUtil.GetCaption(this.Lang, nodeItem); link = new HyperLink(); link.Text = strItemTitle; link.NavigateUrl = strUrl; this.Controls.Add(link); XmlNode nodeTips = nodeItem.SelectSingleNode("tips"); if (nodeTips != null) { this.Controls.Add(new LiteralControl( nodeTips.InnerXml)); } if (this.LayoutStyle == SideBarLayoutStyle.Vertical) { this.Controls.Add(new LiteralControl( "</td></tr>" )); } else if (this.LayoutStyle == SideBarLayoutStyle.Horizontal) { this.Controls.Add(new LiteralControl( "</td>" )); } } if (this.LayoutStyle == SideBarLayoutStyle.Horizontal) { this.Controls.Add(new LiteralControl( "</tr>" )); } this.Controls.Add(new LiteralControl( "</table>" )); if (this.Wrapper == true) { this.Controls.Add(new LiteralControl( this.GetPostfixString() )); } base.Render(output); return; ERROR1: this.Controls.Add(new LiteralControl(strError)); base.Render(output); }
protected void Page_Load(object sender, EventArgs e) { #if NO this.LoginControl1.RestorePassword(); if (this.LoginControl1.KeepLogin == false) { this.SetCookiesLogin(null, null, -1, 0); } #endif if (WebUtil.PrepareEnvironment(this, ref app, ref sessioninfo) == false) { return; } string strError = ""; if (this.IsPostBack == false) { string strLibraryCode = this.Request["library"]; if (string.IsNullOrEmpty(strLibraryCode) == false) { // 强制设置图书馆代码 this.TitleBarControl1.SelectedLibraryCode = strLibraryCode; } if (this.Request["action"] == "autologin" || this.Request.Form["action"] == "autologin") { string strUserName = this.Request["username"]; if (string.IsNullOrEmpty(strUserName) == true) { strUserName = this.Request.Form["username"]; } // 2014/6/9 if (string.IsNullOrEmpty(strUserName) == false) { if (strUserName.IndexOf('%') != -1) { strUserName = HttpUtility.UrlDecode(strUserName); } } // 2013/1/23 if (string.IsNullOrEmpty(strUserName) == true) { strError = "username参数不能为空"; goto ERROR1; } // 登录的途径 2013/1/28 string strPrefix = this.Request["prefix"]; if (string.IsNullOrEmpty(strPrefix) == true) { strPrefix = this.Request.Form["prefix"]; } if (string.IsNullOrEmpty(strPrefix) == false) { strUserName = strPrefix + strUserName; } string strPassword = this.Request["password"]; if (string.IsNullOrEmpty(strPassword) == true) { strPassword = this.Request.Form["password"]; } string strUserType = this.Request["usertype"]; if (string.IsNullOrEmpty(strUserType) == true) { strUserType = this.Request.Form["usertype"]; } if (string.IsNullOrEmpty(strUserType) == true) { strUserType = "reader"; // 缺省为reader } // parameters: // strUserName 读者证条码号。或者 "NB:姓名|出生日期(8字符)" "EM:email地址" "TP:电话号码" "ID:身份证号" // strUserType reader/librarian // return: // -1 error // 0 成功 int nRet = this.LoginControl1.DoLogin( strUserName, strPassword, strUserType, this.TitleBarControl1.SelectedLibraryCode, out strError); if (nRet == -1) { return; } // 登录成功后首次设置馆代码 this.TitleBarControl1.SelectedLibraryCode = // sessioninfo.Channel.LibraryCodeList; sessioninfo.LibraryCodeList; if (sessioninfo.LoginCallStack.Count != 0) { string strUrl = (string)sessioninfo.LoginCallStack.Pop(); Redirect(strUrl); } else { string strRedirect = Request.QueryString["redirect"]; if (string.IsNullOrEmpty(strRedirect) == true) { strRedirect = Request.Form["redirect"]; } if (strRedirect == null || strRedirect == "") { LoginState loginstate = GlobalUtil.GetLoginState(this.Page); if (loginstate == LoginState.Public) { Redirect("searchbiblio.aspx"); } else if (loginstate == LoginState.Reader) { Redirect("borrowinfo.aspx"); // 实在没有办法,就到主页面 } else if (loginstate == LoginState.Librarian) { Redirect("searchbiblio.aspx"); } else { Redirect("searchbiblio.aspx"); } } else { Redirect(strRedirect); } } return; } if (this.Request["action"] == "logout") { string strSsoMainPageUrl = (string)this.Session["sso_mainpage_url"]; // 先前用SSO接口登录的,现在要跳转到其登录页面 if (string.IsNullOrEmpty(strSsoMainPageUrl) == false) { Session.Abandon(); this.ClearCookiesLogin("online,token"); Response.Redirect(strSsoMainPageUrl, true); this.Response.End(); return; } { // 判断当前是不是yczb sso状态 HttpCookie cookie = Request.Cookies.Get("iPlanetDirectoryPro"); if (cookie == null) { goto DONE; } string strSsoToken = cookie.Value; if (String.IsNullOrEmpty(strSsoToken) == true) { goto DONE; } string strSsoPageUrl = ""; // return: // -1 error // 0 没有找到 ssoPageUrl 属性 // 1 找到 int nRet = GetYczbLoginPageUrl(out strSsoPageUrl, out strError); if (nRet == -1) { Session.Abandon(); /* * Response.Write(HttpUtility.HtmlEncode(strError)); * this.Response.End(); * return; * */ goto ERROR1; } Session.Abandon(); if (nRet == 1) { Response.Redirect(strSsoPageUrl, true); // 2009/9/24 changed } this.Response.End(); return; } DONE: // LogoutSsoCookie(sessioninfo.UserID); Session.Abandon(); this.ClearCookiesLogin("online,token"); string strPureUserName = ""; string strDomain = ""; bool bRet = ParseUserName(sessioninfo.UserID, out strPureUserName, out strDomain); // 如果是sso登录方式,需要转到相应domain的login.aspx,再做一次logout if (bRet == true && HasConfigDp2Sso() == true) { List <SsoInfo> infos = null; // return: // -1 error // 0 succeed int nRet = GetDp2SSoInfos( strDomain, out infos, out strError); if (nRet == -1) { goto ERROR1; } // 跳转到指定的URL进行登出 if (infos.Count > 0) { string strRedirectUrl = ""; if (sessioninfo.LoginCallStack.Count != 0) { strRedirectUrl = (string)sessioninfo.LoginCallStack.Pop(); } else { strRedirectUrl = Request.QueryString["redirect"]; if (string.IsNullOrEmpty(strRedirectUrl) == true) { strRedirectUrl = Request.Form["redirect"]; } } string strUrl = infos[0].LogoutUrl; strUrl = strUrl.Replace("%redirect%", HttpUtility.UrlEncode(strRedirectUrl)); Response.Redirect(strUrl, true); this.Response.End(); return; } } this.Redirect("login.aspx"); this.Response.End(); return; } if (this.Request["action"] == "ssologin") { string strType = this.Request["type"]; string strSsoLibraryCode = this.Request["library"]; if (string.IsNullOrEmpty(strType) == true) { #if NO // return: // -1 发生错误 // 1 成功 int nRet = DoSsoLogin(strSsoLibraryCode); if (nRet == -1) { return; } #endif throw new Exception("需要创建具体 type 的 SSO 接口"); } else { // return: // -1 发生错误 // 1 成功 int nRet = DoSsoLogin(strSsoLibraryCode, strType); if (nRet == -1) { return; } } Response.End(); return; } // 访客登录 if (this.Request["action"] == "publiclogin") { LoginControl1_AnonymouseLogin(this, new LoginEventArgs()); return; } string strMessage = this.Request.QueryString["message"]; if (String.IsNullOrEmpty(strMessage) == false) { this.LoginControl1.SetDebugInfo(strMessage); } if (String.IsNullOrEmpty(this.Request["loginstyle"]) == false) { this.LoginControl1.LoginStyle = LoginStyle.None; // bool bChanged = false; if (StringUtil.IsInList("librarian", this.Request["loginstyle"], true) == true) { this.LoginControl1.LoginStyle |= LoginStyle.Librarian; // bChanged = true; } if (StringUtil.IsInList("reader", this.Request["loginstyle"], true) == true) { this.LoginControl1.LoginStyle |= LoginStyle.Reader; // bChanged = true; } #if NO if (bChanged == true) { this.LoginControl1.AdjustActiveColumn(); } #endif } else { if (this.IsPostBack == false) { this.GetLoginPanelInfo(this.LoginControl1); } } /* * this.LoginControl1.Title = "数字平台公共查询"; * this.LoginControl1.TitleFontSize = 26.0F; * */ } this.LoginControl1.RestorePassword(); if (this.LoginControl1.KeepLogin == false) { this.SetCookiesLogin(null, null, -1, 0); } if (StringUtil.IsInList("librarian", this.Request["loginstyle"], true) == true) { return; // 不进行后面的IsSso()判断了 } // 优先进行sso登录 string strDp2Sso = Request.QueryString["dp2sso"]; if (HasConfigDp2Sso() == true && strDp2Sso == "first") { List <SsoInfo> infos = null; // return: // -1 error // 0 succeed int nRet = GetDp2SSoInfos( "*", out infos, out strError); if (nRet == -1) { goto ERROR1; } // 跳转到指定的URL进行登录 if (infos.Count > 0) { // TODO: 多于一个要允许选择 string strRedirectUrl = ""; if (sessioninfo.LoginCallStack.Count != 0) { strRedirectUrl = (string)sessioninfo.LoginCallStack.Pop(); } else { strRedirectUrl = Request.QueryString["redirect"]; if (string.IsNullOrEmpty(strRedirectUrl) == true) { strRedirectUrl = Request.Form["redirect"]; } } string strUrl = infos[0].LoginUrl; strUrl = strUrl.Replace("%redirect%", HttpUtility.UrlEncode(strRedirectUrl)); Response.Redirect(strUrl, true); this.Response.End(); return; } } // 在要求统一认证的情况下,需要将页面重定向到统一认证的那个登录页面 if (IsYczbSso() == true) { string strSsoPageUrl = ""; // return: // -1 error // 0 没有找到 ssoPageUrl 属性 // 1 找到 int nRet = GetYczbLoginPageUrl(out strSsoPageUrl, out strError); if (nRet == -1) { goto ERROR1; } if (nRet == 1) { Response.Redirect(strSsoPageUrl, true); // 2009/9/24 changed this.Response.End(); return; } } // 获得图书馆名 设置页面标题 XmlNode node = app.OpacCfgDom.DocumentElement.SelectSingleNode("libraryInfo/libraryName"); if (node != null) { string strCaption = DomUtil.GetCaption(Lang, node); if (string.IsNullOrEmpty(strCaption) == true) { this.Page.Title += " " + node.InnerText; } else { this.Page.Title += " " + strCaption; } } return; ERROR1: Response.Write(HttpUtility.HtmlEncode(strError)); this.Response.End(); }