// 获得权限定义表HTML字符串 // parameters: // strSource 可能会包含<readerTypes>和<bookTypes>参数 // librarycodelist 当前用户管辖的分馆代码列表 public static int GetRightTableHtml( // string strSource, XmlDocument cfg_dom_param, // string strLibraryCodeList, List <string> librarycodes, out string strResult, out string strError) { strError = ""; strResult = ""; #if NO XmlDocument cfg_dom = null; if (String.IsNullOrEmpty(strSource) == true) { cfg_dom = this.LibraryCfgDom; } else { cfg_dom = new XmlDocument(); try { cfg_dom.LoadXml("<rightsTable>" + strSource + "</rightsTable>"); } catch (Exception ex) { strError = "strSource内容(外加根元素后)装入XMLDOM时出现错误: " + ex.Message; return(-1); } } List <string> librarycodes = new List <string>(); if (SessionInfo.IsGlobalUser(strLibraryCodeList) == true) { // XML代码中的全部馆代码 librarycodes = GetAllLibraryCode(cfg_dom.DocumentElement); StringUtil.RemoveDupNoSort(ref librarycodes); // 去重 // 读者库中用过的全部馆代码 List <string> temp = GetAllLibraryCode(); if (temp.Count > 0 && temp[0] == "") { librarycodes.Insert(0, ""); } } else { librarycodes = StringUtil.FromListString(strLibraryCodeList); } #endif XmlNode root = cfg_dom_param.DocumentElement.SelectSingleNode("//rightsTable"); if (root == null) { strError = "所提供的读者权限定义XML字符串中不存在<rightsTable>元素"; return(-1); } foreach (string strLibraryCode in librarycodes) { strResult += "<p>" + HttpUtility.HtmlEncode("馆代码 '" + strLibraryCode + "' 的读者权限表") + "</p>"; strResult += "<table style='width:100%;font-size:12pt;border-style:solid;border-width:1pt;border-color:#000000;border-collapse:collapse;border-left-width:1pt;border-top-width:1pt;border-right-width:1pt;border-bottom-width: 1pt;background-color:white;'>"; List <String> readertypes = GetReaderTypes( // cfg_dom, root, strLibraryCode); List <String> booktypes = GetBookTypes( // cfg_dom, root, strLibraryCode); if (readertypes.Count == 0 && booktypes.Count == 0) { // 从<rightsTable>的权限定义代码中(而不是从<readerTypes>和<bookTypes>元素下)获得读者和图书类型列表 GetReaderAndBookTypes( root, // cfg_dom, strLibraryCode, out readertypes, out booktypes); } string strTdStyle = "padding: 4pt;border-left-width: 0pt;border-top-width: 0pt;border-right-width: 0.5pt;border-bottom-width: 0.5pt;border-style: solid;border-color: #aaaaaa;"; booktypes.Insert(0, ""); // 空字符串代表只和读者有关的参数 // 标题 strResult += "<tr>"; strResult += "<td>" + "" + "</td>"; for (int j = 0; j < booktypes.Count; j++) { strResult += "<td style='" + strTdStyle + "'>" + booktypes[j] + "</td>"; } strResult += "</tr>"; for (int i = 0; i < readertypes.Count; i++) { strResult += "<tr>"; // 左边第一列 strResult += "<td style='" + strTdStyle + "'>" + readertypes[i] + "</td>"; // 左边第二列:只和读者类型相关的参数 for (int j = 0; j < booktypes.Count; j++) { string strContent = ""; if (j == 0) { for (int k = 0; k < reader_d_paramnames.Length; k++) { string strParamName = reader_d_paramnames[k]; string strParamValue = ""; string strStyle = ""; MatchResult matchresult; int nRet = LoanParam.GetLoanParam( root, // cfg_dom, strLibraryCode, readertypes[i], booktypes[j], // 实际上为空 strParamName, out strParamValue, out matchresult, out strError); if (nRet == -1) { strStyle = "STYLE=\"background-color:blue;font-weight:bold\""; strContent += "<div " + strStyle + ">" + strParamName + ":" + strError + "</div>"; } else { int r = 200; int g = 200; int b = 200; if ((matchresult & MatchResult.BookType) == MatchResult.BookType) { g += 55; } if ((matchresult & MatchResult.ReaderType) == MatchResult.ReaderType) { r += 55; } Color color = Color.FromArgb(r, g, b); strStyle = "STYLE=\"background-color:" + ColorUtil.Color2String(color) + "\""; strContent += "<div " + strStyle + ">" + strParamName + ": " + strParamValue + "</div>"; } } // end of for } else { for (int k = 0; k < two_d_paramnames.Length; k++) { string strParamName = two_d_paramnames[k]; string strParamValue = ""; string strStyle = ""; MatchResult matchresult; int nRet = LoanParam.GetLoanParam( root, // cfg_dom, strLibraryCode, readertypes[i], booktypes[j], strParamName, out strParamValue, out matchresult, out strError); if (nRet == -1) { strStyle = "STYLE=\"background-color:blue;font-weight:bold\""; strContent += "<div " + strStyle + ">" + strParamName + ":" + strError + "</div>"; } else { int r = 200; int g = 200; int b = 200; if ((matchresult & MatchResult.BookType) == MatchResult.BookType) { g += 55; } if ((matchresult & MatchResult.ReaderType) == MatchResult.ReaderType) { r += 55; } Color color = Color.FromArgb(r, g, b); strStyle = "STYLE=\"background-color:" + ColorUtil.Color2String(color) + "\""; strContent += "<div " + strStyle + ">" + strParamName + ": " + strParamValue + "</div>"; } } // end of for } strResult += "<td style='" + strTdStyle + "'>" + strContent + "</td>"; } strResult += "<tr>"; } strResult += "<tr>"; strResult += "<td style='padding: 4pt;' colspan=" + (booktypes.Count + 1).ToString() + ">"; { string strStyle = ""; string strContent = ""; string strText = ""; strContent = "<div>" + "图例:" + "</div>"; strResult += strContent; strText = "来自缺省值"; Color color = Color.FromArgb(200, 200, 200); strStyle = "STYLE=\"background-color:" + ColorUtil.Color2String(color) + "\""; strContent = "<div " + strStyle + ">" + strText + "</div>"; strResult += strContent; strText = "仅匹配了读者类型"; color = Color.FromArgb(255, 200, 200); strStyle = "STYLE=\"background-color:" + ColorUtil.Color2String(color) + "\""; strContent = "<div " + strStyle + ">" + strText + "</div>"; strResult += strContent; strText = "仅匹配了图书类型"; color = Color.FromArgb(200, 255, 200); strStyle = "STYLE=\"background-color:" + ColorUtil.Color2String(color) + "\""; strContent = "<div " + strStyle + ">" + strText + "</div>"; strResult += strContent; strText = "同时匹配了读者和图书类型"; color = Color.FromArgb(255, 255, 200); strStyle = "STYLE=\"background-color:" + ColorUtil.Color2String(color) + "\""; strContent = "<div " + strStyle + ">" + strText + "</div>"; strResult += strContent; } strResult += "</td>"; strResult += "<tr>"; strResult += "</table>"; strResult += "<br/>"; } return(0); }
protected override void RenderContents(HtmlTextWriter output) { // output.Write(Text); string[] reader_d_paramnames = new string[] { "可借总册数", "可预约册数", "以停代金因子", "工作日历名", }; string[] two_d_paramnames = new string[] { // "可借总册数", "可借册数", "借期", // "可预约册数", // 2007/7/8 "超期违约金因子", "丢失违约金因子", // "工作日历名", }; if (this.App == null) { output.Write("App尚未初始化"); return; } output.Write("<table border='1'>"); List <String> readertypes = this.App.GetReaderTypes(); List <String> booktypes = this.App.GetBookTypes(); booktypes.Insert(0, ""); // 空字符串代表只和读者有关的参数 // 标题 output.Write("<tr>"); output.Write("<td>" + "" + "</td>"); for (int j = 0; j < booktypes.Count; j++) { output.Write("<td>" + booktypes[j] + "</td>"); } output.Write("</tr>"); for (int i = 0; i < readertypes.Count; i++) { output.Write("<tr>"); // 左边第一列 output.Write("<td>" + readertypes[i] + "</td>"); // 左边第二列:只和读者类型相关的参数 for (int j = 0; j < booktypes.Count; j++) { string strContent = ""; string strError = ""; if (j == 0) { for (int k = 0; k < reader_d_paramnames.Length; k++) { string strParamName = reader_d_paramnames[k]; string strParamValue = ""; string strStyle = ""; MatchResult matchresult; int nRet = this.App.GetLoanParam(readertypes[i], booktypes[j], // 实际上为空 strParamName, out strParamValue, out matchresult, out strError); if (nRet == -1) { strStyle = "STYLE=\"background-color:blue;font-weight:bold\""; strContent += "<div " + strStyle + ">" + strParamName + ":" + strError + "</div>"; } else { int r = 200; int g = 200; int b = 200; if ((matchresult & MatchResult.BookType) == MatchResult.BookType) { g += 55; } if ((matchresult & MatchResult.ReaderType) == MatchResult.ReaderType) { r += 55; } Color color = Color.FromArgb(r, g, b); strStyle = "STYLE=\"background-color:" + ColorUtil.Color2String(color) + "\""; strContent += "<div " + strStyle + ">" + strParamName + ": " + strParamValue + "</div>"; } } // end of for } else { for (int k = 0; k < two_d_paramnames.Length; k++) { string strParamName = two_d_paramnames[k]; string strParamValue = ""; string strStyle = ""; MatchResult matchresult; int nRet = this.App.GetLoanParam(readertypes[i], booktypes[j], strParamName, out strParamValue, out matchresult, out strError); if (nRet == -1) { strStyle = "STYLE=\"background-color:blue;font-weight:bold\""; strContent += "<div " + strStyle + ">" + strParamName + ":" + strError + "</div>"; } else { int r = 200; int g = 200; int b = 200; if ((matchresult & MatchResult.BookType) == MatchResult.BookType) { g += 55; } if ((matchresult & MatchResult.ReaderType) == MatchResult.ReaderType) { r += 55; } Color color = Color.FromArgb(r, g, b); strStyle = "STYLE=\"background-color:" + ColorUtil.Color2String(color) + "\""; strContent += "<div " + strStyle + ">" + strParamName + ": " + strParamValue + "</div>"; } } // end of for } output.Write("<td>" + strContent + "</td>"); } output.Write("<tr>"); } output.Write("<tr>"); output.Write("<td colspan=" + (booktypes.Count + 1).ToString() + ">"); { string strStyle = ""; string strContent = ""; string strText = ""; strContent = "<div>" + "图例:" + "</div>"; output.Write(strContent); strText = "来自缺省值"; Color color = Color.FromArgb(200, 200, 200); strStyle = "STYLE=\"background-color:" + ColorUtil.Color2String(color) + "\""; strContent = "<div " + strStyle + ">" + strText + "</div>"; output.Write(strContent); strText = "仅匹配了读者类型"; color = Color.FromArgb(255, 200, 200); strStyle = "STYLE=\"background-color:" + ColorUtil.Color2String(color) + "\""; strContent = "<div " + strStyle + ">" + strText + "</div>"; output.Write(strContent); strText = "仅匹配了图书类型"; color = Color.FromArgb(200, 255, 200); strStyle = "STYLE=\"background-color:" + ColorUtil.Color2String(color) + "\""; strContent = "<div " + strStyle + ">" + strText + "</div>"; output.Write(strContent); strText = "同时匹配了读者和图书类型"; color = Color.FromArgb(255, 255, 200); strStyle = "STYLE=\"background-color:" + ColorUtil.Color2String(color) + "\""; strContent = "<div " + strStyle + ">" + strText + "</div>"; output.Write(strContent); } output.Write("</td>"); output.Write("<tr>"); output.Write("</table>"); }
void ReplaceMacro(ref string strHtml) { strHtml = strHtml.Replace("%backcolor%", ColorUtil.Color2String(this.BackColor)) .Replace("%forecolor%", ColorUtil.Color2String(this.ForeColor)) .Replace("%errorbackcolor%", ColorUtil.Color2String(this.ErrorBackColor)); }