Ejemplo n.º 1
0
        // 执行脚本函数 NotifyReader
        // parameters:
        // return:
        //      -2  not found script
        //      -1  出错
        //      0   成功(这只是表示脚本函数正常执行,而不是表明脚本函数没有返回0以外的值)
        // nResultValue
        //      -1  出错
        //      0   没有必要发送
        //      1   需要发送
        public int DoNotifyReaderScriptFunction(
            XmlDocument readerdom,
            Calendar calendar,
            // List<string> notifiedBarcodes,
            string strBodyType,
            out int nResultValue,
            out string strBody,
            out string strMime,
            // out List<string> wantNotifyBarcodes,
            out string strError)
        {
            strError = "";
            strBody = "";
            nResultValue = -1;
            // wantNotifyBarcodes = null;
            strMime = "";

            if (this.m_strAssemblyLibraryHostError != "")
            {
                strError = this.m_strAssemblyLibraryHostError;
                return -1;
            }

            if (this.m_assemblyLibraryHost == null)
            {
                strError = "未定义<script>脚本代码,无法执行脚本函数NotifyReader()。";
                return -2;
            }

            Type hostEntryClassType = ScriptManager.GetDerivedClassType(
                this.m_assemblyLibraryHost,
                "DigitalPlatform.LibraryServer.LibraryHost");
            if (hostEntryClassType == null)
            {
                strError = "<script>脚本中未找到DigitalPlatform.LibraryServer.LibraryHost类的派生类,无法执行脚本函数NotifyReader()。";
                return -2;
            }

            LibraryHost host = (LibraryHost)hostEntryClassType.InvokeMember(null,
                BindingFlags.DeclaredOnly |
                BindingFlags.Public | BindingFlags.NonPublic |
                BindingFlags.Instance | BindingFlags.CreateInstance, null, null,
                null);
            if (host == null)
            {
                strError = "创建DigitalPlatform.LibraryServer.LibraryHost类的派生类的对象(构造函数)失败。";
                return -1;
            }

            host.App = this;

            try
            {
                // 早绑定
                nResultValue = host.NotifyReader(
                    readerdom,
                    calendar,
                    // notifiedBarcodes,
                    strBodyType,
                    out strBody,
                    out strMime,
                    // out wantNotifyBarcodes,
                    out strError);
                // 只要脚本函数被正常执行,nRet就是返回0
                // nResultValue的值是脚本函数的返回值
            }
            catch (Exception ex)
            {
                strError = "执行脚本函数 NotifyReader() 时抛出异常:" + ExceptionUtil.GetDebugText(ex);
                return -1;
            }

            /*
            // 迟绑定技术。从assembly中实时寻找特定名字的函数
            MethodInfo mi = hostEntryClassType.GetMethod("NotifyReader");
            if (mi == null)
            {
                strError = "<script>脚本中DigitalPlatform.LibraryServer.LibraryHost类的派生类中,没有提供int NotifyReader()函数,因此进行读者通知。";
                return -2;
            }

            // 执行函数
            try
            {
                object[] args = new object[2];
                args[0] = strBarcode;
                args[1] = strError;
                nResultValue = (int)mi.Invoke(host,
                     BindingFlags.DeclaredOnly |
                     BindingFlags.Public | BindingFlags.NonPublic |
                     BindingFlags.Instance | BindingFlags.InvokeMethod,
                     null,
                     args,
                     null);

                // 取出out参数值
                strError = (string)args[1];
            }
            catch (Exception ex)
            {
                strError = "执行脚本函数'" + "NotifyReader" + "'出错:" + ExceptionUtil.GetDebugText(ex);
                return -1;
            }
             * */

            return 0;
        }
