欢迎您来到 数字平台。 您尚未登录。[登录] [注册新用户]
当前位置: 论坛首页 / 栏目 文档与手册 / 文章 38

点击:1328

[回复顶层(需要先登录)] [表状] [详细]
[回复(需要先登录)] [引用(需要先登录)]普通文章跟帖
文章id: 38
readerxml2html.cs

作者: xietao


该脚本程序的作用是,把XML格式的读者数据创建为HTML格式的文本。用于为流通前端服务的,负责创建读者信息HTML格式的API中。

还需要配套一个readerxml2html.cs.ref的文件。 

ReaderConverter类的数据成员如下:

    public class ReaderConverter
    {
        public LibraryApplication App = null;
        public SessionInfo SessionInfo = null;

        public string[] BorrowedItemBarcodes = null;
        public string CurrentItemBarcode = "";  // 当前正在操作的条码
        public OperType OperType = OperType.None;

    } 

App为图书馆应用对象。

SessionInfo为Session信息对象。

CurrentItemBarcode是当前正在操作的一个册条码。

OperType是操作类型。定义如下:

    public enum OperType
    {
        None = 0,
        Borrow = 1,
        Return = 2,
    }

 ReaderConverter类含有的方法如下:

        public static string LocalTime(string strRfc1123Time)

将RFC1123格式的时间字符串转换为本地时间字符串格式。


        public static string LocalDate(string strRfc1123Time)

将RFC1123格式的时间字符串转为本地日期字符串格式。


        public string GetParam(string strReaderType,
            string strBookType,
            string strParamName)

获得流通读者权限配置参数。

        public bool IsRecentBorrowedItem(string strBarcode)


看看一个条码是否为最近已经借阅过的册条码。该方法是根据BorrowedItemBarcodes成员进行的判断。

~~~

LibraryApplication类的一些函数,也常用到:

        // 获得和一个特定读者类型相关联的日历
        // return:
        //      -1  error
        //      0   succeed
        public int GetReaderCalendar(string strReaderType,
            out Calendar calendar,
            out string strError)

        // 检查超期情况。
        // return:
        //      -1  数据格式错误
        //      0   没有发现超期    strError也有未来到期的提示信息
        //      1   发现超期   strError中有提示信息
        public int CheckPeriod(
            Calendar calendar,
            string strBorrowDate,
            string strPeriod,
            out string strError)

 

readerxml2html.cs样例如下: 

 

using System;
using System.Xml;

using DigitalPlatform.LibraryServer;
using DigitalPlatform.Xml;

public class MyConverter : ReaderConverter
{