Ejemplo n.º 2
0
        // 短消息通知读者超期的版本。供NotifyReader()的重载版本必要时引用
        public int NotifyReaderSMS(
            XmlDocument readerdom,
            Calendar calendar,
            // List<string> notifiedBarcodes,
            string strBodyType,
            out string strBody,
            out string strMime,
            // out List<string> wantNotifyBarcodes,
            out string strError)
        {
            strBody = "";
            strError = "";
            // wantNotifyBarcodes = new List<string>();
            strMime = "text";
            int nRet = 0;

            string strResult = "";
            int nOverdueCount = 0;  // 超期提醒的事项数
            int nNormalCount = 0;   // 一般提醒的事项数

            XmlNodeList nodes = readerdom.DocumentElement.SelectNodes("borrows/borrow");

            if (nodes.Count == 0)
                return 0;

            string strName = DomUtil.GetElementText(readerdom.DocumentElement,
                "name");
            strResult += "您借阅的下列书刊:\n";

            // 借阅的册
            for (int i = 0; i < nodes.Count; i++)
            {
                XmlNode node = nodes[i];

                string strBarcode = DomUtil.GetAttr(node, "barcode");
                string strConfirmItemRecPath = DomUtil.GetAttr(node, "recPath");
                // 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 strHistory = DomUtil.GetAttr(node, "notifyHistory");

                string strOverDue = "";
                bool bOverdue = false;  // 是否超期
                DateTime timeReturning = DateTime.MinValue;
                {
                    DateTime timeNextWorkingDay;
                    long lOver = 0;
                    string strPeriodUnit = "";

                    // 获得还书日期
                    // return:
                    //      -1  数据格式错误
                    //      0   没有发现超期
                    //      1   发现超期   strError中有提示信息
                    //      2   已经在宽限期内,很容易超期 
                    nRet = this.App.GetReturningTime(
                        calendar,
                        strBorrowDate,
                        strPeriod,
                        out timeReturning,
                        out timeNextWorkingDay,
                        out lOver,
                        out strPeriodUnit,
                        out strError);
                    if (nRet == -1)
                        strOverDue = strError;
                    else
                    {
                        if (nRet == 1)
                        {
                            bOverdue = true;
                            strOverDue = string.Format(this.App.GetString("已超期s"),  // 已超期 {0}
                                                this.App.GetDisplayTimePeriodStringEx(lOver.ToString() + " " + strPeriodUnit));
                        }
                    }
                }

                string strChars = "";
                // 获得一种 body type 的全部通知字符
                strChars = ReadersMonitor.GetNotifiedChars(App,
                    strBodyType,
                    strHistory);

                if (bOverdue == true)
                {
                    // 看看是不是已经通知过
                    if (string.IsNullOrEmpty(strChars) == false && strChars[0] == 'y')
                        continue;

                    // 合并设置一种 body type 的全部通知字符
                    // 把 strChars 中的 'y' 设置到 strHistory 中对应达到位。'n' 不设置
                    nRet = ReadersMonitor.SetNotifiedChars(App,
                        strBodyType,
                        "y",
                        ref strHistory,
                        out strError);
                    if (nRet == -1)
                        return -1;

                    ReadersMonitor.SetChar(ref strChars,
                        0,
                        'y',
                        'n');

                    nOverdueCount++;
                }
                else if (string.IsNullOrEmpty(App.NotifyDef) == false)
                {
                    // 检查超期前的通知点

                    List<int> indices = null;
                    // 检查每个通知点,返回当前时间已经达到或者超过了通知点的那些检查点的下标
                    // return:
                    //      -1  数据格式错误
                    //      0   成功
                    nRet = App.CheckNotifyPoint(
                        calendar,
                        strBorrowDate,
                        strPeriod,
                        App.NotifyDef,
                        out indices,
                        out strError);
                    if (nRet == -1)
                        return -1;

                    // 偏移量 0 让给了超期通知
                    for (int k = 0; k < indices.Count; k++)
                    {
                        indices[k] = indices[k] + 1;
                    }

                    // 检查是否至少有一个字符位置为 ch 代表的值
                    if (CheckChar(strChars, indices, 'n', 'n') == true)
                    {
                        // 至少有一个检查点尚未通知
                        strOverDue = "即将到期";
                    }
                    else
                        continue;

                    foreach (int index in indices)
                    {
                        ReadersMonitor.SetChar(ref strChars,
                            index,
                            'y',
                            'n');
                    }

                    nNormalCount++;
                }
                else
                    continue;

                // 合并设置一种 body type 的全部通知字符
                // 把 strChars 中的 'y' 设置到 strHistory 中对应达到位。'n' 不设置
                nRet = ReadersMonitor.SetNotifiedChars(App,
                    strBodyType,
                    strChars,
                    ref strHistory,
                    out strError);
                if (nRet == -1)
                    return -1;
                DomUtil.SetAttr(node, "notifyHistory", strHistory);

                // 获得图书摘要信息
                string strSummary = "";
                string strBiblioRecPath = "";
                nRet = this.App.GetBiblioSummary(strBarcode,
                    strConfirmItemRecPath,
                    null,   //  strBiblioRecPathExclude,
                    10, // 25,
                    out strBiblioRecPath,
                    out strSummary,
                    out strError);
                if (nRet == -1)
                {
                    strSummary = "ERROR: " + strError;
                }

                // strResult += (i + 1).ToString() + ") " 
                strResult += strSummary + " ";
                // strResult += "借阅日期: " + DateTimeUtil.LocalDate(strBorrowDate) + " ";
                strResult += "应还日期: " + timeReturning.ToString("d") + " ";
                strResult += strOverDue + "\n";
            }

            /*
            if (nOverdueCount > 0)
                strResult += "=== 共有 " + nOverdueCount.ToString() + " 册图书超期, 请尽快归还。";
            if (nNormalCount > 0)
                strResult += "=== 共有 " + nNormalCount.ToString() + " 册图书即将到期, 请注意在期限内归还。";
             * */

            strBody = strResult;

            if (nOverdueCount + nNormalCount > 0)
                return 1;
            else
                return 0;
        }
Ejemplo n.º 3
0
        // 短消息通知读者超期的版本。供NotifyReader()的重载版本必要时引用
        public int NotifyReaderSMS(
    XmlDocument readerdom,
    Calendar calendar,
    List<string> notifiedBarcodes,
    string strBodyType,
    out string strBody,
    out string strMime,
    out List<string> wantNotifyBarcodes,
    out string strError)
        {
            strBody = "";
            strError = "";
            wantNotifyBarcodes = new List<string>();
            strMime = "text";
            int nRet = 0;

            string strResult = "";
            int nOverdueCount = 0;

            XmlNodeList nodes = readerdom.DocumentElement.SelectNodes("borrows/borrow");

            if (nodes.Count == 0)
                return 0;

            string strName = DomUtil.GetElementText(readerdom.DocumentElement,
                "name");
            strResult += strName + "您好!您在图书馆借阅的下列图书:";

            // 借阅的册
            for (int i = 0; i < nodes.Count; i++)
            {
                XmlNode node = nodes[i];

                string strBarcode = DomUtil.GetAttr(node, "barcode");
                string strConfirmItemRecPath = DomUtil.GetAttr(node, "recPath");
                // 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 strOverDue = "";
                bool bOverdue = false;  // 是否超期
                DateTime timeReturning = DateTime.MinValue;
                {

                    DateTime timeNextWorkingDay;
                    long lOver = 0;
                    string strPeriodUnit = "";

                    // 获得还书日期
                    // return:
                    //      -1  数据格式错误
                    //      0   没有发现超期
                    //      1   发现超期   strError中有提示信息
                    //      2   已经在宽限期内,很容易超期 
                    nRet = this.App.GetReturningTime(
                        calendar,
                        strBorrowDate,
                        strPeriod,
                        out timeReturning,
                        out timeNextWorkingDay,
                        out lOver,
                        out strPeriodUnit,
                        out strError);
                    if (nRet == -1)
                        strOverDue = strError;
                    else
                    {
                        if (nRet == 1)
                        {
                            bOverdue = true;
                            strOverDue = string.Format(this.App.GetString("已超期s"),  // 已超期 {0}
                                                this.App.GetDisplayTimePeriodStringEx(lOver.ToString() + " " + strPeriodUnit))
                                ;
                        }
                    }
                }

                if (bOverdue == true)
                {
                    nOverdueCount++;

                    // 看看是不是已经通知过
                    if (notifiedBarcodes.IndexOf(strBarcode) == -1)
                    {
                        wantNotifyBarcodes.Add(strBarcode);
                    }
                    else
                        continue;

                    // 获得图书摘要信息
                    string strSummary = "";
                    string strBiblioRecPath = "";
                    nRet = this.App.GetBiblioSummary(strBarcode,
                        strConfirmItemRecPath,
                        null,   //  strBiblioRecPathExclude,
                        25,
                        out strBiblioRecPath,
                        out strSummary,
                        out strError);
                    if (nRet == -1)
                    {
                        strSummary = "ERROR: " + strError;
                    }

                    strResult += (i+1).ToString() + ") " + strSummary + " ";
                    strResult += "借阅日期: " + DateTimeUtil.LocalDate(strBorrowDate) + " ";
                    strResult += "应还日期: " + timeReturning.ToString("d") + " ";
                    strResult += strOverDue + " ";
                }
            }

            strResult += "=== 共有 " + nOverdueCount.ToString() + " 册图书超期, 请尽快归还。";

            strBody = strResult;

            if (wantNotifyBarcodes.Count > 0)
                return 1;
            else
                return 0;
        }