 public override string Convert(string strXml)
 {
  XmlDocument dom = new XmlDocument();

  try {
   dom.LoadXml(strXml);
  }
  catch (Exception ex)
  {
   return ex.Message;
  }
  string strLink = "<LINK href='"+App.LibraryServerUrl+"/readerhtml.css' type='text/css' rel='stylesheet'>";

  string strResult = "<html><head>"+strLink+"</head><body>";

  // 左右分布的大表格
  strResult += "<table class='layout' width='100%' cellspacing='0' cellpadding='0'>";
  strResult += "<tr class='content'><td class='left' valign='top'>";

  // 识别信息表格
  strResult += "<table class='readerinfo' width='100%' cellspacing='1' cellpadding='4'>";

  // 标题
  // strResult += "<tr class='columntitle'><td class='name'>名</td><td class='value'>值</td></tr>";

  string strReaderBarcode = DomUtil.GetElementText(dom.DocumentElement, "barcode");

  // 证条码
  strResult += "<tr class='content'><td class='name' nowrap>读者证条码</td><td class='value' nowrap>"
 + strReaderBarcode + "</td><tr>";

  // 读者类别  
  string strReaderType = DomUtil.GetElementText(dom.DocumentElement, "readerType");

  strResult += "<tr class='content'><td class='name' nowrap>读者类别</td><td class='value' nowrap>" + strReaderType + "</td><tr>";

  // 发证日期
  strResult += "<tr class='content'><td class='name' nowrap>发证日期</td><td class='value' nowrap>" + LocalDate(DomUtil.GetElementText(dom.DocumentElement, "createDate")) + "</td><tr>";

  // 失效日期
  strResult += "<tr class='content'><td class='name' nowrap>失效日期</td><td class='value' nowrap>" + LocalDate(DomUtil.GetElementText(dom.DocumentElement, "expireDate")) + "</td><tr>";

  // 姓名
  strResult += "<tr class='content'><td class='name' nowrap>姓名</td><td class='value' nowrap>" + DomUtil.GetElementText(dom.DocumentElement, "name") + "</td><tr>";

  // 证状态
  strResult += "<tr class='content'><td class='name' nowrap>证状态</td><td class='value' nowrap>"
 + DomUtil.GetElementText(dom.DocumentElement, "state") + "</td><tr>";

   strResult += "<tr class='content'><td class='name' nowrap> </td><td class='value'>"
 + "</td><tr>";

  strResult += "</table>";

  strResult += "</td><td class='middle'>&nbsp;";

  strResult += "</td><td class='right'>";


  // 其他信息表格
  strResult += "<table class='readerinfo' width='100%' cellspacing='1' cellpadding='4'>";


  strResult += "<tr class='content'><td class='name' nowrap>性别</td><td class='value' nowrap>"
 + DomUtil.GetElementText(dom.DocumentElement, "gender") + "</td><tr>";

  strResult += "<tr class='content'><td class='name' nowrap>出生日期</td><td class='value' nowrap>"
 + LocalDate(DomUtil.GetElementText(dom.DocumentElement, "birthday")) + "</td><tr>";

  strResult += "<tr class='content'><td class='name' nowrap>身份证号</td><td class='value' nowrap>"
 + DomUtil.GetElementText(dom.DocumentElement, "idCardNumber") + "</td><tr>";

  strResult += "<tr class='content'><td class='name' nowrap>单位</td><td class='value'>"
 + DomUtil.GetElementText(dom.DocumentElement, "department") + "</td><tr>";

  strResult += "<tr class='content'><td class='name' nowrap>地址</td><td class='value'>"
 + DomUtil.GetElementText(dom.DocumentElement, "address") + "</td><tr>";

  strResult += "<tr class='content'><td class='name' nowrap>电话</td><td class='value' nowrap>"
 + DomUtil.GetElementText(dom.DocumentElement, "tel") + "</td><tr>";

  strResult += "<tr class='content'><td class='name' nowrap>Email地址</td><td class='value' nowrap>"
 + DomUtil.GetElementText(dom.DocumentElement, "email") + "</td><tr>";

  strResult += "</table>";

  strResult += "</td></tr>";

  // 注释
  // 表格
  strResult += "<tr class='content'><td colspan='3' class='left' valign='top'>";
  strResult += "<table class='readerinfo' width='100%' cellspacing='1' cellpadding='4'>";

   strResult += "<tr class='content'><td class='name' nowrap>注释</td><td class='value'>"
 + DomUtil.GetElementText(dom.DocumentElement, "comment") + "</td><tr>";
  strResult += "</table>";
  strResult += "</td></tr>";


  // 大表格收尾
  strResult += "</table>";

 

  // 超期记录
  XmlNodeList nodes = dom.DocumentElement.SelectNodes("overdues/overdue");
  
  if (nodes.Count > 0)
  {


  strResult += "超期信息<br/>";
  strResult += "<table class='overdue' width='100%' cellspacing='1' cellpadding='4'>";
  strResult += "<tr class='columntitle'><td>册条码</td><td>超期情况</td><td>罚款额</td><td>借阅日期</td><td>期限</td><td>还书日期</td><td>ID</td></tr>";

  for(int i=0;i<nodes.Count;i++)
  {
   XmlNode node = nodes[i];
   string strBarcode = DomUtil.GetAttr(node, "barcode");
   string strOver = DomUtil.GetAttr(node, "reason");
   string strBorrowDate = LocalTime(DomUtil.GetAttr(node, "borrowDate"));
   string strBorrowPeriod = DomUtil.GetAttr(node, "borrowPeriod");
   string strReturnDate = LocalTime(DomUtil.GetAttr(node, "returnDate"));
   string strID = DomUtil.GetAttr(node, "id");
   string strPrice = DomUtil.GetAttr(node, "price");

                 string strBarcodeLink = "<a href='"+App.LibraryServerUrl+"/book.aspx?barcode=" + strBarcode + "&forcelogin=userid' target='_blank'>" + strBarcode + "</a>";

   strResult += "<tr class='content'>";
   strResult += "<td class='barcode' nowrap>" + strBarcodeLink + "</td>";
   strResult += "<td class='reason' nowrap>" + strOver + "</td>";
   strResult += "<td class='price' nowrap>" + strPrice + "</td>";
   strResult += "<td class='borrowdate' nowrap>" + strBorrowDate + "</td>";
   strResult += "<td class='borrowperiod' nowrap>" + strBorrowPeriod + "</td>";
   strResult += "<td class='returndate' nowrap>" + strReturnDate + "</td>";
   strResult += "<td class='id' nowrap>" + strID + "</td>";
   strResult += "</tr>";
  }
  strResult += "</table>";

  }

  // 获得日历
  string strError = "";
  Calendar calendar = null;
  int nRet = this.App.GetReaderCalendar(strReaderType, out calendar, out strError);
  if (nRet == -1)
  {
   strResult += strError;
   calendar = null;
  }


  // 借阅的册
  strResult += "<br/>借阅信息<br/>";
  strResult += "<table class='borrowinfo' width='100%' cellspacing='1' cellpadding='4'>";
  strResult += "<tr class='columntitle'><td nowrap>册条码</td><td nowrap>续借次</td><td nowrap>借阅日期</td><td nowrap>期限</td><td nowrap>操作者</td><td nowrap>是否超期</td><td nowrap>备注</td></tr>";
  nodes = dom.DocumentElement.SelectNodes("borrows/borrow");
  for(int i=0;i<nodes.Count;i++)
  {
   XmlNode node = nodes[i];
   string strBarcode = DomUtil.GetAttr(node, "barcode");
   string strNo = DomUtil.GetAttr(node, "no");
   string strBorrowDate = DomUtil.GetAttr(node, "borrowDate");
   string strPeriod = DomUtil.GetAttr(node, "borrowPeriod");
   string strOperator = DomUtil.GetAttr(node, "operator");
   string strRenewComment = DomUtil.GetAttr(node, "renewComment");

   string strColor="bgcolor=#ffffff";

   if (strBarcode == this.CurrentItemBarcode)
   {
    strColor = "bgcolor=#ff9999"; // 当前正在借阅的册
   }
   else if (IsRecentBorrowedItem(strBarcode) == true)
   {
    strColor = "bgcolor=#ffff99"; // 先前借阅过的册
   }

 

   string strOverDue = "";
         // 检查超期情况。
          // return:
          //      -1  数据格式错误
          //      0   没有发现超期
          //      1   发现超期   strError中有提示信息
          nRet = App.CheckPeriod(
    calendar,
    strBorrowDate,
    strPeriod,
    out strError);
   if (nRet == -1)
    strOverDue = strError;
   else if (nRet == 1)
    strOverDue = strError; // "已超期";
   else
    strOverDue = strError; // 可能也有一些必要的信息,例如非工作日

                 string strBarcodeLink = "<a href='"+App.LibraryServerUrl+"/book.aspx?barcode=" + strBarcode + "&borrower=" + strReaderBarcode  +"&forcelogin=userid' target='_blank'>" + strBarcode + "</a>";


   strResult += "<tr class='content' "+strColor+" nowrap>";
   strResult += "<td class='barcode' nowrap>" + strBarcodeLink + "</td>";
   strResult += "<td class='no' nowrap align='right'>" + strNo + "</td>";
   strResult += "<td class='borrowdate' >" + LocalTime(strBorrowDate) + "</td>";
   strResult += "<td class='period' nowrap>" + strPeriod + "</td>";
   strResult += "<td class='operator' nowrap>" + strOperator + "</td>";
   strResult += "<td class='overdue' >" + strOverDue + "</td>";
   strResult += "<td class='renewcomment' nowrap>" + strRenewComment.Replace(";", "<br/>") + "</td>";
   strResult += "</tr>";
  }
  
  strResult += "<tr class='content'><td colspan='7'>";

  string strMaxItemCount = GetParam(strReaderType, "", "可借总册数");
  strResult += "最多可借:" + strMaxItemCount + " ";

  int nMax = 0;
  try {
   nMax = System.Convert.ToInt32(strMaxItemCount);
  }
  catch
  {
   strResult += "当前读者 可借总册数 参数 '" + strMaxItemCount + "' 格式错误";
   goto CONTINUE1;
  }

  strResult += "当前可借:" + System.Convert.ToString(nMax - nodes.Count) + "";


  strResult += "</td></tr>";
  strResult += "</table>";

CONTINUE1:


  // 预约请求
  strResult += "<br/>预约请求<br/>";
  strResult += "<table class='reservation' width='100%' cellspacing='1' cellpadding='4'>";
  strResult += "<tr class='columntitle'><td nowrap>册条码</td><td nowrap>到达情况</td><td nowrap>摘要</td><td nowrap>请求日期</td><td nowrap>操作者</td></tr>";
  nodes = dom.DocumentElement.SelectNodes("reservations/request");
  
  for(int i=0;i<nodes.Count;i++)
  {

   XmlNode node = nodes[i];

   string strBarcodes = DomUtil.GetAttr(node, "items");
   string strRequestDate = LocalTime(DomUtil.GetAttr(node, "requestDate"));

   string strOperator = DomUtil.GetAttr(node, "operator");

                 string strSummary = this.App.GetBarcodesSummary(
                     this.SessionInfo,
                     strBarcodes,
    "html,forcelogin",
       "target='_blank'");

   string strClass = "content";

                 // 状态
                 string strArrivedDate = DomUtil.GetAttr(node, "arrivedDate");
                 string strState = DomUtil.GetAttr(node, "state");
                 if (strState == "arrived")
                 {
                     strArrivedDate = ItemConverter.LocalTime(strArrivedDate);
                     strState = "已于 "+strArrivedDate+" 到书";
       strClass = "content_active";
                 }


   strResult += "<tr class='"+strClass+"'>";
   strResult += "<td class='barcode' width='10%'>" + MakeBarcodeListHyperLink(strBarcodes, ", ") + "</td>";
   strResult += "<td class='barcode' width='10%'>" + strState + "</td>";
   strResult += "<td class='summary' width='70%'>" + strSummary + "</td>";
   strResult += "<td class='requestdate' width='5%'>" + strRequestDate + "</td>";
   strResult += "<td class='operator' width='5%'>" + strOperator + "</td>";
   strResult += "</tr>";

  }
  strResult += "</table>";

 

  strResult += "</body></html>";

  return strResult;
 }