Ejemplo n.º 4
0
        // 2016/4/25
        /*
<root>
        <type>超期通知</type>
        <record>
         ... 读者记录 XML 原始形态
        </record>
        <items overdueCount=已经到期册数 normalCount=即将到期册数 >
            <item 
                barcode='...' 
                location='...' 
                refID='...' 
                summary='书目摘要' 
                borrowDate='借书日期' 
                borrowPeriod='期限' 
                timeReturning='应还时间' 
                overdue='超期情况描述' 
                overdueType='overdue/warning'>
        <items/>
        <text>纯文本描述</text>
<root/>
         * */
        // MQ 通知读者超期的版本。供 NotifyReader() 的重载版本必要时引用
        public int NotifyReaderMQ(
            XmlDocument readerdom,
            Calendar calendar,
            string strBodyType,
            out string strBody,
            out string strMime,
            out string strError)
        {
            strBody = "";
            strError = "";
            strMime = "xml";
            int nRet = 0;

            string strResult = "";
            int nOverdueCount = 0;  // 超期提醒的事项数
            int nNormalCount = 0;   // 一般提醒的事项数

            XmlNodeList nodes = readerdom.DocumentElement.SelectNodes("borrows/borrow");

            if (nodes.Count == 0)
                return 0;

            // 表达通知信息的 XML 记录
            XmlDocument output_dom = new XmlDocument();
            output_dom.LoadXml("<root />");

            string strName = DomUtil.GetElementText(readerdom.DocumentElement,
                "name");

            DomUtil.SetElementText(output_dom.DocumentElement, "type", "超期通知");
            XmlElement items = output_dom.CreateElement("items");
            output_dom.DocumentElement.AppendChild(items);

            string strRights = DomUtil.GetElementText(readerdom.DocumentElement, "rights");
            bool bTestNotify = (StringUtil.IsInList("_testoverduenotify", strRights) == true);

            strResult += "您借阅的下列书刊:\n";

            // 借阅的册
            for (int i = 0; i < nodes.Count; i++)
            {
                XmlNode node = nodes[i];

                string strBarcode = DomUtil.GetAttr(node, "barcode");
                string strLocation = StringUtil.GetPureLocation(DomUtil.GetAttr(node, "location"));
                string strRefID = DomUtil.GetAttr(node, "refID");

                string strConfirmItemRecPath = DomUtil.GetAttr(node, "recPath");
                // 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 strHistory = DomUtil.GetAttr(node, "notifyHistory");

                string strOverDue = "";
                bool bOverdue = false;  // 是否超期
                DateTime timeReturning = DateTime.MinValue;
                {
                    DateTime timeNextWorkingDay;
                    long lOver = 0;
                    string strPeriodUnit = "";

                    if (bTestNotify == true)
                    {
                        timeReturning = DateTime.Now;
                        timeNextWorkingDay = DateTime.Now;
                        long lValue = 0;
                        LibraryApplication.ParsePeriodUnit(strPeriod,
                            out lValue,
                            out strPeriodUnit, 
                            out strError);
                        lOver = lValue;
                        nRet = 1;
                    }
                    else
                    {
                        // 获得还书日期
                        // return:
                        //      -1  数据格式错误
                        //      0   没有发现超期
                        //      1   发现超期   strError中有提示信息
                        //      2   已经在宽限期内,很容易超期 
                        nRet = this.App.GetReturningTime(
                            calendar,
                            strBorrowDate,
                            strPeriod,
                            out timeReturning,
                            out timeNextWorkingDay,
                            out lOver,
                            out strPeriodUnit,
                            out strError);
                    }
                    if (nRet == -1)
                        strOverDue = strError;
                    else
                    {
                        if (nRet == 1)
                        {
                            bOverdue = true;
                            strOverDue = string.Format(this.App.GetString("已超期s"),  // 已超期 {0}
                                                this.App.GetDisplayTimePeriodStringEx(lOver.ToString() + " " + strPeriodUnit));
                        }
                    }
                }

                string strChars = "";
                // 获得一种 body type 的全部通知字符
                strChars = ReadersMonitor.GetNotifiedChars(App,
                    strBodyType,
                    strHistory);

                if (bOverdue == true)
                {
                    // 看看是不是已经通知过
                    if (string.IsNullOrEmpty(strChars) == false && strChars[0] == 'y'
                        && bTestNotify == false)
                        continue;

                    // 合并设置一种 body type 的全部通知字符
                    // 把 strChars 中的 'y' 设置到 strHistory 中对应达到位。'n' 不设置
                    nRet = ReadersMonitor.SetNotifiedChars(App,
                        strBodyType,
                        "y",
                        ref strHistory,
                        out strError);
                    if (nRet == -1)
                        return -1;

                    ReadersMonitor.SetChar(ref strChars,
                        0,
                        'y',
                        'n');

                    nOverdueCount++;
                }
                else if (string.IsNullOrEmpty(App.NotifyDef) == false)
                {
                    // 检查超期前的通知点

                    List<int> indices = null;
                    // 检查每个通知点,返回当前时间已经达到或者超过了通知点的那些检查点的下标
                    // return:
                    //      -1  数据格式错误
                    //      0   成功
                    nRet = App.CheckNotifyPoint(
                        calendar,
                        strBorrowDate,
                        strPeriod,
                        App.NotifyDef,
                        out indices,
                        out strError);
                    if (nRet == -1)
                        return -1;

                    // 偏移量 0 让给了超期通知
                    for (int k = 0; k < indices.Count; k++)
                    {
                        indices[k] = indices[k] + 1;
                    }

                    // 检查是否至少有一个字符位置为 ch 代表的值
                    if (CheckChar(strChars, indices, 'n', 'n') == true)
                    {
                        // 至少有一个检查点尚未通知
                        strOverDue = "即将到期";
                    }
                    else
                        continue;

                    foreach (int index in indices)
                    {
                        ReadersMonitor.SetChar(ref strChars,
                            index,
                            'y',
                            'n');
                    }

                    nNormalCount++;
                }
                else
                    continue;

                // 合并设置一种 body type 的全部通知字符
                // 把 strChars 中的 'y' 设置到 strHistory 中对应达到位。'n' 不设置
                nRet = ReadersMonitor.SetNotifiedChars(App,
                    strBodyType,
                    strChars,
                    ref strHistory,
                    out strError);
                if (nRet == -1)
                    return -1;
                DomUtil.SetAttr(node, "notifyHistory", strHistory);

                // 获得图书摘要信息
                string strSummary = "";
                string strBiblioRecPath = "";
                nRet = this.App.GetBiblioSummary(strBarcode,
                    strConfirmItemRecPath,
                    null,   //  strBiblioRecPathExclude,
                    -1, // 25,
                    out strBiblioRecPath,
                    out strSummary,
                    out strError);
                if (nRet == -1)
                {
                    strSummary = "ERROR: " + strError;
                }

                // strResult += (i + 1).ToString() + ") " 
                strResult += strSummary + " ";
                // strResult += "借阅日期: " + DateTimeUtil.LocalDate(strBorrowDate) + " ";
                strResult += "应还日期: " + timeReturning.ToString("d") + " ";
                strResult += strOverDue + "\n";

                {
                    XmlElement item = output_dom.CreateElement("item");
                    items.AppendChild(item);

                    item.SetAttribute("barcode", strBarcode);
                    item.SetAttribute("location", strLocation); // 2016/9/5
                    item.SetAttribute("refID", strRefID);
                    item.SetAttribute("summary", strSummary);
                    item.SetAttribute("borrowDate", strBorrowDate); // 2016/9/5
                    item.SetAttribute("borrowPeriod", strPeriod);   // 2016/9/5
                    item.SetAttribute("timeReturning", timeReturning.ToString("d"));
                    item.SetAttribute("overdue", strOverDue);
                    if (bOverdue)
                        item.SetAttribute("overdueType", "overdue");
                    else
                        item.SetAttribute("overdueType", "warning");
                }
            }

            /*
            if (nOverdueCount > 0)
                strResult += "=== 共有 " + nOverdueCount.ToString() + " 册图书超期, 请尽快归还。";
            if (nNormalCount > 0)
                strResult += "=== 共有 " + nNormalCount.ToString() + " 册图书即将到期, 请注意在期限内归还。";
             * */
            items.SetAttribute("overdueCount", nOverdueCount.ToString());
            items.SetAttribute("normalCount", nNormalCount.ToString());

            DomUtil.SetElementText(output_dom.DocumentElement, "text", strResult);

            {
                XmlElement record = output_dom.CreateElement("patronRecord");
                output_dom.DocumentElement.AppendChild(record);
                record.InnerXml = readerdom.DocumentElement.InnerXml;

                DomUtil.DeleteElement(record, "borrowHistory");
                DomUtil.DeleteElement(record, "password");
                DomUtil.DeleteElement(record, "fingerprint");
                // TODO: 是否包含 librryCode 元素?
            }

            strBody = output_dom.DocumentElement.OuterXml;

            if (nOverdueCount + nNormalCount > 0)
                return 1;
            else
                return 0;
        }
Ejemplo n.º 5
0
        // 超期提醒
        // 新版本,可以处理超期前提醒
        // retun:
        //      -1  出错
        //      0   没有必要发送
        //      1   需要发送
        public virtual int NotifyReader(
            XmlDocument readerdom,
            Calendar calendar,
            // List<string> notifiedBarcodes,
            string strBodyType,
            out string strBody,
            out string strMime,
            // out List<string> wantNotifyBarcodes,
            out string strError)
        {
            if (strBodyType == "sms")
            {
                return NotifyReaderSMS(
                    readerdom,
                    calendar,
                    //notifiedBarcodes,
                    strBodyType,
                    out strBody,
                    out strMime,
                    //out wantNotifyBarcodes,
                    out strError);
            }

            if (strBodyType == "mq")
            {
                return NotifyReaderMQ(
                    readerdom,
                    calendar,
                    strBodyType,
                    out strBody,
                    out strMime,
                    out strError);
            }

            strBody = "";
            strError = "";
            // wantNotifyBarcodes = new List<string>();
            strMime = "html";
            int nRet = 0;

            string strResult = "";
            // int nNotifyCount = 0;   // 需要通知的事项 nNotifyCount = nOverduCount + nNormalCount
            int nOverdueCount = 0;  // 超期提醒的事项数
            int nNormalCount = 0;   // 一般提醒的事项数

            XmlNodeList nodes = readerdom.DocumentElement.SelectNodes("borrows/borrow");

            if (nodes.Count == 0)
                return 0;

            string strLink = "<LINK href='" + App.OpacServerUrl + "/readerhtml.css' type='text/css' rel='stylesheet'>";
            strResult = "<html><head>" + strLink + "</head><body>";

            string strName = DomUtil.GetElementText(readerdom.DocumentElement,
    "name");
            strResult += "尊敬的 " + strName + " 您好!<br/><br/>您在图书馆借阅的下列图书:";

            // 借阅的册
            // strResult += "<br/>借阅信息<br/>";
            strResult += "<table class='borrowinfo' width='100%' cellspacing='1' cellpadding='4'>";
            strResult += "<tr class='columntitle'>"
                + "<td nowrap>册条码号</td>"
                + "<td class='no' nowrap align='right'>续借次</td>"
                + "<td nowrap>借阅日期</td>"
                + "<td nowrap>期限</td>"
                + "<td nowrap>应还日期</td>"
                //+ "<td nowrap>操作者</td>"
                + "<td nowrap>超期情况</td>"
                //+ "<td nowrap>备注</td>"
                + "</tr>";
            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 strHistory = DomUtil.GetAttr(node, "notifyHistory");

                string strOverDue = "";
                bool bOverdue = false;
                DateTime timeReturning = DateTime.MinValue;
                {

                    DateTime timeNextWorkingDay;
                    long lOver = 0;
                    string strPeriodUnit = "";

                    // 获得还书日期
                    // return:
                    //      -1  数据格式错误
                    //      0   没有发现超期
                    //      1   发现超期   strError中有提示信息
                    //      2   已经在宽限期内,很容易超期 
                    nRet = this.App.GetReturningTime(
                        calendar,
                        strBorrowDate,
                        strPeriod,
                        out timeReturning,
                        out timeNextWorkingDay,
                        out lOver,
                        out strPeriodUnit,
                        out strError);
                    if (nRet == -1)
                        strOverDue = strError;
                    else
                    {
                        if (nRet == 1)
                        {
                            bOverdue = true;
                            strOverDue = string.Format(this.App.GetString("已超期s"),  // 已超期 {0}
                                                this.App.GetDisplayTimePeriodStringEx(lOver.ToString() + " " + strPeriodUnit));
                        }
                    }
                }

                string strColor = "bgcolor=#ffffff";

                string strChars = "";
                // 获得一种 body type 的全部通知字符
                strChars = ReadersMonitor.GetNotifiedChars(App,
                    strBodyType,
                    strHistory);

                if (bOverdue == true)
                {
                    strColor = "bgcolor=#ff9999";	// 超期

                    // 看看是不是已经通知过
                    if (string.IsNullOrEmpty(strChars) == false && strChars[0] == 'y')
                        continue;

                    // 合并设置一种 body type 的全部通知字符
                    // 把 strChars 中的 'y' 设置到 strHistory 中对应达到位。'n' 不设置
                    nRet = ReadersMonitor.SetNotifiedChars(App,
                        strBodyType,
                        "y",
                        ref strHistory,
                        out strError);
                    if (nRet == -1)
                        return -1;

                    ReadersMonitor.SetChar(ref strChars,
                        0,
                        'y',
                        'n');

                    // nNotifyCount++;
                    nOverdueCount++;
                }
                else if (string.IsNullOrEmpty(App.NotifyDef) == false)
                {
                    // 检查超期前的通知点

                    List<int> indices = null;
                    // 检查每个通知点,返回当前时间已经达到或者超过了通知点的那些检查点的下标
                    // return:
                    //      -1  数据格式错误
                    //      0   成功
                    nRet = App.CheckNotifyPoint(
                        calendar,
                        strBorrowDate,
                        strPeriod,
                        App.NotifyDef,
                        out indices,
                        out strError);
                    if (nRet == -1)
                        return -1;

                    // 偏移量 0 让给了超期通知
                    for (int k = 0; k < indices.Count; k++)
                    {
                        indices[k] = indices[k] + 1;
                    }

                    // 检查是否至少有一个字符位置为 ch 代表的值
                    if (CheckChar(strChars, indices, 'n', 'n') == true)
                    {
                        // 至少有一个检查点尚未通知
                        strOverDue = "即将到期";
                    }
                    else
                        continue;

                    foreach (int index in indices)
                    {
                        ReadersMonitor.SetChar(ref strChars,
                            index,
                            'y',
                            'n');
                    }

                    nNormalCount++;
                    // nNotifyCount++;
                }
                else
                    continue;

                // 合并设置一种 body type 的全部通知字符
                // 把 strChars 中的 'y' 设置到 strHistory 中对应达到位。'n' 不设置
                nRet = ReadersMonitor.SetNotifiedChars(App,
                    strBodyType,
                    strChars,
                    ref strHistory,
                    out strError);
                if (nRet == -1)
                    return -1;
                DomUtil.SetAttr(node, "notifyHistory", strHistory);

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

                strResult += "<tr class='content' " + strColor + " nowrap>";
                strResult += "<td class='barcode' nowrap>" + strBarcodeLink + "</td>";
                strResult += "<td class='no' nowrap align='right'>" + HttpUtility.HtmlEncode(strNo) + "</td>";
                strResult += "<td class='borrowdate' >" + HttpUtility.HtmlEncode(DateTimeUtil.LocalTime(strBorrowDate)) + "</td>";
                strResult += "<td class='period' nowrap>" + HttpUtility.HtmlEncode(App.GetDisplayTimePeriodStringEx(strPeriod)) + "</td>";
                strResult += "<td class='returningdate' >" + HttpUtility.HtmlEncode(timeReturning.ToString("d")) + "</td>";
                // strResult += "<td class='operator' nowrap>" + HttpUtility.HtmlEncode(strOperator) + "</td>";
                strResult += "<td class='overdue' >" + HttpUtility.HtmlEncode(strOverDue) + "</td>";
                // strResult += "<td class='renewcomment' nowrap>" + strRenewComment.Replace(";", "<br/>") + "</td>";
                strResult += "</tr>";
            }

            strResult += "</table>";

            if (nOverdueCount > 0)
            {
                strResult += "<p>";
                strResult += "有 " + nOverdueCount.ToString() + " 册图书已经超期, 请尽快归还。";
                strResult += "</p>";
            }

            if (nNormalCount > 0)
            {
                strResult += "<p>";
                strResult += "有 " + nNormalCount.ToString() + " 册图书即将到期, 请注意在期限内归还。";
                strResult += "</p>";
            }

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

            strBody = strResult;

            if (nOverdueCount + nNormalCount > 0)
                return 1;
            else
                return 0;
        }