        string MakeBarcodeListHyperLink(string strBarcodes,
            string strSep)
        {
            string strResult = "";
            string[] barcodes = strBarcodes.Split(new char[] { ',' });
            for (int i = 0; i < barcodes.Length; i++)
            {
                string strBarcode = barcodes[i];
                if (String.IsNullOrEmpty(strBarcode) == true)
                    continue;

                if (strResult != "")
                    strResult += strSep;
                strResult += "<a href='"+App.LibraryServerUrl+"/book.aspx?barcode=" + strBarcode + "&forcelogin=userid' target='_blank'>"
                    + strBarcode + "</a>";
            }

            return strResult;
        }

}

readerxml2html.cs.ref样例如下:

<?xml version="1.0" encoding="utf-8"?>
<root>
  <ref>system.dll</ref>
  <ref>system.xml.dll</ref>
  <ref>system.windows.forms.dll</ref>
</root>

~~~~~

GetBarcodeSummary()函数有变动,修改后的形式如下:

                 string strSummary = this.App.GetBarcodesSummary(
                     this.SessionInfo,
                     strBarcodes,
    "html,forcelogin",
       "target='_blank'");



发表时间: 2006-12-24 17:08:04
最后修改时间: 2006-12-30 22:30:26



  • 普通文章 dp2图书馆应用服务器参考手册 xietao 2006-12-24 16:18:00[点击:34152]
  • 普通文章 安装 xietao 2006-12-24 16:18:23 (ID:34) [点击:1069]
  • 普通文章 配置circulation.xml xietao 2006-12-24 16:19:34 (ID:36) [点击:1237]
  • 普通文章 cfgs目录下的配置文件 xietao 2006-12-24 16:20:09 (ID:37) [点击:1110]
  • 普通文章 readerxml2html.cs xietao 2006-12-24 17:08:04 (ID:38) [点击:1328]
  • 普通文章 itemxml2html.cs xietao 2006-12-24 17:50:53 (ID:39) [点击:1099]
  • 普通文章 .aspx命令参数规范 xietao 2006-12-25 11:39:08 (ID:40) [点击:2015]
  •  

    在线用户
    (无) 
    当前栏目在线用户数 0, 总在线用户数 0