Ejemplo n.º 6
0
        /*
        public void Invoke(string strFuncName)
        {
            Type classType = this.GetType();

            // new一个Host派生对象
            classType.InvokeMember(strFuncName,
                BindingFlags.DeclaredOnly |
                BindingFlags.Public | BindingFlags.NonPublic |
                BindingFlags.Instance | BindingFlags.InvokeMethod,
                null,
                this,
                null);

        }*/

#if NO
        // 以前的版本,不能实现超期前提醒
        // retun:
        //      -1  出错
        //      0   没有必要发送
        //      1   需要发送
        public virtual int NotifyReader(
            XmlDocument readerdom,
            Calendar calendar,
            List<string> notifiedBarcodes,
            string strBodyType,
            // out int nResultValue,
            out string strBody,
            out string strMime,
            out List<string> wantNotifyBarcodes,
            out string strError)
        {
            strBody = "";
            strError = "";
            wantNotifyBarcodes = new List<string>();
            strMime = "html";
            int nRet = 0;

            string strResult = "";
            int nOverdueCount = 0;

            XmlNodeList nodes = readerdom.DocumentElement.SelectNodes("borrows/borrow");

            if (nodes.Count == 0)
                return 0;

            string strLink = "<LINK href='" + App.OpacServerUrl + "/readerhtml.css' type='text/css' rel='stylesheet'>";
            strResult = "<html><head>" + strLink + "</head><body>";

            // 借阅的册
            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>";
            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 strOverDue = "";
                bool bOverdue = false;
 
                // 检查超期情况。
                // return:
                //      -1  数据格式错误
                //      0   没有发现超期
                //      1   发现超期   strError中有提示信息
                //      2   已经在宽限期内,很容易超期 2009/3/13
                nRet = App.CheckPeriod(
                    calendar,
                    strBorrowDate,
                    strPeriod,
                    out strError);
                if (nRet == -1)
                    strOverDue = strError;
                else if (nRet == 1)
                {
                    strOverDue = strError;	// "已超期";
                    bOverdue = true;
                }
                else
                    strOverDue = strError;	// 可能也有一些必要的信息,例如非工作日

                string strColor = "bgcolor=#ffffff";

                if (bOverdue == true)
                {
                    strColor = "bgcolor=#ff9999";	// 超期

                    nOverdueCount ++;

                    // 看看是不是已经通知过
                    if (notifiedBarcodes.IndexOf(strBarcode) == -1)
                    {
                        wantNotifyBarcodes.Add(strBarcode);
                    }
                }

                string strBarcodeLink = "<a href='" + App.OpacServerUrl + "/book.aspx?barcode=" + strBarcode + "&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' >" + DateTimeUtil.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 += "</table>";

            strResult += "<p>";
            strResult += "有 " + nOverdueCount.ToString()+ " 册图书超期, 请尽快归还。";
            strResult += "</p>";

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

            strBody = strResult;

            if (wantNotifyBarcodes.Count > 0)
                return 1;
            else
                return 0;
        }
Ejemplo n.º 7
0
        // 判断是否超过保留期限
        // return:
        //      -1  error
        //      0   没有超过
        //      1   已经超过
        int CheckeOutOfReservation(
            Calendar calendar,
            XmlDocument queue_rec_dom,
            out string strError)
        {
            strError = "";

            string strState = DomUtil.GetElementText(queue_rec_dom.DocumentElement,
    "state");

            // 对通知完成后的记录, 循环中不必处理
            if (StringUtil.IsInList("outof", strState) == true)
                return 0;

            string strNotifyDate = DomUtil.GetElementText(queue_rec_dom.DocumentElement,
                "notifyDate");

            /*
            string strItemBarcode = DomUtil.GetElementText(queue_rec_dom.DocumentElement,
                "itemBarcode");
            string strReaderBarcode = DomUtil.GetElementText(queue_rec_dom.DocumentElement,
                "readerBarcode");
             * */


            // 解析期限值
            string strPeriodUnit = "";
            long lPeriodValue = 0;

            int nRet = LibraryApplication.ParsePeriodUnit(
                this.App.ArrivedReserveTimeSpan,
                out lPeriodValue,
                out strPeriodUnit,
                out strError);
            if (nRet == -1)
            {
                strError = "预约保留期限 值 '" + this.App.ArrivedReserveTimeSpan + "' 格式错误: " + strError;
                return -1;
            }

            //
            DateTime notifydate;

            try
            {
                notifydate = DateTimeUtil.FromRfc1123DateTimeString(strNotifyDate);
            }
            catch
            {
                strError = "通知日期值 '" + strNotifyDate + "' 格式错误";
                return -1;
            }


            DateTime timeEnd = DateTime.MinValue;

            nRet = LibraryApplication.GetOverTime(
                calendar,
                notifydate,
                lPeriodValue,
                strPeriodUnit,
                out timeEnd,
                out strError);
            if (nRet == -1)
            {
                strError = "计算保留期过程发生错误: " + strError;
                return -1;
            }

            DateTime now = this.App.Clock.UtcNow;  //  DateTime.UtcNow;

            // 正规化时间
            nRet = DateTimeUtil.RoundTime(strPeriodUnit,
                ref now,
                out strError);
            if (nRet == -1)
                return -1;

            TimeSpan delta = now - timeEnd;

            long lDelta = 0;

            nRet = LibraryApplication.ParseTimeSpan(
                delta,
                strPeriodUnit,
                out lDelta,
                out strError);
            if (nRet == -1)
                return -1;

            if (lDelta > 0)
                return 1;

            return 0;
        }
Ejemplo n.º 8
0
        // 检查当前是否有潜在的超期册
        // return:
        //      -1  error
        //      0   没有超期册
        //      1   有超期册
        int CheckOverdue(
            Calendar calendar,
            ref XmlDocument readerdom,
            out string strError)
        {
            strError = "";
            int nOverCount = 0;
            int nRet = 0;

            LibraryApplication app = this.App;

            string strOverdueItemBarcodeList = "";

            XmlNodeList nodes = readerdom.DocumentElement.SelectNodes("borrows/borrow");
            XmlNode node = null;
            if (nodes.Count > 0)
            {
                for (int i = 0; i < nodes.Count; i++)
                {
                    node = nodes[i];
                    string strBarcode = DomUtil.GetAttr(node, "barcode");
                    string strBorrowDate = DomUtil.GetAttr(node, "borrowDate");
                    string strPeriod = DomUtil.GetAttr(node, "borrowPeriod");
                    string strOperator = DomUtil.GetAttr(node, "operator");

                    // return:
                    //      -1  数据格式错误
                    //      0   没有发现超期
                    //      1   发现超期   strError中有提示信息
                    //      2   已经在宽限期内,很容易超期 2009/3/13
                    nRet = app.CheckPeriod(
                        calendar,
                        strBorrowDate,
                        strPeriod,
                        out strError);
                    if (nRet == -1)
                    {
                        strError = "读者记录中 有关册 '" + strBarcode + "' 的借阅期限信息检查出现错误:" + strError;
                    }

                    if (nRet == 1)
                    {
                        if (strOverdueItemBarcodeList != "")
                            strOverdueItemBarcodeList += ",";
                        strOverdueItemBarcodeList += strBarcode;
                        nOverCount++;
                    }


                }

                // 发现未归还的册中出现了超期情况
                if (nOverCount > 0)
                {
                    strError = "该读者当前有 " + Convert.ToString(nOverCount) + " 个未还超期册: " + strOverdueItemBarcodeList + "";
                    return 1;
                }
            }

            return 0;
        }